From 5ea8a358298c1b21032e87888d5cdc1628beac54 Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Fri, 8 Jul 2022 23:18:34 +0300 Subject: [PATCH] Lua: make player:give_bulbs() support target tech in multiresearch mode See OSDN#44936. Signed-off-by: Ihnatus --- server/scripting/api_server_edit.c | 28 +++++++++++++++++++++++----- server/scripting/api_server_edit.h | 3 ++- server/scripting/tolua_server.pkg | 7 ++++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 0c08315e5d..92372151d9 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -1071,14 +1071,32 @@ void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount) } /**********************************************************************//** - Give bulbs to a player + Give bulbs to a player, optionally towards a specific tech. + in which case multiresearch mode is required. The tech known state + won't immediately change unless it is the tech currently researched. **************************************************************************/ -void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount) +void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount, + Tech_Type *tech) { + struct research *presearch; + LUASCRIPT_CHECK_STATE(L); LUASCRIPT_CHECK_SELF(L, pplayer); + presearch = research_get(pplayer); + fc_assert_ret(presearch); + LUASCRIPT_CHECK(L, game.server.multiresearch || !tech, + "Bulbs amounts for specific advances are not saved " + "in this game."); + + if (!tech || advance_number(tech) == presearch->researching) { + update_bulbs(pplayer, amount, TRUE); + /* Currently, multiresearch data are not sent to clients, + * so do it only here */ + send_research_info(presearch, NULL); + return; + } - update_bulbs(pplayer, amount, TRUE); - - send_research_info(research_get(pplayer), NULL); + /* Sometimes may get negative, it's normal though lurking */ + presearch->inventions[advance_number(tech)].bulbs_researched_saved + += amount; } diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index 63d1d4d019..bcbed0ff71 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -112,6 +112,7 @@ 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); +void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount, + Tech_Type *tech); #endif /* API_SERVER_EDIT_H */ diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 18bc991885..fe73dc5522 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -226,7 +226,8 @@ module edit { @ 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); + @ give_bulbs(lua_State *L, Player *self, int amount, + Tech_Type *tech = NULL); } /* Luadata module. */ @@ -364,8 +365,8 @@ function Player:add_history(amount) edit.add_player_history(self, amount) end -function Player:give_bulbs(amount) - edit.give_bulbs(self, amount) +function Player:give_bulbs(amount, tech) + edit.give_bulbs(self, amount, tech) end -- Server functions for City module -- 2.34.1