1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

* reading headers for RoE and AB maps

* some minor changes
This commit is contained in:
mateuszb 2007-08-23 17:38:00 +00:00
parent 9b8517db2a
commit 1541b33b62
5 changed files with 185 additions and 111 deletions

View File

@ -78,66 +78,90 @@ void CAmbarCendamo::deh3m()
for (pom=0;pom<length;pom++)
map.description+=bufor[i++];
map.difficulty = bufor[i++]; // reading map difficulty
map.levelLimit = bufor[i++]; // hero level limit
if(map.version != Eformat::RoE)
{
map.levelLimit = bufor[i++]; // hero level limit
}
else
{
map.levelLimit = 0;
}
for (pom=0;pom<8;pom++)
{
map.players[pom].canHumanPlay = bufor[i++];
map.players[pom].canComputerPlay = bufor[i++];
if ((!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay)))
{
i+=13;
switch(map.version)
{
case Eformat::SoD: case Eformat::WoG:
i+=13;
break;
case Eformat::AB:
i+=12;
break;
case Eformat::RoE:
i+=6;
break;
}
continue;
}
map.players[pom].AITactic = bufor[i++];
if (bufor[i++])
{
map.players[pom].allowedFactions = 0;
map.players[pom].allowedFactions += bufor[i++];
if(map.version == Eformat::SoD || map.version == Eformat::WoG)
i++;
map.players[pom].allowedFactions = 0;
map.players[pom].allowedFactions += bufor[i++];
if(map.version != Eformat::RoE)
map.players[pom].allowedFactions += (bufor[i++])*256;
}
else
{
map.players[pom].allowedFactions = 511;
i+=2;
}
map.players[pom].isFactionRandom = bufor[i++];
map.players[pom].hasMainTown = bufor[i++];
if (map.players[pom].hasMainTown)
{
map.players[pom].generateHeroAtMainTown = bufor[i++];
map.players[pom].generateHero = bufor[i++];
if(map.version != Eformat::RoE)
{
map.players[pom].generateHeroAtMainTown = bufor[i++];
map.players[pom].generateHero = bufor[i++];
}
map.players[pom].posOfMainTown.x = bufor[i++];
map.players[pom].posOfMainTown.y = bufor[i++];
map.players[pom].posOfMainTown.z = bufor[i++];
}
i++; //unknown byte
int unknown = bufor[i++];
if (unknown == 255)
i++; //unknown
if(bufor[i++]!=0xff)
{
map.players[pom].mainHeroPortrait = 255;
i+=5;
continue;
map.players[pom].mainHeroPortrait = bufor[i++];
int nameLength = bufor[i++];
i+=3;
for (int pp=0;pp<nameLength;pp++)
map.players[pom].mainHeroName+=bufor[i++];
}
map.players[pom].mainHeroPortrait = bufor[i++];
int nameLength = bufor[i++];
i+=3;
for (int pp=0;pp<nameLength;pp++)
map.players[pom].mainHeroName+=bufor[i++];
i++; ////unknown byte
int heroCount = bufor[i++];
i+=3;
for (int pp=0;pp<heroCount;pp++)
//i++; //unknown byte
if(map.version != Eformat::RoE)
{
SheroName vv;
vv.heroID=bufor[i++];
int hnl = bufor[i++];
i++; ////unknown byte
int heroCount = bufor[i++];
i+=3;
for (int zz=0;zz<hnl;zz++)
for (int pp=0;pp<heroCount;pp++)
{
vv.heroName+=bufor[i++];
SheroName vv;
vv.heroID=bufor[i++];
int hnl = bufor[i++];
i+=3;
for (int zz=0;zz<hnl;zz++)
{
vv.heroName+=bufor[i++];
}
map.players[pom].heroesNames.push_back(vv);
}
map.players[pom].heroesNames.push_back(vv);
}
}
map.victoryCondition = (EvictoryConditions)bufor[i++];
@ -226,13 +250,13 @@ void CAmbarCendamo::deh3m()
case takeDwellings:
{
map.vicConDetails = new CspecificVictoryConidtions();
nr=3;
nr=0;
break;
}
case takeMines:
{
map.vicConDetails = new CspecificVictoryConidtions();
nr=3;
nr=0;
break;
}
case transportItem:
@ -283,8 +307,10 @@ void CAmbarCendamo::deh3m()
}
}
//reading allowed heroes (20 bytes)
int ist=i; //starting i for loop
for(i; i<ist+20; ++i)
int ist;
ist=i; //starting i for loop
for(i; i<ist+ (map.version == Eformat::RoE ? 16 : 20) ; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
@ -299,54 +325,71 @@ void CAmbarCendamo::deh3m()
}
}
//allowed heroes have been read
i+=36;
//reading allowed artifacts //18 bytes
ist=i; //starting i for loop
for(i; i<ist+18; ++i)
switch(map.version)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
case SoD: case WoG:
i+=36;
break;
case AB:
i+=35;
break;
case RoE:
i+=31;
break;
}
//reading allowed artifacts //18 bytes
if(map.version!=RoE)
{
ist=i; //starting i for loop
for(i; i<ist+18; ++i)
{
if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
}
}
}
}//allowed artifacts have been read
}//allowed artifacts have been read
}
//reading allowed spells (9 bytes)
ist=i; //starting i for loop
for(i; i<ist+9; ++i)
if(map.version>=SoD)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
ist=i; //starting i for loop
for(i; i<ist+9; ++i)
{
if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
}
}
}
}
//allowed spells have been read
//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)
//allowed spells have been read
//allowed hero's abilities (4 bytes)
ist=i; //starting i for loop
for(i; i<ist+4; ++i)
{
if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true;
else
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false;
if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true;
else
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false;
}
}
}
}
@ -366,7 +409,15 @@ void CAmbarCendamo::deh3m()
map.rumors.push_back(ourRumor); //add to our list
}
THC std::cout<<"Reading rumors: "<<th.getDif()<<std::endl;
i+=156;
switch(map.version)
{
case WoG: case SoD: case AB:
i+=156;
break;
case RoE:
i+=0;
break;
}
for (int c=0; c<map.width; c++) // reading terrain
{
for (int z=0; z<map.height; z++)

View File

@ -210,7 +210,7 @@ int _tmain(int argc, _TCHAR* argv[])
#ifdef CHOOSE
CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf
#else
CAmbarCendamo * ac = new CAmbarCendamo("1smok"); //4gryf
CAmbarCendamo * ac = new CAmbarCendamo("RoEtest"); //4gryf
#endif
CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nagłówka
cgi->ac = ac;

Binary file not shown.

89
map.cpp
View File

@ -37,66 +37,87 @@ CMapHeader::CMapHeader(unsigned char *map)
for (pom=0;pom<length;pom++)
this->description+=map[i++];
this->difficulty = map[i++]; // reading map difficulty
this->levelLimit = map[i++]; // hero level limit
if(version!=Eformat::RoE)
{
this->levelLimit = map[i++]; // hero level limit
}
else
{
levelLimit = 0;
}
for (pom=0;pom<8;pom++)
{
this->players[pom].canHumanPlay = map[i++];
this->players[pom].canComputerPlay = map[i++];
if ((!(this->players[pom].canHumanPlay || this->players[pom].canComputerPlay)))
{
i+=13;
switch(version)
{
case Eformat::SoD: case Eformat::WoG:
i+=13;
break;
case Eformat::AB:
i+=12;
break;
case Eformat::RoE:
i+=6;
break;
}
continue;
}
this->players[pom].AITactic = map[i++];
/*if (map[i++])*/i++;
{
this->players[pom].allowedFactions = 0;
this->players[pom].allowedFactions += map[i++];
if(version == Eformat::SoD || version == Eformat::WoG)
i++;
this->players[pom].allowedFactions = 0;
this->players[pom].allowedFactions += map[i++];
if(version != Eformat::RoE)
this->players[pom].allowedFactions += (map[i++])*256;
}
//else
//{
// this->players[pom].allowedFactions = 511;
// i+=2;
//}
this->players[pom].isFactionRandom = map[i++];
this->players[pom].hasMainTown = map[i++];
if (this->players[pom].hasMainTown)
{
this->players[pom].generateHeroAtMainTown = map[i++];
this->players[pom].generateHero = map[i++];
if(version != Eformat::RoE)
{
this->players[pom].generateHeroAtMainTown = map[i++];
this->players[pom].generateHero = map[i++];
}
this->players[pom].posOfMainTown.x = map[i++];
this->players[pom].posOfMainTown.y = map[i++];
this->players[pom].posOfMainTown.z = map[i++];
this->players[pom].posOfMainTown.z = map[i++];
}
i++; //unknown byte
int customPortrait = map[i++];
if (customPortrait == 255)
if (customPortrait != 255)
{
this->players[pom].mainHeroPortrait = 255;
i+=5;
continue;
players[pom].mainHeroPortrait = map[i++];
int nameLength = map[i++];
i+=3;
for (int pp=0;pp<nameLength;pp++)
players[pom].mainHeroName+=map[i++];
}
this->players[pom].mainHeroPortrait = map[i++];
int nameLength = map[i++];
i+=3;
for (int pp=0;pp<nameLength;pp++)
this->players[pom].mainHeroName+=map[i++];
i++; ////heroes placeholders //domostwa
int heroCount = map[i++];
i+=3;
for (int pp=0;pp<heroCount;pp++)
if(version!=Eformat::RoE)
{
SheroName vv;
vv.heroID=map[i++];
int hnl = map[i++];
i++; ////heroes placeholders //domostwa
int heroCount = map[i++];
i+=3;
for (int zz=0;zz<hnl;zz++)
for (int pp=0;pp<heroCount;pp++)
{
vv.heroName+=map[i++];
SheroName vv;
vv.heroID=map[i++];
int hnl = map[i++];
i+=3;
for (int zz=0;zz<hnl;zz++)
{
vv.heroName+=map[i++];
}
this->players[pom].heroesNames.push_back(vv);
}
this->players[pom].heroesNames.push_back(vv);
}
}
this->victoryCondition = (EvictoryConditions)map[i++];

View File

@ -469,8 +469,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
////printing roads
for (int bx=0; bx<dx; bx++)
{
for (int by=0; by<dy; by++)
for (int by=-1; by<dy; by++)
{
if(y+by<=-4)
continue;
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32+16;
sr->x=bx*32;