1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/mapObjects/TownBuildingInstance.h

102 lines
3.0 KiB
C++
Raw Normal View History

2023-04-26 20:55:56 +02:00
/*
* TownBuildingInstance.h, part of VCMI engine
2023-04-26 20:55:56 +02:00
*
* 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
#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;
class CBuilding;
2023-04-26 20:55:56 +02:00
class DLL_LINKAGE TownBuildingInstance : public IObjectInterface
2023-04-26 20:55:56 +02:00
{
///basic class for town structures handled as map objects
public:
TownBuildingInstance(CGTownInstance * town, const BuildingID & index);
TownBuildingInstance(IGameCallback *cb);
2024-01-01 16:37:48 +02:00
CGTownInstance * town;
2023-04-26 20:55:56 +02:00
const BuildingID & getBuildingType() const
{
return bID;
}
PlayerColor getOwner() const override;
MapObjectID getObjGroupIndex() const override;
MapObjectSubID getObjTypeIndex() const override;
const IOwnableObject * asOwnable() const override;
2023-04-26 20:55:56 +02:00
int3 visitablePos() const override;
int3 anchorPos() const override;
2023-04-26 20:55:56 +02:00
template <typename Handler> void serialize(Handler &h)
2023-04-26 20:55:56 +02:00
{
h & bID;
if (h.version < Handler::Version::NEW_TOWN_BUILDINGS)
2024-08-16 14:57:38 +02:00
{
// compatibility code
2024-08-16 14:57:38 +02:00
si32 indexOnTV = 0; //identifies its index on towns vector
BuildingSubID::EBuildingSubID bType = BuildingSubID::NONE;
h & indexOnTV;
h & bType;
}
2023-04-26 20:55:56 +02:00
}
private:
2024-08-16 14:57:38 +02:00
BuildingID bID; //from building list
2023-04-26 20:55:56 +02:00
};
class DLL_LINKAGE TownRewardableBuildingInstance : public TownBuildingInstance, public Rewardable::Interface
2023-04-30 01:58:43 +02:00
{
/// reward selected by player, no serialize
ui16 selectedReward = 0;
std::set<ObjectInstanceID> visitors;
bool wasVisitedBefore(const CGHeroInstance * contextHero) const override;
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
Rewardable::Configuration generateConfiguration(vstd::RNG & rand) const;
const IObjectInterface * getObject() const override;
bool wasVisited(PlayerColor player) const override;
void markAsVisited(const CGHeroInstance * hero) const override;
void markAsScouted(const CGHeroInstance * hero) const override;
2023-04-30 01:58:43 +02:00
public:
void setProperty(ObjProperty what, ObjPropertyID identifier) override;
void onHeroVisit(const CGHeroInstance * h) const override;
bool wasVisited(const CGHeroInstance * contextHero) const override;
2023-04-30 01:58:43 +02:00
void newTurn(vstd::RNG & 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;
void initObj(vstd::RNG & rand) override;
2023-04-30 20:34:41 +02:00
/// applies player selection of reward
void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
2023-04-30 20:34:41 +02:00
TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
TownRewardableBuildingInstance(IGameCallback *cb);
2023-04-30 01:58:43 +02:00
template <typename Handler> void serialize(Handler &h)
2023-04-30 01:58:43 +02:00
{
h & static_cast<TownBuildingInstance&>(*this);
if (h.version >= Handler::Version::NEW_TOWN_BUILDINGS)
h & static_cast<Rewardable::Interface&>(*this);
h & visitors;
2023-04-30 01:58:43 +02:00
}
};
2023-04-26 20:55:56 +02:00
VCMI_LIB_NAMESPACE_END