Campaign AI recruiting

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
taptap
Posts: 980
Joined: October 6th, 2011, 5:42 pm

Campaign AI recruiting

Post by taptap »

How can I change the AI to recruit low and mid level units too, when it has the ability to do high level recruits?

When it only recruits a handful of L3, it is simply too easy, and the AI would almost always be better off with some mid/low level units to fill the ranks. Why isn't this changed in general?
I am a Saurian Skirmisher: I'm a real pest, especially at night.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Campaign AI recruiting

Post by beetlenaut »

There are two macros in side-utils.cfg: LIMIT_RECRUITS and LIMIT_CONTEMPORANEOUS_RECRUITS. Look those up. I think they will help you do what you want.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Superking
Posts: 51
Joined: October 8th, 2011, 10:48 am

Re: Campaign AI recruiting

Post by Superking »

set it to recruit randomly, it'll play better than anything you can arrange with the tags (just delete everything that affects its recruitment and it will recruit randomly)
lover de wesnoth
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Campaign AI recruiting

Post by Max »

this is really bad balancing wise. as campaign designer you want to control the difficulty of your scenarios, and it's crucial to have a tight grip on what the AI recruits...
User avatar
taptap
Posts: 980
Joined: October 6th, 2011, 5:42 pm

Re: Campaign AI recruiting

Post by taptap »

Main concern is it recruits only L2 or even L3 when it is allowed to do so, which isn't very cost efficient and too easy for the player. With the player often striking (and slowing first), such a build is even worse. I guess in some campaigns authors balance by allowing higher or more high-level units to the AI, when this leads to the AI recruiting effectively less but high level units this can mean the opposite, the scenario is easier at the higher difficulty. I played some campaigns on highest level, stopped playing some others, but now on HttT as challenging sometimes the AI can't even recruit a full keep (third last scenario) or is so ridiculously outnumbered that it hurts (underground tunnels, only L3 AI recruits as well, but what good are nightgaunts when there is no other unit around to backstab, seriously).

People who mess with the AI recruiting only do this to make it harder. I reckon I would have had much more problems in Descent into Darkness if I couldn't manipulate AI recruits as much in game.
I am a Saurian Skirmisher: I'm a real pest, especially at night.
BritNavFan
Posts: 10
Joined: December 17th, 2011, 8:47 pm

Re: Campaign AI recruiting

Post by BritNavFan »

@taptap: What you can do (with the tools provided) is pick the unit level that you want the AI to make recruitment decisions for, and use events to handle AI recruiting of other unit levels. (It may be possible to let the AI handle recruiting of higher level units using LIMIT_RECRUITS and LIMIT_CONTEMPORANEOUS_RECRUITS, depending on what precise effect you want.)

So for example I want an Orc/Goblin army that recruits 2/3 L1 orc units and 1/3 L0 goblin spearmen. The AI won't recruit L0 units if it can recruit L1's, and using LIMIT_CONTEMPORANEOUS_RECRUITS would mean that the AI recruits only orcs when the army is small and only goblins when the army is large. I look at the scenario and see that I expect this AI to have an income of about 10g/turn. 1/3 of that is 3g, and goblins cost 9g, so I want it to recruit 1 goblin every three turns. So I make an repeatable event that spawns a goblin which triggers if it's dusk or first watch (1/3 of turns), and I reduce the AI's per turn income by 3g (by changing the values I had previously specified in the "INCOME" macro).

@beetlenaut: Let's say I wanted the AI to recruit 20% level 3's, 40% level 2's and 40% level 1's, picked from 4 unit types at each level, and taking advantage of the AI's ability to dynamically decide what to recruit based on the situation (i.e. in response to what the player picks). I can't do this with the tools provided: either it'll pick all L3's (dynamically), or if I use LIMIT_RECRUITS and LIMIT_CONTEMPORANEOUS_RECRUITS it'll pick as many L3's as it can (not dynamically) and spend the rest of its money on L2's. (My improvised solution would be to playtest the scenario and with the AI recruiting L3's, see what L3 units it picks, then spawn those L3's with events, spawn L1's with events since they're mostly flavour and fodder in a scenario with L3's and lots of L2's, and let the AI decide what L2's to recruit.)
BritNavFan
Posts: 10
Joined: December 17th, 2011, 8:47 pm

Re: Campaign AI recruiting

Post by BritNavFan »

I should mention here that I'm assuming that the AI will only recruit units of the highest level it has available in 1.9.x. What I've tested is that the 1.8.6 AI won't recruit L0 goblin spearmen if it can recruit L1 orcs.

If I were to do a feature request, it would be something like

RECRUIT_UNIT_LEVELS_BY_PROPORTION L# fraction-between-0-and-1 [repeat]

So for example I might specify
RECRUIT_UNIT_LEVELS_BY_PROPORTION L2 0.40 L3 0.20 L1 1.00

and the AI would look at that, check to see whether L2 units were at least 40% of its army, if not, recruit an L2, if so, check whether L3's are 20% of its army, if not, recruit an L3, if so, check to see whether L1's are 100% of its army, they're not (since it must have L2's and L3's to get this far), so it will recruit an L1.

... and I would totally understand if implementing such a feature would be a low priority!
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Campaign AI recruiting

Post by beetlenaut »

Of course the macros I suggested don't work for every situation. It depends on what you want.

I don't like the method of spawning units manually. It seems inelegant. Here is my suggestion for having the control you want. Make a macro RECRUIT_LEVEL LEVEL. You send it 1, 2, or 3, and it modifies the recruit list to only allow the four units of that level. On each recruit event, you choose a random number between 1 and 100. Use that number as your percentage, choose a level based on that, then fire the macro. (Make sure to remove the possibility of getting "3" when there isn't enough gold to recruit a level-3 unit, and so on.)

You could wrap the whole thing into your RECRUIT_UNIT_LEVELS_BY_PROPORTION macro.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
BritNavFan
Posts: 10
Joined: December 17th, 2011, 8:47 pm

Re: Campaign AI recruiting

Post by BritNavFan »

THAT is clever! I like.
User avatar
Coffee
Inactive Developer
Posts: 180
Joined: October 12th, 2010, 8:24 pm

Re: Campaign AI recruiting

Post by Coffee »

A better way to get the AI to recruit a 2/3 goblin to orc ratio army more naturally:

Code: Select all

[event]
     name=turn 1
     
     {MODIFY_AI_ADD_CANDIDATE_ACTION {ENEMY_SIDE} main_loop (
         [candidate_action]
             id=goblin_orc_army
             name=goblin_orc_army
             engine=fai
             type=movement
             evaluation="{AI_CA_RECRUITMENT_SCORE}+100"
             action="recruit(goblin_orc_units[(1 d size(goblin_orc_units))-1])
                     where goblin_orc_units=['Gobin Spearman','Goblin Spearman','Orcish Grunt']"
         [/candidate_action]
     )}
[/event]
     
#you can delete by:
#     {MODIFY_AI_TRY_DELETE_CANDIDATE_ACTION {ENEMY_SIDE} main_loop goblin_orc_army}
BritNavFan
Posts: 10
Joined: December 17th, 2011, 8:47 pm

Re: Campaign AI recruiting

Post by BritNavFan »

I've done some more experimenting, or at least observing, how the AI recruits. It does recruit mixed level forces: based on units' roles (i.e. fighter, archer, mixed fighter, scout, healer.) So if, for example, an AI side can recruit a level 2 "fighter" type (e.g. orc warriors), a level 1 fighter type (e.g. orc grunts), and a level 1 scout type (e.g. wolf riders), it'll recruit orc warriors and wolf riders. But I've never seen it recruit an orc grunt when it could recruit an orc warrior.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Campaign AI recruiting

Post by mattsc »

All: If you want a specific recruiting behavior that seems hard to do in WML, there are probably ways with either Formula AI (as the example given by Coffee) or Lua AI. These wiki pages describe how to do that -- or if you can describe what you want clearly (not: "the AI should be smarter about recruiting"), I can give it a shot. I'm always looking for "little AI projects" like that.

Having said that, I agree with beetlenaut that I generally prefer to let the AI choose what it wants to recruit and manipulate that by changing the recruit lists or something along the lines of the LIMIT_... macros (but there are exceptions to that, when I want a tighter control on what is going on).
Post Reply