#include "../stdafx.h" #include "../CGameInfo.h" #include "CDefHandler.h" #include "CCreatureHandler.h" #include "CLodHandler.h" #include #include #include #include #include #include "../SDL_Extensions.h" int CCreature::getQuantityID(int quantity) { if (quantity<5) return 0; if (quantity<10) return 1; if (quantity<20) return 2; if (quantity<50) return 3; if (quantity<100) return 4; if (quantity<250) return 5; if (quantity<500) return 5; if (quantity<1000) return 6; if (quantity<4000) return 7; return 8; } bool CCreature::isDoubleWide() { return boost::algorithm::find_first(abilityRefs, "DOUBLE_WIDE"); } bool CCreature::isFlying() { return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY"); } int CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought { int ret = 2147483645; int resAmnt = std::min(res.size(),cost.size()); for(int i=0;ibitmaph->getTextFile("ZCRTRAIT.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; for(i; i> tempi >> temps; if (tempi>=creatures.size()) break; boost::assign::insert(nameToID)(temps,tempi); creatures[tempi].nameRef=temps; } ifs.close(); ifs.clear(); for(int i=1;i<=10;i++) levelCreatures.insert(std::pair >(i,std::vector())); ifs.open("config/monsters.txt"); { while(!ifs.eof()) { int id, lvl; ifs >> id >> lvl; if(lvl>0) { creatures[id].level = lvl; levelCreatures[lvl].push_back(&(creatures[id])); } } } ifs.close(); ifs.clear(); ifs.open("config/cr_bgs.txt"); while(!ifs.eof()) { int id; std::string name; ifs >> id >> name; backgrounds[id]=CGI->bitmaph->loadBitmap(name); } ifs.close(); ifs.clear(); ifs.open("config/cr_factions.txt"); while(!ifs.eof()) { int id, fact; ifs >> id >> fact; creatures[id].faction = fact; } ifs.close(); ifs.clear(); //loading 32x32px imgs CDefHandler *smi = CGI->spriteh->giveDef("CPRSMALL.DEF"); smi->notFreeImgs = true; for (int i=0; iourImages.size(); i++) { boost::assign::insert(smallImgs)(i-2,smi->ourImages[i].bitmap); } delete smi; smi = CGI->spriteh->giveDef("TWCRPORT.DEF"); smi->notFreeImgs = true; for (int i=0; iourImages.size(); i++) { boost::assign::insert(bigImgs)(i-2,smi->ourImages[i].bitmap); } delete smi; // //loading unit animation def names 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 andame2 = inp.tellg(); // read length inp.seekg(0,std::ios::beg); // wracamy na poczatek char * bufor = new char[andame2]; // allocate memory inp.read((char*)bufor, andame2); // read map file to buffer inp.close(); buf = std::string(bufor); delete [andame2] bufor; i = 0; //buf iterator hmcr = 0; for(i; ibitmaph->getTextFile("CRANIM.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; for(i; ispriteh->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=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=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=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;i0) { 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 && xBw && yBh) { 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=0 && yB>=0 && xBw && yBh) { 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(TotalRowLength0) { 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; gpixels + 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; } } }