From ca7feb9324dffc1d57f48ded96d73abcc73d2f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Sun, 17 Apr 2022 10:34:09 +0200 Subject: [PATCH 1/3] =?UTF-8?q?OSDN!41121=20S=C5=82awomir=20Lach=20=20-=20Type=20system=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change enum related C-code types into freeciv specenum --- common/counters.c | 29 ++++++++++++++++------------- common/counters.h | 26 ++++++++++++++++++-------- server/citytools.c | 2 +- server/srv_main.c | 2 +- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/common/counters.c b/common/counters.c index 728a113d23..ade1ddc755 100644 --- a/common/counters.c +++ b/common/counters.c @@ -25,7 +25,7 @@ static struct counter counters[MAX_COUNTERS] = { - { (struct name_translation) NAME_INIT, COUNTER_OWNED, CTGT_CITY, 5, 0 } + { (struct name_translation) NAME_INIT, CB_CITY_OWNED_TURNS, CTGT_CITY, 5, 0 } }; static struct counter *counters_city[MAX_COUNTERS]; @@ -36,24 +36,25 @@ static int number_city_counters; ****************************************************************************/ void counters_init(void) { - int i; + int i; - number_city_counters = 0; + number_city_counters = 0; - name_set(&counters[0].name, NULL, N_("?counter:Owned")); + name_set(&counters[0].name, NULL, N_("?counter:Owned")); - for (i = 0; i < MAX_COUNTERS; i++) { + for (i = 0; i < MAX_COUNTERS; i++) { - if (counters[i].type == COUNTER_OWNED) { - /* City counter type */ - counters_city[number_city_counters] = &counters[i]; - counters[i].index = number_city_counters; - counters[i].target = CTGT_CITY; - number_city_counters++; - } - } + if (counters[i].type == CB_CITY_OWNED_TURNS) { + /* City counter type */ + counters_city[number_city_counters] = &counters[i]; + counters[i].index = number_city_counters; + counters[i].target = CTGT_CITY; + number_city_counters++; + } + } } + /************************************************************************//** Free resources allocated by counters system ****************************************************************************/ @@ -167,6 +168,8 @@ struct counter *counter_by_index(int index, enum counter_target target) { case CTGT_CITY: return counters_city[index]; + case CTGT_LAST: + break; } return NULL; diff --git a/common/counters.h b/common/counters.h index f29924a585..b5271888ca 100644 --- a/common/counters.h +++ b/common/counters.h @@ -20,17 +20,28 @@ extern "C" { /* common */ #include "name_translation.h" -enum counter_type { COUNTER_OWNED = 0, COUNTER_COUNT }; - -enum counter_target { CTGT_CITY }; - -/* Space for one counter of each type */ -#define MAX_COUNTERS COUNTER_COUNT +#define SPECENUM_NAME counter_behaviour +/* Not performing any activity right now */ +#define SPECENUM_VALUE0 CB_CITY_OWNED_TURNS +#define SPECENUM_VALUE0NAME "Owned" +/* Number of activities */ +#define SPECENUM_COUNT COUNTER_BEHAVIOUR_LAST +#include "specenum_gen.h" + +#define SPECENUM_NAME counter_target +/* Not performing any activity right now */ +#define SPECENUM_VALUE0 CTGT_CITY +#define SPECENUM_VALUE0NAME "City" +/* Number of activities */ +#define SPECENUM_COUNT CTGT_LAST +#include "specenum_gen.h" + +#define MAX_COUNTERS 20 struct counter { struct name_translation name; - enum counter_type type; + enum counter_behaviour type; enum counter_target target; int checkpoint; int def; /* default value for each entity of given type @@ -55,7 +66,6 @@ int counter_index(struct counter *pcount); struct counter *counter_by_index(int index, enum counter_target target); int counters_get_city_counters_count(void); - #define city_counters_iterate(pcount) { \ int _i_##pcount; \ struct counter *pcount; \ diff --git a/server/citytools.c b/server/citytools.c index ada6227b22..3349f4f250 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1219,7 +1219,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, /* Reset turns owner counters */ if (city_remains) { city_counters_iterate(pcount) { - if (pcount->type == COUNTER_OWNED) { + if (pcount->type == CB_CITY_OWNED_TURNS) { pcity->counter_values[pcount->index] = 0; } } city_counters_iterate_end; diff --git a/server/srv_main.c b/server/srv_main.c index c3fdb1df32..95fb900f99 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1520,7 +1520,7 @@ static void end_turn(void) players_iterate(pplayer) { city_list_iterate(pplayer->cities, pcity) { city_counters_iterate(pcount) { - if (pcount->type == COUNTER_OWNED) { + if (pcount->type == CB_CITY_OWNED_TURNS) { pcity->counter_values[pcount->index]++; } } city_counters_iterate_end; -- 2.35.1