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:
parent
2cd774fe42
commit
a878f5f79a
@ -14,7 +14,7 @@
|
|||||||
#include "../../lib/CObjectHandler.h"
|
#include "../../lib/CObjectHandler.h"
|
||||||
#include "../../lib/Connection.h"
|
#include "../../lib/Connection.h"
|
||||||
#include "../../lib/CGameState.h"
|
#include "../../lib/CGameState.h"
|
||||||
#include "../../lib/map.h"
|
#include "../../lib/Map/CMap.h"
|
||||||
#include "../../lib/NetPacks.h"
|
#include "../../lib/NetPacks.h"
|
||||||
#include "../../lib/CondSh.h"
|
#include "../../lib/CondSh.h"
|
||||||
#include "../../lib/CStopWatch.h"
|
#include "../../lib/CStopWatch.h"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "lib/BattleState.h"
|
#include "lib/BattleState.h"
|
||||||
#include "client/CPlayerInterface.h"
|
#include "client/CPlayerInterface.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "lib/map.h"
|
#include "lib/Map/CMap.h"
|
||||||
#include "lib/CBuildingHandler.h"
|
#include "lib/CBuildingHandler.h"
|
||||||
#include "lib/CDefObjInfoHandler.h"
|
#include "lib/CDefObjInfoHandler.h"
|
||||||
#include "lib/CGeneralTextHandler.h"
|
#include "lib/CGeneralTextHandler.h"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "../CCallback.h"
|
#include "../CCallback.h"
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
#include "../lib/Filesystem/CResourceLoader.h"
|
#include "../lib/Filesystem/CResourceLoader.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/CModHandler.h"
|
#include "../lib/CModHandler.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/CGameState.h"
|
#include "../lib/CGameState.h"
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "../CCreatureWindow.h"
|
#include "../CCreatureWindow.h"
|
||||||
#include "../CVideoHandler.h"
|
#include "../CVideoHandler.h"
|
||||||
#include "../../lib/CTownHandler.h"
|
#include "../../lib/CTownHandler.h"
|
||||||
#include "../../lib/map.h"
|
#include "../../lib/Map/CMap.h"
|
||||||
|
|
||||||
#include "CBattleAnimations.h"
|
#include "CBattleAnimations.h"
|
||||||
#include "CBattleInterfaceClasses.h"
|
#include "CBattleInterfaceClasses.h"
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "../lib/CHeroHandler.h"
|
#include "../lib/CHeroHandler.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/CTownHandler.h"
|
#include "../lib/CTownHandler.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
#include "CPreGame.h"
|
#include "CPreGame.h"
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "CMusicHandler.h"
|
#include "CMusicHandler.h"
|
||||||
#include "../lib/CondSh.h"
|
#include "../lib/CondSh.h"
|
||||||
#include "../lib/NetPacks.h"
|
#include "../lib/NetPacks.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
#include "../lib/CStopWatch.h"
|
#include "../lib/CStopWatch.h"
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "../lib/CTownHandler.h"
|
#include "../lib/CTownHandler.h"
|
||||||
#include "../lib/CHeroHandler.h"
|
#include "../lib/CHeroHandler.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/CCampaignHandler.h"
|
#include "../lib/Map/CCampaignHandler.h"
|
||||||
#include "../lib/CCreatureHandler.h"
|
#include "../lib/CCreatureHandler.h"
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
#include "CMusicHandler.h"
|
#include "CMusicHandler.h"
|
||||||
@ -24,7 +24,7 @@
|
|||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
#include "../lib/Connection.h"
|
#include "../lib/Connection.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "GUIClasses.h"
|
#include "GUIClasses.h"
|
||||||
#include "CPlayerInterface.h"
|
#include "CPlayerInterface.h"
|
||||||
#include "../CCallback.h"
|
#include "../CCallback.h"
|
||||||
@ -41,6 +41,7 @@
|
|||||||
#include "../lib/GameConstants.h"
|
#include "../lib/GameConstants.h"
|
||||||
#include "UIFramework/CGuiHandler.h"
|
#include "UIFramework/CGuiHandler.h"
|
||||||
#include "UIFramework/CIntObjectClasses.h"
|
#include "UIFramework/CIntObjectClasses.h"
|
||||||
|
#include "../lib/Map/CMapService.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CPreGame.cpp, part of VCMI engine
|
* CPreGame.cpp, part of VCMI engine
|
||||||
@ -100,9 +101,8 @@ static void do_quit()
|
|||||||
|
|
||||||
static CMapInfo *mapInfoFromGame()
|
static CMapInfo *mapInfoFromGame()
|
||||||
{
|
{
|
||||||
CMapInfo *ret = new CMapInfo();
|
CMapInfo * ret = new CMapInfo();
|
||||||
CMapHeader *headerCopy = new CMapHeader(*LOCPLINT->cb->getMapHeader()); //will be deleted by CMapInfo d-tor
|
ret->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
|
||||||
ret->setHeader(headerCopy);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,7 +771,7 @@ void CSelectionScreen::changeSelection( const CMapInfo *to )
|
|||||||
SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
|
SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
|
||||||
if(screenType != CMenuScreen::campaignList)
|
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);
|
card->changeSelection(to);
|
||||||
if(screenType != CMenuScreen::campaignList)
|
if(screenType != CMenuScreen::campaignList)
|
||||||
@ -1036,31 +1036,24 @@ std::vector<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
|
|||||||
++iterator;
|
++iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
allItems.resize(ret.size());
|
|
||||||
return ret;
|
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];
|
allItems.clear();
|
||||||
|
for(int i = 0; i < files.size(); ++i)
|
||||||
while(start < allItems.size())
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TInputStreamPtr stream(CMap::getMapStream(files[start].getName()));
|
CMapInfo mapInfo;
|
||||||
int read = stream->read(mapBuffer, 1500);
|
mapInfo.mapInit(files[i].getName());
|
||||||
|
allItems.push_back(std::move(mapInfo));
|
||||||
if(read < 50 || !mapBuffer[4])
|
}
|
||||||
throw std::runtime_error("corrupted map file");
|
catch(std::exception & e)
|
||||||
|
{
|
||||||
allItems[start].mapInit(files[start].getName(), mapBuffer);
|
tlog2 << "Map " << files[i].getName() << " is invalid. Message: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
tlog3 << "\t\tWarning: failed to load map " << files[start].getName() << ": " << 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))
|
if(std::memcmp(sign,"VCMISVG",7))
|
||||||
throw std::runtime_error("not a correct savefile!");
|
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;
|
lf >> *(allItems[i].mapHeader) >> allItems[i].scenarioOpts;
|
||||||
allItems[i].fileURI = files[i].getName();
|
allItems[i].fileURI = files[i].getName();
|
||||||
allItems[i].countPlayers();
|
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
|
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)
|
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;
|
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)
|
bool mapSorter::operator()(const CMapInfo *aaa, const CMapInfo *bbb)
|
||||||
{
|
{
|
||||||
const CMapHeader * a = aaa->mapHeader,
|
const CMapHeader * a = aaa->mapHeader.get(),
|
||||||
* b = bbb->mapHeader;
|
* b = bbb->mapHeader.get();
|
||||||
if(a && b) //if we are sorting scenarios
|
if(a && b) //if we are sorting scenarios
|
||||||
{
|
{
|
||||||
switch (sortBy)
|
switch (sortBy)
|
||||||
@ -2949,10 +2942,10 @@ void CBonusSelection::selectMap( int whichOne )
|
|||||||
ourCampaign->currentMap = whichOne;
|
ourCampaign->currentMap = whichOne;
|
||||||
|
|
||||||
//get header
|
//get header
|
||||||
int i = 0;
|
|
||||||
delete ourHeader;
|
delete ourHeader;
|
||||||
ourHeader = new CMapHeader();
|
std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second;
|
||||||
ourHeader->initFromMemory((const unsigned char*)ourCampaign->camp->mapPieces.find(whichOne)->second.data(), i);
|
auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
|
||||||
|
ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release();
|
||||||
|
|
||||||
std::map<TPlayerColor, std::string> names;
|
std::map<TPlayerColor, std::string> names;
|
||||||
names[1] = settings["general"]["playerName"].String();
|
names[1] = settings["general"]["playerName"].String();
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "../lib/StartInfo.h"
|
#include "../lib/StartInfo.h"
|
||||||
#include "GUIClasses.h"
|
#include "GUIClasses.h"
|
||||||
#include "FunctionList.h"
|
#include "FunctionList.h"
|
||||||
#include "../lib/CMapInfo.h"
|
#include "../lib/Map/CMapInfo.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CPreGame.h, part of VCMI engine
|
* CPreGame.h, part of VCMI engine
|
||||||
@ -142,7 +142,7 @@ class SelectionTab : public CIntObject
|
|||||||
private:
|
private:
|
||||||
CDefHandler *format; //map size
|
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 parseGames(const std::vector<ResourceID> &files, bool multi);
|
||||||
void parseCampaigns(const std::vector<ResourceID> & files );
|
void parseCampaigns(const std::vector<ResourceID> & files );
|
||||||
std::vector<ResourceID> getFiles(std::string dirURI, int resType);
|
std::vector<ResourceID> getFiles(std::string dirURI, int resType);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
|
|
||||||
#include "CMusicHandler.h"
|
#include "CMusicHandler.h"
|
||||||
#include "../lib/CCampaignHandler.h"
|
#include "../lib/Map/CCampaignHandler.h"
|
||||||
#include "../CCallback.h"
|
#include "../CCallback.h"
|
||||||
#include "../lib/CConsoleHandler.h"
|
#include "../lib/CConsoleHandler.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
@ -23,7 +23,7 @@
|
|||||||
#include "../lib/NetPacks.h"
|
#include "../lib/NetPacks.h"
|
||||||
#include "../lib/VCMI_Lib.h"
|
#include "../lib/VCMI_Lib.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "../lib/CSpellHandler.h"
|
#include "../lib/CSpellHandler.h"
|
||||||
#include "../lib/CTownHandler.h"
|
#include "../lib/CTownHandler.h"
|
||||||
#include "../lib/CondSh.h"
|
#include "../lib/CondSh.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
#include "../lib/CStopWatch.h"
|
#include "../lib/CStopWatch.h"
|
||||||
#include "../lib/NetPacks.h"
|
#include "../lib/NetPacks.h"
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "../lib/CHeroHandler.h"
|
#include "../lib/CHeroHandler.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/VCMI_Lib.h"
|
#include "../lib/VCMI_Lib.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "../lib/CSpellHandler.h"
|
#include "../lib/CSpellHandler.h"
|
||||||
#include "CSoundBase.h"
|
#include "CSoundBase.h"
|
||||||
@ -22,7 +22,7 @@
|
|||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
#include "UIFramework/SDL_Extensions.h"
|
#include "UIFramework/SDL_Extensions.h"
|
||||||
#include "BattleInterface/CBattleInterface.h"
|
#include "BattleInterface/CBattleInterface.h"
|
||||||
#include "../lib/CCampaignHandler.h"
|
#include "../lib/Map/CCampaignHandler.h"
|
||||||
#include "../lib/CGameState.h"
|
#include "../lib/CGameState.h"
|
||||||
#include "../lib/BattleState.h"
|
#include "../lib/BattleState.h"
|
||||||
#include "../lib/GameConstants.h"
|
#include "../lib/GameConstants.h"
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "../lib/CTownHandler.h"
|
#include "../lib/CTownHandler.h"
|
||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "CDefHandler.h"
|
#include "CDefHandler.h"
|
||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
#include "../lib/CGeneralTextHandler.h"
|
#include "../lib/CGeneralTextHandler.h"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
|
|
||||||
#include <boost/random/linear_congruential.hpp>
|
#include <boost/random/linear_congruential.hpp>
|
||||||
#include "CCampaignHandler.h"
|
#include "Map/CCampaignHandler.h"
|
||||||
#include "CDefObjInfoHandler.h"
|
#include "CDefObjInfoHandler.h"
|
||||||
#include "CArtHandler.h"
|
#include "CArtHandler.h"
|
||||||
#include "CBuildingHandler.h"
|
#include "CBuildingHandler.h"
|
||||||
@ -15,11 +15,12 @@
|
|||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
#include "VCMI_Lib.h"
|
#include "VCMI_Lib.h"
|
||||||
#include "Connection.h"
|
#include "Connection.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
|
#include "Map/CMapService.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "NetPacks.h"
|
#include "NetPacks.h"
|
||||||
#include "RegisterTypes.h"
|
#include "RegisterTypes.h"
|
||||||
#include "CMapInfo.h"
|
#include "Map/CMapInfo.h"
|
||||||
#include "BattleState.h"
|
#include "BattleState.h"
|
||||||
#include "JsonNode.h"
|
#include "JsonNode.h"
|
||||||
#include "Filesystem/CResourceLoader.h"
|
#include "Filesystem/CResourceLoader.h"
|
||||||
@ -865,16 +866,18 @@ void CGameState::init(StartInfo * si)
|
|||||||
switch(scenarioOps->mode)
|
switch(scenarioOps->mode)
|
||||||
{
|
{
|
||||||
case StartInfo::NEW_GAME:
|
case StartInfo::NEW_GAME:
|
||||||
map = new CMap(scenarioOps->mapname);
|
tlog0 << "Open map file: " << scenarioOps->mapname << std::endl;
|
||||||
|
map = CMapService::loadMap(scenarioOps->mapname).release();
|
||||||
break;
|
break;
|
||||||
case StartInfo::CAMPAIGN:
|
case StartInfo::CAMPAIGN:
|
||||||
{
|
{
|
||||||
|
tlog0 << "Open campaign map file: " << scenarioOps->campState->currentMap << std::endl;
|
||||||
auto campaign = scenarioOps->campState;
|
auto campaign = scenarioOps->campState;
|
||||||
assert(vstd::contains(campaign->camp->mapPieces, scenarioOps->campState->currentMap));
|
assert(vstd::contains(campaign->camp->mapPieces, scenarioOps->campState->currentMap));
|
||||||
|
|
||||||
std::string &mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap];
|
std::string & mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap];
|
||||||
map = new CMap();
|
auto buffer = reinterpret_cast<const ui8 *>(mapContent.data());
|
||||||
map->initFromBytes((const ui8*)mapContent.c_str(), mapContent.size());
|
map = CMapService::loadMap(buffer, mapContent.size()).release();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StartInfo::DUEL:
|
case StartInfo::DUEL:
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include "CCreatureHandler.h"
|
#include "CCreatureHandler.h"
|
||||||
#include "VCMI_Lib.h"
|
#include "VCMI_Lib.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "HeroBonus.h"
|
#include "HeroBonus.h"
|
||||||
|
@ -13,13 +13,16 @@ set(lib_SRCS
|
|||||||
Filesystem/CResourceLoader.cpp
|
Filesystem/CResourceLoader.cpp
|
||||||
Filesystem/CFileInputStream.cpp
|
Filesystem/CFileInputStream.cpp
|
||||||
Filesystem/CCompressedStream.cpp
|
Filesystem/CCompressedStream.cpp
|
||||||
|
Map/CCampaignHandler.cpp
|
||||||
|
Map/CMap.cpp
|
||||||
|
Map/CMapInfo.cpp
|
||||||
|
Map/CMapService.cpp
|
||||||
BattleAction.cpp
|
BattleAction.cpp
|
||||||
BattleHex.cpp
|
BattleHex.cpp
|
||||||
BattleState.cpp
|
BattleState.cpp
|
||||||
CArtHandler.cpp
|
CArtHandler.cpp
|
||||||
CBattleCallback.cpp
|
CBattleCallback.cpp
|
||||||
CBuildingHandler.cpp
|
CBuildingHandler.cpp
|
||||||
CCampaignHandler.cpp
|
|
||||||
CConfigHandler.cpp
|
CConfigHandler.cpp
|
||||||
CConsoleHandler.cpp
|
CConsoleHandler.cpp
|
||||||
CCreatureHandler.cpp
|
CCreatureHandler.cpp
|
||||||
@ -30,7 +33,6 @@ set(lib_SRCS
|
|||||||
CGeneralTextHandler.cpp
|
CGeneralTextHandler.cpp
|
||||||
CHeroHandler.cpp
|
CHeroHandler.cpp
|
||||||
CLogger.cpp
|
CLogger.cpp
|
||||||
CMapInfo.cpp
|
|
||||||
CModHandler.cpp
|
CModHandler.cpp
|
||||||
CObjectHandler.cpp
|
CObjectHandler.cpp
|
||||||
CObstacleInstance.cpp
|
CObstacleInstance.cpp
|
||||||
@ -41,7 +43,6 @@ set(lib_SRCS
|
|||||||
HeroBonus.cpp
|
HeroBonus.cpp
|
||||||
IGameCallback.cpp
|
IGameCallback.cpp
|
||||||
JsonNode.cpp
|
JsonNode.cpp
|
||||||
map.cpp
|
|
||||||
NetPacksLib.cpp
|
NetPacksLib.cpp
|
||||||
ResourceSet.cpp
|
ResourceSet.cpp
|
||||||
VCMI_Lib.cpp
|
VCMI_Lib.cpp
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
@ -16,7 +16,7 @@
|
|||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
#include "NetPacks.h"
|
#include "NetPacks.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
#include <SDL_stdinc.h>
|
#include <SDL_stdinc.h>
|
||||||
#include "CBuildingHandler.h"
|
#include "CBuildingHandler.h"
|
||||||
#include "JsonNode.h"
|
#include "JsonNode.h"
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//for smart objs serialization over net
|
//for smart objs serialization over net
|
||||||
#include "../lib/CMapInfo.h"
|
#include "../lib/Map/CMapInfo.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "BattleState.h"
|
#include "BattleState.h"
|
||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
#include "CCreatureHandler.h"
|
#include "CCreatureHandler.h"
|
||||||
@ -19,7 +19,7 @@
|
|||||||
#include "CHeroHandler.h"
|
#include "CHeroHandler.h"
|
||||||
#include "CSpellHandler.h"
|
#include "CSpellHandler.h"
|
||||||
#include "CTownHandler.h"
|
#include "CTownHandler.h"
|
||||||
#include "CCampaignHandler.h"
|
#include "Map/CCampaignHandler.h"
|
||||||
#include "NetPacks.h"
|
#include "NetPacks.h"
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "ConstTransitivePtr.h"
|
#include "ConstTransitivePtr.h"
|
||||||
#include "CCreatureSet.h" //for CStackInstance
|
#include "CCreatureSet.h" //for CStackInstance
|
||||||
#include "CObjectHandler.h" //for CArmedInstance
|
#include "CObjectHandler.h" //for CArmedInstance
|
||||||
#include "CCampaignHandler.h" //for CCampaignState
|
#include "Map/CCampaignHandler.h" //for CCampaignState
|
||||||
|
|
||||||
const ui32 version = 733;
|
const ui32 version = 733;
|
||||||
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
|
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
|
||||||
|
@ -49,9 +49,9 @@ si64 CFileInputStream::read(ui8 * data, si64 size)
|
|||||||
|
|
||||||
si64 CFileInputStream::seek(si64 position)
|
si64 CFileInputStream::seek(si64 position)
|
||||||
{
|
{
|
||||||
fileStream.seekg(dataStart + std::min(position, dataSize));
|
si64 origin = tell();
|
||||||
|
fileStream.seekg(dataStart + std::min(position, dataSize));
|
||||||
return tell();
|
return tell() - origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CFileInputStream::tell()
|
si64 CFileInputStream::tell()
|
||||||
|
@ -1,45 +1,37 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CMemoryStream.h"
|
#include "CMemoryStream.h"
|
||||||
|
|
||||||
CMemoryStream::CMemoryStream(const ui8 * data, si64 size, bool freeData /*= false*/):
|
CMemoryStream::CMemoryStream(const ui8 * data, si64 size) :
|
||||||
data(data),
|
data(data), size(size), position(0)
|
||||||
size(size),
|
|
||||||
position(0),
|
|
||||||
freeData(freeData)
|
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
CMemoryStream::~CMemoryStream()
|
|
||||||
{
|
|
||||||
if(freeData)
|
|
||||||
{
|
|
||||||
delete[] data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CMemoryStream::read(ui8 * data, si64 size)
|
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;
|
position += size;
|
||||||
return size;
|
return toRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CMemoryStream::seek(si64 position)
|
si64 CMemoryStream::seek(si64 position)
|
||||||
{
|
{
|
||||||
si64 diff = this->position;
|
si64 origin = tell();
|
||||||
this->position = position;
|
this->position = std::min(position, size);
|
||||||
return position - diff;
|
return tell() - origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CMemoryStream::tell()
|
si64 CMemoryStream::tell()
|
||||||
{
|
{
|
||||||
return this->position;
|
return this->position;
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CMemoryStream::skip(si64 delta)
|
si64 CMemoryStream::skip(si64 delta)
|
||||||
{
|
{
|
||||||
this->position += delta;
|
si64 origin = tell();
|
||||||
return delta;
|
this->position += std::min(size - origin, delta);
|
||||||
|
return tell() - origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
si64 CMemoryStream::getSize()
|
si64 CMemoryStream::getSize()
|
||||||
|
@ -20,18 +20,12 @@ class DLL_LINKAGE CMemoryStream : public CInputStream
|
|||||||
{
|
{
|
||||||
public:
|
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 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);
|
CMemoryStream(const ui8 * data, si64 size);
|
||||||
|
|
||||||
/**
|
|
||||||
* D-tor. Frees the data array if the freeData flag was set to true.
|
|
||||||
*/
|
|
||||||
~CMemoryStream();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads n bytes from the stream into the data buffer.
|
* Reads n bytes from the stream into the data buffer.
|
||||||
@ -73,15 +67,12 @@ public:
|
|||||||
si64 getSize();
|
si64 getSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** A pointer to the data array. */
|
/** A pointer to the data array. */
|
||||||
const ui8 * data;
|
const ui8 * data;
|
||||||
|
|
||||||
/** The size in bytes of the array. */
|
/** The size in bytes of the array. */
|
||||||
si64 size;
|
si64 size;
|
||||||
|
|
||||||
/** Current reading position of the stream. */
|
/** Current reading position of the stream. */
|
||||||
si64 position;
|
si64 position;
|
||||||
|
|
||||||
/** Flag which specifies if the data array should be freed in the memory stream's destructor. */
|
|
||||||
bool freeData;
|
|
||||||
};
|
};
|
||||||
|
@ -330,8 +330,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addLoader(std::string mountPoint, shared_ptr<ISimpleResourceLoader> loader, bool writeable);
|
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
|
* Contains lists of same resources which can be accessed uniquely by an
|
||||||
* resource identifier.
|
* resource identifier.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <boost/random/linear_congruential.hpp>
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
|
||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
#include "CHeroHandler.h"
|
#include "CHeroHandler.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CCampaignHandler.h"
|
#include "CCampaignHandler.h"
|
||||||
|
|
||||||
#include "Filesystem/CResourceLoader.h"
|
#include "../Filesystem/CResourceLoader.h"
|
||||||
#include "Filesystem/CCompressedStream.h"
|
#include "../Filesystem/CCompressedStream.h"
|
||||||
#include "../lib/VCMI_Lib.h"
|
#include "../VCMI_Lib.h"
|
||||||
#include "../lib/vcmi_endian.h"
|
#include "../vcmi_endian.h"
|
||||||
#include "CGeneralTextHandler.h"
|
#include "../CGeneralTextHandler.h"
|
||||||
#include "StartInfo.h"
|
#include "../StartInfo.h"
|
||||||
#include "CArtHandler.h" //for hero crossover
|
#include "../CArtHandler.h" //for hero crossover
|
||||||
#include "CObjectHandler.h" //for hero crossover
|
#include "../CObjectHandler.h" //for hero crossover
|
||||||
#include "CHeroHandler.h"
|
#include "../CHeroHandler.h"
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
241
lib/Map/CMap.cpp
Normal file
241
lib/Map/CMap.cpp
Normal 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;
|
||||||
|
}
|
@ -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
|
* 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 CArtifactInstance;
|
||||||
class CGDefInfo;
|
class CGDefInfo;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
@ -31,9 +31,7 @@ class CQuest;
|
|||||||
class CGTownInstance;
|
class CGTownInstance;
|
||||||
class IModableArt;
|
class IModableArt;
|
||||||
class IQuestObject;
|
class IQuestObject;
|
||||||
|
|
||||||
class CInputStream;
|
class CInputStream;
|
||||||
typedef std::unique_ptr<CInputStream> TInputStreamPtr;
|
|
||||||
|
|
||||||
namespace ETerrainType
|
namespace ETerrainType
|
||||||
{
|
{
|
||||||
@ -139,21 +137,21 @@ struct DLL_LINKAGE TerrainTile
|
|||||||
*
|
*
|
||||||
* @return true if the terrain type is water
|
* @return true if the terrain type is water
|
||||||
*/
|
*/
|
||||||
bool isWater() const;
|
bool isWater() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets true if the terrain tile is coastal.
|
* Gets true if the terrain tile is coastal.
|
||||||
*
|
*
|
||||||
* @return true if the terrain tile is coastal
|
* @return true if the terrain tile is coastal
|
||||||
*/
|
*/
|
||||||
bool isCoastal() const;
|
bool isCoastal() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets true if the terrain tile has favourable winds.
|
* Gets true if the terrain tile has favourable winds.
|
||||||
*
|
*
|
||||||
* @return true if the terrain tile has favourable winds
|
* @return true if the terrain tile has favourable winds
|
||||||
*/
|
*/
|
||||||
bool hasFavourableWinds() const;
|
bool hasFavourableWinds() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize method.
|
* Serialize method.
|
||||||
@ -174,22 +172,22 @@ struct DLL_LINKAGE TerrainTile
|
|||||||
/**
|
/**
|
||||||
* The hero name struct consists of the hero id and name.
|
* The hero name struct consists of the hero id and name.
|
||||||
*/
|
*/
|
||||||
struct DLL_LINKAGE SheroName
|
struct DLL_LINKAGE SheroName
|
||||||
{
|
{
|
||||||
/** the id of the hero */
|
/** the id of the hero */
|
||||||
int heroID;
|
int heroID;
|
||||||
|
|
||||||
/** the name of the hero */
|
/** the name of the hero */
|
||||||
std::string heroName;
|
std::string heroName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize method.
|
* Serialize method.
|
||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & heroID & heroName;
|
h & heroID & heroName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -211,10 +209,10 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
ui8 powerPlacehodlers;
|
ui8 powerPlacehodlers;
|
||||||
|
|
||||||
/** player can be played by a human */
|
/** player can be played by a human */
|
||||||
ui8 canHumanPlay;
|
ui8 canHumanPlay;
|
||||||
|
|
||||||
/** player can be played by the computer */
|
/** player can be played by the computer */
|
||||||
ui8 canComputerPlay;
|
ui8 canComputerPlay;
|
||||||
|
|
||||||
/** defines the tactical setting of the AI: 0 - random, 1 - warrior, 2 - builder, 3 - explorer */
|
/** defines the tactical setting of the AI: 0 - random, 1 - warrior, 2 - builder, 3 - explorer */
|
||||||
ui32 AITactic;
|
ui32 AITactic;
|
||||||
@ -229,25 +227,25 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
ui32 mainHeroPortrait;
|
ui32 mainHeroPortrait;
|
||||||
|
|
||||||
/** the name of the main hero */
|
/** the name of the main hero */
|
||||||
std::string mainHeroName;
|
std::string mainHeroName;
|
||||||
|
|
||||||
/** list of available heroes */
|
/** list of available heroes */
|
||||||
std::vector<SheroName> heroesNames;
|
std::vector<SheroName> heroesNames;
|
||||||
|
|
||||||
/** has the player a main town */
|
/** has the player a main town */
|
||||||
ui8 hasMainTown;
|
ui8 hasMainTown;
|
||||||
|
|
||||||
/** generates the hero at the main town */
|
/** generates the hero at the main town */
|
||||||
ui8 generateHeroAtMainTown;
|
ui8 generateHeroAtMainTown;
|
||||||
|
|
||||||
/** the position of the main town */
|
/** the position of the main town */
|
||||||
int3 posOfMainTown;
|
int3 posOfMainTown;
|
||||||
|
|
||||||
/** the team id to which the player belongs to */
|
/** the team id to which the player belongs to */
|
||||||
ui8 team;
|
ui8 team;
|
||||||
|
|
||||||
/** unused. generates a hero */
|
/** unused. generates a hero */
|
||||||
ui8 generateHero;
|
ui8 generateHero;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@ -273,11 +271,11 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & AITactic & allowedFactions & isFactionRandom &
|
h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & AITactic & allowedFactions & isFactionRandom &
|
||||||
mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
|
mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
|
||||||
posOfMainTown & team & generateHero;
|
posOfMainTown & team & generateHero;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,10 +284,10 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
struct DLL_LINKAGE LossCondition
|
struct DLL_LINKAGE LossCondition
|
||||||
{
|
{
|
||||||
/** specifies the condition type */
|
/** specifies the condition type */
|
||||||
ELossConditionType::ELossConditionType typeOfLossCon;
|
ELossConditionType::ELossConditionType typeOfLossCon;
|
||||||
|
|
||||||
/** the position of an object which mustn't be lost */
|
/** the position of an object which mustn't be lost */
|
||||||
int3 pos;
|
int3 pos;
|
||||||
|
|
||||||
/** time limit in days, -1 if not used */
|
/** time limit in days, -1 if not used */
|
||||||
si32 timeLimit;
|
si32 timeLimit;
|
||||||
@ -307,9 +305,9 @@ struct DLL_LINKAGE LossCondition
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & typeOfLossCon & pos & timeLimit & obj;
|
h & typeOfLossCon & pos & timeLimit & obj;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -349,9 +347,9 @@ struct DLL_LINKAGE VictoryCondition
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & condition & allowNormalVictory & appliesToAI & pos & ID & count & obj;
|
h & condition & allowNormalVictory & appliesToAI & pos & ID & count & obj;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -370,9 +368,9 @@ struct DLL_LINKAGE Rumor
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & name & text;
|
h & name & text;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -381,13 +379,13 @@ struct DLL_LINKAGE Rumor
|
|||||||
struct DLL_LINKAGE DisposedHero
|
struct DLL_LINKAGE DisposedHero
|
||||||
{
|
{
|
||||||
/** the id of the hero */
|
/** the id of the hero */
|
||||||
ui32 ID;
|
ui32 ID;
|
||||||
|
|
||||||
/** the portrait id of the hero, 0xFF is default */
|
/** the portrait id of the hero, 0xFF is default */
|
||||||
ui16 portrait;
|
ui16 portrait;
|
||||||
|
|
||||||
/** the name of the hero */
|
/** the name of the hero */
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
/** who can hire this hero (bitfield) */
|
/** who can hire this hero (bitfield) */
|
||||||
ui8 players;
|
ui8 players;
|
||||||
@ -397,9 +395,9 @@ struct DLL_LINKAGE DisposedHero
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & ID & portrait & name & players;
|
h & ID & portrait & name & players;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Class which manages map events.
|
/// Class which manages map events.
|
||||||
@ -424,13 +422,13 @@ public:
|
|||||||
ui8 players;
|
ui8 players;
|
||||||
|
|
||||||
/** affected humans */
|
/** affected humans */
|
||||||
ui8 humanAffected;
|
ui8 humanAffected;
|
||||||
|
|
||||||
/** affacted computer players */
|
/** affacted computer players */
|
||||||
ui8 computerAffected;
|
ui8 computerAffected;
|
||||||
|
|
||||||
/** the day counted continously where the event happens */
|
/** the day counted continously where the event happens */
|
||||||
ui32 firstOccurence;
|
ui32 firstOccurence;
|
||||||
|
|
||||||
/** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
|
/** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
|
||||||
ui32 nextOccurence;
|
ui32 nextOccurence;
|
||||||
@ -449,10 +447,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & name & message & resources
|
h & name & message & resources
|
||||||
& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
|
& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -475,10 +473,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & static_cast<CMapEvent &>(*this);
|
h & static_cast<CMapEvent &>(*this);
|
||||||
h & buildings & creatures;
|
h & buildings & creatures;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace EMapFormat
|
namespace EMapFormat
|
||||||
@ -502,42 +500,10 @@ public:
|
|||||||
CMapHeader();
|
CMapHeader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* D-tor.
|
||||||
*
|
|
||||||
* @param map a pointer to an buffer which contains bytes describing a map header
|
|
||||||
*/
|
|
||||||
CMapHeader(const ui8 * map);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
*/
|
*/
|
||||||
virtual ~CMapHeader();
|
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 */
|
/** the version of the map */
|
||||||
EMapFormat::EMapFormat version;
|
EMapFormat::EMapFormat version;
|
||||||
|
|
||||||
@ -566,7 +532,7 @@ public:
|
|||||||
ui8 levelLimit;
|
ui8 levelLimit;
|
||||||
|
|
||||||
/** the loss condition */
|
/** the loss condition */
|
||||||
LossCondition lossCondition;
|
LossCondition lossCondition;
|
||||||
|
|
||||||
/** the victory condition */
|
/** the victory condition */
|
||||||
VictoryCondition victoryCondition;
|
VictoryCondition victoryCondition;
|
||||||
@ -575,7 +541,7 @@ public:
|
|||||||
std::vector<PlayerInfo> players;
|
std::vector<PlayerInfo> players;
|
||||||
|
|
||||||
/** number of teams */
|
/** number of teams */
|
||||||
ui8 howManyTeams;
|
ui8 howManyTeams;
|
||||||
|
|
||||||
/** list of allowed heroes, index is hero id */
|
/** list of allowed heroes, index is hero id */
|
||||||
std::vector<ui8> allowedHeroes;
|
std::vector<ui8> allowedHeroes;
|
||||||
@ -588,10 +554,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int Version)
|
void serialize(Handler & h, const int Version)
|
||||||
{
|
{
|
||||||
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPLayers;
|
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPLayers;
|
||||||
h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes;
|
h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -601,205 +567,15 @@ public:
|
|||||||
class DLL_LINKAGE CMap : public CMapHeader
|
class DLL_LINKAGE CMap : public CMapHeader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** the checksum of the map */
|
/**
|
||||||
ui32 checksum;
|
* Default constructor.
|
||||||
|
*/
|
||||||
/** a 3-dimensional array of terrain tiles, access is as follows: x, y, level */
|
CMap();
|
||||||
TerrainTile*** terrain;
|
|
||||||
|
|
||||||
/** list of rumors */
|
|
||||||
std::vector<Rumor> rumors;
|
|
||||||
|
|
||||||
/** list of disposed heroes */
|
|
||||||
std::vector<DisposedHero> disposedHeroes;
|
|
||||||
|
|
||||||
/** list of predefined heroes */
|
|
||||||
std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
|
|
||||||
|
|
||||||
/** list of .def files with definitions from .h3m (may be custom) */
|
|
||||||
std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
|
|
||||||
|
|
||||||
/** list of allowed spells, index is the spell id */
|
|
||||||
std::vector<ui8> allowedSpell;
|
|
||||||
|
|
||||||
/** list of allowed artifacts, index is the artifact id */
|
|
||||||
std::vector<ui8> allowedArtifact;
|
|
||||||
|
|
||||||
/** list of allowed abilities, index is the ability id */
|
|
||||||
std::vector<ui8> allowedAbilities;
|
|
||||||
|
|
||||||
/** list of map events */
|
|
||||||
std::list<ConstTransitivePtr<CMapEvent> > events;
|
|
||||||
|
|
||||||
/** specifies the position of the grail */
|
|
||||||
int3 grailPos;
|
|
||||||
|
|
||||||
/** specifies the radius of the grail */
|
|
||||||
int grailRadious;
|
|
||||||
|
|
||||||
/** list of objects */
|
|
||||||
std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
|
|
||||||
|
|
||||||
/** list of heroes */
|
|
||||||
std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
|
|
||||||
|
|
||||||
/** list of towns */
|
|
||||||
std::vector< ConstTransitivePtr<CGTownInstance> > towns;
|
|
||||||
|
|
||||||
/** list of artifacts */
|
|
||||||
std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
|
|
||||||
|
|
||||||
/** list of quests */
|
|
||||||
std::vector< ConstTransitivePtr<CQuest> > quests;
|
|
||||||
|
|
||||||
/** 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.
|
* Destructor.
|
||||||
*
|
|
||||||
* @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);
|
~CMap();
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Erases an artifact instance.
|
||||||
@ -822,14 +598,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Sets the victory/loss condition objectives.
|
* Sets the victory/loss condition objectives.
|
||||||
*/
|
*/
|
||||||
void checkForObjectives();
|
void checkForObjectives();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an visitable/blocking object to a terrain tile.
|
* Adds an visitable/blocking object to a terrain tile.
|
||||||
*
|
*
|
||||||
* @param obj the visitable/blocking object to add to a tile
|
* @param obj the visitable/blocking object to add to a tile
|
||||||
*/
|
*/
|
||||||
void addBlockVisTiles(CGObjectInstance * obj);
|
void addBlockVisTiles(CGObjectInstance * obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an visitable/blocking object from a terrain tile.
|
* Removes an visitable/blocking object from a terrain tile.
|
||||||
@ -839,23 +615,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
|
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.
|
* Gets the terrain tile of the specified position.
|
||||||
*
|
*
|
||||||
@ -896,27 +655,80 @@ public:
|
|||||||
bool isWaterTile(const int3 & pos) const;
|
bool isWaterTile(const int3 & pos) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a input stream from the given map name.
|
* Adds the specified artifact instance to the list of artifacts of this map.
|
||||||
*
|
*
|
||||||
* @param name the name of the map
|
* @param art the artifact which should be added to the list of artifacts
|
||||||
* @return a unique ptr to the input stream
|
|
||||||
*/
|
*/
|
||||||
static TInputStreamPtr getMapStream(std::string name);
|
void addNewArtifactInstance(CArtifactInstance * art);
|
||||||
|
|
||||||
|
/** the checksum of the map */
|
||||||
|
ui32 checksum;
|
||||||
|
|
||||||
|
/** a 3-dimensional array of terrain tiles, access is as follows: x, y, level */
|
||||||
|
TerrainTile*** terrain;
|
||||||
|
|
||||||
|
/** list of rumors */
|
||||||
|
std::vector<Rumor> rumors;
|
||||||
|
|
||||||
|
/** list of disposed heroes */
|
||||||
|
std::vector<DisposedHero> disposedHeroes;
|
||||||
|
|
||||||
|
/** list of predefined heroes */
|
||||||
|
std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
|
||||||
|
|
||||||
|
/** list of .def files with definitions from .h3m (may be custom) */
|
||||||
|
std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
|
||||||
|
|
||||||
|
/** list of allowed spells, index is the spell id */
|
||||||
|
std::vector<ui8> allowedSpell;
|
||||||
|
|
||||||
|
/** list of allowed artifacts, index is the artifact id */
|
||||||
|
std::vector<ui8> allowedArtifact;
|
||||||
|
|
||||||
|
/** list of allowed abilities, index is the ability id */
|
||||||
|
std::vector<ui8> allowedAbilities;
|
||||||
|
|
||||||
|
/** list of map events */
|
||||||
|
std::list<ConstTransitivePtr<CMapEvent> > events;
|
||||||
|
|
||||||
|
/** specifies the position of the grail */
|
||||||
|
int3 grailPos;
|
||||||
|
|
||||||
|
/** specifies the radius of the grail */
|
||||||
|
int grailRadious;
|
||||||
|
|
||||||
|
/** list of objects */
|
||||||
|
std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
|
||||||
|
|
||||||
|
/** list of heroes */
|
||||||
|
std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
|
||||||
|
|
||||||
|
/** list of towns */
|
||||||
|
std::vector< ConstTransitivePtr<CGTownInstance> > towns;
|
||||||
|
|
||||||
|
/** list of artifacts */
|
||||||
|
std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
|
||||||
|
|
||||||
|
/** list of quests */
|
||||||
|
std::vector< ConstTransitivePtr<CQuest> > quests;
|
||||||
|
|
||||||
|
/** associative list to identify which hero/creature id belongs to which object id(index for objects) */
|
||||||
|
bmap<si32, si32> questIdentifierToId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize method.
|
* Serialize method.
|
||||||
*/
|
*/
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler &h, const int formatVersion)
|
void serialize(Handler &h, const int formatVersion)
|
||||||
{
|
{
|
||||||
h & static_cast<CMapHeader&>(*this);
|
h & static_cast<CMapHeader&>(*this);
|
||||||
h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos;
|
h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos;
|
||||||
h & artInstances & quests;
|
h & artInstances & quests;
|
||||||
h & questIdentifierToId;
|
h & questIdentifierToId;
|
||||||
|
|
||||||
//TODO: viccondetails
|
//TODO: viccondetails
|
||||||
if(h.saving)
|
if(h.saving)
|
||||||
{
|
{
|
||||||
// Save terrain
|
// Save terrain
|
||||||
for(int i = 0; i < width ; ++i)
|
for(int i = 0; i < width ; ++i)
|
||||||
{
|
{
|
||||||
@ -924,60 +736,60 @@ public:
|
|||||||
{
|
{
|
||||||
for(int k = 0; k <= twoLevel; ++k)
|
for(int k = 0; k <= twoLevel; ++k)
|
||||||
{
|
{
|
||||||
h & terrain[i][j][k];
|
h & terrain[i][j][k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Load terrain
|
// Load terrain
|
||||||
terrain = new TerrainTile**[width];
|
terrain = new TerrainTile**[width];
|
||||||
for(int ii = 0; ii < width; ++ii)
|
for(int ii = 0; ii < width; ++ii)
|
||||||
{
|
{
|
||||||
terrain[ii] = new TerrainTile*[height];
|
terrain[ii] = new TerrainTile*[height];
|
||||||
for(int jj = 0; jj < height; ++jj)
|
for(int jj = 0; jj < height; ++jj)
|
||||||
{
|
{
|
||||||
terrain[ii][jj] = new TerrainTile[twoLevel + 1];
|
terrain[ii][jj] = new TerrainTile[twoLevel + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i = 0; i < width ; ++i)
|
for(int i = 0; i < width ; ++i)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < height ; ++j)
|
for(int j = 0; j < height ; ++j)
|
||||||
{
|
{
|
||||||
for(int k = 0; k <= twoLevel ; ++k)
|
for(int k = 0; k <= twoLevel ; ++k)
|
||||||
{
|
{
|
||||||
h & terrain[i][j][k];
|
h & terrain[i][j][k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h & customDefs & objects;
|
h & customDefs & objects;
|
||||||
|
|
||||||
// static members
|
// static members
|
||||||
h & CGTeleport::objs;
|
h & CGTeleport::objs;
|
||||||
h & CGTeleport::gates;
|
h & CGTeleport::gates;
|
||||||
h & CGKeys::playerKeyMap;
|
h & CGKeys::playerKeyMap;
|
||||||
h & CGMagi::eyelist;
|
h & CGMagi::eyelist;
|
||||||
h & CGObelisk::obeliskCount & CGObelisk::visited;
|
h & CGObelisk::obeliskCount & CGObelisk::visited;
|
||||||
h & CGTownInstance::merchantArtifacts;
|
h & CGTownInstance::merchantArtifacts;
|
||||||
|
|
||||||
if(!h.saving)
|
if(!h.saving)
|
||||||
{
|
{
|
||||||
for(ui32 i = 0; i < objects.size(); ++i)
|
for(ui32 i = 0; i < objects.size(); ++i)
|
||||||
{
|
{
|
||||||
if(!objects[i]) continue;
|
if(!objects[i]) continue;
|
||||||
|
|
||||||
switch (objects[i]->ID)
|
switch (objects[i]->ID)
|
||||||
{
|
{
|
||||||
case Obj::HERO:
|
case Obj::HERO:
|
||||||
heroes.push_back (static_cast<CGHeroInstance*>(+objects[i]));
|
heroes.push_back (static_cast<CGHeroInstance*>(+objects[i]));
|
||||||
break;
|
break;
|
||||||
case Obj::TOWN:
|
case Obj::TOWN:
|
||||||
towns.push_back (static_cast<CGTownInstance*>(+objects[i]));
|
towns.push_back (static_cast<CGTownInstance*>(+objects[i]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recreate blockvis map
|
// recreate blockvis map
|
||||||
addBlockVisTiles(objects[i]);
|
addBlockVisTiles(objects[i]);
|
||||||
@ -985,46 +797,46 @@ public:
|
|||||||
|
|
||||||
// if hero is visiting/garrisoned in town set appropriate pointers
|
// if hero is visiting/garrisoned in town set appropriate pointers
|
||||||
for(ui32 i = 0; i < heroes.size(); ++i)
|
for(ui32 i = 0; i < heroes.size(); ++i)
|
||||||
{
|
{
|
||||||
int3 vistile = heroes[i]->pos;
|
int3 vistile = heroes[i]->pos;
|
||||||
vistile.x++;
|
vistile.x++;
|
||||||
for(ui32 j = 0; j < towns.size(); ++j)
|
for(ui32 j = 0; j < towns.size(); ++j)
|
||||||
{
|
{
|
||||||
// hero stands on the town entrance
|
// hero stands on the town entrance
|
||||||
if(vistile == towns[j]->pos)
|
if(vistile == towns[j]->pos)
|
||||||
{
|
{
|
||||||
if(heroes[i]->inTownGarrison)
|
if(heroes[i]->inTownGarrison)
|
||||||
{
|
{
|
||||||
towns[j]->garrisonHero = heroes[i];
|
towns[j]->garrisonHero = heroes[i];
|
||||||
removeBlockVisTiles(heroes[i]);
|
removeBlockVisTiles(heroes[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
towns[j]->visitingHero = heroes[i];
|
towns[j]->visitingHero = heroes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
heroes[i]->visitedTown = towns[j];
|
heroes[i]->visitedTown = towns[j];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vistile.x -= 2; //manifest pos
|
vistile.x -= 2; //manifest pos
|
||||||
const TerrainTile & t = getTile(vistile);
|
const TerrainTile & t = getTile(vistile);
|
||||||
if(t.tertype != ETerrainType::WATER) continue;
|
if(t.tertype != ETerrainType::WATER) continue;
|
||||||
|
|
||||||
//hero stands on the water - he must be in the boat
|
//hero stands on the water - he must be in the boat
|
||||||
for(ui32 j = 0; j < t.visitableObjects.size(); ++j)
|
for(ui32 j = 0; j < t.visitableObjects.size(); ++j)
|
||||||
{
|
{
|
||||||
if(t.visitableObjects[j]->ID == Obj::BOAT)
|
if(t.visitableObjects[j]->ID == Obj::BOAT)
|
||||||
{
|
{
|
||||||
CGBoat * b = static_cast<CGBoat *>(t.visitableObjects[j]);
|
CGBoat * b = static_cast<CGBoat *>(t.visitableObjects[j]);
|
||||||
heroes[i]->boat = b;
|
heroes[i]->boat = b;
|
||||||
b->hero = heroes[i];
|
b->hero = heroes[i];
|
||||||
removeBlockVisTiles(b);
|
removeBlockVisTiles(b);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
49
lib/Map/CMapInfo.cpp
Normal file
49
lib/Map/CMapInfo.cpp
Normal 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
42
lib/Map/CMapInfo.h
Normal 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
2543
lib/Map/CMapService.cpp
Normal file
File diff suppressed because it is too large
Load Diff
361
lib/Map/CMapService.h
Normal file
361
lib/Map/CMapService.h
Normal 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;
|
||||||
|
};
|
@ -5,7 +5,7 @@
|
|||||||
#include "BattleAction.h"
|
#include "BattleAction.h"
|
||||||
#include "HeroBonus.h"
|
#include "HeroBonus.h"
|
||||||
#include "CCreatureSet.h"
|
#include "CCreatureSet.h"
|
||||||
#include "CMapInfo.h"
|
#include "Map/CMapInfo.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "ConstTransitivePtr.h"
|
#include "ConstTransitivePtr.h"
|
||||||
#include "int3.h"
|
#include "int3.h"
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
#include "VCMI_Lib.h"
|
#include "VCMI_Lib.h"
|
||||||
#include "map.h"
|
#include "Map/CMap.h"
|
||||||
#include "CSpellHandler.h"
|
#include "CSpellHandler.h"
|
||||||
#include "CCreatureHandler.h"
|
#include "CCreatureHandler.h"
|
||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
|
@ -225,7 +225,6 @@
|
|||||||
<ClCompile Include="BattleState.cpp" />
|
<ClCompile Include="BattleState.cpp" />
|
||||||
<ClCompile Include="CArtHandler.cpp" />
|
<ClCompile Include="CArtHandler.cpp" />
|
||||||
<ClCompile Include="CBuildingHandler.cpp" />
|
<ClCompile Include="CBuildingHandler.cpp" />
|
||||||
<ClCompile Include="CCampaignHandler.cpp" />
|
|
||||||
<ClCompile Include="CConfigHandler.cpp" />
|
<ClCompile Include="CConfigHandler.cpp" />
|
||||||
<ClCompile Include="CConsoleHandler.cpp" />
|
<ClCompile Include="CConsoleHandler.cpp" />
|
||||||
<ClCompile Include="CCreatureHandler.cpp" />
|
<ClCompile Include="CCreatureHandler.cpp" />
|
||||||
@ -236,7 +235,6 @@
|
|||||||
<ClCompile Include="CGeneralTextHandler.cpp" />
|
<ClCompile Include="CGeneralTextHandler.cpp" />
|
||||||
<ClCompile Include="CHeroHandler.cpp" />
|
<ClCompile Include="CHeroHandler.cpp" />
|
||||||
<ClCompile Include="CLogger.cpp" />
|
<ClCompile Include="CLogger.cpp" />
|
||||||
<ClCompile Include="CMapInfo.cpp" />
|
|
||||||
<ClCompile Include="CModHandler.cpp" />
|
<ClCompile Include="CModHandler.cpp" />
|
||||||
<ClCompile Include="CObjectHandler.cpp" />
|
<ClCompile Include="CObjectHandler.cpp" />
|
||||||
<ClCompile Include="CObstacleInstance.cpp" />
|
<ClCompile Include="CObstacleInstance.cpp" />
|
||||||
@ -252,11 +250,14 @@
|
|||||||
<ClCompile Include="Filesystem\CLodArchiveLoader.cpp" />
|
<ClCompile Include="Filesystem\CLodArchiveLoader.cpp" />
|
||||||
<ClCompile Include="Filesystem\CMemoryStream.cpp" />
|
<ClCompile Include="Filesystem\CMemoryStream.cpp" />
|
||||||
<ClCompile Include="Filesystem\CResourceLoader.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="HeroBonus.cpp" />
|
||||||
<ClCompile Include="CBattleCallback.cpp" />
|
<ClCompile Include="CBattleCallback.cpp" />
|
||||||
<ClCompile Include="IGameCallback.cpp" />
|
<ClCompile Include="IGameCallback.cpp" />
|
||||||
<ClCompile Include="JsonNode.cpp" />
|
<ClCompile Include="JsonNode.cpp" />
|
||||||
<ClCompile Include="map.cpp" />
|
|
||||||
<ClCompile Include="NetPacksLib.cpp" />
|
<ClCompile Include="NetPacksLib.cpp" />
|
||||||
<ClCompile Include="ResourceSet.cpp" />
|
<ClCompile Include="ResourceSet.cpp" />
|
||||||
<ClCompile Include="StdInc.cpp">
|
<ClCompile Include="StdInc.cpp">
|
||||||
@ -278,7 +279,6 @@
|
|||||||
<ClInclude Include="BattleState.h" />
|
<ClInclude Include="BattleState.h" />
|
||||||
<ClInclude Include="CArtHandler.h" />
|
<ClInclude Include="CArtHandler.h" />
|
||||||
<ClInclude Include="CBuildingHandler.h" />
|
<ClInclude Include="CBuildingHandler.h" />
|
||||||
<ClInclude Include="CCampaignHandler.h" />
|
|
||||||
<ClInclude Include="CConfigHandler.h" />
|
<ClInclude Include="CConfigHandler.h" />
|
||||||
<ClInclude Include="CConsoleHandler.h" />
|
<ClInclude Include="CConsoleHandler.h" />
|
||||||
<ClInclude Include="CCreatureHandler.h" />
|
<ClInclude Include="CCreatureHandler.h" />
|
||||||
@ -289,7 +289,6 @@
|
|||||||
<ClInclude Include="CGeneralTextHandler.h" />
|
<ClInclude Include="CGeneralTextHandler.h" />
|
||||||
<ClInclude Include="CHeroHandler.h" />
|
<ClInclude Include="CHeroHandler.h" />
|
||||||
<ClInclude Include="CLogger.h" />
|
<ClInclude Include="CLogger.h" />
|
||||||
<ClInclude Include="CMapInfo.h" />
|
|
||||||
<ClInclude Include="CModHandler.h" />
|
<ClInclude Include="CModHandler.h" />
|
||||||
<ClInclude Include="CObjectHandler.h" />
|
<ClInclude Include="CObjectHandler.h" />
|
||||||
<ClInclude Include="CObstacleInstance.h" />
|
<ClInclude Include="CObstacleInstance.h" />
|
||||||
@ -311,6 +310,10 @@
|
|||||||
<ClInclude Include="Filesystem\CMemoryStream.h" />
|
<ClInclude Include="Filesystem\CMemoryStream.h" />
|
||||||
<ClInclude Include="Filesystem\CResourceLoader.h" />
|
<ClInclude Include="Filesystem\CResourceLoader.h" />
|
||||||
<ClInclude Include="Filesystem\ISimpleResourceLoader.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="GameConstants.h" />
|
||||||
<ClInclude Include="HeroBonus.h" />
|
<ClInclude Include="HeroBonus.h" />
|
||||||
<ClInclude Include="CBattleCallback.h" />
|
<ClInclude Include="CBattleCallback.h" />
|
||||||
@ -319,7 +322,6 @@
|
|||||||
<ClInclude Include="int3.h" />
|
<ClInclude Include="int3.h" />
|
||||||
<ClInclude Include="Interprocess.h" />
|
<ClInclude Include="Interprocess.h" />
|
||||||
<ClInclude Include="JsonNode.h" />
|
<ClInclude Include="JsonNode.h" />
|
||||||
<ClInclude Include="map.h" />
|
|
||||||
<ClInclude Include="NetPacks.h" />
|
<ClInclude Include="NetPacks.h" />
|
||||||
<ClInclude Include="RegisterTypes.h" />
|
<ClInclude Include="RegisterTypes.h" />
|
||||||
<ClInclude Include="ResourceSet.h" />
|
<ClInclude Include="ResourceSet.h" />
|
||||||
@ -332,4 +334,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
2281
lib/map.cpp
2281
lib/map.cpp
File diff suppressed because it is too large
Load Diff
@ -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)))
|
#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast<const ui32 *>(p)))
|
||||||
#endif
|
#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
|
assert(len >= 0 && len <= 500000); //not too long
|
||||||
std::string ret; ret.reserve(len);
|
std::string ret;
|
||||||
for(int gg=0; gg<len; ++gg)
|
ret.reserve(len);
|
||||||
|
for(int gg = 0; gg < len; ++gg)
|
||||||
{
|
{
|
||||||
ret += bufor[i++];
|
ret += buffer[i++];
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "../lib/Filesystem/CResourceLoader.h"
|
#include "../lib/Filesystem/CResourceLoader.h"
|
||||||
#include "../lib/Filesystem/CFileInfo.h"
|
#include "../lib/Filesystem/CFileInfo.h"
|
||||||
#include "../lib/int3.h"
|
#include "../lib/int3.h"
|
||||||
#include "../lib/CCampaignHandler.h"
|
#include "../lib/Map/CCampaignHandler.h"
|
||||||
#include "../lib/StartInfo.h"
|
#include "../lib/StartInfo.h"
|
||||||
#include "../lib/CModHandler.h"
|
#include "../lib/CModHandler.h"
|
||||||
#include "../lib/CArtHandler.h"
|
#include "../lib/CArtHandler.h"
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include "../lib/CondSh.h"
|
#include "../lib/CondSh.h"
|
||||||
#include "../lib/NetPacks.h"
|
#include "../lib/NetPacks.h"
|
||||||
#include "../lib/VCMI_Lib.h"
|
#include "../lib/VCMI_Lib.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "../client/CSoundBase.h"
|
#include "../client/CSoundBase.h"
|
||||||
#include "CGameHandler.h"
|
#include "CGameHandler.h"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
|
|
||||||
#include "../lib/Filesystem/CResourceLoader.h"
|
#include "../lib/Filesystem/CResourceLoader.h"
|
||||||
#include "../lib/CCampaignHandler.h"
|
#include "../lib/Map/CCampaignHandler.h"
|
||||||
#include "../lib/CThreadHelper.h"
|
#include "../lib/CThreadHelper.h"
|
||||||
#include "../lib/Connection.h"
|
#include "../lib/Connection.h"
|
||||||
#include "../lib/CModHandler.h"
|
#include "../lib/CModHandler.h"
|
||||||
@ -16,12 +16,12 @@
|
|||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#include "CVCMIServer.h"
|
#include "CVCMIServer.h"
|
||||||
#include "../lib/StartInfo.h"
|
#include "../lib/StartInfo.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/Interprocess.h"
|
#include "../lib/Interprocess.h"
|
||||||
#include "../lib/VCMI_Lib.h"
|
#include "../lib/VCMI_Lib.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
#include "CGameHandler.h"
|
#include "CGameHandler.h"
|
||||||
#include "../lib/CMapInfo.h"
|
#include "../lib/Map/CMapInfo.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/GameConstants.h"
|
#include "../lib/GameConstants.h"
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "CGameHandler.h"
|
#include "CGameHandler.h"
|
||||||
#include "../lib/CObjectHandler.h"
|
#include "../lib/CObjectHandler.h"
|
||||||
#include "../lib/IGameCallback.h"
|
#include "../lib/IGameCallback.h"
|
||||||
#include "../lib/map.h"
|
#include "../lib/Map/CMap.h"
|
||||||
#include "../lib/CGameState.h"
|
#include "../lib/CGameState.h"
|
||||||
#include "../lib/BattleState.h"
|
#include "../lib/BattleState.h"
|
||||||
#include "../lib/BattleAction.h"
|
#include "../lib/BattleAction.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user