From 5ba30325fb5429fa1c0d1cee987764949223b7d7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 7 Feb 2024 08:02:27 +0200 Subject: [PATCH 38/38] Support client side unit age requirements See osdn #48928 Signed-off-by: Marko Lindqvist --- ai/default/daiunit.c | 12 ++++++------ client/packhand.c | 2 ++ common/networking/packets.def | 2 ++ common/requirements.c | 8 ++++---- common/unit.c | 5 +++-- common/unit.h | 5 +++-- server/savegame/savegame2.c | 4 ++-- server/savegame/savegame3.c | 8 ++++---- server/unittools.c | 6 ++++-- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c index c3a701b165..89d58a8a75 100644 --- a/ai/default/daiunit.c +++ b/ai/default/daiunit.c @@ -2144,19 +2144,19 @@ static bool dai_is_unit_tired_waiting_boat(struct ai_type *ait, if (!goto_is_sane(punit, dest)) { if (unit_transported(punit)) { - /* if we're being transported */ + /* If we're being transported */ return FALSE; } - if ((punit->server.birth_turn + 15 < game.info.turn)) { - /* we are tired of waiting */ + if ((punit->birth_turn + 15 < game.info.turn)) { + /* We are tired of waiting */ int ferrys = aiferry_avail_boats(ait, punit->owner); if (ferrys <= 0) { - /* there are no ferrys available... give up */ + /* There are no ferrys available... give up */ return TRUE; } else { - if (punit->server.birth_turn + 20 < game.info.turn) { - /* we are feed up! */ + if (punit->birth_turn + 20 < game.info.turn) { + /* We are fed up! */ return TRUE; } } diff --git a/client/packhand.c b/client/packhand.c index 9551affba0..7971728f75 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -304,6 +304,8 @@ static struct unit *unpackage_unit(const struct packet_unit_info *packet) punit->paradropped = packet->paradropped; punit->done_moving = packet->done_moving; punit->stay = packet->stay; + punit->birth_turn = packet->birth_turn; + punit->current_form_turn = packet->current_form_turn; /* Transporter / transporting information. */ punit->client.occupied = packet->occupied; diff --git a/common/networking/packets.def b/common/networking/packets.def index ab55d78dce..80de518f07 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1067,6 +1067,8 @@ PACKET_UNIT_INFO = 63; sc, lsend, is-game-info, cancel(PACKET_UNIT_SHORT_INFO) BOOL paradropped; BOOL occupied, transported, done_moving; BOOL stay; + TURN birth_turn; + TURN current_form_turn; UNIT_TYPE type; UNIT transported_by; /* Only valid if transported is set. */ diff --git a/common/requirements.c b/common/requirements.c index 48a46ae697..ce8d528d52 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -4372,7 +4372,7 @@ is_age_req_active(const struct civ_map *nmap, } else { return BOOL_TO_TRISTATE( req->source.value.age <= - game.info.turn - context->unit->server.birth_turn); + game.info.turn - context->unit->birth_turn); } break; case REQ_RANGE_CITY: @@ -4420,7 +4420,7 @@ is_form_age_req_active(const struct civ_map *nmap, } else { return BOOL_TO_TRISTATE( req->source.value.form_age <= - game.info.turn - context->unit->server.current_form_turn); + game.info.turn - context->unit->current_form_turn); } break; default: @@ -5639,7 +5639,7 @@ tri_req_active_turns(int pass, int period, if (context->unit == NULL || !is_server()) { return TRI_MAYBE; } else { - int ua = game.info.turn + pass - context->unit->server.birth_turn; + int ua = game.info.turn + pass - context->unit->birth_turn; present = req->source.value.age <= ua; present1 = req->source.value.age <= ua + period; @@ -5673,7 +5673,7 @@ tri_req_active_turns(int pass, int period, if (context->unit == NULL || !is_server()) { return TRI_MAYBE; } else { - int ua = game.info.turn + pass - context->unit->server.current_form_turn; + int ua = game.info.turn + pass - context->unit->current_form_turn; present = req->source.value.form_age <= ua; present1 = req->source.value.form_age <= ua + period; diff --git a/common/unit.c b/common/unit.c index 54e213b071..4b48098c8a 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1715,10 +1715,11 @@ struct unit *unit_virtual_create(struct player *pplayer, struct city *pcity, punit->stay = FALSE; + punit->birth_turn = game.info.turn; + punit->current_form_turn = game.info.turn; + 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 24726c166c..0bde79cb81 100644 --- a/common/unit.h +++ b/common/unit.h @@ -207,6 +207,9 @@ struct unit { bool stay; /* Unit is prohibited from moving */ + int birth_turn; + int current_form_turn; + union { struct { /* Only used at the client (the server is omniscient; ./client/). */ @@ -235,8 +238,6 @@ 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 edf7a4f248..98e02bfb2c 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -4271,10 +4271,10 @@ static bool sg_load_player_unit(struct loaddata *loading, activity = unit_activity_by_name(loading->activities.order[ei], fc_strcasecmp); - punit->server.birth_turn + punit->birth_turn = secfile_lookup_int_default(loading->file, game.info.turn, "%s.born", unitstr); - punit->server.current_form_turn = game.info.turn; + punit->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 d00c93e728..ff6dd54a76 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -6194,10 +6194,10 @@ static bool sg_load_player_unit(struct loaddata *loading, "%s", secfile_error()); action = loading->action.order[ei]; - punit->server.birth_turn + punit->birth_turn = secfile_lookup_int_default(loading->file, game.info.turn, "%s.born", unitstr); - punit->server.current_form_turn + punit->current_form_turn = secfile_lookup_int_default(loading->file, game.info.turn, "%s.current_form_turn", unitstr); @@ -6739,9 +6739,9 @@ static void sg_save_player_units(struct savedata *saving, "%s.done_moving", buf); secfile_insert_int(saving->file, punit->moves_left, "%s.moves", buf); secfile_insert_int(saving->file, punit->fuel, "%s.fuel", buf); - secfile_insert_int(saving->file, punit->server.birth_turn, + secfile_insert_int(saving->file, punit->birth_turn, "%s.born", buf); - secfile_insert_int(saving->file, punit->server.current_form_turn, + secfile_insert_int(saving->file, punit->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 ca0ca2ca6e..c120175a3d 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1578,7 +1578,7 @@ 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; + punit->current_form_turn = game.info.turn; unit_forget_last_activity(punit); if (!can_unit_continue_current_activity(&(wld.map), punit)) { @@ -2222,7 +2222,7 @@ struct unit *unit_change_owner(struct unit *punit, struct player *pplayer, /* Copy some more unit fields */ gained_unit->fuel = punit->fuel; gained_unit->paradropped = punit->paradropped; - gained_unit->server.birth_turn = punit->server.birth_turn; + gained_unit->birth_turn = punit->birth_turn; /* Fog is lifted in the placing algorithm. */ #ifndef FREECIV_NDEBUG @@ -2768,6 +2768,8 @@ void package_unit(struct unit *punit, struct packet_unit_info *packet) packet->paradropped = punit->paradropped; packet->done_moving = punit->done_moving; packet->stay = punit->stay; + packet->birth_turn = punit->birth_turn; + packet->current_form_turn = punit->current_form_turn; if (!unit_transported(punit)) { packet->transported = FALSE; packet->transported_by = 0; -- 2.43.0