From 4bdb6ffd4fb79bc713859f303cb18f1b93a1683a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 12 Nov 2022 23:17:36 +0200 Subject: [PATCH 20/20] Savegame loading: Detect workers outside current city radius See osdn #45343 Signed-off-by: Marko Lindqvist --- server/savegame/savegame2.c | 18 +++++++++++++----- server/savegame/savegame3.c | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index 9ab453b4f6..2073e1aad3 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -3634,10 +3634,18 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, citystr); city_map_radius_sq_set(pcity, radius_sq); - city_tile_iterate(radius_sq, city_tile(pcity), ptile) { + city_tile_iterate(CITY_MAP_MAX_RADIUS_SQ, city_tile(pcity), ptile) { if (loading->worked_tiles[ptile->index] == pcity->id) { - tile_set_worked(ptile, pcity); - workers++; + if (sq_map_distance(ptile, pcity->tile) > radius_sq) { + log_sg("[%s] '%s' (%d, %d) has worker outside current radius " + "at (%d, %d); repairing", citystr, city_name_get(pcity), + TILE_XY(pcity->tile), TILE_XY(ptile)); + pcity->specialists[DEFAULT_SPECIALIST]++; + sp_count++; + } else { + tile_set_worked(ptile, pcity); + workers++; + } #ifdef FREECIV_DEBUG /* set this tile to unused; a check for not resetted tiles is @@ -3652,7 +3660,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, if (NULL != pwork) { log_sg("[%s] city center of '%s' (%d,%d) [%d] is worked by '%s' " - "(%d,%d) [%d]; repairing ", citystr, city_name_get(pcity), + "(%d,%d) [%d]; repairing", citystr, city_name_get(pcity), TILE_XY(city_tile(pcity)), city_size_get(pcity), city_name_get(pwork), TILE_XY(city_tile(pwork)), city_size_get(pwork)); @@ -3660,7 +3668,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, pwork->specialists[DEFAULT_SPECIALIST]++; auto_arrange_workers(pwork); } else { - log_sg("[%s] city center of '%s' (%d,%d) [%d] is empty; repairing ", + log_sg("[%s] city center of '%s' (%d,%d) [%d] is empty; repairing", citystr, city_name_get(pcity), TILE_XY(city_tile(pcity)), city_size_get(pcity)); } diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index fd25b0d19e..277987ca68 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -5137,10 +5137,18 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, citystr); city_map_radius_sq_set(pcity, radius_sq); - city_tile_iterate(radius_sq, city_tile(pcity), ptile) { + city_tile_iterate(CITY_MAP_MAX_RADIUS_SQ, city_tile(pcity), ptile) { if (loading->worked_tiles[ptile->index] == pcity->id) { - tile_set_worked(ptile, pcity); - workers++; + if (sq_map_distance(ptile, pcity->tile) > radius_sq) { + log_sg("[%s] '%s' (%d, %d) has worker outside current radius " + "at (%d, %d); repairing", citystr, city_name_get(pcity), + TILE_XY(pcity->tile), TILE_XY(ptile)); + pcity->specialists[DEFAULT_SPECIALIST]++; + sp_count++; + } else { + tile_set_worked(ptile, pcity); + workers++; + } #ifdef FREECIV_DEBUG /* set this tile to unused; a check for not resetted tiles is @@ -5155,7 +5163,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, if (NULL != pwork) { log_sg("[%s] city center of '%s' (%d,%d) [%d] is worked by '%s' " - "(%d,%d) [%d]; repairing ", citystr, city_name_get(pcity), + "(%d,%d) [%d]; repairing", citystr, city_name_get(pcity), TILE_XY(city_tile(pcity)), city_size_get(pcity), city_name_get(pwork), TILE_XY(city_tile(pwork)), city_size_get(pwork)); @@ -5163,7 +5171,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, pwork->specialists[DEFAULT_SPECIALIST]++; auto_arrange_workers(pwork); } else { - log_sg("[%s] city center of '%s' (%d,%d) [%d] is empty; repairing ", + log_sg("[%s] city center of '%s' (%d,%d) [%d] is empty; repairing", citystr, city_name_get(pcity), TILE_XY(city_tile(pcity)), city_size_get(pcity)); } -- 2.35.1