Tile occupied by units

For code related discussions and questions
Post Reply
lamer
Greenhorn
Posts: 8
Joined: 27 Nov 2013, 00:01

Tile occupied by units

Post by lamer »

Is there an existing way to tell if a tile (node) is occupied by unit(s) and which unit(s)?

Saw a gridPointTree (quad-tree-like object) though it is optimised for region queries.
I need to query as arbitrary map positions (for moveBlockingTileCallback to tell that we can't see waypoint through friendly units) as the whole map tile by tile (to construct costFactorMap<->blockingMap for A*). Thus i have doubts about querying gridPointTree mapWidth*mapHeight times.
At the moment i added additional info about standing units to the MAPTILE struct. But i don't like the way it's working now (through tracking MOVEINACTIVE/MOVENAVIGATE state changes).

A question related to viewtopic.php?f=30&t=11391
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Tile occupied by units

Post by Per »

No, we do not have what you want. The reason is that units do not map precisely to tiles. One tile may contain several units, if they are small enough. If you want to track units anyway, you can do so through checkLocalFeatures() in move.cpp, but you would have to add a list to each tile, which might be expensive to maintain.
lamer
Greenhorn
Posts: 8
Joined: 27 Nov 2013, 00:01

Re: Tile occupied by units

Post by lamer »

Per wrote:but you would have to add a list to each tile, which might be expensive to maintain.
Thats actually exactly what i've done, it works but need to do some tests to identify the cost of such improvements.
Per wrote:If you want to track units anyway, you can do so through checkLocalFeatures() in move.cpp
Will check this function, as for now i've scattered my brand new occupyTile()/unoccupyTile() all over the place where MOVEINACTIVE, MOVENAVIGATE, MOVESHUFFLE state changes occur. Maybe i'm able to move (un)occupyTile into checkLocalFeatures (or near it as i could use oldx, oldy values) to reduce scattering.

Thanks for the assistance.
Post Reply