2012-11-21 12:13:33 +03:00
|
|
|
#include "StdInc.h"
|
2012-11-03 16:30:47 +03:00
|
|
|
#include "CMapService.h"
|
2012-11-20 20:53:45 +03:00
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
#include "../Filesystem/CResourceLoader.h"
|
|
|
|
#include "../Filesystem/CBinaryReader.h"
|
|
|
|
#include "../Filesystem/CCompressedStream.h"
|
|
|
|
#include "../Filesystem/CMemoryStream.h"
|
|
|
|
#include "CMap.h"
|
|
|
|
#include <boost/crc.hpp>
|
2013-02-02 20:20:31 +03:00
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
#include "../CStopWatch.h"
|
|
|
|
#include "../VCMI_Lib.h"
|
|
|
|
#include "../CSpellHandler.h"
|
|
|
|
#include "../CCreatureHandler.h"
|
2012-12-17 15:55:29 +03:00
|
|
|
#include "../CHeroHandler.h"
|
2012-11-03 17:29:54 +03:00
|
|
|
#include "../CObjectHandler.h"
|
|
|
|
#include "../CDefObjInfoHandler.h"
|
2012-11-03 16:30:47 +03:00
|
|
|
|
|
|
|
std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
auto stream = getStreamFromFS(name);
|
|
|
|
return getMapLoader(stream)->loadMap();
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
auto stream = getStreamFromFS(name);
|
|
|
|
return getMapLoader(stream)->loadMapHeader();
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
auto stream = getStreamFromMem(buffer, size);
|
|
|
|
return getMapLoader(stream)->loadMap();
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int size)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
auto stream = getStreamFromMem(buffer, size);
|
|
|
|
return getMapLoader(stream)->loadMapHeader();
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
return CResourceHandler::get()->load(ResourceID(name, EResType::MAP));
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CInputStream> CMapService::getStreamFromMem(const ui8 * buffer, int size)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
return std::unique_ptr<CInputStream>(new CMemoryStream(buffer, size));
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStream> & stream)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Read map header
|
|
|
|
CBinaryReader reader(stream.get());
|
|
|
|
ui32 header = reader.readUInt32();
|
|
|
|
reader.getStream()->seek(0);
|
|
|
|
|
|
|
|
// Check which map format is used
|
|
|
|
// gzip header is 3 bytes only in size
|
|
|
|
switch(header & 0xffffff)
|
|
|
|
{
|
|
|
|
// gzip header magic number, reversed for LE
|
|
|
|
case 0x00088B1F:
|
|
|
|
stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
|
|
|
|
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
|
|
|
case EMapFormat::WOG :
|
|
|
|
case EMapFormat::AB :
|
|
|
|
case EMapFormat::ROE :
|
|
|
|
case EMapFormat::SOD :
|
|
|
|
return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
|
|
|
|
default :
|
|
|
|
throw std::runtime_error("Unknown map format");
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool CMapLoaderH3M::IS_PROFILING_ENABLED = false;
|
|
|
|
|
2012-11-03 22:31:16 +03:00
|
|
|
CMapLoaderH3M::CMapLoaderH3M(CInputStream * stream) : map(nullptr), buffer(nullptr), pos(-1), size(-1)
|
2012-11-03 16:30:47 +03:00
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
initBuffer(stream);
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMapLoaderH3M::~CMapLoaderH3M()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
delete buffer;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::initBuffer(CInputStream * stream)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Read map data into memory completely
|
|
|
|
// TODO Replace with CBinaryReader later... (no need for reading whole
|
|
|
|
// file in memory at once, storing pos & size separately...)
|
|
|
|
stream->seek(0);
|
|
|
|
size = stream->getSize();
|
|
|
|
buffer = new ui8[size];
|
|
|
|
stream->read(buffer, size);
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CMap> CMapLoaderH3M::loadMap()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Init map object by parsing the input buffer
|
2012-11-13 21:01:31 +03:00
|
|
|
map = new CMap();
|
2012-11-11 15:23:31 +03:00
|
|
|
mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
|
|
|
|
init();
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CMapHeader> CMapLoaderH3M::loadMapHeader()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Read header
|
2013-01-20 17:43:58 +03:00
|
|
|
mapHeader = make_unique<CMapHeader>();
|
2012-11-11 15:23:31 +03:00
|
|
|
readHeader();
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
return std::move(mapHeader);
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::init()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Compute checksum
|
|
|
|
boost::crc_32_type result;
|
|
|
|
result.process_bytes(buffer, size);
|
|
|
|
map->checksum = result.checksum();
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
CStopWatch sw;
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
struct MapLoadingTime
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
si64 time;
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
MapLoadingTime(std::string name, si64 time) : name(name),
|
|
|
|
time(time)
|
|
|
|
{
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
std::vector<MapLoadingTime> times;
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readHeader();
|
|
|
|
times.push_back(MapLoadingTime("header", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readDisposedHeroes();
|
|
|
|
times.push_back(MapLoadingTime("disposed heroes", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readAllowedArtifacts();
|
|
|
|
times.push_back(MapLoadingTime("allowed artifacts", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readAllowedSpellsAbilities();
|
|
|
|
times.push_back(MapLoadingTime("allowed spells and abilities", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readRumors();
|
|
|
|
times.push_back(MapLoadingTime("rumors", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readPredefinedHeroes();
|
|
|
|
times.push_back(MapLoadingTime("predefined heroes", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readTerrain();
|
|
|
|
times.push_back(MapLoadingTime("terrain", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readDefInfo();
|
|
|
|
times.push_back(MapLoadingTime("def info", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readObjects();
|
|
|
|
times.push_back(MapLoadingTime("objects", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
readEvents();
|
|
|
|
times.push_back(MapLoadingTime("events", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
// Calculate blocked / visitable positions
|
|
|
|
for(int f = 0; f < map->objects.size(); ++f)
|
|
|
|
{
|
|
|
|
if(!map->objects[f]->defInfo) continue;
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addBlockVisTiles(map->objects[f]);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
times.push_back(MapLoadingTime("blocked/visitable tiles", sw.getDiff()));
|
2012-11-03 16:30:47 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
// Print profiling times
|
|
|
|
if(IS_PROFILING_ENABLED)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(MapLoadingTime & mlt, times)
|
|
|
|
{
|
|
|
|
tlog0 << "\tReading " << mlt.name << " took " << mlt.time << " ms." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readHeader()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
// Check map for validity
|
|
|
|
if(size < 50 || !buffer[4])
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Corrupted map file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map version
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->version = (EMapFormat::EMapFormat)(readUI32());
|
2012-11-11 15:23:31 +03:00
|
|
|
if(mapHeader->version != EMapFormat::ROE && mapHeader->version != EMapFormat::AB && mapHeader->version != EMapFormat::SOD
|
|
|
|
&& mapHeader->version != EMapFormat::WOG)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Invalid map format!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read map name, description, dimensions,...
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->areAnyPlayers = readBool();
|
|
|
|
mapHeader->height = mapHeader->width = readUI32();
|
|
|
|
mapHeader->twoLevel = readBool();
|
|
|
|
mapHeader->name = readString();
|
|
|
|
mapHeader->description = readString();
|
|
|
|
mapHeader->difficulty = readSI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(mapHeader->version != EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->levelLimit = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapHeader->levelLimit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
readPlayerInfo();
|
|
|
|
readVictoryLossConditions();
|
|
|
|
readTeamInfo();
|
|
|
|
readAllowedHeroes();
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readPlayerInfo()
|
|
|
|
{
|
2013-01-06 22:30:12 +03:00
|
|
|
for(int i = 0; i < mapHeader->players.size(); ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].canHumanPlay = readBool();
|
|
|
|
mapHeader->players[i].canComputerPlay = readBool();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// If nobody can play with this player
|
|
|
|
if((!(mapHeader->players[i].canHumanPlay || mapHeader->players[i].canComputerPlay)))
|
|
|
|
{
|
|
|
|
switch(mapHeader->version)
|
|
|
|
{
|
|
|
|
case EMapFormat::SOD:
|
|
|
|
case EMapFormat::WOG:
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(13);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
case EMapFormat::AB:
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(12);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
case EMapFormat::ROE:
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(6);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].aiTactic = static_cast<EAiTactic::EAiTactic>(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
if(mapHeader->version == EMapFormat::SOD || mapHeader->version == EMapFormat::WOG)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].p7 = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapHeader->players[i].p7 = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Factions this player can choose
|
2013-02-02 20:20:31 +03:00
|
|
|
ui16 allowedFactions = readUI8();
|
2012-12-17 15:55:29 +03:00
|
|
|
// How many factions will be read from map
|
|
|
|
ui16 totalFactions = GameConstants::F_NUMBER;
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
if(mapHeader->version != EMapFormat::ROE)
|
2013-02-02 20:20:31 +03:00
|
|
|
allowedFactions += readUI8() * 256;
|
2012-12-17 15:55:29 +03:00
|
|
|
else
|
|
|
|
totalFactions--; //exclude conflux for ROE
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2012-12-17 15:55:29 +03:00
|
|
|
for(int fact = 0; fact < totalFactions; ++fact)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-17 15:55:29 +03:00
|
|
|
if(!(allowedFactions & (1 << fact)))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-17 15:55:29 +03:00
|
|
|
mapHeader->players[i].allowedFactions.erase(fact);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].isFactionRandom = readBool();
|
|
|
|
mapHeader->players[i].hasMainTown = readBool();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(mapHeader->players[i].hasMainTown)
|
|
|
|
{
|
|
|
|
if(mapHeader->version != EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].generateHeroAtMainTown = readBool();
|
|
|
|
mapHeader->players[i].generateHero = readBool();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapHeader->players[i].generateHeroAtMainTown = true;
|
|
|
|
mapHeader->players[i].generateHero = false;
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].posOfMainTown.x = readUI8();
|
|
|
|
mapHeader->players[i].posOfMainTown.y = readUI8();
|
|
|
|
mapHeader->players[i].posOfMainTown.z = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].hasHero = readBool();
|
|
|
|
mapHeader->players[i].customHeroID = readUI8();
|
2012-12-10 17:28:27 +03:00
|
|
|
|
|
|
|
if(mapHeader->players[i].customHeroID != 0xff)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].mainHeroPortrait = readUI8();
|
2012-12-10 17:28:27 +03:00
|
|
|
if (mapHeader->players[i].mainHeroPortrait == 0xff)
|
|
|
|
mapHeader->players[i].mainHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].mainHeroName = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2012-12-10 17:28:27 +03:00
|
|
|
else
|
|
|
|
mapHeader->players[i].customHeroID = -1; //correct 1-byte -1 (0xff) into 4-byte -1
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
if(mapHeader->version != EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].powerPlaceholders = readUI8(); //unknown byte
|
|
|
|
int heroCount = readUI8();
|
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int pp = 0; pp < heroCount; ++pp)
|
|
|
|
{
|
|
|
|
SHeroName vv;
|
2013-02-02 20:20:31 +03:00
|
|
|
vv.heroId = readUI8();
|
|
|
|
vv.heroName = readString();
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
mapHeader->players[i].heroesNames.push_back(vv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readVictoryLossConditions()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
mapHeader->victoryCondition.obj = nullptr;
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.condition = (EVictoryConditionType::EVictoryConditionType)readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// Specific victory conditions
|
|
|
|
if(mapHeader->victoryCondition.condition != EVictoryConditionType::WINSTANDARD)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.allowNormalVictory = readBool();
|
|
|
|
mapHeader->victoryCondition.appliesToAI = readBool();
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
// Read victory conditions
|
2013-02-02 20:20:31 +03:00
|
|
|
// int nr = 0;
|
2012-11-11 15:23:31 +03:00
|
|
|
switch(mapHeader->victoryCondition.condition)
|
|
|
|
{
|
|
|
|
case EVictoryConditionType::ARTIFACT:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.objectId = readUI8();
|
|
|
|
if (mapHeader->version != EMapFormat::ROE)
|
|
|
|
skip(1);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::GATHERTROOP:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.objectId = readUI8();
|
|
|
|
if (mapHeader->version != EMapFormat::ROE)
|
|
|
|
skip(1);
|
|
|
|
mapHeader->victoryCondition.count = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::GATHERRESOURCE:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.objectId = readUI8();
|
|
|
|
mapHeader->victoryCondition.count = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::BUILDCITY:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.pos.x = readUI8();
|
|
|
|
mapHeader->victoryCondition.pos.y = readUI8();
|
|
|
|
mapHeader->victoryCondition.pos.z = readUI8();
|
|
|
|
mapHeader->victoryCondition.count = readUI8();
|
|
|
|
mapHeader->victoryCondition.objectId = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::BUILDGRAIL:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int3 p = readInt3();
|
|
|
|
if(p.z > 2)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
p = int3(-1,-1,-1);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.pos = p;
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::BEATHERO:
|
|
|
|
case EVictoryConditionType::CAPTURECITY:
|
|
|
|
case EVictoryConditionType::BEATMONSTER:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int3 p = readInt3();
|
|
|
|
mapHeader->victoryCondition.pos = p;
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::TAKEDWELLINGS:
|
|
|
|
case EVictoryConditionType::TAKEMINES:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVictoryConditionType::TRANSPORTITEM:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->victoryCondition.objectId = readUI8();
|
|
|
|
int3 p = readInt3();
|
|
|
|
mapHeader->victoryCondition.pos = p;
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read loss conditions
|
|
|
|
mapHeader->lossCondition.typeOfLossCon = (ELossConditionType::ELossConditionType)buffer[pos++];
|
|
|
|
switch(mapHeader->lossCondition.typeOfLossCon)
|
|
|
|
{
|
|
|
|
case ELossConditionType::LOSSCASTLE:
|
|
|
|
case ELossConditionType::LOSSHERO:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int3 p = readInt3();
|
|
|
|
mapHeader->lossCondition.pos = p;
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ELossConditionType::TIMEEXPIRES:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->lossCondition.timeLimit = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readTeamInfo()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->howManyTeams = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(mapHeader->howManyTeams > 0)
|
|
|
|
{
|
|
|
|
// Teams
|
|
|
|
for(int i = 0; i < 8; ++i)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->players[i].team = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No alliances
|
|
|
|
for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
|
|
|
|
{
|
|
|
|
if(mapHeader->players[i].canComputerPlay || mapHeader->players[i].canHumanPlay)
|
|
|
|
{
|
|
|
|
mapHeader->players[i].team = mapHeader->howManyTeams++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readAllowedHeroes()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int lim = mapHeader->version == EMapFormat::ROE ? 16 : 20;
|
|
|
|
|
2012-12-17 15:55:29 +03:00
|
|
|
mapHeader->allowedHeroes.resize(VLC->heroh->heroes.size(), true);
|
2013-02-02 20:20:31 +03:00
|
|
|
|
|
|
|
for(int i = 0; i<lim; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::HEROES_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-17 15:55:29 +03:00
|
|
|
if(c != (c | static_cast<ui8>(std::pow(2., yy))))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->allowedHeroes[i * 8 + yy] = false;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probably reserved for further heroes
|
|
|
|
if(mapHeader->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int placeholdersQty = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int p = 0; p < placeholdersQty; ++p)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
mapHeader->placeholdedHeroes.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readDisposedHeroes()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Reading disposed heroes (20 bytes)
|
|
|
|
ui8 disp = 0;
|
|
|
|
if(map->version >= EMapFormat::SOD)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
disp = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
map->disposedHeroes.resize(disp);
|
|
|
|
for(int g = 0; g < disp; ++g)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
map->disposedHeroes[g].heroId = readUI8();
|
|
|
|
map->disposedHeroes[g].portrait = readUI8();
|
|
|
|
map->disposedHeroes[g].name = readString();
|
|
|
|
map->disposedHeroes[g].players = readUI8();;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//omitting NULLS
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(31);
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readAllowedArtifacts()
|
|
|
|
{
|
2012-12-14 11:37:46 +03:00
|
|
|
map->allowedArtifact.resize (VLC->arth->artifacts.size()); //handle new artifacts, make them allowed by default
|
|
|
|
for (ui32 x = 0; x < map->allowedArtifact.size(); ++x)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
map->allowedArtifact[x] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reading allowed artifacts: 17 or 18 bytes
|
|
|
|
if(map->version != EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int lim = map->version == EMapFormat::AB ? 17 : 18;
|
|
|
|
|
|
|
|
for(int i = 0; i < lim; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::ARTIFACTS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
map->allowedArtifact[i * 8 + yy] = false;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ban combo artifacts
|
|
|
|
if (map->version == EMapFormat::ROE || map->version == EMapFormat::AB)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(CArtifact * artifact, VLC->arth->artifacts)
|
|
|
|
{
|
|
|
|
// combo
|
|
|
|
if (artifact->constituents)
|
|
|
|
{
|
|
|
|
map->allowedArtifact[artifact->id] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (map->version == EMapFormat::ROE)
|
|
|
|
{
|
|
|
|
// Armageddon's Blade
|
|
|
|
map->allowedArtifact[128] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Messy, but needed
|
|
|
|
if(map->victoryCondition.condition == EVictoryConditionType::ARTIFACT
|
|
|
|
|| map->victoryCondition.condition == EVictoryConditionType::TRANSPORTITEM)
|
|
|
|
{
|
|
|
|
map->allowedArtifact[map->victoryCondition.objectId] = false;
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readAllowedSpellsAbilities()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
// Read allowed spells
|
|
|
|
map->allowedSpell.resize(GameConstants::SPELLS_QUANTITY);
|
|
|
|
for(ui32 x = 0; x < map->allowedSpell.size(); x++)
|
|
|
|
{
|
|
|
|
map->allowedSpell[x] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read allowed abilities
|
|
|
|
map->allowedAbilities.resize(GameConstants::SKILL_QUANTITY);
|
|
|
|
for(ui32 x = 0; x < map->allowedAbilities.size(); x++)
|
|
|
|
{
|
|
|
|
map->allowedAbilities[x] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version >= EMapFormat::SOD)
|
|
|
|
{
|
|
|
|
// Reading allowed spells (9 bytes)
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 9; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
map->allowedSpell[i* 8 + yy] = false;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allowed hero's abilities (4 bytes)
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 4; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SKILL_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
map->allowedAbilities[i * 8 + yy] = false;
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readRumors()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int rumNr = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
for(int it = 0; it < rumNr; it++)
|
|
|
|
{
|
|
|
|
Rumor ourRumor;
|
2013-02-02 20:20:31 +03:00
|
|
|
ourRumor.name = readString();
|
|
|
|
ourRumor.text = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
map->rumors.push_back(ourRumor);
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readPredefinedHeroes()
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
switch(map->version)
|
|
|
|
{
|
|
|
|
case EMapFormat::WOG:
|
|
|
|
case EMapFormat::SOD:
|
|
|
|
{
|
|
|
|
// Disposed heroes
|
|
|
|
for(int z = 0; z < GameConstants::HEROES_QUANTITY; z++)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int custom = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(!custom) continue;
|
|
|
|
|
2012-11-13 21:01:31 +03:00
|
|
|
CGHeroInstance * hero = new CGHeroInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
hero->ID = Obj::HERO;
|
|
|
|
hero->subID = z;
|
|
|
|
|
|
|
|
// True if hore's experience is greater than 0
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->exp = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hero->exp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// True if hero has specified abilities
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int howMany = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
hero->secSkills.resize(howMany);
|
|
|
|
for(int yy = 0; yy < howMany; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->secSkills[yy].first = readUI8();
|
|
|
|
hero->secSkills[yy].second = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loadArtifactsOfHero(hero);
|
|
|
|
|
|
|
|
// custom bio
|
|
|
|
if(readChar(buffer, pos))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->biography = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 0xFF is default, 00 male, 01 female
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->sex = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// are spells
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 9; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->spells.insert(i * 8 + yy);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// customPrimSkills
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; xx++)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hero->pushPrimSkill(xx, readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
map->predefinedHeroes.push_back(hero);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EMapFormat::ROE:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
bool artSet = readBool();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// True if artifact set is not default (hero has some artifacts)
|
|
|
|
if(artSet)
|
|
|
|
{
|
|
|
|
for(int pom = 0; pom < 16; pom++)
|
|
|
|
{
|
|
|
|
loadArtifactToSlot(hero, pom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// misc5 art //17
|
|
|
|
if(map->version >= EMapFormat::SOD)
|
|
|
|
{
|
|
|
|
if(!loadArtifactToSlot(hero, ArtifactPosition::MACH4))
|
|
|
|
{
|
|
|
|
// catapult by default
|
|
|
|
hero->putArtifact(ArtifactPosition::MACH4, createArtifact(GameConstants::ID_CATAPULT));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loadArtifactToSlot(hero, ArtifactPosition::SPELLBOOK);
|
|
|
|
|
|
|
|
// 19 //???what is that? gap in file or what? - it's probably fifth slot..
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
|
|
|
loadArtifactToSlot(hero, ArtifactPosition::MISC5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(1);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// bag artifacts //20
|
|
|
|
// number of artifacts in hero's bag
|
2013-02-02 20:20:31 +03:00
|
|
|
int amount = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int ss = 0; ss < amount; ++ss)
|
|
|
|
{
|
|
|
|
loadArtifactToSlot(hero, GameConstants::BACKPACK_START + hero->artifactsInBackpack.size());
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
const int artmask = map->version == EMapFormat::ROE ? 0xff : 0xffff;
|
|
|
|
int aid;
|
|
|
|
|
|
|
|
if(map->version == EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
aid = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
aid = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isArt = aid != artmask;
|
|
|
|
if(isArt)
|
|
|
|
{
|
|
|
|
if(vstd::contains(VLC->arth->bigArtifacts, aid) && slot >= GameConstants::BACKPACK_START)
|
|
|
|
{
|
|
|
|
tlog3 << "Warning: A big artifact (war machine) in hero's backpack, ignoring..." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(aid == 0 && slot == ArtifactPosition::MISC5)
|
|
|
|
{
|
|
|
|
//TODO: check how H3 handles it -> art 0 in slot 18 in AB map
|
|
|
|
tlog3 << "Spellbook to MISC5 slot? Putting it spellbook place. AB format peculiarity ? (format "
|
|
|
|
<< static_cast<int>(map->version) << ")" << std::endl;
|
|
|
|
slot = ArtifactPosition::SPELLBOOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hero->putArtifact(slot, createArtifact(aid));
|
|
|
|
}
|
|
|
|
|
|
|
|
return isArt;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CArtifactInstance * CMapLoaderH3M::createArtifact(int aid, int spellID /*= -1*/)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
CArtifactInstance * a = nullptr;
|
|
|
|
if(aid >= 0)
|
|
|
|
{
|
|
|
|
if(spellID < 0)
|
|
|
|
{
|
|
|
|
a = CArtifactInstance::createNewArtifactInstance(aid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a = CArtifactInstance::createScroll(VLC->spellh->spells[spellID]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
a = new CArtifactInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addNewArtifactInstance(a);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
//TODO make it nicer
|
|
|
|
if(a->artType && a->artType->constituents)
|
|
|
|
{
|
|
|
|
CCombinedArtifactInstance * comb = dynamic_cast<CCombinedArtifactInstance *>(a);
|
|
|
|
BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo & ci, comb->constituentsInfo)
|
|
|
|
{
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addNewArtifactInstance(ci.art);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return a;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readTerrain()
|
|
|
|
{
|
2013-01-06 22:30:12 +03:00
|
|
|
map->initTerrain();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// Read terrain
|
|
|
|
for(int a = 0; a < 2; ++a)
|
|
|
|
{
|
|
|
|
if(a == 1 && !map->twoLevel)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int c = 0; c < map->width; c++)
|
|
|
|
{
|
|
|
|
for(int z = 0; z < map->height; z++)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
map->terrain[z][c][a].terType = static_cast<ETerrainType::ETerrainType>(readUI8());
|
|
|
|
map->terrain[z][c][a].terView = readUI8();
|
|
|
|
map->terrain[z][c][a].riverType = static_cast<ERiverType::ERiverType>(readUI8());
|
|
|
|
map->terrain[z][c][a].riverDir = readUI8();
|
|
|
|
map->terrain[z][c][a].roadType = static_cast<ERoadType::ERoadType>(readUI8());
|
|
|
|
map->terrain[z][c][a].roadDir = readUI8();
|
|
|
|
map->terrain[z][c][a].extTileFlags = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
map->terrain[z][c][a].blocked = (map->terrain[z][c][a].terType == ETerrainType::ROCK ? 1 : 0); //underground tiles are always blocked
|
|
|
|
map->terrain[z][c][a].visitable = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readDefInfo()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int defAmount = readUI32();
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
map->customDefs.reserve(defAmount + 8);
|
|
|
|
|
|
|
|
// Read custom defs
|
|
|
|
for(int idd = 0; idd < defAmount; ++idd)
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGDefInfo * defInfo = new CGDefInfo();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
defInfo->name = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
std::transform(defInfo->name.begin(),defInfo->name.end(),defInfo->name.begin(),(int(*)(int))toupper);
|
|
|
|
|
|
|
|
ui8 bytes[12];
|
|
|
|
for(int v = 0; v < 12; ++v)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
bytes[v] = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
defInfo->terrainAllowed = readUI16();
|
|
|
|
defInfo->terrainMenu = readUI16();
|
|
|
|
defInfo->id = readUI32();
|
|
|
|
defInfo->subid = readUI32();
|
|
|
|
defInfo->type = readUI8();
|
|
|
|
defInfo->printPriority = readUI8();
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int zi = 0; zi < 6; ++zi)
|
|
|
|
{
|
|
|
|
defInfo->blockMap[zi] = reverse(bytes[zi]);
|
|
|
|
}
|
|
|
|
for(int zi = 0; zi < 6; ++zi)
|
|
|
|
{
|
|
|
|
defInfo->visitMap[zi] = reverse(bytes[6 + zi]);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
|
|
|
|
skip(16);
|
2013-01-15 17:20:48 +03:00
|
|
|
if(defInfo->id != Obj::HERO && defInfo->id != Obj::RANDOM_HERO)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
CGDefInfo * h = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid];
|
|
|
|
if(!h)
|
|
|
|
{
|
|
|
|
//remove fake entry
|
|
|
|
VLC->dobjinfo->gobjs[defInfo->id].erase(defInfo->subid);
|
|
|
|
if(VLC->dobjinfo->gobjs[defInfo->id].size())
|
|
|
|
{
|
|
|
|
VLC->dobjinfo->gobjs.erase(defInfo->id);
|
|
|
|
}
|
|
|
|
tlog2 << "\t\tWarning: no defobjinfo entry for object ID="
|
|
|
|
<< defInfo->id << " subID=" << defInfo->subid << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defInfo->visitDir = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid]->visitDir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defInfo->visitDir = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defInfo->id == Obj::EVENT)
|
|
|
|
{
|
|
|
|
std::memset(defInfo->blockMap, 255, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
//calculating coverageMap
|
|
|
|
defInfo->fetchInfoFromMSK();
|
|
|
|
|
|
|
|
map->customDefs.push_back(defInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
//add holes - they always can appear
|
|
|
|
for(int i = 0; i < 8 ; ++i)
|
|
|
|
{
|
2013-01-13 15:40:24 +03:00
|
|
|
map->customDefs.push_back(VLC->dobjinfo->gobjs[Obj::HOLE][i]);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readObjects()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int howManyObjs = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
for(int ww = 0; ww < howManyObjs; ++ww)
|
|
|
|
{
|
|
|
|
CGObjectInstance * nobj = 0;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int3 objPos = readInt3();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int defnum = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
int idToBeGiven = map->objects.size();
|
|
|
|
|
|
|
|
CGDefInfo * defInfo = map->customDefs.at(defnum);
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(5);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
switch(defInfo->id)
|
|
|
|
{
|
|
|
|
case Obj::EVENT:
|
|
|
|
{
|
|
|
|
CGEvent * evnt = new CGEvent();
|
|
|
|
nobj = evnt;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->message = readString();
|
|
|
|
|
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(evnt, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->gainedExp = readUI32();
|
|
|
|
evnt->manaDiff = readUI32();
|
|
|
|
evnt->moraleDiff = readSI8();
|
|
|
|
evnt->luckDiff = readSI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
evnt->resources.resize(GameConstants::RESOURCE_QUANTITY);
|
|
|
|
for(int x = 0; x < 7; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->resources[x] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
evnt->primskills.resize(GameConstants::PRIMARY_SKILLS);
|
|
|
|
for(int x = 0; x < 4; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->primskills[x] = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int gabn = readUI8(); // Number of gained abilities
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gabn; ++oo)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->abilities.push_back(readUI8());
|
|
|
|
evnt->abilityLevels.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int gart = readUI8(); // Number of gained artifacts
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gart; ++oo)
|
|
|
|
{
|
|
|
|
if(map->version == EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->artifacts.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->artifacts.push_back(readUI16());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int gspel = readUI8(); // Number of gained spells
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gspel; ++oo)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
evnt->spells.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int gcre = readUI8(); //number of gained creatures
|
2012-11-11 15:23:31 +03:00
|
|
|
readCreatureSet(&evnt->creatures, gcre, map->version > EMapFormat::ROE);
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(8);
|
|
|
|
evnt->availableFor = readUI8();
|
|
|
|
evnt->computerActivate = readUI8();
|
|
|
|
evnt->removeAfterVisit = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
evnt->humanActivate = true;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::HERO:
|
|
|
|
case Obj::RANDOM_HERO:
|
|
|
|
case Obj::PRISON:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nobj = readHero(idToBeGiven);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::ARENA:
|
|
|
|
case Obj::MERCENARY_CAMP:
|
|
|
|
case Obj::MARLETTO_TOWER:
|
|
|
|
case Obj::STAR_AXIS:
|
|
|
|
case Obj::GARDEN_OF_REVELATION:
|
|
|
|
case Obj::LEARNING_STONE:
|
|
|
|
case Obj::TREE_OF_KNOWLEDGE:
|
|
|
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
|
|
|
case Obj::SCHOOL_OF_MAGIC:
|
|
|
|
case Obj::SCHOOL_OF_WAR:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGVisitableOPH();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::MYSTICAL_GARDEN:
|
|
|
|
case Obj::WINDMILL:
|
|
|
|
case Obj::WATER_WHEEL:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGVisitableOPW();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::MONOLITH1:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::MONOLITH2:
|
|
|
|
case Obj::MONOLITH3:
|
|
|
|
case Obj::SUBTERRANEAN_GATE:
|
|
|
|
case Obj::WHIRLPOOL:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGTeleport();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::CAMPFIRE:
|
|
|
|
case Obj::FLOTSAM:
|
|
|
|
case Obj::SEA_CHEST:
|
|
|
|
case Obj::SHIPWRECK_SURVIVOR:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGPickable();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-15 17:20:48 +03:00
|
|
|
case Obj::TREASURE_CHEST:
|
|
|
|
if(defInfo->subid == 0)
|
|
|
|
{
|
|
|
|
nobj = new CGPickable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//WoG pickable object
|
|
|
|
//TODO: possible special handling
|
|
|
|
nobj = new CGObjectInstance();
|
|
|
|
}
|
|
|
|
break;
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::MONSTER: //Monster
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_MONSTER:
|
|
|
|
case Obj::RANDOM_MONSTER_L1:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_MONSTER_L2:
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_MONSTER_L3:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_MONSTER_L4:
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_MONSTER_L5:
|
|
|
|
case Obj::RANDOM_MONSTER_L6:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_MONSTER_L7:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGCreature * cre = new CGCreature();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = cre;
|
|
|
|
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
cre->identifier = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
map->questIdentifierToId[cre->identifier] = idToBeGiven;
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:01:31 +03:00
|
|
|
CStackInstance * hlp = new CStackInstance();
|
2013-02-02 20:20:31 +03:00
|
|
|
hlp->count = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
//type will be set during initialization
|
|
|
|
cre->putStack(0, hlp);
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
cre->character = readUI8();
|
|
|
|
if(readBool()) //true if there is message or treasury
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
cre->message = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
cre->resources.resize(GameConstants::RESOURCE_QUANTITY);
|
|
|
|
for(int j = 0; j < 7; ++j)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
cre->resources[j] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int artID;
|
|
|
|
if (map->version == EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
artID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
artID = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version == EMapFormat::ROE)
|
|
|
|
{
|
|
|
|
if(artID != 0xff)
|
|
|
|
{
|
|
|
|
cre->gainedArtifact = artID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cre->gainedArtifact = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(artID != 0xffff)
|
|
|
|
{
|
|
|
|
cre->gainedArtifact = artID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cre->gainedArtifact = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
cre->neverFlees = readUI8();
|
|
|
|
cre->notGrowingTeam =readUI8();
|
|
|
|
skip(2);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::OCEAN_BOTTLE:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SIGN:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGSignBottle * sb = new CGSignBottle();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = sb;
|
2013-02-02 20:20:31 +03:00
|
|
|
sb->message = readString();
|
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SEER_HUT:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nobj = readSeerHut();
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addQuest(nobj);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::WITCH_HUT:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGWitchHut * wh = new CGWitchHut();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = wh;
|
|
|
|
|
2012-12-24 18:07:30 +03:00
|
|
|
// in RoE we cannot specify it - all are allowed (I hope)
|
2012-11-11 15:23:31 +03:00
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0 ; i < 4; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SKILL_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
wh->allowedAbilities.push_back(i * 8 + yy);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// RoE map
|
|
|
|
for(int gg = 0; gg < GameConstants::SKILL_QUANTITY; ++gg)
|
|
|
|
{
|
|
|
|
wh->allowedAbilities.push_back(gg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SCHOLAR:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGScholar * sch = new CGScholar();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = sch;
|
2013-02-02 20:20:31 +03:00
|
|
|
sch->bonusType = static_cast<CGScholar::EBonusType>(readUI8());
|
|
|
|
sch->bonusID = readUI8();
|
|
|
|
skip(6);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::GARRISON:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::GARRISON2:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGGarrison * gar = new CGGarrison();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = gar;
|
2013-02-02 20:20:31 +03:00
|
|
|
nobj->setOwner(readUI8());
|
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
readCreatureSet(gar, 7, map->version > EMapFormat::ROE);
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
gar->removableUnits = readBool();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gar->removableUnits = true;
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(8);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::ARTIFACT:
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_ART:
|
|
|
|
case Obj::RANDOM_TREASURE_ART:
|
|
|
|
case Obj::RANDOM_MINOR_ART:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_MAJOR_ART:
|
|
|
|
case Obj::RANDOM_RELIC_ART:
|
|
|
|
case Obj::SPELL_SCROLL:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
int artID = -1;
|
|
|
|
int spellID = -1;
|
2012-11-13 21:01:31 +03:00
|
|
|
CGArtifact * art = new CGArtifact();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = art;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
art->message = readString();
|
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(art, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2012-12-24 18:07:30 +03:00
|
|
|
if(defInfo->id == Obj::SPELL_SCROLL)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
spellID = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
artID = 1;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
else if(defInfo->id == Obj::ARTIFACT)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
//specific artifact
|
|
|
|
artID = defInfo->subid;
|
|
|
|
}
|
|
|
|
|
|
|
|
art->storedArtifact = createArtifact(artID, spellID);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_RESOURCE:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RESOURCE:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGResource * res = new CGResource();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = res;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
res->message = readString();
|
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(res, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
res->amount = readUI32();
|
|
|
|
if(defInfo->subid == Res::GOLD)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
// Gold is multiplied by 100.
|
|
|
|
res->amount *= 100;
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_TOWN:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::TOWN:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nobj = readTown(defInfo->subid);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::MINE:
|
|
|
|
case Obj::ABANDONED_MINE:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGMine();
|
2013-02-02 20:20:31 +03:00
|
|
|
nobj->setOwner(readUI8());
|
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::CREATURE_GENERATOR1:
|
|
|
|
case Obj::CREATURE_GENERATOR2:
|
|
|
|
case Obj::CREATURE_GENERATOR3:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::CREATURE_GENERATOR4:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGDwelling();
|
2013-02-02 20:20:31 +03:00
|
|
|
nobj->setOwner(readUI8());
|
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::REFUGEE_CAMP:
|
|
|
|
case Obj::WAR_MACHINE_FACTORY:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGDwelling();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::SHRINE_OF_MAGIC_INCANTATION:
|
|
|
|
case Obj::SHRINE_OF_MAGIC_GESTURE:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SHRINE_OF_MAGIC_THOUGHT:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGShrine * shr = new CGShrine();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = shr;
|
2013-02-02 20:20:31 +03:00
|
|
|
shr->spell = readUI8();
|
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::PANDORAS_BOX:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGPandoraBox * box = new CGPandoraBox();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = box;
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->message = readString();
|
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(box, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
box->gainedExp = readUI32();
|
|
|
|
box->manaDiff = readUI32();
|
|
|
|
box->moraleDiff = readSI8();
|
|
|
|
box->luckDiff = readSI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
box->resources.resize(GameConstants::RESOURCE_QUANTITY);
|
|
|
|
for(int x = 0; x < 7; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->resources[x] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
box->primskills.resize(GameConstants::PRIMARY_SKILLS);
|
|
|
|
for(int x = 0; x < 4; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->primskills[x] = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int gabn = readUI8();//number of gained abilities
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gabn; ++oo)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->abilities.push_back(readUI8());
|
|
|
|
box->abilityLevels.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
int gart = readUI8(); //number of gained artifacts
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gart; ++oo)
|
|
|
|
{
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->artifacts.push_back(readUI16());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->artifacts.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
int gspel = readUI8(); //number of gained spells
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int oo = 0; oo < gspel; ++oo)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
box->spells.push_back(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
int gcre = readUI8(); //number of gained creatures
|
2012-11-11 15:23:31 +03:00
|
|
|
readCreatureSet(&box->creatures, gcre, map->version > EMapFormat::ROE);
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(8);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::GRAIL:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
map->grailPos = objPos;
|
2013-02-02 20:20:31 +03:00
|
|
|
map->grailRadious = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
continue;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_DWELLING: //same as castle + level range
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::RANDOM_DWELLING_LVL: //same as castle, fixed level
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::RANDOM_DWELLING_FACTION: //level range, fixed faction
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGDwelling();
|
2012-11-11 15:23:31 +03:00
|
|
|
CSpecObjInfo * spec = nullptr;
|
|
|
|
switch(defInfo->id)
|
|
|
|
{
|
2012-12-24 18:07:30 +03:00
|
|
|
break; case Obj::RANDOM_DWELLING: spec = new CCreGenLeveledCastleInfo();
|
|
|
|
break; case Obj::RANDOM_DWELLING_LVL: spec = new CCreGenAsCastleInfo();
|
|
|
|
break; case Obj::RANDOM_DWELLING_FACTION: spec = new CCreGenLeveledInfo();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
spec->player = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
//216 and 217
|
|
|
|
if (auto castleSpec = dynamic_cast<CCreGenAsCastleInfo *>(spec))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
castleSpec->identifier = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(!castleSpec->identifier)
|
|
|
|
{
|
|
|
|
castleSpec->asCastle = false;
|
2013-02-02 20:20:31 +03:00
|
|
|
castleSpec->castles[0] = readUI8();
|
|
|
|
castleSpec->castles[1] = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
castleSpec->asCastle = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//216 and 218
|
|
|
|
if (auto lvlSpec = dynamic_cast<CCreGenLeveledInfo *>(spec))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
lvlSpec->minLevel = std::max(readUI8(), ui8(1));
|
|
|
|
lvlSpec->maxLevel = std::min(readUI8(), ui8(7));
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
nobj->setOwner(spec->player);
|
|
|
|
static_cast<CGDwelling *>(nobj)->info = spec;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::QUEST_GUARD:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGQuestGuard * guard = new CGQuestGuard();
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addQuest(guard);
|
2012-11-11 15:23:31 +03:00
|
|
|
readQuest(guard);
|
|
|
|
nobj = guard;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::FAERIE_RING:
|
|
|
|
case Obj::SWAN_POND:
|
|
|
|
case Obj::IDOL_OF_FORTUNE:
|
|
|
|
case Obj::FOUNTAIN_OF_FORTUNE:
|
|
|
|
case Obj::RALLY_FLAG:
|
|
|
|
case Obj::OASIS:
|
|
|
|
case Obj::TEMPLE:
|
|
|
|
case Obj::WATERING_HOLE:
|
|
|
|
case Obj::FOUNTAIN_OF_YOUTH:
|
|
|
|
case Obj::BUOY:
|
|
|
|
case Obj::MERMAID:
|
|
|
|
case Obj::STABLES:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGBonusingObject();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::MAGIC_WELL:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGMagicWell();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::COVER_OF_DARKNESS:
|
|
|
|
case Obj::REDWOOD_OBSERVATORY:
|
|
|
|
case Obj::PILLAR_OF_FIRE:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGObservatory();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::CORPSE:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::LEAN_TO:
|
|
|
|
case Obj::WAGON:
|
|
|
|
case Obj::WARRIORS_TOMB:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGOnceVisitable();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::BOAT:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGBoat();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SIRENS:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGSirens();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SHIPYARD:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGShipyard();
|
2013-02-02 20:20:31 +03:00
|
|
|
nobj->setOwner(readUI32());
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::HERO_PLACEHOLDER: //hero placeholder
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGHeroPlaceholder * hp = new CGHeroPlaceholder();
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj = hp;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int a = readUI8();//unknown byte, seems to be always 0 (if not - scream!)
|
2012-11-11 15:23:31 +03:00
|
|
|
tlog2 << "Unhandled Hero Placeholder detected: " << a << std::endl;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int htid = readUI8();; //hero type id
|
2012-11-11 15:23:31 +03:00
|
|
|
nobj->subID = htid;
|
|
|
|
|
|
|
|
if(htid == 0xff)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hp->power = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hp->power = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::KEYMASTER:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGKeymasterTent();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::BORDERGUARD:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGBorderGuard();
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addQuest(nobj);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::BORDER_GATE:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGBorderGate();
|
2013-01-06 22:30:12 +03:00
|
|
|
map->addQuest (nobj);
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::EYE_OF_MAGI:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::HUT_OF_MAGI:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGMagi();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
case Obj::DERELICT_SHIP:
|
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
case Obj::CRYPT:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::SHIPWRECK:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CBank();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::PYRAMID: //Pyramid of WoG object
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-24 18:07:30 +03:00
|
|
|
if(defInfo->subid == 0)
|
|
|
|
{
|
|
|
|
nobj = new CGPyramid();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//WoG object
|
|
|
|
//TODO: possible special handling
|
|
|
|
nobj = new CGObjectInstance();
|
2013-01-13 15:40:24 +03:00
|
|
|
}
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::CARTOGRAPHER:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CCartographer();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::MAGIC_SPRING:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGMagicSpring();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::DEN_OF_THIEVES:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGDenOfthieves();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::OBELISK:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGObelisk();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::LIGHTHOUSE: //Lighthouse
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGLighthouse();
|
2013-02-02 20:20:31 +03:00
|
|
|
nobj->tempOwner = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-01-13 15:40:24 +03:00
|
|
|
case Obj::ALTAR_OF_SACRIFICE:
|
|
|
|
case Obj::TRADING_POST:
|
|
|
|
case Obj::FREELANCERS_GUILD:
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::TRADING_POST_SNOW:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGMarket();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::UNIVERSITY:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGUniversity();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:07:30 +03:00
|
|
|
case Obj::BLACK_MARKET:
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGBlackMarket();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: //any other object
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
nobj = new CGObjectInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nobj->pos = objPos;
|
|
|
|
nobj->ID = defInfo->id;
|
|
|
|
nobj->id = idToBeGiven;
|
|
|
|
if(nobj->ID != Obj::HERO && nobj->ID != Obj::HERO_PLACEHOLDER && nobj->ID != Obj::PRISON)
|
|
|
|
{
|
|
|
|
nobj->subID = defInfo->subid;
|
|
|
|
}
|
|
|
|
nobj->defInfo = defInfo;
|
|
|
|
assert(idToBeGiven == map->objects.size());
|
|
|
|
map->objects.push_back(nobj);
|
|
|
|
if(nobj->ID == Obj::TOWN)
|
|
|
|
{
|
|
|
|
map->towns.push_back(static_cast<CGTownInstance *>(nobj));
|
|
|
|
}
|
|
|
|
if(nobj->ID == Obj::HERO)
|
|
|
|
{
|
|
|
|
map->heroes.push_back(static_cast<CGHeroInstance*>(nobj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(map->heroes.begin(), map->heroes.end(), [](const ConstTransitivePtr<CGHeroInstance> & a, const ConstTransitivePtr<CGHeroInstance> & b)
|
|
|
|
{
|
|
|
|
return a->subID < b->subID;
|
|
|
|
});
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number, bool version)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
const int maxID = version ? 0xffff : 0xff;
|
|
|
|
|
|
|
|
for(int ir = 0; ir < number; ++ir)
|
|
|
|
{
|
|
|
|
int creID;
|
|
|
|
int count;
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
if (version)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
creID = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
creID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
count = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// Empty slot
|
|
|
|
if(creID == maxID) continue;
|
|
|
|
|
2012-11-13 21:01:31 +03:00
|
|
|
CStackInstance * hlp = new CStackInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
hlp->count = count;
|
|
|
|
|
|
|
|
if(creID > maxID - 0xf)
|
|
|
|
{
|
|
|
|
//this will happen when random object has random army
|
|
|
|
creID = maxID + 1 - creID + VLC->creh->creatures.size();
|
|
|
|
hlp->idRand = creID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hlp->setType(creID);
|
|
|
|
}
|
|
|
|
|
|
|
|
out->putStack(ir, hlp);
|
|
|
|
}
|
|
|
|
|
|
|
|
out->validTypes(true);
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven)
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGHeroInstance * nhi = new CGHeroInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
int identifier = 0;
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
identifier = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
map->questIdentifierToId[identifier] = idToBeGiven;
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 owner = readUI8();
|
|
|
|
nhi->subID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
for(int j = 0; j < map->predefinedHeroes.size(); ++j)
|
|
|
|
{
|
|
|
|
if(map->predefinedHeroes[j]->subID == nhi->subID)
|
|
|
|
{
|
|
|
|
tlog0 << "Hero " << nhi->subID << " will be taken from the predefined heroes list." << std::endl;
|
|
|
|
delete nhi;
|
|
|
|
nhi = map->predefinedHeroes[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nhi->setOwner(owner);
|
|
|
|
|
|
|
|
nhi->portrait = nhi->subID;
|
|
|
|
|
|
|
|
for(int j = 0; j < map->disposedHeroes.size(); ++j)
|
|
|
|
{
|
|
|
|
if(map->disposedHeroes[j].heroId == nhi->subID)
|
|
|
|
{
|
|
|
|
nhi->name = map->disposedHeroes[j].name;
|
|
|
|
nhi->portrait = map->disposedHeroes[j].portrait;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// True if hero has nonstandard name
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->name = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
|
|
|
// True if hero's experience is greater than 0
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->exp = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nhi->exp = 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->exp = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
//0 means "not set" in <=AB maps
|
|
|
|
if(!nhi->exp)
|
|
|
|
{
|
|
|
|
nhi->exp = 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
// True if hero has specified portrait
|
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->portrait = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if hero has specified abilities
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int howMany = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
nhi->secSkills.resize(howMany);
|
|
|
|
for(int yy = 0; yy < howMany; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->secSkills[yy].first = readUI8();
|
|
|
|
nhi->secSkills[yy].second = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// True if hero has nonstandard garrison
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(nhi, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->formation = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
loadArtifactsOfHero(nhi);
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->patrol.patrolRadious = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(nhi->patrol.patrolRadious == 0xff)
|
|
|
|
{
|
|
|
|
nhi->patrol.patrolling = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nhi->patrol.patrolling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
|
|
|
// True if hero has nonstandard (mapmaker defined) biography
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->biography = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->sex = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// Remove trash
|
|
|
|
if (nhi->sex != 0xFF)
|
|
|
|
{
|
|
|
|
nhi->sex &= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nhi->sex = 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spells
|
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nhi->spells.insert(0xffffffff); //placeholder "preset spells"
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 9; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->spells.insert(i * 8 + yy);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(map->version == EMapFormat::AB)
|
|
|
|
{
|
|
|
|
//we can read one spell
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 buff = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(buff != 254)
|
|
|
|
{
|
|
|
|
nhi->spells.insert(0xffffffff); //placeholder "preset spells"
|
|
|
|
if(buff < 254) //255 means no spells
|
|
|
|
{
|
|
|
|
nhi->spells.insert(buff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
|
|
|
//customPrimSkills
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; ++xx)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nhi->pushPrimSkill(xx, readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(16);
|
2012-11-11 15:23:31 +03:00
|
|
|
return nhi;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGSeerHut * CMapLoaderH3M::readSeerHut()
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGSeerHut * hut = new CGSeerHut();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
|
|
|
readQuest(hut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//RoE
|
2013-02-02 20:20:31 +03:00
|
|
|
int artID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if (artID != 255)
|
|
|
|
{
|
|
|
|
//not none quest
|
|
|
|
hut->quest->m5arts.push_back (artID);
|
|
|
|
hut->quest->missionType = CQuest::MISSION_ART;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hut->quest->missionType = CQuest::MISSION_NONE;
|
|
|
|
}
|
|
|
|
hut->quest->lastDay = -1; //no timeout
|
|
|
|
hut->quest->isCustomFirst = hut->quest->isCustomNext = hut->quest->isCustomComplete = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hut->quest->missionType)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 rewardType = readUI8();
|
2013-02-02 01:04:25 +03:00
|
|
|
hut->rewardType = static_cast<CGSeerHut::ERewardType>(rewardType);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
switch(rewardType)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rVal = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rVal = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rVal = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rVal = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
// Only the first 3 bytes are used. Skip the 4th.
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rVal = readUI32() & 0x00ffffff;
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
|
|
|
hut->rVal = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
|
|
|
hut->rVal = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
if (map->version == EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI16();
|
|
|
|
hut->rVal = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
hut->rID = readUI8();
|
|
|
|
hut->rVal = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(2);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// missionType==255
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return hut;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readQuest(IQuestObject * guard)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->missionType = static_cast<CQuest::Emission>(readUI8());
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
switch(guard->quest->missionType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
guard->quest->m2stats.resize(4);
|
|
|
|
for(int x = 0; x < 4; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->m2stats[x] = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->m13489val = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int artNumber = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < artNumber; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int artid = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
guard->quest->m5arts.push_back(artid);
|
|
|
|
map->allowedArtifact[artid] = false; //these are unavailable for random generation
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int typeNumber = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
guard->quest->m6creatures.resize(typeNumber);
|
|
|
|
for(int hh = 0; hh < typeNumber; ++hh)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->m6creatures[hh].type = VLC->creh->creatures[readUI16()];
|
|
|
|
guard->quest->m6creatures[hh].count = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
guard->quest->m7resources.resize(7);
|
|
|
|
for(int x = 0; x < 7; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->m7resources[x] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
case 9:
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->m13489val = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
int limit = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(limit == (static_cast<int>(0xffffffff)))
|
|
|
|
{
|
|
|
|
guard->quest->lastDay = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guard->quest->lastDay = limit;
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
guard->quest->firstVisitText = readString();
|
|
|
|
guard->quest->nextVisitText = readString();
|
|
|
|
guard->quest->completedText = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
guard->quest->isCustomFirst = guard->quest->firstVisitText.size() > 0;
|
|
|
|
guard->quest->isCustomNext = guard->quest->nextVisitText.size() > 0;
|
|
|
|
guard->quest->isCustomComplete = guard->quest->completedText.size() > 0;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGTownInstance * CMapLoaderH3M::readTown(int castleID)
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CGTownInstance * nt = new CGTownInstance();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->identifier = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->tempOwner = readUI8();
|
|
|
|
if(readBool())// Has name
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->name = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// True if garrison isn't empty
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
readCreatureSet(nt, 7, map->version > EMapFormat::ROE);
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->formation = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// Custom buildings info
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
// Built buildings
|
|
|
|
for(int byte = 0; byte < 6; ++byte)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 m = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int bit = 0; bit < 8; ++bit)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(m & (1 << bit))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nt->builtBuildings.insert(byte * 8 + bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forbidden buildings
|
|
|
|
for(int byte = 6; byte < 12; ++byte)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 m = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int bit = 0; bit < 8; ++bit)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(m & (1 << bit))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nt->forbiddenBuildings.insert((byte - 6) * 8 + bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nt->builtBuildings = convertBuildings(nt->builtBuildings, castleID);
|
|
|
|
nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings, castleID);
|
|
|
|
}
|
|
|
|
// Standard buildings
|
|
|
|
else
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(readBool())
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
// Has fort
|
|
|
|
nt->builtBuildings.insert(EBuilding::FORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
//means that set of standard building should be included
|
|
|
|
nt->builtBuildings.insert(-50);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version > EMapFormat::ROE)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 9; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-18 13:32:11 +03:00
|
|
|
if(c == (c | static_cast<ui8>(std::pow(2., yy))))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->obligatorySpells.push_back(i * 8 + yy);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
for(int i = 0; i < 9; ++i)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 c = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yy = 0; yy < 8; ++yy)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(i * 8 + yy < GameConstants::SPELLS_QUANTITY)
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2012-12-11 15:12:46 +03:00
|
|
|
if(c != (c | static_cast<ui8>(std::pow(2., yy))))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->possibleSpells.push_back(i * 8 + yy);
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read castle events
|
2013-02-02 20:20:31 +03:00
|
|
|
int numberOfEvent = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
for(int gh = 0; gh < numberOfEvent; ++gh)
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CCastleEvent * nce = new CCastleEvent();
|
2012-11-11 15:23:31 +03:00
|
|
|
nce->town = nt;
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->name = readString();
|
|
|
|
nce->message = readString();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int x = 0; x < 7; ++x)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->resources[x] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->players = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->humanAffected = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nce->humanAffected = true;
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->computerAffected = readUI8();
|
|
|
|
nce->firstOccurence = readUI16();
|
|
|
|
nce->nextOccurence = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(17);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
// New buildings
|
|
|
|
for(int byte = 0; byte < 6; ++byte)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ui8 m = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int bit = 0; bit < 8; ++bit)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
if(m & (1 << bit))
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
nce->buildings.insert(byte * 8 + bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nce->buildings = convertBuildings(nce->buildings, castleID, false);
|
|
|
|
|
|
|
|
nce->creatures.resize(7);
|
|
|
|
for(int vv = 0; vv < 7; ++vv)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nce->creatures[vv] = readUI16();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(4);
|
2012-11-11 15:23:31 +03:00
|
|
|
nt->events.push_back(nce);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
nt->alignment = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(3);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
return nt;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::set<si32> CMapLoaderH3M::convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary /*= true*/)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
std::map<int, int> mapa;
|
|
|
|
std::set<si32> ret;
|
|
|
|
|
|
|
|
// Note: this file is parsed many times.
|
|
|
|
const JsonNode config(ResourceID("config/buildings5.json"));
|
|
|
|
|
|
|
|
BOOST_FOREACH(const JsonNode & entry, config["table"].Vector())
|
|
|
|
{
|
|
|
|
int town = entry["town"].Float();
|
|
|
|
|
|
|
|
if (town == castleID || town == -1)
|
|
|
|
{
|
|
|
|
mapa[entry["h3"].Float()] = entry["vcmi"].Float();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto i = h3m.begin(); i != h3m.end(); ++i)
|
|
|
|
{
|
|
|
|
if(mapa[*i] >= 0)
|
|
|
|
{
|
|
|
|
ret.insert(mapa[*i]);
|
|
|
|
}
|
|
|
|
// horde buildings
|
|
|
|
else if(mapa[*i] >= (-GameConstants::CREATURES_PER_TOWN))
|
|
|
|
{
|
|
|
|
int level = (mapa[*i]);
|
|
|
|
|
|
|
|
//(-30)..(-36) - horde buildings (for game loading only), don't see other way to handle hordes in random towns
|
|
|
|
ret.insert(level - 30);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tlog3 << "Conversion warning: unknown building " << *i << " in castle "
|
|
|
|
<< castleID << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addAuxiliary)
|
|
|
|
{
|
|
|
|
//village hall is always present
|
|
|
|
ret.insert(EBuilding::VILLAGE_HALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret.find(EBuilding::CITY_HALL) != ret.end())
|
|
|
|
{
|
|
|
|
ret.insert(EBuilding::EXTRA_CITY_HALL);
|
|
|
|
}
|
|
|
|
if(ret.find(EBuilding::TOWN_HALL) != ret.end())
|
|
|
|
{
|
|
|
|
ret.insert(EBuilding::EXTRA_TOWN_HALL);
|
|
|
|
}
|
|
|
|
if(ret.find(EBuilding::CAPITOL) != ret.end())
|
|
|
|
{
|
|
|
|
ret.insert(EBuilding::EXTRA_CAPITOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapLoaderH3M::readEvents()
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
int numberOfEvents = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int yyoo = 0; yyoo < numberOfEvents; ++yyoo)
|
|
|
|
{
|
2012-11-13 21:01:31 +03:00
|
|
|
CMapEvent * ne = new CMapEvent();
|
2013-02-02 20:20:31 +03:00
|
|
|
ne->name = readString();
|
|
|
|
ne->message = readString();
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
for(int k = 0; k < 7; ++k)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ne->resources[k] = readUI32();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
ne->players = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
if(map->version > EMapFormat::AB)
|
|
|
|
{
|
2013-02-02 20:20:31 +03:00
|
|
|
ne->humanAffected = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ne->humanAffected = true;
|
|
|
|
}
|
2013-02-02 20:20:31 +03:00
|
|
|
ne->computerAffected = readUI8();
|
|
|
|
ne->firstOccurence = readUI16();
|
|
|
|
ne->nextOccurence = readUI8();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-02-02 20:20:31 +03:00
|
|
|
skip(17);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
map->events.push_back(ne);
|
|
|
|
}
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CMapLoaderH3M::reverse(ui8 arg)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
ui8 ret = 0;
|
|
|
|
for(int i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
if((arg & (1 << i)) >> i)
|
|
|
|
{
|
|
|
|
ret |= (128 >> i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2012-11-03 16:30:47 +03:00
|
|
|
}
|