------------------------------------------ Compute Unit Existence ----------------------------------------
| 68 | } |
| 69 | //------------------------------------------ Compute Unit Existence ---------------------------------------- |
| 70 | void GameImpl::computeUnitExistence() |
| 71 | { |
| 72 | for(Unit ui : aliveUnits) //all alive units are dying until proven alive |
| 73 | { |
| 74 | UnitImpl *u = static_cast<UnitImpl*>(ui); |
| 75 | u->wasAlive = true; |
| 76 | u->isAlive = false; |
| 77 | } |
| 78 | |
| 79 | //set the wasAccessible and wasVisible fields |
| 80 | for (Unit u : accessibleUnits) |
| 81 | { |
| 82 | static_cast<UnitImpl*>(u)->wasAccessible = true; |
| 83 | } |
| 84 | for (Unit u : evadeUnits) |
| 85 | { |
| 86 | static_cast<UnitImpl*>(u)->wasAccessible = false; |
| 87 | } |
| 88 | //fill dyingUnits set with all aliveUnits and then clear the aliveUnits set. |
| 89 | dyingUnits = aliveUnits; |
| 90 | aliveUnits.clear(); |
| 91 | |
| 92 | // (We assume isAlive is false for all dyingUnits currently) |
| 93 | // Now we will add alive units to the aliveUnits set and set their isAlive flag to true |
| 94 | |
| 95 | //compute alive units |
| 96 | for ( UnitImpl* u = UnitImpl::BWUnitToBWAPIUnit(BW::BWDATA::UnitNodeList_VisibleUnit_First); u; u = u->getNext() ) |
| 97 | { |
| 98 | if ( isUnitAlive(u) ) |
| 99 | { |
| 100 | u->isAlive = true; |
| 101 | aliveUnits.insert(u); |
| 102 | u->updateInternalData(); |
| 103 | } |
| 104 | } |
| 105 | for ( UnitImpl* u = UnitImpl::BWUnitToBWAPIUnit(BW::BWDATA::UnitNodeList_HiddenUnit_First); u; u = u->getNext() ) |
| 106 | { |
| 107 | if ( isUnitAlive(u, true) ) |
| 108 | { |
| 109 | u->isAlive = true; |
| 110 | aliveUnits.insert(u); |
| 111 | u->updateInternalData(); |
| 112 | } |
| 113 | } |
| 114 | for ( UnitImpl* u = UnitImpl::BWUnitToBWAPIUnit(BW::BWDATA::UnitNodeList_ScannerSweep_First); u; u = u->getNext() ) |
| 115 | { |
| 116 | if ( isUnitAlive(u) ) |
| 117 | { |
| 118 | u->isAlive = true; |
| 119 | aliveUnits.insert(u); |
| 120 | u->updateInternalData(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Since we know isAlive is false for the dying units, but true for the alive units, |
| 125 | // then we can remove the alive ones from the dyingUnits set in linear fashion |
| 126 | auto it = dyingUnits.begin(); |
| 127 | while ( it != dyingUnits.end() ) |
nothing calls this directly
no test coverage detected