2023-04-26 20:55:56 +02:00
|
|
|
/*
|
|
|
|
* CGTownBuilding.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "IObjectInterface.h"
|
2023-04-30 20:34:41 +02:00
|
|
|
#include "../rewardable/Interface.h"
|
2023-04-26 20:55:56 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CGTownInstance;
|
2023-05-02 02:44:09 +02:00
|
|
|
class CBuilding;
|
2023-04-26 20:55:56 +02:00
|
|
|
|
|
|
|
class DLL_LINKAGE CGTownBuilding : public IObjectInterface
|
|
|
|
{
|
|
|
|
///basic class for town structures handled as map objects
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
CGTownBuilding(CGTownInstance * town);
|
|
|
|
CGTownBuilding(IGameCallback *cb);
|
|
|
|
|
2023-04-26 20:55:56 +02:00
|
|
|
si32 indexOnTV = 0; //identifies its index on towns vector
|
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
CGTownInstance * town;
|
2023-04-26 20:55:56 +02:00
|
|
|
|
|
|
|
STRONG_INLINE
|
|
|
|
BuildingSubID::EBuildingSubID getBuildingSubtype() const
|
|
|
|
{
|
|
|
|
return bType;
|
|
|
|
}
|
|
|
|
|
|
|
|
STRONG_INLINE
|
|
|
|
const BuildingID & getBuildingType() const
|
|
|
|
{
|
|
|
|
return bID;
|
|
|
|
}
|
|
|
|
|
|
|
|
STRONG_INLINE
|
|
|
|
void setBuildingSubtype(BuildingSubID::EBuildingSubID subId)
|
|
|
|
{
|
|
|
|
bType = subId;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor getOwner() const override;
|
2023-10-24 16:11:25 +02:00
|
|
|
MapObjectID getObjGroupIndex() const override;
|
|
|
|
MapObjectSubID getObjTypeIndex() const override;
|
2023-04-26 20:55:56 +02:00
|
|
|
|
|
|
|
int3 visitablePos() const override;
|
|
|
|
int3 getPosition() const override;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-04-26 20:55:56 +02:00
|
|
|
{
|
|
|
|
h & bID;
|
|
|
|
h & indexOnTV;
|
|
|
|
h & bType;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BuildingID bID; //from buildig list
|
|
|
|
BuildingSubID::EBuildingSubID bType = BuildingSubID::NONE;
|
|
|
|
|
|
|
|
std::string getVisitingBonusGreeting() const;
|
|
|
|
std::string getCustomBonusGreeting(const Bonus & bonus) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE COPWBonus : public CGTownBuilding
|
|
|
|
{///used for OPW bonusing structures
|
|
|
|
public:
|
2023-11-06 18:27:16 +02:00
|
|
|
std::set<ObjectInstanceID> visitors;
|
|
|
|
void setProperty(ObjProperty what, ObjPropertyID identifier) override;
|
2023-04-26 20:55:56 +02:00
|
|
|
void onHeroVisit (const CGHeroInstance * h) const override;
|
|
|
|
|
|
|
|
COPWBonus(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * TOWN);
|
2024-01-01 16:37:48 +02:00
|
|
|
COPWBonus(IGameCallback *cb);
|
2023-04-26 20:55:56 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-04-26 20:55:56 +02:00
|
|
|
{
|
|
|
|
h & static_cast<CGTownBuilding&>(*this);
|
|
|
|
h & visitors;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CTownBonus : public CGTownBuilding
|
|
|
|
{
|
|
|
|
///used for one-time bonusing structures
|
|
|
|
///feel free to merge inheritance tree
|
|
|
|
public:
|
|
|
|
std::set<ObjectInstanceID> visitors;
|
2023-11-06 18:27:16 +02:00
|
|
|
void setProperty(ObjProperty what, ObjPropertyID identifier) override;
|
2023-04-26 20:55:56 +02:00
|
|
|
void onHeroVisit (const CGHeroInstance * h) const override;
|
|
|
|
|
|
|
|
CTownBonus(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * TOWN);
|
2024-01-01 16:37:48 +02:00
|
|
|
CTownBonus(IGameCallback *cb);
|
2023-04-26 20:55:56 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-04-26 20:55:56 +02:00
|
|
|
{
|
|
|
|
h & static_cast<CGTownBuilding&>(*this);
|
|
|
|
h & visitors;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void applyBonuses(CGHeroInstance * h, const BonusList & bonuses) const;
|
|
|
|
};
|
|
|
|
|
2023-04-30 01:58:43 +02:00
|
|
|
class DLL_LINKAGE CTownRewardableBuilding : public CGTownBuilding, public Rewardable::Interface
|
|
|
|
{
|
2023-04-30 03:29:34 +02:00
|
|
|
/// reward selected by player, no serialize
|
|
|
|
ui16 selectedReward = 0;
|
2023-05-04 13:03:18 +02:00
|
|
|
|
2023-04-30 03:29:34 +02:00
|
|
|
std::set<ObjectInstanceID> visitors;
|
|
|
|
|
|
|
|
bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
|
|
|
|
|
2023-04-30 20:34:41 +02:00
|
|
|
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
|
|
|
|
|
2023-04-30 01:58:43 +02:00
|
|
|
public:
|
2023-11-06 18:27:16 +02:00
|
|
|
void setProperty(ObjProperty what, ObjPropertyID identifier) override;
|
2023-04-30 03:29:34 +02:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
2023-04-30 01:58:43 +02:00
|
|
|
|
2023-05-02 02:44:09 +02:00
|
|
|
void newTurn(CRandomGenerator & rand) const override;
|
|
|
|
|
2023-04-30 20:34:41 +02:00
|
|
|
/// gives second part of reward after hero level-ups for proper granting of spells/mana
|
|
|
|
void heroLevelUpDone(const CGHeroInstance *hero) const override;
|
|
|
|
|
2023-05-02 02:44:09 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
|
|
|
|
2023-04-30 20:34:41 +02:00
|
|
|
/// applies player selection of reward
|
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
|
|
|
|
2023-05-02 02:44:09 +02:00
|
|
|
CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * town, CRandomGenerator & rand);
|
2024-01-01 16:37:48 +02:00
|
|
|
CTownRewardableBuilding(IGameCallback *cb);
|
2023-04-30 01:58:43 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-04-30 01:58:43 +02:00
|
|
|
{
|
|
|
|
h & static_cast<CGTownBuilding&>(*this);
|
|
|
|
h & static_cast<Rewardable::Interface&>(*this);
|
2023-05-02 02:44:09 +02:00
|
|
|
h & visitors;
|
2023-04-30 01:58:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-26 20:55:56 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|