Skip to content

Commit 918c4e0

Browse files
committed
Merge branch 'master' of github.com:SupSuper/OpenXcom
Conflicts: src/Battlescape/BattlescapeState.cpp
2 parents fa03f2c + 29d2497 commit 918c4e0

21 files changed

Lines changed: 572 additions & 191 deletions

‎src/Battlescape/BattlescapeGenerator.cpp‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,18 @@ void BattlescapeGenerator::run()
211211
}*/
212212
// test data
213213
addItem(_game->getRuleset()->getItem("STR_RIFLE"));
214-
addItem(_game->getRuleset()->getItem("STR_HEAVY_CANNON"));
215-
addItem(_game->getRuleset()->getItem("STR_ROCKET_LAUNCHER"));
216214
addItem(_game->getRuleset()->getItem("STR_RIFLE_CLIP"));
215+
addItem(_game->getRuleset()->getItem("STR_HEAVY_CANNON"));
217216
addItem(_game->getRuleset()->getItem("STR_HC_HE_AMMO"));
217+
addItem(_game->getRuleset()->getItem("STR_ROCKET_LAUNCHER"));
218218
addItem(_game->getRuleset()->getItem("STR_SMALL_ROCKET"));
219219
addItem(_game->getRuleset()->getItem("STR_GRENADE"));
220220
addItem(_game->getRuleset()->getItem("STR_SMOKE_GRENADE"));
221221
addItem(_game->getRuleset()->getItem("STR_PISTOL"));
222222
addItem(_game->getRuleset()->getItem("STR_PISTOL_CLIP"));
223+
addItem(_game->getRuleset()->getItem("STR_GRENADE"));
224+
addItem(_game->getRuleset()->getItem("STR_GRENADE"));
225+
addItem(_game->getRuleset()->getItem("STR_GRENADE"));
223226
}
224227

225228
if (_missionType == MISS_UFORECOVERY)
@@ -238,6 +241,19 @@ void BattlescapeGenerator::run()
238241
addAlien(_game->getRuleset()->getAlien("SECTOID_SOLDIER"), _game->getRuleset()->getArmor("SECTOID_ARMOR0"), SCOUT);
239242
addAlien(_game->getRuleset()->getAlien("SECTOID_SOLDIER"), _game->getRuleset()->getArmor("SECTOID_ARMOR0"), SCOUT);
240243
addAlien(_game->getRuleset()->getAlien("SECTOID_SOLDIER"), _game->getRuleset()->getArmor("SECTOID_ARMOR0"), SCOUT);
244+
245+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
246+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
247+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
248+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
249+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
250+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
251+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
252+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
253+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
254+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
255+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL"));
256+
addItem(_game->getRuleset()->getItem("STR_PLASMA_PISTOL_CLIP"));
241257

242258
// set shade (alien bases are a little darker, sites depend on worldshade)
243259
int worldshades[8] = { 0, 1, 2, 3, 5, 7, 9 , 15 };
@@ -611,7 +627,7 @@ int BattlescapeGenerator::loadMAP(MapBlock *mapblock, int xoff, int yoff, RuleTe
611627
_save->getTile(Position(x, y, z))->setMapData(0,part);
612628
}
613629
}
614-
_save->getTile(Position(x, y, z))->setDiscovered(discovered);
630+
_save->getTile(Position(x, y, z))->setDiscovered(discovered, 2);
615631

616632
x++;
617633

‎src/Battlescape/BattlescapeState.cpp‎

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "TerrainModifier.h"
3131
#include "ActionMenuState.h"
3232
#include "UnitInfoState.h"
33+
#include "UnitFallBState.h"
3334
#include "InventoryState.h"
3435
#include "../Engine/Game.h"
3536
#include "../Engine/Music.h"
@@ -396,11 +397,11 @@ void BattlescapeState::mapClick(Action *action)
396397
_action.target = pos;
397398
_map->setCursorType(CT_NONE);
398399
_game->getCursor()->setVisible(false);
399-
_states.push_back(new ProjectileFlyBState(this));
400-
if (_action.type == BA_AUTOSHOT)
400+
_states.push_back(new ProjectileFlyBState(this, _action));
401+
if (_action.type == BA_AUTOSHOT) // TODO - this is not very good, an autoshot gets 3 reaction shots this way
401402
{
402-
_states.push_back(new ProjectileFlyBState(this));
403-
_states.push_back(new ProjectileFlyBState(this));
403+
_states.push_back(new ProjectileFlyBState(this, _action));
404+
_states.push_back(new ProjectileFlyBState(this, _action));
404405
}
405406
statePushFront(new UnitTurnBState(this));
406407
}
@@ -501,6 +502,11 @@ void BattlescapeState::btnKneelClick(Action *action)
501502
bu->kneel(!bu->isKneeled());
502503
_map->cacheUnits();
503504
updateSoldierInfo(bu);
505+
BattleAction action;
506+
if (_battleGame->getTerrainModifier()->checkReactionFire(bu, &action))
507+
{
508+
statePushBack(new ProjectileFlyBState(this, action));
509+
}
504510
}
505511
}
506512
}
@@ -594,7 +600,7 @@ void BattlescapeState::endTurn()
594600
p.x = _battleGame->getTiles()[i]->getPosition().x*16 + 8;
595601
p.y = _battleGame->getTiles()[i]->getPosition().y*16 + 8;
596602
p.z = _battleGame->getTiles()[i]->getPosition().z*24 + _battleGame->getTiles()[i]->getTerrainLevel();
597-
statePushNext(new ExplosionBState(this, p, (*it)));
603+
statePushNext(new ExplosionBState(this, p, (*it), (*it)->getPreviousOwner()));
598604
it = _battleGame->getTiles()[i]->getInventory()->erase(it);
599605
statePushBack(0);
600606
return;
@@ -617,7 +623,7 @@ void BattlescapeState::endTurn()
617623
p.x = (*i)->getPosition().x*16 + 8;
618624
p.y = (*i)->getPosition().y*16 + 8;
619625
p.z = (*i)->getPosition().z*24 + 18;
620-
statePushNext(new ExplosionBState(this, p, (*it)));
626+
statePushNext(new ExplosionBState(this, p, (*it), (*it)->getPreviousOwner()));
621627
it = _battleGame->getItems()->erase(it);
622628
statePushBack(0);
623629
return;
@@ -635,6 +641,8 @@ void BattlescapeState::endTurn()
635641
}
636642

637643
_battleGame->endTurn();
644+
checkForCasualties(0, 0);
645+
638646
updateSoldierInfo(_battleGame->getSelectedUnit());
639647
if (_battleGame->getSelectedUnit())
640648
{
@@ -643,6 +651,58 @@ void BattlescapeState::endTurn()
643651
_game->pushState(new NextTurnState(_game, _battleGame));
644652
}
645653

654+
655+
/**
656+
* Checks for casualties and adjusts morale accordingly.
657+
* @param murderweapon
658+
* @param murderer
659+
*/
660+
void BattlescapeState::checkForCasualties(BattleItem *murderweapon, BattleUnit *murderer)
661+
{
662+
// TODO : include rank bonusses and penalties !!
663+
for (std::vector<BattleUnit*>::iterator j = _battleGame->getUnits()->begin(); j != _battleGame->getUnits()->end(); ++j)
664+
{
665+
if ((*j)->getHealth() == 0 && (*j)->getStatus() != STATUS_DEAD)
666+
{
667+
BattleUnit *victim = (*j);
668+
669+
if (murderer)
670+
{
671+
// if there is a known murderer, he will get a morale bonus if he is of a different faction (what with neutral?)
672+
if (victim->getFaction() == FACTION_PLAYER && murderer->getFaction() == FACTION_HOSTILE ||
673+
victim->getFaction() == FACTION_HOSTILE && murderer->getFaction() == FACTION_PLAYER)
674+
{
675+
murderer->moraleChange(+20);
676+
}
677+
// murderer will get a penalty with friendly fire
678+
if (victim->getFaction() == murderer->getFaction())
679+
{
680+
murderer->moraleChange(-20);
681+
}
682+
}
683+
684+
for (std::vector<BattleUnit*>::iterator i = _battleGame->getUnits()->begin(); i != _battleGame->getUnits()->end(); ++i)
685+
{
686+
// the losing squad all get a morale loss
687+
if ((*i)->getFaction() == victim->getFaction())
688+
{
689+
(*i)->moraleChange(-(22 - ((*i)->getUnit()->getBravery() / 10)*2));
690+
}
691+
// the winning squad all get a morale increase
692+
if ((*i)->getFaction() != victim->getFaction())
693+
{
694+
(*i)->moraleChange(+10);
695+
}
696+
}
697+
698+
if (murderweapon)
699+
statePushNext(new UnitFallBState(this, (*j), murderweapon->getRules()->getDamageType() == DT_HE)); // explosions insta-kill a unit
700+
else
701+
statePushNext(new UnitFallBState(this, (*j), false));
702+
}
703+
}
704+
}
705+
646706
/**
647707
* Abort game.
648708
* @param action Pointer to an action.
@@ -798,6 +858,8 @@ void BattlescapeState::updateSoldierInfo(BattleUnit *battleUnit)
798858
_barMorale->clear();
799859
_btnLeftHandItem->clear();
800860
_btnRightHandItem->clear();
861+
_numAmmoLeft->clear();
862+
_numAmmoRight->clear();
801863
return;
802864
}
803865

@@ -1089,7 +1151,7 @@ void BattlescapeState::popState()
10891151
{
10901152
if (_action.targeting && _battleGame->getSelectedUnit() && !actionFailed)
10911153
{
1092-
_battleGame->getSelectedUnit()->spendTimeUnits(_action.TU, _battleGame->getDebugMode());
1154+
_action.actor->spendTimeUnits(_action.TU, _battleGame->getDebugMode());
10931155
}
10941156
if (_action.type == BA_THROW && !actionFailed)
10951157
{

‎src/Battlescape/BattlescapeState.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class BattlescapeState : public State
176176
void handle(Action *action);
177177
/// Displays a popup window.
178178
void popup(State *state);
179+
/// Checks for casualties in battle.
180+
void checkForCasualties(BattleItem *murderweapon, BattleUnit *murderer);
179181
};
180182

181183
}

‎src/Battlescape/ExplosionBState.cpp‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OpenXcom
4040
/**
4141
* Sets up an ExplosionBState.
4242
*/
43-
ExplosionBState::ExplosionBState(BattlescapeState *parent, Position center, BattleItem *item) : BattleState(parent), _center(center), _item(item)
43+
ExplosionBState::ExplosionBState(BattlescapeState *parent, Position center, BattleItem *item, BattleUnit *unit) : BattleState(parent), _center(center), _item(item), _unit(unit)
4444
{
4545

4646
}
@@ -61,7 +61,6 @@ ExplosionBState::~ExplosionBState()
6161
*/
6262
void ExplosionBState::init()
6363
{
64-
_unit = _parent->getGame()->getSavedGame()->getBattleGame()->getSelectedUnit();
6564
if (_item == 0 || _item->getRules()->getHitAnimation() == 0)
6665
{
6766
_parent->setStateInterval(DEFAULT_ANIM_SPEED);
@@ -106,21 +105,19 @@ void ExplosionBState::think()
106105
{
107106
SavedBattleGame *save = _parent->getGame()->getSavedGame()->getBattleGame();
108107
// after the animation is done, the real explosion takes place
109-
save->getTerrainModifier()->explode(_center, _item->getRules()->getPower(), _item->getRules()->getDamageType(), 100, save->getSelectedUnit());
108+
save->getTerrainModifier()->explode(_center, _item->getRules()->getPower(), _item->getRules()->getDamageType(), 100, _unit);
110109

111110
// now check for new casualties
112-
for (std::vector<BattleUnit*>::iterator j = save->getUnits()->begin(); j != save->getUnits()->end(); ++j)
113-
{
114-
if ((*j)->getHealth() == 0 && (*j)->getStatus() != STATUS_DEAD)
115-
{
116-
_parent->statePushNext(new UnitFallBState(_parent, (*j), _item->getRules()->getDamageType() == DT_HE));
117-
}
118-
}
111+
_parent->checkForCasualties(_item, _unit);
119112

120-
// if this explosion was caused by a unit shooting, now it's the time to put the gun down
113+
// if this explosion was caused by a unit shooting, now it's the time to put the gun down and put the camera back on the shooter
121114
if (_unit && !_unit->isOut())
122115
{
123116
_unit->aim(false);
117+
if (_parent->getMap()->didCameraFollow())
118+
{
119+
_parent->getMap()->centerOnPosition(_unit->getPosition());
120+
}
124121
}
125122
_parent->getMap()->cacheUnits();
126123
_parent->popState();

‎src/Battlescape/ExplosionBState.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ExplosionBState : public BattleState
3939
BattleItem *_item;
4040
public:
4141
/// Creates a new ExplosionBState class
42-
ExplosionBState(BattlescapeState *parent, Position center, BattleItem *item);
42+
ExplosionBState(BattlescapeState *parent, Position center, BattleItem *item, BattleUnit *unit);
4343
/// Cleans up the ExplosionBState.
4444
~ExplosionBState();
4545
/// Initializes the state.

0 commit comments

Comments
 (0)