MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / init

Method init

src/Battlescape/UnitTurnBState.cpp:56–91  ·  view source on GitHub ↗

* Initializes the state. */

Source from the content-addressed store, hash-verified

54 * Initializes the state.
55 */
56void 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.

Callers

nothing calls this directly

Calls 12

generateFunction · 0.85
getFactionMethod · 0.80
lookAtMethod · 0.80
unitOpensDoorMethod · 0.80
setStateIntervalMethod · 0.45
getTurretTypeMethod · 0.45
getStatusMethod · 0.45
getTileEngineMethod · 0.45
playMethod · 0.45
getSoundMethod · 0.45
getResourcePackMethod · 0.45
popStateMethod · 0.45

Tested by

no test coverage detected