From 446f6e3a286f70fd9111be737eee438cdc7bd34f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 18 Dec 2022 21:04:06 +0200 Subject: [PATCH 44/44] Drop deprecated unit_activity values They were left as placeholders when we couldn't let the values following them to change. See osdn #46312 Signed-off-by: Marko Lindqvist --- common/actions.c | 6 --- common/fc_types.h | 82 ++++++++++++++---------------------- common/tile.c | 32 +++++++------- common/unit.c | 48 ++------------------- common/unitlist.c | 10 ++--- server/savegame/savecompat.c | 6 --- server/savegame/savegame2.c | 29 ++++++------- server/savegame/savegame3.c | 13 ++---- server/unittools.c | 23 ---------- 9 files changed, 71 insertions(+), 178 deletions(-) diff --git a/common/actions.c b/common/actions.c index 0c8e18d6cc..38f84f73fe 100644 --- a/common/actions.c +++ b/common/actions.c @@ -2218,13 +2218,7 @@ int action_get_act_time(const struct action *paction, case ACTIVITY_FORTIFIED: case ACTIVITY_SENTRY: case ACTIVITY_GOTO: - case ACTIVITY_UNKNOWN: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: /* Should not happen. Caught by the assertion below. */ break; } diff --git a/common/fc_types.h b/common/fc_types.h index 2bf38d7fee..9b529ef757 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -130,72 +130,54 @@ enum counter_target { CTGT_CITY }; /* Action with the result ACTRES_CLEAN_POLLUTION */ #define SPECENUM_VALUE1 ACTIVITY_POLLUTION #define SPECENUM_VALUE1NAME N_("Pollution") -/* Savegame compatibility */ -#define SPECENUM_VALUE2 ACTIVITY_OLD_ROAD -#define SPECENUM_VALUE2NAME "Unused Road" /* Action with the result ACTRES_CULTIVATE */ -#define SPECENUM_VALUE3 ACTIVITY_MINE -#define SPECENUM_VALUE3NAME N_("?act:Mine") +#define SPECENUM_VALUE2 ACTIVITY_MINE +#define SPECENUM_VALUE2NAME N_("?act:Mine") /* Action with the result ACTRES_IRRIGATE */ -#define SPECENUM_VALUE4 ACTIVITY_IRRIGATE -#define SPECENUM_VALUE4NAME N_("Irrigate") +#define SPECENUM_VALUE3 ACTIVITY_IRRIGATE +#define SPECENUM_VALUE3NAME N_("Irrigate") /* Has completed ACTIVITY_FORTIFYING */ -#define SPECENUM_VALUE5 ACTIVITY_FORTIFIED -#define SPECENUM_VALUE5NAME N_("Fortified") -/* Savegame compatibility */ -#define SPECENUM_VALUE6 ACTIVITY_FORTRESS -#define SPECENUM_VALUE6NAME "Fortress" +#define SPECENUM_VALUE4 ACTIVITY_FORTIFIED +#define SPECENUM_VALUE4NAME N_("Fortified") /* Server side client state (UI) */ -#define SPECENUM_VALUE7 ACTIVITY_SENTRY -#define SPECENUM_VALUE7NAME "Sentry" -/* Savegame compatibility */ -#define SPECENUM_VALUE8 ACTIVITY_OLD_RAILROAD -#define SPECENUM_VALUE8NAME "Unused Railroad" +#define SPECENUM_VALUE5 ACTIVITY_SENTRY +#define SPECENUM_VALUE5NAME "Sentry" /* Action with the result ACTRES_PILLAGE */ -#define SPECENUM_VALUE9 ACTIVITY_PILLAGE -#define SPECENUM_VALUE9NAME N_("Pillage") +#define SPECENUM_VALUE6 ACTIVITY_PILLAGE +#define SPECENUM_VALUE6NAME N_("Pillage") /* AI compatibility. Is not orders' goto. */ -#define SPECENUM_VALUE10 ACTIVITY_GOTO -#define SPECENUM_VALUE10NAME "Goto" +#define SPECENUM_VALUE7 ACTIVITY_GOTO +#define SPECENUM_VALUE7NAME "Goto" /* Server side agent */ -#define SPECENUM_VALUE11 ACTIVITY_EXPLORE -#define SPECENUM_VALUE11NAME "Explore" +#define SPECENUM_VALUE8 ACTIVITY_EXPLORE +#define SPECENUM_VALUE8NAME "Explore" /* Action with the result ACTRES_TRANSFORM_TERRAIN */ -#define SPECENUM_VALUE12 ACTIVITY_TRANSFORM -#define SPECENUM_VALUE12NAME N_("Transform") -/* Unused */ -#define SPECENUM_VALUE13 ACTIVITY_UNKNOWN -#define SPECENUM_VALUE13NAME "Unused" -/* Savegame compatibility */ -#define SPECENUM_VALUE14 ACTIVITY_AIRBASE -#define SPECENUM_VALUE14NAME "Unused Airbase" +#define SPECENUM_VALUE9 ACTIVITY_TRANSFORM +#define SPECENUM_VALUE9NAME N_("Transform") /* Action with the result ACTRES_FORTIFY */ -#define SPECENUM_VALUE15 ACTIVITY_FORTIFYING -#define SPECENUM_VALUE15NAME N_("Fortifying") +#define SPECENUM_VALUE10 ACTIVITY_FORTIFYING +#define SPECENUM_VALUE10NAME N_("Fortifying") /* Action with the result ACTRES_CLEAN_FALLOUT */ -#define SPECENUM_VALUE16 ACTIVITY_FALLOUT -#define SPECENUM_VALUE16NAME N_("Fallout") -/* Unused */ -#define SPECENUM_VALUE17 ACTIVITY_PATROL_UNUSED -#define SPECENUM_VALUE17NAME "Unused Patrol" +#define SPECENUM_VALUE11 ACTIVITY_FALLOUT +#define SPECENUM_VALUE11NAME N_("Fallout") /* Action with the result ACTRES_BASE */ -#define SPECENUM_VALUE18 ACTIVITY_BASE -#define SPECENUM_VALUE18NAME N_("Base") +#define SPECENUM_VALUE12 ACTIVITY_BASE +#define SPECENUM_VALUE12NAME N_("Base") /* Action with the result ACTRES_ROAD */ -#define SPECENUM_VALUE19 ACTIVITY_GEN_ROAD -#define SPECENUM_VALUE19NAME N_("Road") +#define SPECENUM_VALUE13 ACTIVITY_GEN_ROAD +#define SPECENUM_VALUE13NAME N_("Road") /* Action with the result ACTRES_CONVERT */ -#define SPECENUM_VALUE20 ACTIVITY_CONVERT -#define SPECENUM_VALUE20NAME N_("Convert") +#define SPECENUM_VALUE14 ACTIVITY_CONVERT +#define SPECENUM_VALUE14NAME N_("Convert") /* Action with the result ACTRES_CULTIVATE */ -#define SPECENUM_VALUE21 ACTIVITY_CULTIVATE -#define SPECENUM_VALUE21NAME N_("Cultivate") +#define SPECENUM_VALUE15 ACTIVITY_CULTIVATE +#define SPECENUM_VALUE15NAME N_("Cultivate") /* Action with the result ACTRES_PLANT */ -#define SPECENUM_VALUE22 ACTIVITY_PLANT -#define SPECENUM_VALUE22NAME N_("Plant") +#define SPECENUM_VALUE16 ACTIVITY_PLANT +#define SPECENUM_VALUE16NAME N_("Plant") /* Action with the result ACTRES_CLEAN */ -#define SPECENUM_VALUE23 ACTIVITY_CLEAN -#define SPECENUM_VALUE23NAME N_("Clean") +#define SPECENUM_VALUE17 ACTIVITY_CLEAN +#define SPECENUM_VALUE17NAME N_("Clean") /* Number of activities */ #define SPECENUM_COUNT ACTIVITY_LAST #include "specenum_gen.h" diff --git a/common/tile.c b/common/tile.c index c55edc3306..efd9de502b 100644 --- a/common/tile.c +++ b/common/tile.c @@ -419,10 +419,6 @@ int tile_activity_time(enum unit_activity activity, const struct tile *ptile, { struct terrain *pterrain = tile_terrain(ptile); - /* Make sure nobody uses old activities */ - fc_assert_ret_val(activity != ACTIVITY_FORTRESS - && activity != ACTIVITY_AIRBASE, FC_INFINITY); - switch (activity) { case ACTIVITY_CLEAN: case ACTIVITY_POLLUTION: @@ -440,9 +436,18 @@ int tile_activity_time(enum unit_activity activity, const struct tile *ptile, case ACTIVITY_BASE: case ACTIVITY_GEN_ROAD: return terrain_extra_build_time(pterrain, activity, tgt) * ACTIVITY_FACTOR; - default: - return 0; + case ACTIVITY_IDLE: + case ACTIVITY_FORTIFIED: + case ACTIVITY_SENTRY: + case ACTIVITY_GOTO: + case ACTIVITY_EXPLORE: + case ACTIVITY_FORTIFYING: + case ACTIVITY_CONVERT: + case ACTIVITY_LAST: + return 0; /* FIXME: Should some of these be asserted against */ } + + return 0; } /************************************************************************//** @@ -687,20 +692,13 @@ bool tile_apply_activity(struct tile *ptile, Activity_type_id act, tile_plant(ptile); return TRUE; - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - fc_assert(FALSE); - return FALSE; - case ACTIVITY_PILLAGE: case ACTIVITY_BASE: case ACTIVITY_GEN_ROAD: case ACTIVITY_CLEAN: case ACTIVITY_POLLUTION: case ACTIVITY_FALLOUT: - /* do nothing - not implemented */ + /* Do nothing - not implemented */ return FALSE; case ACTIVITY_IDLE: @@ -709,15 +707,15 @@ bool tile_apply_activity(struct tile *ptile, Activity_type_id act, case ACTIVITY_GOTO: case ACTIVITY_EXPLORE: case ACTIVITY_CONVERT: - case ACTIVITY_UNKNOWN: case ACTIVITY_FORTIFYING: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: - /* do nothing - these activities have no effect + /* Do nothing - these activities have no effect on terrain type or tile extras */ return FALSE; } + fc_assert(FALSE); + return FALSE; } diff --git a/common/unit.c b/common/unit.c index 62e0515be7..3679bdd6b7 100644 --- a/common/unit.c +++ b/common/unit.c @@ -545,12 +545,6 @@ bool activity_requires_target(enum unit_activity activity) case ACTIVITY_CONVERT: return FALSE; /* These shouldn't be kicking around internally. */ - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - case ACTIVITY_PATROL_UNUSED: - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_UNKNOWN: case ACTIVITY_LAST: break; } @@ -592,20 +586,11 @@ void setup_real_activities_array(void) } /**********************************************************************//** - Return if given activity really is in game. For savegame compatibility - activity enum cannot be reordered and there is holes in it. + Return if given activity really is in game. **************************************************************************/ bool is_real_activity(enum unit_activity activity) { - /* ACTIVITY_FORTRESS, ACTIVITY_AIRBASE, ACTIVITY_OLD_ROAD, and - * ACTIVITY_OLD_RAILROAD are deprecated */ - return (activity < ACTIVITY_LAST) - && activity != ACTIVITY_FORTRESS - && activity != ACTIVITY_AIRBASE - && activity != ACTIVITY_OLD_ROAD - && activity != ACTIVITY_OLD_RAILROAD - && activity != ACTIVITY_UNKNOWN - && activity != ACTIVITY_PATROL_UNUSED; + return (activity < ACTIVITY_LAST); } /**********************************************************************//** @@ -655,12 +640,6 @@ const char *get_activity_text(enum unit_activity activity) return _("Road"); case ACTIVITY_CONVERT: return _("Convert"); - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - case ACTIVITY_UNKNOWN: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: break; } @@ -1060,15 +1039,10 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, "Please use action_speculate_unit_on_self()"); return is_action_enabled_unit_on_self(ACTION_CONVERT, punit); - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: - case ACTIVITY_UNKNOWN: break; } + log_error("can_unit_do_activity_targeted_at() unknown activity %d", activity); return FALSE; @@ -1081,9 +1055,6 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, static void set_unit_activity_internal(struct unit *punit, enum unit_activity new_activity) { - fc_assert_ret(new_activity != ACTIVITY_FORTRESS - && new_activity != ACTIVITY_AIRBASE); - punit->activity = new_activity; punit->activity_count = 0; punit->activity_target = NULL; @@ -1207,13 +1178,9 @@ void unit_activity_astr(const struct unit *punit, struct astring *astr) case ACTIVITY_CLEAN: case ACTIVITY_POLLUTION: case ACTIVITY_FALLOUT: - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: case ACTIVITY_TRANSFORM: case ACTIVITY_FORTIFYING: case ACTIVITY_FORTIFIED: - case ACTIVITY_AIRBASE: - case ACTIVITY_FORTRESS: case ACTIVITY_SENTRY: case ACTIVITY_GOTO: case ACTIVITY_EXPLORE: @@ -1247,8 +1214,6 @@ void unit_activity_astr(const struct unit *punit, struct astring *astr) astr_add_line(astr, "%s: %s", get_activity_text(punit->activity), extra_name_translation(punit->activity_target)); return; - case ACTIVITY_UNKNOWN: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: break; } @@ -2599,15 +2564,8 @@ bool unit_order_list_is_sane(int length, const struct unit_order *orders) /* Not set from the client. */ case ACTIVITY_GOTO: case ACTIVITY_FORTIFIED: - /* Compatiblity, used in savegames. */ - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: /* Unused. */ - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: - case ACTIVITY_UNKNOWN: log_error("at index %d, unsupported activity %d.", i, orders[i].activity); return FALSE; } diff --git a/common/unitlist.c b/common/unitlist.c index f484965c54..1dd93ce291 100644 --- a/common/unitlist.c +++ b/common/unitlist.c @@ -84,15 +84,15 @@ void unit_list_sort_ord_map(struct unit_list *punitlist) void unit_list_sort_ord_city(struct unit_list *punitlist) { fc_assert_ret(is_server()); + unit_list_sort(punitlist, compar_unit_ord_city); } - /************************************************************************//** Return TRUE if the function returns true for any of the units. ****************************************************************************/ bool can_units_do(const struct unit_list *punits, - bool (can_fn)(const struct unit *punit)) + bool (can_fn)(const struct unit *punit)) { unit_list_iterate(punits, punit) { if (can_fn(punit)) { @@ -107,12 +107,8 @@ bool can_units_do(const struct unit_list *punits, Returns TRUE if any of the units can do the activity. ****************************************************************************/ bool can_units_do_activity(const struct unit_list *punits, - enum unit_activity activity) + enum unit_activity activity) { - /* Make sure nobody uses these old activities any more */ - fc_assert_ret_val(activity != ACTIVITY_FORTRESS - && activity != ACTIVITY_AIRBASE, FALSE); - unit_list_iterate(punits, punit) { if (can_unit_do_activity(punit, activity)) { return TRUE; diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 61be376c39..04772a4634 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1686,13 +1686,7 @@ static void unit_order_activity_to_action(struct unit *act_unit) case ACTIVITY_IDLE: case ACTIVITY_GOTO: case ACTIVITY_FORTIFIED: - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: - case ACTIVITY_UNKNOWN: log_error("Activity %d is not supposed to appear in unit orders", order->activity); break; diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index f5beffe1eb..0581c750ed 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -140,6 +140,10 @@ extern bool sg_success; +#define ACTIVITY_OLD_ROAD (ACTIVITY_LAST + 1) +#define ACTIVITY_OLD_RAILROAD (ACTIVITY_LAST + 2) +#define ACTIVITY_LAST_SAVEGAME2 (ACTIVITY_LAST + 3) + /* * This loops over the entire map to save data. It collects all the data of * a line using GET_XY_CHAR and then executes the macro SECFILE_INSERT_LINE. @@ -288,8 +292,8 @@ static void loaddata_destroy(struct loaddata *loading); static enum unit_orders char2order(char order); static enum direction8 char2dir(char dir); -static char activity2char(enum unit_activity activity); -static enum unit_activity char2activity(char activity); +static char activity2char(int activity); +static int char2activity(char activity); static int unquote_block(const char *const quoted_, void *dest, int dest_length); static void worklist_load(struct section_file *file, int wlist_max_length, @@ -625,9 +629,9 @@ static enum direction8 char2dir(char dir) } /************************************************************************//** - Returns a character identifier for an activity. See also char2activity. + Returns a character identifier for an activity. See also char2activity(). ****************************************************************************/ -static char activity2char(enum unit_activity activity) +static char activity2char(int activity) { switch (activity) { case ACTIVITY_IDLE: @@ -644,8 +648,6 @@ static char activity2char(enum unit_activity activity) return 'i'; case ACTIVITY_FORTIFIED: return 'f'; - case ACTIVITY_FORTRESS: - return 't'; case ACTIVITY_SENTRY: return 's'; case ACTIVITY_OLD_RAILROAD: @@ -658,8 +660,6 @@ static char activity2char(enum unit_activity activity) return 'x'; case ACTIVITY_TRANSFORM: return 'o'; - case ACTIVITY_AIRBASE: - return 'a'; case ACTIVITY_FORTIFYING: return 'y'; case ACTIVITY_FALLOUT: @@ -670,8 +670,6 @@ static char activity2char(enum unit_activity activity) return 'R'; case ACTIVITY_CONVERT: return 'c'; - case ACTIVITY_UNKNOWN: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_CULTIVATE: case ACTIVITY_PLANT: return '?'; @@ -680,17 +678,18 @@ static char activity2char(enum unit_activity activity) } fc_assert(FALSE); + return '?'; } /************************************************************************//** - Returns an activity for a character identifier. See also activity2char. + Returns an activity for a character identifier. See also activity2char(). ****************************************************************************/ -static enum unit_activity char2activity(char activity) +static int char2activity(char activity) { - enum unit_activity a; + int a; - for (a = 0; a < ACTIVITY_LAST; a++) { + for (a = 0; a < ACTIVITY_LAST_SAVEGAME2; a++) { char achar = activity2char(a); if (activity == achar) { @@ -3884,7 +3883,7 @@ static bool sg_load_player_unit(struct loaddata *loading, const char *unitstr) { int j; - enum unit_activity activity; + int activity; int nat_x, nat_y; enum tile_special_type target; struct extra_type *pextra = NULL; diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 10fabb885f..8739f625ed 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -800,11 +800,12 @@ static char dir2char(enum direction8 dir) } fc_assert(FALSE); + return '?'; } /************************************************************************//** - Returns a character identifier for an activity. See also char2activity. + Returns a character identifier for an activity. See also char2activity(). ****************************************************************************/ static char activity2char(enum unit_activity activity) { @@ -845,23 +846,17 @@ static char activity2char(enum unit_activity activity) return 'R'; case ACTIVITY_CONVERT: return 'c'; - case ACTIVITY_OLD_ROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_AIRBASE: - case ACTIVITY_UNKNOWN: - case ACTIVITY_PATROL_UNUSED: - return '?'; case ACTIVITY_LAST: break; } fc_assert(FALSE); + return '?'; } /************************************************************************//** - Returns an activity for a character identifier. See also activity2char. + Returns an activity for a character identifier. See also activity2char(). ****************************************************************************/ static enum unit_activity char2activity(char activity) { diff --git a/server/unittools.c b/server/unittools.c index d6a0e22e74..dab4a68553 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -887,8 +887,6 @@ static void update_unit_activity(struct unit *punit) case ACTIVITY_FORTIFIED: case ACTIVITY_SENTRY: case ACTIVITY_GOTO: - case ACTIVITY_PATROL_UNUSED: - case ACTIVITY_UNKNOWN: case ACTIVITY_LAST: /* We don't need the activity_count for the above */ break; @@ -916,12 +914,6 @@ static void update_unit_activity(struct unit *punit) notify_unit_experience(punit); } break; - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - fc_assert(FALSE); - break; }; unit_restore_movepoints(pplayer, punit); @@ -931,10 +923,8 @@ static void update_unit_activity(struct unit *punit) case ACTIVITY_FORTIFIED: case ACTIVITY_SENTRY: case ACTIVITY_GOTO: - case ACTIVITY_UNKNOWN: case ACTIVITY_FORTIFYING: case ACTIVITY_CONVERT: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_LAST: /* No default, ensure all handled */ break; @@ -1065,13 +1055,6 @@ static void update_unit_activity(struct unit *punit) unit_activity_done = TRUE; } break; - - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: - case ACTIVITY_FORTRESS: - case ACTIVITY_AIRBASE: - fc_assert(FALSE); - break; } if (unit_activity_done) { @@ -3719,18 +3702,12 @@ static void check_unit_activity(struct unit *punit) case ACTIVITY_CULTIVATE: case ACTIVITY_PLANT: case ACTIVITY_FORTIFIED: - case ACTIVITY_FORTRESS: case ACTIVITY_PILLAGE: case ACTIVITY_TRANSFORM: - case ACTIVITY_UNKNOWN: - case ACTIVITY_AIRBASE: case ACTIVITY_FORTIFYING: - case ACTIVITY_PATROL_UNUSED: case ACTIVITY_BASE: case ACTIVITY_GEN_ROAD: case ACTIVITY_CONVERT: - case ACTIVITY_OLD_ROAD: - case ACTIVITY_OLD_RAILROAD: case ACTIVITY_LAST: set_unit_activity(punit, ACTIVITY_IDLE); break; -- 2.35.1