2023-04-26 20:55:56 +02:00
|
|
|
/*
|
2024-08-16 16:49:42 +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
|
|
|
|
|
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
|
|
|
|
2024-08-16 16:49:42 +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:
|
2024-08-16 16:49:42 +02:00
|
|
|
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;
|
2023-10-24 16:11:25 +02:00
|
|
|
MapObjectID getObjGroupIndex() const override;
|
|
|
|
MapObjectSubID getObjTypeIndex() const override;
|
2024-08-24 22:42:19 +02:00
|
|
|
const IOwnableObject * asOwnable() 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;
|
2024-08-16 16:49:42 +02:00
|
|
|
if (h.version < Handler::Version::NEW_TOWN_BUILDINGS)
|
2024-08-16 14:57:38 +02:00
|
|
|
{
|
2024-08-16 16:49:42 +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
|
|
|
};
|
|
|
|
|
2024-08-16 16:49:42 +02:00
|
|
|
class DLL_LINKAGE TownRewardableBuildingInstance : public TownBuildingInstance, public Rewardable::Interface
|
2023-04-30 01:58:43 +02:00
|
|
|
{
|
2023-04-30 03:29:34 +02:00
|
|
|
/// reward selected by player, no serialize
|
|
|
|
ui16 selectedReward = 0;
|
|
|
|
std::set<ObjectInstanceID> visitors;
|
2024-08-16 16:49:42 +02:00
|
|
|
|
2024-09-27 17:40:09 +02:00
|
|
|
bool wasVisitedBefore(const CGHeroInstance * contextHero) const override;
|
|
|
|
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
|
2024-07-12 17:10:03 +02:00
|
|
|
Rewardable::Configuration generateConfiguration(vstd::RNG & rand) const;
|
2024-08-16 16:49:42 +02:00
|
|
|
|
2024-09-27 17:40:09 +02:00
|
|
|
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:
|
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;
|
2024-09-16 21:51:10 +02:00
|
|
|
bool wasVisited(const CGHeroInstance * contextHero) const override;
|
2023-04-30 01:58:43 +02:00
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void newTurn(vstd::RNG & rand) const override;
|
2023-05-02 02:44:09 +02:00
|
|
|
|
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;
|
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void initObj(vstd::RNG & rand) override;
|
2023-05-02 02:44:09 +02:00
|
|
|
|
2023-04-30 20:34:41 +02:00
|
|
|
/// applies player selection of reward
|
2024-08-09 00:28:28 +02:00
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
|
2023-04-30 20:34:41 +02:00
|
|
|
|
2024-08-16 16:49:42 +02:00
|
|
|
TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
|
|
|
|
TownRewardableBuildingInstance(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
|
|
|
{
|
2024-08-16 16:49:42 +02:00
|
|
|
h & static_cast<TownBuildingInstance&>(*this);
|
|
|
|
if (h.version >= Handler::Version::NEW_TOWN_BUILDINGS)
|
|
|
|
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
|