Forcing AI unit to move along a set path

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
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Forcing AI unit to move along a set path

Post by zookeeper »

I'm doing a scenario which begins so that the player's objective is to catch up with the enemy's fleeing leader with one of his units (after which various things happen). I'm finding it impossible to make the AI leader to move along the quickest path to his destination.

Just setting a leader goal as follows doesn't work:

Code: Select all

[ai]
    [leader_goal]
        x,y=37,17
    [/leader_goal]
[/ai]
Because now the AI decides to retreat to a village or more defensive terrain rather than continue to the set destination when one of my units gets close enough. So I'd need some way to force the AI to move it's leader where I want it to as fast as possible, not caring for it's safety.

I've also tried setting caution and aggression to extreme values in the [ai] tag, but to no avail.

I thought about creating an event that would trigger in the beginning of the AI's turn and where I would define the movement for every turn individually, but this seems like much more work than I'd like to do: there's no "move_unit" command, so I'd need to create fake_unit_moves and hides and unhides for every turn as well as deplete the unit's moves in the end of the event etc.

Any way to do this except in such a hard manner?
martenzo
Posts: 564
Joined: August 8th, 2004, 9:01 am
Location: Northern Europe, Estonia, Kardla

Post by martenzo »

I know that there is a movement restriction (don't move to X,Y), but since I haven't used it myself, I don't know the details.
me: Welcome to the real world. If everyone says your art and opinions suck, it's because they DO suck. Even if you're too damned proud/stupid/both to realize it.
danny_california: yep keep telling fairy tales.
MadMax
Posts: 1792
Joined: June 6th, 2004, 3:29 pm
Location: Weldyn, Wesnoth

Post by MadMax »

try passive_leader=yes, but no guarantees on that.

and as for avoiding, you would do

Code: Select all

[ai]
[avoid]
(SUF)
[/avoid]
[/ai]
"ILLEGITIMIS NON CARBORUNDUM"

Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Re: Forcing AI unit to move along a set path

Post by Rhuvaen »

zookeeper wrote:I thought about creating an event that would trigger in the beginning of the AI's turn and where I would define the movement for every turn individually, but this seems like much more work than I'd like to do: there's no "move_unit" command, so I'd need to create fake_unit_moves and hides and unhides for every turn as well as deplete the unit's moves in the end of the event etc.
I think this is quite impossible if you want to consider other units in the path, ZOC's, attack and defense - unless all of this is just a mock situation that helps to move the story along. But I take it the player's aim is to intercept this unit?

One thing I can think of is providing a keep for the leader to move to. This is what I've seen the AI do when I remove their keep with the [terrain] tag: they'll run their leader straight to the next unoccupied keep on the map that's as far as possible from the enemy army :). Maybe this is something you could use. The keep wouldn't need to have to have any adjacent recruitment spaces, as far as I know. :)
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

I think this is quite impossible if you want to consider other units in the path, ZOC's, attack and defense - unless all of this is just a mock situation that helps to move the story along. But I take it the player's aim is to intercept this unit?
It is indeed a very simple mock situation. The player just has to reach the enemy leader with one of his units before the leader reaches a specific hex.

I've also tried 'passive_leader=yes', but it didn't help either.
One thing I can think of is providing a keep for the leader to move to. This is what I've seen the AI do when I remove their keep with the [terrain] tag: they'll run their leader straight to the next unoccupied keep on the map that's as far as possible from the enemy army Smile. Maybe this is something you could use. The keep wouldn't need to have to have any adjacent recruitment spaces, as far as I know. Smile
This didn't seem to work. The AI behavior is also quite odd sometimes; when my units get within a few hexes of the leader, he quite often just...stops. Stands there in the middle of the grassland, even though it isn't in any way any better than the grassland closer to the leader_goal (or keep) where he could have moved to that turn.

Anyway, this is only part of the first scenario in my campaign, and it'll be a long time before I get the campaign in any sort of playable form anyway, so I guess I'll just work on other scenarios while slowly working on that macro to force unit movement.
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Post by turin »

If I understand what you want correct, the first scenario in Liberty does it fairly well. I would take a look at its code.
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
Post Reply