* Runs state functionality every cycle. * Progresses the fall, updates the battlescape, ... */
| 72 | * Progresses the fall, updates the battlescape, ... |
| 73 | */ |
| 74 | void UnitFallBState::think() |
| 75 | { |
| 76 | for (std::list<BattleUnit*>::iterator unit = _parent->getSave()->getFallingUnits()->begin(); unit != _parent->getSave()->getFallingUnits()->end();) |
| 77 | { |
| 78 | if ((*unit)->getStatus() == STATUS_TURNING) |
| 79 | { |
| 80 | (*unit)->abortTurn(); |
| 81 | } |
| 82 | bool largeCheck = true; |
| 83 | bool falling = true; |
| 84 | int size = (*unit)->getArmor()->getSize() - 1; |
| 85 | if ((*unit)->getHealth() == 0 || (*unit)->getStunlevel() >= (*unit)->getHealth()) |
| 86 | { |
| 87 | unit = _parent->getSave()->getFallingUnits()->erase(unit); |
| 88 | continue; |
| 89 | } |
| 90 | bool onScreen = ((*unit)->getVisible() && _parent->getMap()->getCamera()->isOnScreen((*unit)->getPosition(), true)); |
| 91 | Tile *tileBelow = _parent->getSave()->getTile((*unit)->getPosition() + Position(0,0,-1)); |
| 92 | for (int x = size; x >= 0; x--) |
| 93 | { |
| 94 | for (int y = size; y >= 0; y--) |
| 95 | { |
| 96 | Tile *otherTileBelow = _parent->getSave()->getTile((*unit)->getPosition() + Position(x,y,-1)); |
| 97 | if (!_parent->getSave()->getTile((*unit)->getPosition() + Position(x,y,0))->hasNoFloor(otherTileBelow) || (*unit)->getArmor()->getMovementType() == MT_FLY) |
| 98 | { |
| 99 | largeCheck = false; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | falling = largeCheck |
| 105 | && (*unit)->getPosition().z != 0 |
| 106 | && (*unit)->getTile()->hasNoFloor(tileBelow) |
| 107 | && (*unit)->getArmor()->getMovementType() != MT_FLY |
| 108 | && (*unit)->getWalkingPhase() == 0; |
| 109 | |
| 110 | if (falling) |
| 111 | { |
| 112 | // Tile(s) unit is falling into. |
| 113 | for (int x = (*unit)->getArmor()->getSize() - 1; x >= 0; --x) |
| 114 | { |
| 115 | for (int y = (*unit)->getArmor()->getSize() - 1; y >= 0; --y) |
| 116 | { |
| 117 | Tile *tileBelow = _parent->getSave()->getTile((*unit)->getPosition() + Position(x,y,-1)); |
| 118 | tilesToFallInto.push_back(tileBelow); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Check each tile for units that need moving out of the way. |
| 123 | for (std::vector<Tile*>::iterator i = tilesToFallInto.begin(); i < tilesToFallInto.end(); ++i) |
| 124 | { |
| 125 | BattleUnit *unitBelow = (*i)->getUnit(); |
| 126 | if (unitBelow |
| 127 | && (*unit) != unitBelow // falling units do not fall on themselves |
| 128 | && !(std::find(unitsToMove.begin(), unitsToMove.end(), unitBelow) != unitsToMove.end())) // already added |
| 129 | { |
| 130 | unitsToMove.push_back(unitBelow); |
| 131 | } |
nothing calls this directly
no test coverage detected