From 0cc557160442fa0b8ae3201878386dcc66f03885 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Wed, 12 Nov 2008 18:59:33 +0000 Subject: [PATCH] * new spell: implosion * optimizations in def handling * small refactoring --- CBattleInterface.cpp | 7 ++++++- CPathfinder.cpp | 6 +++--- CPathfinder.h | 6 +++--- CPlayerInterface.cpp | 28 ++++++++++++++-------------- client/CCreatureAnimation.cpp | 25 +++++++------------------ client/CCreatureAnimation.h | 7 ++----- config/AC_desc.txt | 2 +- hch/CDefHandler.cpp | 16 +++++++--------- hch/CDefHandler.h | 2 +- int3.h | 12 +++++++----- server/CGameHandler.cpp | 19 ++++++++++++++++--- 11 files changed, 67 insertions(+), 63 deletions(-) diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 0ffa79c99..206d657fb 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -1117,7 +1117,7 @@ bool CBattleInterface::isTileAttackable(const int & number) const void CBattleInterface::hexLclicked(int whichOne) { - if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack + if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack { if(!myTurn) return; //we are not permit to do anything @@ -1351,6 +1351,11 @@ void CBattleInterface::spellCasted(SpellCasted * sc) displayEffect(1, sc->tile); break; } + case 18: //implosion + { + displayEffect(10, sc->tile); + break; + } case 53: //haste { displayEffect(31, sc->tile); diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 5300818fa..e4d61e36d 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -127,7 +127,7 @@ vector* CPathfinder::CalcPath() * Determines if the given node exists in the closed list, returns true if it does. This is * used to ensure you dont check the same node twice. */ -bool CPathfinder::ExistsInClosed(Coordinate node) +bool CPathfinder::ExistsInClosed(const Coordinate & node) const { for(int i = 0; i < Closed.size(); i++) { @@ -386,11 +386,11 @@ void CPathfinder::convertPath(CPath * path, unsigned int mode) //mode=0 -> from } } -int3 CPath::startPos() +int3 CPath::startPos() const { return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z); } -int3 CPath::endPos() +int3 CPath::endPos() const { return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z); } diff --git a/CPathfinder.h b/CPathfinder.h index f8ad2db34..65554c426 100644 --- a/CPathfinder.h +++ b/CPathfinder.h @@ -47,8 +47,8 @@ struct CPath { std::vector nodes; //just get node by node - int3 startPos(); // start point - int3 endPos(); //destination point + int3 startPos() const; // start point + int3 endPos() const; //destination point }; class CPathfinder @@ -65,7 +65,7 @@ private: * Determines if the given node exists in the closed list, returns true if it does. This is * used to ensure you dont check the same node twice. */ - bool ExistsInClosed(Coordinate node); + bool ExistsInClosed(const Coordinate & node) const; /* * Adds the neighbors of the current node to the open cue so they can be considered in the diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index c63b23178..c654b4fb9 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2362,17 +2362,17 @@ CHeroList::CHeroList(int Size) selection = BitmapHandler::loadBitmap("HPSYYY.bmp"); SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255)); - pos = genRect(32*SIZE+arrup->h+arrdo->h,std::max(arrup->w,arrdo->w),conf.go()->ac.hlistX,conf.go()->ac.hlistY); + pos = genRect(32*SIZE+arrup->height+arrdo->height, std::max(arrup->width,arrdo->width), conf.go()->ac.hlistX, conf.go()->ac.hlistY); - arrupp = genRect(arrup->h,arrup->w,pos.x,pos.y); - arrdop = genRect(arrdo->h,arrdo->w,pos.x,pos.y+32*SIZE+arrup->h); + arrupp = genRect(arrup->height, arrup->width, pos.x, pos.y); + arrdop = genRect(arrdo->height, arrdo->width, pos.x, pos.y+32*SIZE+arrup->height); //32px per hero posmobx = pos.x+1; - posmoby = pos.y+arrup->h+1; - posporx = pos.x+mobile->w+2; - pospory = pos.y+arrup->h; - posmanx = pos.x+1+50+mobile->w; - posmany = pos.y+arrup->h+1; + posmoby = pos.y+arrup->height+1; + posporx = pos.x+mobile->width+2; + pospory = pos.y+arrup->height; + posmanx = pos.x+1+50+mobile->width; + posmany = pos.y+arrup->height+1; from = 0; pressed = indeterminate; @@ -2633,16 +2633,16 @@ CTownList::CTownList(int Size, int x, int y, std::string arrupg, std::string arr arrdo = CDefHandler::giveDef(arrdog); pos.x = x; pos.y = y; - pos.w = std::max(arrdo->w,arrup->h); + pos.w = std::max(arrdo->width, arrup->height); arrupp.x=x; arrupp.y=y; - arrupp.w=arrup->w; - arrupp.h=arrup->h; + arrupp.w=arrup->width; + arrupp.h=arrup->height; arrdop.x=x; - arrdop.y=y+arrup->h+32*SIZE; - arrdop.w=arrdo->w; - arrdop.h=arrdo->h; + arrdop.y=y+arrup->height+32*SIZE; + arrdop.w=arrdo->width; + arrdop.h=arrdo->height; posporx = arrdop.x; pospory = arrupp.y + arrupp.h; diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index 2744b2c33..01858f428 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -33,7 +33,7 @@ void CCreatureAnimation::setType(int type) } } -CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL) +CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL) { FDef = CDefHandler::Spriteh->giveFile(name); //load main file @@ -98,7 +98,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEn RLEntries = new int[fullHeight]; } -int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic) +int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str) const { int ret=0; int amp=1; @@ -107,7 +107,7 @@ int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, for (int i=0; i=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) @@ -198,15 +194,10 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker { if (TopMargin>0) { - for (int i=0;i 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; + int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const; + void inline putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const; //////////// diff --git a/config/AC_desc.txt b/config/AC_desc.txt index be9742e21..715871856 100644 --- a/config/AC_desc.txt +++ b/config/AC_desc.txt @@ -9,7 +9,7 @@ 7 1 C04SPA0.DEF 8 1 C04SPE0.DEF 9 1 C04SPF0.DEF -10 0 +10 1 C05SPE0.DEF 11 1 C05SPF0.DEF 12 1 C06SPF0.DEF 13 1 C07SPA0.DEF diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index 535a5217f..3e4f70578 100644 --- a/hch/CDefHandler.cpp +++ b/hch/CDefHandler.cpp @@ -59,8 +59,8 @@ void CDefHandler::openDef(std::string name) delete is; i = 0; DEFType = readNormalNr(i,4,FDef); i+=4; - w = readNormalNr(i,4,FDef); i+=4; - h = readNormalNr(i,4,FDef); i+=4; + width = readNormalNr(i,4,FDef); i+=4; + height = readNormalNr(i,4,FDef); i+=4; i=0xc; totalBlocks = readNormalNr(i,4,FDef); i+=4; @@ -123,8 +123,8 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) defName=name; i = 0; DEFType = readNormalNr(i,4,table); i+=4; - w = readNormalNr(i,4,table); i+=4; - h = readNormalNr(i,4,table); i+=4; + width = readNormalNr(i,4,table); i+=4; + height = readNormalNr(i,4,table); i+=4; i=0xc; totalBlocks = readNormalNr(i,4,table); i+=4; @@ -168,7 +168,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) { SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4); } - RWEntries = new unsigned int[h]; + RWEntries = new unsigned int[height]; for(int i=0; ipixels))[ftcp++]='\0'; } } - for (int i=0;i SEntries ; public: - int w, h; //width and height + int width, height; //width and height static CLodHandler * Spriteh; std::string defName, curDir; std::vector ourImages; diff --git a/int3.h b/int3.h index 6584105fe..e423a0ea6 100644 --- a/int3.h +++ b/int3.h @@ -32,16 +32,18 @@ public: si32 x,y,z; inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor + inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor + inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator inline ~int3(){} // d-tor - does nothing - inline int3 operator+(const int3 & i) const + inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3 {return int3(x+i.x,y+i.y,z+i.z);} - inline int3 operator+(const si32 i) const //increases all components by si32 + inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer {return int3(x+i,y+i,z+i);} - inline int3 operator-(const int3 & i) const + inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3 {return int3(x-i.x,y-i.y,z-i.z);} - inline int3 operator-(const si32 i) const + inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer {return int3(x-i,y-i,z-i);} - inline int3 operator-() const //increases all components by si32 + inline int3 operator-() const //returns opposite position {return int3(-x,-y,-z);} inline double dist2d(const int3 other) const //distance (z coord is not used) {return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));} diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 69d98d0ae..2a527efa7 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1230,7 +1230,7 @@ upgend: sendAndApply(&sc); switch(ba.additionalInfo) //spell id { - case 15://magic arrow + case 15: //magic arrow { CStack * attacked = gs->curB->getStackT(ba.destinationTile); if(!attacked) break; @@ -1243,7 +1243,7 @@ upgend: sendAndApply(&bsa); break; } - case 16://ice bolt + case 16: //ice bolt { CStack * attacked = gs->curB->getStackT(ba.destinationTile); if(!attacked) break; @@ -1256,7 +1256,7 @@ upgend: sendAndApply(&bsa); break; } - case 17://lightning bolt + case 17: //lightning bolt { CStack * attacked = gs->curB->getStackT(ba.destinationTile); if(!attacked) break; @@ -1269,6 +1269,19 @@ upgend: sendAndApply(&bsa); break; } + case 18: //implosion + { + CStack * attacked = gs->curB->getStackT(ba.destinationTile); + if(!attacked) break; + BattleStackAttacked bsa; + bsa.flags |= 2; + bsa.effect = 10; + bsa.damageAmount = h->getPrimSkillLevel(2) * 75 + s->powers[getSchoolLevel(h,s)]; + bsa.stackAttacked = attacked->ID; + prepareAttacked(bsa,attacked); + sendAndApply(&bsa); + break; + } case 53: //haste { SetStackEffect sse;