Xalzar's WML Headaches
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.
Re: Xalzar's WML Headaches
True. Edited previous post.
Re: Xalzar's WML Headaches
Code: Select all
wesnoth.wml_actions.event{
name="side turn",
first_time_only=false,
{"lua", {code="wesnoth.message(wesnoth.wml_conditionals.is_ai())"}}
}
Code: Select all
[event]
name="side turn"
first_time_only=no
[lua]
code=<<wesnoth.message(wesnoth.wml_conditionals.is_ai())>>
[/lua]
[/event]
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]
Change
Code: Select all
[not]
[lua]
[is_ai]
[/is_ai]
[/lua]
[/not]
Code: Select all
[not]
[is_ai]
[/is_ai]
[/not]
Re: Xalzar's WML Headaches
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:
And it works marvelously, as far as I've tested! 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.
On the other hand, if it is the solution I'm quite sorry for all the testing we were doing on the lua code...
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]
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.
On the other hand, if it is the solution I'm quite sorry for all the testing we were doing on the lua code...
Re: Xalzar's WML Headaches
Wiki indicates that ai turn is unsynced. Did you test for oos?
Re: Xalzar's WML Headaches
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?
Re: Xalzar's WML Headaches
Reloaded games maybe. But if common tests succeed its enough to go forward.
Re: Xalzar's WML Headaches
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?
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.
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.
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.
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.
Re: Xalzar's WML Headaches
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.
Re: Xalzar's WML Headaches
Or, if you want a built-in WML solution, you can use
Internally
(I put this into a moveto event simply for ease of testing.)
[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]
[filter_radius]
probably does something like the Breadth-first search josteph suggested.(I put this into a moveto event simply for ease of testing.)
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Xalzar's WML Headaches
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.[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
I've never thought to use it as you exemplified...I must say, that's quite a genius move!
Thank you both!
Re: Xalzar's WML Headaches
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?
Re: Xalzar's WML Headaches
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
https://github.com/wesnoth/wesnoth/issues/3262
Re: Xalzar's WML Headaches
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?
Re: Xalzar's WML Headaches
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.
Basically, unless you write bot or custom wesnoth client, these attributes have no use.
Re: Xalzar's WML Headaches
Thought that was probably the case, many thanks Ravana!