From 85a5170c4aaa7e54c5818d9e6836882deb5deaf5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 17 Apr 2022 10:56:38 +0300 Subject: [PATCH 22/22] Disallow unit upgrade while it's converting Upgrade would change the conversion target, which is wrong in many ways. Reported, and initial patch by, Lexxie See osdn #43328 Signed-off-by: Marko Lindqvist --- common/unit.c | 15 +++++++++++++++ common/unit.h | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/unit.c b/common/unit.c index ad3972e8ed..155c4be54c 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1903,6 +1903,15 @@ enum unit_upgrade_result unit_upgrade_test(const struct unit *punit, return UU_NO_UNITTYPE; } + if (punit->activity == ACTIVITY_CONVERT) { + /* TODO: There may be other activities that the upgraded unit is not + allowed to do, which we could also test. + - + If convert were legal for new unit_type we could allow, but then it + has a 'head start' getting activity time from the old conversion. */ + return UU_NOT_ACTIVITY; + } + if (!is_free) { cost = unit_upgrade_price(pplayer, unit_type_get(punit), to_unittype); if (pplayer->economic.gold < cost) { @@ -2037,6 +2046,12 @@ enum unit_upgrade_result unit_upgrade_info(const struct unit *punit, utype_name_translation(to_unittype), unit_name_translation(punit->transporter)); break; + case UU_NOT_ACTIVITY: + fc_snprintf(buf, bufsz, + _("Cannot upgrade %s while doing '%s'."), + utype_name_translation(from_unittype), + unit_activity_name(punit->activity)); + break; } return result; diff --git a/common/unit.h b/common/unit.h index 7d9b4cde66..e3f34b0792 100644 --- a/common/unit.h +++ b/common/unit.h @@ -62,8 +62,9 @@ enum unit_upgrade_result { UU_NOT_IN_CITY, UU_NOT_CITY_OWNER, UU_NOT_ENOUGH_ROOM, - UU_NOT_TERRAIN, /* The upgraded unit could not survive. */ - UU_UNSUITABLE_TRANSPORT /* Can't upgrade inside current transport. */ + UU_NOT_TERRAIN, /* The upgraded unit could not survive. */ + UU_UNSUITABLE_TRANSPORT, /* Can't upgrade inside current transport. */ + UU_NOT_ACTIVITY /* Can't upgrade during this activity (e.g., CONVERT) */ }; enum unit_airlift_result { -- 2.35.1