Skip to content

Commit 709950b

Browse files
committed
Added sprite support
1 parent a4b8b65 commit 709950b

6 files changed

Lines changed: 94 additions & 23 deletions

File tree

bin/data/Ruleset/Xcom1Ruleset.rul

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9285,6 +9285,20 @@ extraSprites:
92859285
singleImage: true
92869286
files:
92879287
0: Resources/UI/reserve.png
9288+
- type: BIGOBS.PCK
9289+
width: 30
9290+
heigth: 8
9291+
files:
9292+
100: Resources/Commendations/medal_100.png
9293+
101: Resources/Commendations/medal_101.png
9294+
102: Resources/Commendations/medal_102.png
9295+
103: Resources/Commendations/medal_103.png
9296+
104: Resources/Commendations/medal_104.png
9297+
105: Resources/Commendations/medal_105.png
9298+
106: Resources/Commendations/medal_106.png
9299+
107: Resources/Commendations/medal_107.png
9300+
9301+
92889302
# Ruleset for diary and commendations mod
92899303
# When stats reach the criteria threshold, the commendation is awarded
92909304
# Any vector greater than 10 will require more strings to be written for them.
@@ -9311,41 +9325,51 @@ extraSprites:
93119325
commendations:
93129326
- type: STR_MEDAL_MERIT_STAR_NAME
93139327
description: STR_MEDAL_MERIT_STAR_DESCRIPTION
9328+
sprite: 100
93149329
criteria:
9315-
total_kills: [3, 6, 10, 15, 20, 25, 30, 35, 40, 50]
9330+
total_kills: [0, 6, 10, 15, 20, 25, 30, 35, 40, 50]
93169331
- type: STR_MEDAL_MILITARY_CROSS_NAME
93179332
description: STR_MEDAL_MILITARY_CROSS_DESCRIPTION
9333+
sprite: 101
93189334
criteria:
9319-
total_missions: [3, 6, 10, 15, 20, 25, 30, 35, 40, 50]
9335+
total_missions: [0, 6, 10, 15, 20, 25, 30, 35, 40, 50]
93209336
- type: STR_MEDAL_STAR_OF_GALLANTRY_NAME
93219337
description: STR_MEDAL_STAR_OF_GALLANTRY_DESCRIPTION
9338+
sprite: 102
93229339
criteria:
93239340
total_stuns: [1, 3, 5, 7, 9, 11, 13, 15, 17, 20]
93249341
- type: STR_MEDAL_DEFENDER_MEDAL_NAME
93259342
description: STR_MEDAL_DEFENDER_MEDAL_DESCRIPTION
9343+
sprite: 103
93269344
criteria:
93279345
total_base_defense_missions: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
93289346
- type: STR_MEDAL_LONGEST_NIGHT_NAME
93299347
description: STR_MEDAL_LONGEST_NIGHT_DESCRIPTION
9348+
sprite: 104
93309349
criteria:
93319350
total_night_terror_missions: [1, 2, 3, 4, 5, 7, 9, 11, 15, 20]
93329351
- type: STR_MEDAL_HONOR_CROSS_NAME
93339352
description: STR_MEDAL_HONOR_CROSS_DESCRIPTION
9353+
sprite: 105
93349354
criteria:
93359355
total_monthly_service: [1]
93369356
- type: STR_MEDAL_SERVICE_MEDAL_NAME
93379357
description: STR_MEDAL_SERVICE_MEDAL_DESCRIPTION
9358+
sprite: 106
93389359
criteria:
93399360
total_monthly_service: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
93409361
- type: STR_MEDAL_WEAPON_PROFICIENCY_NAME
93419362
description: STR_MEDAL_WEAPON_PROFICIENCY_DESCRIPTION
9363+
sprite: 107
93429364
criteria:
93439365
total_kills_with_a_weapon: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
93449366
- type: STR_MEDAL_CAMPAIGN_RIBBON_NAME
93459367
description: STR_MEDAL_CAMPAIGN_RIBBON_DESCRIPTION
9368+
sprite: 108
93469369
criteria:
93479370
total_missions_in_a_region: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
93489371
- type: STR_MEDAL_XENOCIDE_MEDAL_NAME
93499372
description: STR_MEDAL_XENOCIDE_MEDAL_DESCIRPTION
9373+
sprite: 109
93509374
criteria:
93519375
total_kills_by_race: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]

src/Basescape/SoldierDiaryKillsState.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../Engine/Language.h"
2626
#include "../Engine/Palette.h"
2727
#include "../Engine/Options.h"
28+
#include "../Engine/SurfaceSet.h"
2829
#include "../Geoscape/AllocatePsiTrainingState.h"
2930
#include "../Interface/TextButton.h"
3031
#include "../Interface/Window.h"
@@ -36,6 +37,7 @@
3637
#include "../Savegame/SoldierDiary.h"
3738
#include "../Ruleset/RuleCraft.h"
3839

40+
3941
namespace OpenXcom
4042
{
4143

@@ -94,7 +96,7 @@ SoldierDiaryKillsState::SoldierDiaryKillsState(Game *game, Base *base, size_t so
9496
_txtMedalName = new Text(90, 18, 16, 36);
9597
_txtMedalLevel = new Text(90, 18, 216, 36);
9698
_txtMedalInfo = new Text(280, 32, 20, 150);
97-
_lstCommendations = new TextList(272, 100, 16, 52);
99+
_lstCommendations = new TextList(272, 100, 48, 52);
98100

99101
// Set palette
100102
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(2)), Palette::backPos, 16);
@@ -247,12 +249,16 @@ SoldierDiaryKillsState::SoldierDiaryKillsState(Game *game, Base *base, size_t so
247249

248250
_lstCommendations->setColor(Palette::blockOffset(13)+10);
249251
_lstCommendations->setArrowColor(Palette::blockOffset(15)+1);
250-
_lstCommendations->setColumns(2, 200, 80);
252+
_lstCommendations->setColumns(2, 168, 80);
251253
_lstCommendations->setSelectable(true);
252254
_lstCommendations->setBackground(_window);
253255
_lstCommendations->onMouseOver((ActionHandler)&SoldierDiaryKillsState::lstInfoMouseOver);
254256
_lstCommendations->onMouseOut((ActionHandler)&SoldierDiaryKillsState::lstInfoMouseOut);
255257

258+
259+
260+
261+
256262
init(); // Populate the list
257263
}
258264

@@ -323,6 +329,7 @@ void SoldierDiaryKillsState::init()
323329
std::map<std::string, int> _typeTotals = s->getDiary()->getTypeTotal();
324330
std::map<std::string, int> _UFOTotals = s->getDiary()->getUFOTotal();
325331
_lstCommendations->clearList();
332+
int row;
326333

327334
for (std::map<std::string, int>::const_iterator i = _raceTotals.begin() ; i != _raceTotals.end() ; ++i)
328335
{
@@ -379,9 +386,12 @@ void SoldierDiaryKillsState::init()
379386
_lstUFO->addRow(2, ss1.str().c_str(), ss2.str().c_str());
380387
}
381388

389+
row = 0;
382390
for (std::vector<SoldierCommendations*>::const_iterator i = s->getDiary()->getSoldierCommendations()->begin() ; i != s->getDiary()->getSoldierCommendations()->end() ; ++i)
383391
{
384392
std::wstringstream ss1, ss2, ss3;
393+
int _sprite = (*i)->getSprite();
394+
Surface *_image = new Surface(30, 8, 16, 52 + 8*row);
385395

386396
if ((*i)->getNoun() != "")
387397
{
@@ -397,6 +407,14 @@ void SoldierDiaryKillsState::init()
397407
_lstCommendations->addRow(2, ss1.str().c_str(), ss2.str().c_str());
398408

399409
_commendationsListEntry.push_back(ss3.str().c_str());
410+
411+
// Handle commendation sprites
412+
add(_image);
413+
SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BIGOBS.PCK");
414+
texture->getFrame(_sprite)->setX(0);
415+
texture->getFrame(_sprite)->setY(0);
416+
texture->getFrame(_sprite)->blit(_image);
417+
row++;
400418
}
401419
}
402420

src/Ruleset/RuleCommendations.cpp

Lines changed: 11 additions & 1 deletion
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() : _description(""), _criteria()
28+
RuleCommendations::RuleCommendations() : _description(""), _criteria(), _sprite()
2929
{
3030
}
3131

@@ -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+
_sprite = node["sprite"].as<int>(_sprite);
4748
_listOrder = node["listOrder"].as<int>(_listOrder);
4849
if (!_listOrder)
4950
{
@@ -78,4 +79,13 @@ std::map<std::string, std::vector<int> > *RuleCommendations::getCriteria()
7879
return &_criteria;
7980
}
8081

82+
/**
83+
* Get the commendation's sprite
84+
* @return int Sprite number
85+
*/
86+
int RuleCommendations::getSprite() const
87+
{
88+
return _sprite;
89+
}
90+
8191
}

src/Ruleset/RuleCommendations.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RuleCommendations
3333
std::map<std::string, std::vector<int> > _criteria;
3434
std::string _description;
3535
int _listOrder;
36+
int _sprite;
3637
public:
3738
/// Creates a blank commendation ruleset.
3839
RuleCommendations();
@@ -48,6 +49,8 @@ class RuleCommendations
4849
std::string getDescription() const;
4950
/// Get commendation award criteria
5051
std::map<std::string, std::vector<int> > *getCriteria();
52+
/// Get sprite
53+
int getSprite() const;
5154

5255
};
5356

src/Savegame/SoldierDiary.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
371371
// match nouns and decoration levels
372372
for(std::map<std::string, int>::const_iterator k = _weaponTotal.begin(); k != _weaponTotal.end(); ++k)
373373
{
374-
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), (*j).second.at(_nextCommendationLevel.at((*k).first)));
374+
int _criteria = _nextCommendationLevel[""] == 0 ? 0 : (*j).second.at(_nextCommendationLevel.at((*k).first));
375+
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), _criteria);
375376
}
376377
// If it is still empty, we did not get a commendation
377378
if (_modularCommendations.empty())
@@ -384,7 +385,8 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
384385
{
385386
for(std::map<std::string, int>::const_iterator k = _regionTotal.begin(); k != _regionTotal.end(); ++k)
386387
{
387-
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), (*j).second.at(_nextCommendationLevel.at((*k).first)));
388+
int _criteria = _nextCommendationLevel[""] == 0 ? 0 : (*j).second.at(_nextCommendationLevel.at((*k).first));
389+
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), _criteria);
388390
}
389391
if (_modularCommendations.empty())
390392
{
@@ -396,7 +398,8 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
396398
{
397399
for(std::map<std::string, int>::const_iterator k = _alienRaceTotal.begin(); k != _alienRaceTotal.end(); ++k)
398400
{
399-
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), (*j).second.at(_nextCommendationLevel.at((*k).first)));
401+
int _criteria = _nextCommendationLevel[""] == 0 ? 0 : (*j).second.at(_nextCommendationLevel.at((*k).first));
402+
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), _criteria);
400403
}
401404
if (_modularCommendations.empty())
402405
{
@@ -408,7 +411,8 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
408411
{
409412
for(std::map<std::string, int>::const_iterator k = _alienRankTotal.begin(); k != _alienRankTotal.end(); ++k)
410413
{
411-
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), (*j).second.at(_nextCommendationLevel.at((*k).first)));
414+
int _criteria = _nextCommendationLevel[""] == 0 ? 0 : (*j).second.at(_nextCommendationLevel.at((*k).first));
415+
manageModularCommendations(_nextCommendationLevel, _modularCommendations, (*k), _criteria);
412416
}
413417
if (_modularCommendations.empty())
414418
{
@@ -427,7 +431,7 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
427431
}
428432
for (std::map<std::string, int>::const_iterator j = _modularCommendations.begin(); j != _modularCommendations.end(); ++j)
429433
{
430-
awardCommendation((*i).first, (*i).second->getDescription(), (*j).first);
434+
awardCommendation((*i).first, (*i).second->getDescription(), (*j).first, (*i).second->getSprite());
431435
_awardedCommendation = true;
432436
}
433437
}
@@ -439,26 +443,25 @@ bool SoldierDiary::manageCommendations(Ruleset *rules)
439443
/**
440444
* Manage modular commendations (private)
441445
*/
442-
void SoldierDiary::manageModularCommendations(std::map<std::string, int> progress, std::map<std::string, int> modularCommendations, std::pair<std::string, int> weaponTotal, int currentLevel)
446+
void SoldierDiary::manageModularCommendations(std::map<std::string, int> nextCommendationLevel, std::map<std::string, int> modularCommendations, std::pair<std::string, int> statTotal, int criteria)
443447
{
444-
int _criteria = progress[""] == 0 ? 0 : currentLevel;
445448
// If criteria is 0, we don't have this noun
446-
if (_criteria == 0 && weaponTotal.second >= _criteria)
449+
if (criteria == 0 && statTotal.second >= criteria)
447450
{
448-
modularCommendations[weaponTotal.first]++;
451+
modularCommendations[statTotal.first]++;
449452
}
450453
// If we meet the criteria, remember the noun for award purposes
451-
else if (_criteria != 0 && progress.at(weaponTotal.first) >= _criteria)
454+
else if (criteria != 0 && nextCommendationLevel.at(statTotal.first) >= criteria)
452455
{
453-
modularCommendations[weaponTotal.first]++;
456+
modularCommendations[statTotal.first]++;
454457
}
455458
}
456459

457460
/**
458461
* Award commendations to the soldier.
459462
* @param string Commendation Name.
460463
*/
461-
void SoldierDiary::awardCommendation(std::string _commendationName, std::string _commendationDescription, std::string _noun)
464+
void SoldierDiary::awardCommendation(std::string _commendationName, std::string _commendationDescription, std::string _noun, int sprite)
462465
{
463466
bool _newCommendation = true;
464467

@@ -473,7 +476,7 @@ void SoldierDiary::awardCommendation(std::string _commendationName, std::string
473476
}
474477
if (_newCommendation)
475478
{
476-
_commendations.push_back(new SoldierCommendations(_commendationName, _commendationDescription, _noun, 0, true));
479+
_commendations.push_back(new SoldierCommendations(_commendationName, _commendationDescription, _noun, 0, true, sprite));
477480
}
478481
}
479482

@@ -812,7 +815,7 @@ SoldierCommendations::SoldierCommendations(const YAML::Node &node)
812815
/**
813816
* Initializes a soldier commendation.
814817
*/
815-
SoldierCommendations::SoldierCommendations(std::string commendationName, std::string commendationDescription, std::string noun, int decorationLevel, bool isNew) : _commendationName(commendationName), _commendationDescription(commendationDescription), _noun(noun), _decorationLevel(decorationLevel), _isNew(isNew)
818+
SoldierCommendations::SoldierCommendations(std::string commendationName, std::string commendationDescription, std::string noun, int decorationLevel, bool isNew, int sprite) : _commendationName(commendationName), _commendationDescription(commendationDescription), _noun(noun), _decorationLevel(decorationLevel), _isNew(isNew), _sprite(sprite)
816819
{
817820

818821
}
@@ -835,6 +838,7 @@ void SoldierCommendations::load(const YAML::Node &node)
835838
_noun = node["noun"].as<std::string>(_noun);
836839
_decorationLevel = node["decorationLevel"].as<int>(_decorationLevel);
837840
_isNew = node["isNew"].as<bool>(_isNew);
841+
_sprite = node["sprite"].as<int>(_sprite);
838842
}
839843

840844
/**
@@ -849,6 +853,7 @@ YAML::Node SoldierCommendations::save() const
849853
node["noun"] = _noun;
850854
node["decorationLevel"] = _decorationLevel;
851855
node["isNew"] = _isNew;
856+
node["sprite"] = _sprite;
852857
return node;
853858
}
854859

@@ -960,4 +965,13 @@ void SoldierCommendations::addDecoration()
960965
_isNew = true;
961966
}
962967

968+
/**
969+
* Get the sprite int
970+
* @return sprite int
971+
*/
972+
int SoldierCommendations::getSprite() const
973+
{
974+
return _sprite;
975+
}
976+
963977
}

src/Savegame/SoldierDiary.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ class SoldierCommendations
136136
private:
137137
RuleCommendations *_rules;
138138
std::string _commendationName, _commendationDescription, _noun;
139-
int _decorationLevel;
139+
int _decorationLevel, _sprite;
140140
bool _isNew;
141141
public:
142142
/// Creates a new commendation and loads its contents from YAML.
143143
SoldierCommendations(const YAML::Node& node);
144144
/// Creates a commendation of the specified type.
145-
SoldierCommendations(std::string commendationName, std::string commendationDescription, std::string noun, int decorationLevel, bool isNew);
145+
SoldierCommendations(std::string commendationName, std::string commendationDescription, std::string noun, int decorationLevel, bool isNew, int sprite);
146146
/// Cleans up the commendation.
147147
~SoldierCommendations();
148148
/// Loads the commendation information from YAML.
@@ -168,6 +168,8 @@ class SoldierCommendations
168168
/// Increment decoration level.
169169
// Sets _isNew to true.
170170
void addDecoration();
171+
/// Get sprite
172+
int getSprite() const;
171173
};
172174

173175
class SoldierDiary
@@ -180,7 +182,7 @@ class SoldierDiary
180182
int _scoreTotal, _killTotal, _missionTotal, _winTotal, _stunTotal, _daysWoundedTotal, _baseDefenseMissionTotal,
181183
_terrorMissionTotal, _nightMissionTotal, _nightTerrorMissionTotal, _monthsService;
182184

183-
void manageModularCommendations(std::map<std::string, int> progress, std::map<std::string, int> modularCommendations, std::pair<std::string, int> weaponTotal, int currentLevel);
185+
void manageModularCommendations(std::map<std::string, int> nextCommendationLevel, std::map<std::string, int> modularCommendations, std::pair<std::string, int> statTotal, int criteria);
184186
public:
185187
/// Creates a new soldier-equipment layout item and loads its contents from YAML.
186188
SoldierDiary(const YAML::Node& node);
@@ -239,7 +241,7 @@ class SoldierDiary
239241
/// Manage commendations, return true if a medal is awarded.
240242
bool manageCommendations(Ruleset *rules);
241243
/// Award commendations
242-
void awardCommendation(std::string commendationName, std::string commendationDescription, std::string noun = "");
244+
void awardCommendation(std::string commendationName, std::string commendationDescription, std::string noun = "", int sprite = 100);
243245
/// Increment soldier's service time.
244246
void addMonthlyService();
245247
};

0 commit comments

Comments
 (0)