* 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. */
| 51 | * @param noSound Whether to disable the death sound. |
| 52 | */ |
| 53 | UnitDieBState::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. |
nothing calls this directly
no test coverage detected