|  | @@ -518,3 +518,275 @@ void CCreatureHandler::loadUnitAnimations()
 | 
	
		
			
				|  |  |  		i+=2;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +int CCreatureAnimation::getType() const
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +	return type;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void CCreatureAnimation::setType(int type)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +	this->type = type;
 | 
	
		
			
				|  |  | +	curFrame = 0;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +CCreatureAnimation::CCreatureAnimation(std::string name)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +	//load main file
 | 
	
		
			
				|  |  | +	std::string data2 = CGI->spriteh->getTextFile(name);
 | 
	
		
			
				|  |  | +	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;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +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::nextFrame(SDL_Surface *dest, int x, int y)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +	if(dest->format->BytesPerPixel<3)
 | 
	
		
			
				|  |  | +		return -1; //not enough depth
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	int SIndex = curFrame++; //TODO: finish
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	long BaseOffset, 
 | 
	
		
			
				|  |  | +		SpriteWidth, SpriteHeight, //format sprite'a
 | 
	
		
			
				|  |  | +		LeftMargin, RightMargin, TopMargin,BottomMargin,
 | 
	
		
			
				|  |  | +		i, add, FullHeight,FullWidth,
 | 
	
		
			
				|  |  | +		TotalRowLength, // dlugosc przeczytanego segmentu
 | 
	
		
			
				|  |  | +		NextSpriteOffset, RowAdd;
 | 
	
		
			
				|  |  | +	std::ifstream Fdef;
 | 
	
		
			
				|  |  | +	unsigned char SegmentType, SegmentLength, BL, BR;
 | 
	
		
			
				|  |  | +	unsigned char * TempDef; //memory
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	std::string FTemp;
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	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;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	BMPHeader tb;
 | 
	
		
			
				|  |  | +	tb.x = FullWidth;
 | 
	
		
			
				|  |  | +	tb.y = FullHeight;
 | 
	
		
			
				|  |  | +	tb.dataSize2 = tb.dataSize1 = tb.x*tb.y;
 | 
	
		
			
				|  |  | +	tb.fullSize = tb.dataSize1+436;
 | 
	
		
			
				|  |  | +	tb._h3=tb.fullSize-36;
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	//add = (int)(4*(((float)1) - ((int)(((int)((float)FullWidth/(float)4))-((float)FullWidth/(float)4)))));
 | 
	
		
			
				|  |  | +	add = 4 - FullWidth%4;
 | 
	
		
			
				|  |  | +	/*if (add==4)
 | 
	
		
			
				|  |  | +		add=0;*/ //moved to defcompression dependent block
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
 | 
	
		
			
				|  |  | +    int rmask = 0xff000000;
 | 
	
		
			
				|  |  | +    int gmask = 0x00ff0000;
 | 
	
		
			
				|  |  | +    int bmask = 0x0000ff00;
 | 
	
		
			
				|  |  | +    int amask = 0x000000ff;
 | 
	
		
			
				|  |  | +#else
 | 
	
		
			
				|  |  | +    int rmask = 0x000000ff;
 | 
	
		
			
				|  |  | +    int gmask = 0x0000ff00;
 | 
	
		
			
				|  |  | +    int bmask = 0x00ff0000;
 | 
	
		
			
				|  |  | +    int amask = 0xff000000;
 | 
	
		
			
				|  |  | +#endif
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +	//ret = SDL_CreateRGBSurface(SDL_SWSURFACE, FullWidth, FullHeight, 8, 0, 0, 0, 0);
 | 
	
		
			
				|  |  | +	//int tempee2 = readNormalNr(0,4,((unsigned char *)tempee.c_str()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	int BaseOffsetor = BaseOffset = i;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	/*for(int i=0; i<256; ++i)
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		SDL_Color pr;
 | 
	
		
			
				|  |  | +		pr.r = palette[i].R;
 | 
	
		
			
				|  |  | +		pr.g = palette[i].G;
 | 
	
		
			
				|  |  | +		pr.b = palette[i].B;
 | 
	
		
			
				|  |  | +		pr.unused = palette[i].F;
 | 
	
		
			
				|  |  | +		(*(ret->format->palette->colors+i))=pr;
 | 
	
		
			
				|  |  | +	}*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	for (int i=0;i<800;i++)
 | 
	
		
			
				|  |  | +		fbuffer[i]=0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if (defType2==1) //as it should be allways in creature animations
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		if (add==4)
 | 
	
		
			
				|  |  | +			add=0; ////////was 3
 | 
	
		
			
				|  |  | +		if (TopMargin>0)
 | 
	
		
			
				|  |  | +		{
 | 
	
		
			
				|  |  | +			for (int i=0;i<TopMargin;i++)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				for (int j=0;j<FullWidth+add;j++)
 | 
	
		
			
				|  |  | +					FTemp+=fbuffer[j];
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		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)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				for (int j=0;j<LeftMargin;j++)
 | 
	
		
			
				|  |  | +					FTemp+=fbuffer[j];
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			TotalRowLength=0;
 | 
	
		
			
				|  |  | +			do
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				SegmentType=FDef[BaseOffset++];
 | 
	
		
			
				|  |  | +				SegmentLength=FDef[BaseOffset++];
 | 
	
		
			
				|  |  | +				if (SegmentType==0xFF)
 | 
	
		
			
				|  |  | +				{
 | 
	
		
			
				|  |  | +					for (int k=0;k<=SegmentLength;k++)
 | 
	
		
			
				|  |  | +					{
 | 
	
		
			
				|  |  | +						FTemp+=FDef[BaseOffset+k];
 | 
	
		
			
				|  |  | +						if ((TotalRowLength+k+1)>=SpriteWidth)
 | 
	
		
			
				|  |  | +							break;
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +					BaseOffset+=SegmentLength+1;////
 | 
	
		
			
				|  |  | +					TotalRowLength+=SegmentLength+1;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				else
 | 
	
		
			
				|  |  | +				{
 | 
	
		
			
				|  |  | +					for (int k=0;k<SegmentLength+1;k++)
 | 
	
		
			
				|  |  | +					{
 | 
	
		
			
				|  |  | +						FTemp+=fbuffer[k];//
 | 
	
		
			
				|  |  | +						//FTemp+='\0';
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +					TotalRowLength+=SegmentLength+1;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +			}while(TotalRowLength<SpriteWidth);
 | 
	
		
			
				|  |  | +			RowAdd=SpriteWidth-TotalRowLength;
 | 
	
		
			
				|  |  | +			if (RightMargin>0)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				for (int j=0;j<RightMargin;j++)
 | 
	
		
			
				|  |  | +					FTemp+=fbuffer[j];
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if (add>0)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				for (int j=0;j<add+RowAdd;j++)
 | 
	
		
			
				|  |  | +					FTemp+=fbuffer[j];
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		delete RLEntries;
 | 
	
		
			
				|  |  | +		RLEntries = NULL;
 | 
	
		
			
				|  |  | +		if (BottomMargin>0)
 | 
	
		
			
				|  |  | +		{
 | 
	
		
			
				|  |  | +			for (int i=0;i<BottomMargin;i++)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				for (int j=0;j<FullWidth+add;j++)
 | 
	
		
			
				|  |  | +					FTemp+=fbuffer[j];
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	for (int i=0; i<FullHeight; ++i)
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		for (int j=0;j<FullWidth+add;j++)
 | 
	
		
			
				|  |  | +		{
 | 
	
		
			
				|  |  | +			*((char*)dest->pixels + dest->format->BytesPerPixel * ((i + y)*dest->pitch + j + x)) = FTemp[i*(FullWidth+add)+j];
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	return 0;
 | 
	
		
			
				|  |  | +}
 |