Skip to content

Commit 96fa47e

Browse files
committed
Added logic for kills by criteria
1 parent e83e567 commit 96fa47e

5 files changed

Lines changed: 93 additions & 1 deletion

File tree

bin/data/Ruleset/Commendations.rul

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,40 @@ commendations:
293293
description: STR_MEDAL_HELLRAISER_MEDAL_DESCRIPTION
294294
sprite: 11
295295
criteria:
296-
total_fell_unconcious: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
296+
total_fell_unconcious: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
297+
- type: STR_MEDAL_NAME
298+
description: STR_MEDAL_DESCRIPTION
299+
sprite: 0
300+
criteria:
301+
kills_with_criteria: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
302+
killCriteria:
303+
- ["Sectoid", "Commander"]
304+
# Awarded when soldier kills one Sectoid + Commander
305+
- type: STR_MEDAL_NAME
306+
description: STR_MEDAL_DESCRIPTION
307+
sprite: 0
308+
criteria:
309+
kills_with_criteria: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
310+
killCriteria:
311+
- ["Sectoid"]
312+
- ["Floater"]
313+
- ["Snakeman"]
314+
# Awarded when soldier kills one Sectoid, one Floater, one Snakeman
315+
- type: STR_MEDAL_NAME
316+
description: STR_MEDAL_DESCRIPTION
317+
sprite: 0
318+
criteria:
319+
kills_with_criteria: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
320+
killCriteria:
321+
- ["Sectoid", "Soldier"]
322+
- ["Floater", "Soldier"]
323+
- ["Snakeman", "Soldier"]
324+
# Awarded when soldier kills one Sectoid + Soldier, one Floater + Soldier, one Snakeman + Soldier
325+
- type: STR_MEDAL_NAME
326+
description: STR_MEDAL_DESCRIPTION
327+
sprite: 0
328+
criteria:
329+
kills_with_criteria: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
330+
killCriteria:
331+
- ["Sectoid", "Incendiary Rocket"]
332+
# Awarded when a soldier kills one Sectoid using Incendiary Rockets

src/Ruleset/RuleCommendations.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void RuleCommendations::load(const YAML::Node &node, int listOrder)
4444
{
4545
_description = node["description"].as<std::string>(_description);
4646
_criteria = node["criteria"].as< std::map< std::string, std::vector<int> > >(_criteria);
47+
_killCriteria = node["killCriteria"].as< std::vector< std::vector<std::string> > >(_killCriteria);
4748
_sprite = node["sprite"].as<int>(_sprite);
4849
_listOrder = node["listOrder"].as<int>(_listOrder);
4950
if (!_listOrder)
@@ -79,6 +80,15 @@ std::map<std::string, std::vector<int> > *RuleCommendations::getCriteria()
7980
return &_criteria;
8081
}
8182

83+
/**
84+
* Get commendation award kill criteria
85+
* @return vecotr<string> Commendation kill criteria
86+
*/
87+
std::vector< std::vector<std::string> > *RuleCommendations::getKillCriteria()
88+
{
89+
return &_killCriteria;
90+
}
91+
8292
/**
8393
* Get the commendation's sprite
8494
* @return int Sprite number

src/Ruleset/RuleCommendations.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class RuleCommendations
3131
{
3232
private:
3333
std::map<std::string, std::vector<int> > _criteria;
34+
std::vector< std::vector<std::string> > _killCriteria;
3435
std::string _description;
3536
int _listOrder;
3637
int _sprite;
@@ -49,6 +50,8 @@ class RuleCommendations
4950
std::string getDescription() const;
5051
/// Get commendation award criteria
5152
std::map<std::string, std::vector<int> > *getCriteria();
53+
/// Get commendation award kill related criteria
54+
std::vector< std::vector<std::string> > *getKillCriteria();
5255
/// Get sprite
5356
int getSprite() const;
5457

src/Savegame/SoldierDiary.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ void SoldierDiary::updateDiary()
150150
SoldierDiaryEntries *latestEntry = _diaryEntries.back();
151151
for (std::vector<SoldierDiaryKills*>::const_iterator j = latestEntry->getMissionStatistics()->kills.begin() ; j != latestEntry->getMissionStatistics()->kills.end() ; ++j)
152152
{
153+
_killList.push_back(*j);
153154
_alienRankTotal[(*j)->getAlienRank().c_str()]++;
154155
_alienRaceTotal[(*j)->getAlienRace().c_str()]++;
155156
_weaponTotal[(*j)->getWeapon().c_str()]++;
@@ -468,6 +469,47 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
468469
break;
469470
}
470471
}
472+
else if ((*j).first == "kills_with_criteria")
473+
{
474+
std::vector<std::vector<std::string> > *_killCriteriaList = (*i).second->getKillCriteria();
475+
476+
/// Add "original faction" to the SoldierDiaryKills class so we can track enemy kills
477+
/// Look to see if it's possible to convert the enum AlienState to a string when comparing OR convert the string from the ruleset to an enum AlienState
478+
479+
// Loop over the vector of vectors of items
480+
for (std::vector<std::vector<std::string> >::const_iterator listItem = _killCriteriaList->begin(); listItem != _killCriteriaList->end(); ++listItem)
481+
{
482+
int count = 0; // Reset count
483+
std::vector<SoldierDiaryKills*> _tmpKillList = _killList; // Reset kills
484+
// Loop over the vector of kills
485+
for (std::vector<SoldierDiaryKills*>::const_iterator singleKill = _tmpKillList.begin(); singleKill != _tmpKillList.end(); ++singleKill)
486+
{
487+
bool foundMatch = true; // Reset bool
488+
// Loop over the vector of items
489+
for (std::vector<std::string>::const_iterator item = listItem->begin(); item != listItem->end(); ++item)
490+
{
491+
// See if we find no matches with any criteria. If so, break and try the next kill.
492+
if ((*singleKill)->getAlienRank() != (*item) && (*singleKill)->getAlienRace() != (*item) && (*singleKill)->getWeapon() != (*item) && (*singleKill)->getWeaponAmmo() != (*item))
493+
{
494+
// Remove entries that have no matches.
495+
_tmpKillList.erase(singleKill); // I assume this deletes the current kill from the vector... hopefully.
496+
foundMatch = false;
497+
break;
498+
}
499+
}
500+
if (foundMatch) count++;
501+
}
502+
// If this single vector of items doesn't make the cut, do not award commendation
503+
if (count < (*j).second.at(_nextCommendationLevel[""]))
504+
{
505+
_awardCommendation = false;
506+
break;
507+
}
508+
}
509+
// Break out of this for loop as well
510+
if (!_awardCommendation) break;
511+
512+
}
471513
}
472514
if (_awardCommendation)
473515
{

src/Savegame/SoldierDiary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class SoldierDiary
192192
std::vector<SoldierDiaryEntries*> _diaryEntries;
193193
std::vector<SoldierCommendations*> _commendations;
194194
RuleCommendations *_rules;
195+
std::vector<SoldierDiaryKills*> _killList;
195196
std::map<std::string, int> _alienRankTotal, _alienRaceTotal, _weaponTotal, _weaponAmmoTotal, _regionTotal, _countryTotal, _typeTotal, _UFOTotal;
196197
int _scoreTotal, _killTotal, _missionTotal, _winTotal, _stunTotal, _daysWoundedTotal, _baseDefenseMissionTotal,
197198
_terrorMissionTotal, _nightMissionTotal, _nightTerrorMissionTotal, _monthsService, _unconciousTotal, _killsWithFireTotal;

0 commit comments

Comments
 (0)