1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Hill fort upgrade costs are now loaded from json

This commit is contained in:
Ivan Savenko
2023-06-07 00:17:39 +03:00
parent 2e7c382612
commit a94b68e6aa
9 changed files with 128 additions and 7 deletions

View File

@@ -2169,10 +2169,20 @@ void HillFort::onHeroVisit(const CGHeroInstance * h) const
openWindow(EOpenWindowMode::HILL_FORT_WINDOW,id.getNum(),h->id.getNum());
}
void HillFort::initObj(CRandomGenerator & rand)
{
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
}
void HillFort::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const
{
static const int costModifiers[] = {0, 25, 50, 75, 100}; //we get cheaper upgrades depending on level
const int costModifier = costModifiers[std::min<int>(std::max((int)stack.type->getLevel() - 1, 0), std::size(costModifiers) - 1)];
int32_t level = stack.type->getLevel();
int32_t index = std::clamp<int32_t>(level - 1, 0, upgradeCostPercentage.size() - 1);
int costModifier = upgradeCostPercentage[index];
if (costModifier < 0)
return; // upgrade not allowed
for(const auto & nid : stack.type->upgrades)
{

View File

@@ -15,6 +15,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CMap;
class HillFortInstanceConstructor;
// This one teleport-specific, but has to be available everywhere in callbacks and netpacks
// For now it's will be there till teleports code refactored and moved into own file
@@ -555,9 +556,21 @@ public:
class DLL_LINKAGE HillFort : public CGObjectInstance, public ICreatureUpgrader
{
friend class HillFortInstanceConstructor;
std::vector<int> upgradeCostPercentage;
protected:
void initObj(CRandomGenerator & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override;
void fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const override;
public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & upgradeCostPercentage;
}
};
VCMI_LIB_NAMESPACE_END