From 37905e693f4d99144290984c06b85f5f802995e4 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 12 Mar 2021 13:59:36 +0100 Subject: [PATCH 09/13] Lua API: introduce effects.unit_bonus() See osdn #41746 --- common/scriptcore/api_game_effects.c | 29 ++++++++++++++++++++++++++++ common/scriptcore/api_game_effects.h | 2 ++ common/scriptcore/tolua_game.pkg | 3 +++ 3 files changed, 34 insertions(+) diff --git a/common/scriptcore/api_game_effects.c b/common/scriptcore/api_game_effects.c index ce08b19b4e..ae608aa57c 100644 --- a/common/scriptcore/api_game_effects.c +++ b/common/scriptcore/api_game_effects.c @@ -76,3 +76,32 @@ int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type) } return get_city_bonus(pcity, etype); } + +/**********************************************************************//** + Returns the effect bonus at a unit. + Can take other_player to support local DiplRel requirements. +**************************************************************************/ +int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, + 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, effect_type, 4, string, 0); + + etype = effect_type_by_name(effect_type, fc_strcasecmp); + if (!effect_type_is_valid(etype)) { + return 0; + } + + return get_target_bonus_effects(NULL, + unit_owner(punit), + other_player, + unit_tile(punit) + ? tile_city(unit_tile(punit)) : NULL, + NULL, unit_tile(punit), + punit, unit_type_get(punit), NULL, NULL, + NULL, + etype); +} diff --git a/common/scriptcore/api_game_effects.h b/common/scriptcore/api_game_effects.h index 6cf797a9cf..8cb84e5ed4 100644 --- a/common/scriptcore/api_game_effects.h +++ b/common/scriptcore/api_game_effects.h @@ -28,6 +28,8 @@ int api_effects_player_bonus(lua_State *L, Player *pplayer, const char *effect_type); 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); #ifdef __cplusplus } diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index 28e2b6b5ab..20807d16a5 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -529,6 +529,9 @@ module effects { @ player_bonus (lua_State *L, Player *pplayer, const char *effect_type); int api_effects_city_bonus @ city_bonus (lua_State *L, City *pcity, const char *effect_type); + int api_effects_unit_bonus + @ unit_bonus(lua_State *L, Unit *punit, Player *other_player, + const char *effect_type); } /* Direction module */ -- 2.20.1