1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Move UpgradeInfo class to header and source files

This commit is contained in:
MichalZr6
2024-12-19 11:29:57 +01:00
parent af9445c16f
commit f893c80192
16 changed files with 139 additions and 93 deletions

View File

@@ -52,6 +52,7 @@
#include "../rmg/CMapGenerator.h"
#include "../serializer/CMemorySerializer.h"
#include "../spells/CSpellHandler.h"
#include "UpgradeInfo.h"
#include <vstd/RNG.h>
@@ -1779,23 +1780,4 @@ ArtifactID CGameState::pickRandomArtifact(vstd::RNG & rand, int flags)
return pickRandomArtifact(rand, flags, [](const ArtifactID &) { return true; });
}
void UpgradeInfo::addUpgrade(const CreatureID & upgradeID, const Creature * creature, int costModifier)
{
isAvailable = costModifier >= 0;
upgradesIDs.push_back(upgradeID);
ResourceSet upgradeCost = (upgradeID.toCreature()->getFullRecruitCost() - creature->getFullRecruitCost()) * costModifier / 100;
upgradeCost.positive(); //upgrade cost can't be negative, ignore missing resources
upgradesCosts.push_back(std::move(upgradeCost));
// sort from highest ID to smallest
size_t pos = upgradesIDs.size() - 1;
while(pos > 0 && upgradesIDs[pos] > upgradesIDs[pos - 1])
{
std::swap(upgradesIDs[pos], upgradesIDs[pos - 1]);
std::swap(upgradesCosts[pos], upgradesCosts[pos - 1]);
--pos;
}
}
VCMI_LIB_NAMESPACE_END