diff --git a/data/test/_main.cfg b/data/test/_main.cfg index ce2f0ad5cd8..3f9af650894 100644 --- a/data/test/_main.cfg +++ b/data/test/_main.cfg @@ -29,6 +29,10 @@ #Load test macros {test/macros} +[lua] + code = "wesnoth.dofile 'test/lua/wml_tags.lua'" +[/lua] + # Load automated test scenarios. # # They can be run individually with Wesnoth's `-u` command line option, but are usually run by diff --git a/data/test/lua/wml_tags.lua b/data/test/lua/wml_tags.lua new file mode 100644 index 00000000000..5b13a8e7af0 --- /dev/null +++ b/data/test/lua/wml_tags.lua @@ -0,0 +1,48 @@ +--! #textdomain wesnoth-test + +local T = wml.tag + +---Wrapper for [do_command][attack] that takes unit ids instead of map coordinates, +---as tests are likely to already know the id. +--- +---cfg.attacker,cfg.defender are unit ids, and map to [attack]source,destination= +---cfg.weapon,cfg.defender_weapon are optional, and map to [attack]weapon,defender_weapon= +--- +---cfg.resupply_attacks_left is an optional int, if set then it will ensure the attacker has +---at least that many attacks_left before calling [do_command][attack]. +function wesnoth.wml_actions.test_do_attack_by_id(cfg) + -- can't be called "source", otherwise wmllint wants to add translation marks + if not cfg.attacker then + wml.error("[test_do_attack] missing required attacker= attribute") + end + local attacker = wesnoth.units.find_on_map { id = cfg.attacker }[1] + if not attacker or not attacker.valid then + wml.error("[test_do_attack] attacker did not match a unit") + end + + if not cfg.defender then + wml.error("[test_do_attack] missing required defender= attribute") + end + local defender = wesnoth.units.find_on_map { id = cfg.defender }[1] + if not defender or not defender.valid then + wml.error("[test_do_attack] defender did not match a unit") + end + + local weapon = cfg.weapon or "" + local defender_weapon = cfg.defender_weapon or "" + + -- Avoid needing to modify units to give them multiple attacks per round + -- This attribute is a number rather than a boolean, to support [attack]attacks_used= + if cfg.resupply_attacks_left and attacker.attacks_left < cfg.resupply_attacks_left then + attacker.attacks_left = cfg.resupply_attacks_left + end + + wesnoth.wml_actions.do_command { + T.attack { + T.source { x = attacker.x, y = attacker.y }, + T.destination { x = defender.x, y = defender.y }, + weapon = weapon, + defender_weapon = defender_weapon, + } + } +end diff --git a/data/test/units.cfg b/data/test/units.cfg index 29086e2bb7d..4a0702449c2 100644 --- a/data/test/units.cfg +++ b/data/test/units.cfg @@ -10,7 +10,6 @@ plural_name= _ "tests" description= _ "test race" num_traits=2 - undead_variation=wolf {ORCISH_NAMES} [/race] @@ -32,4 +31,48 @@ note={INTERNAL:SPECIAL_NOTES_DEFENSE_CAP} [/special_note] [/movetype] + + # The main feature of this movetype is that it has 0% defense on all terrains, + # so there's no need to use CHANCE_TO_HIT macros. + [movetype] + name=test_movetype_no_defense + [movement_costs] + shallow_water=2 + reef=2 + swamp_water=2 + flat=2 + sand=2 + forest=2 + hills=2 + village=2 + castle=2 + cave=2 + frozen=2 + fungus=2 + [/movement_costs] + + [defense] + shallow_water=100 + reef=100 + swamp_water=100 + flat=100 + sand=100 + forest=100 + hills=100 + village=100 + castle=100 + cave=100 + frozen=100 + fungus=100 + [/defense] + + [resistance] + blade=100 + pierce=100 + impact=100 + fire=100 + cold=100 + arcane=100 + [/resistance] + [/movetype] [/units] diff --git a/data/test/units/test_melee_quintain.cfg b/data/test/units/test_melee_quintain.cfg new file mode 100644 index 00000000000..91d29fe7d28 --- /dev/null +++ b/data/test/units/test_melee_quintain.cfg @@ -0,0 +1,34 @@ +#textdomain wesnoth-test + +# A Unit with simple stats for testing attack & ability releated functions. +# +# Neutral, and a single melee attack that only has one strike. +[unit_type] + id=Test Melee Quintain + name=_ "test_unit^Test Melee Quintain" + race=test + # Image is a sword, to fit the melee-blade attack type. The icon is a non-flaming + # sword, because "-bare" is the version before the flames are added. + image="items/flame-sword-bare.png" + ignore_race_traits=yes + hitpoints=100 + movement_type=test_movetype_no_defense + movement=20 + experience=50 + level=1 + alignment=neutral + advances_to=null + cost=1 + hide_help=yes + do_not_list=yes + num_traits=0 + [attack] + name="melee_attack" + description=_"Melee Attack" + icon=attacks/sword-human.png + type=blade + range=melee + damage=10 + number=1 + [/attack] +[/unit_type]