1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Boost::small_vector for UpgradeInfo data, UpgradeInfo minor changes

This commit is contained in:
MichalZr6
2025-01-30 16:00:59 +01:00
parent 358189d9c3
commit 93414eb3bf

View File

@@ -11,6 +11,7 @@
#include "../lib/constants/EntityIdentifiers.h"
#include "../lib/ResourceSet.h"
#include <boost/container/small_vector.hpp>
VCMI_LIB_NAMESPACE_BEGIN
@@ -25,9 +26,11 @@ public:
CreatureID oldID; //creature to be upgraded
const std::vector<CreatureID> & getAvailableUpgrades() const
const boost::container::small_vector<CreatureID, 4> & getAvailableUpgrades() const
{
return upgradesIDs;
static const boost::container::small_vector<CreatureID, 4> emptyUpgrades;
return (isAvailable && !upgradesIDs.empty()) ? upgradesIDs : emptyUpgrades;
}
const CreatureID & getUpgrade() const
@@ -44,9 +47,11 @@ public:
return upgradesCosts[std::distance(upgradesIDs.begin(), idIt)];
}
const std::vector<ResourceSet> & getAvailableUpgradeCosts() const
const boost::container::small_vector<ResourceSet, 4> & getAvailableUpgradeCosts() const
{
return upgradesCosts;
static const boost::container::small_vector<ResourceSet, 4> emptyCosts;
return (isAvailable && !upgradesCosts.empty()) ? upgradesCosts : emptyCosts;
}
const ResourceSet & getUpgradeCosts() const
@@ -73,8 +78,8 @@ public:
}
private:
std::vector<CreatureID> upgradesIDs; //possible upgrades
std::vector<ResourceSet> upgradesCosts; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>; cost is for single unit (not entire stack)
boost::container::small_vector<CreatureID, 4> upgradesIDs; //possible upgrades
boost::container::small_vector<ResourceSet, 4> upgradesCosts; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>; cost is for single unit (not entire stack)
bool isAvailable; // flag for unavailableUpgrades like in miniHillFort from HoTA
};