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

Method UnitDieBState

src/Battlescape/UnitDieBState.cpp:53–95  ·  view source on GitHub ↗

* Sets up an UnitDieBState. * @param parent Pointer to the Battlescape. * @param unit Dying unit. * @param damageType Type of damage that caused the death. * @param noSound Whether to disable the death sound. */

Source from the content-addressed store, hash-verified

51 * @param noSound Whether to disable the death sound.
52 */
53UnitDieBState::UnitDieBState(BattlescapeGame *parent, BattleUnit *unit, ItemDamageType damageType, bool noSound) : BattleState(parent), _unit(unit), _damageType(damageType), _noSound(noSound)
54{
55 // don't show the "fall to death" animation when a unit is blasted with explosives or he is already unconscious
56 if (_damageType == DT_HE || _unit->getStatus() == STATUS_UNCONSCIOUS)
57 {
58 _unit->startFalling();
59
60 while (_unit->getStatus() == STATUS_COLLAPSING)
61 {
62 _unit->keepFalling();
63 }
64 }
65 else
66 {
67 if (_unit->getFaction() == FACTION_PLAYER)
68 {
69 _parent->getMap()->setUnitDying(true);
70 }
71 _parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED);
72 _originalDir = _unit->getDirection();
73 if (_originalDir != 3)
74 {
75 _parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED / 3);
76 }
77 }
78
79 _unit->clearVisibleTiles();
80 _unit->clearVisibleUnits();
81
82 if (_unit->getFaction() == FACTION_HOSTILE)
83 {
84 std::vector<Node *> *nodes = _parent->getSave()->getNodes();
85 if (!nodes) return; // this better not happen.
86
87 for (std::vector<Node*>::iterator n = nodes->begin(); n != nodes->end(); ++n)
88 {
89 if (_parent->getSave()->getTileEngine()->distanceSq((*n)->getPosition(), _unit->getPosition()) < 4)
90 {
91 (*n)->setType((*n)->getType() | Node::TYPE_DANGEROUS);
92 }
93 }
94 }
95}
96
97/**
98 * Deletes the UnitDieBState.

Callers

nothing calls this directly

Calls 15

startFallingMethod · 0.80
keepFallingMethod · 0.80
getFactionMethod · 0.80
setUnitDyingMethod · 0.80
clearVisibleTilesMethod · 0.80
clearVisibleUnitsMethod · 0.80
getNodesMethod · 0.80
getSaveMethod · 0.80
distanceSqMethod · 0.80
getStatusMethod · 0.45
getMapMethod · 0.45
setStateIntervalMethod · 0.45

Tested by

no test coverage detected