Checking if a map cell is occupied by a building

Started by eduran, February 11, 2014, 04:59:42 AM

Previous topic - Next topic

eduran

Is there a smart way to do that? It's required to make a placeable custom unit. The best idea I've come up with is to use GetAllUnitsInRange. If no unit is found, great. Otherwise I'd need to check if the unit takes map space (think PZs, ore patches, air units, CRPL cores). And there are Titans and CNs (or CRPL cores with a custom size), which are not 3x3, so those need to be handled in some way. Seems like a lot of work that has to be done each game tick, while the building preview is following the player's mouse cursor.
Any ideas on how to best tackle the issue?

planetfall

This is rather irritating for me too... my suggestion would be a separate core that watches all units and stores a list of occupied coordinates and only updates when one moves, is built or is destroyed, but that's without having tried it and knowing if it's possible or efficient.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

Clean0nion

Quote from: planetfall on February 11, 2014, 06:18:51 AM
This is rather irritating for me too... my suggestion would be a separate core that watches all units and stores a list of occupied coordinates and only updates when one moves, is built or is destroyed, but that's without having tried it and knowing if it's possible or efficient.
Three lists. X, Y, and UnitType.

J

Does GetUnitAt return the unit even if it's not the center cell of that unit?

eduran

Quote from: J on February 11, 2014, 11:06:36 AM
Does GetUnitAt return the unit even if it's not the center cell of that unit?
Sadly, no. It also runs into trouble when multiple units are in the same spot. It could find the ore patch underneath a mine/air unit above a building/PZ under a building and tell you it's save to build there.

Quote from: planetfall on February 11, 2014, 06:18:51 AM
a separate core that watches all units and stores a list of occupied coordinates and only updates when one moves, is built or is destroyed
But how do you know if a unit moved or was destroyed? Call GetAllUnitsInRange and compare the output to your list, probably. Unless there is another way, I think keeping the list up-to-date is more work than simply calling GetAllUnitsRange without storing the output.

knucracker

The game has an internal occupiedMap that it keeps. It is an array that stores a count of the number of things occupying a cell. I'm looking to stop adding additional Apis to crpl but this will be trivial to expose and since I've not released the new build yet because I'm working on a couple other things...

Clean0nion

Quote from: virgilw on February 11, 2014, 12:53:47 PM
The game has an internal occupiedMap that it keeps. It is an array that stores a count of the number of things occupying a cell. I'm looking to stop adding additional Apis to crpl but this will be trivial to expose and since I've not released the new build yet because I'm working on a couple other things...
So is that available as a list, or just hidden at the current build?

knucracker

It isn't available in the current build.  I'll add an api to return the count of a given map location in the upcoming build.

kwinse

GetCellOccupiedCount is working great, thanks Virgil!