From 5b97c800231ef07450180f76d10bafff606e0ad8 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 17 Feb 2023 22:00:01 +0200 Subject: [PATCH 30/30] Lua: Add Player:change_infrapoints() See osdn #47382 Signed-off-by: Marko Lindqvist --- server/scripting/api_server_edit.c | 14 ++++++++++++++ server/scripting/api_server_edit.h | 1 + server/scripting/tolua_server.pkg | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 1e31c4076a..b4cb135110 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -740,6 +740,20 @@ void api_edit_change_gold(lua_State *L, Player *pplayer, int amount) pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount); } +/**********************************************************************//** + Change pplayer's infrapoints by amount. +**************************************************************************/ +void api_edit_change_infrapoints(lua_State *L, Player *pplayer, int amount) +{ + LUASCRIPT_CHECK_STATE(L); + LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player); + + pplayer->economic.infra_points + = MAX(0, pplayer->economic.infra_points + amount); + + send_player_info_c(pplayer, NULL); +} + /**********************************************************************//** Give pplayer technology ptech. Quietly returns NULL if player already has this tech; otherwise returns the tech granted. diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index bcbed0ff71..27d974ff2b 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -77,6 +77,7 @@ void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr); Player *api_edit_create_player(lua_State *L, const char *username, Nation_Type *pnation, const char *ai); void api_edit_change_gold(lua_State *L, Player *pplayer, int amount); +void api_edit_change_infrapoints(lua_State *L, Player *pplayer, int amount); Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer, Tech_Type *ptech, int cost, bool notify, const char *reason); diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 5032ccb840..e9115de6bd 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -160,6 +160,8 @@ module edit { const char *ai); void api_edit_change_gold @ change_gold (lua_State *L, Player *pplayer, int amount); + void api_edit_change_infrapoints + @ change_infrapoints (lua_State *L, Player *pplayer, int amount); /* cost: * 0 or above - The exact cost % to apply * -1 - Apply freecost @@ -338,6 +340,10 @@ function Player:change_gold(amount) edit.change_gold(self, amount) end +function Player:change_infrapoints(amount) + edit.change_infrapoints(self, amount) +end + function Player:give_tech(tech, cost, notify, reason) return edit.give_tech(self, tech, cost, notify, reason) end -- 2.39.1