From fdf21fdc47898fd8231bde7da26dc08518845560 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 11 Nov 2021 07:47:37 +0200 Subject: [PATCH 29/29] Lua: Add Player:give_bulbs() method Requested by ihnatus See osdn #42502 Signed-off-by: Marko Lindqvist --- server/scripting/api_server_edit.c | 13 +++++++++++++ server/scripting/api_server_edit.h | 2 ++ server/scripting/tolua_server.pkg | 7 +++++++ server/techtools.c | 4 ++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index c6fd3dc950..987b18d0d8 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -998,3 +998,16 @@ void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount) pplayer->history += amount; } + +/**********************************************************************//** + Give bulbs to a player +**************************************************************************/ +void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount) +{ + LUASCRIPT_CHECK_STATE(L); + LUASCRIPT_CHECK_SELF(L, pplayer); + + update_bulbs(pplayer, amount, TRUE); + + send_player_info_c(pplayer, NULL); +} diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index 128144df3c..1836a50298 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -107,4 +107,6 @@ void api_edit_unit_moving_allow(lua_State *L, Unit *punit); void api_edit_city_add_history(lua_State *L, City *pcity, int amount); void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount); +void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount); + #endif /* API_SERVER_EDIT_H */ diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index a3de628eba..91e798f06f 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -222,6 +222,9 @@ module edit { @ add_city_history(lua_State *L, City *self, int amount); void api_edit_player_add_history @ add_player_history(lua_State *L, Player *self, int amount); + + void api_edit_player_give_bulbs + @ give_bulbs(lua_State *L, Player *self, int amount); } /* Luadata module. */ @@ -359,6 +362,10 @@ function Player:add_history(amount) edit.add_player_history(self, amount) end +function Player:give_bulbs(amount) + edit.give_bulbs(self, amount) +end + -- Server functions for City module function City:add_history(amount) edit.add_city_history(self, amount) diff --git a/server/techtools.c b/server/techtools.c index 8fe8ac97a7..0483f6c0ad 100644 --- a/server/techtools.c +++ b/server/techtools.c @@ -607,8 +607,8 @@ static bool lose_tech(struct research *research) The caller is responsible for sending updated player information. - This is called from each city every turn, from caravan revenue, and at the - end of the phase. + This is called from each city every turn, from caravan revenue, at the + end of the phase, and from lua API. ****************************************************************************/ void update_bulbs(struct player *pplayer, int bulbs, bool check_tech) { -- 2.33.0