/* * MiscObjects.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 #include "CArmedInstance.h" #include "../MetaString.h" VCMI_LIB_NAMESPACE_BEGIN class CMap; // This one teleport-specific, but has to be available everywhere in callbacks and netpacks // For now it's will be there till teleports code refactored and moved into own file using TTeleportExitsList = std::vector>; /// Legacy class, use CRewardableObject instead class DLL_LINKAGE CTeamVisited: public CGObjectInstance { public: using CGObjectInstance::CGObjectInstance; std::set players; //players that visited this object bool wasVisited (const CGHeroInstance * h) const override; bool wasVisited(PlayerColor player) const override; bool wasVisited(const TeamID & team) const; void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override; template void serialize(Handler &h) { h & static_cast(*this); h & players; } }; class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles { public: using CGObjectInstance::CGObjectInstance; MetaString message; void onHeroVisit(const CGHeroInstance * h) const override; void initObj(CRandomGenerator & rand) override; template void serialize(Handler &h) { h & static_cast(*this); h & message; } protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; class DLL_LINKAGE CGGarrison : public CArmedInstance { public: using CArmedInstance::CArmedInstance; bool removableUnits; void initObj(CRandomGenerator &rand) override; bool passableFor(PlayerColor color) const override; void onHeroVisit(const CGHeroInstance * h) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; template void serialize(Handler &h) { h & static_cast(*this); h & removableUnits; } protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; void addAntimagicGarrisonBonus(); }; class DLL_LINKAGE CGArtifact : public CArmedInstance { public: using CArmedInstance::CArmedInstance; CArtifactInstance * storedArtifact = nullptr; MetaString message; void onHeroVisit(const CGHeroInstance * h) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; std::string getObjectName() const override; std::string getPopupText(PlayerColor player) const override; std::string getPopupText(const CGHeroInstance * hero) const override; std::vector getPopupComponents(PlayerColor player) const override; void pick( const CGHeroInstance * h ) const; void initObj(CRandomGenerator & rand) override; void pickRandomObject(CRandomGenerator & rand) override; void afterAddToMap(CMap * map) override; BattleField getBattlefield() const override; ArtifactID getArtifact() const; template void serialize(Handler &h) { h & static_cast(*this); h & message; h & storedArtifact; } protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; class DLL_LINKAGE CGResource : public CArmedInstance { public: using CArmedInstance::CArmedInstance; static constexpr ui32 RANDOM_AMOUNT = 0; ui32 amount = RANDOM_AMOUNT; //0 if random MetaString message; void onHeroVisit(const CGHeroInstance * h) const override; void initObj(CRandomGenerator & rand) override; void pickRandomObject(CRandomGenerator & rand) override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; std::string getHoverText(PlayerColor player) const override; void collectRes(const PlayerColor & player) const; GameResID resourceID() const; template void serialize(Handler &h) { h & static_cast(*this); h & amount; h & message; } protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; class DLL_LINKAGE CGMine : public CArmedInstance { public: GameResID producedResource; ui32 producedQuantity; std::set abandonedMineResources; bool isAbandoned() const; ResourceSet dailyIncome() const; private: using CArmedInstance::CArmedInstance; void onHeroVisit(const CGHeroInstance * h) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void flagMine(const PlayerColor & player) const; void newTurn(CRandomGenerator & rand) const override; void initObj(CRandomGenerator & rand) override; std::string getObjectName() const override; std::string getHoverText(PlayerColor player) const override; public: template void serialize(Handler &h) { h & static_cast(*this); h & producedResource; h & producedQuantity; h & abandonedMineResources; } ui32 defaultResProduction() const; protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; struct DLL_LINKAGE TeleportChannel { enum EPassability {UNKNOWN, IMPASSABLE, PASSABLE}; std::vector entrances; std::vector exits; EPassability passability = EPassability::UNKNOWN; template void serialize(Handler &h) { h & entrances; h & exits; h & passability; } }; class DLL_LINKAGE CGTeleport : public CGObjectInstance { bool isChannelEntrance(const ObjectInstanceID & id) const; bool isChannelExit(const ObjectInstanceID & id) const; std::vector getAllEntrances(bool excludeCurrent = false) const; protected: enum EType {UNKNOWN, ENTRANCE, EXIT, BOTH}; EType type = EType::UNKNOWN; ObjectInstanceID getRandomExit(const CGHeroInstance * h) const; std::vector getAllExits(bool excludeCurrent = false) const; public: using CGObjectInstance::CGObjectInstance; TeleportChannelID channel; bool isEntrance() const; bool isExit() const; virtual void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const = 0; static bool isTeleport(const CGObjectInstance * dst); static bool isConnected(const CGTeleport * src, const CGTeleport * dst); static bool isConnected(const CGObjectInstance * src, const CGObjectInstance * dst); static void addToChannel(std::map > &channelsList, const CGTeleport * obj); static std::vector getPassableExits(CGameState * gs, const CGHeroInstance * h, std::vector exits); static bool isExitPassable(CGameState * gs, const CGHeroInstance * h, const CGObjectInstance * obj); template void serialize(Handler &h) { h & type; h & channel; h & static_cast(*this); } }; class DLL_LINKAGE CGMonolith : public CGTeleport { TeleportChannelID findMeChannel(const std::vector & IDs, MapObjectSubID SubID) const; protected: void onHeroVisit(const CGHeroInstance * h) const override; void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const override; void initObj(CRandomGenerator & rand) override; public: using CGTeleport::CGTeleport; template void serialize(Handler &h) { h & static_cast(*this); } }; class DLL_LINKAGE CGSubterraneanGate : public CGMonolith { void onHeroVisit(const CGHeroInstance * h) const override; void initObj(CRandomGenerator & rand) override; public: using CGMonolith::CGMonolith; static void postInit(IGameCallback * cb); template void serialize(Handler &h) { h & static_cast(*this); } }; class DLL_LINKAGE CGWhirlpool : public CGMonolith { void onHeroVisit(const CGHeroInstance * h) const override; void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const override; static bool isProtected( const CGHeroInstance * h ); public: using CGMonolith::CGMonolith; template void serialize(Handler &h) { h & static_cast(*this); } }; class DLL_LINKAGE CGSirens : public CGObjectInstance { public: using CGObjectInstance::CGObjectInstance; void onHeroVisit(const CGHeroInstance * h) const override; std::string getHoverText(const CGHeroInstance * hero) const override; void initObj(CRandomGenerator & rand) override; template void serialize(Handler &h) { h & static_cast(*this); } }; class DLL_LINKAGE CGBoat : public CGObjectInstance, public CBonusSystemNode { public: using CGObjectInstance::CGObjectInstance; ui8 direction; const CGHeroInstance *hero; //hero on board bool onboardAssaultAllowed; //if true, hero can attack units from transport bool onboardVisitAllowed; //if true, hero can visit objects from transport EPathfindingLayer layer; //animation filenames. If empty - animations won't be used AnimationPath actualAnimation; //for OH3 boats those have actual animations AnimationPath overlayAnimation; //waves animations std::array flagAnimations; CGBoat(IGameCallback * cb); bool isCoastVisitable() const override; template void serialize(Handler &h) { h & static_cast(*this); h & static_cast(*this); h & direction; h & hero; h & layer; h & onboardAssaultAllowed; h & onboardVisitAllowed; h & actualAnimation; h & overlayAnimation; h & flagAnimations; } }; class DLL_LINKAGE CGShipyard : public CGObjectInstance, public IShipyard { friend class ShipyardInstanceConstructor; BoatId createdBoat; protected: void getOutOffsets(std::vector & offsets) const override; void onHeroVisit(const CGHeroInstance * h) const override; const IObjectInterface * getObject() const override; BoatId getBoatType() const override; public: using CGObjectInstance::CGObjectInstance; template void serialize(Handler & h) { h & static_cast(*this); h & createdBoat; } protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; class DLL_LINKAGE CGMagi : public CGObjectInstance { public: using CGObjectInstance::CGObjectInstance; void initObj(CRandomGenerator & rand) override; void onHeroVisit(const CGHeroInstance * h) const override; template void serialize(Handler &h) { h & static_cast(*this); } }; class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance { void onHeroVisit(const CGHeroInstance * h) const override; public: using CGObjectInstance::CGObjectInstance; }; class DLL_LINKAGE CGObelisk : public CTeamVisited { public: using CTeamVisited::CTeamVisited; void onHeroVisit(const CGHeroInstance * h) const override; void initObj(CRandomGenerator & rand) override; std::string getHoverText(PlayerColor player) const override; template void serialize(Handler &h) { h & static_cast(*this); } protected: void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override; }; class DLL_LINKAGE CGLighthouse : public CGObjectInstance { public: using CGObjectInstance::CGObjectInstance; void onHeroVisit(const CGHeroInstance * h) const override; void initObj(CRandomGenerator & rand) override; template void serialize(Handler &h) { h & static_cast(*this); } void giveBonusTo(const PlayerColor & player, bool onInit = false) const; protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; class DLL_LINKAGE CGTerrainPatch : public CGObjectInstance { public: using CGObjectInstance::CGObjectInstance; bool isTile2Terrain() const override { return true; } }; class DLL_LINKAGE HillFort : public CGObjectInstance, public ICreatureUpgrader { friend class HillFortInstanceConstructor; std::vector upgradeCostPercentage; protected: void onHeroVisit(const CGHeroInstance * h) const override; void fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const override; public: using CGObjectInstance::CGObjectInstance; template void serialize(Handler &h) { h & static_cast(*this); h & upgradeCostPercentage; } }; VCMI_LIB_NAMESPACE_END