Limit AI player to a given area?

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.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Limit AI player to a given area?

Post by kurt751 »

Is it possible to limit an AI player to a given area so he can't wander off?
Ideally with the possibility to remove that limitation later on during the game with an event.
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: Limit AI player to a given area?

Post by SkyOne »

kurt751 wrote:Is it possible to limit an AI player to a given area so he can't wander off?
Ideally with the possibility to remove that limitation later on during the game with an event.
Yes, it is possible by using the micro AIs with the [filter_location] tag, depending on what you want your ai-units to perform.
You can also delete it in a later event. :)
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Limit AI player to a given area?

Post by Dugi »

There's an easier solution. Just use the [avoid] tag on all locations where you don't want it to go.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

SkyOne wrote:Yes, it is possible by using the micro AIs with the [filter_location] tag, depending on what you want your ai-units to perform.
You can also delete it in a later event. :)
Hm, interesting. I haven't played with the MicroAIs yet, and I see some cool stuff there. I'll have to experiment a little with it. :D
That been said I didn't see anything which would help in my case, where I just want the AI player to do his usual stuff, but stay inside a given area.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

Dugi wrote:There's an easier solution. Just use the [avoid] tag on all locations where you don't want it to go.
Uh. It's a 120x120 map... :shock:
But I guess I could make some uncrossable "borders" by just blocking the hexes leading from the "allowed" to the "forbidden" areas. And place some unpassable mountains. That might work just fine, but can I change the AI during the game (after turn 10, for instance)?

Besides, is there an easy way to gather all the hexes to put in the tag? I mean besides pen, paper and lots of time?...
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Limit AI player to a given area?

Post by Ravana »

You can use in filtering things like x=15-83
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

Ravana wrote:You can use in filtering things like x=15-83
:?: What do you mean?
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Limit AI player to a given area?

Post by Dugi »

You can simply write:

Code: Select all

[ai]
  [avoid]
    x=37-68
    y=12-42
  [/avoid]
[/ai]
to prevent it from entering the area 37-68,12-42.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

Dugi wrote:to prevent it from entering the area 37-68,12-42.
That would work for a square area; The problem my areas are really not square... :oops:
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Limit AI player to a given area?

Post by Dugi »

kurt751 wrote:
Dugi wrote:...
That would work for a square area; The problem my areas are really not square... :oops:
You can use [or] [not] and [and] tags to compose it. Of course, if the area is really irregular, you might have to stick with terrain types.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

Dugi wrote:You can use [or] [not] and [and] tags to compose it. Of course, if the area is really irregular, you might have to stick with terrain types.
Terrain types? Uh-oh, that would be even more complicated.
But the booleans might work, by assembling small pieces.

What's the proper syntax to use them? Something like that?

Code: Select all

[ai]
  [avoid]
    x=x-y
    y=x-y
      [and]
    x=x-y
    y=x-y
  [/avoid]
[/ai]
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Limit AI player to a given area?

Post by Ravana »

Close tags too, [/and].
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Limit AI player to a given area?

Post by Dugi »

Code: Select all

[ai]
  [avoid]
    x=1-120
    y=15-24
    [and]
      x=1-120
      y=56-73
    [/and]
  [/avoid]
[/ai]
:doh: All you need is to end the tags and write the actual coordinates there, I thought that's trivial.
kurt751
Posts: 232
Joined: June 4th, 2016, 11:17 pm

Re: Limit AI player to a given area?

Post by kurt751 »

Great! Thanks both of you!
Post Reply