Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix [resistance_defaults] and [terrain_defaults] (issue #5308)
The bug introduced in fcd0ced is fixed by ensuring that movetype::merge() is called with the strings "movement_costs", "vision_costs" and "jamming_costs" instead of "movement", "vision" and "jamming". Both [terrain_defaults][movement] and [terrain_defaults][movement_costs] are supported and equivalent, as added to the master branch in 3522eb2. These now work again: [resistance_defaults] id="special_res_for_test" default="30" [/resistance_defaults] [resistance_defaults] id="copy_of_arcane" default="(arcane)" [/resistance_defaults] [terrain_defaults] id="special_terrain_for_test" [movement] default="(swamp_water + 1)" orcishfoot="(swamp_water * 2)" [/movement] [/terrain_defaults] Formulas can now access other parts of the movetype too, as this allowed the code to be the same as in 1.15: [terrain_defaults] id="special_terrain_for_test" [movement_costs] default="(swamp_water + 1)" orcishfoot="(vision_costs.swamp_water * 2)" [/movement_costs] [/terrain_defaults] [terrain_defaults] id="special_terrain_for_test" [defense] default="(20 + 7 * movement_costs.special_terrain_for_test)" [/defense] [/terrain_defaults] The formula handling will recognise "resistance", "movement_costs", "vision_costs", "jamming_costs" and "defense". For [resistance_defaults], the formula will recognise both "(arcane)" and "(resistance.arcane)" as equivalent, similarly for [terrain_defaults] "(swamp_water)" is a shorthand for whichever subtag is being patched. A [terrain_defaults] tag may use data added in a previous [terrain_defaults], as in the examples above where the second tag's [defense] is based on the first tag's [movement_costs], this gives orcish grunts on the special terrain a 62% chance to be hit. However, relying on data in the same [terrain_defaults] that creates or changes it is unsupported - if the [movement_costs] and [defense] were in a single [terrain_defaults] tag then the result would be implementation defined, because no guarantee is made of the order in which the children of the tag are processed. The unit tests for [terrain_defaults] and [resistance_defaults] must stay out-of-tree until we support some method of testing them without affecting the core units' stats during other tests. The test added here is limited to checking the ways that WML can read the stats, it's also a framework for the out-of-tree parts to use. This is a squashed cherry pick of these commits from 1.15: * 72863e5 (the unit test) * 0ba4332 * 3522eb2 (adding the aliases) * 0035b77 (fix for empty children)
- Loading branch information
1 parent
8773932
commit 2b8e887
Showing
5 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# wmllint: no translatables | ||
|
||
{GENERIC_UNIT_TEST "test_resistances" ( | ||
[event] | ||
name = start | ||
|
||
[store_unit] | ||
[filter] | ||
id=alice | ||
[/filter] | ||
variable=alice | ||
[/store_unit] | ||
|
||
# Elvish archers have a slight malus against arcane | ||
{ASSERT {VARIABLE_CONDITIONAL alice.resistance.arcane equals 110}} | ||
{ASSERT {VARIABLE_CONDITIONAL alice.resistance.impact equals 100}} | ||
{ASSERT {VARIABLE_CONDITIONAL alice.resistance.length equals 1}} | ||
|
||
[store_unit] | ||
[filter] | ||
id=bob | ||
[/filter] | ||
variable=bob | ||
[/store_unit] | ||
|
||
{ASSERT {VARIABLE_CONDITIONAL bob.resistance.arcane equals 100}} | ||
{ASSERT {VARIABLE_CONDITIONAL bob.resistance.impact equals 100}} | ||
|
||
# Check that there are exactly 6 resistance types, therefore that | ||
# none have been added by a [resistance_defaults] tag. | ||
{ASSERT {VARIABLE_CONDITIONAL bob.resistance.length equals 1}} | ||
{VARIABLE key_count -1} | ||
[lua] | ||
code = << | ||
local key_count = 0 | ||
for k,v in pairs(wml.variables["bob.resistance[0]"]) do | ||
key_count = key_count + 1 | ||
end | ||
wml.variables["key_count"] = key_count | ||
>> | ||
[/lua] | ||
{ASSERT {VARIABLE_CONDITIONAL key_count equals 6}} | ||
|
||
{SUCCEED} | ||
[/event] | ||
)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters