mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
Code cleaning/refactoring
This commit is contained in:
@ -9,6 +9,7 @@
|
|||||||
#include "CCallback.h"
|
#include "CCallback.h"
|
||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
#include "hch\CGeneralTextHandler.h"
|
#include "hch\CGeneralTextHandler.h"
|
||||||
|
#include "client/CCreatureAnimation.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
5
CMT.cpp
5
CMT.cpp
@ -26,7 +26,6 @@
|
|||||||
#include "hch\CObjectHandler.h"
|
#include "hch\CObjectHandler.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "hch\CMusicHandler.h"
|
#include "hch\CMusicHandler.h"
|
||||||
#include "hch\CSemiLodHandler.h"
|
|
||||||
#include "hch\CLodHandler.h"
|
#include "hch\CLodHandler.h"
|
||||||
#include "hch\CDefHandler.h"
|
#include "hch\CDefHandler.h"
|
||||||
#include "hch\CSndHandler.h"
|
#include "hch\CSndHandler.h"
|
||||||
@ -855,12 +854,12 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
|
||||||
ac->deh3m();
|
ac->deh3m();
|
||||||
THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
|
||||||
ac->loadDefs();
|
|
||||||
THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;
|
|
||||||
CMapHandler * mh = new CMapHandler();
|
CMapHandler * mh = new CMapHandler();
|
||||||
cgi->mh = mh;
|
cgi->mh = mh;
|
||||||
mh->reader = ac;
|
mh->reader = ac;
|
||||||
THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
|
||||||
|
mh->loadDefs();
|
||||||
|
THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;
|
||||||
mh->init();
|
mh->init();
|
||||||
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "CMessage.h"
|
#include "CMessage.h"
|
||||||
#include "SDL_TTF.h"
|
#include "SDL_TTF.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "hch\CDefHandler.h"
|
#include "hch\CDefHandler.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
@ -10,7 +9,6 @@
|
|||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include "CPlayerInterface.h"
|
#include "CPlayerInterface.h"
|
||||||
#include "hch\CDefHandler.h"
|
#include "hch\CDefHandler.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -48,7 +48,7 @@ vector<Coordinate>* CPathfinder::GetPath(const CGHeroInstance* hero)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blockLandSea = indeterminate;
|
blockLandSea = boost::logic::indeterminate;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcG(&Start);
|
CalcG(&Start);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "CBattleInterface.h"
|
#include "CBattleInterface.h"
|
||||||
#include "CLua.h"
|
#include "CLua.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "client/CCreatureAnimation.h"
|
||||||
using namespace CSDL_Ext;
|
using namespace CSDL_Ext;
|
||||||
|
|
||||||
extern TTF_Font * GEOR16;
|
extern TTF_Font * GEOR16;
|
||||||
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
@ -4,8 +4,6 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "StartInfo.h"
|
#include "StartInfo.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "hch\CSemiLodHandler.h"
|
|
||||||
#include "hch\CPreGameTextHandler.h"
|
#include "hch\CPreGameTextHandler.h"
|
||||||
#include "CMessage.h"
|
#include "CMessage.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
373
client/CCreatureAnimation.cpp
Normal file
373
client/CCreatureAnimation.cpp
Normal file
@ -0,0 +1,373 @@
|
|||||||
|
#include "CCreatureAnimation.h"
|
||||||
|
#include "../CGameInfo.h"
|
||||||
|
#include "../hch/CLodHandler.h"
|
||||||
|
int CCreatureAnimation::getType() const
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCreatureAnimation::setType(int type)
|
||||||
|
{
|
||||||
|
this->type = type;
|
||||||
|
curFrame = 0;
|
||||||
|
if(type!=-1)
|
||||||
|
{
|
||||||
|
if(SEntries[curFrame].group!=type) //rewind
|
||||||
|
{
|
||||||
|
int j=-1; //first frame in displayed group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
|
{
|
||||||
|
if(SEntries[g].group==type && j==-1)
|
||||||
|
{
|
||||||
|
j = g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(curFrame!=-1)
|
||||||
|
curFrame = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(curFrame>=frames)
|
||||||
|
curFrame = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL)
|
||||||
|
{
|
||||||
|
//load main file
|
||||||
|
std::string data2 = CGI->spriteh->getTextFile(name);
|
||||||
|
if(data2.size()==0)
|
||||||
|
throw new std::string("no such def!");
|
||||||
|
FDef = new unsigned char[data2.size()];
|
||||||
|
for(int g=0; g<data2.size(); ++g)
|
||||||
|
{
|
||||||
|
FDef[g] = data2[g];
|
||||||
|
}
|
||||||
|
|
||||||
|
//init anim data
|
||||||
|
int i,j, totalInBlock;
|
||||||
|
char Buffer[13];
|
||||||
|
defName=name;
|
||||||
|
int andame = data2.size();
|
||||||
|
i = 0;
|
||||||
|
DEFType = readNormalNr(i,4); i+=4;
|
||||||
|
fullWidth = readNormalNr(i,4); i+=4;
|
||||||
|
fullHeight = readNormalNr(i,4); i+=4;
|
||||||
|
i=0xc;
|
||||||
|
totalBlocks = readNormalNr(i,4); i+=4;
|
||||||
|
|
||||||
|
i=0x10;
|
||||||
|
for (int it=0;it<256;it++)
|
||||||
|
{
|
||||||
|
palette[it].R = FDef[i++];
|
||||||
|
palette[it].G = FDef[i++];
|
||||||
|
palette[it].B = FDef[i++];
|
||||||
|
palette[it].F = 0;
|
||||||
|
}
|
||||||
|
i=0x310;
|
||||||
|
totalEntries=0;
|
||||||
|
for (int z=0; z<totalBlocks; z++)
|
||||||
|
{
|
||||||
|
int unknown1 = readNormalNr(i,4); i+=4;
|
||||||
|
totalInBlock = readNormalNr(i,4); i+=4;
|
||||||
|
for (j=SEntries.size(); j<totalEntries+totalInBlock; j++)
|
||||||
|
SEntries.push_back(SEntry());
|
||||||
|
int unknown2 = readNormalNr(i,4); i+=4;
|
||||||
|
int unknown3 = readNormalNr(i,4); i+=4;
|
||||||
|
for (j=0; j<totalInBlock; j++)
|
||||||
|
{
|
||||||
|
for (int k=0;k<13;k++) Buffer[k]=FDef[i+k];
|
||||||
|
i+=13;
|
||||||
|
SEntries[totalEntries+j].name=Buffer;
|
||||||
|
}
|
||||||
|
for (j=0; j<totalInBlock; j++)
|
||||||
|
{
|
||||||
|
SEntries[totalEntries+j].offset = readNormalNr(i,4);
|
||||||
|
int unknown4 = readNormalNr(i,4); i+=4;
|
||||||
|
}
|
||||||
|
//totalEntries+=totalInBlock;
|
||||||
|
for(int hh=0; hh<totalInBlock; ++hh)
|
||||||
|
{
|
||||||
|
SEntries[totalEntries].group = z;
|
||||||
|
++totalEntries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(j=0; j<SEntries.size(); ++j)
|
||||||
|
{
|
||||||
|
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
|
||||||
|
}
|
||||||
|
//pictures don't have to be readed here
|
||||||
|
//for(int i=0; i<SEntries.size(); ++i)
|
||||||
|
//{
|
||||||
|
// Cimage nimg;
|
||||||
|
// nimg.bitmap = getSprite(i);
|
||||||
|
// nimg.imName = SEntries[i].name;
|
||||||
|
// nimg.groupNumber = SEntries[i].group;
|
||||||
|
// ourImages.push_back(nimg);
|
||||||
|
//}
|
||||||
|
//delete FDef;
|
||||||
|
//FDef = NULL;
|
||||||
|
|
||||||
|
//init vars
|
||||||
|
curFrame = 0;
|
||||||
|
type = -1;
|
||||||
|
frames = totalEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic)
|
||||||
|
{
|
||||||
|
int ret=0;
|
||||||
|
int amp=1;
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
for (int i=0; i<bytCon; i++)
|
||||||
|
{
|
||||||
|
ret+=str[pos+i]*amp;
|
||||||
|
amp*=256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i=0; i<bytCon; i++)
|
||||||
|
{
|
||||||
|
ret+=FDef[pos+i]*amp;
|
||||||
|
amp*=256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(cyclic && bytCon<4 && ret>=amp/2)
|
||||||
|
{
|
||||||
|
ret = ret-amp;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect)
|
||||||
|
{
|
||||||
|
return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder,destRect);
|
||||||
|
}
|
||||||
|
int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect)
|
||||||
|
{
|
||||||
|
if(dest->format->BytesPerPixel<3)
|
||||||
|
return -1; //not enough depth
|
||||||
|
|
||||||
|
//increasing frame numer
|
||||||
|
int SIndex = -1;
|
||||||
|
if(incrementFrame)
|
||||||
|
{
|
||||||
|
SIndex = curFrame++;
|
||||||
|
if(type!=-1)
|
||||||
|
{
|
||||||
|
if(SEntries[curFrame].group!=type) //rewind
|
||||||
|
{
|
||||||
|
int j=-1; //first frame in displayed group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
|
{
|
||||||
|
if(SEntries[g].group==type && j==-1)
|
||||||
|
{
|
||||||
|
j = g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(curFrame!=-1)
|
||||||
|
curFrame = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(curFrame>=frames)
|
||||||
|
curFrame = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SIndex = curFrame;
|
||||||
|
}
|
||||||
|
//frame number increased
|
||||||
|
|
||||||
|
long BaseOffset,
|
||||||
|
SpriteWidth, SpriteHeight, //sprite format
|
||||||
|
LeftMargin, RightMargin, TopMargin,BottomMargin,
|
||||||
|
i, add, FullHeight,FullWidth,
|
||||||
|
TotalRowLength, // length of read segment
|
||||||
|
RowAdd;
|
||||||
|
unsigned char SegmentType, SegmentLength;
|
||||||
|
|
||||||
|
i=BaseOffset=SEntries[SIndex].offset;
|
||||||
|
int prSize=readNormalNr(i,4,FDef);i+=4;
|
||||||
|
int defType2 = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
FullWidth = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
FullHeight = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
SpriteWidth = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
SpriteHeight = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
LeftMargin = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
TopMargin = readNormalNr(i,4,FDef);i+=4;
|
||||||
|
RightMargin = FullWidth - SpriteWidth - LeftMargin;
|
||||||
|
BottomMargin = FullHeight - SpriteHeight - TopMargin;
|
||||||
|
|
||||||
|
add = 4 - FullWidth%4;
|
||||||
|
|
||||||
|
int BaseOffsetor = BaseOffset = i;
|
||||||
|
|
||||||
|
int ftcp = 0;
|
||||||
|
|
||||||
|
if (defType2==1) //as it should be allways in creature animations
|
||||||
|
{
|
||||||
|
if (TopMargin>0)
|
||||||
|
{
|
||||||
|
for (int i=0;i<TopMargin;i++)
|
||||||
|
{
|
||||||
|
ftcp+=FullWidth+add;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RLEntries = new int[SpriteHeight];
|
||||||
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
|
{
|
||||||
|
RLEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4;
|
||||||
|
}
|
||||||
|
for (int i=0;i<SpriteHeight;i++)
|
||||||
|
{
|
||||||
|
BaseOffset=BaseOffsetor+RLEntries[i];
|
||||||
|
if (LeftMargin>0)
|
||||||
|
{
|
||||||
|
ftcp+=LeftMargin;
|
||||||
|
}
|
||||||
|
TotalRowLength=0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
SegmentType=FDef[BaseOffset++];
|
||||||
|
SegmentLength=FDef[BaseOffset++];
|
||||||
|
if (SegmentType==0xFF)
|
||||||
|
{
|
||||||
|
for (int k=0;k<=SegmentLength;k++)
|
||||||
|
{
|
||||||
|
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
|
||||||
|
int yB = ftcp/(FullWidth+add) + y;
|
||||||
|
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
||||||
|
{
|
||||||
|
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
||||||
|
putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder);
|
||||||
|
}
|
||||||
|
ftcp++; //increment pos
|
||||||
|
if ((TotalRowLength+k+1)>=SpriteWidth)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BaseOffset+=SegmentLength+1;////
|
||||||
|
TotalRowLength+=SegmentLength+1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int k=0;k<SegmentLength+1;k++)
|
||||||
|
{
|
||||||
|
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
|
||||||
|
int yB = ftcp/(FullWidth+add) + y;
|
||||||
|
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
||||||
|
{
|
||||||
|
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
||||||
|
putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder);
|
||||||
|
}
|
||||||
|
ftcp++; //increment pos
|
||||||
|
}
|
||||||
|
TotalRowLength+=SegmentLength+1;
|
||||||
|
}
|
||||||
|
}while(TotalRowLength<SpriteWidth);
|
||||||
|
RowAdd=SpriteWidth-TotalRowLength;
|
||||||
|
if (RightMargin>0)
|
||||||
|
{
|
||||||
|
ftcp+=RightMargin;
|
||||||
|
}
|
||||||
|
if (add>0)
|
||||||
|
{
|
||||||
|
ftcp+=add+RowAdd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete [] RLEntries;
|
||||||
|
RLEntries = NULL;
|
||||||
|
if (BottomMargin>0)
|
||||||
|
{
|
||||||
|
ftcp += BottomMargin * (FullWidth+add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CCreatureAnimation::framesInGroup(int group) const
|
||||||
|
{
|
||||||
|
int ret = 0; //number of frames in given group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
|
{
|
||||||
|
if(SEntries[g].group == group)
|
||||||
|
++ret;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCreatureAnimation::~CCreatureAnimation()
|
||||||
|
{
|
||||||
|
delete [] FDef;
|
||||||
|
if (RWEntries)
|
||||||
|
delete [] RWEntries;
|
||||||
|
if (RLEntries)
|
||||||
|
delete [] RLEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const
|
||||||
|
{
|
||||||
|
if(palc!=0)
|
||||||
|
{
|
||||||
|
Uint8 * p = (Uint8*)dest->pixels + ftcp*3;
|
||||||
|
if(palc > 7) //normal color
|
||||||
|
{
|
||||||
|
p[0] = color.B;
|
||||||
|
p[1] = color.G;
|
||||||
|
p[2] = color.R;
|
||||||
|
}
|
||||||
|
else if(yellowBorder && (palc == 6 || palc == 7)) //dark yellow border
|
||||||
|
{
|
||||||
|
p[0] = 0;
|
||||||
|
p[1] = 0xff;
|
||||||
|
p[2] = 0xff;
|
||||||
|
}
|
||||||
|
else if(yellowBorder && (palc == 5)) //yellow border
|
||||||
|
{
|
||||||
|
p[0] = color.B;
|
||||||
|
p[1] = color.G;
|
||||||
|
p[2] = color.R;
|
||||||
|
}
|
||||||
|
else if(palc < 5) //shadow
|
||||||
|
{
|
||||||
|
Uint16 alpha;
|
||||||
|
switch(color.G)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
alpha = 128;
|
||||||
|
break;
|
||||||
|
case 50:
|
||||||
|
alpha = 50+32;
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
alpha = 100+64;
|
||||||
|
break;
|
||||||
|
case 125:
|
||||||
|
alpha = 125+64;
|
||||||
|
break;
|
||||||
|
case 128:
|
||||||
|
alpha = 128+64;
|
||||||
|
break;
|
||||||
|
case 150:
|
||||||
|
alpha = 150+64;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
alpha = 255;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//alpha counted
|
||||||
|
p[0] = (p[0] * alpha)>>8;
|
||||||
|
p[1] = (p[1] * alpha)>>8;
|
||||||
|
p[2] = (p[2] * alpha)>>8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
client/CCreatureAnimation.h
Normal file
45
client/CCreatureAnimation.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../global.h"
|
||||||
|
#include "../CPlayerInterface.h"
|
||||||
|
#include "../hch/CDefHandler.h"
|
||||||
|
|
||||||
|
class CCreatureAnimation : public CIntObject
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int totalEntries, DEFType, totalBlocks;
|
||||||
|
bool allowRepaint;
|
||||||
|
int length;
|
||||||
|
BMPPalette palette[256];
|
||||||
|
unsigned int * RWEntries;
|
||||||
|
int * RLEntries;
|
||||||
|
struct SEntry
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
int offset;
|
||||||
|
int group;
|
||||||
|
} ;
|
||||||
|
std::vector<SEntry> SEntries ;
|
||||||
|
char id[2];
|
||||||
|
std::string defName, curDir;
|
||||||
|
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
||||||
|
void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
|
||||||
|
|
||||||
|
////////////
|
||||||
|
|
||||||
|
unsigned char * FDef; //animation raw data
|
||||||
|
unsigned int curFrame; //number of currently displayed frame
|
||||||
|
unsigned int frames; //number of frames
|
||||||
|
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
|
||||||
|
public:
|
||||||
|
int fullWidth, fullHeight; //read-only, please!
|
||||||
|
CCreatureAnimation(std::string name); //c-tor
|
||||||
|
~CCreatureAnimation(); //d-tor
|
||||||
|
|
||||||
|
void setType(int type); //sets type of animation and cleares framecount
|
||||||
|
int getType() const; //returns type of animation
|
||||||
|
|
||||||
|
int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
|
||||||
|
int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
|
||||||
|
|
||||||
|
int framesInGroup(int group) const; //retirns number of fromes in given group
|
||||||
|
};
|
@ -1,20 +1,18 @@
|
|||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "CAmbarCendamo.h"
|
#include "CAmbarCendamo.h"
|
||||||
#include "CSemiDefHandler.h"
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
#include "CCastleHandler.h"
|
#include "CCastleHandler.h"
|
||||||
#include "CTownHandler.h"
|
#include "CTownHandler.h"
|
||||||
#include "CDefObjInfoHandler.h"
|
#include "CDefObjInfoHandler.h"
|
||||||
#include "../SDL_Extensions.h"
|
#include "../SDL_Extensions.h"
|
||||||
#include "boost\filesystem.hpp"
|
|
||||||
#include "../CGameState.h"
|
#include "../CGameState.h"
|
||||||
#include "CLodHandler.h"
|
#include "CLodHandler.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "../CLua.h"
|
#include <fstream>
|
||||||
|
std::string nameFromType (EterrainType typ);
|
||||||
int readInt(unsigned char * bufor, int bytCon)
|
int readInt(unsigned char * bufor, int bytCon)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
@ -51,10 +49,10 @@ CAmbarCendamo::CAmbarCendamo (unsigned char * map)
|
|||||||
}
|
}
|
||||||
CAmbarCendamo::CAmbarCendamo (const char * tie)
|
CAmbarCendamo::CAmbarCendamo (const char * tie)
|
||||||
{
|
{
|
||||||
is = new std::ifstream();
|
std::ifstream * is = new std::ifstream();
|
||||||
is -> open(tie,std::ios::binary);
|
is -> open(tie,std::ios::binary);
|
||||||
is->seekg(0,std::ios::end); // na koniec
|
is->seekg(0,std::ios::end); // na koniec
|
||||||
andame = is->tellg(); // read length
|
int andame = is->tellg(); // read length
|
||||||
is->seekg(0,std::ios::beg); // wracamy na poczatek
|
is->seekg(0,std::ios::beg); // wracamy na poczatek
|
||||||
bufor = new unsigned char[andame]; // allocate memory
|
bufor = new unsigned char[andame]; // allocate memory
|
||||||
is->read((char*)bufor, andame); // read map file to buffer
|
is->read((char*)bufor, andame); // read map file to buffer
|
||||||
@ -66,20 +64,7 @@ CAmbarCendamo::~CAmbarCendamo ()
|
|||||||
for (int ii=0;ii<map.width;ii++)
|
for (int ii=0;ii<map.width;ii++)
|
||||||
delete map.terrain[ii] ;
|
delete map.terrain[ii] ;
|
||||||
delete map.terrain;
|
delete map.terrain;
|
||||||
delete bufor;
|
delete[] bufor;
|
||||||
}
|
|
||||||
void CAmbarCendamo::teceDef()
|
|
||||||
{
|
|
||||||
//for (int i=0; i<map.defy.size(); i++)
|
|
||||||
//{
|
|
||||||
// std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
|
|
||||||
// for (int j=0;j<46;j++)
|
|
||||||
// {
|
|
||||||
// (*of) << map.defy[i].bytes[j]<<std::endl;
|
|
||||||
// }
|
|
||||||
// of->close();
|
|
||||||
// delete of;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
std::set<int> convertBuildings(const std::set<int> h3m, int castleID)
|
std::set<int> convertBuildings(const std::set<int> h3m, int castleID)
|
||||||
{
|
{
|
||||||
@ -153,8 +138,8 @@ void CAmbarCendamo::deh3m()
|
|||||||
for (int ii=0;ii<map.width;ii++)
|
for (int ii=0;ii<map.width;ii++)
|
||||||
map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
|
map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
|
||||||
}
|
}
|
||||||
int length = bufor[10]; //name length
|
int pom, length = bufor[10]; //name length
|
||||||
int i=14, pom;
|
i=14;
|
||||||
while (i-14<length) //read name
|
while (i-14<length) //read name
|
||||||
map.name+=bufor[i++];
|
map.name+=bufor[i++];
|
||||||
length = bufor[i] + bufor[i+1]*256; //description length
|
length = bufor[i] + bufor[i+1]*256; //description length
|
||||||
@ -787,24 +772,25 @@ void CAmbarCendamo::deh3m()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
THC std::cout<<"\tReading terrain: "<<th.getDif()<<std::endl;
|
THC std::cout<<"\tReading terrain: "<<th.getDif()<<std::endl;
|
||||||
int defAmount = bufor[i]; // liczba defow
|
|
||||||
defAmount = readNormalNr(i);
|
|
||||||
i+=4;
|
|
||||||
|
|
||||||
std::vector<std::string> defsToUnpack;
|
//////READING DEF INFO///////
|
||||||
|
int defAmount = readNormalNr(i); i+=4;
|
||||||
|
map.defy.reserve(defAmount);
|
||||||
|
|
||||||
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
|
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
|
||||||
{
|
{
|
||||||
int nameLength = readNormalNr(i,4);i+=4;
|
|
||||||
CGDefInfo * vinya = new CGDefInfo(); // info about new def
|
CGDefInfo * vinya = new CGDefInfo(); // info about new def
|
||||||
|
|
||||||
|
//reading name
|
||||||
|
int nameLength = readNormalNr(i,4);i+=4;
|
||||||
|
vinya->name.reserve(nameLength);
|
||||||
for (int cd=0;cd<nameLength;cd++)
|
for (int cd=0;cd<nameLength;cd++)
|
||||||
{
|
{
|
||||||
vinya->name += bufor[i++];
|
vinya->name += bufor[i++];
|
||||||
}
|
}
|
||||||
//for (int v=0; v<42; v++) // read info
|
|
||||||
//{
|
|
||||||
// vinya->bytes[v] = bufor[i++];
|
|
||||||
//}
|
|
||||||
std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper);
|
std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper);
|
||||||
|
|
||||||
|
|
||||||
unsigned char bytes[12];
|
unsigned char bytes[12];
|
||||||
for (int v=0; v<12; v++) // read info
|
for (int v=0; v<12; v++) // read info
|
||||||
{
|
{
|
||||||
@ -826,9 +812,9 @@ void CAmbarCendamo::deh3m()
|
|||||||
}
|
}
|
||||||
i+=16;
|
i+=16;
|
||||||
map.defy.push_back(vinya); // add this def to the vector
|
map.defy.push_back(vinya); // add this def to the vector
|
||||||
defsToUnpack.push_back(vinya->name);
|
|
||||||
}
|
}
|
||||||
THC std::cout<<"\tReading defs: "<<th.getDif()<<std::endl;
|
THC std::cout<<"\tReading defs info: "<<th.getDif()<<std::endl;
|
||||||
|
|
||||||
////loading objects
|
////loading objects
|
||||||
int howManyObjs = readNormalNr(i, 4); i+=4;
|
int howManyObjs = readNormalNr(i, 4); i+=4;
|
||||||
for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
|
for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
|
||||||
@ -844,14 +830,8 @@ void CAmbarCendamo::deh3m()
|
|||||||
nobj->defInfo = map.defy[tempd];
|
nobj->defInfo = map.defy[tempd];
|
||||||
nobj->ID = nobj->defInfo->id;
|
nobj->ID = nobj->defInfo->id;
|
||||||
nobj->subID = nobj->defInfo->subid;
|
nobj->subID = nobj->defInfo->subid;
|
||||||
//nobj->defInfo = readNormalNr(i, 4); i+=4;
|
|
||||||
//nobj->isHero = false;
|
|
||||||
//nobj->moveDir = 0;
|
|
||||||
//nobj->isStanding = true;
|
|
||||||
//nobj->state->owner = 254; //a lot of objs will never have an owner
|
|
||||||
|
|
||||||
//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
|
//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size()) std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
|
||||||
// std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
|
|
||||||
|
|
||||||
i+=5;
|
i+=5;
|
||||||
unsigned char buff [30];
|
unsigned char buff [30];
|
||||||
@ -859,10 +839,9 @@ void CAmbarCendamo::deh3m()
|
|||||||
{
|
{
|
||||||
buff[ccc] = bufor[i+ccc];
|
buff[ccc] = bufor[i+ccc];
|
||||||
}
|
}
|
||||||
EDefType uu = getDefType(nobj->defInfo);
|
|
||||||
int j = nobj->defInfo->id;
|
int j = nobj->defInfo->id;
|
||||||
int p = 99;
|
int p = 99;
|
||||||
switch(uu)
|
switch(getDefType(nobj->defInfo))
|
||||||
{
|
{
|
||||||
case EDefType::EVENTOBJ_DEF: //for event - objects
|
case EDefType::EVENTOBJ_DEF: //for event - objects
|
||||||
{
|
{
|
||||||
@ -884,7 +863,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->areGuarders = bufor[i]; ++i;
|
spec->areGuarders = bufor[i]; ++i;
|
||||||
if(spec->areGuarders)
|
if(spec->areGuarders)
|
||||||
{
|
{
|
||||||
spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28);
|
spec->guarders = readCreatureSet();
|
||||||
}
|
}
|
||||||
i+=4;
|
i+=4;
|
||||||
}
|
}
|
||||||
@ -927,7 +906,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
|
spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
|
||||||
}
|
}
|
||||||
int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
|
int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
|
||||||
spec->creatures = readCreatureSet(i, gcre); i+=3*gcre;
|
spec->creatures = readCreatureSet(gcre);
|
||||||
if(map.version>RoE)
|
if(map.version>RoE)
|
||||||
i+=gcre;
|
i+=gcre;
|
||||||
i+=8;
|
i+=8;
|
||||||
@ -996,7 +975,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->standardGarrison = standGarrison;
|
spec->standardGarrison = standGarrison;
|
||||||
if(standGarrison)
|
if(standGarrison)
|
||||||
{
|
{
|
||||||
spec->garrison = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28); //4 bytes per slot
|
spec->garrison = readCreatureSet();
|
||||||
}
|
}
|
||||||
bool form = bufor[i]; ++i; //formation
|
bool form = bufor[i]; ++i; //formation
|
||||||
spec->garrison.formation = form;
|
spec->garrison.formation = form;
|
||||||
@ -1726,7 +1705,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
CGarrisonObjInfo * spec = new CGarrisonObjInfo;
|
CGarrisonObjInfo * spec = new CGarrisonObjInfo;
|
||||||
spec->player = bufor[i]; ++i;
|
spec->player = bufor[i]; ++i;
|
||||||
i+=3;
|
i+=3;
|
||||||
spec->units = readCreatureSet(i); i+= (map.version==RoE ? 21 : 28);
|
spec->units = readCreatureSet();
|
||||||
if(map.version > RoE)
|
if(map.version > RoE)
|
||||||
{
|
{
|
||||||
spec->movableUnits = bufor[i]; ++i;
|
spec->movableUnits = bufor[i]; ++i;
|
||||||
@ -1753,7 +1732,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
if(areGuards)
|
if(areGuards)
|
||||||
{
|
{
|
||||||
spec->areGuards = true;
|
spec->areGuards = true;
|
||||||
spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28) ;
|
spec->guards = readCreatureSet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
spec->areGuards = false;
|
spec->areGuards = false;
|
||||||
@ -1776,7 +1755,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->areGuards = bufor[i]; ++i;
|
spec->areGuards = bufor[i]; ++i;
|
||||||
if(spec->areGuards)
|
if(spec->areGuards)
|
||||||
{
|
{
|
||||||
spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28);
|
spec->guards = readCreatureSet();
|
||||||
}
|
}
|
||||||
i+=4;
|
i+=4;
|
||||||
}
|
}
|
||||||
@ -1820,7 +1799,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
|
bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
|
||||||
if(stGarr)
|
if(stGarr)
|
||||||
{
|
{
|
||||||
spec->garrison = readCreatureSet(i); i+=( map.version > RoE ? 28 : 21 );
|
spec->garrison = readCreatureSet();
|
||||||
}
|
}
|
||||||
spec->garrison.formation = bufor[i]; ++i;
|
spec->garrison.formation = bufor[i]; ++i;
|
||||||
spec->unusualBuildins = bufor[i]; ++i;
|
spec->unusualBuildins = bufor[i]; ++i;
|
||||||
@ -2021,7 +2000,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->areGuarders = bufor[i]; ++i;
|
spec->areGuarders = bufor[i]; ++i;
|
||||||
if(spec->areGuarders)
|
if(spec->areGuarders)
|
||||||
{
|
{
|
||||||
spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28 );
|
spec->guarders = readCreatureSet();
|
||||||
}
|
}
|
||||||
i+=4;
|
i+=4;
|
||||||
}
|
}
|
||||||
@ -2044,7 +2023,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->areGuarders = bufor[i]; ++i;
|
spec->areGuarders = bufor[i]; ++i;
|
||||||
if(spec->areGuarders)
|
if(spec->areGuarders)
|
||||||
{
|
{
|
||||||
spec->guarders = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28);
|
spec->guarders = readCreatureSet();
|
||||||
}
|
}
|
||||||
i+=4;
|
i+=4;
|
||||||
}
|
}
|
||||||
@ -2089,7 +2068,7 @@ void CAmbarCendamo::deh3m()
|
|||||||
spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
|
spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
|
||||||
}
|
}
|
||||||
int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
|
int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
|
||||||
spec->creatures = readCreatureSet(i, gcre); i+=3*gcre;
|
spec->creatures = readCreatureSet(gcre);
|
||||||
if(map.version > RoE)
|
if(map.version > RoE)
|
||||||
i+=gcre;
|
i+=gcre;
|
||||||
i+=8;
|
i+=8;
|
||||||
@ -2376,23 +2355,18 @@ borderguardend:
|
|||||||
}
|
}
|
||||||
} //end of main switch
|
} //end of main switch
|
||||||
CGameInfo::mainObj->objh->objInstances.push_back(nobj);
|
CGameInfo::mainObj->objh->objInstances.push_back(nobj);
|
||||||
//TODO - doko�czy�, du�o do zrobienia - trzeba patrze�, co def niesie
|
}//end of loading objects
|
||||||
}//*/ //end of loading objects; commented to make application work until it will be finished
|
|
||||||
////objects loaded
|
|
||||||
|
|
||||||
THC std::cout<<"\tReading objects: "<<th.getDif()<<std::endl;
|
THC std::cout<<"\tReading objects: "<<th.getDif()<<std::endl;
|
||||||
//processMap(defsToUnpack);
|
|
||||||
std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
|
|
||||||
|
|
||||||
THC std::cout<<"\tUnpacking defs: "<<th.getDif()<<std::endl;
|
///loading defs from lod
|
||||||
for (int i=0;i<dhandlers.size();i++)
|
for (int ir=0;ir<map.defy.size();ir++)
|
||||||
{
|
{
|
||||||
map.defy[i]->handler=dhandlers[i];
|
map.defy[ir]->handler=CGI->spriteh->giveDef(map.defy[ir]->name);
|
||||||
CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[i]->id][map.defy[i]->subid];
|
CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[ir]->id][map.defy[ir]->subid];
|
||||||
if(pom)
|
if(pom)
|
||||||
pom->handler=dhandlers[i];
|
pom->handler=map.defy[ir]->handler;
|
||||||
else
|
else
|
||||||
std::cout << "Lacking def info for " << map.defy[i]->id << " " << map.defy[i]->subid <<" " << map.defy[i]->name << std::endl;
|
std::cout << "Lacking def info for " << map.defy[ir]->id << " " << map.defy[ir]->subid <<" " << map.defy[ir]->name << std::endl;
|
||||||
}
|
}
|
||||||
for(int vv=0; vv<map.defy.size(); ++vv)
|
for(int vv=0; vv<map.defy.size(); ++vv)
|
||||||
{
|
{
|
||||||
@ -2401,14 +2375,11 @@ borderguardend:
|
|||||||
for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
|
for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
|
||||||
{
|
{
|
||||||
map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
|
map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
|
||||||
//SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, CSDL_Ext::std32bppSurface);
|
|
||||||
//SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap);
|
|
||||||
//map.defy[vv]->handler->ourImages[yy].bitmap = bufs;
|
|
||||||
map.defy[vv]->handler->alphaTransformed = true;
|
map.defy[vv]->handler->alphaTransformed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
|
||||||
|
|
||||||
THC std::cout<<"\tHandling defs: "<<th.getDif()<<std::endl;
|
|
||||||
|
|
||||||
//loading events
|
//loading events
|
||||||
int numberOfEvents = readNormalNr(i); i+=4;
|
int numberOfEvents = readNormalNr(i); i+=4;
|
||||||
@ -2447,14 +2418,17 @@ borderguardend:
|
|||||||
i+=18;
|
i+=18;
|
||||||
map.events.push_back(ne);
|
map.events.push_back(ne);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//map readed, bufor no longer needed
|
||||||
|
delete[] bufor; bufor=NULL;
|
||||||
}
|
}
|
||||||
int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
|
int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
int amp=1;
|
int amp=1;
|
||||||
for (int i=0; i<bytCon; i++)
|
for (int ir=0; ir<bytCon; ir++)
|
||||||
{
|
{
|
||||||
ret+=bufor[pos+i]*amp;
|
ret+=bufor[pos+ir]*amp;
|
||||||
amp*=256;
|
amp*=256;
|
||||||
}
|
}
|
||||||
if(cyclic && bytCon<4 && ret>=amp/2)
|
if(cyclic && bytCon<4 && ret>=amp/2)
|
||||||
@ -2464,29 +2438,6 @@ int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAmbarCendamo::loadDefs()
|
|
||||||
{
|
|
||||||
std::set<int> loadedTypes;
|
|
||||||
for (int i=0; i<map.width; i++)
|
|
||||||
{
|
|
||||||
for (int j=0; j<map.width; j++)
|
|
||||||
{
|
|
||||||
if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
|
|
||||||
{
|
|
||||||
CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
|
|
||||||
loadedTypes.insert(map.terrain[i][j].tertype);
|
|
||||||
defs.push_back(sdh);
|
|
||||||
}
|
|
||||||
if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
|
|
||||||
{
|
|
||||||
CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
|
|
||||||
loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
|
|
||||||
defs.push_back(sdh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EDefType CAmbarCendamo::getDefType(CGDefInfo * a)
|
EDefType CAmbarCendamo::getDefType(CGDefInfo * a)
|
||||||
{
|
{
|
||||||
switch(a->id)
|
switch(a->id)
|
||||||
@ -2544,161 +2495,42 @@ EDefType CAmbarCendamo::getDefType(CGDefInfo * a)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
|
CCreatureSet CAmbarCendamo::readCreatureSet(int number)
|
||||||
{
|
{
|
||||||
if(map.version>RoE)
|
if(map.version>RoE)
|
||||||
{
|
{
|
||||||
CCreatureSet ret;
|
CCreatureSet ret;
|
||||||
std::pair<CCreature *, int> ins;
|
std::pair<CCreature *, int> ins;
|
||||||
if(number>0 && readNormalNr(pos, 2)!=0xffff)
|
for(int ir=0;ir<number;ir++)
|
||||||
{
|
{
|
||||||
int rettt = readNormalNr(pos, 2);
|
int rettt = readNormalNr(i+ir*4, 2);
|
||||||
|
if(rettt==0xffff) continue;
|
||||||
if(rettt>32768)
|
if(rettt>32768)
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
||||||
ins.second = readNormalNr(pos+2, 2);
|
ins.second = readNormalNr(i+ir*4+2, 2);
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
|
std::pair<int,std::pair<CCreature *, int> > tt(ir,ins);
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+4, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+6, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+8, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+10, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+12, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+14, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+16, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+18, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+20, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+22, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+24, 2);
|
|
||||||
if(rettt>32768)
|
|
||||||
rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+26, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
|
|
||||||
ret.slots.insert(tt);
|
ret.slots.insert(tt);
|
||||||
}
|
}
|
||||||
|
i+=number*4;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCreatureSet ret;
|
CCreatureSet ret;
|
||||||
std::pair<CCreature *, int> ins;
|
std::pair<CCreature *, int> ins;
|
||||||
if(number>0 && readNormalNr(pos, 1)!=0xff)
|
for(int ir=0;ir<number;ir++)
|
||||||
{
|
{
|
||||||
int rettt = readNormalNr(pos, 1);
|
int rettt = readNormalNr(i+ir*3, 1);
|
||||||
|
if(rettt==0xff) continue;
|
||||||
if(rettt>220)
|
if(rettt>220)
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
||||||
ins.second = readNormalNr(pos+1, 2);
|
ins.second = readNormalNr(i+ir*3+1, 2);
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
|
std::pair<int,std::pair<CCreature *, int> > tt(ir,ins);
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>1 && readNormalNr(pos+3, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+3, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+4, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>2 && readNormalNr(pos+6, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+6, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+7, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>3 && readNormalNr(pos+9, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+9, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+10, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>4 && readNormalNr(pos+12, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+12, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+13, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>5 && readNormalNr(pos+15, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+15, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+16, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
|
|
||||||
ret.slots.insert(tt);
|
|
||||||
}
|
|
||||||
if(number>6 && readNormalNr(pos+18, 1)!=0xff)
|
|
||||||
{
|
|
||||||
int rettt = readNormalNr(pos+18, 1);
|
|
||||||
if(rettt>220)
|
|
||||||
rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
|
|
||||||
ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
|
|
||||||
ins.second = readNormalNr(pos+19, 2);
|
|
||||||
std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
|
|
||||||
ret.slots.insert(tt);
|
ret.slots.insert(tt);
|
||||||
}
|
}
|
||||||
|
i+=number*3;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
|
|
||||||
{}
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#ifndef CAMBARCENDAMO_H
|
#ifndef CAMBARCENDAMO_H
|
||||||
#define CAMBARCENDAMO_H
|
#define CAMBARCENDAMO_H
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "../map.h"
|
#include "../map.h"
|
||||||
#include "CSemiDefHandler.h"
|
|
||||||
#include "CDefHandler.h"
|
#include "CDefHandler.h"
|
||||||
#include "CCreatureHandler.h"
|
#include "CCreatureHandler.h"
|
||||||
|
|
||||||
@ -18,23 +16,17 @@ class CAmbarCendamo
|
|||||||
public:
|
public:
|
||||||
/////////////////member variables
|
/////////////////member variables
|
||||||
Mapa map;
|
Mapa map;
|
||||||
std::ifstream * is; // stream used to read map file
|
|
||||||
int andame; // length of map file
|
//map file
|
||||||
unsigned char * bufor; // here we store map bytecode
|
unsigned char * bufor; // here we store map bytecode
|
||||||
std::vector<CDefHandler*> defs;
|
int i; //our pos in the file
|
||||||
/////////////////member functions
|
|
||||||
CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file
|
CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file
|
||||||
CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete
|
CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete
|
||||||
~CAmbarCendamo (); // d-tor
|
~CAmbarCendamo (); // d-tor
|
||||||
int readNormalNr (int pos, int bytCon=4, bool cyclic = false); //read number from bytCon bytes starting from pos position in buffer ; if cyclic is true, number is treated as it were signed number with bytCon bytes
|
int readNormalNr (int pos, int bytCon=4, bool cyclic = false); //read number from bytCon bytes starting from pos position in buffer ; if cyclic is true, number is treated as it were signed number with bytCon bytes
|
||||||
void teceDef (); // create files with info about defs
|
|
||||||
void deh3m(); // decode file, results are stored in map
|
void deh3m(); // decode file, results are stored in map
|
||||||
void processMap(std::vector<std::string> & defsToUnpack); //choose castles, creatures, resources, artifacts...
|
|
||||||
////
|
|
||||||
std::vector<std::string> resDefNames;
|
|
||||||
////
|
|
||||||
void loadDefs();
|
|
||||||
EDefType getDefType(CGDefInfo * a); //returns type of object in def
|
EDefType getDefType(CGDefInfo * a); //returns type of object in def
|
||||||
CCreatureSet readCreatureSet(int pos, int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7)
|
CCreatureSet readCreatureSet(int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7)
|
||||||
};
|
};
|
||||||
#endif //CAMBARCENDAMO_H
|
#endif //CAMBARCENDAMO_H
|
@ -31,8 +31,6 @@ public:
|
|||||||
bool unusualBuildins; //if true, intrepret bytes below
|
bool unusualBuildins; //if true, intrepret bytes below
|
||||||
unsigned char buildingSettings[12]; //raw format for two vectors above (greatly depends on town type)
|
unsigned char buildingSettings[12]; //raw format for two vectors above (greatly depends on town type)
|
||||||
bool hasFort; //used only if unusualBuildings is false
|
bool hasFort; //used only if unusualBuildings is false
|
||||||
CHero * visitingHero;
|
|
||||||
CHero * garnisonHero;
|
|
||||||
|
|
||||||
unsigned char bytes[4]; //identifying bytes
|
unsigned char bytes[4]; //identifying bytes
|
||||||
unsigned char player; //255 - nobody, players 0 - 7
|
unsigned char player; //255 - nobody, players 0 - 7
|
||||||
|
@ -611,421 +611,3 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int
|
|||||||
}
|
}
|
||||||
i+=2;
|
i+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCreatureHandler::loadUnitAnimations()
|
|
||||||
{
|
|
||||||
//std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
|
|
||||||
//inp.seekg(0,std::ios::end); // na koniec
|
|
||||||
//int andame = inp.tellg(); // read length
|
|
||||||
//inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
|
||||||
//char * bufor = new char[andame]; // allocate memory
|
|
||||||
//inp.read((char*)bufor, andame); // read map file to buffer
|
|
||||||
//inp.close();
|
|
||||||
//std::string buf = std::string(bufor);
|
|
||||||
//delete [andame] bufor;
|
|
||||||
|
|
||||||
//int i = 0; //buf iterator
|
|
||||||
//int hmcr = 0;
|
|
||||||
//for(i; i<andame; ++i) //omitting rubbish
|
|
||||||
//{
|
|
||||||
// if(buf[i]=='\r')
|
|
||||||
// break;
|
|
||||||
//}
|
|
||||||
//i+=2;
|
|
||||||
//for(int s=0; s<creatures.size(); ++s)
|
|
||||||
//{
|
|
||||||
// int befi=i;
|
|
||||||
// std::string rub;
|
|
||||||
// for(i; i<andame; ++i)
|
|
||||||
// {
|
|
||||||
// if(buf[i]==' ')
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// rub = buf.substr(befi, i-befi);
|
|
||||||
// ++i;
|
|
||||||
|
|
||||||
// befi=i;
|
|
||||||
// for(i; i<andame; ++i)
|
|
||||||
// {
|
|
||||||
// if(buf[i]=='\r')
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// std::string defName = buf.substr(befi, i-befi);
|
|
||||||
// if(defName != std::string("x"))
|
|
||||||
// creatures[s].battleAnimation = CGameInfo::mainObj->spriteh->giveDef(defName);
|
|
||||||
// else
|
|
||||||
// creatures[s].battleAnimation = NULL;
|
|
||||||
// i+=2;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
int CCreatureAnimation::getType() const
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCreatureAnimation::setType(int type)
|
|
||||||
{
|
|
||||||
this->type = type;
|
|
||||||
curFrame = 0;
|
|
||||||
if(type!=-1)
|
|
||||||
{
|
|
||||||
if(SEntries[curFrame].group!=type) //rewind
|
|
||||||
{
|
|
||||||
int j=-1; //first frame in displayed group
|
|
||||||
for(int g=0; g<SEntries.size(); ++g)
|
|
||||||
{
|
|
||||||
if(SEntries[g].group==type && j==-1)
|
|
||||||
{
|
|
||||||
j = g;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(curFrame!=-1)
|
|
||||||
curFrame = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(curFrame>=frames)
|
|
||||||
curFrame = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL)
|
|
||||||
{
|
|
||||||
//load main file
|
|
||||||
std::string data2 = CGI->spriteh->getTextFile(name);
|
|
||||||
if(data2.size()==0)
|
|
||||||
throw new std::string("no such def!");
|
|
||||||
FDef = new unsigned char[data2.size()];
|
|
||||||
for(int g=0; g<data2.size(); ++g)
|
|
||||||
{
|
|
||||||
FDef[g] = data2[g];
|
|
||||||
}
|
|
||||||
|
|
||||||
//init anim data
|
|
||||||
int i,j, totalInBlock;
|
|
||||||
char Buffer[13];
|
|
||||||
defName=name;
|
|
||||||
int andame = data2.size();
|
|
||||||
i = 0;
|
|
||||||
DEFType = readNormalNr(i,4); i+=4;
|
|
||||||
fullWidth = readNormalNr(i,4); i+=4;
|
|
||||||
fullHeight = readNormalNr(i,4); i+=4;
|
|
||||||
i=0xc;
|
|
||||||
totalBlocks = readNormalNr(i,4); i+=4;
|
|
||||||
|
|
||||||
i=0x10;
|
|
||||||
for (int it=0;it<256;it++)
|
|
||||||
{
|
|
||||||
palette[it].R = FDef[i++];
|
|
||||||
palette[it].G = FDef[i++];
|
|
||||||
palette[it].B = FDef[i++];
|
|
||||||
palette[it].F = 0;
|
|
||||||
}
|
|
||||||
i=0x310;
|
|
||||||
totalEntries=0;
|
|
||||||
for (int z=0; z<totalBlocks; z++)
|
|
||||||
{
|
|
||||||
int unknown1 = readNormalNr(i,4); i+=4;
|
|
||||||
totalInBlock = readNormalNr(i,4); i+=4;
|
|
||||||
for (j=SEntries.size(); j<totalEntries+totalInBlock; j++)
|
|
||||||
SEntries.push_back(SEntry());
|
|
||||||
int unknown2 = readNormalNr(i,4); i+=4;
|
|
||||||
int unknown3 = readNormalNr(i,4); i+=4;
|
|
||||||
for (j=0; j<totalInBlock; j++)
|
|
||||||
{
|
|
||||||
for (int k=0;k<13;k++) Buffer[k]=FDef[i+k];
|
|
||||||
i+=13;
|
|
||||||
SEntries[totalEntries+j].name=Buffer;
|
|
||||||
}
|
|
||||||
for (j=0; j<totalInBlock; j++)
|
|
||||||
{
|
|
||||||
SEntries[totalEntries+j].offset = readNormalNr(i,4);
|
|
||||||
int unknown4 = readNormalNr(i,4); i+=4;
|
|
||||||
}
|
|
||||||
//totalEntries+=totalInBlock;
|
|
||||||
for(int hh=0; hh<totalInBlock; ++hh)
|
|
||||||
{
|
|
||||||
SEntries[totalEntries].group = z;
|
|
||||||
++totalEntries;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(j=0; j<SEntries.size(); ++j)
|
|
||||||
{
|
|
||||||
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
|
|
||||||
}
|
|
||||||
//pictures don't have to be readed here
|
|
||||||
//for(int i=0; i<SEntries.size(); ++i)
|
|
||||||
//{
|
|
||||||
// Cimage nimg;
|
|
||||||
// nimg.bitmap = getSprite(i);
|
|
||||||
// nimg.imName = SEntries[i].name;
|
|
||||||
// nimg.groupNumber = SEntries[i].group;
|
|
||||||
// ourImages.push_back(nimg);
|
|
||||||
//}
|
|
||||||
//delete FDef;
|
|
||||||
//FDef = NULL;
|
|
||||||
|
|
||||||
//init vars
|
|
||||||
curFrame = 0;
|
|
||||||
type = -1;
|
|
||||||
frames = totalEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic)
|
|
||||||
{
|
|
||||||
int ret=0;
|
|
||||||
int amp=1;
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
for (int i=0; i<bytCon; i++)
|
|
||||||
{
|
|
||||||
ret+=str[pos+i]*amp;
|
|
||||||
amp*=256;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i=0; i<bytCon; i++)
|
|
||||||
{
|
|
||||||
ret+=FDef[pos+i]*amp;
|
|
||||||
amp*=256;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cyclic && bytCon<4 && ret>=amp/2)
|
|
||||||
{
|
|
||||||
ret = ret-amp;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect)
|
|
||||||
{
|
|
||||||
return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder,destRect);
|
|
||||||
}
|
|
||||||
int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect)
|
|
||||||
{
|
|
||||||
if(dest->format->BytesPerPixel<3)
|
|
||||||
return -1; //not enough depth
|
|
||||||
|
|
||||||
//increasing frame numer
|
|
||||||
int SIndex = -1;
|
|
||||||
if(incrementFrame)
|
|
||||||
{
|
|
||||||
SIndex = curFrame++;
|
|
||||||
if(type!=-1)
|
|
||||||
{
|
|
||||||
if(SEntries[curFrame].group!=type) //rewind
|
|
||||||
{
|
|
||||||
int j=-1; //first frame in displayed group
|
|
||||||
for(int g=0; g<SEntries.size(); ++g)
|
|
||||||
{
|
|
||||||
if(SEntries[g].group==type && j==-1)
|
|
||||||
{
|
|
||||||
j = g;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(curFrame!=-1)
|
|
||||||
curFrame = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(curFrame>=frames)
|
|
||||||
curFrame = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SIndex = curFrame;
|
|
||||||
}
|
|
||||||
//frame number increased
|
|
||||||
|
|
||||||
long BaseOffset,
|
|
||||||
SpriteWidth, SpriteHeight, //sprite format
|
|
||||||
LeftMargin, RightMargin, TopMargin,BottomMargin,
|
|
||||||
i, add, FullHeight,FullWidth,
|
|
||||||
TotalRowLength, // length of read segment
|
|
||||||
RowAdd;
|
|
||||||
unsigned char SegmentType, SegmentLength;
|
|
||||||
|
|
||||||
i=BaseOffset=SEntries[SIndex].offset;
|
|
||||||
int prSize=readNormalNr(i,4,FDef);i+=4;
|
|
||||||
int defType2 = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
FullWidth = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
FullHeight = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
SpriteWidth = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
SpriteHeight = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
LeftMargin = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
TopMargin = readNormalNr(i,4,FDef);i+=4;
|
|
||||||
RightMargin = FullWidth - SpriteWidth - LeftMargin;
|
|
||||||
BottomMargin = FullHeight - SpriteHeight - TopMargin;
|
|
||||||
|
|
||||||
add = 4 - FullWidth%4;
|
|
||||||
|
|
||||||
int BaseOffsetor = BaseOffset = i;
|
|
||||||
|
|
||||||
int ftcp = 0;
|
|
||||||
|
|
||||||
if (defType2==1) //as it should be allways in creature animations
|
|
||||||
{
|
|
||||||
if (TopMargin>0)
|
|
||||||
{
|
|
||||||
for (int i=0;i<TopMargin;i++)
|
|
||||||
{
|
|
||||||
ftcp+=FullWidth+add;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RLEntries = new int[SpriteHeight];
|
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
|
||||||
{
|
|
||||||
RLEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4;
|
|
||||||
}
|
|
||||||
for (int i=0;i<SpriteHeight;i++)
|
|
||||||
{
|
|
||||||
BaseOffset=BaseOffsetor+RLEntries[i];
|
|
||||||
if (LeftMargin>0)
|
|
||||||
{
|
|
||||||
ftcp+=LeftMargin;
|
|
||||||
}
|
|
||||||
TotalRowLength=0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
SegmentType=FDef[BaseOffset++];
|
|
||||||
SegmentLength=FDef[BaseOffset++];
|
|
||||||
if (SegmentType==0xFF)
|
|
||||||
{
|
|
||||||
for (int k=0;k<=SegmentLength;k++)
|
|
||||||
{
|
|
||||||
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
|
|
||||||
int yB = ftcp/(FullWidth+add) + y;
|
|
||||||
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
|
||||||
{
|
|
||||||
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
|
||||||
putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder);
|
|
||||||
}
|
|
||||||
ftcp++; //increment pos
|
|
||||||
if ((TotalRowLength+k+1)>=SpriteWidth)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
BaseOffset+=SegmentLength+1;////
|
|
||||||
TotalRowLength+=SegmentLength+1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int k=0;k<SegmentLength+1;k++)
|
|
||||||
{
|
|
||||||
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
|
|
||||||
int yB = ftcp/(FullWidth+add) + y;
|
|
||||||
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
|
|
||||||
{
|
|
||||||
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
|
|
||||||
putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder);
|
|
||||||
}
|
|
||||||
ftcp++; //increment pos
|
|
||||||
}
|
|
||||||
TotalRowLength+=SegmentLength+1;
|
|
||||||
}
|
|
||||||
}while(TotalRowLength<SpriteWidth);
|
|
||||||
RowAdd=SpriteWidth-TotalRowLength;
|
|
||||||
if (RightMargin>0)
|
|
||||||
{
|
|
||||||
ftcp+=RightMargin;
|
|
||||||
}
|
|
||||||
if (add>0)
|
|
||||||
{
|
|
||||||
ftcp+=add+RowAdd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete [] RLEntries;
|
|
||||||
RLEntries = NULL;
|
|
||||||
if (BottomMargin>0)
|
|
||||||
{
|
|
||||||
ftcp += BottomMargin * (FullWidth+add);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CCreatureAnimation::framesInGroup(int group) const
|
|
||||||
{
|
|
||||||
int ret = 0; //number of frames in given group
|
|
||||||
for(int g=0; g<SEntries.size(); ++g)
|
|
||||||
{
|
|
||||||
if(SEntries[g].group == group)
|
|
||||||
++ret;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCreatureAnimation::~CCreatureAnimation()
|
|
||||||
{
|
|
||||||
delete [] FDef;
|
|
||||||
if (RWEntries)
|
|
||||||
delete [] RWEntries;
|
|
||||||
if (RLEntries)
|
|
||||||
delete [] RLEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const
|
|
||||||
{
|
|
||||||
if(palc!=0)
|
|
||||||
{
|
|
||||||
Uint8 * p = (Uint8*)dest->pixels + ftcp*3;
|
|
||||||
if(palc > 7) //normal color
|
|
||||||
{
|
|
||||||
p[0] = color.B;
|
|
||||||
p[1] = color.G;
|
|
||||||
p[2] = color.R;
|
|
||||||
}
|
|
||||||
else if(yellowBorder && (palc == 6 || palc == 7)) //dark yellow border
|
|
||||||
{
|
|
||||||
p[0] = 0;
|
|
||||||
p[1] = 0xff;
|
|
||||||
p[2] = 0xff;
|
|
||||||
}
|
|
||||||
else if(yellowBorder && (palc == 5)) //yellow border
|
|
||||||
{
|
|
||||||
p[0] = color.B;
|
|
||||||
p[1] = color.G;
|
|
||||||
p[2] = color.R;
|
|
||||||
}
|
|
||||||
else if(palc < 5) //shadow
|
|
||||||
{
|
|
||||||
Uint16 alpha;
|
|
||||||
switch(color.G)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
alpha = 128;
|
|
||||||
break;
|
|
||||||
case 50:
|
|
||||||
alpha = 50+32;
|
|
||||||
break;
|
|
||||||
case 100:
|
|
||||||
alpha = 100+64;
|
|
||||||
break;
|
|
||||||
case 125:
|
|
||||||
alpha = 125+64;
|
|
||||||
break;
|
|
||||||
case 128:
|
|
||||||
alpha = 128+64;
|
|
||||||
break;
|
|
||||||
case 150:
|
|
||||||
alpha = 150+64;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
alpha = 255;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//alpha counted
|
|
||||||
p[0] = (p[0] * alpha)>>8;
|
|
||||||
p[1] = (p[1] * alpha)>>8;
|
|
||||||
p[2] = (p[2] * alpha)>>8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#ifndef CCREATUREHANDLER_H
|
#ifndef CCREATUREHANDLER_H
|
||||||
#define CCREATUREHANDLER_H
|
#define CCREATUREHANDLER_H
|
||||||
|
|
||||||
#include "../CPlayerInterface.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "CDefHandler.h"
|
#include <set>
|
||||||
|
|
||||||
class CDefHandler;
|
class CDefHandler;
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
@ -51,8 +50,6 @@ class CCreatureSet //seven combined creatures
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::map<int,std::pair<CCreature*,int> > slots;
|
std::map<int,std::pair<CCreature*,int> > slots;
|
||||||
//CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot
|
|
||||||
//unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots
|
|
||||||
bool formation; //false - wide, true - tight
|
bool formation; //false - wide, true - tight
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,48 +65,5 @@ public:
|
|||||||
void loadCreatures();
|
void loadCreatures();
|
||||||
void loadAnimationInfo();
|
void loadAnimationInfo();
|
||||||
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
||||||
void loadUnitAnimations();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CCreatureAnimation : public CIntObject
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
int totalEntries, DEFType, totalBlocks;
|
|
||||||
bool allowRepaint;
|
|
||||||
int length;
|
|
||||||
BMPPalette palette[256];
|
|
||||||
unsigned int * RWEntries;
|
|
||||||
int * RLEntries;
|
|
||||||
struct SEntry
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
int offset;
|
|
||||||
int group;
|
|
||||||
} ;
|
|
||||||
std::vector<SEntry> SEntries ;
|
|
||||||
char id[2];
|
|
||||||
std::string defName, curDir;
|
|
||||||
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
|
||||||
void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
|
|
||||||
|
|
||||||
////////////
|
|
||||||
|
|
||||||
unsigned char * FDef; //animation raw data
|
|
||||||
unsigned int curFrame; //number of currently displayed frame
|
|
||||||
unsigned int frames; //number of frames
|
|
||||||
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
|
|
||||||
public:
|
|
||||||
int fullWidth, fullHeight; //read-only, please!
|
|
||||||
CCreatureAnimation(std::string name); //c-tor
|
|
||||||
~CCreatureAnimation(); //d-tor
|
|
||||||
|
|
||||||
void setType(int type); //sets type of animation and cleares framecount
|
|
||||||
int getType() const; //returns type of animation
|
|
||||||
|
|
||||||
int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
|
|
||||||
int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
|
|
||||||
|
|
||||||
int framesInGroup(int group) const; //retirns number of fromes in given group
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //CCREATUREHANDLER_H
|
#endif //CCREATUREHANDLER_H
|
Binary file not shown.
@ -18,6 +18,7 @@ class CTown;
|
|||||||
class CHero;
|
class CHero;
|
||||||
class CBuilding;
|
class CBuilding;
|
||||||
class CSpell;
|
class CSpell;
|
||||||
|
class CGTownInstance;
|
||||||
class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
|
class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
#include "../stdafx.h"
|
|
||||||
#include "CSemiDefHandler.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include "SDL_image.h"
|
|
||||||
extern SDL_Surface * screen;
|
|
||||||
std::string CSemiDefHandler::nameFromType (EterrainType typ)
|
|
||||||
{
|
|
||||||
switch(typ)
|
|
||||||
{
|
|
||||||
case dirt:
|
|
||||||
{
|
|
||||||
return std::string("DIRTTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case sand:
|
|
||||||
{
|
|
||||||
return std::string("SANDTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case grass:
|
|
||||||
{
|
|
||||||
return std::string("GRASTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case snow:
|
|
||||||
{
|
|
||||||
return std::string("SNOWTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case swamp:
|
|
||||||
{
|
|
||||||
return std::string("SWMPTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case rough:
|
|
||||||
{
|
|
||||||
return std::string("ROUGTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case subterranean:
|
|
||||||
{
|
|
||||||
return std::string("SUBBTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case lava:
|
|
||||||
{
|
|
||||||
return std::string("LAVATL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case water:
|
|
||||||
{
|
|
||||||
return std::string("WATRTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case rock:
|
|
||||||
{
|
|
||||||
return std::string("ROCKTL.DEF");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
void CSemiDefHandler::openDef(std::string name, std::string lodName, int dist)
|
|
||||||
{
|
|
||||||
std::ifstream * is = new std::ifstream();
|
|
||||||
is -> open((lodName+"\\"+name).c_str(),std::ios::binary);
|
|
||||||
is->seekg(0,std::ios::end); // na koniec
|
|
||||||
int andame = is->tellg(); // read length
|
|
||||||
is->seekg(0,std::ios::beg); // wracamy na poczatek
|
|
||||||
buforD = new unsigned char[andame]; // allocate memory
|
|
||||||
is->read((char*)buforD, andame); // read map file to buffer
|
|
||||||
defName = name;
|
|
||||||
int gdzie = defName.find_last_of("\\");
|
|
||||||
defName = defName.substr(gdzie+1, gdzie-defName.length());
|
|
||||||
delete is;
|
|
||||||
|
|
||||||
readFileList(dist);
|
|
||||||
loadImages(lodName);
|
|
||||||
|
|
||||||
}
|
|
||||||
CSemiDefHandler::~CSemiDefHandler()
|
|
||||||
{
|
|
||||||
for (int i=0;i<ourImages.size();i++)
|
|
||||||
SDL_FreeSurface(ourImages[i].bitmap);
|
|
||||||
}
|
|
||||||
void CSemiDefHandler::readFileList(int dist)
|
|
||||||
{
|
|
||||||
howManyImgs = buforD[788];
|
|
||||||
int i = 800;
|
|
||||||
for (int pom=0;pom<howManyImgs;pom++)
|
|
||||||
{
|
|
||||||
std::string temp;
|
|
||||||
while (buforD[i]!=0)
|
|
||||||
{
|
|
||||||
temp+=buforD[i++];
|
|
||||||
}
|
|
||||||
i+=dist; //by�o zwi�kszenie tylko o jedno
|
|
||||||
if (temp!="")
|
|
||||||
{
|
|
||||||
temp = temp.substr(0,temp.length()-4) + ".BMP";
|
|
||||||
namesOfImgs.push_back(temp);
|
|
||||||
}
|
|
||||||
else pom--;
|
|
||||||
}
|
|
||||||
delete buforD;
|
|
||||||
}
|
|
||||||
void CSemiDefHandler::loadImages(std::string path)
|
|
||||||
{
|
|
||||||
for (int i=0; i<namesOfImgs.size(); i++)
|
|
||||||
{
|
|
||||||
openImg((path+"\\_"+defName+"\\"+namesOfImgs[i]).c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SDL_DisplayBitmap(const char *file, SDL_Surface *ekran, int x, int y)
|
|
||||||
{
|
|
||||||
SDL_Surface *image;
|
|
||||||
SDL_Rect dest;
|
|
||||||
image = SDL_LoadBMP(file);
|
|
||||||
if ( image == NULL )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Nie mo�na wczyta� %s: %s\n", file, SDL_GetError());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dest.x = x;
|
|
||||||
dest.y = y;
|
|
||||||
dest.w = image->w;
|
|
||||||
dest.h = image->h;
|
|
||||||
SDL_BlitSurface(image, NULL, ekran, &dest);
|
|
||||||
SDL_UpdateRects(ekran, 1, &dest);
|
|
||||||
SDL_FreeSurface(image);
|
|
||||||
}
|
|
||||||
void CSemiDefHandler::openImg(const char *name)
|
|
||||||
{
|
|
||||||
SDL_Surface *image;
|
|
||||||
image=IMG_Load(name);
|
|
||||||
//SDL_DisplayBitmap(name,image, 0,0);
|
|
||||||
if(!image)
|
|
||||||
{
|
|
||||||
printf("IMG_Load: %s\n", IMG_GetError());
|
|
||||||
return;
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
Cimage vinya;
|
|
||||||
vinya.bitmap = image;
|
|
||||||
SDL_SetColorKey(vinya.bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(vinya.bitmap->format,0,255,255));
|
|
||||||
vinya.imName = name;
|
|
||||||
ourImages.push_back(vinya);
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef SEMIDEF_H
|
|
||||||
#define SEMIDEF_H
|
|
||||||
#include "../global.h"
|
|
||||||
#include <string>
|
|
||||||
#include "SDL.h"
|
|
||||||
//#include "SDL_image.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
struct Cimage
|
|
||||||
{
|
|
||||||
int groupNumber;
|
|
||||||
std::string imName; //name without extension
|
|
||||||
SDL_Surface * bitmap;
|
|
||||||
};
|
|
||||||
class CSemiDefHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int howManyImgs;
|
|
||||||
std::string defName;
|
|
||||||
std::vector<Cimage> ourImages;
|
|
||||||
std::vector<std::string> namesOfImgs;
|
|
||||||
unsigned char * buforD;
|
|
||||||
|
|
||||||
static std::string nameFromType(EterrainType typ);
|
|
||||||
void openImg(const char *name);
|
|
||||||
void openDef(std::string name, std::string lodName, int dist=1);
|
|
||||||
void readFileList(int dist = 1);
|
|
||||||
void loadImages(std::string path);
|
|
||||||
~CSemiDefHandler();
|
|
||||||
};
|
|
||||||
#endif // SEMIDEF_H
|
|
@ -1,12 +0,0 @@
|
|||||||
#include "../stdafx.h"
|
|
||||||
#include "CSemiLodHandler.h"
|
|
||||||
void CSemiLodHandler::openLod(std::string path)
|
|
||||||
{
|
|
||||||
ourName = path;
|
|
||||||
};
|
|
||||||
CSemiDefHandler * CSemiLodHandler::giveDef(std::string name, int dist)
|
|
||||||
{
|
|
||||||
CSemiDefHandler * ret = new CSemiDefHandler();
|
|
||||||
ret->openDef(name, ourName, dist);
|
|
||||||
return ret;
|
|
||||||
};
|
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef CSEMILODHANDLER_H
|
|
||||||
#define CSEMILODHANDLER_H
|
|
||||||
|
|
||||||
#include "CSemiDefHandler.h"
|
|
||||||
class CSemiLodHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string ourName; // name of our lod
|
|
||||||
void openLod(std::string path);
|
|
||||||
CSemiDefHandler * giveDef(std::string name, int dist=1); //loads def from our lod
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //CSEMILODHANDLER_H
|
|
9
map.cpp
9
map.cpp
@ -12,15 +12,6 @@ int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool DefInfo::isVisitable()
|
|
||||||
{
|
|
||||||
for (int i=6; i<12; i++)
|
|
||||||
{
|
|
||||||
if (bytes[i])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
CMapHeader::CMapHeader(unsigned char *map)
|
CMapHeader::CMapHeader(unsigned char *map)
|
||||||
{
|
{
|
||||||
this->version = (Eformat)map[0]; //wersja mapy
|
this->version = (Eformat)map[0]; //wersja mapy
|
||||||
|
31
map.h
31
map.h
@ -3,9 +3,8 @@
|
|||||||
#pragma warning (disable : 4482)
|
#pragma warning (disable : 4482)
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "hch\CDefHandler.h"
|
|
||||||
class CGDefInfo;
|
class CGDefInfo;
|
||||||
class CHeroObjInfo;
|
class CHeroObjInfo;
|
||||||
enum ESortBy{name,playerAm,size,format, viccon,loscon};
|
enum ESortBy{name,playerAm,size,format, viccon,loscon};
|
||||||
@ -25,24 +24,6 @@ struct TimeEvent
|
|||||||
bool areCompsAffected;
|
bool areCompsAffected;
|
||||||
int firstAfterNDays; //how many days after appears this event
|
int firstAfterNDays; //how many days after appears this event
|
||||||
int nextAfterNDays; //how many days after the epperance before appaers this event
|
int nextAfterNDays; //how many days after the epperance before appaers this event
|
||||||
//bajty wydarze� (59 + |teksty|)
|
|
||||||
//4 bajty na d�ugo�� nazwy zdarzenia
|
|
||||||
//nazwa zdarzenia (bajty dodatkowe)
|
|
||||||
//4 bajty na d�ugo�� wiadomo�ci
|
|
||||||
//wiadomo�� (bajty dodatkowe)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci drewna (zapis normalny) lub ff,ff,ff,ff - ilo�� drewna do odebrania (maksymalna ilo�� drewna, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci rt�ci (zapis normalny) lub ff,ff,ff,ff - ilo�� rt�ci do odebrania (maksymalna ilo�� rt�ci, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci rudy (zapis normalny) lub ff,ff,ff,ff - ilo�� rudy do odebrania (maksymalna ilo�� rudy, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci siarki (zapis normalny) lub ff,ff,ff,ff - ilo�� siarki do odebrania (maksymalna ilo�� siarki, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci kryszta�u (zapis normalny) lub ff,ff,ff,ff - ilo�� kryszta�u do odebrania (maksymalna ilo�� kryszta�u, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci klejnot�w (zapis normalny) lub ff,ff,ff,ff - ilo�� klejnot�w do odebrania (maksymalna ilo�� klejnot�w, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//4 bajty na zwi�kszenie si� ilosci z�ota (zapis normalny) lub ff,ff,ff,ff - ilo�� z�ota do odebrania (maksymalna ilo�� z�ota, kt�r� mo�na da�/odebra� to 32767)
|
|
||||||
//1 bajt - kt�rych graczy dotyczy zdarzenie (pole bitowe, +1 - pierwszy, +2 - drugi, +4 - trzeci, +8 - czwarty, +16 - pi�ty, +32 - sz�sty, +64 - si�dmy, +128 - �smy)
|
|
||||||
//1 bajt - czy zdarzenie odnosi si� do graczy - ludzi (00 - nie, 01 - tak)
|
|
||||||
//1 bajt - czy zdarzenie odnosi si� do graczy komputerowych (00 - nie, 01 - tak)
|
|
||||||
//2 bajty - op��nienie pierwszego wyst�pienia (w dniach, zapis normalny, maks 671)
|
|
||||||
//1 bajt - co ile dni wyst�puje zdarzenie (maks 28, 00 oznacza zdarzenie jednorazowe)
|
|
||||||
//17 bajt�w zerowych
|
|
||||||
};
|
};
|
||||||
struct TerrainTile
|
struct TerrainTile
|
||||||
{
|
{
|
||||||
@ -54,16 +35,6 @@ struct TerrainTile
|
|||||||
unsigned char roadDir; // direction of Eroad
|
unsigned char roadDir; // direction of Eroad
|
||||||
unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
|
unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
|
||||||
};
|
};
|
||||||
struct DefInfo //information from def declaration
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
int bytes [42];
|
|
||||||
//CSemiDefHandler * handler;
|
|
||||||
CDefHandler * handler;
|
|
||||||
int printPriority;
|
|
||||||
bool isOnDefList;
|
|
||||||
bool isVisitable();
|
|
||||||
};
|
|
||||||
struct SheroName //name of starting hero
|
struct SheroName //name of starting hero
|
||||||
{
|
{
|
||||||
int heroID;
|
int heroID;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "SDL_rotozoom.h"
|
#include "SDL_rotozoom.h"
|
||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
@ -16,7 +15,63 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
extern SDL_Surface * screen;
|
extern SDL_Surface * screen;
|
||||||
|
std::string nameFromType (EterrainType typ)
|
||||||
|
{
|
||||||
|
switch(typ)
|
||||||
|
{
|
||||||
|
case dirt:
|
||||||
|
{
|
||||||
|
return std::string("DIRTTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case sand:
|
||||||
|
{
|
||||||
|
return std::string("SANDTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case grass:
|
||||||
|
{
|
||||||
|
return std::string("GRASTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case snow:
|
||||||
|
{
|
||||||
|
return std::string("SNOWTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case swamp:
|
||||||
|
{
|
||||||
|
return std::string("SWMPTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case rough:
|
||||||
|
{
|
||||||
|
return std::string("ROUGTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case subterranean:
|
||||||
|
{
|
||||||
|
return std::string("SUBBTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case lava:
|
||||||
|
{
|
||||||
|
return std::string("LAVATL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case water:
|
||||||
|
{
|
||||||
|
return std::string("WATRTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case rock:
|
||||||
|
{
|
||||||
|
return std::string("ROCKTL.DEF");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
class OCM_HLP
|
class OCM_HLP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -616,14 +671,14 @@ void CMapHandler::borderAndTerrainBitmapInit()
|
|||||||
//TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
|
//TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
|
||||||
std::string name;
|
std::string name;
|
||||||
if (k>0)
|
if (k>0)
|
||||||
name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype);
|
name = nameFromType(reader->map.undergroungTerrain[i][j].tertype);
|
||||||
else
|
else
|
||||||
name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
|
name = nameFromType(reader->map.terrain[i][j].tertype);
|
||||||
for (unsigned int m=0; m<reader->defs.size(); m++)
|
for (unsigned int m=0; m<defs.size(); m++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (reader->defs[m]->defName != name)
|
if (defs[m]->defName != name)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -632,7 +687,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
|
|||||||
ktora = reader->map.terrain[i][j].terview;
|
ktora = reader->map.terrain[i][j].terview;
|
||||||
else
|
else
|
||||||
ktora = reader->map.undergroungTerrain[i][j].terview;
|
ktora = reader->map.undergroungTerrain[i][j].terview;
|
||||||
ttiles[i][j][k].terbitmap.push_back(reader->defs[m]->ourImages[ktora].bitmap);
|
ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap);
|
||||||
int zz;
|
int zz;
|
||||||
if (k==0)
|
if (k==0)
|
||||||
zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4;
|
zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4;
|
||||||
@ -1732,3 +1787,27 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
|
|||||||
}
|
}
|
||||||
return -2; //shouldn't happen
|
return -2; //shouldn't happen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CMapHandler::loadDefs()
|
||||||
|
{
|
||||||
|
std::set<int> loadedTypes;
|
||||||
|
for (int i=0; i<reader->map.width; i++)
|
||||||
|
{
|
||||||
|
for (int j=0; j<reader->map.width; j++)
|
||||||
|
{
|
||||||
|
if (loadedTypes.find(reader->map.terrain[i][j].tertype)==loadedTypes.end())
|
||||||
|
{
|
||||||
|
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.terrain[i][j].tertype).c_str());
|
||||||
|
loadedTypes.insert(reader->map.terrain[i][j].tertype);
|
||||||
|
defs.push_back(sdh);
|
||||||
|
}
|
||||||
|
if (reader->map.twoLevel && loadedTypes.find(reader->map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
|
||||||
|
{
|
||||||
|
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.undergroungTerrain[i][j].tertype).c_str());
|
||||||
|
loadedTypes.insert(reader->map.undergroungTerrain[i][j].tertype);
|
||||||
|
defs.push_back(sdh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
#define MAPHANDLER_H
|
#define MAPHANDLER_H
|
||||||
|
|
||||||
#include "hch\CAmbarCendamo.h"
|
#include "hch\CAmbarCendamo.h"
|
||||||
#include "hch\CSemiDefHandler.h"
|
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "hch\CDefHandler.h"
|
#include "hch\CDefHandler.h"
|
||||||
#include <boost/logic/tribool.hpp>
|
#include <boost/logic/tribool.hpp>
|
||||||
@ -70,6 +69,7 @@ public:
|
|||||||
//std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
|
//std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
|
||||||
std::vector<CDefHandler *> roadDefs;
|
std::vector<CDefHandler *> roadDefs;
|
||||||
std::vector<CDefHandler *> staticRiverDefs;
|
std::vector<CDefHandler *> staticRiverDefs;
|
||||||
|
std::vector<CDefHandler*> defs;
|
||||||
|
|
||||||
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
|
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
|
||||||
std::map<int, CGDefInfo*> villages, forts, capitols;
|
std::map<int, CGDefInfo*> villages, forts, capitols;
|
||||||
@ -78,6 +78,7 @@ public:
|
|||||||
|
|
||||||
PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
|
PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
|
||||||
|
|
||||||
|
void loadDefs();
|
||||||
char & visAccess(int x, int y);
|
char & visAccess(int x, int y);
|
||||||
char & undVisAccess(int x, int y);
|
char & undVisAccess(int x, int y);
|
||||||
SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
|
SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
|
||||||
|
Reference in New Issue
Block a user