From 054be122100df2f2793f40508adcaade1d37cf3d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 5 Jan 2022 04:26:03 +0200 Subject: [PATCH 21/21] Sanity check transform_result and transform_time consistency No longer just correct inconsistent transform_result and transform_time from the ruleset, but consider it an error. See osdn #42256 Signed-off-by: Marko Lindqvist --- data/alien/terrain.ruleset | 2 +- data/civ1/terrain.ruleset | 2 +- data/civ2/terrain.ruleset | 2 +- data/civ2civ3/terrain.ruleset | 2 +- data/classic/terrain.ruleset | 2 +- data/experimental/terrain.ruleset | 2 +- data/granularity/terrain.ruleset | 2 +- data/multiplayer/terrain.ruleset | 2 +- data/ruledit/comments-3.1.txt | 2 +- data/sandbox/terrain.ruleset | 2 +- data/stub/terrain.ruleset | 2 +- data/webperimental/terrain.ruleset | 2 +- server/ruleset.c | 22 ++++++++++++++-------- 13 files changed, 26 insertions(+), 20 deletions(-) diff --git a/data/alien/terrain.ruleset b/data/alien/terrain.ruleset index b209f6a8cf..8cabfc9978 100644 --- a/data/alien/terrain.ruleset +++ b/data/alien/terrain.ruleset @@ -137,7 +137,7 @@ ocean_resources = TRUE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/civ1/terrain.ruleset b/data/civ1/terrain.ruleset index 5e159868d4..6ae03c63bb 100644 --- a/data/civ1/terrain.ruleset +++ b/data/civ1/terrain.ruleset @@ -131,7 +131,7 @@ igter_cost = 1 ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/civ2/terrain.ruleset b/data/civ2/terrain.ruleset index f13cf2b686..576ed96af1 100644 --- a/data/civ2/terrain.ruleset +++ b/data/civ2/terrain.ruleset @@ -131,7 +131,7 @@ pythagorean_diagonal = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/civ2civ3/terrain.ruleset b/data/civ2civ3/terrain.ruleset index 77a1bf28e9..cd58dee34f 100644 --- a/data/civ2civ3/terrain.ruleset +++ b/data/civ2civ3/terrain.ruleset @@ -143,7 +143,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/classic/terrain.ruleset b/data/classic/terrain.ruleset index ce0329ec44..49f8bd91f6 100644 --- a/data/classic/terrain.ruleset +++ b/data/classic/terrain.ruleset @@ -136,7 +136,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/experimental/terrain.ruleset b/data/experimental/terrain.ruleset index 5355d31dfa..82e516abde 100644 --- a/data/experimental/terrain.ruleset +++ b/data/experimental/terrain.ruleset @@ -138,7 +138,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/granularity/terrain.ruleset b/data/granularity/terrain.ruleset index 3bde92a408..89fd6b9569 100644 --- a/data/granularity/terrain.ruleset +++ b/data/granularity/terrain.ruleset @@ -133,7 +133,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/multiplayer/terrain.ruleset b/data/multiplayer/terrain.ruleset index 93266a44c4..577536601b 100644 --- a/data/multiplayer/terrain.ruleset +++ b/data/multiplayer/terrain.ruleset @@ -136,7 +136,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/ruledit/comments-3.1.txt b/data/ruledit/comments-3.1.txt index 4dd35d921b..75312da7a7 100644 --- a/data/ruledit/comments-3.1.txt +++ b/data/ruledit/comments-3.1.txt @@ -615,7 +615,7 @@ terrains = "\ ; \"no\" -- cannot transform\n\ ; terrain rule_name -- transformation changes to that\n\ ; terrain\n\ -; transform_time = time to transform; if 0, cannot transform\n\ +; transform_time = time to transform\n\ ; placing_time = time for \'placing\' an extra; if 0, cannot place\n\ ; Nonzero values only affect extras with build_time 0.\n\ ; Such extras can modify time with build_time_factor.\n\ diff --git a/data/sandbox/terrain.ruleset b/data/sandbox/terrain.ruleset index 37d8039fc6..63a7c54693 100644 --- a/data/sandbox/terrain.ruleset +++ b/data/sandbox/terrain.ruleset @@ -144,7 +144,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/stub/terrain.ruleset b/data/stub/terrain.ruleset index 7f526069f6..586701dec5 100644 --- a/data/stub/terrain.ruleset +++ b/data/stub/terrain.ruleset @@ -124,7 +124,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/data/webperimental/terrain.ruleset b/data/webperimental/terrain.ruleset index 6156a5c664..c6cc5173d8 100644 --- a/data/webperimental/terrain.ruleset +++ b/data/webperimental/terrain.ruleset @@ -136,7 +136,7 @@ ocean_resources = FALSE ; "no" -- cannot transform ; terrain rule_name -- transformation changes to that ; terrain -; transform_time = time to transform; if 0, cannot transform +; transform_time = time to transform ; placing_time = time for 'placing' an extra; if 0, cannot place ; Nonzero values only affect extras with build_time 0. ; Such extras can modify time with build_time_factor. diff --git a/server/ruleset.c b/server/ruleset.c index 54217fa700..5fdf16ee7e 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3434,16 +3434,22 @@ static bool load_ruleset_terrain(struct section_file *file, ok = FALSE; break; } - if (pterrain->transform_time <= 0) { - /* Transform time of zero is documented to disable the transform - * regardless of given transform result. That's fine, but in the - * future we may consider it an error to give combination of - * transform_result and transform_time where one indicates it's - * enabled and the other that it's not. - * Note that we already strip transform_result when doing ruleup - * from older ruleset that has such a construct. */ + if (compat->compat_mode && compat->ver_terrain < RSFORMAT_3_1 + && pterrain->transform_time <= 0) { + /* Transform time of zero was documented to disable the transform + * regardless of given transform result in earlier versions, i.e., + * having them inconsistent was not an error. */ pterrain->transform_result = NULL; } + if ((pterrain->transform_result != NULL + && pterrain->transform_time <= 0) + || (pterrain->transform_result == NULL + && pterrain->transform_time > 0)) { + ruleset_error(LOG_ERROR, "%s: transform_result and transform_time disagree " + "whether transforming is enabled", tsection); + ok = FALSE; + break; + } pterrain->placing_time = 1; /* default */ lookup_time(file, &pterrain->placing_time, -- 2.34.1