1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* Separated map loading from the map object * Moved map classes to lib/Map * Renamed map.h/cpp to CMap.h/cpp * Profiling of map loading is now optional * Updated CMemoryStream

This commit is contained in:
beegee1 2012-11-03 13:30:47 +00:00
parent 2cd774fe42
commit a878f5f79a
41 changed files with 3548 additions and 2904 deletions

View File

@ -14,7 +14,7 @@
#include "../../lib/CObjectHandler.h"
#include "../../lib/Connection.h"
#include "../../lib/CGameState.h"
#include "../../lib/map.h"
#include "../../lib/Map/CMap.h"
#include "../../lib/NetPacks.h"
#include "../../lib/CondSh.h"
#include "../../lib/CStopWatch.h"

View File

@ -7,7 +7,7 @@
#include "lib/BattleState.h"
#include "client/CPlayerInterface.h"
#include "client/Client.h"
#include "lib/map.h"
#include "lib/Map/CMap.h"
#include "lib/CBuildingHandler.h"
#include "lib/CDefObjInfoHandler.h"
#include "lib/CGeneralTextHandler.h"

View File

@ -4,7 +4,7 @@
#include "../CCallback.h"
#include "../lib/JsonNode.h"
#include "../lib/Filesystem/CResourceLoader.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/CModHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/CGameState.h"

View File

@ -24,7 +24,7 @@
#include "../CCreatureWindow.h"
#include "../CVideoHandler.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/map.h"
#include "../../lib/Map/CMap.h"
#include "CBattleAnimations.h"
#include "CBattleInterfaceClasses.h"

View File

@ -19,7 +19,7 @@
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/JsonNode.h"
#include "mapHandler.h"
#include "CPreGame.h"

View File

@ -30,7 +30,7 @@
#include "CMusicHandler.h"
#include "../lib/CondSh.h"
#include "../lib/NetPacks.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/VCMIDirs.h"
#include "mapHandler.h"
#include "../lib/CStopWatch.h"

View File

@ -16,7 +16,7 @@
#include "../lib/CTownHandler.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/Map/CCampaignHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/JsonNode.h"
#include "CMusicHandler.h"
@ -24,7 +24,7 @@
#include "Graphics.h"
#include "../lib/Connection.h"
#include "../lib/VCMIDirs.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "GUIClasses.h"
#include "CPlayerInterface.h"
#include "../CCallback.h"
@ -41,6 +41,7 @@
#include "../lib/GameConstants.h"
#include "UIFramework/CGuiHandler.h"
#include "UIFramework/CIntObjectClasses.h"
#include "../lib/Map/CMapService.h"
/*
* CPreGame.cpp, part of VCMI engine
@ -101,8 +102,7 @@ static void do_quit()
static CMapInfo *mapInfoFromGame()
{
CMapInfo * ret = new CMapInfo();
CMapHeader *headerCopy = new CMapHeader(*LOCPLINT->cb->getMapHeader()); //will be deleted by CMapInfo d-tor
ret->setHeader(headerCopy);
ret->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
return ret;
}
@ -771,7 +771,7 @@ void CSelectionScreen::changeSelection( const CMapInfo *to )
SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
if(screenType != CMenuScreen::campaignList)
{
updateStartInfo(to ? to->fileURI : "", sInfo, to ? to->mapHeader : NULL);
updateStartInfo(to ? to->fileURI : "", sInfo, to ? to->mapHeader.get() : NULL);
}
card->changeSelection(to);
if(screenType != CMenuScreen::campaignList)
@ -1036,31 +1036,24 @@ std::vector<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
++iterator;
}
allItems.resize(ret.size());
return ret;
}
void SelectionTab::parseMaps(const std::vector<ResourceID> &files, int start, int threads)
void SelectionTab::parseMaps(const std::vector<ResourceID> & files)
{
ui8 mapBuffer[1500];
while(start < allItems.size())
allItems.clear();
for(int i = 0; i < files.size(); ++i)
{
try
{
TInputStreamPtr stream(CMap::getMapStream(files[start].getName()));
int read = stream->read(mapBuffer, 1500);
if(read < 50 || !mapBuffer[4])
throw std::runtime_error("corrupted map file");
allItems[start].mapInit(files[start].getName(), mapBuffer);
CMapInfo mapInfo;
mapInfo.mapInit(files[i].getName());
allItems.push_back(std::move(mapInfo));
}
catch(std::exception & e)
{
tlog3 << "\t\tWarning: failed to load map " << files[start].getName() << ": " << e.what() << std::endl;
tlog2 << "Map " << files[i].getName() << " is invalid. Message: " << e.what() << std::endl;
}
start += threads;
}
}
@ -1077,7 +1070,7 @@ void SelectionTab::parseGames(const std::vector<ResourceID> &files, bool multi)
if(std::memcmp(sign,"VCMISVG",7))
throw std::runtime_error("not a correct savefile!");
allItems[i].mapHeader = new CMapHeader();
allItems[i].mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader);
lf >> *(allItems[i].mapHeader) >> allItems[i].scenarioOpts;
allItems[i].fileURI = files[i].getName();
allItems[i].countPlayers();
@ -1086,12 +1079,12 @@ void SelectionTab::parseGames(const std::vector<ResourceID> &files, bool multi)
if((allItems[i].actualHumanPlayers > 1) != multi) //if multi mode then only multi games, otherwise single
{
vstd::clear_pointer(allItems[i].mapHeader);
allItems[i].mapHeader.reset(nullptr);
}
}
catch(std::exception &e)
{
vstd::clear_pointer(allItems[i].mapHeader);
allItems[i].mapHeader.reset(nullptr);
tlog3 << "Failed to process " << files[i].getName() <<": " << e.what() << std::endl;
}
}
@ -2612,8 +2605,8 @@ CScenarioInfo::~CScenarioInfo()
bool mapSorter::operator()(const CMapInfo *aaa, const CMapInfo *bbb)
{
const CMapHeader * a = aaa->mapHeader,
* b = bbb->mapHeader;
const CMapHeader * a = aaa->mapHeader.get(),
* b = bbb->mapHeader.get();
if(a && b) //if we are sorting scenarios
{
switch (sortBy)
@ -2949,10 +2942,10 @@ void CBonusSelection::selectMap( int whichOne )
ourCampaign->currentMap = whichOne;
//get header
int i = 0;
delete ourHeader;
ourHeader = new CMapHeader();
ourHeader->initFromMemory((const unsigned char*)ourCampaign->camp->mapPieces.find(whichOne)->second.data(), i);
std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second;
auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release();
std::map<TPlayerColor, std::string> names;
names[1] = settings["general"]["playerName"].String();

View File

@ -5,7 +5,7 @@
#include "../lib/StartInfo.h"
#include "GUIClasses.h"
#include "FunctionList.h"
#include "../lib/CMapInfo.h"
#include "../lib/Map/CMapInfo.h"
/*
* CPreGame.h, part of VCMI engine
@ -142,7 +142,7 @@ class SelectionTab : public CIntObject
private:
CDefHandler *format; //map size
void parseMaps(const std::vector<ResourceID> &files, int start = 0, int threads = 1);
void parseMaps(const std::vector<ResourceID> &files);
void parseGames(const std::vector<ResourceID> &files, bool multi);
void parseCampaigns(const std::vector<ResourceID> & files );
std::vector<ResourceID> getFiles(std::string dirURI, int resType);

View File

@ -1,7 +1,7 @@
#include "StdInc.h"
#include "CMusicHandler.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/Map/CCampaignHandler.h"
#include "../CCallback.h"
#include "../lib/CConsoleHandler.h"
#include "CGameInfo.h"
@ -23,7 +23,7 @@
#include "../lib/NetPacks.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/VCMIDirs.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/JsonNode.h"
#include "mapHandler.h"
#include "../lib/CConfigHandler.h"

View File

@ -26,7 +26,7 @@
#include "../lib/CSpellHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/CondSh.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "mapHandler.h"
#include "../lib/CStopWatch.h"
#include "../lib/NetPacks.h"

View File

@ -13,7 +13,7 @@
#include "../lib/CHeroHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/VCMIDirs.h"
#include "../lib/CSpellHandler.h"
#include "CSoundBase.h"
@ -22,7 +22,7 @@
#include "../lib/CConfigHandler.h"
#include "UIFramework/SDL_Extensions.h"
#include "BattleInterface/CBattleInterface.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/Map/CCampaignHandler.h"
#include "../lib/CGameState.h"
#include "../lib/BattleState.h"
#include "../lib/GameConstants.h"

View File

@ -9,7 +9,7 @@
#include "../lib/CTownHandler.h"
#include "Graphics.h"
#include "../lib/CObjectHandler.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "CDefHandler.h"
#include "../lib/CConfigHandler.h"
#include "../lib/CGeneralTextHandler.h"

View File

@ -2,7 +2,7 @@
#include "CGameState.h"
#include <boost/random/linear_congruential.hpp>
#include "CCampaignHandler.h"
#include "Map/CCampaignHandler.h"
#include "CDefObjInfoHandler.h"
#include "CArtHandler.h"
#include "CBuildingHandler.h"
@ -15,11 +15,12 @@
#include "CModHandler.h"
#include "VCMI_Lib.h"
#include "Connection.h"
#include "map.h"
#include "Map/CMap.h"
#include "Map/CMapService.h"
#include "StartInfo.h"
#include "NetPacks.h"
#include "RegisterTypes.h"
#include "CMapInfo.h"
#include "Map/CMapInfo.h"
#include "BattleState.h"
#include "JsonNode.h"
#include "Filesystem/CResourceLoader.h"
@ -865,16 +866,18 @@ void CGameState::init(StartInfo * si)
switch(scenarioOps->mode)
{
case StartInfo::NEW_GAME:
map = new CMap(scenarioOps->mapname);
tlog0 << "Open map file: " << scenarioOps->mapname << std::endl;
map = CMapService::loadMap(scenarioOps->mapname).release();
break;
case StartInfo::CAMPAIGN:
{
tlog0 << "Open campaign map file: " << scenarioOps->campState->currentMap << std::endl;
auto campaign = scenarioOps->campState;
assert(vstd::contains(campaign->camp->mapPieces, scenarioOps->campState->currentMap));
std::string & mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap];
map = new CMap();
map->initFromBytes((const ui8*)mapContent.c_str(), mapContent.size());
auto buffer = reinterpret_cast<const ui8 *>(mapContent.data());
map = CMapService::loadMap(buffer, mapContent.size()).release();
}
break;
case StartInfo::DUEL:

View File

@ -5,7 +5,7 @@
#ifndef _MSC_VER
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "map.h"
#include "Map/CMap.h"
#endif
#include "HeroBonus.h"

View File

@ -13,13 +13,16 @@ set(lib_SRCS
Filesystem/CResourceLoader.cpp
Filesystem/CFileInputStream.cpp
Filesystem/CCompressedStream.cpp
Map/CCampaignHandler.cpp
Map/CMap.cpp
Map/CMapInfo.cpp
Map/CMapService.cpp
BattleAction.cpp
BattleHex.cpp
BattleState.cpp
CArtHandler.cpp
CBattleCallback.cpp
CBuildingHandler.cpp
CCampaignHandler.cpp
CConfigHandler.cpp
CConsoleHandler.cpp
CCreatureHandler.cpp
@ -30,7 +33,6 @@ set(lib_SRCS
CGeneralTextHandler.cpp
CHeroHandler.cpp
CLogger.cpp
CMapInfo.cpp
CModHandler.cpp
CObjectHandler.cpp
CObstacleInstance.cpp
@ -41,7 +43,6 @@ set(lib_SRCS
HeroBonus.cpp
IGameCallback.cpp
JsonNode.cpp
map.cpp
NetPacksLib.cpp
ResourceSet.cpp
VCMI_Lib.cpp

View File

@ -1,71 +0,0 @@
#include "StdInc.h"
#include "CMapInfo.h"
#include "StartInfo.h"
#include "map.h"
#include "CCampaignHandler.h"
#include "GameConstants.h"
void CMapInfo::countPlayers()
{
actualHumanPlayers = playerAmnt = humanPlayers = 0;
for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
{
if(mapHeader->players[i].canHumanPlay)
{
playerAmnt++;
humanPlayers++;
}
else if(mapHeader->players[i].canComputerPlay)
{
playerAmnt++;
}
}
if(scenarioOpts)
for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
if(i->second.human)
actualHumanPlayers++;
}
CMapInfo::CMapInfo(bool map)
: mapHeader(NULL), campaignHeader(NULL), scenarioOpts(NULL)
{
}
void CMapInfo::mapInit(const std::string &fname, const ui8 *map )
{
fileURI = fname;
int i = 0;
mapHeader = new CMapHeader();
mapHeader->version = EMapFormat::INVALID;
try
{
mapHeader->initFromMemory(map, i);
countPlayers();
}
catch (const std::exception &e)
{
tlog1 << "\t\tWarning: evil map file: " << fname << ": " << e.what() << std::endl;
delete mapHeader;
mapHeader = NULL;
}
}
CMapInfo::~CMapInfo()
{
delete mapHeader;
delete campaignHeader;
}
void CMapInfo::campaignInit()
{
campaignHeader = new CCampaignHeader( CCampaignHandler::getHeader(fileURI) );
}
void CMapInfo::setHeader(CMapHeader *header)
{
mapHeader = header;
}

View File

@ -1,35 +0,0 @@
#pragma once
class CMapHeader;
class CCampaignHeader;
struct StartInfo;
/// A class which stores the count of human players and all players, the filename,
/// scenario options, the map header information,...
class DLL_LINKAGE CMapInfo
{
public:
CMapHeader * mapHeader; //may be NULL if campaign
CCampaignHeader * campaignHeader; //may be NULL if scenario
StartInfo *scenarioOpts; //options with which scenario has been started (used only with saved games)
std::string fileURI;
std::string date;
int playerAmnt, //players in map
humanPlayers; //players ALLOWED to be controlled by human
int actualHumanPlayers; // >1 if multiplayer game
CMapInfo(bool map = true);
~CMapInfo();
//CMapInfo(const std::string &fname, const ui8 *map);
void setHeader(CMapHeader *header);
void mapInit(const std::string &fname, const ui8 *map);
void campaignInit();
void countPlayers();
template <typename Handler> void serialize(Handler &h, const int Version)
{
h & mapHeader & campaignHeader & scenarioOpts & fileURI & date & playerAmnt & humanPlayers;
h & actualHumanPlayers;
}
};

View File

@ -16,7 +16,7 @@
#include "CGameState.h"
#include "NetPacks.h"
#include "StartInfo.h"
#include "map.h"
#include "Map/CMap.h"
#include <SDL_stdinc.h>
#include "CBuildingHandler.h"
#include "JsonNode.h"

View File

@ -6,11 +6,11 @@
#endif
//for smart objs serialization over net
#include "../lib/CMapInfo.h"
#include "../lib/Map/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "map.h"
#include "Map/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
@ -19,7 +19,7 @@
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "CCampaignHandler.h"
#include "Map/CCampaignHandler.h"
#include "NetPacks.h"
#include <boost/asio.hpp>

View File

@ -23,7 +23,7 @@
#include "ConstTransitivePtr.h"
#include "CCreatureSet.h" //for CStackInstance
#include "CObjectHandler.h" //for CArmedInstance
#include "CCampaignHandler.h" //for CCampaignState
#include "Map/CCampaignHandler.h" //for CCampaignState
const ui32 version = 733;
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;

View File

@ -49,9 +49,9 @@ si64 CFileInputStream::read(ui8 * data, si64 size)
si64 CFileInputStream::seek(si64 position)
{
si64 origin = tell();
fileStream.seekg(dataStart + std::min(position, dataSize));
return tell();
return tell() - origin;
}
si64 CFileInputStream::tell()

View File

@ -1,34 +1,25 @@
#include "StdInc.h"
#include "CMemoryStream.h"
CMemoryStream::CMemoryStream(const ui8 * data, si64 size, bool freeData /*= false*/):
data(data),
size(size),
position(0),
freeData(freeData)
CMemoryStream::CMemoryStream(const ui8 * data, si64 size) :
data(data), size(size), position(0)
{
}
CMemoryStream::~CMemoryStream()
{
if(freeData)
{
delete[] data;
}
}
si64 CMemoryStream::read(ui8 * data, si64 size)
{
std::copy(this->data + position, this->data + position + size, data);
si64 toRead = std::min(this->size - tell(), size);
std::copy(this->data + position, this->data + position + toRead, data);
position += size;
return size;
return toRead;
}
si64 CMemoryStream::seek(si64 position)
{
si64 diff = this->position;
this->position = position;
return position - diff;
si64 origin = tell();
this->position = std::min(position, size);
return tell() - origin;
}
si64 CMemoryStream::tell()
@ -38,8 +29,9 @@ si64 CMemoryStream::tell()
si64 CMemoryStream::skip(si64 delta)
{
this->position += delta;
return delta;
si64 origin = tell();
this->position += std::min(size - origin, delta);
return tell() - origin;
}
si64 CMemoryStream::getSize()

View File

@ -20,18 +20,12 @@ class DLL_LINKAGE CMemoryStream : public CInputStream
{
public:
/**
* C-tor. The data buffer will be freed by the stream's destructor.
* C-tor. The data buffer won't be free'd. (no ownership)
*
* @param data A pointer to the data array.
* @param data a pointer to the data array.
* @param size The size in bytes of the array.
* @param freeData Flag which specifies if the data array should be freed in the memory stream's destructor.
*/
CMemoryStream(const ui8 * data, si64 size, bool freeData);
/**
* D-tor. Frees the data array if the freeData flag was set to true.
*/
~CMemoryStream();
CMemoryStream(const ui8 * data, si64 size);
/**
* Reads n bytes from the stream into the data buffer.
@ -81,7 +75,4 @@ private:
/** Current reading position of the stream. */
si64 position;
/** Flag which specifies if the data array should be freed in the memory stream's destructor. */
bool freeData;
};

View File

@ -330,8 +330,7 @@ public:
*/
void addLoader(std::string mountPoint, shared_ptr<ISimpleResourceLoader> loader, bool writeable);
public:
private:
/**
* Contains lists of same resources which can be accessed uniquely by an
* resource identifier.

View File

@ -4,7 +4,7 @@
#include <boost/random/linear_congruential.hpp>
#include "CGameState.h"
#include "map.h"
#include "Map/CMap.h"
#include "CObjectHandler.h"
#include "CHeroHandler.h"
#include "StartInfo.h"

View File

@ -1,15 +1,15 @@
#include "StdInc.h"
#include "CCampaignHandler.h"
#include "Filesystem/CResourceLoader.h"
#include "Filesystem/CCompressedStream.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/vcmi_endian.h"
#include "CGeneralTextHandler.h"
#include "StartInfo.h"
#include "CArtHandler.h" //for hero crossover
#include "CObjectHandler.h" //for hero crossover
#include "CHeroHandler.h"
#include "../Filesystem/CResourceLoader.h"
#include "../Filesystem/CCompressedStream.h"
#include "../VCMI_Lib.h"
#include "../vcmi_endian.h"
#include "../CGeneralTextHandler.h"
#include "../StartInfo.h"
#include "../CArtHandler.h" //for hero crossover
#include "../CObjectHandler.h" //for hero crossover
#include "../CHeroHandler.h"
namespace fs = boost::filesystem;

241
lib/Map/CMap.cpp Normal file
View File

@ -0,0 +1,241 @@
#include "StdInc.h"
#include "CMap.h"
#include "../CObjectHandler.h"
#include "../CArtHandler.h"
PlayerInfo::PlayerInfo(): p7(0), p8(0), p9(0), canHumanPlay(0), canComputerPlay(0),
AITactic(0), isFactionRandom(0),
mainHeroPortrait(0), hasMainTown(0), generateHeroAtMainTown(0),
team(255), generateHero(0)
{
}
si8 PlayerInfo::defaultCastle() const
{
assert(!allowedFactions.empty()); // impossible?
if(allowedFactions.size() == 1)
{
// only one faction is available - pick it
return *allowedFactions.begin();
}
// set to random
return -1;
}
si8 PlayerInfo::defaultHero() const
{
// we will generate hero in front of main town
if((generateHeroAtMainTown && hasMainTown) || p8)
{
//random hero
return -1;
}
return -2;
}
CMapHeader::CMapHeader() : version(EMapFormat::INVALID)
{
areAnyPLayers = difficulty = levelLimit = howManyTeams = 0;
height = width = twoLevel = -1;
}
CMapHeader::~CMapHeader()
{
}
void CMap::removeBlockVisTiles(CGObjectInstance * obj, bool total)
{
for(int fx=0; fx<8; ++fx)
{
for(int fy=0; fy<6; ++fy)
{
int xVal = obj->pos.x + fx - 7;
int yVal = obj->pos.y + fy - 5;
int zVal = obj->pos.z;
if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
{
TerrainTile & curt = terrain[xVal][yVal][zVal];
if(total || ((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
{
curt.visitableObjects -= obj;
curt.visitable = curt.visitableObjects.size();
}
if(total || !((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
{
curt.blockingObjects -= obj;
curt.blocked = curt.blockingObjects.size();
}
}
}
}
}
void CMap::addBlockVisTiles(CGObjectInstance * obj)
{
for(int fx=0; fx<8; ++fx)
{
for(int fy=0; fy<6; ++fy)
{
int xVal = obj->pos.x + fx - 7;
int yVal = obj->pos.y + fy - 5;
int zVal = obj->pos.z;
if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
{
TerrainTile & curt = terrain[xVal][yVal][zVal];
if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
{
curt.visitableObjects.push_back(obj);
curt.visitable = true;
}
if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
{
curt.blockingObjects.push_back(obj);
curt.blocked = true;
}
}
}
}
}
CMap::CMap() : terrain(nullptr)
{
}
CMap::~CMap()
{
if(terrain)
{
for(int ii=0;ii<width;ii++)
{
for(int jj=0;jj<height;jj++)
delete [] terrain[ii][jj];
delete [] terrain[ii];
}
delete [] terrain;
}
for(std::list<ConstTransitivePtr<CMapEvent> >::iterator i = events.begin(); i != events.end(); i++)
{
i->dellNull();
}
}
CGHeroInstance * CMap::getHero(int heroID)
{
for(ui32 i=0; i<heroes.size();i++)
if(heroes[i]->subID == heroID)
return heroes[i];
return nullptr;
}
bool CMap::isInTheMap(const int3 &pos) const
{
if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
return false;
else return true;
}
TerrainTile & CMap::getTile( const int3 & tile )
{
return terrain[tile.x][tile.y][tile.z];
}
const TerrainTile & CMap::getTile( const int3 & tile ) const
{
return terrain[tile.x][tile.y][tile.z];
}
bool CMap::isWaterTile(const int3 &pos) const
{
return isInTheMap(pos) && getTile(pos).tertype == ETerrainType::WATER;
}
const CGObjectInstance *CMap::getObjectiveObjectFrom(int3 pos, bool lookForHero)
{
const std::vector <CGObjectInstance *> & objs = getTile(pos).visitableObjects;
assert(objs.size());
if(objs.size() > 1 && lookForHero && objs.front()->ID != Obj::HERO)
{
assert(objs.back()->ID == Obj::HERO);
return objs.back();
}
else
return objs.front();
}
void CMap::checkForObjectives()
{
if(isInTheMap(victoryCondition.pos))
victoryCondition.obj = getObjectiveObjectFrom(victoryCondition.pos, victoryCondition.condition == EVictoryConditionType::BEATHERO);
if(isInTheMap(lossCondition.pos))
lossCondition.obj = getObjectiveObjectFrom(lossCondition.pos, lossCondition.typeOfLossCon == ELossConditionType::LOSSHERO);
}
void CMap::addNewArtifactInstance( CArtifactInstance *art )
{
art->id = artInstances.size();
artInstances.push_back(art);
}
void CMap::eraseArtifactInstance(CArtifactInstance *art)
{
assert(artInstances[art->id] == art);
artInstances[art->id].dellNull();
}
LossCondition::LossCondition()
{
obj = NULL;
timeLimit = -1;
pos = int3(-1,-1,-1);
}
VictoryCondition::VictoryCondition()
{
pos = int3(-1,-1,-1);
obj = NULL;
ID = allowNormalVictory = appliesToAI = count = 0;
}
bool TerrainTile::entrableTerrain(const TerrainTile * from /*= NULL*/) const
{
return entrableTerrain(from ? from->tertype != ETerrainType::WATER : true, from ? from->tertype == ETerrainType::WATER : true);
}
bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const
{
return tertype != ETerrainType::ROCK
&& ((allowSea && tertype == ETerrainType::WATER) || (allowLand && tertype != ETerrainType::WATER));
}
bool TerrainTile::isClear(const TerrainTile *from /*= NULL*/) const
{
return entrableTerrain(from) && !blocked;
}
int TerrainTile::topVisitableID() const
{
return visitableObjects.size() ? visitableObjects.back()->ID : -1;
}
bool TerrainTile::isCoastal() const
{
return extTileFlags & 64;
}
bool TerrainTile::hasFavourableWinds() const
{
return extTileFlags & 128;
}
bool TerrainTile::isWater() const
{
return tertype == ETerrainType::WATER;
}

View File

@ -1,18 +1,6 @@
#pragma once
#ifndef _MSC_VER
#include "CObjectHandler.h"
#include "CDefObjInfoHandler.h"
#endif
#include "ConstTransitivePtr.h"
#include "ResourceSet.h"
#include "int3.h"
#include "GameConstants.h"
/*
* map.h, part of VCMI engine
* CMap.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@ -21,6 +9,18 @@
*
*/
#pragma once
#ifndef _MSC_VER
#include "../CObjectHandler.h"
#include "../CDefObjInfoHandler.h"
#endif
#include "../ConstTransitivePtr.h"
#include "../ResourceSet.h"
#include "../int3.h"
#include "../GameConstants.h"
class CArtifactInstance;
class CGDefInfo;
class CGObjectInstance;
@ -31,9 +31,7 @@ class CQuest;
class CGTownInstance;
class IModableArt;
class IQuestObject;
class CInputStream;
typedef std::unique_ptr<CInputStream> TInputStreamPtr;
namespace ETerrainType
{
@ -502,42 +500,10 @@ public:
CMapHeader();
/**
* Constructor.
*
* @param map a pointer to an buffer which contains bytes describing a map header
*/
CMapHeader(const ui8 * map);
/**
* Destructor.
* D-tor.
*/
virtual ~CMapHeader();
/**
* Initializes the map header from memory.
*
* @param buffer a pointer to an buffer which contains bytes describing a map header
* @param i the index where to start reading from
*/
void initFromMemory(const ui8 * buffer, int & i);
/**
* Loads victory/loss conditions.
*
* @param buffer a pointer to an buffer which contains bytes describing a map header
* @param i the index where to start reading from
*/
void loadViCLossConditions(const ui8 * buffer, int & i);
/**
* Loads information about players.
*
* @param pom
* @param buffer a pointer to an buffer which contains bytes describing a map header
* @param i the index where to start reading from
*/
void loadPlayerInfo(int & pom, const ui8 * buffer, int & i);
/** the version of the map */
EMapFormat::EMapFormat version;
@ -601,6 +567,100 @@ public:
class DLL_LINKAGE CMap : public CMapHeader
{
public:
/**
* Default constructor.
*/
CMap();
/**
* Destructor.
*/
~CMap();
/**
* Erases an artifact instance.
*
* @param art the artifact to erase
*/
void eraseArtifactInstance(CArtifactInstance * art);
/**
* Gets the topmost object or the lowermost object depending on the flag
* lookForHero from the specified position.
*
* @param pos the position of the tile
* @param lookForHero true if you want to get the lowermost object, false if
* you want to get the topmost object
* @return the object at the given position and level
*/
const CGObjectInstance * getObjectiveObjectFrom(int3 pos, bool lookForHero);
/**
* Sets the victory/loss condition objectives.
*/
void checkForObjectives();
/**
* Adds an visitable/blocking object to a terrain tile.
*
* @param obj the visitable/blocking object to add to a tile
*/
void addBlockVisTiles(CGObjectInstance * obj);
/**
* Removes an visitable/blocking object from a terrain tile.
*
* @param obj the visitable/blocking object to remove from a tile
* @param total
*/
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
/**
* Gets the terrain tile of the specified position.
*
* @param tile the position of the tile
* @return the terrain tile of the specified position
*/
TerrainTile & getTile(const int3 & tile);
/**
* Gets the terrain tile as a const of the specified position.
*
* @param tile the position of the tile
* @return the terrain tile as a const of the specified position
*/
const TerrainTile & getTile(const int3 & tile) const;
/**
* Gets the hero with the given id.
* @param heroID the hero id
* @return the hero with the given id
*/
CGHeroInstance * getHero(int heroID);
/**
* Validates if the position is in the bounds of the map.
*
* @param pos the position to test
* @return true if the position is in the bounds of the map
*/
bool isInTheMap(const int3 & pos) const;
/**
* Validates if the tile at the given position is a water terrain type.
*
* @param pos the position to test
* @return true if the tile at the given position is a water terrain type
*/
bool isWaterTile(const int3 & pos) const;
/**
* Adds the specified artifact instance to the list of artifacts of this map.
*
* @param art the artifact which should be added to the list of artifacts
*/
void addNewArtifactInstance(CArtifactInstance * art);
/** the checksum of the map */
ui32 checksum;
@ -655,254 +715,6 @@ public:
/** associative list to identify which hero/creature id belongs to which object id(index for objects) */
bmap<si32, si32> questIdentifierToId;
/**
* Creates map from decompressed .h3m data.
*
* @param buffer a pointer to an buffer which contains bytes describing a map
* @param size the length of the buffer
*/
void initFromBytes(const ui8 * buffer, size_t size);
/**
* Reads events from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
*/
void readEvents(const ui8 * buffer, int & i);
/**
* Reads objects from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing objects
* @param i the index where to start reading from
*/
void readObjects(const ui8 * buffer, int & i);
/**
* Loads quest information and stores that to a quest guard object.
*
* @param guard the quest guard object where the quest info should be applied to
* @param buffer a pointer to an buffer which contains bytes describing objects
* @param i the index where to start reading from
*/
void loadQuest(IQuestObject * guard, const ui8 * buffer, int & i);
/**
* Reads def information from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing def information
* @param i the index where to start reading from
*/
void readDefInfo(const ui8 * buffer, int & i);
/**
* Reads terrain data from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing terrain data
* @param i the index where to start reading from
*/
void readTerrain(const ui8 * buffer, int & i);
/**
* Reads predefined heroes from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
*/
void readPredefinedHeroes(const ui8 * buffer, int & i);
/**
* Reads events from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
*/
void readHeader(const ui8 * buffer, int & i);
/**
* Reads events from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
*/
void readRumors(const ui8 * buffer, int & i);
/**
* Loads a hero from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
* @param idToBeGiven the object id which should be set for the hero
* @return a object instance
*/
CGObjectInstance * loadHero(const ui8 * buffer, int & i, int idToBeGiven);
/**
* Loads artifacts of a hero from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
* @param hero the hero which should hold those artifacts
*/
void loadArtifactsOfHero(const ui8 * buffer, int & i, CGHeroInstance * hero);
/**
* Loads an artifact from a buffer 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
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
* @return true if it loaded an artifact
*/
bool loadArtifactToSlot(CGHeroInstance * hero, int slot, const ui8 * buffer, int & i);
/**
* Loads a town from a buffer.
*
* @param town a pointer to a town object which gets filled by data
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
* @param castleID the id of the castle type
*/
void loadTown(CGObjectInstance * & town, const ui8 * buffer, int & i, int castleID);
/**
* Loads a seer hut from a buffer.
*
* @param buffer a pointer to an buffer which contains bytes describing events
* @param i the index where to start reading from
* @param seerHut the seer hut object which gets filled by data
* @return index of the reading position of the buffer
*/
int loadSeerHut(const ui8 * buffer, int i, CGObjectInstance * & seerHut);
/**
* 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 * createArt(int aid, int spellID = -1);
/**
* Adds the specified artifact instance to the list of artifacts of this map.
*
* @param art the artifact which should be added to the list of artifacts
*/
void addNewArtifactInstance(CArtifactInstance * art);
/**
* Adds a quest to the list of quests of this map.
*
* @param quest the quest object which should be added to the list of quests
*/
void addQuest(CGObjectInstance * quest);
/**
* Erases an artifact instance.
*
* @param art the artifact to erase
*/
void eraseArtifactInstance(CArtifactInstance * art);
/**
* Gets the topmost object or the lowermost object depending on the flag
* lookForHero from the specified position.
*
* @param pos the position of the tile
* @param lookForHero true if you want to get the lowermost object, false if
* you want to get the topmost object
* @return the object at the given position and level
*/
const CGObjectInstance * getObjectiveObjectFrom(int3 pos, bool lookForHero);
/**
* Sets the victory/loss condition objectives.
*/
void checkForObjectives();
/**
* Adds an visitable/blocking object to a terrain tile.
*
* @param obj the visitable/blocking object to add to a tile
*/
void addBlockVisTiles(CGObjectInstance * obj);
/**
* Removes an visitable/blocking object from a terrain tile.
*
* @param obj the visitable/blocking object to remove from a tile
* @param total
*/
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
/**
* Constructor. Creates a map from file.
*
* @param filename the name of the h3m map file
*/
CMap(std::string filename);
/**
* Default constructor.
*/
CMap();
/**
* Destructor.
*/
~CMap();
/**
* Gets the terrain tile of the specified position.
*
* @param tile the position of the tile
* @return the terrain tile of the specified position
*/
TerrainTile & getTile(const int3 & tile);
/**
* Gets the terrain tile as a const of the specified position.
*
* @param tile the position of the tile
* @return the terrain tile as a const of the specified position
*/
const TerrainTile & getTile(const int3 & tile) const;
/**
* Gets the hero with the given id.
* @param heroID the hero id
* @return the hero with the given id
*/
CGHeroInstance * getHero(int heroID);
/**
* Validates if the position is in the bounds of the map.
*
* @param pos the position to test
* @return true if the position is in the bounds of the map
*/
bool isInTheMap(const int3 & pos) const;
/**
* Validates if the tile at the given position is a water terrain type.
*
* @param pos the position to test
* @return true if the tile at the given position is a water terrain type
*/
bool isWaterTile(const int3 & pos) const;
/**
* Gets a input stream from the given map name.
*
* @param name the name of the map
* @return a unique ptr to the input stream
*/
static TInputStreamPtr getMapStream(std::string name);
/**
* Serialize method.
*/

49
lib/Map/CMapInfo.cpp Normal file
View File

@ -0,0 +1,49 @@
#include "StdInc.h"
#include "CMapInfo.h"
#include "../StartInfo.h"
#include "CMap.h"
#include "CCampaignHandler.h"
#include "../GameConstants.h"
#include "CMapService.h"
void CMapInfo::countPlayers()
{
actualHumanPlayers = playerAmnt = humanPlayers = 0;
for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
{
if(mapHeader->players[i].canHumanPlay)
{
playerAmnt++;
humanPlayers++;
}
else if(mapHeader->players[i].canComputerPlay)
{
playerAmnt++;
}
}
if(scenarioOpts)
for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
if(i->second.human)
actualHumanPlayers++;
}
CMapInfo::CMapInfo() : mapHeader(nullptr), campaignHeader(nullptr),
scenarioOpts(nullptr)
{
}
void CMapInfo::mapInit(const std::string & fname)
{
fileURI = fname;
mapHeader = CMapService::loadMapHeader(fname);
countPlayers();
}
void CMapInfo::campaignInit()
{
campaignHeader = std::unique_ptr<CCampaignHeader>(new CCampaignHeader(CCampaignHandler::getHeader(fileURI)));
}

42
lib/Map/CMapInfo.h Normal file
View File

@ -0,0 +1,42 @@
#pragma once
// Forward class declarations aren't enough here. The compiler
// generated CMapInfo d-tor, generates the unique_ptr d-tor as well here
// as a inline method. The unique_ptr d-tor requires a complete type. Defining
// the CMapInfo d-tor to let the compiler add the d-tor stuff in the .cpp file
// would work with one exception. It prevents the generation of the move
// constructor which is needed. (Writing such a c-tor is nasty.) With the
// new c++11 keyword "default" for constructors this problem could be solved. But it isn't
// available for Visual Studio for now. (Empty d-tor in .cpp would be required anyway)
#include "CMap.h"
#include "CCampaignHandler.h"
struct StartInfo;
/**
* A class which stores the count of human players and all players, the filename,
* scenario options, the map header information,...
*/
class DLL_LINKAGE CMapInfo
{
public:
std::unique_ptr<CMapHeader> mapHeader; //may be nullptr if campaign
std::unique_ptr<CCampaignHeader> campaignHeader; //may be nullptr if scenario
StartInfo * scenarioOpts; //options with which scenario has been started (used only with saved games)
std::string fileURI;
std::string date;
int playerAmnt; //players in map
int humanPlayers; //players ALLOWED to be controlled by human
int actualHumanPlayers; // >1 if multiplayer game
CMapInfo();
void mapInit(const std::string & fname);
void campaignInit();
void countPlayers();
template <typename Handler> void serialize(Handler &h, const int Version)
{
h & mapHeader & campaignHeader & scenarioOpts & fileURI & date & playerAmnt & humanPlayers;
h & actualHumanPlayers;
}
};

2543
lib/Map/CMapService.cpp Normal file

File diff suppressed because it is too large Load Diff

361
lib/Map/CMapService.h Normal file
View File

@ -0,0 +1,361 @@
/*
* CMapService.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
class CMap;
class CMapHeader;
class CInputStream;
class CGHeroInstance;
class CArtifactInstance;
class CGObjectInstance;
class CGSeerHut;
class IQuestObject;
class CGTownInstance;
class CCreatureSet;
class CInputStream;
class IMapLoader;
/**
* The map service provides loading of VCMI/H3 map files. It can
* be extended to save maps later as well.
*/
class DLL_LINKAGE CMapService
{
public:
/**
* Loads the VCMI/H3 map file specified by the name.
*
* @param name the name of the map
* @return a unique ptr to the loaded map class
*/
static std::unique_ptr<CMap> loadMap(const std::string & name);
/**
* Loads the VCMI/H3 map header specified by the name.
*
* @param name the name of the map
* @return a unique ptr to the loaded map header class
*/
static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
/**
* Loads the VCMI/H3 map file from a buffer. This method is temporarily
* in use to ease the transition to use the new map service.
*
* TODO Replace method params with a CampaignMapInfo struct which contains
* a campaign loading object + name of map.
*
* @param buffer a pointer to a buffer containing the map data
* @param size the size of the buffer
* @return a unique ptr to the loaded map class
*/
static std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size);
/**
* Loads the VCMI/H3 map header from a buffer. This method is temporarily
* in use to ease the transition to use the new map service.
*
* TODO Replace method params with a CampaignMapInfo struct which contains
* a campaign loading object + name of map.
*
* @param buffer a pointer to a buffer containing the map header data
* @param size the size of the buffer
* @return a unique ptr to the loaded map class
*/
static std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size);
private:
/**
* Gets a map input stream object specified by a map name.
*
* @param name the name of the map
* @return a unique ptr to the input stream class
*/
static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
/**
* Gets a map input stream from a buffer.
*
* @param buffer a pointer to a buffer containing the map data
* @param size the size of the buffer
* @return a unique ptr to the input stream class
*/
static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
/**
* Gets a map loader from the given stream. It performs checks to test
* in which map format the map is.
*
* @param stream the input map stream
* @return the constructed map loader
*/
static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
};
/**
* Interface for loading a map.
*/
class DLL_LINKAGE IMapLoader
{
public:
/**
* Loads the VCMI/H3 map file.
*
* @return a unique ptr of the loaded map class
*/
virtual std::unique_ptr<CMap> loadMap() = 0;
/**
* Loads the VCMI/H3 map header.
*
* @return a unique ptr of the loaded map header class
*/
virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
};
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);
/**
* Adds the specified artifact instance to the list of artifacts of this map.
*
* @param art the artifact which should be added to the list of artifacts
*/
void addNewArtifactInstance(CArtifactInstance * art);
/**
* 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
* @param version true for > ROE maps
*/
void readCreatureSet(CCreatureSet * out, int number, bool version);
/**
* Reads a hero.
*
* @param idToBeGiven the object id which should be set for the hero
* @return a object instance
*/
CGObjectInstance * readHero(int idToBeGiven);
/**
* Reads a seer hut.
*
* @return the initialized seer hut object
*/
CGSeerHut * readSeerHut();
/**
* Reads a quest for the given quest guard.
*
* @param guard the quest guard where that quest should be applied to
*/
void readQuest(IQuestObject * guard);
/**
* Adds the specified quest instance to the list of quests.
*
* @param quest the quest object which should be added to the list of quests
*/
void addQuest(CGObjectInstance * quest);
/**
* Reads a town.
*
* @param castleID the id of the castle type
* @return the loaded town object
*/
CGTownInstance * readTown(int castleID);
/**
* Converts buildings to the specified castle id.
*
* @param h3m the ids of the buildings
* @param castleID the castle id
* @param addAuxiliary true if the village hall should be added
* @return the converted buildings
*/
std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary = true);
/**
* Reads events.
*/
void readEvents();
/**
* Adds object instance to block visitable tiles.
*
* @param obj the object to add
*/
void addBlockVisibleTiles(CGObjectInstance * obj);
/**
* Reverses the input argument.
*
* @param arg the input argument
* @return the reversed 8-bit integer
*/
ui8 reverse(ui8 arg);
/**
* Init buffer / size.
*
* @param stream the stream which serves as the data input
*/
void initBuffer(CInputStream * stream);
/** 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;
/** pointer to the array containing the map data;
* TODO replace with CBinaryReader later (this makes pos & size redundant) */
ui8 * buffer;
/** current buffer reading position */
int pos;
/** size of the map in bytes */
int size;
};

View File

@ -5,7 +5,7 @@
#include "BattleAction.h"
#include "HeroBonus.h"
#include "CCreatureSet.h"
#include "CMapInfo.h"
#include "Map/CMapInfo.h"
#include "StartInfo.h"
#include "ConstTransitivePtr.h"
#include "int3.h"

View File

@ -8,7 +8,7 @@
#include "CObjectHandler.h"
#include "CModHandler.h"
#include "VCMI_Lib.h"
#include "map.h"
#include "Map/CMap.h"
#include "CSpellHandler.h"
#include "CCreatureHandler.h"
#include "CGameState.h"

View File

@ -225,7 +225,6 @@
<ClCompile Include="BattleState.cpp" />
<ClCompile Include="CArtHandler.cpp" />
<ClCompile Include="CBuildingHandler.cpp" />
<ClCompile Include="CCampaignHandler.cpp" />
<ClCompile Include="CConfigHandler.cpp" />
<ClCompile Include="CConsoleHandler.cpp" />
<ClCompile Include="CCreatureHandler.cpp" />
@ -236,7 +235,6 @@
<ClCompile Include="CGeneralTextHandler.cpp" />
<ClCompile Include="CHeroHandler.cpp" />
<ClCompile Include="CLogger.cpp" />
<ClCompile Include="CMapInfo.cpp" />
<ClCompile Include="CModHandler.cpp" />
<ClCompile Include="CObjectHandler.cpp" />
<ClCompile Include="CObstacleInstance.cpp" />
@ -252,11 +250,14 @@
<ClCompile Include="Filesystem\CLodArchiveLoader.cpp" />
<ClCompile Include="Filesystem\CMemoryStream.cpp" />
<ClCompile Include="Filesystem\CResourceLoader.cpp" />
<ClCompile Include="Map\CCampaignHandler.cpp" />
<ClCompile Include="Map\CMap.cpp" />
<ClCompile Include="Map\CMapInfo.cpp" />
<ClCompile Include="Map\CMapService.cpp" />
<ClCompile Include="HeroBonus.cpp" />
<ClCompile Include="CBattleCallback.cpp" />
<ClCompile Include="IGameCallback.cpp" />
<ClCompile Include="JsonNode.cpp" />
<ClCompile Include="map.cpp" />
<ClCompile Include="NetPacksLib.cpp" />
<ClCompile Include="ResourceSet.cpp" />
<ClCompile Include="StdInc.cpp">
@ -278,7 +279,6 @@
<ClInclude Include="BattleState.h" />
<ClInclude Include="CArtHandler.h" />
<ClInclude Include="CBuildingHandler.h" />
<ClInclude Include="CCampaignHandler.h" />
<ClInclude Include="CConfigHandler.h" />
<ClInclude Include="CConsoleHandler.h" />
<ClInclude Include="CCreatureHandler.h" />
@ -289,7 +289,6 @@
<ClInclude Include="CGeneralTextHandler.h" />
<ClInclude Include="CHeroHandler.h" />
<ClInclude Include="CLogger.h" />
<ClInclude Include="CMapInfo.h" />
<ClInclude Include="CModHandler.h" />
<ClInclude Include="CObjectHandler.h" />
<ClInclude Include="CObstacleInstance.h" />
@ -311,6 +310,10 @@
<ClInclude Include="Filesystem\CMemoryStream.h" />
<ClInclude Include="Filesystem\CResourceLoader.h" />
<ClInclude Include="Filesystem\ISimpleResourceLoader.h" />
<ClCompile Include="Map\CCampaignHandler.h" />
<ClCompile Include="Map\CMap.h" />
<ClCompile Include="Map\CMapInfo.h" />
<ClCompile Include="Map\CMapService.h" />
<ClInclude Include="GameConstants.h" />
<ClInclude Include="HeroBonus.h" />
<ClInclude Include="CBattleCallback.h" />
@ -319,7 +322,6 @@
<ClInclude Include="int3.h" />
<ClInclude Include="Interprocess.h" />
<ClInclude Include="JsonNode.h" />
<ClInclude Include="map.h" />
<ClInclude Include="NetPacks.h" />
<ClInclude Include="RegisterTypes.h" />
<ClInclude Include="ResourceSet.h" />

File diff suppressed because it is too large Load Diff

View File

@ -44,19 +44,21 @@ static inline ui32 read_unaligned_u32(const void *p)
#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast<const ui32 *>(p)))
#endif
static inline char readChar(const ui8 * bufor, int &i)
static inline char readChar(const ui8 * buffer, int & i)
{
return bufor[i++];
return buffer[i++];
}
static inline std::string readString(const ui8 * bufor, int &i)
static inline std::string readString(const ui8 * buffer, int & i)
{
int len = read_le_u32(bufor + i); i+=4;
int len = read_le_u32(buffer + i);
i += 4;
assert(len >= 0 && len <= 500000); //not too long
std::string ret; ret.reserve(len);
std::string ret;
ret.reserve(len);
for(int gg = 0; gg < len; ++gg)
{
ret += bufor[i++];
ret += buffer[i++];
}
return ret;
}

View File

@ -3,7 +3,7 @@
#include "../lib/Filesystem/CResourceLoader.h"
#include "../lib/Filesystem/CFileInfo.h"
#include "../lib/int3.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/Map/CCampaignHandler.h"
#include "../lib/StartInfo.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
@ -20,7 +20,7 @@
#include "../lib/CondSh.h"
#include "../lib/NetPacks.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/VCMIDirs.h"
#include "../client/CSoundBase.h"
#include "CGameHandler.h"

View File

@ -1,7 +1,7 @@
#include "StdInc.h"
#include "../lib/Filesystem/CResourceLoader.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/Map/CCampaignHandler.h"
#include "../lib/CThreadHelper.h"
#include "../lib/Connection.h"
#include "../lib/CModHandler.h"
@ -16,12 +16,12 @@
#include "zlib.h"
#include "CVCMIServer.h"
#include "../lib/StartInfo.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/Interprocess.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/VCMIDirs.h"
#include "CGameHandler.h"
#include "../lib/CMapInfo.h"
#include "../lib/Map/CMapInfo.h"
#include "../lib/CObjectHandler.h"
#include "../lib/GameConstants.h"

View File

@ -4,7 +4,7 @@
#include "CGameHandler.h"
#include "../lib/CObjectHandler.h"
#include "../lib/IGameCallback.h"
#include "../lib/map.h"
#include "../lib/Map/CMap.h"
#include "../lib/CGameState.h"
#include "../lib/BattleState.h"
#include "../lib/BattleAction.h"