* Initializes the explosion. * The animation and sound starts here. * If the animation is finished, the actual effect takes place. */
| 68 | * If the animation is finished, the actual effect takes place. |
| 69 | */ |
| 70 | void ExplosionBState::init() |
| 71 | { |
| 72 | if (_item) |
| 73 | { |
| 74 | _power = _item->getRules()->getPower(); |
| 75 | _pistolWhip = (_item->getRules()->getBattleType() != BT_MELEE && |
| 76 | _parent->getCurrentAction()->type == BA_HIT); |
| 77 | if (_pistolWhip) |
| 78 | { |
| 79 | _power = _item->getRules()->getMeleePower(); |
| 80 | } |
| 81 | // since melee aliens don't use a conventional weapon type, we use their strength instead. |
| 82 | if (_item->getRules()->isStrengthApplied()) |
| 83 | { |
| 84 | _power += _unit->getStats()->strength; |
| 85 | } |
| 86 | |
| 87 | _areaOfEffect = _item->getRules()->getBattleType() != BT_MELEE && |
| 88 | _item->getRules()->getExplosionRadius() != 0 && |
| 89 | !_pistolWhip; |
| 90 | } |
| 91 | else if (_tile) |
| 92 | { |
| 93 | _power = _tile->getExplosive(); |
| 94 | _areaOfEffect = true; |
| 95 | } |
| 96 | else if (_unit && _unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH) |
| 97 | { |
| 98 | _power = _parent->getRuleset()->getItem(_unit->getArmor()->getCorpseGeoscape())->getPower(); |
| 99 | _areaOfEffect = true; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | _power = 120; |
| 104 | _areaOfEffect = true; |
| 105 | } |
| 106 | |
| 107 | Tile *t = _parent->getSave()->getTile(Position(_center.x/16, _center.y/16, _center.z/24)); |
| 108 | if (_areaOfEffect) |
| 109 | { |
| 110 | if (_power) |
| 111 | { |
| 112 | int frame = 0; |
| 113 | int counter = std::max(1, (_power/5) / 5); |
| 114 | for (int i = 0; i < _power/5; i++) |
| 115 | { |
| 116 | int X = RNG::generate(-_power/2,_power/2); |
| 117 | int Y = RNG::generate(-_power/2,_power/2); |
| 118 | Position p = _center; |
| 119 | p.x += X; p.y += Y; |
| 120 | Explosion *explosion = new Explosion(p, frame, true); |
| 121 | // add the explosion on the map |
| 122 | _parent->getMap()->getExplosions()->push_back(explosion); |
| 123 | if (i > 0 && i % counter == 0) |
| 124 | { |
| 125 | --frame; |
| 126 | } |
| 127 | } |
nothing calls this directly
no test coverage detected