2008-06-19 09:08:05 +03:00
|
|
|
#define VCMI_DLL
|
2007-06-28 13:47:28 +03:00
|
|
|
#include "stdafx.h"
|
2007-06-20 15:00:18 +03:00
|
|
|
#include "map.h"
|
2008-06-21 16:27:52 +03:00
|
|
|
#include "hch/CObjectHandler.h"
|
|
|
|
#include "hch/CDefObjInfoHandler.h"
|
|
|
|
#include "lib/VCMI_Lib.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
#include <zlib.h>
|
|
|
|
#include <boost/crc.hpp>
|
2008-08-01 14:21:15 +03:00
|
|
|
std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
|
|
|
std::map<int,int> mapa;
|
2008-08-01 14:21:15 +03:00
|
|
|
std::set<si32> ret;
|
2008-06-21 16:27:52 +03:00
|
|
|
std::ifstream b5("config/buildings5.txt");
|
|
|
|
while(!b5.eof())
|
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
b5 >> a >> b;
|
|
|
|
if(castleID==8 && b==17) //magic university ID 17 (h3m) => 21 (vcmi)
|
|
|
|
b=21;
|
|
|
|
mapa[a]=b;
|
|
|
|
}
|
|
|
|
|
2008-08-01 14:21:15 +03:00
|
|
|
for(std::set<si32>::const_iterator i=h3m.begin();i!=h3m.end();i++)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
|
|
|
if(mapa[*i]>=0)
|
|
|
|
ret.insert(mapa[*i]);
|
|
|
|
else if(mapa[*i] >= (-CREATURES_PER_TOWN)) // horde buildings
|
|
|
|
{
|
|
|
|
int level = (-mapa[*i]);
|
|
|
|
if(h3m.find(20+(level*3)) != h3m.end()) //upgraded creature horde building
|
|
|
|
{
|
|
|
|
if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5)))
|
|
|
|
ret.insert(25);
|
|
|
|
else
|
|
|
|
ret.insert(19);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5)))
|
|
|
|
ret.insert(24);
|
|
|
|
else
|
|
|
|
ret.insert(18);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-19 15:09:15 +03:00
|
|
|
tlog3<<"Conversion warning: unknown building "<<*i<<" in castle "<<castleID<<std::endl;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.insert(10); //village hall is always present
|
|
|
|
ret.insert(-1); //houses near v.hall / eyecandies
|
|
|
|
ret.insert(-2); //terrain eyecandy, if -1 is used
|
2007-06-20 15:00:18 +03:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
if(ret.find(11)!=ret.end())
|
|
|
|
ret.insert(27);
|
|
|
|
if(ret.find(12)!=ret.end())
|
|
|
|
ret.insert(28);
|
|
|
|
if(ret.find(13)!=ret.end())
|
|
|
|
ret.insert(29);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
unsigned int intPow(unsigned int a, unsigned int b)
|
|
|
|
{
|
|
|
|
unsigned int ret=1;
|
|
|
|
for(int i=0; i<b; ++i)
|
|
|
|
ret*=a;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
unsigned char reverse(unsigned char arg)
|
|
|
|
{
|
|
|
|
unsigned char ret = 0;
|
|
|
|
for (int i=0; i<8;i++)
|
|
|
|
{
|
|
|
|
if(((arg)&(1<<i))>>i)
|
|
|
|
{
|
|
|
|
ret |= (128>>i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EDefType getDefType(CGDefInfo * a)
|
|
|
|
{
|
|
|
|
switch(a->id)
|
|
|
|
{
|
|
|
|
case 5: case 65: case 66: case 67: case 68: case 69:
|
2008-08-04 12:05:52 +03:00
|
|
|
return ARTIFACT_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 6:
|
2008-08-04 12:05:52 +03:00
|
|
|
return PANDORA_DEF; //hanled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 26:
|
2008-08-04 12:05:52 +03:00
|
|
|
return EVENTOBJ_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 33:
|
2008-08-04 12:05:52 +03:00
|
|
|
return GARRISON_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 34: case 70: case 62: //70 - random hero //62 - prison
|
2008-08-04 12:05:52 +03:00
|
|
|
return HERO_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 36:
|
2008-08-04 12:05:52 +03:00
|
|
|
return GRAIL_DEF; //hanled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
|
2008-08-04 12:05:52 +03:00
|
|
|
return PLAYERONLY_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
|
2008-08-04 12:05:52 +03:00
|
|
|
return CREATURES_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 59:
|
2008-08-04 12:05:52 +03:00
|
|
|
return SIGN_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 77:
|
2008-08-04 12:05:52 +03:00
|
|
|
return TOWN_DEF; //can be problematic, but handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 79: case 76:
|
2008-08-04 12:05:52 +03:00
|
|
|
return RESOURCE_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 81:
|
2008-08-04 12:05:52 +03:00
|
|
|
return SCHOLAR_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 83:
|
2008-08-04 12:05:52 +03:00
|
|
|
return SEERHUT_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 91:
|
2008-08-04 12:05:52 +03:00
|
|
|
return SIGN_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 88: case 89: case 90:
|
|
|
|
return SHRINE_DEF; //handled
|
|
|
|
case 93:
|
|
|
|
return SPELLSCROLL_DEF; //handled
|
|
|
|
case 98:
|
2008-08-04 12:05:52 +03:00
|
|
|
return TOWN_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 113:
|
2008-08-04 12:05:52 +03:00
|
|
|
return WITCHHUT_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 214:
|
2008-08-04 12:05:52 +03:00
|
|
|
return HEROPLACEHOLDER_DEF; //partially handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 215:
|
2008-08-04 12:05:52 +03:00
|
|
|
return BORDERGUARD_DEF; //handled by analogy to seer huts ;]
|
2008-06-21 16:27:52 +03:00
|
|
|
case 216:
|
2008-08-04 12:05:52 +03:00
|
|
|
return CREGEN2_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 217:
|
2008-08-04 12:05:52 +03:00
|
|
|
return CREGEN_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 218:
|
2008-08-04 12:05:52 +03:00
|
|
|
return CREGEN3_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
case 219:
|
2008-08-04 12:05:52 +03:00
|
|
|
return GARRISON_DEF; //handled
|
2008-06-21 16:27:52 +03:00
|
|
|
default:
|
2008-08-04 12:05:52 +03:00
|
|
|
return TERRAINOBJ_DEF; // nothing to be handled
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4, bool cyclic = false)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
|
|
|
int ret=0;
|
|
|
|
int amp=1;
|
2008-06-21 16:27:52 +03:00
|
|
|
for (int ir=0; ir<bytCon; ir++)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
ret+=bufor[pos+ir]*amp;
|
|
|
|
amp*=256;
|
|
|
|
}
|
|
|
|
if(cyclic && bytCon<4 && ret>=amp/2)
|
|
|
|
{
|
|
|
|
ret = ret-amp;
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
char readChar(unsigned char * bufor, int &i)
|
|
|
|
{
|
|
|
|
return bufor[i++];
|
|
|
|
}
|
|
|
|
std::string readString(unsigned char * bufor, int &i)
|
|
|
|
{
|
|
|
|
int len = readNormalNr(bufor,i); i+=4;
|
|
|
|
std::string ret; ret.reserve(len);
|
|
|
|
for(int gg=0; gg<len; ++gg)
|
|
|
|
{
|
|
|
|
ret += bufor[i++];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
CCreatureSet readCreatureSet(unsigned char * bufor, int &i, int number, bool version) //version==true for >RoE maps
|
|
|
|
{
|
|
|
|
if(version)
|
|
|
|
{
|
|
|
|
CCreatureSet ret;
|
2008-07-31 16:21:42 +03:00
|
|
|
std::pair<ui32,si32> ins;
|
2008-06-21 16:27:52 +03:00
|
|
|
for(int ir=0;ir<number;ir++)
|
|
|
|
{
|
|
|
|
int rettt = readNormalNr(bufor,i+ir*4, 2);
|
|
|
|
if(rettt==0xffff) continue;
|
|
|
|
if(rettt>32768)
|
|
|
|
rettt = 65536-rettt+VLC->creh->creatures.size()-16;
|
2008-07-31 16:21:42 +03:00
|
|
|
ins.first = rettt;
|
2008-06-21 16:27:52 +03:00
|
|
|
ins.second = readNormalNr(bufor,i+ir*4+2, 2);
|
2008-07-31 16:21:42 +03:00
|
|
|
std::pair<si32,std::pair<ui32,si32> > tt(ir,ins);
|
2008-06-21 16:27:52 +03:00
|
|
|
ret.slots.insert(tt);
|
|
|
|
}
|
|
|
|
i+=number*4;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCreatureSet ret;
|
2008-07-31 16:21:42 +03:00
|
|
|
std::pair<ui32,si32> ins;
|
2008-06-21 16:27:52 +03:00
|
|
|
for(int ir=0;ir<number;ir++)
|
|
|
|
{
|
|
|
|
int rettt = readNormalNr(bufor,i+ir*3, 1);
|
|
|
|
if(rettt==0xff) continue;
|
|
|
|
if(rettt>220)
|
|
|
|
rettt = 256-rettt+VLC->creh->creatures.size()-16;
|
2008-07-31 16:21:42 +03:00
|
|
|
ins.first = rettt;
|
2008-06-21 16:27:52 +03:00
|
|
|
ins.second = readNormalNr(bufor,i+ir*3+1, 2);
|
2008-07-31 16:21:42 +03:00
|
|
|
std::pair<si32,std::pair<ui32,si32> > tt(ir,ins);
|
2008-06-21 16:27:52 +03:00
|
|
|
ret.slots.insert(tt);
|
|
|
|
}
|
|
|
|
i+=number*3;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2007-06-20 15:00:18 +03:00
|
|
|
CMapHeader::CMapHeader(unsigned char *map)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
int i=0;
|
|
|
|
initFromMemory(map,i);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapHeader::CMapHeader()
|
|
|
|
{
|
|
|
|
areAnyPLayers = difficulty = levelLimit = howManyTeams = 0;
|
|
|
|
height = width = twoLevel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHeader::initFromMemory( unsigned char *bufor, int &i )
|
|
|
|
{
|
|
|
|
version = (Eformat)(readNormalNr(bufor,i)); i+=4; //map version
|
|
|
|
areAnyPLayers = readChar(bufor,i); //invalid on some maps
|
|
|
|
height = width = (readNormalNr(bufor,i)); i+=4; // wymiary mapy
|
|
|
|
twoLevel = readChar(bufor,i); //czy sa lochy
|
|
|
|
int pom;
|
|
|
|
name = readString(bufor,i);
|
|
|
|
description= readString(bufor,i);
|
|
|
|
difficulty = readChar(bufor,i); // reading map difficulty
|
|
|
|
if(version != RoE)
|
|
|
|
levelLimit = readChar(bufor,i); // hero level limit
|
2007-08-23 20:38:00 +03:00
|
|
|
else
|
|
|
|
levelLimit = 0;
|
2009-01-06 20:42:20 +02:00
|
|
|
loadPlayerInfo(pom, bufor, i);
|
|
|
|
loadViCLossConditions(bufor, i);
|
|
|
|
|
|
|
|
howManyTeams=bufor[i++]; //read number of teams
|
|
|
|
if(howManyTeams>0) //read team numbers
|
|
|
|
{
|
|
|
|
for(int rr=0; rr<8; ++rr)
|
|
|
|
{
|
|
|
|
players[rr].team=bufor[i++];
|
|
|
|
}
|
2007-08-23 20:38:00 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
}
|
|
|
|
void CMapHeader::loadPlayerInfo( int &pom, unsigned char * bufor, int &i )
|
|
|
|
{
|
2009-01-11 00:08:18 +02:00
|
|
|
players.resize(8);
|
2007-06-20 15:00:18 +03:00
|
|
|
for (pom=0;pom<8;pom++)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].canHumanPlay = bufor[i++];
|
|
|
|
players[pom].canComputerPlay = bufor[i++];
|
|
|
|
if ((!(players[pom].canHumanPlay || players[pom].canComputerPlay)))
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
memset(&players[pom],0,sizeof(PlayerInfo));
|
2007-08-23 20:38:00 +03:00
|
|
|
switch(version)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
case SoD: case WoG:
|
2007-08-23 20:38:00 +03:00
|
|
|
i+=13;
|
|
|
|
break;
|
2008-08-02 18:08:03 +03:00
|
|
|
case AB:
|
2007-08-23 20:38:00 +03:00
|
|
|
i+=12;
|
|
|
|
break;
|
2008-08-02 18:08:03 +03:00
|
|
|
case RoE:
|
2007-08-23 20:38:00 +03:00
|
|
|
i+=6;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-20 15:00:18 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].AITactic = bufor[i++];
|
2007-08-23 20:38:00 +03:00
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
if(version == SoD || version == WoG)
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].p7= bufor[i++];
|
|
|
|
else
|
|
|
|
players[pom].p7= -1;
|
2007-08-23 20:38:00 +03:00
|
|
|
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].allowedFactions = 0;
|
|
|
|
players[pom].allowedFactions += bufor[i++];
|
2008-08-02 18:08:03 +03:00
|
|
|
if(version != RoE)
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].allowedFactions += (bufor[i++])*256;
|
2007-08-23 20:38:00 +03:00
|
|
|
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].isFactionRandom = bufor[i++];
|
|
|
|
players[pom].hasMainTown = bufor[i++];
|
|
|
|
if (players[pom].hasMainTown)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
if(version != RoE)
|
2007-08-23 20:38:00 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].generateHeroAtMainTown = bufor[i++];
|
|
|
|
players[pom].generateHero = bufor[i++];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
players[pom].generateHeroAtMainTown = false;
|
|
|
|
players[pom].generateHero = false;
|
2007-08-23 20:38:00 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
|
|
|
|
players[pom].posOfMainTown.x = bufor[i++];
|
|
|
|
players[pom].posOfMainTown.y = bufor[i++];
|
|
|
|
players[pom].posOfMainTown.z = bufor[i++];
|
|
|
|
|
|
|
|
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].p8= bufor[i++];
|
|
|
|
players[pom].p9= bufor[i++];
|
2007-08-27 17:15:03 +03:00
|
|
|
if(players[pom].p9!=0xff)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].mainHeroPortrait = bufor[i++];
|
|
|
|
int nameLength = bufor[i++];
|
|
|
|
i+=3;
|
2007-08-23 20:38:00 +03:00
|
|
|
for (int pp=0;pp<nameLength;pp++)
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].mainHeroName+=bufor[i++];
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
2007-08-23 20:38:00 +03:00
|
|
|
|
2009-01-06 20:42:20 +02:00
|
|
|
if(version != RoE)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
i++; ////unknown byte
|
|
|
|
int heroCount = bufor[i++];
|
2007-06-20 15:00:18 +03:00
|
|
|
i+=3;
|
2007-08-23 20:38:00 +03:00
|
|
|
for (int pp=0;pp<heroCount;pp++)
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2007-08-23 20:38:00 +03:00
|
|
|
SheroName vv;
|
2009-01-06 20:42:20 +02:00
|
|
|
vv.heroID=bufor[i++];
|
|
|
|
int hnl = bufor[i++];
|
2007-08-23 20:38:00 +03:00
|
|
|
i+=3;
|
|
|
|
for (int zz=0;zz<hnl;zz++)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
vv.heroName+=bufor[i++];
|
2007-08-23 20:38:00 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
players[pom].heroesNames.push_back(vv);
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHeader::loadViCLossConditions( unsigned char * bufor, int &i)
|
|
|
|
{
|
|
|
|
victoryCondition.condition = (EvictoryConditions)bufor[i++];
|
|
|
|
if (victoryCondition.condition != winStandard) //specific victory conditions
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
|
|
|
int nr;
|
2009-01-06 20:42:20 +02:00
|
|
|
switch (victoryCondition.condition) //read victory conditions
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
|
|
|
case artifact:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.ID = bufor[i+2];
|
2007-08-24 18:00:13 +03:00
|
|
|
nr=(version==RoE ? 1 : 2);
|
2007-06-20 15:00:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gatherTroop:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
int temp1 = bufor[i+2];
|
|
|
|
int temp2 = bufor[i+3];
|
|
|
|
victoryCondition.ID = bufor[i+2];
|
|
|
|
victoryCondition.count = readNormalNr(bufor, i+(version==RoE ? 3 : 4));
|
2007-08-24 18:00:13 +03:00
|
|
|
nr=(version==RoE ? 5 : 6);
|
2007-06-20 15:00:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gatherResource:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.ID = bufor[i+2];
|
|
|
|
victoryCondition.count = readNormalNr(bufor, i+3);
|
2007-06-20 15:00:18 +03:00
|
|
|
nr=5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case buildCity:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.pos.x = bufor[i+2];
|
|
|
|
victoryCondition.pos.y = bufor[i+3];
|
|
|
|
victoryCondition.pos.z = bufor[i+4];
|
|
|
|
victoryCondition.count = bufor[i+5];
|
|
|
|
victoryCondition.ID = bufor[i+6];
|
2007-06-20 15:00:18 +03:00
|
|
|
nr=5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case buildGrail:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
if (bufor[i+4]>2)
|
|
|
|
victoryCondition.pos = int3(-1,-1,-1);
|
2007-06-20 15:00:18 +03:00
|
|
|
else
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.pos.x = bufor[i+2];
|
|
|
|
victoryCondition.pos.y = bufor[i+3];
|
|
|
|
victoryCondition.pos.z = bufor[i+4];
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
|
|
|
nr=3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case beatHero:
|
|
|
|
case captureCity:
|
|
|
|
case beatMonster:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.pos.x = bufor[i+2];
|
|
|
|
victoryCondition.pos.y = bufor[i+3];
|
|
|
|
victoryCondition.pos.z = bufor[i+4];
|
2007-06-20 15:00:18 +03:00
|
|
|
nr=3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case takeDwellings:
|
|
|
|
case takeMines:
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2007-06-20 15:00:18 +03:00
|
|
|
nr=3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case transportItem:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.ID = bufor[i+2];
|
|
|
|
victoryCondition.pos.x = bufor[i+3];
|
|
|
|
victoryCondition.pos.y = bufor[i+4];
|
|
|
|
victoryCondition.pos.z = bufor[i+5];
|
2008-02-25 20:35:10 +02:00
|
|
|
nr=4;
|
2007-06-20 15:00:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
victoryCondition.allowNormalVictory = bufor[i++];
|
|
|
|
victoryCondition.appliesToAI = bufor[i++];
|
2007-06-20 15:00:18 +03:00
|
|
|
i+=nr;
|
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
|
|
|
|
switch (lossCondition.typeOfLossCon) //read loss conditions
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
|
|
|
case lossCastle:
|
2009-01-06 20:42:20 +02:00
|
|
|
{
|
|
|
|
lossCondition.castlePos.x=bufor[i++];
|
|
|
|
lossCondition.castlePos.y=bufor[i++];
|
|
|
|
lossCondition.castlePos.z=bufor[i++];
|
|
|
|
break;
|
|
|
|
}
|
2007-06-20 15:00:18 +03:00
|
|
|
case lossHero:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
lossCondition.heroPos.x=bufor[i++];
|
|
|
|
lossCondition.heroPos.y=bufor[i++];
|
|
|
|
lossCondition.heroPos.z=bufor[i++];
|
|
|
|
break;
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
case timeExpires:
|
2007-06-20 15:00:18 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
lossCondition.timeLimit = readNormalNr(bufor,i++,2);
|
|
|
|
i++;
|
|
|
|
break;
|
2007-06-20 15:00:18 +03:00
|
|
|
}
|
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
void Mapa::initFromBytes(unsigned char * bufor)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
int i=0;
|
|
|
|
initFromMemory(bufor,i);
|
2008-08-15 15:11:42 +03:00
|
|
|
timeHandler th;
|
2008-06-21 16:27:52 +03:00
|
|
|
th.getDif();
|
2008-08-15 15:11:42 +03:00
|
|
|
readHeader(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading header: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readRumors(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading rumors: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readPredefinedHeroes(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readTerrain(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading terrain: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readDefInfo(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading defs info: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readObjects(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading objects: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
readEvents(bufor, i);
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tReading events: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
//map readed, bufor no longer needed
|
2008-08-15 15:11:42 +03:00
|
|
|
for(int f=0; f<objects.size(); ++f) //calculationg blocked / visitable positions
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
if(!objects[f]->defInfo)
|
|
|
|
continue;
|
|
|
|
addBlockVisTiles(objects[f]);
|
|
|
|
}
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
void Mapa::removeBlockVisTiles(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 -= obj;
|
|
|
|
curt.visitable = curt.visitableObjects.size();
|
|
|
|
}
|
|
|
|
if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
|
|
|
|
{
|
|
|
|
curt.blockingObjects -= obj;
|
2008-09-20 21:30:37 +03:00
|
|
|
curt.blocked = curt.blockingObjects.size();
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Mapa::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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Mapa::Mapa(std::string filename)
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"Opening map file: "<<filename<<"\t "<<std::flush;
|
2008-08-15 15:11:42 +03:00
|
|
|
gzFile map = gzopen(filename.c_str(),"rb");
|
|
|
|
std::vector<unsigned char> mapstr; int pom;
|
|
|
|
while((pom=gzgetc(map))>=0)
|
|
|
|
{
|
|
|
|
mapstr.push_back(pom);
|
|
|
|
}
|
|
|
|
gzclose(map);
|
|
|
|
unsigned char *initTable = new unsigned char[mapstr.size()];
|
|
|
|
for(int ss=0; ss<mapstr.size(); ++ss)
|
|
|
|
{
|
|
|
|
initTable[ss] = mapstr[ss];
|
|
|
|
}
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0<<"done."<<std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
boost::crc_32_type result;
|
|
|
|
result.process_bytes(initTable,mapstr.size());
|
|
|
|
checksum = result.checksum();
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog0 << "\tOur map checksum: "<<result.checksum() << std::endl;
|
2008-08-15 15:11:42 +03:00
|
|
|
initFromBytes(initTable);
|
2009-01-11 00:08:18 +02:00
|
|
|
delete [] initTable;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
|
2009-01-06 20:42:20 +02:00
|
|
|
Mapa::Mapa()
|
|
|
|
{
|
2009-01-11 00:08:18 +02:00
|
|
|
terrain = NULL;
|
2009-01-06 20:42:20 +02:00
|
|
|
|
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
Mapa::~Mapa()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
CGHeroInstance * Mapa::getHero(int ID, int mode)
|
|
|
|
{
|
|
|
|
if (mode != 0)
|
|
|
|
#ifndef __GNUC__
|
|
|
|
throw new std::exception("gs->getHero: This mode is not supported!");
|
|
|
|
#else
|
|
|
|
throw new std::exception();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(int i=0; i<heroes.size();i++)
|
|
|
|
if(heroes[i]->subID == ID)
|
|
|
|
return heroes[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-22 19:48:41 +02:00
|
|
|
int Mapa::loadSeerHut( unsigned char * bufor, int i, CGObjectInstance *& nobj )
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGSeerHut *hut = new CGSeerHut();
|
|
|
|
nobj = hut;
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
if(version>RoE)
|
|
|
|
{
|
2008-12-27 03:01:59 +02:00
|
|
|
loadQuest(hut,bufor,i);
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
else //RoE
|
|
|
|
{
|
|
|
|
int artID = bufor[i]; ++i;
|
|
|
|
if(artID!=255) //not none quest
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
hut->m5arts.push_back(artID);
|
|
|
|
hut->missionType = 5;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
hut->missionType = 255;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-22 19:48:41 +02:00
|
|
|
if(hut->missionType!=255)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
unsigned char rewardType = bufor[i]; ++i;
|
2008-12-22 19:48:41 +02:00
|
|
|
hut->rewardType = rewardType;
|
2008-08-15 15:11:42 +03:00
|
|
|
|
|
|
|
switch(rewardType)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rVal = readNormalNr(bufor,i); i+=4;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rVal = readNormalNr(bufor,i); i+=4;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rVal = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rVal = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = bufor[i]; ++i;
|
|
|
|
hut->rVal = readNormalNr(bufor,i, 3); i+=3;
|
2008-08-15 15:11:42 +03:00
|
|
|
i+=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = bufor[i]; ++i;
|
|
|
|
hut->rVal = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = bufor[i]; ++i;
|
|
|
|
hut->rVal = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
hut->rVal = readNormalNr(bufor,i, 2); i+=2;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
hut->rID = bufor[i]; ++i;
|
|
|
|
hut->rVal = readNormalNr(bufor,i, 2); i+=2;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}// end of internal switch
|
|
|
|
i+=2;
|
|
|
|
}
|
|
|
|
else //missionType==255
|
|
|
|
{
|
|
|
|
i+=3;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
|
|
|
|
{
|
|
|
|
CGTownInstance * nt = new CGTownInstance();
|
2008-12-22 19:48:41 +02:00
|
|
|
//(*(static_cast<CGObjectInstance*>(nt))) = *nobj;
|
|
|
|
//delete nobj;
|
2008-08-15 15:11:42 +03:00
|
|
|
nobj = nt;
|
|
|
|
nt->identifier = 0;
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
readNormalNr(bufor,i); i+=4;
|
|
|
|
}
|
|
|
|
nt->tempOwner = bufor[i]; ++i;
|
|
|
|
if(readChar(bufor,i)) //has name
|
|
|
|
nt->name = readString(bufor,i);
|
|
|
|
if(readChar(bufor,i))//true if garrison isn't empty
|
|
|
|
nt->army = readCreatureSet(bufor,i,7,(version>RoE));
|
|
|
|
nt->army.formation = bufor[i]; ++i;
|
|
|
|
if(readChar(bufor,i)) //unusualBuildings
|
|
|
|
{
|
|
|
|
//built buildings
|
|
|
|
for(int byte=0;byte<6;byte++)
|
|
|
|
{
|
|
|
|
for(int bit=0;bit<8;bit++)
|
|
|
|
if(bufor[i] & (1<<bit))
|
|
|
|
nt->builtBuildings.insert(byte*8+bit);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
//forbidden buildings
|
|
|
|
for(int byte=6;byte<12;byte++)
|
|
|
|
{
|
|
|
|
for(int bit=0;bit<8;bit++)
|
|
|
|
if(bufor[i] & (1<<bit))
|
2008-08-20 09:57:53 +03:00
|
|
|
nt->forbiddenBuildings.insert((byte-6)*8+bit);
|
2008-08-15 15:11:42 +03:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID);
|
|
|
|
nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID);
|
|
|
|
}
|
|
|
|
else //standard buildings
|
|
|
|
{
|
|
|
|
if(readChar(bufor,i)) //has fort
|
|
|
|
nt->builtBuildings.insert(7);
|
|
|
|
nt->builtBuildings.insert(-50); //means that set of standard building should be included
|
|
|
|
}
|
|
|
|
|
|
|
|
int ist = i;
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
for(i; i<ist+9; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SPELLS_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
nt->obligatorySpells.push_back((i-ist)*8+yy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ist = i;
|
|
|
|
for(i; i<ist+9; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SPELLS_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c != (c|((unsigned char)intPow(2, yy))))
|
|
|
|
nt->possibleSpells.push_back((i-ist)*8+yy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////// reading castle events //////////////////////////////////
|
|
|
|
|
|
|
|
int numberOfEvent = readNormalNr(bufor,i); i+=4;
|
|
|
|
|
|
|
|
for(int gh = 0; gh<numberOfEvent; ++gh)
|
|
|
|
{
|
|
|
|
CCastleEvent nce;
|
2008-12-31 11:33:46 +02:00
|
|
|
nce.name = readString(bufor,i);
|
|
|
|
nce.message = readString(bufor,i);
|
2009-01-25 18:19:34 +02:00
|
|
|
nce.resources.resize(RESOURCE_QUANTITY);
|
2008-12-31 11:33:46 +02:00
|
|
|
for(int x=0; x < 7; x++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-12-31 11:33:46 +02:00
|
|
|
nce.resources[x] = readNormalNr(bufor,i);
|
|
|
|
i+=4;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nce.players = bufor[i]; ++i;
|
|
|
|
if(version > AB)
|
|
|
|
{
|
|
|
|
nce.forHuman = bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nce.forHuman = true;
|
2008-12-31 11:33:46 +02:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
nce.forComputer = bufor[i]; ++i;
|
|
|
|
nce.firstShow = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
nce.forEvery = bufor[i]; ++i;
|
|
|
|
|
|
|
|
i+=17;
|
|
|
|
|
|
|
|
for(int kk=0; kk<6; ++kk)
|
|
|
|
{
|
|
|
|
nce.bytes[kk] = bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int vv=0; vv<7; ++vv)
|
|
|
|
{
|
|
|
|
nce.gen[vv] = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
}
|
|
|
|
i+=4;
|
|
|
|
nt->events.insert(nce);
|
|
|
|
}//castle events have been read
|
|
|
|
|
|
|
|
if(version > AB)
|
|
|
|
{
|
|
|
|
nt->alignment = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
else
|
2008-08-15 15:11:42 +03:00
|
|
|
nt->alignment = 0xff;
|
|
|
|
i+=3;
|
|
|
|
|
|
|
|
nt->builded = 0;
|
|
|
|
nt->destroyed = 0;
|
|
|
|
nt->garrisonHero = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
|
|
|
|
{
|
|
|
|
CGHeroInstance * nhi = new CGHeroInstance;
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj=nhi;
|
|
|
|
|
2008-10-26 22:58:34 +02:00
|
|
|
int identifier = 0;
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
identifier = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
|
|
|
ui8 owner = bufor[i++];
|
2008-10-26 22:58:34 +02:00
|
|
|
nobj->subID = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
|
|
|
|
for(int j=0; j<predefinedHeroes.size(); j++)
|
|
|
|
{
|
|
|
|
if(predefinedHeroes[j]->subID == nobj->subID)
|
|
|
|
{
|
|
|
|
*nhi = *predefinedHeroes[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj->setOwner(owner);
|
2008-10-26 22:58:34 +02:00
|
|
|
|
2008-12-22 19:48:41 +02:00
|
|
|
//(*(static_cast<CGObjectInstance*>(nhi))) = *nobj;
|
|
|
|
//delete nobj;
|
2008-10-26 22:58:34 +02:00
|
|
|
nhi->portrait = nhi->subID;
|
|
|
|
|
|
|
|
for(int j=0; j<disposedHeroes.size(); j++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-10-26 22:58:34 +02:00
|
|
|
if(disposedHeroes[j].ID == nhi->subID)
|
|
|
|
{
|
|
|
|
nhi->name = disposedHeroes[j].name;
|
|
|
|
nhi->portrait = disposedHeroes[j].portrait;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
nhi->identifier = identifier;
|
2008-08-15 15:11:42 +03:00
|
|
|
if(readChar(bufor,i))//true if hero has nonstandard name
|
|
|
|
nhi->name = readString(bufor,i);
|
|
|
|
if(version>AB)
|
|
|
|
{
|
|
|
|
if(readChar(bufor,i))//true if hore's experience is greater than 0
|
|
|
|
{ nhi->exp = readNormalNr(bufor,i); i+=4; }
|
|
|
|
else
|
2008-11-15 02:55:19 +02:00
|
|
|
nhi->exp = 0xffffffff;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ nhi->exp = readNormalNr(bufor,i); i+=4; }
|
|
|
|
|
|
|
|
bool portrait=bufor[i]; ++i;
|
|
|
|
if (portrait)
|
2008-10-26 22:58:34 +02:00
|
|
|
nhi->portrait = readChar(bufor,i);
|
2008-08-15 15:11:42 +03:00
|
|
|
if(readChar(bufor,i))//true if hero has specified abilities
|
|
|
|
{
|
|
|
|
int howMany = readNormalNr(bufor,i); i+=4;
|
|
|
|
nhi->secSkills.resize(howMany);
|
|
|
|
for(int yy=0; yy<howMany; ++yy)
|
|
|
|
{
|
|
|
|
nhi->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
nhi->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(readChar(bufor,i))//true if hero has nonstandard garrison
|
|
|
|
nhi->army = readCreatureSet(bufor,i,7,(version>RoE));
|
|
|
|
nhi->army.formation =bufor[i]; ++i; //formation
|
|
|
|
bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
|
|
|
|
int artmask = version == RoE ? 0xff : 0xffff;
|
|
|
|
int artidlen = version == RoE ? 1 : 2;
|
|
|
|
if(artSet)
|
|
|
|
{
|
|
|
|
for(int pom=0;pom<16;pom++)
|
|
|
|
{
|
|
|
|
int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
nhi->artifWorn[pom] = id;
|
|
|
|
}
|
|
|
|
//misc5 art //17
|
|
|
|
if(version>=SoD)
|
|
|
|
{
|
|
|
|
int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
nhi->artifWorn[16] = id;
|
|
|
|
}
|
|
|
|
//spellbook
|
|
|
|
int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
nhi->artifWorn[17] = id;
|
|
|
|
//19 //???what is that? gap in file or what? - it's probably fifth slot..
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
nhi->artifWorn[18] = id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i+=1;
|
|
|
|
//bag artifacts //20
|
|
|
|
int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
|
|
|
|
if(amount>0)
|
|
|
|
{
|
|
|
|
for(int ss=0; ss<amount; ++ss)
|
|
|
|
{
|
|
|
|
id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
nhi->artifacts.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} //artifacts
|
|
|
|
|
|
|
|
nhi->patrol.patrolRadious = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
if(nhi->patrol.patrolRadious == 0xff)
|
|
|
|
nhi->patrol.patrolling = false;
|
|
|
|
else
|
|
|
|
nhi->patrol.patrolling = true;
|
|
|
|
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
if(readChar(bufor,i))//true if hero has nonstandard (mapmaker defined) biography
|
|
|
|
nhi->biography = readString(bufor,i);
|
|
|
|
nhi->sex = !(bufor[i]); ++i;
|
|
|
|
}
|
|
|
|
//spells
|
|
|
|
if(version>AB)
|
|
|
|
{
|
|
|
|
bool areSpells = bufor[i]; ++i;
|
|
|
|
|
|
|
|
if(areSpells) //TODO: sprawdzi� //seems to be ok - tow
|
|
|
|
{
|
|
|
|
int ist = i;
|
|
|
|
for(i; i<ist+9; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SPELLS_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
nhi->spells.insert((i-ist)*8+yy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(version==AB) //we can read one spell
|
|
|
|
{
|
|
|
|
unsigned char buff = bufor[i]; ++i;
|
|
|
|
if(buff!=254)
|
|
|
|
{
|
|
|
|
nhi->spells.insert(buff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//spells loaded
|
|
|
|
if(version>AB)
|
|
|
|
{
|
|
|
|
if(readChar(bufor,i))//customPrimSkills
|
|
|
|
{
|
|
|
|
nhi->primSkills.resize(4);
|
|
|
|
for(int xx=0;xx<4;xx++)
|
|
|
|
nhi->primSkills[xx] = bufor[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i+=16;
|
|
|
|
nhi->moveDir = 4;
|
|
|
|
nhi->isStanding = true;
|
|
|
|
nhi->level = -1;
|
|
|
|
nhi->mana = -1;
|
|
|
|
nhi->movement = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::readRumors( unsigned char * bufor, int &i)
|
|
|
|
{
|
|
|
|
int rumNr = readNormalNr(bufor,i,4);i+=4;
|
|
|
|
for (int it=0;it<rumNr;it++)
|
|
|
|
{
|
|
|
|
Rumor ourRumor;
|
|
|
|
int nameL = readNormalNr(bufor,i,4);i+=4; //read length of name of rumor
|
|
|
|
for (int zz=0; zz<nameL; zz++)
|
|
|
|
ourRumor.name+=bufor[i++];
|
|
|
|
nameL = readNormalNr(bufor,i,4);i+=4; //read length of rumor
|
|
|
|
for (int zz=0; zz<nameL; zz++)
|
|
|
|
ourRumor.text+=bufor[i++];
|
|
|
|
rumors.push_back(ourRumor); //add to our list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::readHeader( unsigned char * bufor, int &i)
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
//reading allowed heroes (20 bytes)
|
|
|
|
int ist;
|
|
|
|
|
|
|
|
ist=i; //starting i for loop
|
|
|
|
|
|
|
|
allowedHeroes.resize(HEROES_QUANTITY);
|
|
|
|
for(int xx=0;xx<HEROES_QUANTITY;xx++)
|
|
|
|
allowedHeroes[xx] = true;
|
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
for(i; i<ist+ (version == RoE ? 16 : 20) ; ++i)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
if((i-ist)*8+yy < HEROES_QUANTITY)
|
|
|
|
if(c != (c|((unsigned char)intPow(2, yy))))
|
|
|
|
allowedHeroes[(i-ist)*8+yy] = false;
|
|
|
|
}
|
|
|
|
if(version>RoE) //probably reserved for further heroes
|
|
|
|
i+=4;
|
|
|
|
unsigned char disp = 0;
|
|
|
|
if(version>=SoD)
|
|
|
|
{
|
|
|
|
disp = bufor[i++];
|
|
|
|
disposedHeroes.resize(disp);
|
|
|
|
for(int g=0; g<disp; ++g)
|
|
|
|
{
|
|
|
|
disposedHeroes[g].ID = bufor[i++];
|
|
|
|
disposedHeroes[g].portrait = bufor[i++];
|
|
|
|
int lenbuf = readNormalNr(bufor,i); i+=4;
|
|
|
|
for (int zz=0; zz<lenbuf; zz++)
|
|
|
|
disposedHeroes[g].name+=bufor[i++];
|
2008-10-26 22:58:34 +02:00
|
|
|
disposedHeroes[g].players = bufor[i++];
|
|
|
|
//int players = bufor[i++];
|
|
|
|
//for(int zz=0;zz<8;zz++)
|
|
|
|
//{
|
|
|
|
// int por = (1<<zz);
|
|
|
|
// if(players & por)
|
|
|
|
// disposedHeroes[g].players[zz] = true;
|
|
|
|
// else
|
|
|
|
// disposedHeroes[g].players[zz] = false;
|
|
|
|
//}
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i+=31; //omitting NULLS
|
|
|
|
|
|
|
|
allowedArtifact.resize(ARTIFACTS_QUANTITY);
|
|
|
|
for(int x=0;x<allowedArtifact.size();x++)
|
|
|
|
allowedArtifact[x] = true;
|
|
|
|
|
|
|
|
//reading allowed artifacts: 17 or 18 bytes
|
|
|
|
if(version!=RoE)
|
|
|
|
{
|
|
|
|
ist=i; //starting i for loop
|
|
|
|
for(i; i<ist+(version==AB ? 17 : 18); ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < ARTIFACTS_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
allowedArtifact[(i-ist)*8+yy] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}//allowed artifacts have been read
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
allowedSpell.resize(SPELLS_QUANTITY);
|
|
|
|
for(int x=0;x<allowedSpell.size();x++)
|
|
|
|
allowedSpell[x] = true;
|
|
|
|
|
|
|
|
allowedAbilities.resize(SKILL_QUANTITY);
|
|
|
|
for(int x=0;x<allowedAbilities.size();x++)
|
|
|
|
allowedAbilities[x] = true;
|
|
|
|
|
|
|
|
if(version>=SoD)
|
|
|
|
{
|
|
|
|
//reading allowed spells (9 bytes)
|
|
|
|
ist=i; //starting i for loop
|
|
|
|
for(i; i<ist+9; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
if((i-ist)*8+yy < SPELLS_QUANTITY)
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
allowedSpell[(i-ist)*8+yy] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//allowed hero's abilities (4 bytes)
|
|
|
|
ist=i; //starting i for loop
|
|
|
|
for(i; i<ist+4; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SKILL_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
allowedAbilities[(i-ist)*8+yy] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
void Mapa::readPredefinedHeroes( unsigned char * bufor, int &i)
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
switch(version)
|
|
|
|
{
|
|
|
|
case WoG: case SoD:
|
|
|
|
{
|
|
|
|
for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
|
|
|
|
{
|
|
|
|
int custom = bufor[i++];
|
|
|
|
if(!custom)
|
|
|
|
continue;
|
|
|
|
CGHeroInstance * cgh = new CGHeroInstance;
|
|
|
|
cgh->ID = 34;
|
|
|
|
cgh->subID = z;
|
|
|
|
if(readChar(bufor,i))//true if hore's experience is greater than 0
|
|
|
|
{ cgh->exp = readNormalNr(bufor,i); i+=4; }
|
|
|
|
else
|
|
|
|
cgh->exp = 0;
|
|
|
|
if(readChar(bufor,i))//true if hero has specified abilities
|
|
|
|
{
|
|
|
|
int howMany = readNormalNr(bufor,i); i+=4;
|
|
|
|
cgh->secSkills.resize(howMany);
|
|
|
|
for(int yy=0; yy<howMany; ++yy)
|
|
|
|
{
|
|
|
|
cgh->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
cgh->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
|
|
|
|
int artmask = version == RoE ? 0xff : 0xffff;
|
|
|
|
int artidlen = version == RoE ? 1 : 2;
|
|
|
|
if(artSet)
|
|
|
|
{
|
|
|
|
for(int pom=0;pom<16;pom++)
|
|
|
|
{
|
|
|
|
int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
cgh->artifWorn[pom] = id;
|
|
|
|
}
|
|
|
|
//misc5 art //17
|
|
|
|
if(version>=SoD)
|
|
|
|
{
|
|
|
|
i+=2;
|
|
|
|
//int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
//if(id!=artmask)
|
|
|
|
// spec->artifWorn[16] = id;
|
|
|
|
}
|
|
|
|
//spellbook
|
|
|
|
int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
cgh->artifWorn[17] = id;
|
|
|
|
//19 //???what is that? gap in file or what? - it's probably fifth slot..
|
|
|
|
if(version>RoE)
|
|
|
|
{
|
|
|
|
id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
cgh->artifWorn[18] = id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i+=1;
|
|
|
|
//bag artifacts //20
|
|
|
|
int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
|
|
|
|
if(amount>0)
|
|
|
|
{
|
|
|
|
for(int ss=0; ss<amount; ++ss)
|
|
|
|
{
|
|
|
|
id = readNormalNr(bufor,i, artidlen); i+=artidlen;
|
|
|
|
if(id!=artmask)
|
|
|
|
cgh->artifacts.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} //artifacts
|
|
|
|
if(readChar(bufor,i))//customBio
|
|
|
|
cgh->biography = readString(bufor,i);
|
|
|
|
int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female
|
|
|
|
if(readChar(bufor,i))//are spells
|
|
|
|
{
|
|
|
|
int ist = i;
|
|
|
|
for(i; i<ist+9; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SPELLS_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
|
|
|
cgh->spells.insert((i-ist)*8+yy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(readChar(bufor,i))//customPrimSkills
|
|
|
|
{
|
|
|
|
cgh->primSkills.resize(4);
|
|
|
|
for(int xx=0;xx<4;xx++)
|
|
|
|
cgh->primSkills[xx] = bufor[i++];
|
|
|
|
}
|
|
|
|
predefinedHeroes.push_back(cgh);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RoE:
|
|
|
|
i+=0;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::readTerrain( unsigned char * bufor, int &i)
|
|
|
|
{
|
2009-01-06 20:42:20 +02:00
|
|
|
terrain = new TerrainTile**[width]; // allocate memory
|
|
|
|
for (int ii=0;ii<width;ii++)
|
|
|
|
{
|
|
|
|
terrain[ii] = new TerrainTile*[height]; // allocate memory
|
|
|
|
for(int jj=0;jj<height;jj++)
|
|
|
|
terrain[ii][jj] = new TerrainTile[twoLevel+1];
|
|
|
|
}
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
for (int c=0; c<width; c++) // reading terrain
|
|
|
|
{
|
|
|
|
for (int z=0; z<height; z++)
|
|
|
|
{
|
2008-07-29 22:10:28 +03:00
|
|
|
terrain[z][c][0].tertype = (EterrainType)(bufor[i++]);
|
|
|
|
terrain[z][c][0].terview = bufor[i++];
|
|
|
|
terrain[z][c][0].nuine = (Eriver)bufor[i++];
|
|
|
|
terrain[z][c][0].rivDir = bufor[i++];
|
|
|
|
terrain[z][c][0].malle = (Eroad)bufor[i++];
|
|
|
|
terrain[z][c][0].roadDir = bufor[i++];
|
|
|
|
terrain[z][c][0].siodmyTajemniczyBajt = bufor[i++];
|
|
|
|
terrain[z][c][0].blocked = 0;
|
|
|
|
terrain[z][c][0].visitable = 0;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (twoLevel) // read underground terrain
|
|
|
|
{
|
|
|
|
for (int c=0; c<width; c++) // reading terrain
|
|
|
|
{
|
|
|
|
for (int z=0; z<height; z++)
|
|
|
|
{
|
2008-07-29 22:10:28 +03:00
|
|
|
terrain[z][c][1].tertype = (EterrainType)(bufor[i++]);
|
|
|
|
terrain[z][c][1].terview = bufor[i++];
|
|
|
|
terrain[z][c][1].nuine = (Eriver)bufor[i++];
|
|
|
|
terrain[z][c][1].rivDir = bufor[i++];
|
|
|
|
terrain[z][c][1].malle = (Eroad)bufor[i++];
|
|
|
|
terrain[z][c][1].roadDir = bufor[i++];
|
|
|
|
terrain[z][c][1].siodmyTajemniczyBajt = bufor[i++];
|
|
|
|
terrain[z][c][1].blocked = 0;
|
|
|
|
terrain[z][c][1].visitable = 0;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
void Mapa::readDefInfo( unsigned char * bufor, int &i)
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
int defAmount = readNormalNr(bufor,i); i+=4;
|
|
|
|
defy.reserve(defAmount);
|
|
|
|
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
|
|
|
|
{
|
|
|
|
CGDefInfo * vinya = new CGDefInfo(); // info about new def
|
|
|
|
|
|
|
|
//reading name
|
|
|
|
int nameLength = readNormalNr(bufor,i,4);i+=4;
|
|
|
|
vinya->name.reserve(nameLength);
|
|
|
|
for (int cd=0;cd<nameLength;cd++)
|
|
|
|
{
|
|
|
|
vinya->name += bufor[i++];
|
|
|
|
}
|
|
|
|
std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper);
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char bytes[12];
|
|
|
|
for (int v=0; v<12; v++) // read info
|
|
|
|
{
|
|
|
|
bytes[v] = bufor[i++];
|
|
|
|
}
|
|
|
|
vinya->terrainAllowed = readNormalNr(bufor,i,2);i+=2;
|
|
|
|
vinya->terrainMenu = readNormalNr(bufor,i,2);i+=2;
|
|
|
|
vinya->id = readNormalNr(bufor,i,4);i+=4;
|
|
|
|
vinya->subid = readNormalNr(bufor,i,4);i+=4;
|
|
|
|
vinya->type = bufor[i++];
|
|
|
|
vinya->printPriority = bufor[i++];
|
|
|
|
for (int zi=0; zi<6; zi++)
|
|
|
|
{
|
|
|
|
vinya->blockMap[zi] = reverse(bytes[zi]);
|
|
|
|
}
|
|
|
|
for (int zi=0; zi<6; zi++)
|
|
|
|
{
|
|
|
|
vinya->visitMap[zi] = reverse(bytes[6+zi]);
|
|
|
|
}
|
|
|
|
i+=16;
|
2008-09-19 11:16:19 +03:00
|
|
|
if(vinya->id!=34 && vinya->id!=70)
|
2008-09-18 17:18:08 +03:00
|
|
|
vinya->visitDir = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]->visitDir;
|
|
|
|
else
|
|
|
|
vinya->visitDir = 0xff;
|
2008-06-21 16:27:52 +03:00
|
|
|
defy.push_back(vinya); // add this def to the vector
|
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
void Mapa::readObjects( unsigned char * bufor, int &i)
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
int howManyObjs = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGObjectInstance * nobj = 0;
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-12-22 19:48:41 +02:00
|
|
|
int3 pos;
|
|
|
|
pos.x = bufor[i++];
|
|
|
|
pos.y = bufor[i++];
|
|
|
|
pos.z = bufor[i++];
|
|
|
|
int defnum = readNormalNr(bufor,i, 4); i+=4;
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-12-22 19:48:41 +02:00
|
|
|
CGDefInfo * defInfo = defy[defnum];
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=5;
|
2008-12-22 19:48:41 +02:00
|
|
|
|
|
|
|
switch(defInfo->id)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
case 26: //for event objects
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGEvent *evnt = new CGEvent();
|
|
|
|
nobj = evnt;
|
|
|
|
|
|
|
|
bool guardMess = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
if(guardMess)
|
|
|
|
{
|
|
|
|
int messLong = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
if(messLong>0)
|
|
|
|
{
|
|
|
|
for(int yy=0; yy<messLong; ++yy)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->message +=bufor[i+yy];
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
i+=messLong;
|
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
if(bufor[i++])
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->guarders = readCreatureSet(bufor,i,7,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
i+=4;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->gainedExp = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
evnt->manaDiff = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
evnt->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
|
|
|
|
evnt->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
|
2009-01-06 20:42:20 +02:00
|
|
|
|
|
|
|
evnt->resources.resize(RESOURCE_QUANTITY);
|
|
|
|
for(int x=0; x<7; x++)
|
|
|
|
{
|
|
|
|
evnt->resources[x] = readNormalNr(bufor,i);
|
|
|
|
i+=4;
|
|
|
|
}
|
|
|
|
|
|
|
|
evnt->primskills.resize(PRIMARY_SKILLS);
|
|
|
|
for(int x=0; x<4; x++)
|
|
|
|
{
|
|
|
|
evnt->primskills[x] = readNormalNr(bufor,i, 1);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int gabn; //number of gained abilities
|
|
|
|
gabn = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
for(int oo = 0; oo<gabn; ++oo)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
|
|
|
|
evnt->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
|
|
|
|
for(int oo = 0; oo<gart; ++oo)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->artifacts.push_back(readNormalNr(bufor,i, (version == RoE ? 1 : 2))); i+=(version == RoE ? 1 : 2);
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
|
|
|
|
for(int oo = 0; oo<gspel; ++oo)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
|
2009-01-06 20:42:20 +02:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=8;
|
2008-12-22 19:48:41 +02:00
|
|
|
evnt->availableFor = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
evnt->computerActivate = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
evnt->humanActivate = readNormalNr(bufor,i, 1); ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=4;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 34: case 70: case 62: //34 - hero; 70 - random hero; 62 - prison
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
loadHero(nobj, bufor, i);
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
case 4: //arena
|
2008-12-27 03:01:59 +02:00
|
|
|
case 51: //Mercenary Camp
|
|
|
|
case 23: //Marletto Tower
|
|
|
|
case 61: // Star Axis
|
|
|
|
case 32: // Garden of Revelation
|
|
|
|
case 100: //Learning Stone
|
|
|
|
case 102: //Tree of Knowledge
|
|
|
|
{
|
|
|
|
nobj = new CGVisitableOPH();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 55: //mystical garden
|
|
|
|
case 112://windmill
|
|
|
|
case 109://water wheel
|
|
|
|
{
|
|
|
|
nobj = new CGVisitableOPW();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 43: //teleport
|
|
|
|
case 44: //teleport
|
|
|
|
case 45: //teleport
|
|
|
|
case 103://subterranean gate
|
|
|
|
{
|
|
|
|
nobj = new CGTeleport();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 12: //campfire
|
|
|
|
case 101: //treasure chest
|
|
|
|
{
|
|
|
|
nobj = new CGPickable();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 54: //Monster
|
|
|
|
case 71: case 72: case 73: case 74: case 75: // Random Monster 1 - 4
|
|
|
|
case 162: case 163: case 164: // Random Monster 5 - 7
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGCreature *cre = new CGCreature();
|
|
|
|
nobj = cre;
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
if(version>RoE)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->identifier = readNormalNr(bufor,i); i+=4;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->army.slots[0].second = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
cre->character = bufor[i]; ++i;
|
2008-08-15 15:11:42 +03:00
|
|
|
bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
|
|
|
|
if(isMesTre)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->message = readString(bufor,i);
|
|
|
|
cre->resources.resize(RESOURCE_QUANTITY);
|
|
|
|
for(int j=0; j<7; j++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->resources[j] = readNormalNr(bufor,i); i+=4;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
int artID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
|
|
|
|
if(version==RoE)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
if(artID!=0xff)
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->gainedArtifact = artID;
|
2008-08-15 15:11:42 +03:00
|
|
|
else
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->gainedArtifact = -1;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
if(artID!=0xffff)
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->gainedArtifact = artID;
|
2008-08-15 15:11:42 +03:00
|
|
|
else
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->gainedArtifact = -1;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
cre->neverFlees = bufor[i]; ++i;
|
|
|
|
cre->notGrowingTeam = bufor[i]; ++i;
|
|
|
|
i+=2;;
|
2008-08-15 15:11:42 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 59: case 91: //ocean bottle and sign
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGSignBottle *sb = new CGSignBottle();
|
|
|
|
nobj = sb;
|
|
|
|
sb->message = readString(bufor,i);
|
2008-08-15 15:11:42 +03:00
|
|
|
i+=4;
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 83: //seer's hut
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
i = loadSeerHut(bufor, i, nobj);
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 113: //witch hut
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGWitchHut *wh = new CGWitchHut();
|
|
|
|
nobj = wh;
|
2008-06-21 16:27:52 +03:00
|
|
|
if(version>RoE) //in reo we cannot specify it - all are allowed (I hope)
|
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
int ist=i; //starting i for loop
|
2008-06-21 16:27:52 +03:00
|
|
|
for(i; i<ist+4; ++i)
|
|
|
|
{
|
|
|
|
unsigned char c = bufor[i];
|
|
|
|
for(int yy=0; yy<8; ++yy)
|
|
|
|
{
|
|
|
|
if((i-ist)*8+yy < SKILL_QUANTITY)
|
|
|
|
{
|
|
|
|
if(c == (c|((unsigned char)intPow(2, yy))))
|
2008-12-22 19:48:41 +02:00
|
|
|
wh->allowedAbilities.push_back((i-ist)*8+yy);
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //(RoE map)
|
|
|
|
{
|
|
|
|
for(int gg=0; gg<SKILL_QUANTITY; ++gg)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
wh->allowedAbilities.push_back(gg);
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 81: //scholar
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGScholar *sch = new CGScholar();
|
|
|
|
nobj = sch;
|
|
|
|
sch->bonusType = bufor[i]; ++i;
|
|
|
|
switch(sch->bonusType)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
|
|
|
case 0xff:
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case 0:
|
2008-12-22 19:48:41 +02:00
|
|
|
sch->r0type = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2008-12-22 19:48:41 +02:00
|
|
|
sch->r1 = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2008-12-22 19:48:41 +02:00
|
|
|
sch->r2 = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=6;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 33: case 219: //garrison
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGGarrison *gar = new CGGarrison();
|
|
|
|
nobj = gar;
|
|
|
|
nobj->setOwner(bufor[i++]);
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=3;
|
2008-12-22 19:48:41 +02:00
|
|
|
gar->army = readCreatureSet(bufor,i,7,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
if(version > RoE)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
gar->removableUnits = bufor[i]; ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
else
|
2008-12-22 19:48:41 +02:00
|
|
|
gar->removableUnits = true;
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=8;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
case 5: //artifact
|
|
|
|
case 65: case 66: case 67: case 68: case 69: //random artifact
|
2008-12-22 19:48:41 +02:00
|
|
|
case 93: //spell scroll
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGArtifact *art = new CGArtifact();
|
|
|
|
nobj = art;
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
bool areSettings = bufor[i]; ++i;
|
|
|
|
if(areSettings)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
art->message = readString(bufor,i);
|
2008-06-21 16:27:52 +03:00
|
|
|
bool areGuards = bufor[i]; ++i;
|
|
|
|
if(areGuards)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
art->army = readCreatureSet(bufor,i,7,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
art->spell = readNormalNr(bufor,i);
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
case 76: case 79: //random resource; resource
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGResource *res = new CGResource();
|
|
|
|
nobj = res;
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
bool isMessGuard = bufor[i]; ++i;
|
|
|
|
if(isMessGuard)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
res->message = readString(bufor,i);
|
|
|
|
if(bufor[i++])
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
res->army = readCreatureSet(bufor,i,7,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
i+=4;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
res->amount = readNormalNr(bufor,i); i+=4;
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=4;
|
2008-12-22 19:48:41 +02:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
case 77: case 98: //random town; town
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-08-15 15:11:42 +03:00
|
|
|
loadTown(nobj, bufor, i);
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
case 53:
|
|
|
|
{
|
|
|
|
nobj = new CGMine();
|
|
|
|
nobj->setOwner(bufor[i++]);
|
|
|
|
i+=3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 17: case 18: case 19: case 20: //dwellings
|
|
|
|
case 42: //lighthouse
|
|
|
|
case 87: //shipyard
|
|
|
|
case 220://mine (?)
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj = new CGObjectInstance();
|
|
|
|
nobj->setOwner(bufor[i++]);
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=3;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 88: case 89: case 90: //spell shrine
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGShrine * shr = new CGShrine();
|
|
|
|
nobj = shr;
|
|
|
|
shr->spell = bufor[i]; i+=4;
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 6:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGPandoraBox *box = new CGPandoraBox();
|
|
|
|
nobj = box;
|
2008-06-21 16:27:52 +03:00
|
|
|
bool messg = bufor[i]; ++i;
|
|
|
|
if(messg)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->message = readString(bufor,i);
|
|
|
|
if(bufor[i++])
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->army = readCreatureSet(bufor,i,7,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
i+=4;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
|
|
|
|
box->gainedExp = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
box->manaDiff = readNormalNr(bufor,i, 4); i+=4;
|
|
|
|
box->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
|
2009-01-06 20:42:20 +02:00
|
|
|
box->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
|
|
|
|
|
|
|
|
box->resources.resize(RESOURCE_QUANTITY);
|
|
|
|
for(int x=0; x<7; x++)
|
|
|
|
{
|
|
|
|
box->resources[x] = readNormalNr(bufor,i);
|
|
|
|
i+=4;
|
|
|
|
}
|
|
|
|
|
|
|
|
box->primskills.resize(PRIMARY_SKILLS);
|
|
|
|
for(int x=0; x<4; x++)
|
|
|
|
{
|
|
|
|
box->primskills[x] = readNormalNr(bufor,i, 1);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int gabn; //number of gained abilities
|
|
|
|
gabn = readNormalNr(bufor,i, 1); ++i;
|
|
|
|
for(int oo = 0; oo<gabn; ++oo)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
|
|
|
|
box->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
|
|
|
|
for(int oo = 0; oo<gart; ++oo)
|
|
|
|
{
|
|
|
|
if(version > RoE)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->artifacts.push_back(readNormalNr(bufor,i, 2)); i+=2;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->artifacts.push_back(readNormalNr(bufor,i, 1)); i+=1;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
|
|
|
|
for(int oo = 0; oo<gspel; ++oo)
|
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
box->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
|
|
|
int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
|
2008-12-22 19:48:41 +02:00
|
|
|
box->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
|
2008-06-21 16:27:52 +03:00
|
|
|
i+=8;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 36:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
grailPos = pos;
|
|
|
|
grailRadious = readNormalNr(bufor,i); i+=4;
|
|
|
|
continue;
|
2008-06-21 16:27:52 +03:00
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 217:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj = new CGObjectInstance();
|
2008-06-21 16:27:52 +03:00
|
|
|
CCreGenObjInfo * spec = new CCreGenObjInfo;
|
|
|
|
spec->player = readNormalNr(bufor,i); i+=4;
|
|
|
|
spec->identifier = readNormalNr(bufor,i); i+=4;
|
|
|
|
if(!spec->identifier)
|
|
|
|
{
|
|
|
|
spec->asCastle = false;
|
|
|
|
spec->castles[0] = bufor[i]; ++i;
|
|
|
|
spec->castles[1] = bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spec->asCastle = true;
|
|
|
|
}
|
|
|
|
nobj->setOwner(spec->player);
|
|
|
|
nobj->info = spec;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 216:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj = new CGObjectInstance();
|
2008-06-21 16:27:52 +03:00
|
|
|
CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
|
|
|
|
spec->player = readNormalNr(bufor,i); i+=4;
|
|
|
|
spec->identifier = readNormalNr(bufor,i); i+=4;
|
|
|
|
if(!spec->identifier)
|
|
|
|
{
|
|
|
|
spec->asCastle = false;
|
|
|
|
spec->castles[0] = bufor[i]; ++i;
|
|
|
|
spec->castles[1] = bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spec->asCastle = true;
|
|
|
|
}
|
|
|
|
spec->minLevel = bufor[i]; ++i;
|
|
|
|
spec->maxLevel = bufor[i]; ++i;
|
|
|
|
nobj->setOwner(spec->player);
|
|
|
|
nobj->info = spec;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 218:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
nobj = new CGObjectInstance();
|
2008-06-21 16:27:52 +03:00
|
|
|
CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
|
|
|
|
spec->player = bufor[i]; ++i;
|
|
|
|
i+=3;
|
|
|
|
spec->minLevel = bufor[i]; ++i;
|
|
|
|
spec->maxLevel = bufor[i]; ++i;
|
|
|
|
if(spec->maxLevel>7)
|
|
|
|
spec->maxLevel = 7;
|
|
|
|
if(spec->minLevel<1)
|
|
|
|
spec->minLevel = 1;
|
|
|
|
nobj->setOwner(spec->player);
|
|
|
|
nobj->info = spec;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 215:
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
2008-12-22 19:48:41 +02:00
|
|
|
CGQuestGuard *guard = new CGQuestGuard();
|
|
|
|
nobj = guard;
|
2008-12-27 03:01:59 +02:00
|
|
|
loadQuest(guard, bufor, i);
|
2008-06-21 16:27:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
case 214: //hero placeholder
|
2008-06-21 16:27:52 +03:00
|
|
|
{
|
|
|
|
i+=3; //TODO: handle it more properly
|
|
|
|
break;
|
|
|
|
}
|
2008-12-22 19:48:41 +02:00
|
|
|
default:
|
|
|
|
nobj = new CGObjectInstance();
|
2008-06-21 16:27:52 +03:00
|
|
|
} //end of main switch
|
2008-12-22 19:48:41 +02:00
|
|
|
|
|
|
|
nobj->pos = pos;
|
|
|
|
nobj->ID = defInfo->id;
|
|
|
|
nobj->id = objects.size();
|
|
|
|
if(nobj->ID != 34)
|
|
|
|
nobj->subID = defInfo->subid;
|
|
|
|
nobj->defInfo = defInfo;
|
2008-06-21 16:27:52 +03:00
|
|
|
objects.push_back(nobj);
|
2008-12-22 19:48:41 +02:00
|
|
|
if(nobj->ID==98)
|
|
|
|
towns.push_back(static_cast<CGTownInstance*>(nobj));
|
|
|
|
if(nobj->ID==34)
|
|
|
|
heroes.push_back(static_cast<CGHeroInstance*>(nobj));
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mapa::readEvents( unsigned char * bufor, int &i )
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
int numberOfEvents = readNormalNr(bufor,i); i+=4;
|
|
|
|
for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
|
|
|
|
{
|
|
|
|
CMapEvent ne;
|
|
|
|
ne.name = std::string();
|
|
|
|
ne.message = std::string();
|
|
|
|
int nameLen = readNormalNr(bufor,i); i+=4;
|
|
|
|
for(int qq=0; qq<nameLen; ++qq)
|
|
|
|
{
|
|
|
|
ne.name += bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
int messLen = readNormalNr(bufor,i); i+=4;
|
|
|
|
for(int qq=0; qq<messLen; ++qq)
|
|
|
|
{
|
|
|
|
ne.message +=bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
ne.wood = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.mercury = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.ore = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.sulfur = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.crystal = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.gems = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.gold = readNormalNr(bufor,i); i+=4;
|
|
|
|
ne.players = bufor[i]; ++i;
|
|
|
|
if(version>AB)
|
|
|
|
{
|
|
|
|
ne.humanAffected = bufor[i]; ++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ne.humanAffected = true;
|
|
|
|
ne.computerAffected = bufor[i]; ++i;
|
|
|
|
ne.firstOccurence = bufor[i]; ++i;
|
|
|
|
ne.nextOccurence = bufor[i]; ++i;
|
|
|
|
i+=18;
|
|
|
|
events.push_back(ne);
|
|
|
|
}
|
2008-08-30 00:41:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Mapa::isInTheMap( int3 pos )
|
|
|
|
{
|
|
|
|
if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
|
|
|
|
return false;
|
|
|
|
else return true;
|
2008-09-18 23:24:53 +03:00
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
|
|
|
|
void Mapa::loadQuest(CQuest * guard, unsigned char * bufor, int & i)
|
|
|
|
{
|
|
|
|
guard->missionType = bufor[i]; ++i;
|
|
|
|
int len1, len2, len3;
|
|
|
|
switch(guard->missionType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
guard->m2stats.resize(4);
|
|
|
|
for(int x=0; x<4; x++)
|
|
|
|
{
|
|
|
|
guard->m2stats[x] = bufor[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
guard->m13489val = readNormalNr(bufor,i); i+=4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
int artNumber = bufor[i]; ++i;
|
|
|
|
for(int yy=0; yy<artNumber; ++yy)
|
|
|
|
{
|
|
|
|
guard->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
int typeNumber = bufor[i]; ++i;
|
|
|
|
for(int hh=0; hh<typeNumber; ++hh)
|
|
|
|
{
|
|
|
|
ui32 creType = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
ui32 creNumb = readNormalNr(bufor,i, 2); i+=2;
|
|
|
|
guard->m6creatures.push_back(std::make_pair(creType,creNumb));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
guard->m7resources.resize(7);
|
|
|
|
for(int x=0; x<7; x++)
|
|
|
|
{
|
|
|
|
guard->m7resources[x] = readNormalNr(bufor,i);
|
|
|
|
i+=4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
guard->m13489val = bufor[i]; ++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int limit = readNormalNr(bufor,i); i+=4;
|
|
|
|
if(limit == ((int)0xffffffff))
|
|
|
|
{
|
|
|
|
guard->lastDay = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guard->lastDay = limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
guard->firstVisitText = readString(bufor,i);
|
|
|
|
guard->nextVisitText = readString(bufor,i);
|
|
|
|
guard->completedText = readString(bufor,i);
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMapInfo::countPlayers()
|
|
|
|
{
|
|
|
|
playerAmnt=humenPlayers=0;
|
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
|
|
|
if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
|
|
|
|
else if (players[i].canComputerPlay) {playerAmnt++;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapInfo::CMapInfo( std::string fname, unsigned char *map )
|
|
|
|
:CMapHeader(map),filename(fname)
|
|
|
|
{
|
|
|
|
countPlayers();
|
2008-12-27 03:01:59 +02:00
|
|
|
}
|