WML messenger_ai problem

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
ZombieKnight
Posts: 180
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

WML messenger_ai problem

Post by ZombieKnight »

I store some side=7 units into units_to_micro_ai array, hat works fine.
But the [foreach][micro_ai] works unexpected(leader starts moving to 36,7 while units on units_to_micro_ai array keep fighting)

Code: Select all

[store_unit]
            [filter]
                side=7
                [not]
                    [filter_location]
                        terrain=W*,S*
                    [/filter_location]
                [/not]
                [and]
                    [not]
                        [filter_location]
                            x,y=44,3
                            radius=3
                        [/filter_location]
                    [/not]
                [/and]
            [/filter]
            variable=units_to_micro_ai
        [/store_unit]
        [foreach]
            array=units_to_micro_ai
            [do]
                [micro_ai]
                    side=7
                    ai_type=messenger_escort
                    action=add
                    [filter]
                        id=$units_to_micro_ai[$i].id
                    [/filter]
                    waypoint_x=36
                    waypoint_y=7
                [/micro_ai]
            [/do]
        [/foreach]
(I'm working on retreat micro-ai for nagas that aren't in water, then I want to add them lurker micro_ai so they'll stay in the water)

Any idea whats wrong?
Is there a better way to do so?
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Spannerbag
Posts: 538
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: WML messenger_ai problem

Post by Spannerbag »

I've not used that particular micro_ai but you don't need to use a loop.
Instead, inside your [micro_ai][filter] you could just have find_in=units_to_micro_ai

However, if you only store those units purely to associate them with the micro_ai I think you could replace all your code with:

Code: Select all

[micro_ai]
    side=7
    ai_type=messenger_escort
    action=add
    [filter]
        side=7
        [not]
            [filter_location]
                terrain=W*,S*
            [/filter_location]
        [/not]
        [and]
            [not]
                [filter_location]
                    x,y=44,3
                    radius=3
                [/filter_location]
            [/not]
        [/and]
    [/filter]
    waypoint_x=36
    waypoint_y=7
[/micro_ai]
You might even be able to pack it down a bit more by using a single [filter_location] with the two locations joined with a logical or?
I think this filter should work the same as the one above:

Code: Select all

    [filter]
        side=7
        [not]
            [filter_location]
                terrain=W*,S*
                [or]
                    [and]
                        x,y=44,3
                        radius=3
                    [/and]
                [/or]
            [/filter_location]
        [/not]
    [/filter]
Hope this works/helps!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
white_haired_uncle
Posts: 1226
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: WML messenger_ai problem

Post by white_haired_uncle »

Spannerbag wrote: April 12th, 2024, 10:15 pm
However, if you only store those units purely to associate them with the micro_ai I think you could replace all your code with:
I think that's quite different. The first looks like "If you're not in the water/swamp or near some location RIGHT NOW you get assigned the mai". The second looks like it assigns everyone to the mai, but it's only effective on them if they're not in the water/etc on a given turn.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 180
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: WML messenger_ai problem

Post by ZombieKnight »

Idk why still doesn't work...
I'm shifting to the goto micro_ai
I had saurian in profile before, but I've merged my discord profile with forum one...
User avatar
Spannerbag
Posts: 538
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: WML messenger_ai problem

Post by Spannerbag »

white_haired_uncle wrote: April 12th, 2024, 10:59 pm
Spannerbag wrote: April 12th, 2024, 10:15 pm
However, if you only store those units purely to associate them with the micro_ai I think you could replace all your code with:
I think that's quite different. The first looks like "If you're not in the water/swamp or near some location RIGHT NOW you get assigned the mai". The second looks like it assigns everyone to the mai, but it's only effective on them if they're not in the water/etc on a given turn.
Ah. I'd assumed that the filter would only be referenced when the micro_ai started rather than every turn.
Whenever I've used a micro_ai I've always set it up in prestart or start and assumed everything was only referenced once... but then my filter conditions don't change so I've never had cause to consider/realise that the eligible units are re-evaluated every turn...

However it might be worth trying the first (find_in) version?
If the stored variable isn't changed or deleted that would feed the same units to the micro_ai every turn.
(Even if all of these units killed the code should still work, I imagine.)

If I had the time I'd do some testing but sadly I don't. :(

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
ZombieKnight
Posts: 180
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: WML messenger_ai problem

Post by ZombieKnight »

Jup find_in + goto works...
Checked ai aspects, it's stored there as it is, so your second suggestion would turn it off, as they'll get there.
I had saurian in profile before, but I've merged my discord profile with forum one...
Post Reply