A few questions

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
User avatar
Casual User
Posts: 475
Joined: March 11th, 2005, 5:05 pm

A few questions

Post by Casual User »

The Setup

I'm writing a scenario where a random mounted raiding party is generated in a random position on the map, and you must lead your fellow villagers out of harm's way (and if possible evacuate some of the isolated farms).

If you see a leitmotiv in my plots, it's your imagination :P .

However, a few WML problems have risen up.

A few general questions

I have a lot of macros based around '[event] name=capture'. Does this also fire when you use [capture_village]? How about when you use {STARTING_VILLAGES}?

Also, if you have a victory event and an event with '[endlevel] result=victory' in it, does the victory event fire when the [endlevel] ire?

An AI problem

How can I make those guys stick together? I tried writing grouping=yes inside the [ai] tag, but the raiders still all go their own way like idiots.

The problem is that, if they're separated, your villagers can pick them off one by one (whereas you'd really need to run and hide if they're together). That's not what I wanted my scenario to be like at all.

A different AI problem

I need the raiders to have a leader, because otherwise, they don't burn down villages (that macro is based on capture, which doesn't fire with a no_leader side).

If I give them an isolated leader in a well-hidden keep somewhere, he runs off (even if I make him a passive_leader), which means you can meet him alone, sometimes completely isolated from his guys.

If I give them a normal leader and teleport him to his guys, he hangs around the back row and never attacks...

I need a 'lead from the front' type barbarian leader.

I can make him a normal (but strong) unit, and have the real leader elsewhere. The apparent leader will 'lead from the front', but you might meet the real leader wandering around all alone :? .

Or I can make the apparent leader the real leader, but then he doesn't 'lead from the front' :? .

The only solution I can see is give them a general leader, put him in a corner of the map, surround him with cavewall and hide it with shroud... But it seems like a cheap solution.

Is there anyway to code the AI so he won't be over-protective of his leader?

A coding mishap

I was writing the code to make the ennemies pop up in a random location chosen from among four possibilities. Problem is, out of ~10 tries, they popped up in the same place 8 times... And when they didn't, they always popped up in the same place.

Maybe it's just statistical clustering, but do you see any problem with the code?

Code: Select all

[set_variable]
name=attack
random=1..4
[/set_variable]
[if]
[variable]
name=attack
equals=1
[/variable]
[then]
[teleport]
[filter]
description=Aleugzi
[/filter]
x,y=18,1
[/teleport]
{SPEC_UNIT tunn_cavalier 2 20 1 ({TRAIT_RESILIENT}) ({TRAIT_STRONG})}
{SPEC_UNIT tunn_cavalier 2 19 1 ({TRAIT_QUICK}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 19 2 ({TRAIT_QUICK}) ({TRAIT_INTELLIGENT})}
{SPEC_UNIT tunn_horseman 2 18 2 ({TRAIT_STRONG}) ({TRAIT_QUICK})}
{SPEC_UNIT tunn_horseman 2 20 2 ({TRAIT_INTELLIGENT}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 18 3 ({TRAIT_STRONG}) ({TRAIT_DEXTROUS})}
[/then]
[/if]
[if]
[variable]
name=attack
equals=2
[/variable]
[then]
[teleport]
[filter]
description=Aleugzi
[/filter]
x,y=32,1
[/teleport]
{SPEC_UNIT tunn_cavalier 2 31 1 ({TRAIT_RESILIENT}) ({TRAIT_STRONG})}
{SPEC_UNIT tunn_cavalier 2 30 1 ({TRAIT_QUICK}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 31 2 ({TRAIT_QUICK}) ({TRAIT_INTELLIGENT})}
{SPEC_UNIT tunn_horseman 2 32 2 ({TRAIT_STRONG}) ({TRAIT_QUICK})}
{SPEC_UNIT tunn_horseman 2 33 2 ({TRAIT_INTELLIGENT}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 30 2 ({TRAIT_STRONG}) ({TRAIT_DEXTROUS})}
[/then]
[/if]
[if]
[variable]
name=attack
equals=3
[/variable]
[then]
[teleport]
[filter]
description=Aleugzi
[/filter]
x,y=40,28
[/teleport]
{SPEC_UNIT tunn_cavalier 2 40 29 ({TRAIT_RESILIENT}) ({TRAIT_STRONG})}
{SPEC_UNIT tunn_cavalier 2 40 27 ({TRAIT_QUICK}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 39 28 ({TRAIT_QUICK}) ({TRAIT_INTELLIGENT})}
{SPEC_UNIT tunn_horseman 2 39 29 ({TRAIT_STRONG}) ({TRAIT_QUICK})}
{SPEC_UNIT tunn_horseman 2 39 30 ({TRAIT_INTELLIGENT}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 40 30 ({TRAIT_STRONG}) ({TRAIT_DEXTROUS})}
[/then]
[/if]
[if]
[variable]
name=attack
equals=4
[/variable]
[then]
[teleport]
[filter]
description=Aleugzi
[/filter]
x,y=19,37
[/teleport]
{SPEC_UNIT tunn_cavalier 2 20 37 ({TRAIT_RESILIENT}) ({TRAIT_STRONG})}
{SPEC_UNIT tunn_cavalier 2 21 38 ({TRAIT_QUICK}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 21 37 ({TRAIT_QUICK}) ({TRAIT_INTELLIGENT})}
{SPEC_UNIT tunn_horseman 2 20 36 ({TRAIT_STRONG}) ({TRAIT_QUICK})}
{SPEC_UNIT tunn_horseman 2 19 36 ({TRAIT_INTELLIGENT}) ({TRAIT_DEXTROUS})}
{SPEC_UNIT tunn_horseman 2 21 36 ({TRAIT_STRONG}) ({TRAIT_DEXTROUS})}
[/then]
[/if]
Oof, that's a lot... Thanks in advance.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: A few questions

Post by Sapient »

For the AI, try:
scout_village_targetting=5
grouping=defensive

The only solution I can see is give them a general leader, put him in a corner of the map, surround him with cavewall and hide it with shroud... But it seems like a cheap solution.
It works and that seems to be the typical way of doing it. I guess another option would be to give him an invisible standing image and then sourround with deep water.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: A few questions

Post by zookeeper »

Sapient wrote:
The only solution I can see is give them a general leader, put him in a corner of the map, surround him with cavewall and hide it with shroud... But it seems like a cheap solution.
It works and that seems to be the typical way of doing it. I guess another option would be to give him an invisible standing image and then sourround with deep water.
Or, better yet, put him in deep water and have his custom unit type have ambush in deep water (or just the same submerge that skeletons have). He should be completely undetectable then (just make sure there's deep water around him so no one can move next to him).

I have another idea how the whole "flock" and the real leader could be grouped nicely, I'll get to that a bit later.
sparr
Posts: 209
Joined: March 6th, 2006, 5:02 am

Post by sparr »

i only read the AI stuff for the first time today, but i think i saw a way to flag an area as higher priority for npc units... with a unit filter and a radius you could probably make the area around each of their units important to their other units
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: A few questions

Post by zookeeper »

Casual User wrote:A few general questions

I have a lot of macros based around '[event] name=capture'. Does this also fire when you use [capture_village]? How about when you use {STARTING_VILLAGES}?
I'd guess they don't fire when capturing villages with WML.
Casual User wrote:Also, if you have a victory event and an event with '[endlevel] result=victory' in it, does the victory event fire when the [endlevel] ire?
It should, yes.
Casual User wrote:An AI problem

How can I make those guys stick together? I tried writing grouping=yes inside the [ai] tag, but the raiders still all go their own way like idiots.

The problem is that, if they're separated, your villagers can pick them off one by one (whereas you'd really need to run and hide if they're together). That's not what I wanted my scenario to be like at all.
If you're writing this for 1.1.2 or newer, you could make it so that:

The leader is put into a separate side (let's say side 2) and the other guys in another (side 3). Allied sides, of course. Then, the leader moves wherever he likes on his own turn. On the beginning of the other guys' turn, however, their moveto destinations will be randomly selected from the hexes surrounding the leader (you can do this nowadays, although it's pretty complex). This way, they should all stay pretty much in one group. I haven't tested this myself, however, but I can do so and write the code for it if you'd like.
Casual User wrote:I need a 'lead from the front' type barbarian leader.

I can make him a normal (but strong) unit, and have the real leader elsewhere. The apparent leader will 'lead from the front', but you might meet the real leader wandering around all alone :? .

Or I can make the apparent leader the real leader, but then he doesn't 'lead from the front' :? .

The only solution I can see is give them a general leader, put him in a corner of the map, surround him with cavewall and hide it with shroud... But it seems like a cheap solution.

Is there anyway to code the AI so he won't be over-protective of his leader?
You could try removing the leader status (canrecruit=1 to canrecruit=0) from the leader for the duration of his turn. This way, the AI might not consider that unit all that valuable and will attack with it just like with any other normal unit. Two side turn events, one removing leaderness and one restoring it, should work here.
Casual User wrote:A coding mishap

I was writing the code to make the ennemies pop up in a random location chosen from among four possibilities. Problem is, out of ~10 tries, they popped up in the same place 8 times... And when they didn't, they always popped up in the same place.

Maybe it's just statistical clustering, but do you see any problem with the code?
To me, that code looks just fine. I wouldn't know what's causing the clustering, although someone complained about the RNG doing something a bit like that (although in terrain graphics WML code, not this). Perhaps make a test that generates random numbers like this and shows them in [message]s to the user, to verify whether it's really the RNG?
sparr wrote:i only read the AI stuff for the first time today, but i think i saw a way to flag an area as higher priority for npc units... with a unit filter and a radius you could probably make the area around each of their units important to their other units
I guess you're referring to [target] or [protect_unit]. [protect_unit] might work (at least it's worth a try); just have the radius large enough so that the AI considers the leader "threatened" most of the time, since it won't place units around the protected unit unless there's a threat inside that radius.
User avatar
Casual User
Posts: 475
Joined: March 11th, 2005, 5:05 pm

Post by Casual User »

I've taken the cheapest way out.

I've made a little lake of deep water, make the leader start out in the middle, and put fog in the scenarios. There is still one that has no fog, but I can always add it manually.
zookeeper wrote:On the beginning of the other guys' turn, however, their moveto destinations will be randomly selected from the hexes surrounding the leader (you can do this nowadays, although it's pretty complex).
Sounds a bit too complex.

I'll have to test some more, but if it proves to be a real problem, I think I've found a way to fix it:

Code: Select all

[event]
name=moveto
[filter]
side=2
[/filter]
[modify_side]
side=2
[ai]
[target]
x,y=$x1,$y1
[/target]
[/ai]
[/modify_side]
[/event]
It probably needs refining, but it should work fine.
zookeeper wrote:I wouldn't know what's causing the clustering, although someone complained about the RNG doing something a bit like that (although in terrain graphics WML code, not this).
I think it was clustering, I've re-written the code with new parametres, and it seems to work.

Thanks for the replies.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

Casual User wrote:I've made a little lake of deep water, make the leader start out in the middle, and put fog in the scenarios. There is still one that has no fog, but I can always add it manually.
Or just make the enemy leader a Draug. Or, on older versions of wesnoth, place a tree island in the middle of the deep water and let the enemy leader be an elvish avenger.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply