123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- /*
- * MapFormatH3M.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 "CMapService.h"
- #include "../GameConstants.h"
- #include "../ResourceSet.h"
- #include "../int3.h"
- #include "../Filesystem/CBinaryReader.h"
- class CGHeroInstance;
- class CArtifactInstance;
- class CGObjectInstance;
- class CGSeerHut;
- class IQuestObject;
- class CGTownInstance;
- class CCreatureSet;
- class CInputStream;
- class DLL_LINKAGE CMapLoaderH3M : public IMapLoader
- {
- public:
- /**
- * Default constructor.
- *
- * @param stream a stream containing the map data
- */
- CMapLoaderH3M(CInputStream * stream);
- /**
- * Destructor.
- */
- ~CMapLoaderH3M();
- /**
- * Loads the VCMI/H3 map file.
- *
- * @return a unique ptr of the loaded map class
- */
- std::unique_ptr<CMap> loadMap();
- /**
- * Loads the VCMI/H3 map header.
- *
- * @return a unique ptr of the loaded map header class
- */
- std::unique_ptr<CMapHeader> loadMapHeader();
- /** true if you want to enable the map loader profiler to see how long a specific part took; default=false */
- static const bool IS_PROFILING_ENABLED;
- private:
- /**
- * Initializes the map object from parsing the input buffer.
- */
- void init();
- /**
- * Reads the map header.
- */
- void readHeader();
- /**
- * Reads player information.
- */
- void readPlayerInfo();
- /**
- * Reads victory/loss conditions.
- */
- void readVictoryLossConditions();
- /**
- * Reads team information.
- */
- void readTeamInfo();
- /**
- * Reads the list of allowed heroes.
- */
- void readAllowedHeroes();
- /**
- * Reads the list of disposed heroes.
- */
- void readDisposedHeroes();
- /**
- * Reads the list of allowed artifacts.
- */
- void readAllowedArtifacts();
- /**
- * Reads the list of allowed spells and abilities.
- */
- void readAllowedSpellsAbilities();
- /**
- * Loads artifacts of a hero.
- *
- * @param hero the hero which should hold those artifacts
- */
- void loadArtifactsOfHero(CGHeroInstance * hero);
- /**
- * Loads an artifact to the given slot of the specified hero.
- *
- * @param hero the hero which should hold that artifact
- * @param slot the artifact slot where to place that artifact
- * @return true if it loaded an artifact
- */
- bool loadArtifactToSlot(CGHeroInstance * hero, int slot);
- /**
- * Creates an artifact instance.
- *
- * @param aid the id of the artifact
- * @param spellID optional. the id of a spell if a spell scroll object should be created
- * @return the created artifact instance
- */
- CArtifactInstance * createArtifact(int aid, int spellID = -1);
- /**
- * Read rumors.
- */
- void readRumors();
- /**
- * Reads predefined heroes.
- */
- void readPredefinedHeroes();
- /**
- * Reads terrain data.
- */
- void readTerrain();
- /**
- * Reads custom(map) def information.
- */
- void readDefInfo();
- /**
- * Reads objects(towns, mines,...).
- */
- void readObjects();
- /**
- * Reads a creature set.
- *
- * @param out the loaded creature set
- * @param number the count of creatures to read
- */
- void readCreatureSet(CCreatureSet * out, int number);
- /**
- * Reads a hero.
- *
- * @param idToBeGiven the object id which should be set for the hero
- * @return a object instance
- */
- CGObjectInstance * readHero(ObjectInstanceID idToBeGiven);
- /**
- * Reads a seer hut.
- *
- * @return the initialized seer hut object
- */
- CGSeerHut * readSeerHut();
- /**
- * Reads a quest for the given quest guard.
- *
- * @param guard the quest guard where that quest should be applied to
- */
- void readQuest(IQuestObject * guard);
- /**
- * Reads a town.
- *
- * @param castleID the id of the castle type
- * @return the loaded town object
- */
- CGTownInstance * readTown(int castleID);
- /**
- * Converts buildings to the specified castle id.
- *
- * @param h3m the ids of the buildings
- * @param castleID the castle id
- * @param addAuxiliary true if the village hall should be added
- * @return the converted buildings
- */
- std::set<BuildingID> convertBuildings(const std::set<BuildingID> h3m, int castleID, bool addAuxiliary = true);
- /**
- * Reads events.
- */
- void readEvents();
- /**
- * read optional message and optional guards
- */
- void readMessageAndGuards(std::string& message, CCreatureSet * guards);
- void readSpells(std::set<SpellID> & dest);
- void readResourses(TResources& resources);
- template <class Indenifier>
- void readBitmask(std::set<Indenifier> &dest, const int byteCount, const int limit, bool negate = true);
- /** Reads bitmask to boolean vector
- * @param dest destination vector, shall be filed with "true" values
- * @param byteCount size in bytes of bimask
- * @param limit max count of vector elements to alter
- * @param negate if true then set bit in mask means clear flag in vertor
- */
- void readBitmask(std::vector<bool> & dest, const int byteCount, const int limit, bool negate = true);
- /**
- * Reverses the input argument.
- *
- * @param arg the input argument
- * @return the reversed 8-bit integer
- */
- ui8 reverse(ui8 arg);
- /**
- * Helper to read map position
- */
- inline int3 readInt3()
- {
- int3 p;
- p.x = reader.readUInt8();
- p.y = reader.readUInt8();
- p.z = reader.readUInt8();
- return p;
- }
- /** ptr to the map object which gets filled by data from the buffer */
- CMap * map;
- /**
- * ptr to the map header object which gets filled by data from the buffer.
- * (when loading a map then the mapHeader ptr points to the same object)
- */
- std::unique_ptr<CMapHeader> mapHeader;
- CBinaryReader reader;
- CInputStream * inputStream;
- };
|