Questions about AI healer_support, zone_guardian and Retreat CA

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
vghetto
Posts: 167
Joined: November 2nd, 2019, 5:12 pm

Questions about AI healer_support, zone_guardian and Retreat CA

Post by vghetto »

Hi,

I have an allied AI side with no leaders (side 9).
This side is controlled by a couple of mirco_ais, mainly zone_guardian and healer_support.
The zone that the AI protects is the radius around the human player units (side 1), and it's own units (side 9).

When there isn't any enemy around, then some specific location is given for regrouping with station_x,station_y.

The ca_score for the healer_support is the default value, but for the zone_guardian I've set it to be 30000, which is less than the Retreat CA of 40000.

It all works well, but my main issues are with village grabbing for the purpose of healing and the healers.

The healers seem to actively seek out injured units only when in combat mode. They don't go after the injured units when there aren't any threats, i.e. the units are back to station_x,y.

And since they have no leaders, and all of the villages are owned by side 1, the Retreat CA won't use any of the villages for the purpose of healing.
If they happen to land on side 1's villages by random chance, then the Retreat CA seems to take over and they will stay there until they are fully healed before zone_guardian takes over and they move on.

My questions are:
1) How can I make the healers heal when not in combat mode?
2) How can I make the injured units use the nearby side 1 villages for healing?

More specifically, how can I make the Retreat CA use owned side 1 villages?
Hopefully without lowering the ca score further or using move-to-targets ca.

Thanks in advance.

Code: Select all

[micro_ai]
        action=add
        side=9
        ai_type=healer_support
        ca_id=healer_support_king
        aggression=1.0
        injured_units_only=yes
[/micro_ai]

[micro_ai]
        action=add
        side=9
        ai_type=zone_guardian
        ca_id=zone_guardian_king
        # less than Retreat 40000
        ca_score=30000
        [filter]
                side=9
        [/filter]
        [filter_location]
                [and]
                        [filter]
                                side=1,9
                        [/filter]
                        radius=6
                [/and]
        [/filter_location]
        station_x,station_y=$meeting_loc.x,$meeting_loc.y
[/micro_ai]
Edit: My bad, meant Healing CA, not Retreat CA, or whichever is relevant to getting on the village for the purpose of healing.

Edit2: I have a feeling that the answer will involve injecting a new custom CA somewhere :)
A new question, is generic_rush_engine.lua the same as the default RCA_AI?

Edit3: I think I got this. I'm creating my own copy of micro_ai called wf_zone_guardian and checking if guardian.hitpoints < guardian.max_hitpoints in the station part of code. Now it's only a matter of getting the lua right.

Edit4: If anyone is interested, a couple of new micro_ais.
zone_guardian with village healing
https://github.com/virtualghetto/Wild_F ... ardian.lua

a bonus micro_ai:
guardian variation called loiter_guardian :) It is a mish mash of return_guardian, lurker and zone_guardian lol
https://github.com/virtualghetto/Wild_F ... ardian.lua

defs are here: https://github.com/virtualghetto/Wild_F ... /wf_ai.lua

Edit5: yet another guardian variation called curse_guardian. Based on the attack code of zone_guardian, it moves and attacks units defined in filter_second. it does nothing if there aren't any targets.
https://github.com/virtualghetto/Wild_F ... ardian.lua

mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Questions about AI healer_support, zone_guardian and Retreat CA

Post by mattsc »

Hey vghetto,

Very nice, adjusting the Micro AIs to your needs! That's really how we meant it back in the day. We set up a variety of "default" behaviors, but it is impossible to predict every possible use, so modifying them to your use case might sometimes be the best way forward.

Sorry for the slow reply. There was something I wanted to look into and I just hadn't gotten around to it yet. You said that the Healer Support MAI does not heal units unless there's an enemy threatening them. I looked back into the code, that's not how it's supposed to be. Healers prefer units threatened by enemies, but if none of those in reach (of the healers), they should choose unthreatened units. If you have an example save where this is (not) happening, could you send it to me to check out? If that's what's going it, it sounds like a bug.

And: generic_rush_engine.lua is the engine for the extra CAs of the Experimental AI.

Besides that, it looks like you answered all your questions yourself, but let me know if I missed something.

vghetto
Posts: 167
Joined: November 2nd, 2019, 5:12 pm

Re: Questions about AI healer_support, zone_guardian and Retreat CA

Post by vghetto »

mattsc wrote:
June 6th, 2020, 6:40 pm
You said that the Healer Support MAI does not heal units unless there's an enemy threatening them. I looked back into the code, that's not how it's supposed to be. Healers prefer units threatened by enemies, but if none of those in reach (of the healers), they should choose unthreatened units. If you have an example save where this is (not) happening, could you send it to me to check out? If that's what's going it, it sounds like a bug.
Thanks mattsc.
Please see attached demo of the healer not helping the poor soldiers :(
Click on End Turn to get it going.

I tried setting injured_units_only to yes and no. both gave the same result.

Ugh... Edit again: I'm noticing that the units get random_traits, I thought random_traits default was no :?

One more Edit: I forgot to add an enemy side in the attachment, but that doesn't change anything. I tried.

Ok, we have a map with no villages, 2 injured units and healers. What would a human player do?
Most likely move the healer towards the injured units, which is what I expected the healer_support to do. Or, move the injured units towards the healer, which I expected the Healing/Retreat? CA to do. But, as the attachment demonstrates, neither of those options took place.

Edit: Problem seems to stem from the soldiers having movement points. I'm reuploading the attachment. I including an event on turn refresh that takes away the moves from the injured units. In that case the healer will go after the first injured unit. But it won't go after the other injured unit because it is 2 hops away I guess.
Attachments
_main.cfg
(3.06 KiB) Downloaded 28 times

mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Questions about AI healer_support, zone_guardian and Retreat CA

Post by mattsc »

It looks like you figured out the issue yourself again. :-) (I didn't see that until after I looked into the demo you first posted.) Indeed, the reason why the healers don't go for those injured units is because, in the original version you posted, they have MP left. That's done so that the rest of the AI doesn't move units away after the healers are placed next to them. In scenarios with enemies and villages, that's generally not a problem because all units move somewhere.

I guess what we could do is have the Micro AI also evaluate healer moves toward units that have moves left, and return those only when no moves toward units without moves are found, but with a very low CA score. That would then kick in at the end of the evaluation, only if no other moves are done (as in your test case).

And yes, the healers not moving toward the other injured unit is because it is out of range. Doing something about that would be much more complex for general use, as it would require weighing that move against other moves looking one or several turns ahead. Trying to do that (around the current AI) would cause more problems than it solves, but if you wanted it for a custom AI in a specific scenario it wouldn't be too hard to write.
vghetto wrote:
June 6th, 2020, 11:15 pm
Or, move the injured units towards the healer, which I expected the Healing/Retreat? CA to do.
As you noticed, they don't do that. The retreat CA in 1.14 is the original C++ CA and it's very limited. 1.15 has a somewhat improved version of the 1.14 Experimental AI's retreat_injured CA, but it probably would not work quite like that either. In order to "do this right", you'd really have to have the two CAs (healing and retreating) coordinate their moves to some extent. You did that for your scenario with the custom CAs you created, but doing it so that it works in general without too many side effects is more difficult, I think. Still, it's something we should think about and, for example, in the Fred AI I am certainly attempting to coordinate moves by different CAs. For example, it "reserves" healing locations for units who should retreat; but it does not actively coordinate that with healer moves (yet).

vghetto
Posts: 167
Joined: November 2nd, 2019, 5:12 pm

Re: Questions about AI healer_support, zone_guardian and Retreat CA

Post by vghetto »

Thank you for the response.
Initially the healer not actively seeking the injured stopped being a priority in my case, because the altered zone_guardian took care of that. The injured units healed themselves. But I thought, why not, I'd give it a shot and try to make a variation on the healer move ca for my mod. I failed miserably. The healer_support code turned out to be too complex for me with extract unit, attack maps, and playing with the score so this happens before that and stuff, I couldn't do it. :oops:

On a different note, this might not be a big deal since the ca_id text might not count for much, but I noticed that in the misc mai defs, ca_simple_attack.lua for the assassin is designated with ca_id attack but for simple_attack, the same file is designated as ca_id move.

mattsc
Developer
Posts: 1166
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Questions about AI healer_support, zone_guardian and Retreat CA

Post by mattsc »

It's always hard to understand somebody else's code, esp. if it's dealing with something that one is not very familiar with (which you might or might not be, I don't know). Let me know if there is something specific you would still like to do or change, and I am sure we can work it out together.
vghetto wrote:
June 8th, 2020, 10:16 pm
On a different note, this might not be a big deal since the ca_id text might not count for much, but I noticed that in the misc mai defs, ca_simple_attack.lua for the assassin is designated with ca_id attack but for simple_attack, the same file is designated as ca_id move.
Yeah, that actually does not matter at all for any practical purposes. It's just an internal identifier assigned to the candidate action. It could be set to anything. The only important part is that it is different for each CA if the AI has more than one CA.

Post Reply