From 655d594bc3acd231d72eb5b425a7e0f07bb65e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Fri, 7 Jan 2022 13:20:47 +0100 Subject: [PATCH] - Added city counter load routines Loading city counter routine --- server/savegame/savegame3.c | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 6678113954..3d91053bfb 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -337,6 +337,7 @@ static void sg_save_scenario(struct savedata *saving); static void sg_load_settings(struct loaddata *loading); static void sg_save_settings(struct savedata *saving); +static void sg_load_counters (struct loaddata * loading); static void sg_save_counters (struct savedata * saving); static void sg_load_map(struct loaddata *loading); @@ -477,6 +478,8 @@ void savegame3_load(struct section_file *file) sg_load_researches(loading); /* [player] */ sg_load_players(loading); + /* [counters] */ + sg_load_counters(loading); /* [event_cache] */ sg_load_event_cache(loading); /* [treaties] */ @@ -2573,6 +2576,44 @@ static void sg_save_settings(struct savedata *saving) /* Add all compatibility settings here. */ } + +/************************************************************************//** +Load '[counters]'. +****************************************************************************/ + +static void sg_load_counters (struct loaddata * loading) +{ + struct city *pcity; + int i, j; + size_t length; + int *city_count; + int city_ccount = secfile_lookup_int_default(loading->file, 0, + "savefile.city_counters_order_size"); + + i = 0; + while (NULL != (city_count = + secfile_lookup_int_vec(loading->file, &length, + "counters.c%d", i))) { + + if (length -1 != (size_t) city_ccount) { + + log_error("Bad city counters vector size. Should be %d. Is %ld.", city_ccount, length - 1); + break; + } + + pcity = game_city_by_number(city_count[0]); + pcity->counter_values = fc_calloc(city_ccount, sizeof(*pcity->counter_values)); + + for (j = 0; j < city_ccount; ++j) { + + pcity->counter_values[j] = city_count[j+1]; + } + + free(city_count); + ++i; + } +} + /************************************************************************//** Save [counters]. ****************************************************************************/ -- 2.34.1