Skip to content

Commit 7f4e28e

Browse files
committed
Things appear to be working for the most part
1 parent e2123b4 commit 7f4e28e

5 files changed

Lines changed: 43 additions & 42 deletions

File tree

bin/data/Ruleset/Xcom1Ruleset.rul

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9293,14 +9293,9 @@ extraSprites:
92939293
commendations:
92949294
- type: STR_MEDAL_MERIT_STAR_NAME
92959295
description: STR_MEDAL_MERIT_STAR_DESC
9296-
criteria:
9297-
total_kills: [1, 2, 3]
9298-
total_missions: [0, 1, 2]
9299-
bonus:
9300-
tu: [0, 1, 2]
9296+
total_kills: [1, 2, 3]
9297+
total_missions: [0, 1, 2]
93019298
- type: STR_MILITARY_CROSS_NAME
93029299
description: STR_MILITARY_CROSS_DESC
9303-
criteria:
9304-
total_missions: [1, 3, 5]
9305-
bonus:
9306-
tu: [1, 1, 1]
9300+
total_missions: [1, 3, 5]
9301+

src/Battlescape/DebriefingState.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ DebriefingState::DebriefingState(Game *game) : State(game), _region(0), _country
236236
{
237237
(*j)->getGeoscapeSoldier()->getDiary()->addSoldierDiaryEntry(_missionTime, _missionRegion, _missionCountry, _missionType, _missionUFO, (*j)->getGeoscapeSoldier()->getTempKills(), _missionSuccess, _missionScore, _missionRating, _missionRace, _missionDaylight, (*j)->getGeoscapeSoldier()->getWoundRecovery());
238238
(*j)->getGeoscapeSoldier()->clearTempKills();
239+
if ((*j)->getGeoscapeSoldier()->getDiary()->manageCommendations(_game->getRuleset()))
240+
{
241+
_soldiersCommended.push_back((*j)->getGeoscapeSoldier());
242+
}
239243
}
240244
}
241245

@@ -673,11 +677,6 @@ void DebriefingState::prepareDebriefing()
673677
if (soldier != 0)
674678
{
675679
recoverItems((*j)->getInventory(), base);
676-
677-
if (soldier->getDiary()->manageCommendations(_game->getRuleset()))
678-
{
679-
_soldiersCommended.push_back(soldier);
680-
}
681680
}
682681
else
683682
{ // non soldier player = tank

src/Ruleset/RuleCommendations.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace OpenXcom
2525
/**
2626
* Creates a blank set of extra sprite data.
2727
*/
28-
RuleCommendations::RuleCommendations(const std::string &type) : _type(type), _description(""), _criteria(), _bonus(), _listOrder(0)
28+
RuleCommendations::RuleCommendations(const std::string &type) : _type(type), _description(""), _total_kills(), _listOrder(0)
2929
{
3030
}
3131

@@ -44,8 +44,8 @@ void RuleCommendations::load(const YAML::Node &node, int listOrder)
4444
{
4545
_type = node["type"].as<std::string>(_type);
4646
_description = node["description"].as<std::string>(_description);
47-
_criteria = node["critera"].as<std::map<std::string, std::vector<int> > >(_criteria);
48-
_bonus = node["bonus"].as<std::map<std::string, std::vector<int> > >(_bonus);
47+
_total_kills = node["total_kills"].as<std::vector<int> >(_total_kills);
48+
_total_missions = node["total_missions"].as<std::vector<int> >(_total_missions);
4949
_listOrder = node["listOrder"].as<int>(_listOrder);
5050
if (!_listOrder)
5151
{
@@ -84,10 +84,14 @@ std::string RuleCommendations::getDescription() const
8484
* Get commendation award criteria
8585
* @return map<string, int> Commendation criteria
8686
*/
87-
std::map<std::string, std::vector<int> > RuleCommendations::getCriteria() const
87+
std::vector<int> RuleCommendations::getTotalKills() const
8888
{
89-
return _criteria;
89+
return _total_kills;
9090
}
9191

92+
std::vector<int> RuleCommendations::getTotalMissions() const
93+
{
94+
return _total_missions;
95+
}
9296

9397
}

src/Ruleset/RuleCommendations.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class RuleCommendations
3131
{
3232
private:
3333
std::string _type, _description;
34-
std::map<std::string, std::vector<int> > _criteria;
35-
std::map<std::string, std::vector<int> > _bonus;
34+
std::vector<int> _total_kills, _total_missions;
3635
int _listOrder;
3736
public:
3837
/// Creates a blank commendation ruleset.
@@ -47,8 +46,9 @@ class RuleCommendations
4746
std::string getName() const;
4847
/// Get commendation description
4948
std::string getDescription() const;
50-
/// Get commendation award criteria
51-
std::map<std::string, std::vector<int> > getCriteria() const;
49+
/// Get commendation award criteria for kills
50+
std::vector<int> getTotalKills() const;
51+
std::vector<int> getTotalMissions() const;
5252
};
5353

5454
}

src/Savegame/SoldierDiary.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,44 +316,47 @@ std::vector<SoldierCommendations*> *SoldierDiary::getSoldierCommendations()
316316
bool SoldierDiary::manageCommendations(Ruleset *rules)
317317
{
318318
std::vector<std::string> _commendationsList = rules->getCommendationList();
319-
bool awardedCommendation = true;
319+
bool awardedCommendation = false;
320320
int _decorationLevel = 0;
321-
std::string _criteriaType;
322-
int _criteriaThreshold;
321+
std::vector<int> _total_kills, _total_missions;
323322

324323
// Loop over all commendations
325324
for (std::vector<std::string>::const_iterator i = _commendationsList.begin(); i != _commendationsList.end(); ++i)
326325
{
326+
_total_kills.clear();
327+
_total_missions.clear();
328+
327329
// Each commendation has its own list of criteria
328-
std::map<std::string, std::vector<int> > _commendationCriteria = rules->getCommendation(*i)->getCriteria();
330+
if (!rules->getCommendation(*i)->getTotalKills().empty())
331+
_total_kills = rules->getCommendation(*i)->getTotalKills();
332+
if (!rules->getCommendation(*i)->getTotalMissions().empty())
333+
_total_missions = rules->getCommendation(*i)->getTotalMissions();
329334

330335
// See if we already have the commendation, and if so what level it is
331336
for (std::vector<SoldierCommendations*>::const_iterator j = _commendations.begin(); j != _commendations.end(); ++j)
332337
{
333338
// Do we already have the commendation?
334339
if ( (*i) == (*j)->getCommendationName() )
335340
{
336-
_decorationLevel = (*j)->getDecorationLevelInt();
337-
break;
338-
}
339-
}
340-
341-
// Loop over criteria
342-
for(std::map<std::string, std::vector<int> >::const_iterator j = _commendationCriteria.begin(); j != _commendationCriteria.end(); ++j)
343-
{
344-
// If we don't have ANY of the following, that means we won't be awarded the commendation
345-
if ( !((*j).first == "total_kills" && getKillTotal() >= (*j).second[_decorationLevel] ||
346-
(*j).first == "total_missions" && getMissionTotal() >= (*j).second[_decorationLevel]) )
347-
{
348-
awardedCommendation = false;
341+
_decorationLevel = (*j)->getDecorationLevelInt() + 1;
349342
break;
350343
}
351344
}
352345

353-
if (awardedCommendation)
346+
// Go through each possible criteria
347+
// If there is a criteria (not empty) AND the soldier does not match it, then he does not get the medal, full stop.
348+
if ( !_total_kills.empty() && _total_kills.size() != _decorationLevel && getKillTotal() < _total_kills[_decorationLevel] )
354349
{
355-
awardCommendation(*i);
350+
continue;
351+
}
352+
else if ( !_total_missions.empty() && _total_missions.size() != _decorationLevel && getMissionTotal() < _total_missions[_decorationLevel] )
353+
{
354+
continue;
356355
}
356+
357+
// If the code has made it this far, this soldier deserves a medal!
358+
awardCommendation(*i);
359+
awardedCommendation = true;
357360
}
358361

359362
return awardedCommendation;

0 commit comments

Comments
 (0)