From 5ccef463b2db3e99011f0e073c090800fcac52f0 Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Thu, 3 Feb 2022 23:16:19 +0300 Subject: [PATCH] Remove unit veterancy loss during conversion. This done by moving more specific stuff out of transform_unit function. See OSDN#43778 Signed-off-by: Ihnatus --- server/unithand.c | 6 +++--- server/unittools.c | 22 ++++++---------------- server/unittools.h | 2 +- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/server/unithand.c b/server/unithand.c index 19ba06ce12..b188f3fb2d 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -252,13 +252,13 @@ static bool do_unit_upgrade(struct player *pplayer, { const struct unit_type *from_unit = unit_type_get(punit); const struct unit_type *to_unit = can_upgrade_unittype(pplayer, from_unit); + int cost = unit_upgrade_price(pplayer, from_unit, to_unit); - transform_unit(punit, to_unit, FALSE); + transform_unit(punit, to_unit, game.server.upgrade_veteran_loss); + pplayer->economic.gold -= cost; send_player_info_c(pplayer, pplayer->connections); if (ordered_by == ACT_REQ_PLAYER) { - int cost = unit_upgrade_price(pplayer, from_unit, to_unit); - notify_player(pplayer, unit_tile(punit), E_UNIT_UPGRADED, ftc_server, PL_("%s upgraded to %s for %d gold.", "%s upgraded to %s for %d gold.", cost), diff --git a/server/unittools.c b/server/unittools.c index 3dbf954880..c4020b2b64 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -433,7 +433,7 @@ static void do_upgrade_effects(struct player *pplayer) const struct unit_type *type_from = unit_type_get(punit); const struct unit_type *type_to = can_upgrade_unittype(pplayer, type_from); - transform_unit(punit, type_to, TRUE); + transform_unit(punit, type_to, game.server.autoupgrade_veteran_loss); notify_player(pplayer, unit_tile(punit), E_UNIT_UPGRADED, ftc_server, _("%s was upgraded for free to %s."), utype_name_translation(type_from), @@ -775,7 +775,7 @@ static void unit_convert(struct unit *punit) to_type = from_type->converted_to; if (unit_can_convert(punit)) { - transform_unit(punit, to_type, TRUE); + transform_unit(punit, to_type, 0); notify_player(unit_owner(punit), unit_tile(punit), E_UNIT_UPGRADED, ftc_server, _("%s converted to %s."), @@ -1526,36 +1526,26 @@ bool is_airunit_refuel_point(const struct tile *ptile, test first to check that the transformation is legal (test_unit_upgrade() or test_unit_convert()). - is_free: Does unit owner need to pay upgrade price. + vet_loss: Number of veteran levels lost in process. Note that this function is strongly tied to unit.c:test_unit_upgrade(). **************************************************************************/ void transform_unit(struct unit *punit, const struct unit_type *to_unit, - bool is_free) + int vet_loss) { struct player *pplayer = unit_owner(punit); const struct unit_type *old_type = punit->utype; int old_mr = unit_move_rate(punit); int old_hp = unit_type_get(punit)->hp; - if (!is_free) { - pplayer->economic.gold -= - unit_upgrade_price(pplayer, unit_type_get(punit), to_unit); - } - punit->utype = to_unit; /* New type may not have the same veteran system, and we may want to * knock some levels off. */ punit->veteran = MIN(punit->veteran, utype_veteran_system(to_unit)->levels - 1); - if (is_free) { - punit->veteran = MAX(punit->veteran - - game.server.autoupgrade_veteran_loss, 0); - } else { - punit->veteran = MAX(punit->veteran - - game.server.upgrade_veteran_loss, 0); - } + /* Keeping the old behaviour, so first clip top, then reduce */ + punit->veteran = MAX(punit->veteran - vet_loss, 0); /* Scale HP and MP, rounding down. Be careful with integer arithmetic, * and don't kill the unit. unit_move_rate() is used to take into account diff --git a/server/unittools.h b/server/unittools.h index 07bd543b5b..5f21151b84 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -120,7 +120,7 @@ void unit_forget_last_activity(struct unit *punit); /* creation/deletion/upgrading */ void transform_unit(struct unit *punit, const struct unit_type *to_unit, - bool has_to_pay); + int vet_loss); struct unit *create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left); -- 2.32.0