From fbfad3c0534a054d9ed460c1da600922e7b0be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Wed, 9 Feb 2022 18:03:52 +0100 Subject: [PATCH] - Introduce city's counter iterration - Increase counter "Owned" value of each city Increase counter "Owned" value at end of each turn (for each city) - Repair bugs reported by cazfi --- common/counters.h | 11 +++++++++++ server/citytools.c | 10 ++++++++++ server/srv_main.c | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/common/counters.h b/common/counters.h index ec7c1a3683..865337dc47 100644 --- a/common/counters.h +++ b/common/counters.h @@ -48,6 +48,17 @@ 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; \ + int _ccounter_count = counters_get_city_counters_count(); \ + for (_i_##pcount = 0; _i_##pcount < _ccounter_count; _i_##pcount++) { \ + pcount = counter_by_index(_i_##pcount, CTGT_CITY); + +#define city_counters_iterate_end } \ + } + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/server/citytools.c b/server/citytools.c index 89a7e4d639..149e398c74 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -33,6 +33,7 @@ #include "base.h" #include "citizens.h" #include "city.h" +#include "counters.h" #include "culture.h" #include "events.h" #include "game.h" @@ -1215,6 +1216,15 @@ bool transfer_city(struct player *ptaker, struct city *pcity, city_remains = FALSE; } + /* Reset turns owner counters */ + if (city_remains) { + city_counters_iterate(pcount) { + if (pcount->type == COUNTER_OWNED) { + pcity->counter_values[pcount->index] = 0; + } + } city_counters_iterate_end; + } + if (city_remains) { /* Update the city's trade routes. */ reestablish_city_trade_routes(pcity); diff --git a/server/srv_main.c b/server/srv_main.c index 16e0f177c4..cb7d09adfa 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -67,6 +67,7 @@ #include "calendar.h" #include "capstr.h" #include "city.h" +#include "counters.h" #include "culture.h" #include "dataio.h" #include "effects.h" @@ -1485,6 +1486,16 @@ static void end_turn(void) map_calculate_borders(); + /* Update city's counter values */ + players_iterate(pplayer) { + city_list_iterate(pplayer->cities, pcity) { + city_counters_iterate(pcount) { + if (pcount->type == COUNTER_OWNED) { + pcity->counter_values[pcount->index]++; + } + } city_counters_iterate_end; + } city_list_iterate_end; + } players_iterate_end; /* Output some AI measurement information */ players_iterate(pplayer) { if (!is_ai(pplayer) || is_barbarian(pplayer)) { -- 2.35.1