From e2367f646508e5e4c69877054d078d7d98bb5b55 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 12 Mar 2021 15:28:33 +0100 Subject: [PATCH] Lua API: introduce effects.unit_vs_tile_bonus(). It is like effects.unit_bonus() except that it takes a tile argument and that the city the effect is evaluated against is the city at the argument tile rather than the city at the unit's tile. See osdn #41749 --- common/scriptcore/api_game_effects.c | 23 +++++++++++++++++++++++ common/scriptcore/api_game_effects.h | 2 ++ common/scriptcore/tolua_game.pkg | 3 +++ 3 files changed, 28 insertions(+) diff --git a/common/scriptcore/api_game_effects.c b/common/scriptcore/api_game_effects.c index 9f8559b662..3abebce108 100644 --- a/common/scriptcore/api_game_effects.c +++ b/common/scriptcore/api_game_effects.c @@ -106,3 +106,26 @@ int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, NULL, etype); } + +/***********************************************************************//** + Returns the effect bonus at a tile and the specified unit. + Unlike effects.unit_bonus() the city the effect is evaluated against is + the city at ptile tile rather than the city at the unit's tile. +***************************************************************************/ +int api_effects_unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile, + const char *effect_type) +{ + enum effect_type etype = EFT_COUNT; + + LUASCRIPT_CHECK_STATE(L, 0); + LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, 0); + LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, 0); + LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 4, string, 0); + + etype = effect_type_by_name(effect_type, fc_strcasecmp); + if (!effect_type_is_valid(etype)) { + return 0; + } + + return get_unit_vs_tile_bonus(ptile, punit, etype); +} diff --git a/common/scriptcore/api_game_effects.h b/common/scriptcore/api_game_effects.h index 8cb84e5ed4..bd990cb92c 100644 --- a/common/scriptcore/api_game_effects.h +++ b/common/scriptcore/api_game_effects.h @@ -30,6 +30,8 @@ int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type); int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, const char *effect_type); +int api_effects_unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile, + const char *effect_type); #ifdef __cplusplus } diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index 20807d16a5..7b3cbb7d75 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -532,6 +532,9 @@ module effects { int api_effects_unit_bonus @ unit_bonus(lua_State *L, Unit *punit, Player *other_player, const char *effect_type); + int api_effects_unit_vs_tile_bonus + @ unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile, + const char *effect_type); } /* Direction module */ -- 2.20.1