I have a 2d map in my rts. On the map there are some units. I want to check if there is any unit in range of another. The units range is given in fields. See the image:

On the pic none of units (red, blue, green) can attack each other. I want to, for example check, for example if there is any units in range of blue. The answer is no. I know the blue’s range and position, I also know positions of the rest. I also know if the map xy is occupied. How can I check this?
You want to iterate over all points
(x + i, y + j)around your unit at(x, y)such thatwhere
Ris the range of attack. (This is a disk in the L1-metric.) So, like this:Alternatively, you can halve the outer loop by unrolling:
As @Alink says, you’ll have to handle the map boundary in some way or another.