Xalzar's WML Headaches

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.
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

Pentarctagon wrote: June 13th, 2019, 1:41 pm You are a n00b.
True. Edited previous post. :doh:
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Xalzar's WML Headaches

Post by Ravana »

Code: Select all

wesnoth.wml_actions.event{
			name="side turn",
			first_time_only=false,
			{"lua", {code="wesnoth.message(wesnoth.wml_conditionals.is_ai())"}}
		}
Is exactly same as

Code: Select all

[event]
	name="side turn"
	first_time_only=no
	[lua]
		code=<<wesnoth.message(wesnoth.wml_conditionals.is_ai())>>
	[/lua]
[/event]
Which works as

Code: Select all

[event]
	name="side turn"
	first_time_only=no
	[if]
		[is_ai]
		[/is_ai]
		[then]
			[chat]
				message="yes"
			[/chat]
		[/then]
		[else]
			[chat]
				message="no"
			[/chat]
		[/else]
	[/if]
[/event]
Only for testing.


Change

Code: Select all

[not]
				[lua]
					[is_ai]
					[/is_ai]
				[/lua]
			[/not]
			
To

Code: Select all

[not]
					[is_ai]
					[/is_ai]
			[/not]
			
It is wesnoth.wml_conditionals.is_ai that was defined, not wesnoth.wml_conditionals.lua.
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

Ahem...I don't know how to say it, but I think I've found the solution completely elsewhere.

I've found an event - ai turn - of which I ignored the existence and that helped immensely, here's the code:

Code: Select all

[event]
		name=side turn
		first_time_only=no
		[set_variable]
			name=isai
			value=no
		[/set_variable]
	[/event]
	[event]
		name=ai turn
		first_time_only=no
		[set_variable]
			name=isai
			value=yes
		[/set_variable]
	[/event]
	[event]
		name=recruit
		id=xrecruit
		first_time_only=no
		[filter_condition]
			[variable]
				name=isai
				name=isai
				equals=no
			[/variable]
		[/filter_condition]
		...
	[/event]
And it works marvelously, as far as I've tested! :D It works even if the side controller switches during the match.
If you have remarks about this, for example if you know special cases where it could cause OOS, I'd be very happy to hear you out. Let's hope there aren't though, I'm happy about the simplicity of this solution. :whistle:

On the other hand, if it is the solution I'm quite sorry for all the testing we were doing on the lua code... :oops:
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Xalzar's WML Headaches

Post by Ravana »

Wiki indicates that ai turn is unsynced. Did you test for oos?
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

Ravana wrote: June 14th, 2019, 11:53 am Wiki indicates that ai turn is unsynced. Did you test for oos?
I mean, wiki says it could only break replays at the worst. I've done some tests, all negative for OOS, but I'm no expert so I don't know if I've left something unchecked. Do you have some ideas of particular conditions which would need careful testing?
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Xalzar's WML Headaches

Post by Ravana »

Reloaded games maybe. But if common tests succeed its enough to go forward.
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

Another bump in the road: what do you experts think I should use to check if a unit is in contact to a squadron of identical units?

:eng: Let me explain: I know how to check adjacencies and unit type, my question is about strange "unit formations".
For example: I have a unit which needs to be adjacent to other same units to form a "chain" of at least 5 units to avoid a malus.
The "chain" could be compact, so for example:
-unit A adj to B,C,D
-unit B adj to A,C,D
-unit C adj to A,B,C,E
-unit D adj to A,B,C,E
-unit E adj to C,D
or linear, to the other extreme:
-unit A adj to B adj to C adj to D adj to E
...and both cases should let the unit avoid the malus.

I cannot simply check number of adjacencies and number of units in a radius, since a situation like this could happen:
-A adj to B,C
-D adj to E, inside radius 2, one hex of distance from ABC
also, the checked radius should be equal to the maximum number of units in the chain, in order for the "linear" option to be valid (in this case 5, so the disjointed chains are very possible).

Any idea to resolve this conundrum? I have some simplified, alternative ways for this ability to work if you think it's too complicated (mainly I'd check for a restricted radius so multiple little chains are impossible). But first I'd like to know if someone has a brilliant idea to do this. :D

My idea in the works is...Maybe every unit adjacent to another should get an internal variable to keep count, but then multiple adjacencies and branching chains complicate things greatly. Perhaps with the use of [for], an increasing variable (add=1 for every adjacent unit), then check from the second unit and so forth and a final check to see if the variable reaches 5? Is it too heavy to calculate? I have possibly several units with this ability. :hmm:
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Xalzar's WML Headaches

Post by josteph »

Use https://en.wikipedia.org/wiki/Breadth-first_search rooted in unit A. Keep a list of hexes you've already visited to prevent visiting a hex more than once. It'll be a few lines of lua.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Xalzar's WML Headaches

Post by mattsc »

Or, if you want a built-in WML solution, you can use [filter_radius]. Something like this should do what I think you want:

Code: Select all

[event]
    name=moveto
    first_time_only=no

    [store_locations]
        variable=n_units
        [filter]
            id=Vanak
        [/filter]
        radius=99
        [filter_radius]
            [filter]
                side=1
            [/filter]
        [/filter_radius]
    [/store_locations]

    [message]
        id=Vanak
        message="We form a group of $n_units.length units on side 1."
    [/message]
[/event]
Internally [filter_radius] probably does something like the Breadth-first search josteph suggested.
(I put this into a moveto event simply for ease of testing.)
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

[filter_radius]: a standard location filter; normally the radius extends outwards from matching locations one step at a time without checking any additional information-- however, if this tag is present, the radius will be restricted so that it can only expand outwards in the directions where it passes the given location filter
In hindsight, reading this again, I could have inferred that using a [filter] I would have been able to "snake" the filter through the unit chain.
I've never thought to use it as you exemplified...I must say, that's quite a genius move! :shock: :D

Thank you both! :)
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

A more "conceptual" question: what is the meaning of min_range and max_range inside [attack]? I've not yet found a description of these keys in the wiki... Am I blind? :oops:
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Xalzar's WML Headaches

Post by Ravana »

It shows how many tiles away that attack may be used. It has almost no in-game significance, since official client does not support sending commands to attack from non-adjacent tile.

https://github.com/wesnoth/wesnoth/issues/3262
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

So I guess it's for modding...but I've never seen anybody use these for non-adjacent attacks, why were they added? How do they work? Why there is no documentation about these? :hmm:
User avatar
Ravana
Forum Moderator
Posts: 2995
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Xalzar's WML Headaches

Post by Ravana »

I remember from somewhere that before version 1.0 wesnoth supported ranged attacks. But these specific attributes are from 2011 - planned support for ranged attack that was not completed? The linked issue contains info that I found when trying out how the attributes worked.

Basically, unless you write bot or custom wesnoth client, these attributes have no use.
User avatar
Xalzar
Posts: 310
Joined: April 4th, 2009, 10:03 pm
Location: New Saurgrath

Re: Xalzar's WML Headaches

Post by Xalzar »

Thought that was probably the case, many thanks Ravana!
Post Reply