Skip to content

Commit ecd7b62

Browse files
committed
small fix for zombies
1 parent fd46c58 commit ecd7b62

6 files changed

Lines changed: 37 additions & 18 deletions

File tree

‎src/Battlescape/BattlescapeGame.cpp‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,11 +1525,6 @@ BattleUnit *BattlescapeGame::convertUnit(BattleUnit *unit, const std::string &ne
15251525

15261526
unit->instaKill();
15271527

1528-
if (Options::battleNotifyDeath && unit->getFaction() == FACTION_PLAYER && unit->getOriginalFaction() == FACTION_PLAYER)
1529-
{
1530-
_parentState->getGame()->pushState(new InfoboxState(_parentState->getGame()->getLanguage()->getString("STR_HAS_BEEN_KILLED", unit->getGender()).arg(unit->getName(_parentState->getGame()->getLanguage()))));
1531-
}
1532-
15331528
for (std::vector<BattleItem*>::iterator i = unit->getInventory()->begin(); i != unit->getInventory()->end(); ++i)
15341529
{
15351530
dropItem(unit->getPosition(), (*i));
@@ -1980,17 +1975,20 @@ void BattlescapeGame::tallyUnits(int &liveAliens, int &liveSoldiers)
19801975
}
19811976
}
19821977

1983-
void BattlescapeGame::convertInfected()
1978+
bool BattlescapeGame::convertInfected()
19841979
{
1980+
bool retVal = false;
19851981
for (std::vector<BattleUnit*>::iterator j = _save->getUnits()->begin(); j != _save->getUnits()->end(); ++j)
19861982
{
19871983
if ((*j)->getHealth() > 0 && (*j)->getRespawn())
19881984
{
1985+
retVal = true;
19891986
(*j)->setRespawn(false);
19901987
convertUnit((*j), (*j)->getSpawnUnit());
19911988
j = _save->getUnits()->begin();
19921989
}
19931990
}
1991+
return retVal;
19941992
}
19951993
/**
19961994
* Sets the kneel reservation setting.

‎src/Battlescape/BattlescapeGame.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class BattlescapeGame
180180
BattleActionType getReservedAction();
181181
/// Tallies the living units, converting them if necessary.
182182
void tallyUnits(int &liveAliens, int &liveSoldiers);
183-
void convertInfected();
183+
bool convertInfected();
184184
/// Sets the kneel reservation setting.
185185
void setKneelReserved(bool reserved);
186186
/// Checks the kneel reservation setting.

‎src/Battlescape/MeleeAttackBState.cpp‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
#include "TileEngine.h"
2424
#include "Pathfinding.h"
2525
#include "Map.h"
26+
#include "InfoboxState.h"
2627
#include "Camera.h"
2728
#include "AlienBAIState.h"
2829
#include "../Savegame/Tile.h"
2930
#include "../Engine/RNG.h"
31+
#include "../Engine/Game.h"
32+
#include "../Engine/Language.h"
3033
#include "../Savegame/SavedBattleGame.h"
3134
#include "../Savegame/BattleUnit.h"
3235
#include "../Savegame/BattleItem.h"
@@ -41,7 +44,7 @@ namespace OpenXcom
4144
/**
4245
* Sets up a MeleeAttackBState.
4346
*/
44-
MeleeAttackBState::MeleeAttackBState(BattlescapeGame *parent, BattleAction action) : BattleState(parent, action), _unit(0), _target(0), _weapon(0), _ammo(0), _initialized(false)
47+
MeleeAttackBState::MeleeAttackBState(BattlescapeGame *parent, BattleAction action) : BattleState(parent, action), _unit(0), _target(0), _weapon(0), _ammo(0), _initialized(false), _deathMessage(false)
4548
{
4649
}
4750

@@ -128,6 +131,13 @@ void MeleeAttackBState::init()
128131
*/
129132
void MeleeAttackBState::think()
130133
{
134+
if (_deathMessage)
135+
{
136+
Game *game = _parent->getSave()->getBattleState()->getGame();
137+
game->pushState(new InfoboxState(game->getLanguage()->getString("STR_HAS_BEEN_KILLED", _target->getGender()).arg(_target->getName(game->getLanguage()))));
138+
_parent->popState();
139+
return;
140+
}
131141
_parent->getSave()->getBattleState()->clearMouseScrollingState();
132142

133143
// if the unit burns floortiles, burn floortiles
@@ -140,7 +150,6 @@ void MeleeAttackBState::think()
140150
// this is because unlike regular bullet hits or explosions, melee attacks can MISS.
141151
// we also do it at this point instead of in performMeleeAttack because we want the scream to come AFTER the hit sound
142152
resolveHit();
143-
144153
// aliens
145154
if (_unit->getFaction() != FACTION_PLAYER &&
146155
// with enough TU for a second attack (*2 because they'll get charged for the initial attack when this state pops.)
@@ -172,8 +181,15 @@ void MeleeAttackBState::think()
172181
{
173182
_parent->setupCursor();
174183
}
175-
_parent->convertInfected();
176-
_parent->popState();
184+
if (_parent->convertInfected() && Options::battleNotifyDeath && _target && _target->getFaction() == FACTION_PLAYER)
185+
{
186+
_deathMessage = true;
187+
_parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED);
188+
}
189+
else
190+
{
191+
_parent->popState();
192+
}
177193
}
178194
}
179195

‎src/Battlescape/MeleeAttackBState.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MeleeAttackBState : public BattleState
3939
BattleUnit *_unit, *_target;
4040
BattleItem *_weapon, *_ammo;
4141
Position _voxel;
42-
bool _initialized;
42+
bool _initialized, _deathMessage;
4343
public:
4444
/// Creates a new MeleeAttackBState class
4545
MeleeAttackBState(BattlescapeGame *parent, BattleAction action);

‎src/Battlescape/UnitDieBState.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace OpenXcom
5050
* @param damageType Type of damage that caused the death.
5151
* @param noSound Whether to disable the death sound.
5252
*/
53-
UnitDieBState::UnitDieBState(BattlescapeGame *parent, BattleUnit *unit, ItemDamageType damageType, bool noSound) : BattleState(parent), _unit(unit), _damageType(damageType), _noSound(noSound), _extraFrame(false)
53+
UnitDieBState::UnitDieBState(BattlescapeGame *parent, BattleUnit *unit, ItemDamageType damageType, bool noSound) : BattleState(parent), _unit(unit), _damageType(damageType), _noSound(noSound), _extraFrame(0)
5454
{
5555
// don't show the "fall to death" animation when a unit is blasted with explosives or he is already unconscious
5656
if (_damageType == DT_HE || _unit->getStatus() == STATUS_UNCONSCIOUS)
@@ -145,19 +145,19 @@ void UnitDieBState::think()
145145
}
146146
}
147147
}
148-
if (_extraFrame)
148+
if (_extraFrame == 2)
149149
{
150150
_parent->getMap()->setUnitDying(false);
151151
_parent->getTileEngine()->calculateUnitLighting();
152152
_parent->popState();
153-
if (_unit->getOriginalFaction() == FACTION_PLAYER && _unit->getSpawnUnit().empty())
153+
if (_unit->getOriginalFaction() == FACTION_PLAYER)
154154
{
155155
Game *game = _parent->getSave()->getBattleState()->getGame();
156156
if (_unit->getStatus() == STATUS_DEAD)
157157
{
158158
if (_unit->getArmor()->getSize() == 1)
159159
{
160-
if (_damageType == DT_NONE)
160+
if (_damageType == DT_NONE && _unit->getSpawnUnit().empty())
161161
{
162162
game->pushState(new InfoboxOKState(game->getLanguage()->getString("STR_HAS_DIED_FROM_A_FATAL_WOUND", _unit->getGender()).arg(_unit->getName(game->getLanguage()))));
163163
}
@@ -187,9 +187,13 @@ void UnitDieBState::think()
187187
}
188188
}
189189
}
190+
else if (_extraFrame == 1)
191+
{
192+
_extraFrame++;
193+
}
190194
else if (_unit->isOut())
191195
{
192-
_extraFrame = true;
196+
_extraFrame = 1;
193197
if (!_noSound && _damageType == DT_HE && _unit->getStatus() != STATUS_UNCONSCIOUS)
194198
{
195199
playDeathSound();

‎src/Battlescape/UnitDieBState.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class UnitDieBState : public BattleState
3737
private:
3838
BattleUnit *_unit;
3939
ItemDamageType _damageType;
40-
bool _noSound, _extraFrame;
40+
bool _noSound;
41+
int _extraFrame;
4142
public:
4243
/// Creates a new UnitDieBState class
4344
UnitDieBState(BattlescapeGame *parent, BattleUnit *unit, ItemDamageType damageType, bool noSound);

0 commit comments

Comments
 (0)