From 631b7014581b0d0aef01c2dc27e8ad85ac13f191 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 27 May 2023 06:25:49 +0300 Subject: [PATCH 24/24] Track how city was last acquired For now it's either founded by current owner, or conquered somehow. See osdn #47366 Signed-off-by: Marko Lindqvist --- common/city.c | 1 + common/city.h | 5 ++-- common/fc_types.h | 8 ++++++ server/citytools.c | 1 + server/savegame/savecompat.c | 48 ++++++++++++++++++++++++++++++++++++ server/savegame/savegame2.c | 17 +++++++++---- server/savegame/savegame3.c | 8 +++++- 7 files changed, 80 insertions(+), 8 deletions(-) diff --git a/common/city.c b/common/city.c index 0de4bd8476..12f22e48d2 100644 --- a/common/city.c +++ b/common/city.c @@ -3342,6 +3342,7 @@ struct city *create_city_virtual(struct player *pplayer, pcity->tile = ptile; fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned cities! */ pcity->owner = pplayer; + pcity->acquire_t = CACQ_FOUNDED; if (is_server()) { pcity->original = pplayer; diff --git a/common/city.h b/common/city.h index 3be4ce4eca..91ddfa047c 100644 --- a/common/city.h +++ b/common/city.h @@ -312,8 +312,9 @@ struct city { int id; int style; enum capital_type capital; + enum city_acquire_type acquire_t; - /* the people */ + /* The people */ citizens size; citizens feel[CITIZEN_LAST][FEELING_LAST]; @@ -325,7 +326,7 @@ struct city { citizens *nationality; /* Nationality of the citizens. */ - /* trade routes */ + /* Trade routes */ struct trade_route_list *routes; /* Tile output, regardless of if the tile is actually worked. It is used diff --git a/common/fc_types.h b/common/fc_types.h index cd00b1bcd7..34332e10a4 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -1366,6 +1366,14 @@ typedef float adv_want; #define SPECENUM_VALUE2NAME "Always" #include "specenum_gen.h" +/* Used in the savegames, by numeric value. */ +#define SPECENUM_NAME city_acquire_type +#define SPECENUM_VALUE0 CACQ_CONQUEST +#define SPECENUM_VALUE0NAME "Conquest" +#define SPECENUM_VALUE1 CACQ_FOUNDED +#define SPECENUM_VALUE1NAME "Founded" +#include "specenum_gen.h" + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/server/citytools.c b/server/citytools.c index 523f5c3251..eb0ad68a1f 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1188,6 +1188,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, pcity->owner = ptaker; pcity->capital = CAPITAL_NOT; + pcity->acquire_t = CACQ_CONQUEST; map_claim_ownership(pcenter, ptaker, pcenter, TRUE); city_list_prepend(ptaker->cities, pcity); diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 182923e2b0..445f407629 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -2342,6 +2342,20 @@ static void compat_load_030200(struct loaddata *loading, plrno, cnro); wlist_max_length = MAX(wlist_max_length, wl_length); + + if (format_class == SAVEGAME_3) { + if (secfile_lookup_int_default(loading->file, plrno, + "player%d.c%d.original", + plrno, cnro) != plrno) { + secfile_insert_int(loading->file, CACQ_CONQUEST, + "player%d.c%d.acquire_t", + plrno, cnro); + } else { + secfile_insert_int(loading->file, CACQ_FOUNDED, + "player%d.c%d.acquire_t", + plrno, cnro); + } + } } secfile_insert_int(loading->file, wlist_max_length, @@ -2933,6 +2947,40 @@ static void compat_load_dev(struct loaddata *loading) } } + /* Add acquire_t entries for cities */ + { + player_slots_iterate(pslot) { + int plrno = player_slot_index(pslot); + int ncities; + int cnro; + + if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) { + continue; + } + + ncities = secfile_lookup_int_default(loading->file, 0, + "player%d.ncities", plrno); + + for (cnro = 0; cnro < ncities; cnro++) { + if (secfile_entry_lookup(loading->file, + "player%d.c%d.acquire_t", + plrno, cnro) == NULL) { + if (secfile_lookup_int_default(loading->file, plrno, + "player%d.c%d.original", + plrno, cnro) != plrno) { + secfile_insert_int(loading->file, CACQ_CONQUEST, + "player%d.c%d.acquire_t", + plrno, cnro); + } else { + secfile_insert_int(loading->file, CACQ_FOUNDED, + "player%d.c%d.acquire_t", + plrno, cnro); + } + } + } + } player_slots_iterate_end; + } + /* Add orders_max_length entries for players */ { player_slots_iterate(pslot) { diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index 05152bbdf9..f48de70463 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -3509,9 +3509,16 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, pcity->original = past; } + /* savegame2 saves never had this information. Guess. */ + if (pcity->original != plr) { + pcity->acquire_t = CACQ_CONQUEST; + } else { + pcity->acquire_t = CACQ_FOUNDED; + } + sg_warn_ret_val(secfile_lookup_int(loading->file, &value, "%s.size", citystr), FALSE, "%s", secfile_error()); - size = (citizens)value; /* set the correct type */ + size = (citizens)value; /* Set the correct type */ sg_warn_ret_val(value == (int)size, FALSE, "Invalid city size: %d, set to %d", value, size); city_size_set(pcity, size); @@ -3568,7 +3575,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, pcity->steal = secfile_lookup_int_default(loading->file, 0, "%s.steal", citystr); - /* before did_buy for undocumented hack */ + /* Before did_buy for undocumented hack */ pcity->turn_founded = secfile_lookup_int_default(loading->file, -2, "%s.turn_founded", citystr); @@ -3576,12 +3583,12 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, citystr), FALSE, "%s", secfile_error()); pcity->did_buy = (i != 0); if (i == -1 && pcity->turn_founded == -2) { - /* undocumented hack */ + /* Undocumented hack */ pcity->turn_founded = game.info.turn; } - pcity->did_sell = - secfile_lookup_bool_default(loading->file, FALSE, "%s.did_sell", citystr); + pcity->did_sell + = secfile_lookup_bool_default(loading->file, FALSE, "%s.did_sell", citystr); sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->turn_last_built, "%s.turn_last_built", citystr), diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 502889dd69..d22facc8b7 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -4970,6 +4970,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, const char *stylename; int partner; int want; + int acq_t_tmp; sg_warn_ret_val(secfile_lookup_int(loading->file, &nat_x, "%s.x", citystr), FALSE, "%s", secfile_error()); @@ -5079,6 +5080,10 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->turn_founded, "%s.turn_founded", citystr), FALSE, "%s", secfile_error()); + sg_warn_ret_val(secfile_lookup_int(loading->file, &acq_t_tmp, + "%s.acquire_t", citystr), + FALSE, "%s", secfile_error()); + pcity->acquire_t = acq_t_tmp; sg_warn_ret_val(secfile_lookup_bool(loading->file, &pcity->did_buy, "%s.did_buy", citystr), FALSE, "%s", secfile_error()); sg_warn_ret_val(secfile_lookup_bool(loading->file, &pcity->did_sell, "%s.did_sell", @@ -5572,12 +5577,13 @@ static void sg_save_player_cities(struct savedata *saving, secfile_insert_int(saving->file, pcity->steal, "%s.steal", buf); secfile_insert_int(saving->file, pcity->turn_founded, "%s.turn_founded", buf); + secfile_insert_int(saving->file, pcity->acquire_t, "%s.acquire_t", buf); secfile_insert_bool(saving->file, pcity->did_buy, "%s.did_buy", buf); secfile_insert_bool(saving->file, pcity->did_sell, "%s.did_sell", buf); secfile_insert_int(saving->file, pcity->turn_last_built, "%s.turn_last_built", buf); - /* for visual debugging, variable length strings together here */ + /* For visual debugging, variable length strings together here */ secfile_insert_str(saving->file, city_name_get(pcity), "%s.name", buf); secfile_insert_str(saving->file, universal_type_rule_name(&pcity->production), -- 2.39.2