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

Method init

src/Battlescape/ProjectileFlyBState.cpp:69–272  ·  view source on GitHub ↗

* Initializes the sequence: * - checks if the shot is valid, * - calculates the base accuracy. */

Source from the content-addressed store, hash-verified

67 * - calculates the base accuracy.
68 */
69void ProjectileFlyBState::init()
70{
71 if (_initialized) return;
72 _initialized = true;
73
74 BattleItem *weapon = _action.weapon;
75 _projectileItem = 0;
76
77 if (!weapon) // can't shoot without weapon
78 {
79 _parent->popState();
80 return;
81 }
82
83 if (!_parent->getSave()->getTile(_action.target)) // invalid target position
84 {
85 _parent->popState();
86 return;
87 }
88
89 if (_parent->getPanicHandled() &&
90 _action.type != BA_HIT &&
91 _action.type != BA_STUN &&
92 _action.actor->getTimeUnits() < _action.TU)
93 {
94 _action.result = "STR_NOT_ENOUGH_TIME_UNITS";
95 _parent->popState();
96 return;
97 }
98
99 _unit = _action.actor;
100
101 _ammo = weapon->getAmmoItem();
102
103 if (_unit->isOut() || _unit->getHealth() == 0 || _unit->getHealth() < _unit->getStunlevel())
104 {
105 // something went wrong - we can't shoot when dead or unconscious, or if we're about to fall over.
106 _parent->popState();
107 return;
108 }
109
110 // reaction fire
111 if (_unit->getFaction() != _parent->getSave()->getSide())
112 {
113 // no ammo or target is dead: give the time units back and cancel the shot.
114 if (_ammo == 0
115 || !_parent->getSave()->getTile(_action.target)->getUnit()
116 || _parent->getSave()->getTile(_action.target)->getUnit()->isOut()
117 || _parent->getSave()->getTile(_action.target)->getUnit() != _parent->getSave()->getSelectedUnit())
118 {
119 _unit->setTimeUnits(_unit->getTimeUnits() + _unit->getActionTUs(_action.type, _action.weapon));
120 _parent->popState();
121 return;
122 }
123 }
124
125 // autoshot will default back to snapshot if it's not possible
126 if (weapon->getRules()->getAccuracyAuto() == 0 && _action.type == BA_AUTOSHOT)

Callers

nothing calls this directly

Calls 15

getSaveMethod · 0.80
getPanicHandledMethod · 0.80
getTimeUnitsMethod · 0.80
isOutMethod · 0.80
getHealthMethod · 0.80
getStunlevelMethod · 0.80
getFactionMethod · 0.80
getSideMethod · 0.80
getSelectedUnitMethod · 0.80
setTimeUnitsMethod · 0.80
getActionTUsMethod · 0.80
getAccuracyAutoMethod · 0.80

Tested by

no test coverage detected