From 0ed6c8ee969ece1eef6687f28a1b46c0a7713d50 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 19 Feb 2021 23:24:44 +0100 Subject: [PATCH 9/9] ruleup: purge unused effects by default. Support deleting unused effects in ruleset_purge_unused_entities(). See osdn #41620 --- common/effects.c | 3 +++ common/effects.h | 4 ++++ server/ruleset.c | 24 ++++++++++++++++++++++++ tools/ruleutil/rulesave.c | 5 +++++ 4 files changed, 36 insertions(+) diff --git a/common/effects.c b/common/effects.c index 3ea0902142..88876f2321 100644 --- a/common/effects.c +++ b/common/effects.c @@ -185,6 +185,9 @@ struct effect *effect_new(enum effect_type type, int value, effect_list_append(ruleset_cache.tracker, peffect); effect_list_append(get_effects(type), peffect); + /* Only relevant for ruledit and other rulesave users. */ + peffect->ruledit_do_not_save = FALSE; + return peffect; } diff --git a/common/effects.h b/common/effects.h index a0536509d2..776d6169c0 100644 --- a/common/effects.h +++ b/common/effects.h @@ -335,6 +335,10 @@ struct effect { /* An effect can have multiple requirements. The effect will only be * active if all of these requirement are met. */ struct requirement_vector reqs; + + /* Only relevant for rueldit and other rulesave users. Indicates that + * this effect is deleted and shouldn't saved. */ + bool ruledit_do_not_save; }; /* An effect_list is a list of effects. */ diff --git a/server/ruleset.c b/server/ruleset.c index 2800216939..a465be3c41 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -259,6 +259,29 @@ static int ruleset_purge_unused_enablers(void) return purged; } +/**********************************************************************//** + Purge unused effects from the ruleset. +**************************************************************************/ +static int ruleset_purge_unused_effects(void) +{ + int purged = 0; + enum effect_type type; + + for (type = effect_type_begin(); type != effect_type_end(); + type = effect_type_next(type)) { + effect_list_iterate(get_effects(type), eft) { + if (req_vec_is_impossible_to_fulfill(&eft->reqs)) { + eft->ruledit_do_not_save = TRUE; + purged++; + log_normal("Purged unused effect for %s", + effect_type_name(eft->type)); + } + } effect_list_iterate_end; + } + + return purged; +} + /**********************************************************************//** Purge unused entities from the ruleset. **************************************************************************/ @@ -267,6 +290,7 @@ int ruleset_purge_unused_entities(void) int purged = 0; purged += ruleset_purge_unused_enablers(); + purged += ruleset_purge_unused_effects(); return purged; } diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 1a70765c78..a9f164799b 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -762,6 +762,11 @@ static bool effect_save(struct effect *peffect, void *data) effect_cb_data *cbdata = (effect_cb_data *)data; char path[512]; + if (peffect->ruledit_do_not_save) { + /* Is supposed to be skipped. */ + return TRUE; + } + fc_snprintf(path, sizeof(path), "effect_%d", cbdata->idx++); secfile_insert_str(cbdata->sfile, -- 2.20.1