• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Solved] unit group problem

Status
Not open for further replies.
Level 2
Joined
Mar 11, 2015
Messages
8
how to make a unit group take units only belonging to the enemy of my caster?
 
Last edited by a moderator:
Level 4
Joined
Feb 12, 2016
Messages
71
GroupEnumUnitsInRange

With a filter funtion that does
return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(YourUnit))

Alternatively you just get all units in range and then check for that condition when you loop through the group.

It's on my list to benchmark what is more efficient - I guess it depends on the setting. If there are a lot of non-enemies in range then you will have to remove a lot units from the resulting group, which is likely slower than the filter function calls.
 
Level 7
Joined
Oct 19, 2015
Messages
286
It's on my list to benchmark what is more efficient - I guess it depends on the setting. If there are a lot of non-enemies in range then you will have to remove a lot units from the resulting group, which is likely slower than the filter function calls.
The filter function calls will always be slower, since they grow in proportion to the number of units enumed as well.
 
Level 4
Joined
Feb 12, 2016
Messages
71
The filter function calls will always be slower, since they grow in proportion to the number of units enumed as well.

Sure, but you forget about additional function-calls, that arise from you having to remove more units of the resulting groups when you loop through it.

That is, assuming that you use the FirstOfGroup() -> GrouRemoveUnit() iteration method.

But i guess even if not, with other iteration methods it is the same. More units in the resulting group -> more work.
 
Level 7
Joined
Oct 19, 2015
Messages
286
The point is, adding (with the GroupEnum) and then removing the unit from the group (by calling GroupRemoveUnit, along with the FirstOfGroup call) is less costly than evaluating a filter function. So even if the area contains only units that don't pass the filter, it will still be faster to use a null filter function and then filter the units in the FirstOfGroup loop.
 
Level 4
Joined
Feb 12, 2016
Messages
71
How can you be so certain of this? Its not deducible by logic itself, so it must be something else.

Did you / someone benchmark it already?
 
Status
Not open for further replies.
Top