Author Topic: Islive And A Dead Unit  (Read 1505 times)

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Islive And A Dead Unit
« on: November 19, 2010, 03:45:57 PM »
Just to be sure, if you call IsLive() on a dead unit, the unitID gets set to 0, right?
Praise the mighty light towers!!!

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Islive And A Dead Unit
« Reply #1 on: November 19, 2010, 06:32:47 PM »
Quote
Just to be sure, if you call IsLive() on a dead unit, the unitID gets set to 0, right?
I don't think so.
Also, unit 0 always = some kind of "root" unit or whatever. Calling many of the other unit functions on it will cause the game to crash, as will calling them on "invalid" unit IDs. IsLive() always seems to be safe, though, so long as you're not setting the unit ID to something out of the unit array's bounds.
« Last Edit: November 19, 2010, 06:34:52 PM by Arklon »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Islive And A Dead Unit
« Reply #2 on: November 20, 2010, 02:06:09 AM »
That is actually correct. The IsLive function works something like this:

Code: [Select]
// Untested pseudo code
int _Unit::IsLive()
{
  if (this->unitIndex == 0)
    return FALSE;

  Unit* unit = map.unit[this->unitIndex];
  if ((unit->next != -1) && ((unit->flags & IsDeadFlag) == 0))
    return TRUE;

  this->unitIndex = 0;  //  ** Clear unitIndex to 0
  return FALSE;
}


So if FALSE is returned, then the unitIndex either already was 0, or it just got set to 0.
 
« Last Edit: November 20, 2010, 02:07:08 AM by Hooman »

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Islive And A Dead Unit
« Reply #3 on: November 20, 2010, 06:14:19 AM »
Ok, thanks.
Praise the mighty light towers!!!