Skip to content

Commit 69f674b

Browse files
committed
- Fixed support for soldier armor.
- Added death sounds to ruleset.
1 parent 518f1ac commit 69f674b

9 files changed

Lines changed: 55 additions & 41 deletions

File tree

src/Basescape/CraftArmorState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "../Savegame/Soldier.h"
3232
#include "../Savegame/Craft.h"
3333
#include "../Ruleset/RuleCraft.h"
34+
#include "../Ruleset/Armor.h"
3435
#include "SoldierArmorState.h"
3536

3637
namespace OpenXcom
@@ -96,7 +97,7 @@ CraftArmorState::CraftArmorState(Game *game, Base *base, unsigned int craft) : S
9697
Craft *c = _base->getCrafts()->at(_craft);
9798
for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i)
9899
{
99-
_lstSoldiers->addRow(3, (*i)->getName().c_str(), (*i)->getCraftString(_game->getLanguage()).c_str(), _game->getLanguage()->getString("STR_NONE_UC").c_str());
100+
_lstSoldiers->addRow(3, (*i)->getName().c_str(), (*i)->getCraftString(_game->getLanguage()).c_str(), _game->getLanguage()->getString((*i)->getArmor()->getType()).c_str());
100101

101102
Uint8 color;
102103
if ((*i)->getCraft() == c)

src/Basescape/SoldierInfoState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "../Ruleset/RuleCraft.h"
3535
#include "../Savegame/Soldier.h"
3636
#include "../Engine/SurfaceSet.h"
37+
#include "../Ruleset/Armor.h"
3738
#include "SoldierArmorState.h"
3839

3940
namespace OpenXcom
@@ -342,7 +343,7 @@ void SoldierInfoState::init()
342343
_barStrength->setValue(current->strength);
343344
_barStrength->setValue2(initial->strength);
344345

345-
_txtArmor->setText(_game->getLanguage()->getString("STR_NONE_UC"));
346+
_txtArmor->setText(_game->getLanguage()->getString(s->getArmor()->getType()));
346347

347348
std::wstringstream ss9;
348349
ss9 << _game->getLanguage()->getString("STR_RANK_") << L'\x01' << _game->getLanguage()->getString(s->getRankString());

src/Battlescape/UnitDieBState.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,7 @@ void UnitDieBState::init()
8787
}
8888
else
8989
{
90-
// todo get death sound from Unit
91-
if (_unit->getArmor()->getSize() > 1)
92-
{
93-
// HWP destroy sound
94-
_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(23)->play();
95-
}
96-
else
97-
{
98-
_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(10)->play();
99-
}
90+
_parent->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_unit->getDeathSound())->play();
10091
}
10192
}
10293

src/Ruleset/Ruleset.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "yaml.h"
2222
#include "../Engine/Options.h"
2323
#include "../Engine/Exception.h"
24+
#include "../Engine/CrossPlatform.h"
2425
#include "SoldierNamePool.h"
2526
#include "RuleCountry.h"
2627
#include "RuleRegion.h"
@@ -50,6 +51,16 @@ namespace OpenXcom
5051
Ruleset::Ruleset() : _names(), _countries(), _regions(), _facilities(), _crafts(), _craftWeapons(), _items(), _ufos(),
5152
_terrains(), _mapDataSets(), _soldiers(), _units(), _invs(), _costSoldier(0), _costEngineer(0), _costScientist(0), _timePersonnel(0)
5253
{
54+
// Add soldier names
55+
std::vector<std::string> names = CrossPlatform::getFolderContents(Options::getDataFolder() + "SoldierName/", "nam");
56+
57+
for (std::vector<std::string>::iterator i = names.begin(); i != names.end(); ++i)
58+
{
59+
std::string file = (*i).substr(0, (*i).length()-4);
60+
SoldierNamePool *pool = new SoldierNamePool();
61+
pool->load(file);
62+
_names.push_back(pool);
63+
}
5364
}
5465

5566
/**

src/Ruleset/XcomRuleset.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
20692069
sectoidSoldier->setStats(s1);
20702070
sectoidSoldier->setVoxelParameters(16, 12, 2);
20712071
sectoidSoldier->setValue(10);
2072+
sectoidSoldier->setDeathSound(10);
20722073
sectoidSoldier->setAIParameters(3, 2);
20732074

20742075
Unit *sectoidEngineer = new Unit("SECTOID_ENGINEER", "STR_SECTOID", "STR_LIVE_ENGINEER");
@@ -2087,6 +2088,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
20872088
sectoidEngineer->setStats(s1);
20882089
sectoidEngineer->setVoxelParameters(16, 12, 2);
20892090
sectoidEngineer->setValue(16);
2091+
sectoidEngineer->setDeathSound(10);
20902092
sectoidEngineer->setAIParameters(6, 2);
20912093

20922094
Unit *sectoidNavigator = new Unit("SECTOID_NAVIGATOR", "STR_SECTOID", "STR_LIVE_NAVIGATOR");
@@ -2105,6 +2107,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
21052107
sectoidNavigator->setStats(s1);
21062108
sectoidNavigator->setVoxelParameters(16, 12, 2);
21072109
sectoidNavigator->setValue(12);
2110+
sectoidNavigator->setDeathSound(10);
21082111
sectoidNavigator->setAIParameters(4, 2);
21092112

21102113
Unit *cyberdisc = new Unit("CYBERDISC", "STR_CYBERDISC", "");
@@ -2123,6 +2126,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
21232126
cyberdisc->setStats(s1);
21242127
cyberdisc->setVoxelParameters(15, 15, 4);
21252128
cyberdisc->setValue(20);
2129+
cyberdisc->setDeathSound(23);
21262130
cyberdisc->setAIParameters(5, 1);
21272131
cyberdisc->setSpecialAbility(SPECAB_EXPLODEONDEATH);
21282132

@@ -2142,6 +2146,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
21422146
floaterSoldier->setStats(s1);
21432147
floaterSoldier->setVoxelParameters(21, 16, 3);
21442148
floaterSoldier->setValue(12);
2149+
floaterSoldier->setDeathSound(10);
21452150
floaterSoldier->setAIParameters(4, 2);
21462151

21472152
Unit *tankCannon = new Unit("TANK_CANNON", "STR_TANK_CANNON", "");
@@ -2160,6 +2165,7 @@ XcomRuleset::XcomRuleset() : Ruleset()
21602165
tankCannon->setStats(s1);
21612166
tankCannon->setVoxelParameters(15, 15, 4);
21622167
tankCannon->setValue(20);
2168+
tankCannon->setDeathSound(23);
21632169

21642170
_units.insert(std::pair<std::string, Unit*>("SECTOID_SOLDIER", sectoidSoldier));
21652171
_units.insert(std::pair<std::string, Unit*>("SECTOID_ENGINEER", sectoidEngineer));

src/Savegame/BattleUnit.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,15 @@ BattleUnit::BattleUnit(Soldier *soldier, UnitFaction faction) : _faction(faction
4848
_id = soldier->getId();
4949
_type = "SOLDIER";
5050
_rank = soldier->getRankString();
51-
_stats.bravery = soldier->getCurrentStats()->bravery;
52-
_stats.firing = soldier->getCurrentStats()->firing;
53-
_stats.health = soldier->getCurrentStats()->health;
54-
_stats.melee = soldier->getCurrentStats()->melee;
55-
_stats.psiSkill = soldier->getCurrentStats()->psiSkill;
56-
_stats.psiStrength = soldier->getCurrentStats()->psiStrength;
57-
_stats.reactions = soldier->getCurrentStats()->reactions;
58-
_stats.stamina = soldier->getCurrentStats()->stamina;
59-
_stats.strength = soldier->getCurrentStats()->strength;
60-
_stats.throwing = soldier->getCurrentStats()->throwing;
61-
_stats.tu = soldier->getCurrentStats()->tu;
51+
_stats = *soldier->getCurrentStats();
6252
_standHeight = soldier->getRules()->getStandHeight();
6353
_kneelHeight = soldier->getRules()->getKneelHeight();
6454
_loftemps = soldier->getRules()->getLoftemps();
6555
_deathSound = 0; // this one is hardcoded
6656
_intelligence = 2;
6757
_aggression = 1;
6858
_specab = SPECAB_NONE;
69-
_armor = soldier->getArmorData();
59+
_armor = soldier->getArmor();
7060
_gender = soldier->getGender();
7161

7262
int rankbonus = 0;
@@ -108,17 +98,7 @@ BattleUnit::BattleUnit(Unit *unit, UnitFaction faction, Armor *armor) : _faction
10898
_type = unit->getType();
10999
_rank = unit->getRank();
110100
_race = unit->getRace();
111-
_stats.bravery = unit->getStats()->bravery;
112-
_stats.firing = unit->getStats()->firing;
113-
_stats.health = unit->getStats()->health;
114-
_stats.melee = unit->getStats()->melee;
115-
_stats.psiSkill = unit->getStats()->psiSkill;
116-
_stats.psiStrength = unit->getStats()->psiStrength;
117-
_stats.reactions = unit->getStats()->reactions;
118-
_stats.stamina = unit->getStats()->stamina;
119-
_stats.strength = unit->getStats()->strength;
120-
_stats.throwing = unit->getStats()->throwing;
121-
_stats.tu = unit->getStats()->tu;
101+
_stats = *unit->getStats();
122102
_standHeight = unit->getStandHeight();
123103
_kneelHeight = unit->getKneelHeight();
124104
_loftemps = unit->getLoftemps();
@@ -1764,6 +1744,7 @@ int BattleUnit::getLoftemps() const
17641744
{
17651745
return _loftemps;
17661746
}
1747+
17671748
/**
17681749
* Get the unit's value. Used for score at debriefing.
17691750
* @return value score
@@ -1773,6 +1754,15 @@ int BattleUnit::getValue() const
17731754
return _value;
17741755
}
17751756

1757+
/**
1758+
* Get the unit's death sound.
1759+
* @return id.
1760+
*/
1761+
int BattleUnit::getDeathSound() const
1762+
{
1763+
return _deathSound;
1764+
}
1765+
17761766
/**
17771767
* Get whether the unit is affected by fatal wounds.
17781768
* Normally only soldiers are affected by fatal wounds.

src/Savegame/BattleUnit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class BattleUnit
288288
int getLoftemps() const;
289289
/// Get the unit's value.
290290
int getValue() const;
291+
/// Get the unit's death sound.
292+
int getDeathSound() const;
291293
/// Get whether the unit is affected by fatal wounds.
292294
bool isWoundable() const;
293295
/// Get whether the unit is affected by fear.

src/Savegame/Soldier.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,24 @@ bool Soldier::isPromoted()
371371
return promoted;
372372
}
373373

374-
/// Gets a pointer to the armor data.
375-
Armor *Soldier::getArmorData() const
374+
/**
375+
* Returns the unit's current armor.
376+
* @return Pointer to armor data.
377+
*/
378+
Armor *const Soldier::getArmor() const
376379
{
377380
return _armor;
378381
}
379382

383+
/**
384+
* Changes the unit's current armor.
385+
* @param armor Pointer to armor data.
386+
*/
387+
void Soldier::setArmor(Armor *armor)
388+
{
389+
_armor = armor;
390+
}
391+
380392
/**
381393
* Returns the amount of time until the soldier is healed.
382394
* @return Number of days.

src/Savegame/Soldier.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class Soldier
9494
SoldierGender getGender() const;
9595
/// Gets the soldier's look.
9696
SoldierLook getLook() const;
97-
/// Gets a string version of the soldier's armor.
98-
std::string getArmor() const;
9997
/// Gets soldier rules.
10098
RuleSoldier *getRules() const;
10199
/// Gets the soldier's unique ID.
@@ -110,8 +108,10 @@ class Soldier
110108
UnitStats *getCurrentStats();
111109
/// Get whether the unit was recently promoted.
112110
bool isPromoted();
113-
/// Gets a pointer to the armor data.
114-
Armor *getArmorData() const;
111+
/// Gets the soldier armor.
112+
Armor *const getArmor() const;
113+
/// Sets the soldier armor.
114+
void setArmor(Armor *armor);
115115
/// Gets the soldier's wound recovery time.
116116
int getWoundRecovery() const;
117117
/// Sets the soldier's wound recovery time.

0 commit comments

Comments
 (0)