AI and tunnels

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
jeeree
Posts: 12
Joined: July 22nd, 2014, 2:42 am

AI and tunnels

Post by jeeree »

Hi,
I made a map with a few tunnels connecting 2 continents. However, it seems like AI isn't very good with tunnels. If there is an attackable target on the other side of the tunnel, the AI uses the tunnel very well and goes through it to attack the target. But if there is nothing to attack through the tunnel, then the AI won't use the tunnels at all (even though there might be enemy units a few turns away). So it seems like the tunnels are not being considered during the move CA but is considered during the combat CA. Is this intended or a bug? Is there any way to fix it?
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI and tunnels

Post by mattsc »

Hi there,

I haven't tested tunnels recently and I don't know the exact situation on your map, but just a guess: the AI only considers enemy leaders and villages it does not own as default targets for the move-to-targets CA. Thus, if there are only non-leader enemies and no villages (or not many) on the other side, it will never move units through them. That is independent of whether this is through a tunnel or just on a "normal" map, but it's probably more noticeable with tunnels. You can change that by assigning units or locations on the other side of the tunnel as targets using the [goal] tag.

I don't know if this will help in your situation, but it might be worth a try.
jeeree
Posts: 12
Joined: July 22nd, 2014, 2:42 am

Re: AI and tunnels

Post by jeeree »

There are villages and leaders on the other side, but somehow the AI just refuses to take the tunnel unless something can be attacked in the current turn. I tried to use [goal] tag, but that slows down the ai movement phase significantly (200X200 map with 9 sides, a lot of units)
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI and tunnels

Post by mattsc »

Hmm, I don't know then without seeing the details. Would you mind sending me the scenario file and a relevant savegame with a situation where you think the AI should move through a tunnel and does not?
User avatar
skeptical_troll
Posts: 530
Joined: August 31st, 2015, 11:06 pm

Re: AI and tunnels

Post by skeptical_troll »

I revive this old thread instead of opening a new one because I have exactly the same problem. Namely, I set up a tunnel between tiles in the map in this way

Code: Select all

    [event]
      name=prestart
      [tunnel]
	bidirectional=yes
	[source]
	  x,y=8,3
	[/source]
	[target]
	  x=1,13,25,36
	  y=36,9,2,6
	[/target]
	[filter]
	 side=3
	[/filter]
      [/tunnel]
  [/event]
This is meant to have the AI recruiting in a location which is inaccessible for the player, and sending his units via tunnels. However, the AI recruits but does not use them, unless there is an enemy unit or a village to grab which are immediately reachable withing one turn. Once the enemy units are on the other side of the tunnels they behave normally, i.e. they slowly approach the enemy leaders. What is the state of this? Is there a way to setup the tunnel or the AI so that it will work as a normal path in the map?
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: AI and tunnels

Post by Paulomat4 »

I don't really know about Tunnels, but you could add a Micro ai to every unit that is recruited, make it move through the tunnel and Release it once that it's on the other side :)
Creator of Dawn of Thunder and Global Unitmarkers

"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
User avatar
skeptical_troll
Posts: 530
Joined: August 31st, 2015, 11:06 pm

Re: AI and tunnels

Post by skeptical_troll »

Paulomat4 wrote:I don't really know about Tunnels, but you could add a Micro ai to every unit that is recruited, make it move through the tunnel and Release it once that it's on the other side
thanks for the suggestion, that actually did the trick. I set up a [micro_ai] with a target location more or less at the center of the map, but valid only for units on the recruiting side of the tunnel. Strangely enough, the same trick does not work by setting a 'target location' goal in the ai at [side] level. Things are working now, but I really don't know why. That's the typical case where I should not touch anything.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI and tunnels

Post by mattsc »

I wrote a little test scenario and looked into this. I could confirm that the candidate actions controlling attacks and village grabbing were able to handle tunnels and that the move-to-targets CA was not. The reason for this is that the tunnel-handling path finding code was added to the former two, but not to the latter. [I assume that it was simply forgotten to do so when tunnels were introduced, but I was not part of that so take that as conjecture.] I have fixed this now and it should work in the next releases of both Wesnoth 1.12 and 1.13. Until those releases, I agree with Paulomat4 that using a Micro AI is probably the simplest work-around.
skeptical_troll wrote:I set up a [micro_ai] with a target location more or less at the center of the map, but valid only for units on the recruiting side of the tunnel. Strangely enough, the same trick does not work by setting a 'target location' goal in the ai at [side] level.
That's because the (Goto, I presume?) Micro AI uses a completely different code base than the default AI's move-to-targets candidate action, and the bug was only present in the latter.
User avatar
skeptical_troll
Posts: 530
Joined: August 31st, 2015, 11:06 pm

Re: AI and tunnels

Post by skeptical_troll »

Thanks for looking into this, now everything makes sense. I will use the (Goto, indeed) Micro AI until the next release is out!
Post Reply