Changing recruitment with [modify_ai].

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
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Changing recruitment with [modify_ai].

Post by BajMic »

Hello, I am trying to follow the wiki https://wiki.wesnoth.org/Modifying_AI_C ... _ai.5D_Tag, however there is something I am doing wrong. May I ask for help with the following blocks? I would be very grateful.

The initial AI:

Code: Select all

  			[aspect]
    				id=recruitment_instructions
    				[facet]
      					[value] 
        					[limit]
							id=corpse_limit
          						type=Walking Corpse
          						max=8
        					[/limit]
        					[recruit]
							id=Garry_recruitment
							importance=0
							leader_id=Garry
        					[/recruit]
      					[/value]
    				[/facet]
  			[/aspect]
The change that doesn't seem to work:

Code: Select all

				[modify_unit]
					[filter]
						id=Harry
					[/filter]
					extra_recruit=Skeleton
				[/modify_unit]
				[modify_ai]
					side=2
 					action=delete
					path=aspect[recruitment_instructions].recruit[corpse_limit]
				[/modify_ai]
				[modify_ai]
					side=2
 					action=add
					path=aspect[recruitment_instructions].recruit[Harry_recruitment]
    					[facet]
      						[value] 
        						[recruit]
								#id=Harry_recruitment
								importance=2
								type=Skeleton
								blocker=no
        						[/recruit]
      						[/value]
    					[/facet]

				[/modify_ai]
				[modify_ai]
					side=2
 					action=change
					path=aspect[recruitment_instructions].recruit[Garry_recruitment]
    					[facet]
      						[value] 
        						[recruit]
								#id=Garry_recruitment
								importance=1
								type=Walking Corpse
								blocker=no
        						[/recruit]
      						[/value]
    					[/facet]
				[/modify_ai]
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Re: Changing recruitment with [modify_ai].

Post by BajMic »

I tried to circumvent the problem, by defining the following at the start:

Code: Select all

  			[aspect]
    				id=recruitment_instructions
    				[facet]
      					[value] 
        					[recruit]
							id=Harry_recruitment
							importance=2
							leader_id=Harry
							type=Skeleton
							blocker=no
        					[/recruit]
        					[recruit]
							id=Garry_recruitment
							importance=1
							leader_id=Garry
							type=Walking Corpse
							blocker=no
							number=8
							total=yes
        					[/recruit]
      					[/value]
    				[/facet]
  			[/aspect]
Then later, once conditions were met, activated the following:

Code: Select all

				[modify_unit]
					[filter]
						id=Harry
					[/filter]
					extra_recruit=Skeleton
				[/modify_unit]
And I can't for the sake of it get the Harry to recruit anything no matter how I tweak these blocks. What I am trying to do is make Harry start recruiting only past a certain point during the scenario.
User avatar
Heindal
Posts: 1506
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Changing recruitment with [modify_ai].

Post by Heindal »

Usually you give a side the ability to recruit something, not a unit. For example:

Code: Select all

        [allow_recruit]
            type=unityouget
            side=sideofyourleader
        [/allow_recruit]
This can be nested inside an event. Which just triggers if you have a specific unit with a special ability.
In Five Fates I use hidden abilities, that are given by level ups and a chosen advancement path.

After an advancement it checks if a unit has this ability and gives the side the ability to recruit the unit.

Here is the code.

Code: Select all

[event]
        name=post advance
        first_time_only=no
        [filter]
            id=you
            ability=ElvishFriend2
        [/filter]
        [allow_recruit]
            type=Elvish Shaman
            side=1
        [/allow_recruit]
    [/event]

You can also modify a side using modify_side and change the recruit list, or setting new ones with the options in this thread:

https://wiki.wesnoth.org/DirectActionsW ... recruit.5D
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Re: Changing recruitment with [modify_ai].

Post by BajMic »

Thank you Heindal. The issue is the same side has two leaders on the opposing sides of the map. One should only be able to recruit WC and the other Skeletons. Can't mix it.
User avatar
ChaosRider
Posts: 1415
Joined: April 15th, 2012, 1:15 pm

Re: Changing recruitment with [modify_ai].

Post by ChaosRider »

Sometimes its good to use in opened game command line:
"debug"
"inspect"
Then you can check on unit which variable contain recruit list, is it a unit or side.
Creator of WOTG (+6400 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.18 Wesnoth server.
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Re: Changing recruitment with [modify_ai].

Post by BajMic »

According to the debug mode, Harry can recruit Skeletons as intended. I also replaced the tag with the one suggested by Ravana, but he still is not recruiting. I am worried that there may be some clash between [ai] being setup while Harry was still unable to recruit Skeletons. Could that be the case anyhow?

I also tend to get the
missing component definition in [modify_ai]
error when trying to tinker with [modify_ai]. Can someone advise me how to write path correctly?

I already tried all the following:

Code: Select all

path=aspect[recruitment_instructions].facet[value].recruit[Harry_recruitment]
path=aspect[recruitment_instructions].facet[].value[].recruit[Harry_recruitment]
path=aspect[recruitment_instructions].facet[].recruit[Harry_recruitment]
path=aspect[recruitment_instructions].recruit[Harry_recruitment]
User avatar
beetlenaut
Developer
Posts: 2885
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Changing recruitment with [modify_ai].

Post by beetlenaut »

BajMic wrote: January 29th, 2026, 7:35 pm I also replaced the tag with the one suggested by Ravana, but he still is not recruiting.
Replaced? Does that mean you put it inside [modify_ai]? It won't work there. It is a direct action that works inside general command blocks (like [event] or [if][then]). If that is where it is, we need to see the code around it because something else is not working. That is the correct tag.
BajMic wrote: January 29th, 2026, 7:35 pmI am worried that there may be some clash between [ai] being setup while Harry was still unable to recruit Skeletons. Could that be the case anyhow?
No.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Celtic_Minstrel
Developer
Posts: 2434
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Changing recruitment with [modify_ai].

Post by Celtic_Minstrel »

BajMic wrote: January 29th, 2026, 4:21 pm Hello, I am trying to follow the wiki https://wiki.wesnoth.org/Modifying_AI_C ... _ai.5D_Tag, however there is something I am doing wrong. May I ask for help with the following blocks? I would be very grateful.
I can see at least two issues in the code in your opening post.
  1. You declare a [limit] with an ID of corpse_limit, but then try to remove a [recruit] with that ID. If you want to remove the limit, it should look like this:

    Code: Select all

    [modify_ai]
    	side=2
    	action=delete
    	aspect[recruitment_instructions].limit[corpse_limit]
    [/modify_ai]
    
  2. When you tried to to add a new [recruit], instead of providing a [recruit] tag, you provided a [facet] tag. To add a new recruitment instruction, I think you'd want it to look like this:

    Code: Select all

    [modify_ai]
    	side=2
    	action=add
    	path=aspect[recruitment_instructions].recruit[]
    	[recruit]
    		id=Harry_recruitment
    		importance=2
    		type=Skeleton
    		blocker=no
    	[/recruit]
    [/modify_ai]
    
    Also notice here that there's no ID passed to the leaf level of the path= when adding a node.
Putting both of those changes together produces the following:

Code: Select all

				[modify_unit]
					[filter]
						id=Harry
					[/filter]
					extra_recruit=Skeleton
				[/modify_unit]
				[modify_ai]
					side=2
 					action=delete
					path=aspect[recruitment_instructions].limit[corpse_limit]
				[/modify_ai]
				[modify_ai]
					side=2
 					action=add
					path=aspect[recruitment_instructions].recruit[]
        				[recruit]
						id=Harry_recruitment
						importance=2
						type=Skeleton
						blocker=no
        				[/recruit]
				[/modify_ai]
				[modify_ai]
					side=2
 					action=change
					path=aspect[recruitment_instructions].recruit[Garry_recruitment]
        				[recruit]
						id=Garry_recruitment
						importance=1
						type=Walking Corpse
						blocker=no
        				[/recruit]
				[/modify_ai]
Does that code work for you?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Re: Changing recruitment with [modify_ai].

Post by BajMic »

It doesn't work. I am trying to figure it out as we speak. I already tested the blocks individually, tried to remove any other coinciding blocks, etc.

Then I made a single block:

Code: Select all

				[modify_ai]
					side=2
					action=delete
					path=aspect[recruitment_instructions].recruit[Garry_recruitment]
				[/modify_ai]
There was no error message, but :inspect showed no change, "Garry_recruitment" was still there, and yet the skeleton started recruiting a turn later... ?

Code: Select all

advancements:  Revenant,Javelineer
aggression:  0.4
allow_ally_villages:  no
caution:  0.25
grouping:  offensive
leader_aggression:  -4
leader_ignores_keep:  no
leader_value:  0
passive_leader:  yes
passive_leader_shares_keep:  no
recruitment_diversity:  2
recruitment_instructions:  
----config begin----
[recruit]
	blocker = yes
	id = Harry_recruitment
	importance = 2
	pattern = no
	total = no
	type = Skeleton
[/recruit]
[recruit]
	blocker = yes
	id = Garry_recruitment
	importance = 1
	leader_id = Garry
	number = 8
	pattern = yes
	total = yes
	type = Walking Corpse
[/recruit]
-----config end-----
recruitment_more:  
recruitment_pattern:  
recruitment_randomness:  50
recruitment_save_gold:  
----config begin----
active = 0
-----config end-----
retreat_enemy_weight:  1
retreat_factor:  0.25
scout_village_targeting:  3
simple_targeting:  no
support_villages:  no
village_value:  0
villages_per_scout:  4
User avatar
Celtic_Minstrel
Developer
Posts: 2434
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Changing recruitment with [modify_ai].

Post by Celtic_Minstrel »

Hmm. Thinking about it, the problem is probably that your recruitment instructions aspect is a composite aspect, so a path without a facet won't match. Try something like this:

The definition (the only change is adding an ID to the facet):

Code: Select all

  			[aspect]
    				id=recruitment_instructions
    				[facet]
    					id=my_recruitment
      					[value] 
        					[limit]
							id=corpse_limit
          						type=Walking Corpse
          						max=8
        					[/limit]
        					[recruit]
							id=Garry_recruitment
							importance=0
							leader_id=Garry
        					[/recruit]
      					[/value]
    				[/facet]
  			[/aspect]
The removal function:

Code: Select all

				[modify_ai]
					side=2
					action=delete
					path=aspect[recruitment_instructions].facet[my_recruitment].recruit[Garry_recruitment]
				[/modify_ai]
Side note: If you wanted, you could shorten the definition a bit:

Code: Select all

[recruitment_instructions]
	id=my_recruitment
	[value] 
		[limit]
			id=corpse_limit
			type=Walking Corpse
			max=8
		[/limit]
		[recruit]
			id=Garry_recruitment
			importance=0
			leader_id=Garry
		[/recruit]
	[/value]
[/recruitment_instructions]
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
BajMic
Posts: 140
Joined: January 24th, 2023, 1:22 am

Re: Changing recruitment with [modify_ai].

Post by BajMic »

Sorry for responding so late, I could only check now.

It finally worked, thank you Celtic Minstrel.

I started with:

Code: Select all

  			[aspect]
    				id=recruitment_instructions
    				[facet]
    					id=my_recruitment
      					[value] 
        					[recruit]
							id=Harry_recruitment
							importance=2
							#leader_id=Harry
							type=Skeleton
							blocker=no
        					[/recruit]
        					[recruit]
							id=Garry_recruitment
							importance=1
							leader_id=Garry
							type=Walking Corpse
							#blocker=no
							number=8
							total=yes
        					[/recruit]
      					[/value]
    				[/facet]
  			[/aspect]
Changed to:

Code: Select all

				[modify_ai]
					side=2
					action=delete
					path=aspect[recruitment_instructions].facet[my_recruitment].recruit[Garry_recruitment]
				[/modify_ai]
Inspect:

Code: Select all

advancements:  Revenant,Javelineer
aggression:  0.4
allow_ally_villages:  no
caution:  0.25
grouping:  offensive
leader_aggression:  -4
leader_ignores_keep:  no
leader_value:  0
passive_leader:  yes
passive_leader_shares_keep:  no
recruitment_diversity:  2
recruitment_instructions:  
----config begin----
[recruit]
	blocker = no
	id = Harry_recruitment
	importance = 2
	pattern = yes
	total = no
	type = Skeleton
[/recruit]
-----config end-----
recruitment_more:  
recruitment_pattern:  
recruitment_randomness:  50
recruitment_save_gold:  
----config begin----
active = 0
-----config end-----
retreat_enemy_weight:  1
retreat_factor:  0.25
scout_village_targeting:  3
simple_targeting:  no
support_villages:  no
village_value:  0
villages_per_scout:  4
Next, I edited the starting block:

Code: Select all

  			[aspect]
    				id=recruitment_instructions
      					[value] 
        					[recruit]
							id=Harry_recruitment
							importance=2
							#leader_id=Harry
							type=Skeleton
							blocker=no
        					[/recruit]
        					[recruit]
							id=Garry_recruitment
							importance=1
							leader_id=Garry
							type=Walking Corpse
							#blocker=no
							number=8
							total=yes
        					[/recruit]
      					[/value]
  			[/aspect]
And it worked, too.

Thank you for your patience.
Post Reply