MCPcopy Create free account
hub / github.com/bwapi/bwapi / isUnitAlive

Function isUnitAlive

bwapi/BWAPI/Source/BWAPI/GameUnits.cpp:26–68  ·  view source on GitHub ↗

------------------------------------------------ IS UNIT ALIVE

Source from the content-addressed store, hash-verified

24 }
25 //------------------------------------------------ IS UNIT ALIVE
26 bool inline isUnitAlive(UnitImpl* i, bool isHidden = false)
27 {
28 //this function determines if a unit in one of the alive unit lists is actually "alive" according to BWAPI
29 //this function is only used in computeUnitExistence and shouldn't be called from any other function
30
31 if ( !i ) return false;
32
33 BW::CUnit *u = i->getOriginalRawData;
34 if ( !u ) return false;
35
36 UnitType _getType = BWAPI::UnitType(u->unitType);
37
38 // Replica of official UnitInterface::IsDead function
39 if ( !u->sprite || (u->orderID == Orders::Die && u->orderState == 1) )
40 {
41 //Broodwar->printf("%s has met a true death", _getType.getName().c_str());
42 return false;
43 }
44 // The rest is garbage?
45
46 if ( u->orderID == Orders::Die && u->orderState != 1)
47 { // Starcraft will keep a unit alive when order state is not 1
48 // if for some reason the "die" order was interrupted, the unit will remain alive with 0 hp
49 //Broodwar->printf("Bad logic, %s would not die with order state %u", _getType.getName().c_str(), u->orderState);
50 return false;
51 }
52
53 if ( isHidden ) //usually means: is inside another unit?
54 {
55 if (_getType == UnitTypes::Unknown)
56 { // Unknown units are not actually dead, idk why we assume so
57 //Broodwar->printf("Bad logic?, unknown unit type death");
58 return false;//skip subunits if they are in this list
59 }
60 else if (_getType == UnitTypes::Protoss_Scarab )
61 { // some reason we decided all protoss scarabs are dead
62 //Broodwar->printf("Bad logic?, %s death", _getType.getName().c_str());
63 return false;
64 }
65 }
66 // unit is alive otherwise
67 return true;
68 }
69 //------------------------------------------ Compute Unit Existence ----------------------------------------
70 void GameImpl::computeUnitExistence()
71 {

Callers 1

computeUnitExistenceMethod · 0.85

Calls 1

UnitTypeClass · 0.70

Tested by

no test coverage detected