From 058f6e08d0a1c83815008a30107b1877b3c01bbf Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 25 Jul 2023 23:22:42 +0300 Subject: [PATCH 13/13] Replace action_get_activity() by actres_get_activity() As a side-effect, fixes an use of uninitialized action actor kind. See osdn #48443 Signed-off-by: Marko Lindqvist --- ai/tex/texaicity.c | 6 +++--- ai/threaded/taicity.c | 6 +++--- common/actions.c | 34 +++++++++++++++------------------- common/actions.h | 4 ++-- common/extras.c | 6 ++++-- server/actiontools.c | 2 +- server/advisors/autosettlers.c | 6 +++--- server/savegame/savecompat.c | 3 ++- server/unithand.c | 8 ++++---- 9 files changed, 37 insertions(+), 38 deletions(-) diff --git a/ai/tex/texaicity.c b/ai/tex/texaicity.c index 8f2b4d9e8b..d2834a877f 100644 --- a/ai/tex/texaicity.c +++ b/ai/tex/texaicity.c @@ -316,7 +316,7 @@ static void texai_tile_worker_task_select(struct player *pplayer, unit_list_iterate(ptile->units, punit) { if (unit_owner(punit) == pplayer && unit_has_type_flag(punit, UTYF_SETTLERS) - && punit->activity == action_get_activity(paction)) { + && punit->activity == actres_get_activity(paction->result)) { consider = FALSE; break; } @@ -383,7 +383,7 @@ static void texai_tile_worker_task_select(struct player *pplayer, if ((value - orig_value) * TWMP > worked->want) { worked->want = TWMP * (value - orig_value); worked->ptile = ptile; - worked->act = action_get_activity(paction); + worked->act = actres_get_activity(paction->result); worked->tgt = tgt; if (limit == TWTL_BUILDABLE_UNITS) { unit_list_iterate(units, punit) { @@ -411,7 +411,7 @@ static void texai_tile_worker_task_select(struct player *pplayer, state->uw_max_base = base_value; unworked->want = TWMP * (value - orig_value); unworked->ptile = ptile; - unworked->act = action_get_activity(paction); + unworked->act = actres_get_activity(paction->result); unworked->tgt = tgt; if (limit == TWTL_BUILDABLE_UNITS) { unit_list_iterate(units, punit) { diff --git a/ai/threaded/taicity.c b/ai/threaded/taicity.c index 96622ec0b6..7870070ed0 100644 --- a/ai/threaded/taicity.c +++ b/ai/threaded/taicity.c @@ -262,7 +262,7 @@ static void tai_tile_worker_task_select(struct player *pplayer, unit_list_iterate(ptile->units, punit) { if (unit_owner(punit) == pplayer && unit_has_type_flag(punit, UTYF_SETTLERS) - && punit->activity == action_get_activity(paction)) { + && punit->activity == actres_get_activity(paction->result)) { consider = FALSE; break; } @@ -328,7 +328,7 @@ static void tai_tile_worker_task_select(struct player *pplayer, if ((value - orig_value) * TWMP > worked->want) { worked->want = TWMP * (value - orig_value); worked->ptile = ptile; - worked->act = action_get_activity(paction); + worked->act = actres_get_activity(paction->result); worked->tgt = tgt; if (limit == TWTL_BUILDABLE_UNITS) { unit_list_iterate(units, punit) { @@ -356,7 +356,7 @@ static void tai_tile_worker_task_select(struct player *pplayer, state->uw_max_base = base_value; unworked->want = TWMP * (value - orig_value); unworked->ptile = ptile; - unworked->act = action_get_activity(paction); + unworked->act = actres_get_activity(paction->result); unworked->tgt = tgt; if (limit == TWTL_BUILDABLE_UNITS) { unit_list_iterate(units, punit) { diff --git a/common/actions.c b/common/actions.c index 52ea9344bd..8c971c3dcc 100644 --- a/common/actions.c +++ b/common/actions.c @@ -1619,7 +1619,7 @@ static struct action *action_new(action_id id, action->result = result; if (result != ACTRES_LAST) { - enum unit_activity act = action_get_activity(action); + enum unit_activity act = actres_get_activity(result); action_list_append(actlist_by_result[result], action); @@ -2133,35 +2133,31 @@ int action_get_role(const struct action *paction) Returns the unit activity this action may cause or ACTIVITY_LAST if the action doesn't result in a unit activity. **************************************************************************/ -enum unit_activity action_get_activity(const struct action *paction) +enum unit_activity actres_get_activity(enum action_result result) { - fc_assert_msg(AAK_UNIT == action_get_actor_kind(paction), - "Action %s isn't performed by a unit", - action_rule_name(paction)); - - if (action_has_result(paction, ACTRES_FORTIFY)) { + if (result == ACTRES_FORTIFY) { return ACTIVITY_FORTIFYING; - } else if (action_has_result(paction, ACTRES_BASE)) { + } else if (result == ACTRES_BASE) { return ACTIVITY_BASE; - } else if (action_has_result(paction, ACTRES_ROAD)) { + } else if (result == ACTRES_ROAD) { return ACTIVITY_GEN_ROAD; - } else if (action_has_result(paction, ACTRES_PILLAGE)) { + } else if (result == ACTRES_PILLAGE) { return ACTIVITY_PILLAGE; - } else if (action_has_result(paction, ACTRES_CLEAN_POLLUTION)) { + } else if (result == ACTRES_CLEAN_POLLUTION) { return ACTIVITY_POLLUTION; - } else if (action_has_result(paction, ACTRES_CLEAN_FALLOUT)) { + } else if (result == ACTRES_CLEAN_FALLOUT) { return ACTIVITY_FALLOUT; - } else if (action_has_result(paction, ACTRES_TRANSFORM_TERRAIN)) { + } else if (result == ACTRES_TRANSFORM_TERRAIN) { return ACTIVITY_TRANSFORM; - } else if (action_has_result(paction, ACTRES_CONVERT)) { + } else if (result == ACTRES_CONVERT) { return ACTIVITY_CONVERT; - } else if (action_has_result(paction, ACTRES_PLANT)) { + } else if (result == ACTRES_PLANT) { return ACTIVITY_PLANT; - } else if (action_has_result(paction, ACTRES_MINE)) { + } else if (result == ACTRES_MINE) { return ACTIVITY_MINE; - } else if (action_has_result(paction, ACTRES_CULTIVATE)) { + } else if (result == ACTRES_CULTIVATE) { return ACTIVITY_CULTIVATE; - } else if (action_has_result(paction, ACTRES_IRRIGATE)) { + } else if (result == ACTRES_IRRIGATE) { return ACTIVITY_IRRIGATE; } else { return ACTIVITY_LAST; @@ -2179,7 +2175,7 @@ int action_get_act_time(const struct action *paction, const struct tile *tgt_tile, const struct extra_type *tgt_extra) { - enum unit_activity pactivity = action_get_activity(paction); + enum unit_activity pactivity = actres_get_activity(paction->result); if (pactivity == ACTIVITY_LAST) { /* Happens instantaneously, not at turn change. */ diff --git a/common/actions.h b/common/actions.h index d97e5e962f..af606d7775 100644 --- a/common/actions.h +++ b/common/actions.h @@ -707,9 +707,9 @@ int action_get_role(const struct action *paction); #define action_id_get_role(act_id) \ action_get_role(action_by_number(act_id)) -enum unit_activity action_get_activity(const struct action *paction); +enum unit_activity actres_get_activity(enum action_result result); #define action_id_get_activity(act_id) \ - action_get_activity(action_by_number(act_id)) + actres_get_activity(action_by_number(act_id)->result) const char *action_rule_name(const struct action *action); const char *action_id_rule_name(action_id act_id); diff --git a/common/extras.c b/common/extras.c index 3ed42d8e5d..c8271cf639 100644 --- a/common/extras.c +++ b/common/extras.c @@ -990,7 +990,8 @@ bool is_extra_removed_by_worker_action(const struct extra_type *pextra) bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction) { - enum unit_activity act = action_get_activity(paction); + enum unit_activity act = actres_get_activity(paction->result); + return is_extra_caused_by(pextra, activity_to_extra_cause(act)); } @@ -1000,7 +1001,8 @@ bool is_extra_caused_by_action(const struct extra_type *pextra, bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction) { - enum unit_activity act = action_get_activity(paction); + enum unit_activity act = actres_get_activity(paction->result); + return is_extra_removed_by(pextra, activity_to_extra_rmcause(act)); } diff --git a/server/actiontools.c b/server/actiontools.c index bd1b08d8fb..974e82a455 100644 --- a/server/actiontools.c +++ b/server/actiontools.c @@ -905,7 +905,7 @@ int action_sub_target_id_for_action(const struct action *paction, if (action_has_result(paction, ACTRES_PILLAGE)) { /* Special treatment for "Pillage" */ struct extra_type *pextra; - enum unit_activity activity = action_get_activity(paction); + enum unit_activity activity = actres_get_activity(paction->result); unit_assign_specific_activity_target(actor_unit, &activity, &pextra); diff --git a/server/advisors/autosettlers.c b/server/advisors/autosettlers.c index 36a6604af0..42df4d52a1 100644 --- a/server/advisors/autosettlers.c +++ b/server/advisors/autosettlers.c @@ -597,8 +597,8 @@ adv_want settler_evaluate_improvements(const struct civ_map *nmap, ptile, parameter.omniscience, ptile, pextra))) { - act = action_get_activity(taction); - eval_act = action_get_activity(taction); + act = actres_get_activity(taction->result); + eval_act = actres_get_activity(taction->result); break; } } @@ -615,7 +615,7 @@ adv_want settler_evaluate_improvements(const struct civ_map *nmap, ptile, parameter.omniscience, ptile, pextra))) { - act = action_get_activity(taction); + act = actres_get_activity(taction->result); break; } } diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 944b86965e..82938282de 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1637,7 +1637,8 @@ static void unit_order_activity_to_action(struct unit *act_unit) case ACTIVITY_PILLAGE: action_iterate(act_id) { struct action *paction = action_by_number(act_id); - if (action_get_activity(paction) == order->activity) { + + if (actres_get_activity(paction->result) == order->activity) { order->order = ORDER_PERFORM_ACTION; order->action = action_number(paction); order->activity = ACTIVITY_LAST; diff --git a/server/unithand.c b/server/unithand.c index 1497cfa238..89ee9d06fd 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -3261,9 +3261,9 @@ bool unit_perform_action(struct player *pplayer, break; } - if (action_get_activity(paction) != ACTIVITY_LAST + if (actres_get_activity(paction->result) != ACTIVITY_LAST && unit_activity_needs_target_from_client( - action_get_activity(paction)) + actres_get_activity(paction->result)) && target_extra == NULL) { /* Missing required action extra target. */ log_verbose("unit_perform_action() action %d requires action " @@ -6103,7 +6103,7 @@ static void unit_activity_dependencies(struct unit *punit, static bool do_action_activity(struct unit *punit, const struct action *paction) { - enum unit_activity new_activity = action_get_activity(paction); + enum unit_activity new_activity = actres_get_activity(paction->result); fc_assert_ret_val(new_activity != ACTIVITY_LAST, FALSE); fc_assert_ret_val(!activity_requires_target(new_activity), FALSE); @@ -6167,7 +6167,7 @@ static bool do_action_activity_targeted(struct unit *punit, const struct action *paction, struct extra_type **new_target) { - enum unit_activity new_activity = action_get_activity(paction); + enum unit_activity new_activity = actres_get_activity(paction->result); fc_assert_ret_val(new_activity != ACTIVITY_LAST, FALSE); fc_assert_ret_val(activity_requires_target(new_activity), -- 2.40.1