From a574138dbac0068161fa95307a9b2601873043fb Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Wed, 3 Feb 2021 09:47:06 +0100 Subject: [PATCH 15/15] Lua script API: export action target kind. Export an action's target kind as a string to Lua. It is already exposed to the ruleset via the user actions target kind setting. This can be used to write a call back handler that is registered for multiple target kinds but still can get target kind specific information. See osdn #41446 --- common/scriptcore/api_game_methods.c | 16 ++++++++++++++++ common/scriptcore/api_game_methods.h | 1 + common/scriptcore/tolua_game.pkg | 2 ++ 3 files changed, 19 insertions(+) diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c index f32c72c4cf..c16cc93682 100644 --- a/common/scriptcore/api_game_methods.c +++ b/common/scriptcore/api_game_methods.c @@ -730,6 +730,22 @@ const char *api_methods_action_name_translation(lua_State *L, Action *pact) return action_id_name_translation(pact->id); } +/**********************************************************************//** + Return target kind for Action +**************************************************************************/ +const char *api_methods_action_target_kind(lua_State *L, Action *pact) +{ + struct action *paction; + + LUASCRIPT_CHECK_STATE(L, NULL); + LUASCRIPT_CHECK_SELF(L, pact, NULL); + + paction = action_by_number(pact->id); + fc_assert_ret_val(paction, "error: no action"); + + return action_target_kind_name(action_get_target_kind(paction)); +} + /*************************************************************************//** Return the native x coordinate of the tile. *****************************************************************************/ diff --git a/common/scriptcore/api_game_methods.h b/common/scriptcore/api_game_methods.h index d99db85bcc..3d19dd489d 100644 --- a/common/scriptcore/api_game_methods.h +++ b/common/scriptcore/api_game_methods.h @@ -122,6 +122,7 @@ const char *api_methods_achievement_name_translation(lua_State *L, const char *api_methods_action_rule_name(lua_State *L, Action *pact); const char *api_methods_action_name_translation(lua_State *L, Action *pact); +const char *api_methods_action_target_kind(lua_State *L, Action *pact); /* Tile */ int api_methods_tile_nat_x(lua_State *L, Tile *ptile); diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index 9022074379..669e30d5de 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -436,6 +436,8 @@ module Action { @ rule_name (lua_State *L, Action *self); const char *api_methods_action_name_translation @ name_translation (lua_State *L, Action *self); + const char *api_methods_action_target_kind + @ target_kind (lua_State *L, Action *self); } /* Module Unit_List_Link. */ -- 2.20.1