From c6562429998fcd17ead40a2f33a16dd84522da11 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 19 Feb 2021 19:48:07 +0100 Subject: [PATCH 4/6] Support purging unused action enablers. Introduce ruleset_purge_unused_entities(). All it does right now is to purge unused action enablers. See osdn #41614 --- server/ruleset.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ server/ruleset.h | 2 ++ 2 files changed, 54 insertions(+) diff --git a/server/ruleset.c b/server/ruleset.c index 5ef2ed0423..2800216939 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -219,6 +219,58 @@ void ruleset_error_real(const char *file, const char *function, } } +/**********************************************************************//** + Purge unused action enablers from the ruleset. +**************************************************************************/ +static int ruleset_purge_unused_enablers(void) +{ + int purged = 0; + + action_iterate(act_id) { + struct action *paction = action_by_number(act_id); + + /* Impossible hard requirement. */ + if (!action_is_in_use(paction)) { + /* Make sure that all action enablers are disabled. */ + action_enabler_list_iterate(action_enablers_for_action(paction->id), + ae) { + ae->disabled = TRUE; + purged++; + } action_enabler_list_iterate_end; + + log_normal("Purged all action enablers for %s", + action_rule_name(paction)); + } + + /* Impossible requirement vector requirement. */ + action_enabler_list_iterate(action_enablers_for_action(paction->id), + ae) { + if (!ae->disabled + && (req_vec_is_impossible_to_fulfill(&ae->actor_reqs) + || req_vec_is_impossible_to_fulfill(&ae->target_reqs))) { + ae->disabled = TRUE; + purged++; + log_normal("Purged unused action enabler for %s", + action_rule_name(paction)); + } + } action_enabler_list_iterate_end; + } action_iterate_end; + + return purged; +} + +/**********************************************************************//** + Purge unused entities from the ruleset. +**************************************************************************/ +int ruleset_purge_unused_entities(void) +{ + int purged = 0; + + purged += ruleset_purge_unused_enablers(); + + return purged; +} + /**********************************************************************//** datafilename() wrapper: tries to match in two ways. Returns NULL on failure, the (statically allocated) filename on success. diff --git a/server/ruleset.h b/server/ruleset.h index 7b3cd06467..f886e3db45 100644 --- a/server/ruleset.h +++ b/server/ruleset.h @@ -60,6 +60,8 @@ void ruleset_error_real(const char *file, const char *function, char *get_script_buffer(void); char *get_parser_buffer(void); +int ruleset_purge_unused_entities(void); + /* Default ruleset values that are not settings (in game.h) */ #define GAME_DEFAULT_ADDTOSIZE 9 -- 2.20.1