how to use opponent's terrain to calculate own defense?
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
how to use opponent's terrain to calculate own defense?
unit's defense depends on terrain it stands on
how to use terrain other than the one unit is currently standing on?
the idea is to use enemy's terrain for determining attacker's defense for close combat encounters, implying that attacking unit has to enter opponent's tile to perform melee attack
https://wiki.wesnoth.org/StandardUnitFilter allows to filter by unit's defense and it is probably possible to temporarily replace terrain under it when combat starts but how to make AI take it into account?
one approach that may work is covering entire map with [time_area]'s (https://wiki.wesnoth.org/DirectActionsW ... me_area.5D, one per general terrain type like flat or forest) that do not actually change time of day but instead are used in https://wiki.wesnoth.org/StandardLocationFilter
but this approach seems to be extremely cumbersome - any other ways to achieve that?
how to use terrain other than the one unit is currently standing on?
the idea is to use enemy's terrain for determining attacker's defense for close combat encounters, implying that attacking unit has to enter opponent's tile to perform melee attack
https://wiki.wesnoth.org/StandardUnitFilter allows to filter by unit's defense and it is probably possible to temporarily replace terrain under it when combat starts but how to make AI take it into account?
one approach that may work is covering entire map with [time_area]'s (https://wiki.wesnoth.org/DirectActionsW ... me_area.5D, one per general terrain type like flat or forest) that do not actually change time of day but instead are used in https://wiki.wesnoth.org/StandardLocationFilter
but this approach seems to be extremely cumbersome - any other ways to achieve that?
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
- lhybrideur
- Posts: 379
- Joined: July 9th, 2019, 1:46 pm
Re: how to use opponent's terrain to calculate own defense?
Maybe creating an ability or a weapon special that would use enemy's terrain as defense or to modify defense would work.
Re: how to use opponent's terrain to calculate own defense?
it is easy to modify defense in weapon special by modifying opponent's chance to hitlhybrideur wrote: ↑July 21st, 2023, 11:03 am Maybe creating an ability or a weapon special that would use enemy's terrain as defense or to modify defense would work.
the problem is how to tie amount of accuracy/defense to opponent's terrain
it is also (probably) possible to change terrain under attacker to same as one under defender when combat starts and change it back to original one right after combat BUT it will not show in combat estimation window (one where player gets to choose which weapon will be used) and consequently AI will not be able to take it into account
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
Re: how to use opponent's terrain to calculate own defense?
Use self+other or attacker+defender and chance_to_hit/defense_on according to what fits your needs best.
Code: Select all
# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
[modify_unit]
[filter]
[/filter]
[object]
[effect]
apply_to=attack
[set_specials]
[chance_to_hit]
value="(chance_to_hit(self, other.loc))"
value="(defense_on(self, other.loc))"
apply_to=self
active_on=offense
[/chance_to_hit]
[/set_specials]
[/effect]
[/object]
[/modify_unit]
Re: how to use opponent's terrain to calculate own defense?
thanks, going to try it
is it https://wiki.wesnoth.org/Wesnoth_Formula_Language used in your example after "value="?
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
Re: how to use opponent's terrain to calculate own defense?
following parameters for [chance_to_hit] special seem to do the trick:
except it works only under wesnoth 1.14.x and later
going to search for some other way for older versions of wesnoth
Code: Select all
value="(100-defense_on(self, other.loc))"
apply_to=opponent
active_on=offense
going to search for some other way for older versions of wesnoth
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
Re: how to use opponent's terrain to calculate own defense?
EDIT: weapon special described above overrides fixed chance to hit specials like mainline's "magical" weapon special when fixed chance to hit is lower than one yielded by above formula, like when defender is land unit standing in water
yet to find how to counter this issue
yet to find how to counter this issue
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
- ForestDragon
- Posts: 1785
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: how to use opponent's terrain to calculate own defense?
[filter_attacker][filter_weapon] might help https://wiki.wesnoth.org/FilterWML#Filtering_Weapons, https://wiki.wesnoth.org/AbilitiesWMLlea wrote: ↑November 5th, 2023, 6:06 pm EDIT: weapon special described above overrides fixed chance to hit specials like mainline's "magical" weapon special when fixed chance to hit is lower than one yielded by above formula, like when defender is land unit standing in water
yet to find how to counter this issue
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Re: how to use opponent's terrain to calculate own defense?
it does help with specials that set purely fixed chance to hit (like "magical" in mainline) but not ones that are intended to limit maximum chance to hit (like "unreliable" in "Altera", no suitable example in mainline) since these should cap "incoming" value rather than ignore itForestDragon wrote: ↑November 5th, 2023, 6:39 pm[filter_attacker][filter_weapon] might help https://wiki.wesnoth.org/FilterWML#Filtering_Weapons, https://wiki.wesnoth.org/AbilitiesWML
ability to filter "incoming" value instead of base value would help but no idea how to implement such filter
maybe can construct something with "if" clause and "min" function from formula language - going to try it when will have enough free time
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
Re: how to use opponent's terrain to calculate own defense?
what this commented line is for?Ravana wrote: ↑July 21st, 2023, 5:34 pmCode: Select all
# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
did it somehow help with debugging?
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)