From b466782cf6b5605324b6f9eb88ddc14b7c8ee44b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 3 Oct 2021 00:31:23 +0300 Subject: [PATCH 40/41] Lua: Add Tile:show() and Tile:hide() methods Requested by ihnatus See osdn #42973 Signed-off-by: Marko Lindqvist --- server/scripting/api_server_edit.c | 46 ++++++++++++++++++++++++++++++ server/scripting/api_server_edit.h | 2 ++ server/scripting/tolua_server.pkg | 12 ++++++++ 3 files changed, 60 insertions(+) diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 91128e0ff6..5814a7b843 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -754,6 +754,52 @@ void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label) } } +/**********************************************************************//** + Reveal tile as it is currently to the player. +**************************************************************************/ +void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer) +{ + LUASCRIPT_CHECK_STATE(L); + LUASCRIPT_CHECK_SELF(L, ptile); + LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player); + + map_show_tile(pplayer, ptile); +} + +/**********************************************************************//** + Try to hide tile from player. +**************************************************************************/ +bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer) +{ + struct city *pcity; + + LUASCRIPT_CHECK_STATE(L, FALSE); + LUASCRIPT_CHECK_SELF(L, ptile, FALSE); + LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player, FALSE); + + if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) { + /* Can't hide currently seen tile */ + return FALSE; + } + + pcity = tile_city(ptile); + + if (pcity != NULL) { + trade_partners_iterate(pcity, partner) { + if (really_gives_vision(pplayer, city_owner(partner))) { + /* Can't remove vision about trade partner */ + return FALSE; + } + } trade_partners_iterate_end; + } + + dbv_clr(&pplayer->tile_known, tile_index(ptile)); + + send_tile_info(pplayer->connections, ptile, TRUE); + + return TRUE; +} + /**********************************************************************//** Global climate change. **************************************************************************/ diff --git a/server/scripting/api_server_edit.h b/server/scripting/api_server_edit.h index ddc1dbcf8c..40282bdae8 100644 --- a/server/scripting/api_server_edit.h +++ b/server/scripting/api_server_edit.h @@ -85,6 +85,8 @@ void api_edit_create_road(lua_State *L, Tile *ptile, const char *name); void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name); void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label); +void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer); +bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer); void api_edit_climate_change(lua_State *L, enum climate_change_type type, int effect); diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 85ca709f36..2558ea0a6a 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -145,6 +145,10 @@ module edit { @ remove_extra (lua_State *L, Tile *ptile, const char *name); void api_edit_tile_set_label @ tile_set_label (lua_State *L, Tile *ptile, const char *label); + void api_edit_tile_show + @ tile_show (lua_State *L, Tile *ptile, Player *pplayer); + bool api_edit_tile_hide + @ tile_hide (lua_State *L, Tile *ptile, Player *pplayer); Player *api_edit_create_player @ create_player(lua_State *L, const char *username, Nation_Type *nation, const char *ai); @@ -456,6 +460,14 @@ function Tile:set_label(label) edit.tile_set_label(self, label) end +function Tile:show(player) + edit.tile_show(self, player) +end + +function Tile:hide(player) + return edit.tile_hide(self, player) +end + $] /* Additions to common Player module. */ -- 2.33.0