1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Rewardable town buildings prototype

This commit is contained in:
nordsoft 2023-04-30 03:58:43 +04:00
parent 3df0ce229e
commit 2adcc89a0d
6 changed files with 39 additions and 4 deletions

View File

@ -627,6 +627,12 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
for(auto & bonus : ret->onVisitBonuses)
bonus->sid = Bonus::getSid32(ret->town->faction->getIndex(), ret->bid);
}
if(!source["rewards"].isNull() && ret->subId == BuildingSubID::NONE)
{
ret->subId = BuildingSubID::CONFIGURABLE_REWARD;
ret->rewardableObjectInfo.init(source["rewards"]);
}
}
//MODS COMPATIBILITY FOR 0.96
if(!ret->produce.nonZero())

View File

@ -21,6 +21,7 @@
#include "battle/BattleHex.h"
#include "HeroBonus.h"
#include "Point.h"
#include "mapObjects/CRewardableConstructor.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -56,6 +57,8 @@ public:
std::set<BuildingID> overrideBids; /// the building which bonuses should be overridden with bonuses of the current building
BonusList buildingBonuses;
BonusList onVisitBonuses;
CRandomRewardObjectInfo rewardableObjectInfo; ///configurable rewards for special buildings
enum EBuildMode
{
@ -134,6 +137,7 @@ public:
h & overrideBids;
h & buildingBonuses;
h & onVisitBonuses;
h & rewardableObjectInfo;
}
friend class CTownHandler;

View File

@ -581,7 +581,8 @@ namespace BuildingSubID
EXPERIENCE_VISITING_BONUS,
LIGHTHOUSE,
TREASURY,
CUSTOM_VISITING_BONUS
CUSTOM_VISITING_BONUS,
CONFIGURABLE_REWARD
};
}

View File

@ -11,6 +11,7 @@
#pragma once
#include "CObjectHandler.h"
#include "CRewardableObject.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -104,4 +105,20 @@ private:
void applyBonuses(CGHeroInstance * h, const BonusList & bonuses) const;
};
class DLL_LINKAGE CTownRewardableBuilding : public CGTownBuilding, public Rewardable::Interface
{
public:
void setProperty(ui8 what, ui32 val) override;
void onHeroVisit (const CGHeroInstance * h) const override;
CTownRewardableBuilding(CGTownInstance * TOWN);
CTownRewardableBuilding() = default;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGTownBuilding&>(*this);
h & static_cast<Rewardable::Interface&>(*this);
}
};
VCMI_LIB_NAMESPACE_END

View File

@ -365,7 +365,7 @@ bool CGTownInstance::isBonusingBuildingAdded(BuildingID::EBuildingID bid) const
return present != bonusingBuildings.end();
}
void CGTownInstance::addTownBonuses()
void CGTownInstance::addTownBonuses(CRandomGenerator & rand)
{
for(const auto & kvp : town->buildings)
{
@ -377,6 +377,13 @@ void CGTownInstance::addTownBonuses()
if(kvp.second->IsWeekBonus())
bonusingBuildings.push_back(new COPWBonus(kvp.second->bid, kvp.second->subId, this));
if(kvp.second->subId == BuildingSubID::CONFIGURABLE_REWARD)
{
auto * newBuilding = new CTownRewardableBuilding(this);
kvp.second->rewardableObjectInfo.configureObject(newBuilding->configuration(), rand);
bonusingBuildings.push_back(newBuilding);
}
}
}
@ -465,7 +472,7 @@ void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structu
}
}
initOverriddenBids();
addTownBonuses(); //add special bonuses from buildings to the bonusingBuildings vector.
addTownBonuses(rand); //add special bonuses from buildings to the bonusingBuildings vector.
recreateBuildingsBonuses();
updateAppearance();
}

View File

@ -214,7 +214,7 @@ private:
bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const;
bool isBonusingBuildingAdded(BuildingID::EBuildingID bid) const;
void initOverriddenBids();
void addTownBonuses();
void addTownBonuses(CRandomGenerator & rand);
};
VCMI_LIB_NAMESPACE_END