/* * CMap.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 "CMapDefines.h" #include "CMapHeader.h" #include "../ConstTransitivePtr.h" #include "../GameCallbackHolder.h" #include "../networkPacks/TradeItem.h" VCMI_LIB_NAMESPACE_BEGIN class CArtifactInstance; class CArtifactSet; class CGObjectInstance; class CGHeroInstance; class CCommanderInstance; class CGCreature; class CQuest; class CGTownInstance; class IModableArt; class IQuestObject; class CInputStream; class CMapEditManager; class JsonSerializeFormat; class IGameSettings; class GameSettings; struct TeleportChannel; enum class EGameSettings; /// The rumor struct consists of a rumor name and text. struct DLL_LINKAGE Rumor { std::string name; MetaString text; Rumor() = default; ~Rumor() = default; template void serialize(Handler & h) { h & name; h & text; } void serializeJson(JsonSerializeFormat & handler); }; /// The disposed hero struct describes which hero can be hired from which player. struct DLL_LINKAGE DisposedHero { DisposedHero(); HeroTypeID heroId; HeroTypeID portrait; /// The portrait id of the hero, -1 is default. std::string name; std::set players; /// Who can hire this hero (bitfield). template void serialize(Handler & h) { h & heroId; h & portrait; h & name; h & players; } }; /// The map contains the map header, the tiles of the terrain, objects, heroes, towns, rumors... class DLL_LINKAGE CMap : public CMapHeader, public GameCallbackHolder { std::unique_ptr gameSettings; public: explicit CMap(IGameCallback *cb); ~CMap(); void initTerrain(); CMapEditManager * getEditManager(); TerrainTile & getTile(const int3 & tile); const TerrainTile & getTile(const int3 & tile) const; bool isCoastalTile(const int3 & pos) const; bool isWaterTile(const int3 & pos) const; inline bool isInTheMap(const int3 & pos) const { // Check whether coord < 0 is done implicitly. Negative signed int overflows to unsigned number larger than all signed ints. return static_cast(pos.x) < static_cast(width) && static_cast(pos.y) < static_cast(height) && static_cast(pos.z) <= (twoLevel ? 1 : 0); } bool canMoveBetween(const int3 &src, const int3 &dst) const; bool checkForVisitableDir(const int3 & src, const TerrainTile * pom, const int3 & dst) const; int3 guardingCreaturePosition (int3 pos) const; void addBlockVisTiles(CGObjectInstance * obj); void removeBlockVisTiles(CGObjectInstance * obj, bool total = false); void calculateGuardingGreaturePositions(); void addNewArtifactInstance(CArtifactSet & artSet); void addNewArtifactInstance(ConstTransitivePtr art); void eraseArtifactInstance(CArtifactInstance * art); void moveArtifactInstance(CArtifactSet & srcSet, const ArtifactPosition & srcSlot, CArtifactSet & dstSet, const ArtifactPosition & dstSlot); void putArtifactInstance(CArtifactSet & set, CArtifactInstance * art, const ArtifactPosition & slot); void removeArtifactInstance(CArtifactSet & set, const ArtifactPosition & slot); void addNewQuestInstance(CQuest * quest); void removeQuestInstance(CQuest * quest); void setUniqueInstanceName(CGObjectInstance * obj); ///Use only this method when creating new map object instances void addNewObject(CGObjectInstance * obj); void moveObject(CGObjectInstance * obj, const int3 & dst); void removeObject(CGObjectInstance * obj); bool isWaterMap() const; bool calculateWaterContent(); void banWaterArtifacts(); void banWaterHeroes(); void banHero(const HeroTypeID& id); void unbanHero(const HeroTypeID & id); void banWaterSpells(); void banWaterSkills(); void banWaterContent(); /// Gets object of specified type on requested position const CGObjectInstance * getObjectiveObjectFrom(const int3 & pos, Obj type); CGHeroInstance * getHero(HeroTypeID heroId); /// Sets the victory/loss condition objectives ?? void checkForObjectives(); void resetStaticData(); void resolveQuestIdentifiers(); void reindexObjects(); ui32 checksum; std::vector rumors; std::vector disposedHeroes; std::vector > predefinedHeroes; std::set allowedSpells; std::set allowedArtifact; std::set allowedAbilities; std::vector events; int3 grailPos; int grailRadius; //Central lists of items in game. Position of item in the vectors below is their (instance) id. std::vector< ConstTransitivePtr > objects; std::vector< ConstTransitivePtr > towns; std::vector< ConstTransitivePtr > artInstances; std::vector< ConstTransitivePtr > quests; std::vector< ConstTransitivePtr > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc. //Helper lists std::vector< ConstTransitivePtr > heroesOnMap; std::map > teleportChannels; /// associative list to identify which hero/creature id belongs to which object id(index for objects) std::map questIdentifierToId; std::unique_ptr editManager; boost::multi_array guardingCreaturePositions; std::map > instanceNames; bool waterMap; ui8 obeliskCount = 0; //how many obelisks are on map std::map obelisksVisited; //map: team_id => how many obelisks has been visited std::vector townMerchantArtifacts; std::vector townUniversitySkills; void overrideGameSettings(const JsonNode & input); void overrideGameSetting(EGameSettings option, const JsonNode & input); const IGameSettings & getSettings() const; private: /// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground boost::multi_array terrain; si32 uidCounter; //TODO: initialize when loading an old map public: template void serialize(Handler &h) { h & static_cast(*this); h & triggeredEvents; //from CMapHeader h & rumors; h & allowedSpells; h & allowedAbilities; h & allowedArtifact; h & events; h & grailPos; h & artInstances; h & quests; h & allHeroes; //TODO: viccondetails h & terrain; h & guardingCreaturePositions; h & objects; h & heroesOnMap; h & teleportChannels; h & towns; h & artInstances; // static members h & obeliskCount; h & obelisksVisited; if (h.version < Handler::Version::REMOVE_VLC_POINTERS) { int32_t size = 0; h & size; for (int32_t i = 0; i < size; ++i) { bool isNull = false; ArtifactID artifact; h & isNull; if (!isNull) h & artifact; townMerchantArtifacts.push_back(artifact); } } else { h & townMerchantArtifacts; } h & townUniversitySkills; h & instanceNames; if (h.version >= Handler::Version::PER_MAP_GAME_SETTINGS) h & *gameSettings; } }; VCMI_LIB_NAMESPACE_END