Skip to content

Commit 60faecc

Browse files
committed
Fixed a crash when MCing XCOM units
1 parent 14993be commit 60faecc

2 files changed

Lines changed: 74 additions & 3 deletions

File tree

src/Battlescape/BattlescapeGame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ void BattlescapeGame::checkForCasualties(BattleItem *murderweapon, BattleUnit *m
653653

654654
if ((*j)->getHealth() == 0 && (*j)->getStatus() != STATUS_DEAD && (*j)->getStatus() != STATUS_COLLAPSING)
655655
{
656-
// Assume that, in absence of a murderer and an explosion, fire killed victim.
656+
// Assume that, in absence of a murderer and an explosion, the laster unit to hit the victim is the murderer.
657+
// Possible causes of death: bleed out, fire.
657658
// Assume that the fire that killed victim was started by the unit who hit victim with DT_IN.
658659
if (!murderer && !terrainExplosion)
659660
{

src/Battlescape/PsiAttackBState.cpp

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,76 @@ void PsiAttackBState::psiAttack()
163163
Game *game = _parent->getSave()->getBattleState()->getGame();
164164
_action.actor->addPsiSkillExp();
165165
_action.actor->addPsiSkillExp();
166+
/// Decide target race and rank.
167+
std::string killStatRank, killStatRace;
168+
// Soldiers
169+
if (_target->getGeoscapeSoldier() && _target->getOriginalFaction() == FACTION_PLAYER)
170+
{
171+
if (_target->getUnitRules() != NULL && _target->getUnitRules()->getRank() != "")
172+
{
173+
killStatRank = _target->getGeoscapeSoldier()->getRankString();
174+
}
175+
else
176+
{
177+
killStatRank = "STR_LIVE_SOLDIER";
178+
}
179+
if (_target->getUnitRules() != NULL && _target->getUnitRules()->getRace() != "")
180+
{
181+
killStatRace = _target->getUnitRules()->getRace();
182+
}
183+
else
184+
{
185+
killStatRace = "STR_HUMAN";
186+
}
187+
}
188+
// Aliens
189+
else if (_target->getOriginalFaction() == FACTION_HOSTILE)
190+
{
191+
if (_target->getUnitRules() != NULL && _target->getUnitRules()->getRank() != "")
192+
{
193+
killStatRank = _target->getUnitRules()->getRank();
194+
}
195+
else
196+
{
197+
killStatRank = "STR_UNKNOWN";
198+
}
199+
if (_target->getUnitRules() != NULL && _target->getUnitRules()->getRace() != "")
200+
{
201+
killStatRace = _target->getUnitRules()->getRace();
202+
}
203+
else
204+
{
205+
killStatRace = "STR_LIVE_SOLDIER";
206+
}
207+
}
208+
// Civilians
209+
else if (_target->getOriginalFaction() == FACTION_NEUTRAL)
210+
{
211+
if (_target->getUnitRules() != NULL && _target->getUnitRules()->getRank() != "")
212+
{
213+
killStatRank = _target->getUnitRules()->getRank();
214+
}
215+
else
216+
{
217+
killStatRank = "STR_CIVILIAN";
218+
}
219+
if (_target->getUnitRules() != NULL && (_target->getUnitRules()->getRace() != "" || _target->getUnitRules()->getRace() != "STR_CIVILIAN"))
220+
{
221+
killStatRace = _target->getUnitRules()->getRace();
222+
}
223+
else
224+
{
225+
killStatRace = "STR_HUMAN";
226+
}
227+
}
228+
// Error
229+
else
230+
{
231+
killStatRank = "STR_UNKNOWN";
232+
killStatRace = "STR_UNKNOWN";
233+
}
234+
235+
166236
if (_action.type == BA_PANIC)
167237
{
168238
int moraleLoss = (110-_target->getBaseStats()->bravery);
@@ -171,7 +241,7 @@ void PsiAttackBState::psiAttack()
171241
// Award Panic battle unit kill
172242
if (!_unit->getStatistics()->duplicateEntry(STATUS_PANICKING, _target->getId()))
173243
{
174-
_unit->getStatistics()->kills.push_back(new BattleUnitKills(_target->getRankString(), _target->getUnitRules()->getRace(), _action.weapon->getRules()->getName(), _action.weapon->getRules()->getName(), _target->getFaction(), STATUS_PANICKING, _parent->getSave()->getGeoscapeSave()->getMissionStatistics()->size(), turn, SIDE_FRONT, BODYPART_HEAD, _target->getId()));
244+
_unit->getStatistics()->kills.push_back(new BattleUnitKills(killStatRank, killStatRace, _action.weapon->getRules()->getName(), _action.weapon->getRules()->getName(), _target->getFaction(), STATUS_PANICKING, _parent->getSave()->getGeoscapeSave()->getMissionStatistics()->size(), turn, SIDE_FRONT, BODYPART_HEAD, _target->getId()));
175245
_target->setMurdererId(_unit->getId());
176246
}
177247
if (_parent->getSave()->getSide() == FACTION_PLAYER)
@@ -184,7 +254,7 @@ void PsiAttackBState::psiAttack()
184254
// Award MC battle unit kill
185255
if (!_unit->getStatistics()->duplicateEntry(STATUS_TURNING, _target->getId()))
186256
{
187-
_unit->getStatistics()->kills.push_back(new BattleUnitKills(_target->getRankString(), _target->getUnitRules()->getRace(), _action.weapon->getRules()->getName(), _action.weapon->getRules()->getName(), _target->getFaction(), STATUS_TURNING, _parent->getSave()->getGeoscapeSave()->getMissionStatistics()->size(), turn, SIDE_FRONT, BODYPART_HEAD, _target->getId()));
257+
_unit->getStatistics()->kills.push_back(new BattleUnitKills(killStatRank, killStatRace, _action.weapon->getRules()->getName(), _action.weapon->getRules()->getName(), _target->getFaction(), STATUS_TURNING, _parent->getSave()->getGeoscapeSave()->getMissionStatistics()->size(), turn, SIDE_FRONT, BODYPART_HEAD, _target->getId()));
188258
_target->setMurdererId(_unit->getId());
189259
}
190260
_target->convertToFaction(_unit->getFaction());

0 commit comments

Comments
 (0)