From 93282c94dcb7acf332bf714de0b10413eec7d8de Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Apr 2023 19:17:52 +0300 Subject: [PATCH 39/39] Add initial internal actions support See osdn #47810 Signed-off-by: Marko Lindqvist --- common/actions.c | 31 ++++++++++++++++++++++++++++--- common/actions.h | 7 ++++++- server/ruleset.c | 2 +- tools/ruleutil/rulesave.c | 9 ++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/common/actions.c b/common/actions.c index cc63840795..acced0ac7e 100644 --- a/common/actions.c +++ b/common/actions.c @@ -1864,10 +1864,10 @@ const char *action_rule_name(const struct action *action) to the call. Copy the result if you want it to remain valid over another call to this function. **************************************************************************/ -const char *action_name_translation(const struct action *action) +const char *action_name_translation(const struct action *paction) { /* Use action_id_name_translation() to format the UI name. */ - return action_id_name_translation(action->id); + return action_id_name_translation(paction->id); } /**********************************************************************//** @@ -1955,6 +1955,8 @@ const char *action_prepare_ui_name(action_id act_id, const char *mnemonic, /* Text representation of the probability. */ const char *probtxt; + fc_assert(!action_id_is_internal(act_id)); + if (!actions_are_ready()) { /* Could be a client who haven't gotten the ruleset yet */ @@ -6568,8 +6570,9 @@ static bool action_has_possible_actor_hard_reqs(struct action *paction) /**********************************************************************//** Returns TRUE if the specified action may be enabled in the current ruleset. + @param paction the action to check if is in use. - @returns TRUE if the action could be enabled in the current ruleset. + @return TRUE if the action could be enabled in the current ruleset. **************************************************************************/ bool action_is_in_use(struct action *paction) { @@ -6591,6 +6594,28 @@ bool action_is_in_use(struct action *paction) return FALSE; } +/**********************************************************************//** + Is the action for freeciv's internal use only? + + @param paction The action to check + @return Whether action is for internal use only +**************************************************************************/ +bool action_is_internal(struct action *paction) +{ + return action_has_result(paction, ACTRES_ENABLER_CHECK); +} + +/**********************************************************************//** + Is action by id for freeciv's internal use only? + + @param act Id of the action to check + @return Whether action is for internal use only +**************************************************************************/ +bool action_id_is_internal(action_id act) +{ + return action_is_internal(action_by_number(act)); +} + /**********************************************************************//** Returns action auto performer rule slot number num so it can be filled. **************************************************************************/ diff --git a/common/actions.h b/common/actions.h index 131938206d..95c6ae287a 100644 --- a/common/actions.h +++ b/common/actions.h @@ -261,6 +261,8 @@ const char *gen_action_name_update_cb(const char *old_name); /* TODO: Move next to "Move" */ #define SPECENUM_VALUE112 ACTION_TELEPORT #define SPECENUM_VALUE112NAME "Teleport" + +/* User actions */ #define SPECENUM_VALUE113 ACTION_USER_ACTION1 #define SPECENUM_VALUE113NAME "User Action 1" #define SPECENUM_VALUE114 ACTION_USER_ACTION2 @@ -666,7 +668,7 @@ enum unit_activity action_get_activity(const struct action *paction); const char *action_rule_name(const struct action *action); const char *action_id_rule_name(action_id act_id); -const char *action_name_translation(const struct action *action); +const char *action_name_translation(const struct action *paction); const char *action_id_name_translation(action_id act_id); const char *action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic); @@ -907,6 +909,9 @@ bool action_mp_full_makes_legal(const struct unit *actor, bool action_is_in_use(struct action *paction); +bool action_is_internal(struct action *paction); +bool action_id_is_internal(action_id act); + /* Action lists */ void action_array_end(action_id *act_array, int size); void action_array_add_all_by_result(action_id *act_array, diff --git a/server/ruleset.c b/server/ruleset.c index 37a08e9911..d88f0d4521 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -7628,7 +7628,7 @@ static bool load_ruleset_actions(struct section_file *file, ok = FALSE; } else if (!load_action_actor_consuming_always(file, act_id)) { ok = FALSE; - } else { + } else if (!action_id_is_internal(act_id)) { load_action_ui_name(file, act_id, action_ui_name_ruleset_var_name(act_id)); } diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index a2ff7480f7..430741c83f 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -866,7 +866,14 @@ static bool save_effects_ruleset(const char *filename, const char *name) static bool save_action_ui_name(struct section_file *sfile, int act, const char *entry_name) { - const char *ui_name = action_by_number(act)->ui_name; + struct action *paction = action_by_number(act); + const char *ui_name; + + if (action_is_internal(paction)) { + return TRUE; + } + + ui_name = paction->ui_name; if (ui_name == NULL) { fc_assert(ui_name != NULL); -- 2.39.2