@@ -316,44 +316,47 @@ std::vector<SoldierCommendations*> *SoldierDiary::getSoldierCommendations()
316316bool 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