AI question

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

AI question

Post by Casual User »

Good afternoon.

I'm trying to do something a bit more complex with WML, and the AI to go with it is buggy.

The idea

I want an ennemy leader that starts off in the middle of the map and runs towards his keep. If he's cornered, he will fight, but if he can flee, he will (the idea being, of course, to corner him).

The problem

I put his starting location on the keep, [teleport] him to the middle of the map in the prestart and put [leader_target] in the [ai] tag.

It works insofar as he will start going towards his keep, but if he catches sight of one of your guys, he's likely to attack (which kind of spoils the fun, as you no longer have to catch up to and encircle him, but merely get close to him).

So then I put his aggression level low, with an event changing his aggression level when he reaches his keep, but now he doesn't attack when he's cornered.

A possible solution

One solution would be to have an event changing his aggresion as soon as he is attacked. This would definitely be a step in the right direction, but you wouldn't really need to trap him anymore, just catch up to him...

Can anyone think of a way to write the AI to do what I would like him to?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

In 1.1.2+ you can set those goto_x and goto_y unit variables of the AI unit to point to his keep (do it every turn, in a name=ai turn event), which should make him always run to the keep along the shortest route. If he's encircled (and thus, ends his forced movement next to an enemy), then I guess he should attack just like any other AI unit would in that situation.

In 1.0.2, I wouldn't count on being able to really do something like this. Except maybe define several [side]s with different [ai] settings and flip the unit back and forth between those sides depending on the situation - how close and where there are enemies, for example. Still, it wouldn't likely work very well.
User avatar
Casual User
Posts: 475
Joined: March 11th, 2005, 5:05 pm

Post by Casual User »

zookeeper wrote:If he's encircled (and thus, ends his forced movement next to an enemy), then I guess he should attack just like any other AI unit would in that situation.
Yeah, he should... but I write in 1.0.2 :( .

Oh well, thanks...
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

It would be possible in that version but it would take some tricky WML.

Expanding upon the side flipping idea, the primary mode could be passive AI, but each turn you could move him along a set route with MOVE_UNIT. Then you would need a script that detects the path being blocked-- and that would be the hard part. The downside to this approach: he might move "through" someone if the blocked condition is not detected properly.

Maybe someone else has a better suggestion, though.
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