From 3f9f1a0108101d189823d093bc0e81f55ae48569 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 15 Apr 2022 18:49:08 +0300 Subject: [PATCH 09/48] rssanity: Check that there is base City_Vision_Radius_Sq effect Requested by ddeanbrown See osdn #43647 Signed-off-by: Marko Lindqvist --- doc/README.effects | 2 ++ server/rssanity.c | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/README.effects b/doc/README.effects index 41709ed2a4..a6aaca2b01 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -257,6 +257,8 @@ City_Unhappy_Size City_Vision_Radius_Sq Increase city vision radius in squared distance by amount tiles. + There must be a base effect present in the ruleset; + one with no requirements at all, i.e., always active Civil_War_Chance Base chance in per cent of a nation being split by civil war when its diff --git a/server/rssanity.c b/server/rssanity.c index 88d6d865b2..ac93aaa611 100644 --- a/server/rssanity.c +++ b/server/rssanity.c @@ -479,6 +479,12 @@ static bool sanity_check_req_vec(const struct requirement_vector *preqs, return TRUE; } +typedef struct { + struct { + bool city_vision_radius_sq; + } base_effects; +} els_data; + /**********************************************************************//** Sanity check callback for iterating effects cache. **************************************************************************/ @@ -486,8 +492,15 @@ static bool effect_list_sanity_cb(struct effect *peffect, void *data) { int one_tile = -1; /* TODO: Determine correct value from effect. * -1 disables checking */ + els_data *els = (els_data *)data; - if (peffect->type == EFT_ACTION_SUCCESS_TARGET_MOVE_COST) { + /* TODO: Refactor this to be more reusable when we check + * for more than one base effect. */ + if (peffect->type == EFT_CITY_VISION_RADIUS_SQ) { + if (requirement_vector_size(&peffect->reqs) == 0) { + els->base_effects.city_vision_radius_sq = TRUE; + } + } else if (peffect->type == EFT_ACTION_SUCCESS_TARGET_MOVE_COST) { /* Only unit targets can pay in move fragments. */ requirement_vector_iterate(&peffect->reqs, preq) { if (preq->source.kind == VUT_ACTION) { @@ -781,6 +794,7 @@ bool sanity_check_ruleset_data(bool ignore_retired) * one. */ bool default_gov_failed = FALSE; bool obsoleted_by_loop = FALSE; + els_data els; if (!sanity_check_metadata()) { ok = FALSE; @@ -990,9 +1004,17 @@ bool sanity_check_ruleset_data(bool ignore_retired) } } unit_type_iterate_end; + memset(&els, 0, sizeof(els)); + /* Check requirement sets against conflicting requirements. * For effects check also other sanity in the same iteration */ - if (!iterate_effect_cache(effect_list_sanity_cb, NULL)) { + if (!iterate_effect_cache(effect_list_sanity_cb, &els)) { + ok = FALSE; + } + + if (!els.base_effects.city_vision_radius_sq) { + ruleset_error(LOG_ERROR, + "There is no base City_Vision_Radius_Sq effect."); ok = FALSE; } -- 2.35.1