AI recruitment with persistent=yes

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
MadMax
Posts: 1792
Joined: June 6th, 2004, 3:29 pm
Location: Weldyn, Wesnoth

AI recruitment with persistent=yes

Post by MadMax »

I'm trying to give an AI side a recall list, and I found that it only works if I set persistent=yes in its [side] tag. However, with persistent=yes, the side does not spend all its gold recruiting (possibly saving gold for future scenarios). I'd like the side to be able to recall, but have the default recruiting behavior as well (not caring about its income). Is there any way to do this? Thanks
"ILLEGITIMIS NON CARBORUNDUM"

Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: AI recruitment with persistent=yes

Post by tekelili »

I dont know if there is a solution for your problem, but in case none provides you one, I had also a problem with AI recalling for different reasons, and did this code to hack them. May be you find something usefull in case you need a "desperate" solution
Spoiler:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: AI recruitment with persistent=yes

Post by beetlenaut »

You could also let the AI recruit as normal, then use a recruit event to give each unit a random number of XP, and give the AI a refund for the cost of the unit minus 20. That won't work well when the AI gets low on gold, but you might want it to just recruit a couple level-1 units at that point anyway.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: AI recruitment with persistent=yes

Post by SkyOne »

Hi MadMax,

Glad to see you are back.:)

Anyway, like you said, since BfW 1.11.7, the AI saves gold: http://forums.wesnoth.org/viewtopic.php?f=21&t=39700
It probably affects your issue, I guess.

So you probably just need:

Code: Select all

[ai]
    [aspect]
        id=recruitment_save_gold
        [facet]
            [value]
                active=0
            [/value]
        [/facet]
    [/aspect]
[/ai]
in the side.
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: AI recruitment with persistent=yes

Post by James_The_Invisible »

Actually, in the last post of the thread that you linked
mattsc wrote:Another quick update: The following will be in the release notes when 1.11.9 comes out:
RCA (default) AI gold saving default is reverted back to 'off'
so the cause of the described behavior is probably different and your code will not change anything.
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: AI recruitment with persistent=yes

Post by SkyOne »

James_The_Invisible wrote:Actually, in the last post of the thread that you linked
mattsc wrote:Another quick update: The following will be in the release notes when 1.11.9 comes out:
RCA (default) AI gold saving default is reverted back to 'off'
so the cause of the described behavior is probably different and your code will not change anything.
Uh-oh! :shock: You are right.
I just have run a scenario that affects the matter without the code (removing) on 1.11.16. It is off now.

Sorry MadMax. It doesn't help at all...
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
MadMax
Posts: 1792
Joined: June 6th, 2004, 3:29 pm
Location: Weldyn, Wesnoth

Re: AI recruitment with persistent=yes

Post by MadMax »

SkyOne wrote:Uh-oh! :shock: You are right.
I just have run a scenario that affects the matter without the code (removing) on 1.11.16. It is off now.

Sorry MadMax. It doesn't help at all...
Tested, doesn't work. I noticed though that if the recall list is empty, the AI seems to recruit normally (even with persistent=yes). Could this be a bug?
"ILLEGITIMIS NON CARBORUNDUM"

Father of Flight to Freedom
http://www.wesnoth.org/wiki/FlightToFreedom
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI recruitment with persistent=yes

Post by mattsc »

MadMax wrote:I noticed though that if the recall list is empty, the AI seems to recruit normally (even with persistent=yes). Could this be a bug?
That does sound like a bug, yes. I thought that I had done something like this previously and it worked, but I haven't tried recently. Which version of Wesnoth are you using? I'll test this, but it might be a week or so before I get to it.
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: AI recruitment with persistent=yes

Post by James_The_Invisible »

Why should it be a bug? What would you do if you lost all your veterans? (No matter if it is a result of a bad strategy or a decision of scenario's designer.) I believe that you would start recruiting new units.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI recruitment with persistent=yes

Post by mattsc »

James_The_Invisible wrote:Why should it be a bug? What would you do if you lost all your veterans? (No matter if it is a result of a bad strategy or a decision of scenario's designer.) I believe that you would start recruiting new units.
Indeed. That's not the bug. The way how I understood the question was that the previously described behavior in combination with this might be a bug: If the recall list is empty, the AI recruits. If it is not empty, it does not recruit (if there's gold left for recruiting but not for recalling). Is the latter behavior a bug given that it works when the recall list is empty?

However, thinking about it some more, I think that this is not actually a bug per se but rather non-perfect AI behavior. If I remember correctly, the AI always recalls all units first and only starts recruiting once it is done with that. It will recall a walking corpse for 20 gold rather than getting a new one from the recruit list. Thus, this is a "feature" (albeit admittedly not a good one) rather than a bug. (Note that I was not involved in the development of this, that was "before my time", so I'm just basing this on observations of AI behavior.)
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: AI recruitment with persistent=yes

Post by James_The_Invisible »

If I remember correctly,the AI always recalls all units first and only starts recruiting once it is done with that.
Yes, I have observed this too. And yes, it would be better to recruit any new unit (even a wc) than recall a walking corpse for 20 gold. But I can see that this behavior comes only from macro RECALL_AI_SIDE and one can define a better one with only wml. It would not be so easy but it is possible. (I do not know what all setting persistent attribute of [side] to yes does. I have only seen that it stores side's leader, recall list and gold.)
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI recruitment with persistent=yes

Post by mattsc »

James_The_Invisible wrote:I do not know what all setting persistent attribute of [side] to yes does.
If I remember correctly, it is needed since non-persistent sides have no recall list and persistent=no is the default for AI sides.
James_The_Invisible wrote:But I can see that this behavior comes only from macro RECALL_AI_SIDE and one can define a better one with only wml. It would not be so easy but it is possible.
Well, actually, no that is not what controls the default recalling, which is done from within the AI C++ code. This macro is an alternative to that, that could be used instead. Maybe it was written before the AI engine could handle recalls? Just guessing here ... But yes, this could in principle be modified to do alternative recalling. However ...

So I did some quick tests over lunch break of this using my own test scenario and Wesnoth 1.11.16 and none of those problems exist there. The AI will happily mix recalls and recruits even if the recall list is not empty yet. And it stubbornly refuses to recall walking corpses, peasants or other units it does not consider worth the gold, just as it should. This was all changed when flixx implemented the new recruitment mechanism for Wesnoth 1.11.7.

MadMax: does that mean that you are using a version earlier than 1.11.7? If so, then you can consider this fixed. If not, could you post your scenario and a start-of-scenario save so that we can figure out what's going on, as it seems to work for me.
Post Reply