Outpost Universe Forums

Projects & Development => Outpost 2 Programming & Development => Topic started by: Flashy on November 19, 2010, 03:45:57 PM

Title: Islive And A Dead Unit
Post by: Flashy 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?
Title: Islive And A Dead Unit
Post by: Arklon 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.
Title: Islive And A Dead Unit
Post by: Hooman 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.
 
Title: Islive And A Dead Unit
Post by: Flashy on November 20, 2010, 06:14:19 AM
Ok, thanks.