mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Rewardable town buildings prototype
This commit is contained in:
parent
3df0ce229e
commit
2adcc89a0d
@ -627,6 +627,12 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
|
|||||||
for(auto & bonus : ret->onVisitBonuses)
|
for(auto & bonus : ret->onVisitBonuses)
|
||||||
bonus->sid = Bonus::getSid32(ret->town->faction->getIndex(), ret->bid);
|
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
|
//MODS COMPATIBILITY FOR 0.96
|
||||||
if(!ret->produce.nonZero())
|
if(!ret->produce.nonZero())
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "battle/BattleHex.h"
|
#include "battle/BattleHex.h"
|
||||||
#include "HeroBonus.h"
|
#include "HeroBonus.h"
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
#include "mapObjects/CRewardableConstructor.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ public:
|
|||||||
BonusList buildingBonuses;
|
BonusList buildingBonuses;
|
||||||
BonusList onVisitBonuses;
|
BonusList onVisitBonuses;
|
||||||
|
|
||||||
|
CRandomRewardObjectInfo rewardableObjectInfo; ///configurable rewards for special buildings
|
||||||
|
|
||||||
enum EBuildMode
|
enum EBuildMode
|
||||||
{
|
{
|
||||||
BUILD_NORMAL, // 0 - normal, default
|
BUILD_NORMAL, // 0 - normal, default
|
||||||
@ -134,6 +137,7 @@ public:
|
|||||||
h & overrideBids;
|
h & overrideBids;
|
||||||
h & buildingBonuses;
|
h & buildingBonuses;
|
||||||
h & onVisitBonuses;
|
h & onVisitBonuses;
|
||||||
|
h & rewardableObjectInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class CTownHandler;
|
friend class CTownHandler;
|
||||||
|
@ -581,7 +581,8 @@ namespace BuildingSubID
|
|||||||
EXPERIENCE_VISITING_BONUS,
|
EXPERIENCE_VISITING_BONUS,
|
||||||
LIGHTHOUSE,
|
LIGHTHOUSE,
|
||||||
TREASURY,
|
TREASURY,
|
||||||
CUSTOM_VISITING_BONUS
|
CUSTOM_VISITING_BONUS,
|
||||||
|
CONFIGURABLE_REWARD
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
|
#include "CRewardableObject.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -104,4 +105,20 @@ private:
|
|||||||
void applyBonuses(CGHeroInstance * h, const BonusList & bonuses) const;
|
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
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -365,7 +365,7 @@ bool CGTownInstance::isBonusingBuildingAdded(BuildingID::EBuildingID bid) const
|
|||||||
return present != bonusingBuildings.end();
|
return present != bonusingBuildings.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGTownInstance::addTownBonuses()
|
void CGTownInstance::addTownBonuses(CRandomGenerator & rand)
|
||||||
{
|
{
|
||||||
for(const auto & kvp : town->buildings)
|
for(const auto & kvp : town->buildings)
|
||||||
{
|
{
|
||||||
@ -377,6 +377,13 @@ void CGTownInstance::addTownBonuses()
|
|||||||
|
|
||||||
if(kvp.second->IsWeekBonus())
|
if(kvp.second->IsWeekBonus())
|
||||||
bonusingBuildings.push_back(new COPWBonus(kvp.second->bid, kvp.second->subId, this));
|
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();
|
initOverriddenBids();
|
||||||
addTownBonuses(); //add special bonuses from buildings to the bonusingBuildings vector.
|
addTownBonuses(rand); //add special bonuses from buildings to the bonusingBuildings vector.
|
||||||
recreateBuildingsBonuses();
|
recreateBuildingsBonuses();
|
||||||
updateAppearance();
|
updateAppearance();
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ private:
|
|||||||
bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const;
|
bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const;
|
||||||
bool isBonusingBuildingAdded(BuildingID::EBuildingID bid) const;
|
bool isBonusingBuildingAdded(BuildingID::EBuildingID bid) const;
|
||||||
void initOverriddenBids();
|
void initOverriddenBids();
|
||||||
void addTownBonuses();
|
void addTownBonuses(CRandomGenerator & rand);
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
Loading…
Reference in New Issue
Block a user