Skip to content

Commit a50ee1c

Browse files
committed
Expansion of recolor algorithm
Possible of recolor based on rank and third recolor based on race. Bonus fix for load save constructor for MC aliens.
1 parent 4c05a2e commit a50ee1c

8 files changed

Lines changed: 186 additions & 116 deletions

File tree

‎src/Battlescape/BattlescapeGenerator.cpp‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ BattleUnit *BattlescapeGenerator::addXCOMUnit(BattleUnit *unit)
704704
unit->setDirection(RNG::generate(0,7));
705705
_save->getUnits()->push_back(unit);
706706
_save->getTileEngine()->calculateFOV(unit);
707-
unit->deriveRank();
708707
unit->setSpecialWeapon(_save, _game->getRuleset());
709708
return unit;
710709
}
@@ -716,7 +715,6 @@ BattleUnit *BattlescapeGenerator::addXCOMUnit(BattleUnit *unit)
716715
unit->setDirection(RNG::generate(0,7));
717716
_save->getUnits()->push_back(unit);
718717
_save->getTileEngine()->calculateFOV(unit);
719-
unit->deriveRank();
720718
unit->setSpecialWeapon(_save, _game->getRuleset());
721719
return unit;
722720
}
@@ -742,7 +740,6 @@ BattleUnit *BattlescapeGenerator::addXCOMUnit(BattleUnit *unit)
742740
{
743741
_save->getUnits()->push_back(unit);
744742
unit->setDirection(dir);
745-
unit->deriveRank();
746743
unit->setSpecialWeapon(_save, _game->getRuleset());
747744
return unit;
748745
}
@@ -758,7 +755,6 @@ BattleUnit *BattlescapeGenerator::addXCOMUnit(BattleUnit *unit)
758755
if (_save->setUnitPosition(unit, _save->getTiles()[i]->getPosition()))
759756
{
760757
_save->getUnits()->push_back(unit);
761-
unit->deriveRank();
762758
unit->setSpecialWeapon(_save, _game->getRuleset());
763759
return unit;
764760
}

‎src/Battlescape/UnitSprite.cpp‎

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace OpenXcom
4545
* @param x X position in pixels.
4646
* @param y Y position in pixels.
4747
*/
48-
UnitSprite::UnitSprite(int width, int height, int x, int y, bool helmet) : Surface(width, height, x, y), _unit(0), _itemA(0), _itemB(0), _unitSurface(0), _itemSurfaceA(0), _itemSurfaceB(0), _part(0), _animationFrame(0), _drawingRoutine(0), _helmet(helmet)
48+
UnitSprite::UnitSprite(int width, int height, int x, int y, bool helmet) : Surface(width, height, x, y), _unit(0), _itemA(0), _itemB(0), _unitSurface(0), _itemSurfaceA(0), _itemSurfaceB(0), _part(0), _animationFrame(0), _drawingRoutine(0), _helmet(helmet), _color(0), _colorSize(0)
4949
{
5050
}
5151

@@ -85,13 +85,15 @@ void UnitSprite::setBattleUnit(BattleUnit *unit, int part)
8585

8686
if (Options::battleHairBleach)
8787
{
88-
_colorA = _unit->getRecolor(0);
89-
_colorB = _unit->getRecolor(1);
90-
}
91-
else
92-
{
93-
_colorA = std::pair<Uint8, Uint8>();
94-
_colorB = std::pair<Uint8, Uint8>();
88+
_colorSize =_unit->getRecolor().size();
89+
if (_colorSize)
90+
{
91+
_color = &(_unit->getRecolor()[0]);
92+
}
93+
else
94+
{
95+
_color = 0;
96+
}
9597
}
9698
}
9799

@@ -120,7 +122,7 @@ struct ColorReplace
120122
static const Uint8 ColorGroup = 15<<4;
121123
static const Uint8 ColorShade = 15;
122124

123-
static inline bool func(Uint8& dest, const Uint8& src, const std::pair<Uint8, Uint8>& face_color)
125+
static inline bool loop(Uint8& dest, const Uint8& src, const std::pair<Uint8, Uint8>& face_color)
124126
{
125127
if ((src & ColorGroup) == face_color.first)
126128
{
@@ -132,30 +134,18 @@ struct ColorReplace
132134
return false;
133135
}
134136
}
135-
};
136137

137-
struct Color1
138-
{
139-
static inline void func(Uint8& dest, const Uint8& src, const std::pair<Uint8, Uint8>& colorA, int, int)
138+
static inline void func(Uint8& dest, const Uint8& src, const std::pair<Uint8, Uint8> *color, int size, int)
140139
{
141140
if (src)
142141
{
143-
if (ColorReplace::func(dest, src, colorA)) return;
144-
145-
dest = src;
146-
}
147-
}
148-
};
149-
150-
struct Color2
151-
{
152-
static inline void func(Uint8& dest, const Uint8& src, const std::pair<Uint8, Uint8>& colorA, const std::pair<Uint8, Uint8>& colorB, int)
153-
{
154-
if (src)
155-
{
156-
if (ColorReplace::func(dest, src, colorA)) return;
157-
if (ColorReplace::func(dest, src, colorB)) return;
158-
142+
for (int i = 0; i < size; ++i)
143+
{
144+
if (loop(dest, src, color[i]))
145+
{
146+
return;
147+
}
148+
}
159149
dest = src;
160150
}
161151
}
@@ -165,16 +155,10 @@ struct Color2
165155

166156
void UnitSprite::drawRecolored(Surface *src)
167157
{
168-
if (_colorB.first != 0)
169-
{
170-
lock();
171-
ShaderDraw<Color2>(ShaderSurface(this), ShaderSurface(src), ShaderScalar(_colorA), ShaderScalar(_colorB));
172-
unlock();
173-
}
174-
else if (_colorA.first != 0)
158+
if (_colorSize)
175159
{
176160
lock();
177-
ShaderDraw<Color1>(ShaderSurface(this), ShaderSurface(src), ShaderScalar(_colorA));
161+
ShaderDraw<ColorReplace>(ShaderSurface(this), ShaderSurface(src), ShaderScalar(_color), ShaderScalar(_colorSize));
178162
unlock();
179163
}
180164
else

‎src/Battlescape/UnitSprite.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class UnitSprite : public Surface
4040
SurfaceSet *_unitSurface, *_itemSurfaceA, *_itemSurfaceB;
4141
int _part, _animationFrame, _drawingRoutine;
4242
bool _helmet;
43-
std::pair<Uint8, Uint8> _colorA, _colorB;
43+
const std::pair<Uint8, Uint8> *_color;
44+
int _colorSize;
4445

4546
/// Drawing routine for XCom soldiers in overalls, sectoids (routine 0),
4647
/// mutons (routine 10),

‎src/Ruleset/Armor.cpp‎

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ Armor::Armor(const std::string &type) :
3131
_type(type), _frontArmor(0), _sideArmor(0), _rearArmor(0), _underArmor(0),
3232
_drawingRoutine(0), _movementType(MT_WALK), _size(1), _weight(0),
3333
_deathFrames(3), _constantAnimation(false), _canHoldWeapon(false),
34-
_forcedTorso(TORSO_USE_GENDER), _faceColorGroup(0), _hairColorGroup(0)
34+
_forcedTorso(TORSO_USE_GENDER),
35+
_faceColorGroup(0), _hairColorGroup(0), _utileColorGroup(0), _rankColorGroup(0)
3536
{
3637
for (int i=0; i < DAMAGE_TYPES; i++)
3738
_damageModifier[i] = 1.0f;
38-
39-
_faceColor.resize((LOOK_AFRICAN + 1) * 2);
40-
_hairColor.resize((LOOK_AFRICAN + 1) * 2);
4139
}
4240

4341
/**
@@ -113,16 +111,12 @@ void Armor::load(const YAML::Node &node)
113111

114112
_faceColorGroup = node["spriteFaceGroup"].as<int>(_faceColorGroup);
115113
_hairColorGroup = node["spriteHairGroup"].as<int>(_hairColorGroup);
116-
if (const YAML::Node& colors = node["spriteFaceColor"])
117-
{
118-
for (size_t i = 0; i < colors.size() && i < _faceColor.size(); ++i)
119-
_faceColor[i] = colors[i].as<int>();
120-
}
121-
if (const YAML::Node& colors = node["spriteHairColor"])
122-
{
123-
for (size_t i = 0; i < colors.size() && i < _hairColor.size(); ++i)
124-
_hairColor[i] = colors[i].as<int>();
125-
}
114+
_rankColorGroup = node["spriteRankGroup"].as<int>(_rankColorGroup);
115+
_utileColorGroup = node["spriteUtileGroup"].as<int>(_utileColorGroup);
116+
_faceColor = node["spriteFaceColor"].as<std::vector<int> >(_faceColor);
117+
_hairColor = node["spriteHairColor"].as<std::vector<int> >(_hairColor);
118+
_rankColor = node["spriteRankColor"].as<std::vector<int> >(_rankColor);
119+
_utileColor = node["spriteUtileColor"].as<std::vector<int> >(_utileColor);
126120
}
127121

128122
/**
@@ -331,38 +325,103 @@ ForcedTorso Armor::getForcedTorso() const
331325
}
332326

333327
/**
334-
* Gets hair base color group for replacement, if -1 then don't replace colors.
335-
* @return Color group or -1.
328+
* Gets hair base color group for replacement, if 0 then don't replace colors.
329+
* @return Color group or 0.
336330
*/
337331
int Armor::getFaceColorGroup() const
338332
{
339333
return _faceColorGroup;
340334
}
341335

342336
/**
343-
* Gets hair base color group for replacement, if -1 then don't replace colors.
344-
* @return Color group or -1.
337+
* Gets hair base color group for replacement, if 0 then don't replace colors.
338+
* @return Color group or 0.
345339
*/
346340
int Armor::getHairColorGroup() const
347341
{
348342
return _hairColorGroup;
349343
}
350344

351345
/**
352-
* Gets new face colors for replacement.
353-
* @return Vector with new values based on gender and race.
346+
* Gets utile base color group for replacement, if 0 then don't replace colors.
347+
* @return Color group or 0.
348+
*/
349+
int Armor::getUtileColorGroup() const
350+
{
351+
return _utileColorGroup;
352+
}
353+
354+
/**
355+
* Gets rank base color group for replacement, if 0 then don't replace colors.
356+
* @return Color group or 0.
357+
*/
358+
int Armor::getRankColorGroup() const
359+
{
360+
return _rankColorGroup;
361+
}
362+
363+
/**
364+
* Gets new face colors for replacement, if 0 then don't replace colors.
365+
* @return Color index or 0.
366+
*/
367+
int Armor::getFaceColor(int i) const
368+
{
369+
if ((size_t)i < _faceColor.size())
370+
{
371+
return _faceColor[i];
372+
}
373+
else
374+
{
375+
return 0;
376+
}
377+
}
378+
379+
/**
380+
* Gets new hair colors for replacement, if 0 then don't replace colors.
381+
* @return Color index or 0.
354382
*/
355-
const std::vector<int>& Armor::getFaceColor() const
383+
int Armor::getHairColor(int i) const
356384
{
357-
return _faceColor;
385+
if ((size_t)i < _hairColor.size())
386+
{
387+
return _hairColor[i];
388+
}
389+
else
390+
{
391+
return 0;
392+
}
358393
}
359394

360395
/**
361-
* Gets new hair colors for replacement.
362-
* @return Vector with new values based on gender and race.
396+
* Gets new utile colors for replacement, if 0 then don't replace colors.
397+
* @return Color index or 0.
363398
*/
364-
const std::vector<int>& Armor::getHairColor() const
399+
int Armor::getUtileColor(int i) const
365400
{
366-
return _hairColor;
401+
if ((size_t)i < _utileColor.size())
402+
{
403+
return _utileColor[i];
404+
}
405+
else
406+
{
407+
return 0;
408+
}
367409
}
410+
411+
/**
412+
* Gets new rank colors for replacement, if 0 then don't replace colors.
413+
* @return Color index or 0.
414+
*/
415+
int Armor::getRankColor(int i) const
416+
{
417+
if ((size_t)i < _rankColor.size())
418+
{
419+
return _rankColor[i];
420+
}
421+
else
422+
{
423+
return 0;
424+
}
425+
}
426+
368427
}

‎src/Ruleset/Armor.h‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class Armor
5151
bool _constantAnimation;
5252
bool _canHoldWeapon;
5353
ForcedTorso _forcedTorso;
54-
int _faceColorGroup, _hairColorGroup;
55-
std::vector<int> _faceColor, _hairColor;
54+
int _faceColorGroup, _hairColorGroup, _utileColorGroup, _rankColorGroup;
55+
std::vector<int> _faceColor, _hairColor, _utileColor, _rankColor;
5656
public:
5757
/// Creates a blank armor ruleset.
5858
Armor(const std::string &type);
@@ -108,10 +108,18 @@ class Armor
108108
int getFaceColorGroup() const;
109109
/// Get hair base color
110110
int getHairColorGroup() const;
111+
/// Get utile base color
112+
int getUtileColorGroup() const;
113+
/// Get rank base color
114+
int getRankColorGroup() const;
111115
/// Get face base color
112-
const std::vector<int>& getFaceColor() const;
116+
int getFaceColor(int i) const;
113117
/// Get hair base color
114-
const std::vector<int>& getHairColor() const;
118+
int getHairColor(int i) const;
119+
/// Get utile base color
120+
int getUtileColor(int i) const;
121+
/// Get rank base color
122+
int getRankColor(int i) const;
115123
};
116124

117125
}

0 commit comments

Comments
 (0)