From 1960b31bcb445f84680f193835d7e9dd4da9bfbe Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 17 Apr 2022 10:52:50 +0300 Subject: [PATCH 45/45] 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/scriptcore/api_game_methods.c | 2 ++ common/unit.c | 15 +++++++++++++++ common/unit.h | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c index 7e2f620051..08a14a1099 100644 --- a/common/scriptcore/api_game_methods.c +++ b/common/scriptcore/api_game_methods.c @@ -626,6 +626,8 @@ const char *api_methods_unit_transform_problem(lua_State *L, Unit *punit, return "transport"; case UU_NOT_TERRAIN: return "terrain"; + case UU_NOT_ACTIVITY: + return "activity"; case UU_NO_UNITTYPE: case UU_NO_MONEY: case UU_NOT_IN_CITY: diff --git a/common/unit.c b/common/unit.c index b84f60a7cd..bf9c3d6b7c 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1916,6 +1916,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) { @@ -2023,6 +2032,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 74c851d893..4b3765a26e 100644 --- a/common/unit.h +++ b/common/unit.h @@ -63,8 +63,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