Closed Sanian-Creations closed 3 years ago
Yeah, that's basically how this API works at its core. It searches the "map footprint" array for units. So this API (as is) will have to stay.
An alternate might be GetUnitsByType and then to do a range check. That's have some things work internally (like snipers shooting at blobs or skimmers).
I could add a new API that searches all units, but the efficiency of that could be problematic. It would O(n) where n is the number of units on a map which can be in the hundreds or even a thousand. The current API only has to search nearby array cells to see if they have unit footprints in them.
Of course if the entire map is being searched, the current API is terrible when it comes to efficiency... So maybe another API that looks across all units would be warranted. Or an API that looks across all units of a certain type (like GetUnitsByType) but it also has filter options (like range, etc).
Added a new GetUnits API.
Switching off the setting "occupies land" will hide that unit from showing up in any search done with GetUnitsInRange.
Reproduce
Place a custom unit somewhere on the map
Run the following script from the console:
The uid of any unit withing 10 tiles of the cursor will now be printed to the console. It should do this for the unit we just placed.
Go to the CPACK Manager, click the unit type we just placed and uncheck "occupies land" under Settings > Basic, then click "Update Unit instances".
Running the same script again will now no longer show the unit we previously placed.
On one hand it makes sense that it doesn't detect units with the setting turned off because they don't take up any space, but this is a real thorn in the eye when trying to work with units that either fly, dig in the ground or just move over the ground without preventing the player from building there, those units mustn't occupy land but we still want to check whenever they get in range of something.