Skip to content

Commit

Permalink
Unified damage types
Browse files Browse the repository at this point in the history
Remove most special cases for damage types.
  • Loading branch information
Yankes committed Aug 24, 2014
1 parent 0f60ee3 commit fff6451
Show file tree
Hide file tree
Showing 28 changed files with 547 additions and 295 deletions.
2 changes: 1 addition & 1 deletion src/Battlescape/ActionMenuState.cpp
Expand Up @@ -107,7 +107,7 @@ ActionMenuState::ActionMenuState(BattleAction *action, int x, int y) : _action(a
if (weapon->getTUMelee())
{
// stun rod
if (weapon->getBattleType() == BT_MELEE && weapon->getDamageType() == DT_STUN)
if (weapon->getBattleType() == BT_MELEE && weapon->getDamageType()->ResistType == DT_STUN)
{
addItem(BA_HIT, "STR_STUN", &id);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Battlescape/AlienBAIState.cpp
Expand Up @@ -451,8 +451,8 @@ void AlienBAIState::setupPatrol()
{
node = *i;
int d = _save->getTileEngine()->distanceSq(_unit->getPosition(), node->getPosition());
if (_unit->getPosition().z == node->getPosition().z
&& d < closest
if (_unit->getPosition().z == node->getPosition().z
&& d < closest
&& (!(node->getType() & Node::TYPE_SMALL) || _unit->getArmor()->getSize() == 1))
{
_fromNode = node;
Expand All @@ -471,7 +471,7 @@ void AlienBAIState::setupPatrol()
{
// after turn 20 or if the morale is low, everyone moves out the UFO and scout
// also anyone standing in fire should also probably move
if (_save->isCheating() || !_fromNode || _fromNode->getRank() == 0 ||
if (_save->isCheating() || !_fromNode || _fromNode->getRank() == 0 ||
(_save->getTile(_unit->getPosition()) && _save->getTile(_unit->getPosition())->getFire()))
{
scout = true;
Expand All @@ -488,7 +488,7 @@ void AlienBAIState::setupPatrol()
// can i shoot an object?
if (_fromNode->isTarget() &&
_unit->getMainHandWeapon() &&
_unit->getMainHandWeapon()->getAmmoItem()->getRules()->getDamageType() != DT_HE &&
_unit->getMainHandWeapon()->getAmmoItem()->getRules()->getDamageType()->isDirect() &&
_save->getModuleMap()[_fromNode->getPosition().x / 10][_fromNode->getPosition().y / 10].second > 0)
{
// scan this room for objects to destroy
Expand Down
8 changes: 4 additions & 4 deletions src/Battlescape/BattlescapeGame.cpp
Expand Up @@ -555,26 +555,26 @@ void BattlescapeGame::checkForCasualties(BattleItem *murderweapon, BattleUnit *m
if (hiddenExplosion)
{
// this is instant death from UFO powersources, without screaming sounds
statePushNext(new UnitDieBState(this, (*j), DT_HE, true));
statePushNext(new UnitDieBState(this, (*j), getRuleset()->getDamageType(DT_HE), true));
}
else
{
if (terrainExplosion)
{
// terrain explosion
statePushNext(new UnitDieBState(this, (*j), DT_HE, false));
statePushNext(new UnitDieBState(this, (*j), getRuleset()->getDamageType(DT_HE), false));
}
else
{
// no murderer, and no terrain explosion, must be fatal wounds
statePushNext(new UnitDieBState(this, (*j), DT_NONE, false)); // DT_NONE = STR_HAS_DIED_FROM_A_FATAL_WOUND
statePushNext(new UnitDieBState(this, (*j), getRuleset()->getDamageType(DT_NONE), false)); // DT_NONE = STR_HAS_DIED_FROM_A_FATAL_WOUND
}
}
}
}
else if ((*j)->getStunlevel() >= (*j)->getHealth() && (*j)->getStatus() != STATUS_DEAD && (*j)->getStatus() != STATUS_UNCONSCIOUS && (*j)->getStatus() != STATUS_COLLAPSING && (*j)->getStatus() != STATUS_TURNING)
{
statePushNext(new UnitDieBState(this, (*j), DT_STUN, true));
statePushNext(new UnitDieBState(this, (*j), getRuleset()->getDamageType(DT_NONE), true)); // no damage type used there
}
}
BattleUnit *bu = _save->getSelectedUnit();
Expand Down
6 changes: 4 additions & 2 deletions src/Battlescape/BattlescapeGenerator.cpp
Expand Up @@ -1807,15 +1807,17 @@ void BattlescapeGenerator::explodePowerSources()
pos.x = _save->getTiles()[i]->getPosition().x*16;
pos.y = _save->getTiles()[i]->getPosition().y*16;
pos.z = (_save->getTiles()[i]->getPosition().z*24) +12;
_save->getTileEngine()->explode(pos, 180+RNG::generate(0,70), DT_HE, 10);
_save->getTileEngine()->explode(pos, 180+RNG::generate(0,70), _game->getRuleset()->getDamageType(DT_HE), 10);
}
}
Tile *t = _save->getTileEngine()->checkForTerrainExplosions();
while (t)
{
int power = t->getExplosive();
t->setExplosive(0, true);
Position p = Position(t->getPosition().x * 16, t->getPosition().y * 16, t->getPosition().z * 24);
p += Position(8,8,0);
_save->getTileEngine()->explode(p, t->getExplosive(), DT_HE, t->getExplosive() / 10);
_save->getTileEngine()->explode(p, power, _game->getRuleset()->getDamageType(DT_HE), power / 10);
t = _save->getTileEngine()->checkForTerrainExplosions();
}
}
Expand Down
65 changes: 32 additions & 33 deletions src/Battlescape/ExplosionBState.cpp
Expand Up @@ -49,7 +49,7 @@ namespace OpenXcom
* @param tile Tile the explosion is on.
* @param lowerWeapon Whether the unit causing this explosion should now lower their weapon.
*/
ExplosionBState::ExplosionBState(BattlescapeGame *parent, Position center, BattleItem *item, BattleUnit *unit, Tile *tile, bool lowerWeapon) : BattleState(parent), _unit(unit), _center(center), _item(item), _tile(tile), _power(0), _areaOfEffect(false), _lowerWeapon(lowerWeapon), _pistolWhip(false), _hit(false)
ExplosionBState::ExplosionBState(BattlescapeGame *parent, Position center, BattleItem *item, BattleUnit *unit, Tile *tile, bool lowerWeapon) : BattleState(parent), _unit(unit), _center(center), _item(item), _damageType(), _tile(tile), _power(0), _radius(6), _areaOfEffect(false), _lowerWeapon(lowerWeapon), _pistolWhip(false), _hit(false)
{

}
Expand All @@ -72,12 +72,16 @@ void ExplosionBState::init()
if (_item)
{
_power = _item->getRules()->getPower();
_damageType = _item->getRules()->getDamageType();
_radius = _item->getRules()->getExplosionRadius();
// getCurrentAction() only works for player actions: aliens cannot melee attack with rifle butts.
_pistolWhip = (_item->getRules()->getBattleType() != BT_MELEE &&
_parent->getCurrentAction()->type == BA_HIT);
if (_pistolWhip)
{
_power = _item->getRules()->getMeleePower();
_damageType = _parent->getRuleset()->getDamageType(DT_MELEE);
_radius = 0;
}
// since melee aliens don't use a conventional weapon type, we use their strength instead.
if (_item->getRules()->isStrengthApplied())
Expand All @@ -92,16 +96,23 @@ void ExplosionBState::init()
else if (_tile)
{
_power = _tile->getExplosive();
_tile->setExplosive(0, true);
_damageType = _parent->getRuleset()->getDamageType(DT_HE);
_radius = _power /10;
_areaOfEffect = true;
}
else if (_unit && _unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH)
{
_power = _parent->getRuleset()->getItem(_unit->getArmor()->getCorpseGeoscape())->getPower();
RuleItem* corpse = _parent->getRuleset()->getItem(_unit->getArmor()->getCorpseGeoscape());
_power = corpse->getPower();
_damageType = corpse->getDamageType();
_radius = corpse->getExplosionRadius();
_areaOfEffect = true;
}
else
{
_power = 120;
_damageType = _parent->getRuleset()->getDamageType(DT_HE);
_areaOfEffect = true;
}

Expand Down Expand Up @@ -208,7 +219,7 @@ void ExplosionBState::explode()
{
bool terrainExplosion = false;
SavedBattleGame *save = _parent->getSave();
// last minute adjustment: determine if we actually
// last minute adjustment: determine if we actually
if (_hit)
{
save->getBattleGame()->getCurrentAction()->type = BA_NONE;
Expand Down Expand Up @@ -241,46 +252,34 @@ void ExplosionBState::explode()
{
_unit = _item->getPreviousOwner();
}
}

if (_areaOfEffect)
{
save->getTileEngine()->explode(_center, _power, _item->getRules()->getDamageType(), _item->getRules()->getExplosionRadius(), _unit);
}
else
if (_areaOfEffect)
{
save->getTileEngine()->explode(_center, _power, _damageType, _radius, _unit);
}
else
{
BattleUnit *victim = save->getTileEngine()->hit(_center, _power, _damageType, _unit);
// check if this unit turns others into zombies
if (!_item->getRules()->getZombieUnit().empty()
&& victim
&& victim->getArmor()->getSize() == 1
&& victim->getSpawnUnit().empty()
&& victim->getOriginalFaction() != FACTION_HOSTILE)
{
ItemDamageType type = _item->getRules()->getDamageType();
if (_pistolWhip)
{
type = DT_STUN;
}
BattleUnit *victim = save->getTileEngine()->hit(_center, _power, type, _unit);
// check if this unit turns others into zombies
if (!_item->getRules()->getZombieUnit().empty()
&& victim
&& victim->getArmor()->getSize() == 1
&& victim->getSpawnUnit().empty()
&& victim->getOriginalFaction() != FACTION_HOSTILE)
{
// converts the victim to a zombie on death
victim->setSpecialAbility(SPECAB_RESPAWN);
victim->setSpawnUnit(_item->getRules()->getZombieUnit());
}
// converts the victim to a zombie on death
victim->setSpecialAbility(SPECAB_RESPAWN);
victim->setSpawnUnit(_item->getRules()->getZombieUnit());
}
}

if (_tile)
{
save->getTileEngine()->explode(_center, _power, DT_HE, _power/10);
terrainExplosion = true;
}
if (!_tile && !_item)
{
int radius = 6;
// explosion not caused by terrain or an item, must be by a unit (cyberdisc)
if (_unit && _unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH)
{
radius = _parent->getRuleset()->getItem(_unit->getArmor()->getCorpseGeoscape())->getExplosionRadius();
}
save->getTileEngine()->explode(_center, _power, DT_HE, radius);
terrainExplosion = true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Battlescape/ExplosionBState.h
Expand Up @@ -30,6 +30,7 @@ class BattlescapeGame;
class BattleUnit;
class BattleItem;
class Tile;
class RuleDamageType;

/**
* Explosion state not only handles explosions, but also bullet impacts!
Expand All @@ -41,8 +42,10 @@ class ExplosionBState : public BattleState
BattleUnit *_unit;
Position _center;
BattleItem *_item;
const RuleDamageType *_damageType;
Tile *_tile;
int _power;
int _radius;
bool _areaOfEffect, _lowerWeapon, _pistolWhip, _hit;
/// Calculates the effects of the explosion.
void explode();
Expand Down
4 changes: 2 additions & 2 deletions src/Battlescape/ProjectileFlyBState.cpp
Expand Up @@ -532,7 +532,7 @@ void ProjectileFlyBState::think()
_parent->statePushFront(new ExplosionBState(_parent, _parent->getMap()->getProjectile()->getPosition(offset), _ammo, _action.actor, 0, (_action.type != BA_AUTOSHOT || _action.autoShotCounter == _action.weapon->getRules()->getAutoShots() || !_action.weapon->getAmmoItem())));

// special shotgun behaviour: trace extra projectile paths, and add bullet hits at their termination points.
if (_ammo && _ammo->getRules()->getShotgunPellets() != 0)
if (_ammo && _ammo->getRules()->getShotgunPellets() != 0 && _ammo->getRules()->getDamageType()->isDirect())
{
int i = 1;
int bulletSprite = _ammo->getRules()->getBulletSprite();
Expand All @@ -550,7 +550,7 @@ void ProjectileFlyBState::think()
{
// as above: skip the shot to the end of it's path
proj->skipTrajectory();
// insert an explosion and hit
// insert an explosion and hit
if (_projectileImpact != V_OUTOFBOUNDS)
{
Explosion *explosion = new Explosion(proj->getPosition(1), _ammo->getRules()->getHitAnimation(), false, false);
Expand Down

0 comments on commit fff6451

Please sign in to comment.