Skip to content

Commit

Permalink
FIX: UPGRADE_UNIT not allowed on converting units
Browse files Browse the repository at this point in the history
Prevents exploits/bugs where upgraded unit type would inherit ACTIVITY_CONVERT that may be illegal for its type.
  • Loading branch information
Lexxie9952 committed Dec 4, 2021
1 parent 233eeb7 commit fc68165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions freeciv/freeciv/common/unit.c
Expand Up @@ -2063,6 +2063,15 @@ enum unit_upgrade_result unit_upgrade_test(const struct unit *punit,
struct city *pcity;
int cost;

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 (!to_unittype) {
return UU_NO_UNITTYPE;
}
Expand Down Expand Up @@ -2196,6 +2205,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;
Expand Down
5 changes: 3 additions & 2 deletions freeciv/freeciv/common/unit.h
Expand Up @@ -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 {
Expand Down

0 comments on commit fc68165

Please sign in to comment.