From 4ca9898163ab1203155a75f01871d92693bace64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Sun, 14 Nov 2021 16:10:26 +0100 Subject: [PATCH] - Added intial counters savegame-related functions Added functions to save counters (savegame-related) and save counter information. --- server/savegame/savegame3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index aca6c1ee1b..b7dfaa2809 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -90,6 +90,7 @@ #include "capability.h" #include "citizens.h" #include "city.h" +#include "counters.h" #include "game.h" #include "government.h" #include "map.h" @@ -336,6 +337,8 @@ 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_save_counters (struct savedata * saving); + static void sg_load_map(struct loaddata *loading); static void sg_save_map(struct savedata *saving); static void sg_load_map_tiles(struct loaddata *loading); @@ -523,6 +526,8 @@ static void savegame3_save_real(struct section_file *file, sg_save_scenario(saving); /* [savefile] */ sg_save_savefile(saving); + /* [counters] */ + sg_save_counters(saving); /* [game] */ sg_save_game(saving); /* [random] */ @@ -2568,6 +2573,34 @@ static void sg_save_settings(struct savedata *saving) /* Add all compatibility settings here. */ } +/************************************************************************//** +Save [counters]. +****************************************************************************/ +static void sg_save_counters(struct savedata *saving) +{ + /* Check status and return if not OK (sg_success != TRUE). */ + sg_check_ret(); + + int *countoffset;; + int j, count; + + count = counters_get_city_counters_count(); + countoffset = fc_calloc(count, sizeof(*countoffset)); + + + secfile_insert_int(saving->file, count, + "savefile.city_counters_order_size"); + + for (j = 0; j < count; j++) { + countoffset[j] = counter_id(counter_by_index(j, CTGT_CITY)); + } + + secfile_insert_int_vec(saving->file, countoffset, + count, + "savefile.city_counters_order_vector"); + free(countoffset); +} + /* ======================================================================= * Load / save the main map. * ======================================================================= */ -- 2.34.0