AI recruitment pattern

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.
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

AI recruitment pattern

Post by Rya »

We wondered about this ingame yesterday so I wanted to ask if someone here knows the answer:

How is it determined what units the AI recruits? I know there are recruitment patterns like "Fighter,Fighter,Fighter,Archer,Mixed" (Loyalists), but how does the AI decide what Fighter to recruit for example? From personal experience the AI always only builds the strongest units. Fighter for Loyalists seems to be always Heavy Infantry. Someone ingame said that it depends on the opponent faction and that he only build HIs exclusively when there's an undead enemy. Is that true? Where is the file that says "If you fight against this, recruit that unit"?
How does it work with a custom recruit list? For example if I give the AI all level 1 and level 2 units from all factions. Usually the AI seems to build often the same units (always level 2 units and never level 1 units).

Is it possible to make the AI recruit a higher variety of units and is it possible to change the recruit pattern (not recruit list) for a single scenario?
Wesnoth
The developer says "no".
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: AI recruitment pattern

Post by Anonymissimus »

Rya wrote:Someone ingame said that it depends on the opponent faction and that he only build HIs exclusively when there's an undead enemy. Is that true?
Apparently. It is also influenced by terrain analysis. Both things can be turned off using recruitment_ignore_bad_combat (opponent's units) and recruitment_ignore_bad_movement (terrain)
Is it possible to make the AI recruit a higher variety of units
Yes. That's what the core macros LIMIT_CONTEMPORANEOUS_RECRUITS and LIMIT_RECRUITS are for.
and is it possible to change the recruit pattern (not recruit list) for a single scenario?
Should work with [modify_side][ai]recruitment_pattern=...in an event. Or at scenario start with [side][ai]recruitment_pattern=...
The default recruitment pattern is analog to the recruitment list (It matches the usage types of the units listed there.).
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
Soliton
Site Administrator
Posts: 1732
Joined: April 5th, 2005, 3:25 pm
Location: #wesnoth-mp

Re: AI recruitment pattern

Post by Soliton »

Anonymissimus wrote:
Rya wrote:Someone ingame said that it depends on the opponent faction and that he only build HIs exclusively when there's an undead enemy. Is that true?
Apparently. It is also influenced by terrain analysis. Both things can be turned off using recruitment_ignore_bad_combat (opponent's units) and recruitment_ignore_bad_movement (terrain)
Is it possible to make the AI recruit a higher variety of units
Yes. That's what the core macros LIMIT_CONTEMPORANEOUS_RECRUITS and LIMIT_RECRUITS are for.
You can also use an empty recruitment_pattern to have the AI consider units regardless of their usage key. Together with the above mentioned ignore settings recruitment should be pretty much completely random then.
"If gameplay requires it, they can be made to live on Venus." -- scott
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Those macros are used by just writing: {LIMIT_CONTEMPORANEOUS_RECRUITS}
Right?
Is there somewhere a list of those macros explaining what exactly they do?

So to randomize the recruited units I call those and then do:
[side]
side=4
canrecruit=yes
controller=ai
team_name=StrongCPU
gold=300
village_gold=2
[ai]
recruitment_pattern=
[/ai]
[/side]
Is that correct?

I'll try it out.
Wesnoth
The developer says "no".
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: AI recruitment pattern

Post by Max »

Rya wrote:Is there somewhere a list of those macros explaining what exactly they do?
http://www.wesnoth.org/macro-reference. ... -utils.cfg
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Hmm according to the documentation I'd need to define a unit there, but what if I want to limit all units to 2 each? Do I really need to write one line for every single unit or is there some way to say "All units"?
Wesnoth
The developer says "no".
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: AI recruitment pattern

Post by Anonymissimus »

Don't forget the arguments that the macro needs.

And no, du to the way this macro works I'm guessing you need to call it once for each unit type, if you want to have (say) 2 of each unit type.
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
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Aww, that's too bad, then there's not really a way to shuffle the recruitment unless you know the faction of the ai.
Wesnoth
The developer says "no".
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Are those macros just written into the multiplayer tag?

So let's say I want the AI (side 4) to only recruit 2 Armageddon Drakes, 2 Dwarvish Runemasters and 2 Elvish High Lords at the same time I just do:
[multiplayer]
...
{LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Armageddon Drake" 2}
{LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Dwarvish Runemaster" 2}
{LIMIT_CONTEMPORANEOUS_RECRUITS 4 "Elvish High Lord" 2}
...
[/multiplayer]

Correct?
I guess I can use that somehow.
Wesnoth
The developer says "no".
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Hm I tried this now, but the problem is, that this command also enables the recruitment of the unit! So if I write down all units of all faction the cpu will not only have the recruitment limited but is also able to recruit units from others faction. :-/
Wesnoth
The developer says "no".
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: AI recruitment pattern

Post by Anonymissimus »

Well, I'm guessing there IS a way to do what you want. But you can't use that core macros then. You'd need to code it by yourself.

My ideas gather around
-[event]name=recruit[filter]side=side_number
-record the recruited type in an array of containers, each container containing a string determining the unit type and an integer indicating how many units of that type of that side are on the map and possibly disallow recruitment of that type
-[event]name=die[filter]side=side_number
-decrease the integer in the array indicating the number of units of that type of that side that are on the map and possibly (re)allow recruitment of that type for that side

It requires at least two loops and lots of variable handling. And that's surely an advanced wml task, if it doesn't make sense to you then don't try...

Another approach could be to extract the recruitment list (this is possible for sure with store_side). But the treatment of the single unit types would probably require string operations (extracting the single unit types from the recruitment list) and I don't know how to do that...
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
User avatar
Crab
Inactive Developer
Posts: 200
Joined: March 18th, 2009, 9:42 pm

Re: AI recruitment pattern

Post by Crab »

since r39701, it's also possible to limit maximum number of units in the field by type, for any ai which uses default recruitment, using [limit] subtag of the [value] of ai_default::recruitment implementation of recruitment aspect.

this does nothing to the actual allowed recruits list (so, it's safe to use units AI is not able to recruit there), only dynamically limits AIs options

Example:

Code: Select all

[ai]
 {AI_SIMPLE_ALWAYS_ASPECT_VALUE recruitment (
     name=ai_default::recruitment
     [limit]
         type=Elvish Archer
         max=1
     [/limit]
     [limit]
         type=Elvish Fighter
         max=1
     [/limit]
   )}
[/ai]
note: it's advised to use "recruitment_ignore_bad_combat=yes" and "recruitment_ignore_bad_movement=yes" in such a setup, otherwise the AI might recruit nothing if 'best' units for all usages are at maximum allowed count (because, in such a situation, it doesn't want to recruit 'best' units due to number-in-the-field limitation, and it doesn't want to recruit 'bad' units)
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

To which tag do the options "recruitment_ignore_bad_combat=no" and "recruitment_ignore_bad_movement=no" belong to? [side]?
Wesnoth
The developer says "no".
Velensk
Multiplayer Contributor
Posts: 4005
Joined: January 24th, 2007, 12:56 am

Re: AI recruitment pattern

Post by Velensk »

Th [AI] tag within the side tag.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: AI recruitment pattern

Post by Rya »

Wait a minute, shouldn't it be "=yes" for both in that sentence of Crab?

After all it should ignore it, right?
Wesnoth
The developer says "no".
Post Reply