2013-02-04 13:29:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
2013-02-05 00:58:42 +03:00
|
|
|
#include "../GameConstants.h"
|
|
|
|
#include "../ResourceSet.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
#include "../mapObjects/CObjectClassesHandler.h"
|
2013-02-04 13:29:59 +03:00
|
|
|
|
|
|
|
#include "../int3.h"
|
|
|
|
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../filesystem/CBinaryReader.h"
|
2013-02-07 20:02:15 +03:00
|
|
|
|
2013-02-04 13:29:59 +03:00
|
|
|
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
|
|
|
|
*/
|
2013-02-05 00:58:42 +03:00
|
|
|
void readCreatureSet(CCreatureSet * out, int number);
|
2013-02-04 13:29:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a hero.
|
|
|
|
*
|
|
|
|
* @param idToBeGiven the object id which should be set for the hero
|
|
|
|
* @return a object instance
|
|
|
|
*/
|
2013-02-14 02:55:42 +03:00
|
|
|
CGObjectInstance * readHero(ObjectInstanceID idToBeGiven);
|
2013-02-04 13:29:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-02-11 22:11:34 +03:00
|
|
|
std::set<BuildingID> convertBuildings(const std::set<BuildingID> h3m, int castleID, bool addAuxiliary = true);
|
2013-02-04 13:29:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads events.
|
|
|
|
*/
|
|
|
|
void readEvents();
|
|
|
|
|
2013-02-07 20:02:15 +03:00
|
|
|
/**
|
|
|
|
* read optional message and optional guards
|
|
|
|
*/
|
|
|
|
void readMessageAndGuards(std::string& message, CCreatureSet * guards);
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void readSpells(std::set<SpellID> & dest);
|
2013-02-05 00:58:42 +03:00
|
|
|
|
|
|
|
void readResourses(TResources& resources);
|
|
|
|
|
2013-02-07 20:02:15 +03:00
|
|
|
template <class Indenifier>
|
|
|
|
void readBitmask(std::set<Indenifier> &dest, const int byteCount, const int limit, bool negate = true);
|
|
|
|
|
2013-02-05 00:58:42 +03:00
|
|
|
/** 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);
|
|
|
|
|
2013-02-04 13:29:59 +03:00
|
|
|
/**
|
|
|
|
* Reverses the input argument.
|
|
|
|
*
|
|
|
|
* @param arg the input argument
|
|
|
|
* @return the reversed 8-bit integer
|
|
|
|
*/
|
|
|
|
ui8 reverse(ui8 arg);
|
|
|
|
|
|
|
|
/**
|
2013-02-07 20:02:15 +03:00
|
|
|
* Helper to read map position
|
2013-02-04 13:29:59 +03:00
|
|
|
*/
|
|
|
|
inline int3 readInt3()
|
|
|
|
{
|
|
|
|
int3 p;
|
2013-02-07 20:02:15 +03:00
|
|
|
p.x = reader.readUInt8();
|
|
|
|
p.y = reader.readUInt8();
|
|
|
|
p.z = reader.readUInt8();
|
2013-02-04 13:29:59 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
/** List of templates loaded from the map, used on later stage to create
|
|
|
|
* objects but not needed for fully functional CMap */
|
|
|
|
std::vector<ObjectTemplate> templates;
|
|
|
|
|
2013-02-04 13:29:59 +03:00
|
|
|
/** 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;
|
|
|
|
|
2013-02-07 20:02:15 +03:00
|
|
|
CBinaryReader reader;
|
|
|
|
CInputStream * inputStream;
|
2013-02-04 13:29:59 +03:00
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
};
|