From baa83b724be60004015d7e17eb045d3bd343b3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Tue, 20 Jun 2023 17:23:44 +0200 Subject: [PATCH] =?UTF-8?q?!OSDN:#47827:S=C5=82awomir=20Lach=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement basic lua api for counters. diff --git a/common/scriptcore/api_game_find.c b/common/scriptcore/api_game_find.c index b0ef7aa2ec..d24295c54d 100644 --- a/common/scriptcore/api_game_find.c +++ b/common/scriptcore/api_game_find.c @@ -16,6 +16,7 @@ #endif /* common */ +#include "counters.h" #include "idex.h" #include "map.h" #include "movement.h" @@ -369,6 +370,27 @@ Action *api_find_action_type_by_name(lua_State *L, const char *name) return action_by_rule_name(name); } +/**********************************************************************//** + Returns the counter specified by id. +**************************************************************************/ +Counter *api_find_counter(lua_State *L, int counter_id) +{ + LUASCRIPT_CHECK_STATE(L, NULL); + + return counter_by_id(counter_id); +} + +/**********************************************************************//** + Returns the counter specified by name. +**************************************************************************/ +Counter *api_find_counter_by_name(lua_State *L, const char *name) +{ + LUASCRIPT_CHECK_STATE(L, NULL); + LUASCRIPT_CHECK_ARG_NIL(L, name, 2, string, NULL); + + return counter_by_rule_name(name); +} + /**********************************************************************//** Return a dummy pointer. **************************************************************************/ diff --git a/common/scriptcore/api_game_find.h b/common/scriptcore/api_game_find.h index 8594adcde6..921586de5b 100644 --- a/common/scriptcore/api_game_find.h +++ b/common/scriptcore/api_game_find.h @@ -30,6 +30,9 @@ Player *api_find_player(lua_State *L, int player_id); City *api_find_city(lua_State *L, Player *pplayer, int city_id); +Counter *api_find_counter_by_name(lua_State *L, const char *name); +Counter *api_find_counter(lua_State *L, int counter_id); + Unit *api_find_unit(lua_State *L, Player *pplayer, int unit_id); Unit *api_find_transport_unit(lua_State *L, Player *pplayer, Unit_Type *ptype, Tile *ptile); diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c index 183b43d3d9..a12a77c5e4 100644 --- a/common/scriptcore/api_game_methods.c +++ b/common/scriptcore/api_game_methods.c @@ -290,6 +290,27 @@ int api_methods_city_culture_get(lua_State *L, City *pcity) return city_culture(pcity); } +/**********************************************************************//** +Returns rule name of the counter. +**************************************************************************/ +const char *api_methods_counter_rule_name(lua_State *L, Counter *c) +{ + LUASCRIPT_CHECK_ARG_NIL(L, c, 2, Counter, NULL); + + return counter_rule_name(c); +} + +/**********************************************************************//** +Returns translation name of the counter. +**************************************************************************/ +const char *api_methods_counter_name_translation(lua_State *L, Counter *c) +{ + LUASCRIPT_CHECK_ARG_NIL(L, c, 2, Counter, NULL); + + return counter_name_translation(c); +} + + /**********************************************************************//** Return TRUE iff city happy **************************************************************************/ diff --git a/common/scriptcore/api_game_methods.h b/common/scriptcore/api_game_methods.h index 6fcdb388db..a5d133cc89 100644 --- a/common/scriptcore/api_game_methods.h +++ b/common/scriptcore/api_game_methods.h @@ -63,6 +63,10 @@ bool api_methods_is_gov_center(lua_State *L, City *pcity); bool api_methods_is_capital(lua_State *L, City *pcity); bool api_methods_is_primary_capital(lua_State *L, City *pcity); +/* Counter */ +const char *api_methods_counter_rule_name(lua_State *L, Counter *c); +const char *api_methods_counter_name_translation(lua_State *L, Counter *c); + /* Government */ const char *api_methods_government_rule_name(lua_State *L, Government *pgovernment); diff --git a/common/scriptcore/luascript_types.h b/common/scriptcore/luascript_types.h index a87aecfbee..ede832e145 100644 --- a/common/scriptcore/luascript_types.h +++ b/common/scriptcore/luascript_types.h @@ -23,6 +23,7 @@ extern "C" { /* common */ #include "achievements.h" #include "actions.h" +#include "counters.h" #include "city.h" #include "connection.h" #include "events.h" @@ -44,6 +45,7 @@ extern "C" { * tolua_common_z.pkg. */ typedef struct player Player; typedef struct player_ai Player_ai; +typedef struct counter Counter; typedef struct city City; typedef struct unit Unit; typedef struct tile Tile; diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index a5e23ad87e..cc180a903f 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -47,6 +47,10 @@ struct City { const int id; }; +struct Counter +{ +}; + struct Connection { const int id; }; @@ -164,6 +168,11 @@ module game { @ ruleset_name (lua_State *L); } +module Counter { + const char *api_methods_counter_rule_name @ rule_name (lua_State *L, Counter *c); + const char *api_methods_counter_name_translation @ name_translation (lua_State *L, Counter *c); +} + /* Module Player. */ module Player { module properties { @@ -528,6 +537,10 @@ module City_List_Link { /* Module find. */ module find { + Counter *api_find_counter_by_name + @ counter (lua_State *L, const char *name); + Counter *api_find_counter + @ counter (lua_State *L, int counter_id); Player *api_find_player_by_name @ player (lua_State *L, const char *name); Player *api_find_player -- 2.42.0