make a unit chase another unit
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.
make a unit chase another unit
I have this psycho unit named Rashti. When she gets beaten up too badly, she splits in half. One half stays under player control, the other half joins the enemy side. I want the enemy half to mercilessly hunt down the player's leader. I can't seem to come up with AI tags that will actually accomplish that though. When I test the behavior in a game, I don't see any evidence of targeting. Even when the enemy half is right next to the player's leader, it prefers to attack other units.
Has anyone been able to implement reliable hunting behavior?
Has anyone been able to implement reliable hunting behavior?
To Lands Unknown, an Arabesque adventure of stunning background art, mobile summoning, and strong storytelling.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: make a unit chase another unit
With standard wml ai tags this is completely impossible. Maybe with new ai syntax.
You can perhaps do some "ai herding": Before the ai makes his decision (side turn event) make the target unit especially weak to the hunter's attack type. After it has attacked, revert (attack start event). Combine with an [ai][target] setting for a side containing only the chaser. (That setting only works if the chaser can't attack anyone else.)
You can perhaps do some "ai herding": Before the ai makes his decision (side turn event) make the target unit especially weak to the hunter's attack type. After it has attacked, revert (attack start event). Combine with an [ai][target] setting for a side containing only the chaser. (That setting only works if the chaser can't attack anyone else.)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: make a unit chase another unit
or you could make all other units hidden/allied for the duration of the evil halves' turn
it's a bit of cheating, and probably clumsy resourcewise, but might just work
it's a bit of cheating, and probably clumsy resourcewise, but might just work
Like cats? I've made a whole faction of them to kick ass with!
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Re: make a unit chase another unit
I've been going by what's documented for AiWML. I see that "new" syntax is stuff from Wesnoth 1.8; I haven't looked at that section yet. Also the "old" documentation is not 100% complete, leaving me to guess at whether I need [filter][/filter] tags for subsections and so forth. The game didn't reject my WML though; I just wonder if it silently dismisses unworkable WML. I used the inspection tool to look at AI settings, but the information shown doesn't look like the concepts provided in WML. I guess I'll go read the AI forum for a bit.Anonymissimus wrote:With standard wml ai tags this is completely impossible. Maybe with new ai syntax.
The behavior I want to implement is really simple. Perhaps I should do it in Lua.
To Lands Unknown, an Arabesque adventure of stunning background art, mobile summoning, and strong storytelling.
- Alarantalara
- Art Contributor
- Posts: 786
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: make a unit chase another unit
A solution using ForumlaAi.
Use the following code in the side definition for the side that will have the chasing unit.
Replace 2 with the actual side number
Replace hunter_id with the id of the unit that does the hunting
Replace target id with the id of the unit that is the target
The hunter unit will chase down the target and attack it if possible. It will only attack other units if it can't attack its target.
The ids and names are rather random since I copied some code I wrote for myself to get this working quickly. You probably want to change them to something meaningful.
Use the following code in the side definition for the side that will have the chasing unit.
Replace 2 with the actual side number
Replace hunter_id with the id of the unit that does the hunting
Replace target id with the id of the unit that is the target
The hunter unit will chase down the target and attack it if possible. It will only attack other units if it can't attack its target.
Code: Select all
[ai]
{MODIFY_AI_ADD_CANDIDATE_ACTION 2 main_loop (
[candidate_action]
id=escape_south
engine=fai
name=escape_south
type=movement
evaluation="if(me.id='hunter_id',{AI_CA_GOTO_SCORE}+10,0)"
action="move(me.loc, choose(unit_moves(me.loc),'mloc',-sum(map(simplest_path(mloc,find(units,id='target_id').loc,me.loc), 'path_location', movement_cost( me, path_location ) ))) )"
[/candidate_action]
)}
{MODIFY_AI_ADD_CANDIDATE_ACTION 2 main_loop (
[candidate_action]
id=attack_gra
engine=fai
name=attack_gra
type=attack
evaluation="if(me.id = 'hunter_id' and target.id = 'target_id', {AI_CA_GOTO_SCORE} ,0)"
action="attack(me.loc, me.loc, target.loc)"
[/candidate_action]
)}
[/ai]
Re: make a unit chase another unit
It is 1.8+ and works fine on both versions.bvanevery wrote:I see that "new" syntax is stuff from Wesnoth 1.8; I haven't looked at that section yet.
{ai/aliases/stable_singleplayer.cfg}
Some great stuff there, But you have to include this above the [ai] tag for it to work:Alarantalara wrote:A solution using ForumlaAi.
Code: Select all
{ai/aliases/stable_singleplayer.cfg}
Re: make a unit chase another unit
There was allways a AI command to make all units attack the opposite leader. It is used in a lot of scenarios and was allways working. If you put your evil Rashti in a side of its own (But allied with the ather bad guys), it should work.
There is stuff like ignore bad combat and so on. Make sure to make the Rashti side agressive and focused on the leader.
There is stuff like ignore bad combat and so on. Make sure to make the Rashti side agressive and focused on the leader.
My Temple Project: http://forums.wesnoth.org/viewtopic.php?f=23&t=29800
This is "must-play" campaign! Don´t read the thread, unless you need help. http://forums.wesnoth.org/viewtopic.php?f=8&t=31895
This is "must-play" campaign! Don´t read the thread, unless you need help. http://forums.wesnoth.org/viewtopic.php?f=8&t=31895
Re: make a unit chase another unit
Alarantalara, note that there's next_hop formula function which makes the formula slightly less verbose.
it can be used like this:
basically, it return the next 'this turn' destination for our unit if we know the end destination.
it can be used like this:
Code: Select all
move(my_leader.loc,next_hop(my_leader.loc,loc(20,6)))
- Alarantalara
- Art Contributor
- Posts: 786
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: make a unit chase another unit
I was actually copying a different suggestion you had made earlier. According to your post there, this more complicated code ensures that the unit still moves if the desired target is occupied (which this certainly is). Since next_hop existed then, I assumed this would remain a better option. Has the behaviour of next_hop changed? I'll certainly test it though.
- Alarantalara
- Art Contributor
- Posts: 786
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: make a unit chase another unit
I finally got around to testing it and it turns out that there are some behaviour differences.
next_hop seems to try to go around enemy units, while the more verbose option tries to take the straight line route regardless of enemies with no backtracking.
For this specific instance, given that the unit is "psycho", I think the more verbose option may be the better choice here.
I'll definitely remember next_hop if I want more sane behaviour
next_hop seems to try to go around enemy units, while the more verbose option tries to take the straight line route regardless of enemies with no backtracking.
For this specific instance, given that the unit is "psycho", I think the more verbose option may be the better choice here.
I'll definitely remember next_hop if I want more sane behaviour