WML RESOURCES by enclave

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
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: WML RESOURCES by enclave

Post by tekelili »

enclave wrote:Adding some ability to some unit at coordinates x,y=5,3
Here we will try to add LEADERSHIP LVL2
I want to point that giving leadership this way can be problematic after unit advances. In WC II I have a way to give leadership to any unit and manage it after unit advances (using into [object])

Code: Select all

#define WCT_LEADERSHIP_X LEVEL
[effect]
    [filter]
        level={LEVEL}
    [/filter]
    apply_to=new_ability
    [abilities]
        {ABILITY_LEADERSHIP_LEVEL_{LEVEL}}
    [/abilities]
[/effect]
#enddef

#define WCT_LEADERSHIP
    {WCT_LEADERSHIP_X 1}
    {WCT_LEADERSHIP_X 2}
    {WCT_LEADERSHIP_X 3}
    {WCT_LEADERSHIP_X 4}
#enddef
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Thanks tekelili, an interesting and useful example ;)
It would be a lot more efford and pain to do it my way in your case:

Code: Select all

#define WCT_LEADERSHIP_X LEVEL
[store_unit]
[filter]
level={LEVEL}
[/filter]
variable=temp_unit_level{LEVEL}
[/store_unit]
{FOREACH temp_unit_level{LEVEL} counter_i}
{INSERT_LEADERSHIP_LVL{LEVEL}_ABILITY_INTO_UNIT_ARRAY temp_unit_level{LEVEL}[$counter_i]}
{NEXT counter_i}
#enddef

#define WCT_LEADERSHIP
    {WCT_LEADERSHIP_X 1}
    {WCT_LEADERSHIP_X 2}
    {WCT_LEADERSHIP_X 3}
    {WCT_LEADERSHIP_X 4}
#enddef
And it would also require these defines.. plus define for each level
Spoiler:
Thanks zookeeper! It would be great to have a part of wiki with many examples of codes like we do here.. very useful!
Sometimes there is big lack of examples when I'm trying something new.. like [filter_vision] and such.. rare things.
You can remove abilities via direct variable manipulation like you did, but I think then they might suddenly re-appear when the unit gets unexpectedly rebuilt in some situation. You should generally do things like that with an [object] unless there's a specific reason not to.
unexpectedly rebuilt? do you know any example situation? I would really like to know in which cases it might happen.. would be very useful. And also you think, or it really happens? Thanks very much in advance!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML RESOURCES by enclave

Post by zookeeper »

enclave wrote:unexpectedly rebuilt? do you know any example situation? I would really like to know in which cases it might happen.. would be very useful. And also you think, or it really happens? Thanks very much in advance!
Eh, I'm not sure about situations other than advancement.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

zookeeper wrote:
enclave wrote:unexpectedly rebuilt? do you know any example situation? I would really like to know in which cases it might happen.. would be very useful. And also you think, or it really happens? Thanks very much in advance!
Eh, I'm not sure about situations other than advancement.
Ok, nice to know anyway ;) Thanks!
User avatar
Celtic_Minstrel
Developer
Posts: 1759
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML RESOURCES by enclave

Post by Celtic_Minstrel »

enclave wrote: unexpectedly rebuilt? do you know any example situation? I would really like to know in which cases it might happen.. would be very useful. And also you think, or it really happens? Thanks very much in advance!
Advancing to a different unit type is the main situation where a unit might get rebuilt. I'm not sure if loading a game or recalling a unit rebuilds it (possibly not, though I recall having some issues related to that). It's also rebuilt if you change its variation (usually with an [object], I think) or use [transform_unit]. It's not rebuilt if it gets an AMLA.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: WML RESOURCES by enclave

Post by gfgtdf »

its also rebuild if an object is removed because the duration= expires.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Celtic_Minstrel
Developer
Posts: 1759
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML RESOURCES by enclave

Post by Celtic_Minstrel »

Which includes use of [remove_object] in 1.13.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Thanks very much guys ;)

Back to business...
If anyone needs to filter mounted unit types then here we go:
Spoiler:
Just easier when you don't need to find and write all these unit types yourself.. they already there for your convenience.. copy paste.. what can be easier? :) I found a nice source here: https://units.wesnoth.org/1.12/mainline ... nline.html

PS. the codes in the spoiler may not work properly.. I have not tested them but I assume they work, let me know if not if you trying to use them.
Last edited by enclave on October 7th, 2016, 7:02 pm, edited 1 time in total.
User avatar
Ravana
Forum Moderator
Posts: 2479
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML RESOURCES by enclave

Post by Ravana »

Hardcoding unit types... meaning it will only ever apply to one version of one era. Not good for a resource.

Resource is not indented. Unstore unstores one. Not all units are recruited see https://wiki.wesnoth.org/EventWML#unit_ ... er_only.29. Not all mounted units are recruited as mounted units. Not all mounted units remain as mounted units. Not all variations of single unit type have same state of mountedness.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Ravana wrote:Hardcoding unit types... meaning it will only ever apply to one version of one era. Not good for a resource.

Resource is not indented. Unstore unstores one. Not all units are recruited see https://wiki.wesnoth.org/EventWML#unit_ ... er_only.29. Not all mounted units are recruited as mounted units. Not all mounted units remain as mounted units. Not all variations of single unit type have same state of mountedness.
well I guess my example really bad, all I wanted is to give people a list of mounted unit types that they can just copy paste into their filter to, for example, give double damage vs mounted units.. to their spearman. Before I found the link I provided I was just going into wesnoth core and was opening every single cfg for every single unit to get their "type".. which was a long and annoying work.
User avatar
Celtic_Minstrel
Developer
Posts: 1759
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML RESOURCES by enclave

Post by Celtic_Minstrel »

Zombies mean you can't match mounted units with a simple list of types. If you want a filter that will match all core mounted units, you need something like this:

Code: Select all

[filter]
    type=Cavalryman,Dragoon,Cavalier,Horseman,Knight,Lancer,Grand Knight,Paladin,Elvish Scout,Elvish Rider,Elvish Outrider,Khaiyal,Faris,Qanas,Mufariq,Hadaf,Rami,Saree,Jawal,Chocobone,Wolf Rider,Goblin Knight,Goblin Pillager,Direwolf Rider,Gryphon Rider,Gryphon Master
    [or]
        type=Walking Corpse,Soulless
        variation=mounted
    [/or]
[/filter]
By the way, wolves are not mounted creatures, so including them in your filter is quite silly. I omitted them from mine. You also forgot the gryphons.

It can also be simplified in 1.13 using the new type_tree attribute:

Code: Select all

[filter]
    type_tree=Elvish Scout,Cavalryman,Horseman,Khaiyal,Rami,Chocobone,Wolf Rider,Gryphon Rider
    [or]
        type_tree=Walking Corpse
        variation=mounted
    [/or]
[/filter]
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: WML RESOURCES by enclave

Post by enclave »

Thanks very much Celtic_Minstrel, thats really useful! ;)

Back to topic..
Working with arrays
a) Rename arrays
b) Copy arrays
c) inserting arrays etc..
have fun..

a) Renaming arrays

Code: Select all

#define RENAME_ARRAY ARRAY_OLD_NAME ARRAY_NEW_NAME
[set_variables]
name={ARRAY_NEW_NAME}
mode=replace
[insert_tag]
name=value
variable={ARRAY_OLD_NAME}
[/insert_tag]
[/set_variables]
{CLEAR_VARIABLE {ARRAY_OLD_NAME}}
#enddef
b) Copying arrays

Code: Select all

#define COPY_WHOLE_ARRAY ARRAY_OLD_NAME ARRAY_NEW_NAME
[set_variables]
name={ARRAY_NEW_NAME}
mode=replace
[insert_tag]
name=value
variable={ARRAY_OLD_NAME}
[/insert_tag]
[/set_variables]
#enddef
c) Inserting arrays etc

Code: Select all

#define INSERT_ARRAY_TO_ARRAY ARRAY_1 TO_ARRAY_2
[set_variables]
name={TO_ARRAY_2}
mode=insert
[insert_tag]
name=value
variable={ARRAY_1}
[/insert_tag]
[/set_variables]
#enddef

#define MERGE_ARRAY_TO_ARRAY ARRAY_1 TO_ARRAY_2
[set_variables]
name={TO_ARRAY_2}
mode=merge
[insert_tag]
name=value
variable={ARRAY_1}
[/insert_tag]
[/set_variables]
#enddef

#define APPEND_ARRAY_TO_ARRAY ARRAY_1 TO_ARRAY_2
[set_variables]
name={TO_ARRAY_2}
mode=append
[insert_tag]
name=value
variable={ARRAY_1}
[/insert_tag]
[/set_variables]
#enddef
Then just use them like any macro like so: {RENAME_ARRAY old_name new_name}

There is more options in wiki: https://wiki.wesnoth.org/InternalAction ... riables.5D
you can insert into specified index.. and I think if you don't specify mode, it defaults to replace.
Maybe you could do similar with "to_variable", but it's possible that I have already tried and failed, I can't remember.
Post Reply