diff --git a/server/unithand.c b/server/unithand.c index cfcd28f875..2098aa39e7 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -233,13 +233,13 @@ static bool do_unit_upgrade(struct player *pplayer, { struct unit_type *from_unit = unit_type_get(punit); 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 ff83798c6f..f8856db8fe 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -407,7 +407,7 @@ static void do_upgrade_effects(struct player *pplayer) struct unit_type *type_from = unit_type_get(punit); 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), @@ -748,7 +748,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."), @@ -1475,36 +1475,27 @@ 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, struct unit_type *to_unit, - bool is_free) + int vet_loss) { struct player *pplayer = unit_owner(punit); 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 1ca701a185..594f95e8ca 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -119,7 +119,7 @@ void unit_forget_last_activity(struct unit *punit); /* creation/deletion/upgrading */ void transform_unit(struct unit *punit, struct unit_type *to_unit, - bool has_to_pay); + int vet_loss); struct unit *create_unit(struct player *pplayer, struct tile *ptile, struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left);