* Runs state functionality every cycle. */
| 94 | * Runs state functionality every cycle. |
| 95 | */ |
| 96 | void UnitTurnBState::think() |
| 97 | { |
| 98 | const int tu = _unit->getFaction() == _parent->getSave()->getSide() ? 1 : 0; // one turn is 1 tu unless during reaction fire. |
| 99 | |
| 100 | if (_unit->getFaction() == _parent->getSave()->getSide() && _parent->getPanicHandled() && !_action.targeting && !_parent->checkReservedTU(_unit, tu)) |
| 101 | { |
| 102 | _unit->abortTurn(); |
| 103 | _parent->popState(); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | if (_unit->spendTimeUnits(tu)) |
| 108 | { |
| 109 | size_t unitSpotted = _unit->getUnitsSpottedThisTurn().size(); |
| 110 | _unit->turn(_turret); |
| 111 | _parent->getTileEngine()->calculateFOV(_unit); |
| 112 | _unit->setCache(0); |
| 113 | _parent->getMap()->cacheUnit(_unit); |
| 114 | if (_unit->getFaction() == _parent->getSave()->getSide() && _parent->getPanicHandled() && _action.type == BA_NONE && _unit->getUnitsSpottedThisTurn().size() > unitSpotted) |
| 115 | { |
| 116 | _unit->abortTurn(); |
| 117 | } |
| 118 | if (_unit->getStatus() == STATUS_STANDING) |
| 119 | { |
| 120 | _parent->popState(); |
| 121 | } |
| 122 | } |
| 123 | else if (_parent->getPanicHandled()) |
| 124 | { |
| 125 | _action.result = "STR_NOT_ENOUGH_TIME_UNITS"; |
| 126 | _unit->abortTurn(); |
| 127 | _parent->popState(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Unit turning cannot be cancelled. |
nothing calls this directly
no test coverage detected