From 7f3b5a9127095d2b7c2db5dc62cc74cf11595172 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 15 Oct 2023 18:51:14 +0300 Subject: [PATCH 29/35] Store unit's transformation turn See osdn #48847 Signed-off-by: Marko Lindqvist --- common/unit.c | 1 + common/unit.h | 1 + server/savegame/savegame2.c | 1 + server/savegame/savegame3.c | 5 +++++ server/unittools.c | 2 ++ 5 files changed, 10 insertions(+) diff --git a/common/unit.c b/common/unit.c index 9c4eb22afb..a08f2a13db 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1712,6 +1712,7 @@ struct unit *unit_virtual_create(struct player *pplayer, struct city *pcity, if (is_server()) { punit->server.debug = FALSE; punit->server.birth_turn = game.info.turn; + punit->server.current_form_turn = game.info.turn; punit->server.dying = FALSE; diff --git a/common/unit.h b/common/unit.h index 16f0c29db0..b71a841dec 100644 --- a/common/unit.h +++ b/common/unit.h @@ -233,6 +233,7 @@ struct unit { struct unit_adv *adv; void *ais[FREECIV_AI_MOD_LAST]; int birth_turn; + int current_form_turn; /* ord_map and ord_city are the order index of this unit in tile.units * and city.units_supported; they are only used for save/reload */ diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index 6978e89920..55c60ae9e4 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -4271,6 +4271,7 @@ static bool sg_load_player_unit(struct loaddata *loading, punit->server.birth_turn = secfile_lookup_int_default(loading->file, game.info.turn, "%s.born", unitstr); + punit->server.current_form_turn = game.info.turn; extra_id = secfile_lookup_int_default(loading->file, -2, "%s.activity_tgt", unitstr); diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index c436dfc49f..8e4f51a54a 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -6104,6 +6104,9 @@ static bool sg_load_player_unit(struct loaddata *loading, punit->server.birth_turn = secfile_lookup_int_default(loading->file, game.info.turn, "%s.born", unitstr); + punit->server.current_form_turn + = secfile_lookup_int_default(loading->file, game.info.turn, + "%s.current_form_turn", unitstr); extra_id = secfile_lookup_int_default(loading->file, -2, "%s.activity_tgt", unitstr); @@ -6643,6 +6646,8 @@ static void sg_save_player_units(struct savedata *saving, secfile_insert_int(saving->file, punit->fuel, "%s.fuel", buf); secfile_insert_int(saving->file, punit->server.birth_turn, "%s.born", buf); + secfile_insert_int(saving->file, punit->server.current_form_turn, + "%s.current_form_turn", buf); secfile_insert_int(saving->file, punit->battlegroup, "%s.battlegroup", buf); diff --git a/server/unittools.c b/server/unittools.c index 57e2b9feb8..876b055572 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1602,6 +1602,8 @@ void transform_unit(struct unit *punit, const struct unit_type *to_unit, punit->moves_left = punit->moves_left * unit_move_rate(punit) / old_mr; } + punit->server.current_form_turn = game.info.turn; + unit_forget_last_activity(punit); if (!can_unit_continue_current_activity(punit)) { unit_activities_cancel(punit); -- 2.42.0