Author Topic: Finding Units On A Tile  (Read 2407 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Finding Units On A Tile
« on: July 15, 2010, 12:07:15 PM »
Hey, does anyone know if there's a way to check what type of unit is on a specific tile?

Note that I'm not talking about simply detecting any unit on a tile using a trigger.  I want to check a specific location and grab the mapID of the unit on that tile (or return mapNone if no unit is there).
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Finding Units On A Tile
« Reply #1 on: July 15, 2010, 02:14:46 PM »
I don't know of any good way either.

I currently do it by running a RectEnum on one tile (the centre tile for buildings) and using GetNext(<unit>) to get the handle.
"Nothing from nowhere, I'm no one at all"

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Finding Units On A Tile
« Reply #2 on: July 15, 2010, 02:35:21 PM »
What militates against using a LocationEnumerator ? Im using it and it works for me.

What im using is something like

Code: [Select]
LocationEnumerator SpaceportEnum(LOCATION(tr.Location().x-2, tr.Location().y-1));
if(SpaceportEnum.GetNext(unitontile))
{
[Stuff, in my code i checked if its a spaceport with unitontileGetType()]
}
« Last Edit: July 15, 2010, 02:42:54 PM by Flashy »
Praise the mighty light towers!!!

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
Finding Units On A Tile
« Reply #3 on: July 25, 2010, 06:58:33 PM »
Quote
Hey, does anyone know if there's a way to check what type of unit is on a specific tile?

Note that I'm not talking about simply detecting any unit on a tile using a trigger.  I want to check a specific location and grab the mapID of the unit on that tile (or return mapNone if no unit is there).
HFL, or the old GetTile hack. If you go HFL, use GameMapEx::GetTileEx, and check the tile.unitIndex field. I dunno how that works for structures (if at all), though, but it works for vehicles. A LocationEnumerator would probably work as well.

Oh, I should probably commit my HFL fixes (which includes a fix for the aforementioned function, which was horribly broken) to the SVN...
« Last Edit: July 25, 2010, 07:01:21 PM by Arklon »