Recognizing the numbers of units for AI purposes.

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

Recognizing the numbers of units for AI purposes.

Post by BajMic »

Hi,

I am going through the wiki and tutorials, but it still goes a little bit over my head.

Is there a reliable way of recognizing a hex that neighbours with a specific number of units? E.g., define a filter which only includes hexes that have no units on them, but two red and one blue in radius of 1?

Thanks.
User avatar
Spannerbag
Posts: 556
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Recognizing the numbers of units for AI purposes.

Post by Spannerbag »

BajMic wrote: August 12th, 2023, 7:47 pm Hi,

I am going through the wiki and tutorials, but it still goes a little bit over my head.

Is there a reliable way of recognizing a hex that neighbours with a specific number of units? E.g., define a filter which only includes hexes that have no units on them, but two red and one blue in radius of 1?

Thanks.
Hi,
If I understand correctly, you want to find all empty hexes (no unit stationed on it) that have precisely 2 red and one blue units adjacent to it (radius=1).

It would be helpful to know the context for this filter; is it going to be used in a moveto event or to count the number of such locations or something else?

Anyway, assuming you simply want to filter those locations for some reason then I *think* something like this might work (assuming red is side 1 and blue is side 2, if not change the side numbers below accordingly):

Code: Select all

    [filter_location]
        [not]                    # Ensures hex is unoccupied
            [filter]
            [/filter]
        [/not]
        [filter_adjacent_location]
            [filter]
                side=1        # Assumes red=side 1
            [/filter]
            count=2
        [/filter_adjacent_location]
        [filter_adjacent_location]
            [filter]
                side=2        # Assumes blue=side 2
            [/filter]
            count=1
        [/filter_adjacent_location]
    [/filter_location]
I have not tested this so may well have got something wrong.
Also other folk may well come up with better suggestions but hopefully this will give you a starting point?

Anyway, hope this 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...
BajMic
Posts: 46
Joined: January 24th, 2023, 1:22 am

Re: Recognizing the numbers of units for AI purposes.

Post by BajMic »

Yes. This is what I needed, thank you. I am trying to tailor-script the scenario AI to play more human-like.

Can I use the "count" parameter in standard location filters as well? I only used it in conditional tags so far.
User avatar
Celtic_Minstrel
Developer
Posts: 2274
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Recognizing the numbers of units for AI purposes.

Post by Celtic_Minstrel »

It can be used in either [filter_adjacent] or [filter_adjacent_location]. That means it's not available directly in a standard location filter; but [filter_adjacent_location] is part of a standard location filter, so pretty close.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply