How to get information about the era in WML?

The place to post your WML questions and answers.

Moderators: Developers, 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 get information about the era in WML?

Postby iceiceice » October 15th, 2013, 5:23 pm

Is there any way to get the information in the era tag, (or for that matter, in any other high level tag,) into variables in WML? I'm looking for something like "[store_multiplayer_sides]" which would give an array of factions in this era, but lacking this is there some kind of workaround?
iceiceice
Developer
 
Posts: 339
Joined: August 23rd, 2013, 2:10 am

Re: How to get information about the era in WML?

Postby Anonymissimus » October 15th, 2013, 7:14 pm

Not sure whether the following is what you're looking for...

This is from data/multiplayer/scenarios/2p_Hornshark_Island.cfg:
Code: Select all
    [event]
        name=prestart

        [set_variables]
            name=factions
            [value]
                {multiplayer/factions/drakes-default.cfg}
                {multiplayer/factions/knalgans-default.cfg}
                {multiplayer/factions/loyalists-default.cfg}
                {multiplayer/factions/northerners-default.cfg}
                {multiplayer/factions/rebels-default.cfg}
                {multiplayer/factions/undead-default.cfg}
            [/value]
        [/set_variables]
#...
        {CLEAR_VARIABLE factions}
    [/event]

It is done there to know the unit types composition of the factions.

Use the :inspect debug command to look whether you find the information needed in the array created. You can do similar with all kinds of wml (such as an addon era), and use :inpect to work out how to access what you need, it works in the usual way wml variables are accessed.
These preprocessor-referenced files must exist. You could use #ifhave to check whether they do.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Anonymissimus
Developer
 
Posts: 2379
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How to get information about the era in WML?

Postby Dugi » October 15th, 2013, 7:37 pm

I suppose that most eras aren't as nice as Hornshark Island to identify themselves. To get their recruit list, you can use [store_side], and in the array it produces, you can find the list of unit the side can recruit under the .recruit key. That might help you to identify the factions and also the era.
Legend of the Invincibles - single player campaign, trying to be an expansion to regular Wesnoth, where units can advance indefinitely, gear becomes an important factor and tons of new abilities increase the game's variety.
User avatar
Dugi
 
Posts: 3140
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains

Re: How to get information about the era in WML?

Postby iceiceice » October 19th, 2013, 6:34 pm

Anonymissimus wrote:Not sure whether the following is what you're looking for...

This is from data/multiplayer/scenarios/2p_Hornshark_Island.cfg:


Thanks for this, this is a very nice technique which I have now used in a few places. But you're right it isn't exactly what I'm looking for.

I can be a bit more concrete about what I need to do. (Warning: Large wall of text ahead :o) I'm currently developing two add-ons: Rushed By Yetis and Captain's Mode. Rushed By Yetis is a multiplayer map pool add-on, (historically mainted by a bevy of colorful characters), which contains two features -- (1) map pools which are mp campaigns with a prestart event which transitions you to a random map from some list and shuffles the sides, and (2) a "no mirror era" which is the same as default era except that if players choose random factions they will never get repeats (preventing a "mirror matchup".) Captain's mode is a variation on the Pick Your Recruits mod; it functions as a multiplayer campaign, where in the first scenario you draft a custom faction choosing from all available default era units, then it kicks you to an RBY map pool scenario.

In both of these (no mirror era and captain's mode) you need to be able to get lists of recruits for factions and such in WML. Actually previously these things were hard coded in both but it seems like bad design. So now I have made it so that they are getting these lists from Doc Paterson's Hornshark code as you pointed out; if nothing else it means we will never have to track down typos in unit type ids and such, and I think it makes the code more clear.

I would like to make it easy to use these things with UMC eras and unit sets. For instance if a user launched Captain's mode with era "Default + Kalifate" I would like the scenario to detect this and throw the Kalifate units into the pool. I would have thought this would be easy to do, but it turns out that wesnoth doesn't give you easy ways to access the keys of high level tags which is unfortunate. If I tried to do this with Doc Paterson's technique / the technique Dugi suggests I don't think it would work since if no one randomed a Kalifate leader you wouldn't see any Kalifate recruits, (as Dugi points out).

I attempted a number of different things to try to get the era into wml: for instance, I saw somewhere else on the forums that people have used the [+tag] syntax to overwrite parts of high level tags, for instance someone used [+units] [+unit] id = lich ... [/unit] [/units] to modify the lich in his umc campaign. So I fooled around with something like
Code: Select all
 
[+era]
    [event]
        name = preload
        {VARIABLE era_name $name}
    [/event]
[/era]


But of course this doesn't work for various reasons, first of all name is a key of era, not a variable, so you cannot dereference it even though I think something like this would work in e.g. c++, java. (if they had +tag syntax, etc... I realize this claim is pretty much meaningless but still you get my point :)). Also afaik you cannot replace $name with $this.name or some such, I guess that wesnoth sometimes uses a self-referential pointer "this" in the unit filter wml, but not for arbitrary tags.

Also I think it doesn't work because the era file is read and processed well before my [+tag] is encountered?

In any event it seems very strange, with the [+tag] syntax it seems it is in some sense possible to overwrite fields of high level tags, but there is no way to actually read them??

Also it occurred to me that perhaps there is some Lua function that lets you access high level tags -- another example of a high level tag I would like to access is [game_config] [multiplayer], which I believe c.f. MultiplayerServerWML should give me info about how the timer is configured. Currently it happens fairly regularly that noobs / (possibly not noobs) will host ladder games with invalid timer settings; ladder games are supposed to be played with a round bonus of at least +300 sec. However if this is the only bad number likely no one will notice until like turn 10 or so, and then it ends in a big argument where someone was winning and gets mad the game is thrown out. It would be nice if RBY would throw a warning at turn 1 when the timer is bad, e.g., when game.mp_countdown_turn_bonus < 300. (It appears, based on looking at save game files, that mp_countdown_turn_bonus and other timer tags become keys of the [multiplayer] tag. Also mp_era does as well. So figuring out how to access these things would help alot. Update: I realized there is a lua proxy table called "wesnoth.game_config", and poking around with :lua ... it seems that it does contain keys described at LuaWML:Misc#wesnoth.game_config, which is many of the fields listed here GameConfigWML, including one called mp_debug, but seemingly not the keys mp_era, mp_countdown_turn_bonus that I am looking for.)

Similarly to what I would like for Captain's mode, it would be nice if users could get No Mirror versions of UMC eras as well, or failing that, if it were very easy for a WML coder to modify the .cfg's to create this. In the past this would have been very difficult because there were like 6 different macros "give drakes" "give knalgans" etc.. The way it works now, it has become much easier for a WML hacker at least because you would just go to the block
Code: Select all
        [set_variables]
            name=factions
            [value]
                {multiplayer/factions/drakes-default.cfg}
                {multiplayer/factions/knalgans-default.cfg}
                {multiplayer/factions/loyalists-default.cfg}
                {multiplayer/factions/northerners-default.cfg}
                {multiplayer/factions/rebels-default.cfg}
                {multiplayer/factions/undead-default.cfg}
            [/value]
        [/set_variables]


and put in links to your own faction files instead. (Actually right now you'd have to do slightly more than this but we could make it as easy as this if we wanted.)

But in the future I guess v1.11 will give us "modifications" in addition to scenarios and eras? In this case perhaps "no mirror era" should become a modification, and then I would like for it to detect the era and give the correct behavior. Hence the topic of the post :)
Last edited by iceiceice on October 20th, 2013, 2:29 am, edited 1 time in total.
iceiceice
Developer
 
Posts: 339
Joined: August 23rd, 2013, 2:10 am

Re: How to get information about the era in WML?

Postby iceiceice » October 20th, 2013, 2:00 am

I remembered that one of the reasons that I thought it should be possible to grab all the units in an era is that I casually specced a survival game once, I'm pretty sure it was orocia, in which it looked like they had random waves from random ageless era factions and the players had no idea what was coming next. However, I found on the add-on server that what this most likely was was orocia random mod, which in fact does not work as I guessed by randomly making waves from the current era, but instead appears to have literally thousands upon thousands of lines of hard coded references to Ageless era units :|
Last edited by iceiceice on October 20th, 2013, 12:54 pm, edited 2 times in total.
iceiceice
Developer
 
Posts: 339
Joined: August 23rd, 2013, 2:10 am

Re: How to get information about the era in WML?

Postby Sapient » October 20th, 2013, 4:37 am

As far as I know, there's not currently a way to do what you're asking. Although I agree it would be nice to have access to the era and faction information somehow.
http://www.wesnoth.org/wiki/User:Sapient... "Lift with the legs, Rogar, not the back." --Newmoon, Elven Archer
User avatar
Sapient
Developer
 
Posts: 4193
Joined: November 26th, 2005, 7:41 am

Re: How to get information about the era in WML?

Postby iceiceice » October 20th, 2013, 12:40 pm

That's a shame. Think I will give up on this for now.

Thanks,
~iceiceice~
iceiceice
Developer
 
Posts: 339
Joined: August 23rd, 2013, 2:10 am

Re: How to get information about the era in WML?

Postby Anonymissimus » October 20th, 2013, 3:06 pm

It appears, based on looking at save game files, that mp_countdown_turn_bonus and other timer tags become keys of the [multiplayer] tag. Also mp_era does as well. So figuring out how to access these things would help alot.

Using lua's wesnoth.game_event.on_save it may be possible to read such fields, if they're written into the savegame's wml.
You'll need hardcore lua, iterate a lot, and in 1.11.x things will likely be different again (that is, the fields to access and such, it would still work)

It's not Doc Paterson's technique btw, I wrote that "faction detection" thing in Hornshark. 8)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Anonymissimus
Developer
 
Posts: 2379
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How to get information about the era in WML?

Postby iceiceice » October 20th, 2013, 8:29 pm

I will have to wait a bit until I have some more time and do some more reading about lua but if you think you have an idea about how to do this I would be very happy to pursue it with you :geek:
iceiceice
Developer
 
Posts: 339
Joined: August 23rd, 2013, 2:10 am

Re: How to get information about the era in WML?

Postby Anonymissimus » October 21st, 2013, 2:51 pm

After some research, including source inspection, I see that my memory failed me. wesnoth.game_events.on_load only passes those wml tags to lua that have been inserted by it previously (in on_save which doesn't get passed arguments). So no chance to read the [multiplayer] child.

(Not sure why; perhaps it's to prevent modification. It looks as if it could work if the lua code just wants to read some values.)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Anonymissimus
Developer
 
Posts: 2379
Joined: August 15th, 2008, 8:46 pm
Location: Germany


Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 2 guests