how to use opponent's terrain to calculate own defense?

The place to post your WML questions and answers.

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.
Post Reply
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

how to use opponent's terrain to calculate own defense?

Post by lea »

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?
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)
User avatar
lhybrideur
Posts: 379
Joined: July 9th, 2019, 1:46 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lhybrideur »

Maybe creating an ability or a weapon special that would use enemy's terrain as defense or to modify defense would work.
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

lhybrideur 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.
it is easy to modify defense in weapon special by modifying opponent's chance to hit
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)
User avatar
Ravana
Forum Moderator
Posts: 3075
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: how to use opponent's terrain to calculate own defense?

Post by Ravana »

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]
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

Ravana wrote: July 21st, 2023, 5:34 pm Use self+other or attacker+defender and chance_to_hit/defense_on according to what fits your needs best.
... ... ...
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)
User avatar
Ravana
Forum Moderator
Posts: 3075
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: how to use opponent's terrain to calculate own defense?

Post by Ravana »

Yes.
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

following parameters for [chance_to_hit] special seem to do the trick:

Code: Select all

    value="(100-defense_on(self, other.loc))"
    apply_to=opponent
    active_on=offense
except it works only under wesnoth 1.14.x and later

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)
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

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
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)
User avatar
ForestDragon
Posts: 1785
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: how to use opponent's terrain to calculate own defense?

Post by ForestDragon »

lea 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
[filter_attacker][filter_weapon] might help https://wiki.wesnoth.org/FilterWML#Filtering_Weapons, https://wiki.wesnoth.org/AbilitiesWML
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
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

ForestDragon 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
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 it
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)
lea
Posts: 301
Joined: October 1st, 2016, 7:25 pm

Re: how to use opponent's terrain to calculate own defense?

Post by lea »

Ravana wrote: July 21st, 2023, 5:34 pm

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
what this commented line is for?
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)
User avatar
Ravana
Forum Moderator
Posts: 3075
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: how to use opponent's terrain to calculate own defense?

Post by Ravana »

Post Reply