From df5681c8c445d22ae52cd7ea46a3c5e438c769ed Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 7 Jul 2023 18:12:46 +0300 Subject: [PATCH 20/20] Lua: Add City:transfer() method Requested anonymously See osdn #48312 Signed-off-by: Marko Lindqvist --- server/scripting/api_server_edit.c | 12 ++++++++++++ server/scripting/api_server_edit.h | 3 ++- server/scripting/tolua_server.pkg | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 85d1349365..e59d4647c7 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -624,6 +624,18 @@ void api_edit_remove_city(lua_State *L, City *pcity) remove_city(pcity); } +/**********************************************************************//** + Transfer city from player to another. +**************************************************************************/ +bool api_edit_transfer_city(lua_State *L, City *pcity, Player *new_owner) +{ + LUASCRIPT_CHECK_STATE(L, FALSE); + LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City, FALSE); + LUASCRIPT_CHECK_ARG_NIL(L, new_owner, 3, Player, FALSE); + + return transfer_city(new_owner, pcity, FALSE, FALSE, FALSE, FALSE, FALSE); +} + /**********************************************************************//** Create a building to a city **************************************************************************/ diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index e484469ef6..c35212b1d4 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -19,7 +19,7 @@ struct lua_State; -/* type of climate change */ +/* Type of climate change */ enum climate_change_type { CLIMATE_CHANGE_GLOBAL_WARMING, CLIMATE_CHANGE_NUCLEAR_WINTER @@ -72,6 +72,7 @@ bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr); bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile, const char *name); void api_edit_remove_city(lua_State *L, City *pcity); +bool api_edit_transfer_city(lua_State *L, City *pcity, Player *new_owner); void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr); void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr); Player *api_edit_create_player(lua_State *L, const char *username, diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index e9115de6bd..8db60fdd09 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -129,6 +129,8 @@ module edit { bool api_edit_create_city @ create_city (lua_State *L, Player *pplayer, Tile *ptile, const char *name); + bool api_edit_transfer_city + @ transfer_city (lua_State *L, City *pcity, Player *new_owner); void api_edit_remove_city @ remove_city (lua_State *L, City *pcity); void api_edit_create_building @@ -380,6 +382,10 @@ function City:remove() edit.remove_city(self) end +function City:transfer(new_owner) + edit.transfer_city(self, new_owner) +end + function City:add_history(amount) edit.add_city_history(self, amount) end -- 2.40.1