* Initializes the state. */
| 54 | * Initializes the state. |
| 55 | */ |
| 56 | void UnitTurnBState::init() |
| 57 | { |
| 58 | _unit = _action.actor; |
| 59 | _action.TU = 0; |
| 60 | if (_unit->getFaction() == FACTION_PLAYER) |
| 61 | _parent->setStateInterval(Options::battleXcomSpeed); |
| 62 | else |
| 63 | _parent->setStateInterval(Options::battleAlienSpeed); |
| 64 | |
| 65 | // if the unit has a turret and we are turning during targeting, then only the turret turns |
| 66 | _turret = _unit->getTurretType() != -1 && (_action.targeting || _action.strafe); |
| 67 | |
| 68 | _unit->lookAt(_action.target, _turret); |
| 69 | |
| 70 | if (_unit->getStatus() != STATUS_TURNING) |
| 71 | { |
| 72 | if (_action.type == BA_NONE) |
| 73 | { |
| 74 | // try to open a door |
| 75 | int door = _parent->getTileEngine()->unitOpensDoor(_unit, true); |
| 76 | if (door == 0) |
| 77 | { |
| 78 | _parent->getResourcePack()->getSound("BATTLE.CAT", 3)->play(); // normal door |
| 79 | } |
| 80 | if (door == 1) |
| 81 | { |
| 82 | _parent->getResourcePack()->getSound("BATTLE.CAT", RNG::generate(20,21))->play(); // ufo door |
| 83 | } |
| 84 | if (door == 4) |
| 85 | { |
| 86 | _action.result = "STR_NOT_ENOUGH_TIME_UNITS"; |
| 87 | } |
| 88 | } |
| 89 | _parent->popState(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Runs state functionality every cycle. |
nothing calls this directly
no test coverage detected