From 26b61b8cc4d399e2e5f0fed9409548074d425e9f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 6 May 2024 18:25:04 +0300 Subject: [PATCH 66/66] Lua: Add Tile:known(player) and Tile:seen(player) Requested by ihnatus See osdn #42684 Signed-off-by: Marko Lindqvist --- common/scriptcore/api_game_methods.c | 25 +++++++++++++++++++++++++ common/scriptcore/api_game_methods.h | 2 ++ common/scriptcore/tolua_game.pkg | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c index 310b18eb4f..c97099f2e9 100644 --- a/common/scriptcore/api_game_methods.c +++ b/common/scriptcore/api_game_methods.c @@ -1395,6 +1395,30 @@ Tile *api_methods_unit_tile_get(lua_State *L, Unit *punit) return unit_tile(punit); } +/**********************************************************************//** + Whether player knows the tile +**************************************************************************/ +bool api_methods_tile_known(lua_State *L, Tile *self, Player *watcher) +{ + LUASCRIPT_CHECK_STATE(L, FALSE); + LUASCRIPT_CHECK_SELF(L, self, FALSE); + LUASCRIPT_CHECK_ARG_NIL(L, watcher, 3, Player, FALSE); + + return tile_get_known(self, watcher) != TILE_UNKNOWN; +} + +/**********************************************************************//** + Whether player currently sees the tile +**************************************************************************/ +bool api_methods_tile_seen(lua_State *L, Tile *self, Player *watcher) +{ + LUASCRIPT_CHECK_STATE(L, FALSE); + LUASCRIPT_CHECK_SELF(L, self, FALSE); + LUASCRIPT_CHECK_ARG_NIL(L, watcher, 3, Player, FALSE); + + return tile_get_known(self, watcher) == TILE_KNOWN_SEEN; +} + /**********************************************************************//** Get unit orientation **************************************************************************/ @@ -1426,6 +1450,7 @@ Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L, { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_SELF(L, punit, NULL); + return unit_list_head(punit->transporting); } diff --git a/common/scriptcore/api_game_methods.h b/common/scriptcore/api_game_methods.h index 2af0a9ac0b..ac0b2dd19a 100644 --- a/common/scriptcore/api_game_methods.h +++ b/common/scriptcore/api_game_methods.h @@ -174,6 +174,8 @@ Tile *api_methods_private_tile_for_outward_index(lua_State *L, Tile *pstart, int tindex); Unit_List_Link *api_methods_private_tile_unit_list_head(lua_State *L, Tile *ptile); +bool api_methods_tile_known(lua_State *L, Tile *self, Player *watcher); +bool api_methods_tile_seen(lua_State *L, Tile *self, Player *watcher); /* Unit */ bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit); diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index 4e123023f8..b23bbbfe75 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -294,6 +294,11 @@ module City { @ link_text(lua_State *L, City *self); const char *api_methods_city_tile_link @ tile_link_text(lua_State *L, City *self); + + bool api_methods_tile_known + @ known(lua_State *L, Tile *self, Player *watcher); + bool api_methods_tile_seen + @ seen(lua_State *L, Tile *self, Player *watcher); } $[ -- 2.43.0