Stopping the AI leader from moving to attack?

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
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Stopping the AI leader from moving to attack?

Post by A Guy »

Hey there. I need the AI to be able to do everything it would normally do with its leader, but need to get rid of its suicidal tendency to attack with its leader when it'd be better off sitting on a keep. is there any way to make the leader unwilling to attack?

Here's what I have:

Code: Select all

	[ai]
		[aspect]
			id=attacks
			[facet]
				invalidate_on_gamestate_change=yes
				[filter_own]
					[not]
						canrecruit=yes
					[/not]
				[/filter_own]
			[/facet]
		[/aspect]
	[/ai]
This seems to prevent the AI from attacking with the leader - however, I want to stop it from *moving* to attack with the leader - attacking with the leader is fine if the AI doesn't commit suicide doing it.
I'm just... a guy...
I'm back for now, I might get started on some work again.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Stopping the AI leader from moving to attack?

Post by JaMiT »

Have you tried setting [wiki=AiWML#The_.5Bai.5D_Tag:_Defining_Aspects]leader_aggression =[/wiki] -4000000?

I forget which AI settings work when, but that attribute claims to do what you seem to be asking for.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Stopping the AI leader from moving to attack?

Post by mattsc »

JaMiT wrote:Have you tried setting [wiki=AiWML#The_.5Bai.5D_Tag:_Defining_Aspects]leader_aggression =[/wiki] -4000000?
That won't work, unfortunately, at least not entirely. The problem is that "damage received by enemy for this attack" is a multiplicative factor in all of this and thus, if it there is no damage to be received in the attack itself the AI will attack, not matter how dangerous a position it gets its leader into with that. And yes, I did try. I had a Dwarvish Berserker leader happily attack a Dark Adept surrounded by Troll Warriors with leader_aggression = -1,000,000. :P

For future reference, A Guy also asked this question on IRC. Here's some of the relevant text:

Code: Select all

20130626 00:17:18< mattsc> A_Guy: I assume you still want the leader to grab villages etc.?  Otherwise you could simply set moves=0 at the beginning of the turn.
20130626 00:27:06< A_Guy> mattsc>Yes, I want the AI to use its leader for everything it would normally do, except suicidally charging when there's a keep it can retreat to.
20130626 00:30:15< mattsc> Well, setting leader_aggression=-1000 (or so) will only partly prevent that.
20130626 00:31:15< mattsc> If you want to go with the approach from your post, you could put an [or] tag parallel to the [not] that includes leaders that have enemies next to them.
20130626 00:32:03< mattsc> But that doesn't guarantee that the leader will attack that enemy, only that it only attacks with the leader when there's an adjacent enemy.
20130626 00:33:09< mattsc> So, if you wanted to be absolutely certain, you'd have to exclude the leader as you do in your post, and then add an additional attack candidate action only for the leader.  That would have to be custom written though.
20130626 00:38:48< A_Guy> Uh-huh, thanks.
20130626 00:47:12< mattsc> A_Guy: actually, I think there is a different way.  You could incude the combat CA twice, once with the attacks aspect set as in your post; and the second with [filter}own} set to the leader, and [filter_enemy] to units adjacent to the leader.
20130626 00:47:38< A_Guy> Hmm. I'll try that, thanks.
20130626 00:47:42< mattsc> oops: [filter_own]
20130626 00:48:11< mattsc> You probably want to set the CA score to 99,999 for the second CA in that case
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Stopping the AI leader from moving to attack?

Post by JaMiT »

mattsc wrote:I had a Dwarvish Berserker leader happily attack a Dark Adept surrounded by Troll Warriors with leader_aggression = -1,000,000. :P
I choose to fail to see the problem with that. :Awesome:
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Stopping the AI leader from moving to attack?

Post by mattsc »

JaMiT wrote:
mattsc wrote:I had a Dwarvish Berserker leader happily attack a Dark Adept surrounded by Troll Warriors with leader_aggression = -1,000,000. :P
I choose to fail to see the problem with that. :Awesome:
How about a Peasant leader leaving his keep to throw a spear at a Troll Warrior? Same setting for leader_aggression. :D
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Stopping the AI leader from moving to attack?

Post by JaMiT »

The Peasant deserves a medal for valor! :mrgreen:


Okay, I thought the AI evaluated safety better than that. There is code (somewhere) that evaluates how much power the enemy can bring to bear on a given hex. That calculation must be going awry, since the AI is doing those things with its leaders. Maybe that part of the code is lacking a "save the leader" clause? It might be a bug.
... but I still choose to fail to see a problem. :)
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Stopping the AI leader from moving to attack?

Post by Anonymissimus »

Setting max_moves very low works pretty well in practice. Typically that low that the leader cannot move into terrain which is bad for him with the moves of only 1 turn. You may want a village within these moves in the case of poison.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Post Reply