diff --git a/AI_Base.h b/AI_Base.h index cf1ecd3d0..b57070e2f 100644 --- a/AI_Base.h +++ b/AI_Base.h @@ -1,15 +1,14 @@ +#ifndef AIBASE_H +#define AIBASE_H + +#ifdef _MSC_VER #pragma once +#endif + #include #include #include "CGameInterface.h" #define AI_INTERFACE_VER 1 - - - - - - - - +#endif //AIBASE_H diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index 1c9fdd92e..8b32a6335 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -118,29 +118,31 @@ void AdventureMapButton::init(const CFunctionList &Callback, const std:: state=0; hoverTexts = Name; helpBox=HelpBox; - int est = LOCPLINT->playerID; + //int est = LOCPLINT->playerID; //TODO use me CDefHandler * temp = CDefHandler::giveDef(defName); temp->notFreeImgs = true; - for (int i=0;iourImages.size();i++) + for (size_t i=0;iourImages.size();i++) { imgs.resize(1); imgs[0].push_back(temp->ourImages[i].bitmap); - if(playerColoredButton) + if(playerColoredButton) { graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); + } } delete temp; if (add && add->size()) { imgs.resize(imgs.size()+add->size()); - for (int i=0; isize();i++) + for (size_t i=0; isize();i++) { temp = CDefHandler::giveDef((*add)[i]); temp->notFreeImgs = true; - for (int j=0;jourImages.size();j++) + for (size_t j=0;jourImages.size();j++) { imgs[i+1].push_back(temp->ourImages[j].bitmap); - if(playerColoredButton) + if(playerColoredButton) { graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); + } } delete temp; } @@ -220,25 +222,28 @@ CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2activate(); + } } void CHighlightableButtonsGroup::deactivate() { - for(int i=0;ideactivate(); + } } void CHighlightableButtonsGroup::select(int id, bool mode) { CHighlightableButton *bt = NULL; if(mode) { - for(int i=0;iID == id) bt = buttons[i]; } @@ -252,15 +257,16 @@ void CHighlightableButtonsGroup::select(int id, bool mode) void CHighlightableButtonsGroup::selectionChanged(int to) { - for(int i=0;iID!=to && buttons[i]->selected) buttons[i]->select(false); onChange(to); } void CHighlightableButtonsGroup::show(SDL_Surface * to ) { - for(int i=0;ishow(); + } } void CSlider::sliderClicked() diff --git a/AdventureMapButton.h b/AdventureMapButton.h index 0522307a5..34073de26 100644 --- a/AdventureMapButton.h +++ b/AdventureMapButton.h @@ -1,4 +1,11 @@ +#ifndef ADVENTUREMAPBUTTON_H +#define ADVENTUREMAPBUTTON_H + +#ifdef _MSC_VER #pragma once +#endif + + #include "CPlayerInterface.h" #include "client/FunctionList.h" #include @@ -91,3 +98,4 @@ public: int Value=0, bool Horizontal=true); ~CSlider(); }; +#endif //ADVENTUREMAPBUTTON_H diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 5f9a1f93b..0f7d5d697 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -27,8 +27,13 @@ #include #include #include -#pragma warning (disable : 4355) + +#ifdef _MSC_VER +#pragma warning (disable : 4355) +#endif + extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts + #define ADVOPT (conf.go()->ac) using namespace boost::logic; using namespace boost::assign; @@ -113,7 +118,7 @@ void CMinimap::draw() int mw = map[0]->w, mh = map[0]->h, wo = mw/mapSizes.x, ho = mh/mapSizes.y; - for (int i=0; igetPosition(false); if(hpos.z!=LOCPLINT->adventureInt->position.z) @@ -136,7 +141,7 @@ void CMinimap::draw() for(int y=0; y oo = LOCPLINT->cb->getFlaggableObjects(int3(x, y, LOCPLINT->adventureInt->position.z)); - for(int v=0; v(oo[v])) //heroes have been printed { @@ -170,7 +175,7 @@ void CMinimap::draw() void CMinimap::redraw(int level)// (level==-1) => redraw all levels { int3 mapSizes = LOCPLINT->cb->getMapSize(); - for (int i=0; imh->sizes.z; i++) + for (size_t i=0; imh->sizes.z; i++) { SDL_Surface * pom ; if ((level>=0) && (i!=level)) @@ -194,8 +199,8 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels } //FoW - int mw = map[0]->w, mh = map[0]->h, - wo = mw/mapSizes.x, ho = mh/mapSizes.y; + int mw = map[0]->w, mh = map[0]->h;//, + //wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me for(int d=0; dmh->map->twoLevel+1; ++d) { if(level>=0 && d!=level) @@ -302,7 +307,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL) pos.h=tilesh*32 - ADVOPT.advmapTrimY; moveX = moveY = 0; arrows = CDefHandler::giveDef("ADAG.DEF"); - for(int y=0; yourImages.size(); ++y) + for(size_t y=0; y < arrows->ourImages.size(); ++y) { arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap); } @@ -338,7 +343,7 @@ void CTerrainRect::clickLeft(tribool down) currentPath = NULL; } objs = LOCPLINT->cb->getBlockingObjs(mp); - for(int i=0; iID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town { @@ -363,13 +368,13 @@ void CTerrainRect::clickLeft(tribool down) else { objs = LOCPLINT->cb->getVisitableObjs(mp); - for(int i=0; iID == 98) goto endchkpt; } objs = LOCPLINT->cb->getBlockingObjs(mp); - for(int i=0; iID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town { @@ -451,7 +456,7 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) } } objs = LOCPLINT->cb->getBlockingObjs(pom); - for(int i=0; iID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town { @@ -475,7 +480,7 @@ void CTerrainRect::hover(bool on) } void CTerrainRect::showPath() { - for (int i=0;inodes.size()-1;i++) + for (size_t i=0; i < currentPath->nodes.size()-1; ++i) { int pn=-1;//number of picture if (i==0) //last tile @@ -728,7 +733,7 @@ void CTerrainRect::showPath() } void CTerrainRect::show() { - SDL_Surface * teren = CGI->mh->terrainRect + SDL_Surface * teren = CGI->mh->terrainRect //TODO use me (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, @@ -1028,8 +1033,8 @@ nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second, endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second, boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e), -townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD),//(5,&genRect(192,48,747,196),747,196,747,372), -heroList(ADVOPT.hlistSize) +heroList(ADVOPT.hlistSize), +townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372), { selection = NULL; townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); @@ -1339,7 +1344,7 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c } else { - for (int i=0;iobjsToBlit.size();i++) + for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i) { //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down) CSimpleWindow * pom = dynamic_cast(LOCPLINT->objsToBlit[i]); diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index d13e59a35..2c17d36d4 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -1,2511 +1,2542 @@ -#include "CBattleInterface.h" -#include "CGameInfo.h" -#include "hch/CLodHandler.h" -#include "SDL_Extensions.h" -#include "CAdvmapInterface.h" -#include "AdventureMapButton.h" -#include "hch/CObjectHandler.h" -#include "hch/CHeroHandler.h" -#include "hch/CDefHandler.h" -#include "hch/CSpellHandler.h" -#include "CCursorHandler.h" -#include "CCallback.h" -#include "CGameState.h" -#include "hch/CGeneralTextHandler.h" -#include "client/CCreatureAnimation.h" -#include "client/Graphics.h" -#include "client/CSpellWindow.h" -#include -#include -#include "lib/CondSh.h" -#include "lib/NetPacks.h" -#include -#ifndef __GNUC__ -const double M_PI = 3.14159265358979323846; -#else -#define _USE_MATH_DEFINES -#include -#endif - -extern SDL_Surface * screen; -extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; -extern SDL_Color zwykly; - -class CMP_stack2 -{ -public: - inline bool operator ()(const CStack& a, const CStack& b) - { - return (a.speed())>(b.speed()); - } -} cmpst2 ; - -CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) -: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), - attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true), - printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1) -{ - strongInterest = true; - givenCommand = new CondSh(NULL); - //initializing armies - this->army1 = army1; - this->army2 = army2; - std::map stacks = LOCPLINT->cb->battleGetStacks(); - for(std::map::iterator b=stacks.begin(); b!=stacks.end(); ++b) - { - std::pair coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature); - creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName)); - creAnims[b->second.ID]->setType(2); - creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second); - creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner; - } - //preparing menu background and terrain - std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; - background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); - menu = BitmapHandler::loadBitmap("CBAR.BMP"); - graphics->blueToPlayersAdv(menu, hero1->tempOwner); - - //preparing graphics for displaying amounts of creatures - amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); - CSDL_Ext::alphaTransform(amountNormal); - for(int g=0; gformat->palette->ncolors; ++g) - { - if((amountNormal->format->palette->colors+g)->b != 132 && - (amountNormal->format->palette->colors+g)->g != 231 && - (amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border - { - (amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f; - (amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f; - (amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f; - } - } - amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); - CSDL_Ext::alphaTransform(amountPositive); - for(int g=0; gformat->palette->ncolors; ++g) - { - if((amountPositive->format->palette->colors+g)->b != 132 && - (amountPositive->format->palette->colors+g)->g != 231 && - (amountPositive->format->palette->colors+g)->r != 255) //it's not yellow border - { - (amountPositive->format->palette->colors+g)->r = (float)((amountPositive->format->palette->colors+g)->r) * 0.18f; - (amountPositive->format->palette->colors+g)->g = (float)((amountPositive->format->palette->colors+g)->g) * 1.00f; - (amountPositive->format->palette->colors+g)->b = (float)((amountPositive->format->palette->colors+g)->b) * 0.18f; - } - } - amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); - CSDL_Ext::alphaTransform(amountNegative); - for(int g=0; gformat->palette->ncolors; ++g) - { - if((amountNegative->format->palette->colors+g)->b != 132 && - (amountNegative->format->palette->colors+g)->g != 231 && - (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border - { - (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f; - (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 0.18f; - (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f; - } - } - amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); - CSDL_Ext::alphaTransform(amountNegative); - for(int g=0; gformat->palette->ncolors; ++g) - { - if((amountNegative->format->palette->colors+g)->b != 132 && - (amountNegative->format->palette->colors+g)->g != 231 && - (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border - { - (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f; - (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 1.00f; - (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f; - } - } - - ////blitting menu background and terrain - blitAt(background, 0, 0); - blitAt(menu, 0, 556); - CSDL_Ext::update(); - - //preparing buttons and console - bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o); - bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s); - bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r); - bAutofight = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a); - bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c); - bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w); - bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d); - bDefence->assignedKeys.insert(SDLK_SPACE); - bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP); - bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN); - bConsoleDown->bitmapOffset = 2; - console = new CBattleConsole(); - console->pos.x = 211; - console->pos.y = 560; - console->pos.w = 406; - console->pos.h = 38; - - //loading hero animations - if(hero1) // attacking hero - { - attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this); - attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0); - } - else - { - attackingHero = NULL; - } - if(hero2) // defending hero - { - defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this); - defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0); - } - else - { - defendingHero = NULL; - } - - //preparing cells and hexes - cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP"); - CSDL_Ext::alphaTransform(cellBorder); - cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP"); - CSDL_Ext::alphaTransform(cellShade); - for(int h=0; hh, cellShade->w, x, y); - bfield[h].accesible = true; - bfield[h].myInterface = this; - } - //locking occupied positions on batlefield - for(std::map::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function - { - bfield[it->second.position].accesible = false; - } - - //loading projectiles for units - for(std::map::iterator g = stacks.begin(); g != stacks.end(); ++g) - { - if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string()) - { - idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]); - - if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images - { - for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k) - { - Cimage ci; - ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap); - ci.groupNumber = 0; - ci.imName = std::string(); - idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci); - } - } - for(int s=0; ssecond.creature->idNumber]->ourImages.size(); ++s) //alpha transforming - { - CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap); - } - } - } - - - //preparing graphic with cell borders - cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder); - //copying palette - for(int g=0; gformat->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256 - { - cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g]; - } - //palette copied - for(int i=0; iw; ++cellX) - { - for(int cellY = 0; cellY < cellBorder->h; ++cellY) - { - if(y+cellY < cellBorders->h && x+cellX < cellBorders->w) - * ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX); - } - } - } - } - - backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen); -} - -CBattleInterface::~CBattleInterface() -{ - SDL_FreeSurface(background); - SDL_FreeSurface(menu); - SDL_FreeSurface(amountNormal); - SDL_FreeSurface(amountNegative); - SDL_FreeSurface(amountPositive); - SDL_FreeSurface(amountEffNeutral); - SDL_FreeSurface(cellBorders); - SDL_FreeSurface(backgroundWithHexes); - delete bOptions; - delete bSurrender; - delete bFlee; - delete bAutofight; - delete bSpell; - delete bWait; - delete bDefence; - delete bConsoleUp; - delete bConsoleDown; - delete console; - delete resWindow; - delete givenCommand; - - delete attackingHero; - delete defendingHero; - - SDL_FreeSurface(cellBorder); - SDL_FreeSurface(cellShade); - - for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g) - delete g->second; - - for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g) - delete g->second; -} - -void CBattleInterface::setPrintCellBorders(bool set) -{ - printCellBorders = set; - redrawBackgroundWithHexes(activeStack); -} - -void CBattleInterface::setPrintStackRange(bool set) -{ - printStackRange = set; - redrawBackgroundWithHexes(activeStack); -} - -void CBattleInterface::setPrintMouseShadow(bool set) -{ - printMouseShadow = set; -} - -void CBattleInterface::activate() -{ - KeyInterested::activate(); - MotionInterested::activate(); - subInt = NULL; - bOptions->activate(); - bSurrender->activate(); - bFlee->activate(); - bAutofight->activate(); - bSpell->activate(); - bWait->activate(); - bDefence->activate(); - bConsoleUp->activate(); - bConsoleDown->activate(); - for(int b=0; bactivate(); - if(defendingHero) - defendingHero->activate(); -} - -void CBattleInterface::deactivate() -{ - KeyInterested::deactivate(); - MotionInterested::deactivate(); - bOptions->deactivate(); - bSurrender->deactivate(); - bFlee->deactivate(); - bAutofight->deactivate(); - bSpell->deactivate(); - bWait->deactivate(); - bDefence->deactivate(); - bConsoleUp->deactivate(); - bConsoleDown->deactivate(); - for(int b=0; bdeactivate(); - if(defendingHero) - defendingHero->deactivate(); -} - -void CBattleInterface::show(SDL_Surface * to) -{ - std::map stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places - ++animCount; - if(!to) //"evaluating" to - to = screen; - - //printing background and hexes - if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range - { - blitAt(backgroundWithHexes, 0, 0, to); - } - else - { - //showing background - blitAt(background, 0, 0, to); - if(printCellBorders) - { - CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL); - } - } - //printing hovered cell - if(printMouseShadow) - { - for(int b=0; bh, cellShade->w, x, y)); - } - } - } - - - //showing menu background and console - blitAt(menu, 0, 556, to); - console->show(to); - - //showing buttons - bOptions->show(to); - bSurrender->show(to); - bFlee->show(to); - bAutofight->show(to); - bSpell->show(to); - bWait->show(to); - bDefence->show(to); - bConsoleUp->show(to); - bConsoleDown->show(to); - - //showing hero animations - if(attackingHero) - attackingHero->show(to); - if(defendingHero) - defendingHero->show(to); - - ////showing units //a lot of work... - std::vector stackAliveByHex[BFIELD_SIZE]; - //double loop because dead stacks should be printed first - for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) - { - if(j->second.alive()) - stackAliveByHex[j->second.position].push_back(j->second.ID); - } - std::vector stackDeadByHex[BFIELD_SIZE]; - for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) - { - if(!j->second.alive()) - stackDeadByHex[j->second.position].push_back(j->second.ID); - } - - attackingShowHelper(); // handle attack animation - - for(int b=0; bnextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died - } - } - for(int b=0; bgetType(); - bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3; - creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died - //printing amount - if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive - { - int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202; - - //blitting amoutn background box - SDL_Surface *amountBG = NULL; - if(stacks[stackAliveByHex[b][v]].effects.size() == 0) - { - amountBG = amountNormal; - } - else - { - int pos=0; //determining total positiveness of effects - for(int c=0; cspellh->spells[ stacks[stackAliveByHex[b][v]].effects[c].id ].positiveness; - } - if(pos > 0) - { - amountBG = amountPositive; - } - else if(pos < 0) - { - amountBG = amountNegative; - } - else - { - amountBG = amountEffNeutral; - } - } - SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260)); - //blitting amount - std::stringstream ss; - ss<pos.x + xAdd + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); - } - } - } - //units shown - projectileShowHelper(to);//showing projectiles - - //showing spell effects - if(battleEffects.size()) - { - std::vector< std::list::iterator > toErase; - for(std::list::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it) - { - blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to); - ++(it->frame); - - if(it->frame == it->maxFrame) - toErase.push_back(it); - } - for(int b=0; banim; - battleEffects.erase(toErase[b]); - } - } - - - //showing queue of stacks - if(showStackQueue) - { - int xPos = screen->w/2 - ( stacks.size() * 37 )/2; - int yPos = 10; - - std::vector stacksSorted; - stacksSorted = LOCPLINT->cb->battleGetStackQueue(); - int startFrom = -1; - for(int n=0; nsmallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos)); - //printing colored border - for(int xFrom = xPos-1; xFromplayerColors[stacksSorted[b % stacksSorted.size()].owner]; - } - else - { - pc = *graphics->neutralColor; - } - CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b); - } - } - } - //colored border printed - SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos)); - xPos += 37; - } - } - } - - //showing window with result of battle - if(resWindow) - { - resWindow->show(to); - } -} -void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key) -{ - if(key.keysym.sym == SDLK_q) - showStackQueue = key.state==SDL_PRESSED; -} -void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) -{ - if(activeStack>=0 && !spellDestSelectMode) - { - int myNumber = -1; //number of hovered tile - for(int g=0; gcurh->changeGraphic(1, 6); - } - else - { - if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end()) - { - CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber); - if(shere) - { - if(shere->owner == LOCPLINT->playerID) //our stack - CGI->curh->changeGraphic(1,5); - else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy - CGI->curh->changeGraphic(1,3); - else if(isTileAttackable(myNumber)) //available enemy (melee attackable) - { - int fromHex = previouslyHoveredHex; - if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex)) - { - switch(BattleInfo::mutualPosition(fromHex, myNumber)) - { - case 0: - CGI->curh->changeGraphic(1,12); - break; - case 1: - CGI->curh->changeGraphic(1,7); - break; - case 2: - CGI->curh->changeGraphic(1,8); - break; - case 3: - CGI->curh->changeGraphic(1,9); - break; - case 4: - CGI->curh->changeGraphic(1,10); - break; - case 5: - CGI->curh->changeGraphic(1,11); - break; - } - } - } - else //unavailable enemy - CGI->curh->changeGraphic(1,0); - } - else //empty unavailable tile - CGI->curh->changeGraphic(1,0); - } - else //available tile - { - if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying()) - CGI->curh->changeGraphic(1,2); - else - CGI->curh->changeGraphic(1,1); - } - } - } - else if(spellDestSelectMode) - { - int myNumber = -1; //number of hovered tile - for(int g=0; gcurh->changeGraphic(1, 0); - } - else - { - switch(spellSelMode) - { - case 0: - CGI->curh->changeGraphic(3, 0); - break; - case 1: - if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(myNumber)->owner ) - CGI->curh->changeGraphic(3, 0); - else - CGI->curh->changeGraphic(1, 0); - break; - case 2: - if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(myNumber)->owner ) - CGI->curh->changeGraphic(3, 0); - else - CGI->curh->changeGraphic(1, 0); - break; - case 3: - if(LOCPLINT->cb->battleGetStackByPos(myNumber)) - CGI->curh->changeGraphic(3, 0); - else - CGI->curh->changeGraphic(1, 0); - break; - case 4: //TODO: implement this case - break; - } - } - } -} - -bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) -{ - if(creAnims[number]==NULL) - return false; //there is no such creature - creAnims[number]->setType(8); - int firstFrame = creAnims[number]->getFrame(); - for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - creDir[number] = !creDir[number]; - - CStack curs = *LOCPLINT->cb->battleGetStackByID(number); - std::pair coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature); - creAnims[number]->pos.x = coords.first; - //creAnims[number]->pos.y = coords.second; - - if(wideTrick && curs.creature->isDoubleWide()) - { - if(curs.attackerOwned) - { - if(!creDir[number]) - creAnims[number]->pos.x -= 44; - } - else - { - if(creDir[number]) - creAnims[number]->pos.x += 44; - } - } - - creAnims[number]->setType(7); - firstFrame = creAnims[number]->getFrame(); - for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - creAnims[number]->setType(2); - - return true; -} - -void CBattleInterface::bOptionsf() -{ - CGI->curh->changeGraphic(0,0); - deactivate(); - - SDL_Rect temp_rect = genRect(431, 481, 160, 84); - CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this); - optionsWin->activate(); - LOCPLINT->objsToBlit.push_back(optionsWin); -} - -void CBattleInterface::bSurrenderf() -{ -} - -void CBattleInterface::bFleef() -{ - CFunctionList ony = boost::bind(&CBattleInterface::activate,this); - ony += boost::bind(&CBattleInterface::reallyFlee,this); - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, boost::bind(&CBattleInterface::activate,this), true, false); -} - -void CBattleInterface::reallyFlee() -{ - giveCommand(4,0,0); - CGI->curh->changeGraphic(0, 0); -} - -void CBattleInterface::bAutofightf() -{ -} - -void CBattleInterface::bSpellf() -{ - CGI->curh->changeGraphic(0,0); - deactivate(); - - const CGHeroInstance * chi = NULL; - if(attackingHeroInstance->tempOwner == LOCPLINT->playerID) - chi = attackingHeroInstance; - else - chi = defendingHeroInstance; - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), chi); - spellWindow->activate(); - LOCPLINT->objsToBlit.push_back(spellWindow); -} - -void CBattleInterface::bWaitf() -{ - giveCommand(8,0,activeStack); -} - -void CBattleInterface::bDefencef() -{ - giveCommand(3,0,activeStack); -} - -void CBattleInterface::bConsoleUpf() -{ - console->scrollUp(); -} - -void CBattleInterface::bConsoleDownf() -{ - console->scrollDown(); -} - -void CBattleInterface::newStack(CStack stack) -{ - creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName); - creAnims[stack.ID]->setType(2); - creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner; -} - -void CBattleInterface::stackRemoved(CStack stack) -{ - delete creAnims[stack.ID]; - creAnims.erase(stack.ID); -} - -void CBattleInterface::stackActivated(int number) -{ - //givenCommand = NULL; - activeStack = number; - myTurn = true; - redrawBackgroundWithHexes(number); - bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(number)->state,WAITING)); //block waiting button if stack has been already waiting -} - -void CBattleInterface::stackMoved(int number, int destHex, bool endMoving) -{ - bool startMoving = creAnims[number]->type==20; - //a few useful variables - int curStackPos = LOCPLINT->cb->battleGetPos(number); - int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1; - int hexWbase = 44, hexHbase = 42; - bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide(); - - if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier) - { - CGI->curh->hide(); - for(int i=0; iframesInGroup(20)*getAnimSpeedMultiplier()-1; ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - if((animCount+1)%(4/animSpeed)==0) - creAnims[number]->incrementFrame(); - } - } - - int mutPos = BattleInfo::mutualPosition(curStackPos, destHex); - - { - switch(mutPos) //reverse unit if necessary - { - case 0: case 4: case 5: - if(creDir[number] == true) - reverseCreature(number, curStackPos, twoTiles); - break; - case 1: case 2: case 3: - if(creDir[number] == false) - reverseCreature(number, curStackPos, twoTiles); - break; - } - //moving instructions - creAnims[number]->setType(0); - float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;] - for(int i=0; ipos.x = posX; - posY -= ((float)hexHbase)/((float)steps); - creAnims[number]->pos.y = posY; - break; - case 1: - posX += ((float)hexWbase)/(2.0f*steps); - creAnims[number]->pos.x = posX; - posY -= ((float)hexHbase)/((float)steps); - creAnims[number]->pos.y = posY; - break; - case 2: - posX += ((float)hexWbase)/((float)steps); - creAnims[number]->pos.x = posX; - break; - case 3: - posX += ((float)hexWbase)/(2.0f*steps); - creAnims[number]->pos.x = posX; - posY += ((float)hexHbase)/((float)steps); - creAnims[number]->pos.y = posY; - break; - case 4: - posX -= ((float)hexWbase)/(2.0f*steps); - creAnims[number]->pos.x = posX; - posY += ((float)hexHbase)/((float)steps); - creAnims[number]->pos.y = posY; - break; - case 5: - posX -= ((float)hexWbase)/((float)steps); - creAnims[number]->pos.x = posX; - break; - } - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - if((animCount+1)%(4/animSpeed)==0) - creAnims[number]->incrementFrame(); - } - } - - if(endMoving) //animation of ending move - { - if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier) - { - creAnims[number]->setType(21); - for(int i=0; iframesInGroup(21)*getAnimSpeedMultiplier()-1; ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - if((animCount+1)%(4/animSpeed)==0) - creAnims[number]->incrementFrame(); - } - } - creAnims[number]->setType(2); //resetting to default - CGI->curh->show(); - } - - CStack curs = *LOCPLINT->cb->battleGetStackByID(number); - if(endMoving) //resetting to default - { - if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner)) - reverseCreature(number, destHex, twoTiles); - } - std::pair coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature); - creAnims[number]->pos.x = coords.first; - if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed - creAnims[number]->pos.x -= 44; - creAnims[number]->pos.y = coords.second; -} - -void CBattleInterface::stacksAreAttacked(std::vector attackedInfos) -{ - //restoring default state of battleWindow by calling show func - while(true) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - - //checking break conditions - bool break_loop = true; - for(int g=0; ggetType() != 2) - break_loop = false; - if(attackingInfo && attackingInfo->IDby == attackedInfos[g].IDby) - break_loop = false; - } - if(break_loop) break; - } - if(attackedInfos.size() == 1 && attackedInfos[0].byShooting) //delay hit animation - { - CStack attacker = *LOCPLINT->cb->battleGetStackByID(attackedInfos[0].IDby); - while(true) - { - bool found = false; - for(std::list::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it) - { - if(it->creID == attacker.creature->idNumber) - { - found = true; - break; - } - } - if(!found) - break; - else - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - } - } - //initializing - std::map animLengths; - std::map increments; - int maxLen = 0; - for(int g=0; gsetType(5); //death - animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5); - } - else - { - creAnims[attackedInfos[g].ID]->setType(3); //getting hit - animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3); - } - animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen)); - increments.insert(std::make_pair(attackedInfos[g].ID, 0)); - if(animLen > maxLen) - { - maxLen = animLen; - } - } - //main showing loop - bool continueLoop = true; - while(continueLoop) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - for(int g=0; gincrementFrame(); - ++(increments[attackedInfos[g].ID]); - } - if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3) - creAnims[attackedInfos[g].ID]->setType(2); - } - bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued - for(int g=0; ggetType() == 3) - creAnims[attackedInfos[g].ID]->setType(2); - } - - //printing info to console - for(int g=0; ggetType()!=2) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack - int reversedShift = 0; //shift of attacking stack's position due to reversing - if(aStack.attackerOwned) - { - if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - reverseCreature(ID, aStack.position, true); - break; - case -1: - if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest - { - reverseCreature(ID, aStack.position, true); - reversedShift = (aStack.attackerOwned ? -1 : 1); - } - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - reverseCreature(ID, aStack.position, true); - break; - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - reverseCreature(ID, aStack.position, true); - break; - case 5: - reverseCreature(ID, aStack.position, true); - break; - } - } - } - else //if(aStack.attackerOwned) - { - if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - break; - case 2: - reverseCreature(ID, aStack.position, true); - break; - case 3: - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - //reverseCreature(ID, aStack.position, true); - break; - case -1: - if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest - { - reverseCreature(ID, aStack.position, true); - reversedShift = (aStack.attackerOwned ? -1 : 1); - } - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - reverseCreature(ID, aStack.position, true); - break; - case 2: - reverseCreature(ID, aStack.position, true); - break; - case 3: - reverseCreature(ID, aStack.position, true); - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - //reverseCreature(ID, aStack.position, true); - break; - } - } - } - - attackingInfo = new CAttHelper; - attackingInfo->dest = dest; - attackingInfo->frame = 0; - attackingInfo->hitCount = 0; - attackingInfo->ID = ID; - attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID; - attackingInfo->reversing = false; - attackingInfo->posShiftDueToDist = reversedShift; - attackingInfo->shooting = false; - - switch(BattleInfo::mutualPosition(aStack.position + reversedShift, dest)) //attack direction - { - case 0: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - case 1: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - case 2: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - case 3: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(13); - break; - case 4: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(13); - break; - case 5: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - default: - tlog1<<"Critical Error! Wrong dest in stackAttacking!"<addText(CGI->generaltexth->allTexts[412]); -} - -void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional) -{ - BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack() - ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; - ba->actionType = action; - ba->destinationTile = tile; - ba->stackNumber = stack; - ba->additionalInfo = additional; - givenCommand->setn(ba); - myTurn = false; - activeStack = -1; -} - -bool CBattleInterface::isTileAttackable(const int & number) const -{ - for(int b=0; bcb->battleGetStackByPos(whichOne) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne)->owner ) - allowCasting = false; - break; - case 2: - if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne)->owner ) - allowCasting = false; - break; - case 3: - if(!LOCPLINT->cb->battleGetStackByPos(whichOne)) - allowCasting = false; - break; - case 4: //TODO: implement this case - break; - } - //destination checked - if(allowCasting) - { - spellToCast->destinationTile = whichOne; - LOCPLINT->cb->battleMakeAction(spellToCast); - delete spellToCast; - spellToCast = NULL; - spellDestSelectMode = false; - CGI->curh->changeGraphic(1, 6); - } - } - else - { - CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one - if(!dest || !dest->alive()) //no creature at that tile - { - if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range - { - CGI->curh->changeGraphic(1, 6); //cursor should be changed - giveCommand(2,whichOne,activeStack); - } - } - else if(dest->owner != attackingHeroInstance->tempOwner - && LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting - { - CGI->curh->changeGraphic(1, 6); //cursor should be changed - giveCommand(7,whichOne,activeStack); - } - else if(dest->owner != attackingHeroInstance->tempOwner) //attacking - { - switch(CGI->curh->number) - { - case 12: - giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne); - break; - case 7: - giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne); - break; - case 8: - giveCommand(6,whichOne - 1,activeStack,whichOne); - break; - case 9: - giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne); - break; - case 10: - giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne); - break; - case 11: - giveCommand(6,whichOne + 1,activeStack,whichOne); - break; - } - CGI->curh->changeGraphic(1, 6); //cursor should be changed - } - } - } -} - -void CBattleInterface::stackIsShooting(int ID, int dest) -{ - if(attackingInfo != NULL) - { - return; //something went wrong - } - //projectile - float projectileAngle; //in radians; if positive, projectiles goes up - float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) - int fromHex = LOCPLINT->cb->battleGetPos(ID); - projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17)); - if(fromHex < dest) - projectileAngle = -projectileAngle; - - SProjectileInfo spi; - spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber; - - spi.step = 0; - spi.frameNum = 0; - spi.spin = CGI->creh->idToProjectileSpin[spi.creID]; - - std::pair xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID)); - std::pair destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID)); - destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot - - if(projectileAngle > straightAngle) //upper shot - { - spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX; - spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY; - } - else if(projectileAngle < -straightAngle) //lower shot - { - spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX; - spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY; - } - else //straight shot - { - spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX; - spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY; - } - spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40; - if(spi.lastStep == 0) - spi.lastStep = 1; - spi.dx = (destcoord.first - spi.x) / spi.lastStep; - spi.dy = (destcoord.second - spi.y) / spi.lastStep; - //set starting frame - if(spi.spin) - { - spi.frameNum = 0; - } - else - { - spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1); - } - //set delay - spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame; - projectiles.push_back(spi); - - //attack aniamtion - attackingInfo = new CAttHelper; - attackingInfo->dest = dest; - attackingInfo->frame = 0; - attackingInfo->hitCount = 0; - attackingInfo->ID = ID; - attackingInfo->reversing = false; - attackingInfo->posShiftDueToDist = 0; - attackingInfo->shooting = true; - if(projectileAngle > straightAngle) //upper shot - attackingInfo->shootingGroup = 14; - else if(projectileAngle < -straightAngle) //lower shot - attackingInfo->shootingGroup = 16; - else //straight shot - attackingInfo->shootingGroup = 15; - attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup); -} - -void CBattleInterface::battleFinished(const BattleResult& br) -{ - deactivate(); - CGI->curh->changeGraphic(0,0); - - SDL_Rect temp_rect = genRect(561, 470, 165, 19); - resWindow = new CBattleReslutWindow(br, temp_rect, this); - resWindow->activate(); -} - -void CBattleInterface::spellCasted(SpellCasted * sc) -{ - std::vector< std::string > anims; //for magic arrow and ice bolt - switch(sc->id) - { - case 15: //magic arrow - { - //initialization of anims - anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF"); - } - case 16: //ice bolt - { - if(anims.size() == 0) //initialiaztion of anims - { - anims.push_back("C08SPW0.DEF"); anims.push_back("C08SPW1.DEF"); anims.push_back("C08SPW2.DEF"); anims.push_back("C08SPW3.DEF"); anims.push_back("C08SPW4.DEF"); - } - } //end of ice bolt only part - { //common ice bolt and magic arrow part - //initial variables - std::string animToDisplay; - std::pair srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60); - std::pair destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow - destcoord.first += 250; destcoord.second += 240; - - //animation angle - float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second)); - - //choosing animation by angle - if(angle > 1.50) - animToDisplay = anims[0]; - else if(angle > 1.20) - animToDisplay = anims[1]; - else if(angle > 0.90) - animToDisplay = anims[2]; - else if(angle > 0.60) - animToDisplay = anims[3]; - else - animToDisplay = anims[4]; - - //displaying animation - int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40; - if(steps <= 0) - steps = 1; - - CDefHandler * animDef = CDefHandler::giveDef(animToDisplay); - - int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps; - - for(int g=0; gourImages[g%animDef->ourImages.size()].bitmap->clip_rect; - SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy); - SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - - int b=0; - break; //for 15 and 16 cases - } - case 17: //lightning bolt - { - displayEffect(1, sc->tile); - break; - } - case 18: //implosion - { - displayEffect(10, sc->tile); - break; - } - case 27: //shield - { - displayEffect(27, sc->tile); - break; - } - case 28: //air shield - { - displayEffect(2, sc->tile); - break; - } - case 41: //bless - { - displayEffect(36, sc->tile); - break; - } - case 42: //curse - { - displayEffect(40, sc->tile); - break; - } - case 43: //bloodlust - { - displayEffect(4, sc->tile); //TODO: give better animation for this spell - break; - } - case 45: //weakness - { - displayEffect(56, sc->tile); //TODO: give better animation for this spell - break; - } - case 46: //stone skin - { - displayEffect(54, sc->tile); - break; - } - case 48: //prayer - { - displayEffect(0, sc->tile); - break; - } - case 53: //haste - { - displayEffect(31, sc->tile); - break; - } - case 54: //slow - { - displayEffect(19, sc->tile); - break; - } - case 56: //frenzy - { - displayEffect(17, sc->tile); - break; - } - case 61: //forgetfulness - { - displayEffect(42, sc->tile); - break; - } - } -} - -void CBattleInterface::castThisSpell(int spellID) -{ - BattleAction * ba = new BattleAction; - ba->actionType = 1; - ba->additionalInfo = spellID; //spell number - ba->destinationTile = -1; - ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2; - ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; - spellToCast = ba; - spellDestSelectMode = true; - - //choosing possible tragets - const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance; - spellSelMode = 0; - if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos) - { - switch(CGI->spellh->spells[spellID].positiveness) - { - case -1 : - spellSelMode = 2; - break; - case 0: - spellSelMode = 3; - break; - case 1: - spellSelMode = 1; - break; - } - } - if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos) - { - if(castingHero && castingHero->getSpellSecLevel(spellID) < 3) - { - switch(CGI->spellh->spells[spellID].positiveness) - { - case -1 : - spellSelMode = 2; - break; - case 0: - spellSelMode = 3; - break; - case 1: - spellSelMode = 1; - break; - } - } - else - { - spellSelMode = -1; - } - } - CGI->curh->changeGraphic(3, 0); -} - -void CBattleInterface::displayEffect(ui32 effect, int destTile) -{ - if(graphics->battleACToDef[effect].size() != 0) - { - SBattleEffect be; - be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); - be.frame = 0; - be.maxFrame = be.anim->ourImages.size(); - be.x = 22 * ( ((destTile/BFIELD_WIDTH) + 1)%2 ) + 44 * (destTile % BFIELD_WIDTH) + 45; - be.y = 105 + 42 * (destTile/BFIELD_WIDTH); - - if(effect != 1 && effect != 0) - { - be.x -= be.anim->ourImages[0].bitmap->w/2; - be.y -= be.anim->ourImages[0].bitmap->h/2; - } - else if(effect == 1) - { - be.x -= be.anim->ourImages[0].bitmap->w; - be.y -= be.anim->ourImages[0].bitmap->h; - } - else if (effect == 0) - { - be.x -= be.anim->ourImages[0].bitmap->w/2; - be.y -= be.anim->ourImages[0].bitmap->h; - } - - battleEffects.push_back(be); - } - //battleEffects -} - -void CBattleInterface::setAnimSpeed(int set) -{ - animSpeed = set; -} - -int CBattleInterface::getAnimSpeed() const -{ - return animSpeed; -} - -float CBattleInterface::getAnimSpeedMultiplier() const -{ - switch(animSpeed) - { - case 1: - return 3.5f; - case 2: - return 2.2f; - case 4: - return 1.0f; - default: - return 0.0f; - } -} - -void CBattleInterface::attackingShowHelper() -{ - if(attackingInfo && !attackingInfo->reversing) - { - if(attackingInfo->frame == 0) - { - CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack - if(attackingInfo->shooting) - { - creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup); - } - else - { - if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position+attackingInfo->posShiftDueToDist, attackingInfo->dest)) //attack direction - { - case 0: - creAnims[attackingInfo->ID]->setType(11); - break; - case 1: - creAnims[attackingInfo->ID]->setType(11); - break; - case 2: - creAnims[attackingInfo->ID]->setType(12); - break; - case 3: - creAnims[attackingInfo->ID]->setType(13); - break; - case 4: - creAnims[attackingInfo->ID]->setType(13); - break; - case 5: - creAnims[attackingInfo->ID]->setType(12); - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - creAnims[attackingInfo->ID]->setType(11); - break; - case 1: - creAnims[attackingInfo->ID]->setType(11); - break; - case 2: - creAnims[attackingInfo->ID]->setType(12); - break; - case 3: - creAnims[attackingInfo->ID]->setType(13); - break; - case 4: - creAnims[attackingInfo->ID]->setType(13); - break; - case 5: - creAnims[attackingInfo->ID]->setType(12); - break; - } - } - } - } - else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) - { - attackingInfo->reversing = true; - - CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack - if(aStackp == NULL) - return; - CStack aStack = *aStackp; - if(aStack.attackerOwned) - { - if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case -1: - if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest - { - reverseCreature(attackingInfo->ID, aStack.position, true); - } - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 5: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - } - } - } - else //if(aStack.attackerOwned) - { - if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - break; - case 2: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 3: - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - //reverseCreature(ID, aStack.position, true); - break; - case -1: - if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest - { - reverseCreature(attackingInfo->ID, aStack.position, true); - } - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - //reverseCreature(ID, aStack.position, true); - break; - case 1: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 2: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 3: - reverseCreature(attackingInfo->ID, aStack.position, true); - break; - case 4: - //reverseCreature(ID, aStack.position, true); - break; - case 5: - //reverseCreature(ID, aStack.position, true); - break; - } - } - } - attackingInfo->reversing = false; - creAnims[attackingInfo->ID]->setType(2); - delete attackingInfo; - attackingInfo = NULL; - } - if(attackingInfo) - { - attackingInfo->hitCount++; - if(attackingInfo->hitCount%(4/animSpeed) == 0) - attackingInfo->frame++; - } - } -} - -void CBattleInterface::redrawBackgroundWithHexes(int activeStack) -{ - shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack); - - //preparating background graphic with hexes and shaded hexes - blitAt(background, 0, 0, backgroundWithHexes); - if(printCellBorders) - CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL); - - if(printStackRange) - { - for(int m=0; mh, cellShade->w, x, y)); - } - } -} - -void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby) -{ - char tabh[200]; - CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby); - CStack defender = *LOCPLINT->cb->battleGetStackByID(ID); - int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(), - (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()), - dmg); - if(killed > 0) - { - if(killed > 1) - { - sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str()); - } - else //killed == 1 - { - sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str()); - } - } - - console->addText(std::string(tabh)); -} - -void CBattleInterface::projectileShowHelper(SDL_Surface * to) -{ - if(to == NULL) - to = screen; - std::list< std::list::iterator > toBeDeleted; - for(std::list::iterator it=projectiles.begin(); it!=projectiles.end(); ++it) - { - if(it->animStartDelay>0) - { - --(it->animStartDelay); - continue; - } - SDL_Rect dst; - dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h; - dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w; - dst.x = it->x; - dst.y = it->y; - CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst); - //actualizing projectile - ++it->step; - if(it->step == it->lastStep) - { - toBeDeleted.insert(toBeDeleted.end(), it); - } - else - { - it->x += it->dx; - it->y += it->dy; - if(it->spin) - { - ++(it->frameNum); - it->frameNum %= idToProjectile[it->creID]->ourImages.size(); - } - } - } - for(std::list< std::list::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it) - { - projectiles.erase(*it); - } -} - -void CBattleHero::show(SDL_Surface *to) -{ - //animation of flag - if(flip) - { - CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 752, 39)); - } - else - { - CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39)); - } - ++flagAnimCount; - if(flagAnimCount%4==0) - { - ++flagAnim; - flagAnim %= flag->ourImages.size(); - } - //animation of hero - int tick=-1; - for(int i=0; iourImages.size(); ++i) - { - if(dh->ourImages[i].groupNumber==phase) - ++tick; - if(tick==image) - { - SDL_Rect posb = pos; - CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); - ++image; - if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame - { - image = 0; - } - break; - } - } -} - -void CBattleHero::activate() -{ - ClickableL::activate(); -} -void CBattleHero::deactivate() -{ - ClickableL::deactivate(); -} - -void CBattleHero::setPhase(int newPhase) -{ - phase = newPhase; - image = 0; -} - -void CBattleHero::clickLeft(boost::logic::tribool down) -{ - if(!down && myHero) - { - for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) - return; - } - CGI->curh->changeGraphic(0,0); - LOCPLINT->curint->deactivate(); - - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero); - spellWindow->activate(); - LOCPLINT->objsToBlit.push_back(spellWindow); - } -} - -CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero), myOwner(owner) -{ - dh = CDefHandler::giveDef( defName ); - for(int i=0; iourImages.size(); ++i) //transforming images - { - if(flip) - { - SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); - SDL_FreeSurface(dh->ourImages[i].bitmap); - dh->ourImages[i].bitmap = hlp; - } - dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); - } - dh->alphaTransformed = true; - - if(flip) - flag = CDefHandler::giveDef("CMFLAGR.DEF"); - else - flag = CDefHandler::giveDef("CMFLAGL.DEF"); - - //coloring flag and adding transparency - for(int i=0; iourImages.size(); ++i) - { - flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); - graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); - } -} - -CBattleHero::~CBattleHero() -{ - delete dh; - delete flag; -} - -std::pair CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature) -{ - std::pair ret = std::make_pair(-500, -500); //returned value - ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y - //counting x - if(attacker) - { - ret.first = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); - } - else - { - ret.first = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); - } - //shifting position for double - hex creatures - if(creature && creature->isDoubleWide()) - { - if(attacker) - { - ret.first -= 42; - } - else - { - ret.first += 42; - } - } - //returning - return ret; -} -void CBattleHex::activate() -{ - Hoverable::activate(); - MotionInterested::activate(); - ClickableL::activate(); - ClickableR::activate(); -} - -void CBattleHex::deactivate() -{ - Hoverable::deactivate(); - MotionInterested::deactivate(); - ClickableL::deactivate(); - ClickableR::deactivate(); -} - -void CBattleHex::hover(bool on) -{ - hovered = on; - Hoverable::hover(on); - if(!on && setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false) -{ -} - -void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) -{ - if(myInterface->cellShade) - { - if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex - { - strictHovered = false; - } - else //hovered pixel is inside hex - { - strictHovered = true; - } - } - - if(hovered && strictHovered) //print attacked creature to console - { - if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && - LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID && - LOCPLINT->cb->battleGetStackByPos(myNumber)->alive()) - { - char tabh[160]; - CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber); - const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; - sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); - myInterface->console->alterTxt = std::string(tabh); - setAlterText = true; - } - } - else if(setAlterText) - { - myInterface->console->alterTxt = std::string(); - setAlterText = false; - } -} - -void CBattleHex::clickLeft(boost::logic::tribool down) -{ - if(!down && hovered && strictHovered) //we've been really clicked! - { - myInterface->hexLclicked(myNumber); - } -} - -void CBattleHex::clickRight(boost::logic::tribool down) -{ - int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile - if(hovered && strictHovered && stID!=-1) - { - CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info - if(!myst.alive()) return; - StackState *pom = NULL; - if(down) - { - pom = new StackState(); - const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance; - if(h) - { - pom->attackBonus = h->getPrimSkillLevel(0); - pom->defenseBonus = h->getPrimSkillLevel(1); - pom->luck = h->getCurrentLuck(); - pom->morale = h->getCurrentMorale(); - pom->shotsLeft = myst.shots; - for(int vb=0; vbeffects.insert(myst.effects[vb].id); - } - } - pom->currentHealth = myst.firstHPleft; - (new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function(),boost::function(),NULL)) - ->activate(); - } - delete pom; - } -} - -CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("") -{ -} - -CBattleConsole::~CBattleConsole() -{ - texts.clear(); -} - -void CBattleConsole::show(SDL_Surface * to) -{ - if(alterTxt.size()) - { - CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); - } - else if(texts.size()) - { - if(texts.size()==1) - { - CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); - } - else - { - CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); - CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to); - } - } -} - -bool CBattleConsole::addText(const std::string & text) -{ - if(text.size()>70) - return false; //text too long! - int firstInToken = 0; - for(int i=0; i= texts.size()) //no such pos - return; - texts[pos] = text; -} - -void CBattleConsole::scrollUp(unsigned int by) -{ - if(lastShown > by) - lastShown -= by; -} - -void CBattleConsole::scrollDown(unsigned int by) -{ - if(lastShown + by < texts.size()) - lastShown += by; -} - -CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner) -{ - this->pos = pos; - background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); - graphics->blueToPlayersAdv(background, LOCPLINT->playerID); - SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); - SDL_FreeSurface(background); - background = pom; - exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN); - - if(br.winner==0) //attacker won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background); - } - else //if(br.winner==1) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background); - } - - - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background); - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background); - - std::string attackerName, defenderName; - - if(owner->attackingHeroInstance) //a hero attacked - { - SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38)); - //setting attackerName - attackerName = owner->attackingHeroInstance->name; - } - else //a monster attacked - { - int bestMonsterID = -1; - int bestPower = 0; - for(std::map >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it) - { - if( CGI->creh->creatures[it->first].AIValue > bestPower) - { - bestPower = CGI->creh->creatures[it->first].AIValue; - bestMonsterID = it->first; - } - } - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38)); - //setting attackerName - attackerName = CGI->creh->creatures[bestMonsterID].namePl; - } - if(owner->defendingHeroInstance) //a hero defended - { - SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38)); - //setting defenderName - defenderName = owner->defendingHeroInstance->name; - } - else //a monster defended - { - int bestMonsterID = -1; - int bestPower = 0; - for(std::map >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it) - { - if( CGI->creh->creatures[it->second.first].AIValue > bestPower) - { - bestPower = CGI->creh->creatures[it->second.first].AIValue; - bestMonsterID = it->second.first; - } - } - SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38)); - //setting defenderName - defenderName = CGI->creh->creatures[bestMonsterID].namePl; - } - - //printing attacker and defender's names - CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background); - CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background); - //printing casualities - for(int step = 0; step < 2; ++step) - { - if(br.casualties[step].size()==0) - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background); - } - else - { - int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture - int yPos = 344 + step*97; - for(std::set >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) - { - blitAt(graphics->smallImgs[it->first], xPos, yPos, background); - std::stringstream amount; - amount<second; - CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background); - xPos += 42; - } - } - } - //printing result description - bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner); - switch(br.result) - { - case 0: //normal victory - if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background); - } - else - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background); - } - break; - case 1: //flee - if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background); - } - else - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background); - } - break; - case 2: //surrender - if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background); - } - else - { - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background); - } - break; - } -} - -CBattleReslutWindow::~CBattleReslutWindow() -{ - SDL_FreeSurface(background); -} - -void CBattleReslutWindow::activate() -{ - LOCPLINT->showingDialog->set(true); - exit->activate(); -} - -void CBattleReslutWindow::deactivate() -{ - exit->deactivate(); -} - -void CBattleReslutWindow::show(SDL_Surface *to) -{ - //evaluating to - if(!to) - to = screen; - - SDL_BlitSurface(background, NULL, to, &pos); - exit->show(to); -} - -void CBattleReslutWindow::bExitf() -{ - LOCPLINT->battleResultQuited(); -} - -CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) -{ - pos = position; - background = BitmapHandler::loadBitmap("comopbck.bmp", true); - graphics->blueToPlayersAdv(background, LOCPLINT->playerID); - - viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false); - viewGrid->select(owner->printCellBorders); - movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false); - movementShadow->select(owner->printStackRange); - mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false); - mouseShadow->select(owner->printMouseShadow); - - animSpeeds = new CHighlightableButtonsGroup(0); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def",252, 309, 2); - animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",315, 309, 4); - animSpeeds->select(owner->getAnimSpeed(), 1); - animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); - - setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[392].first, CGI->generaltexth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def"); - std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]); - exit = new AdventureMapButton (CGI->generaltexth->zelp[393].first, CGI->generaltexth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN); - std::swap(exit->imgs[0][0], exit->imgs[0][1]); - - //printing texts to background - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options - CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info - - //auto - combat options - CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures - CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells - CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult - CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista - CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent - - //creature info - CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats - CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only - - //general options - CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid - CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow - CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow - CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation - //texts printed -} - -CBattleOptionsWindow::~CBattleOptionsWindow() -{ - SDL_FreeSurface(background); - - delete setToDefault; - delete exit; - - delete viewGrid; - delete movementShadow; - delete animSpeeds; - delete mouseShadow; -} - -void CBattleOptionsWindow::activate() -{ - setToDefault->activate(); - exit->activate(); - viewGrid->activate(); - movementShadow->activate(); - animSpeeds->activate(); - mouseShadow->activate(); -} - -void CBattleOptionsWindow::deactivate() -{ - setToDefault->deactivate(); - exit->deactivate(); - viewGrid->deactivate(); - movementShadow->deactivate(); - animSpeeds->deactivate(); - mouseShadow->deactivate(); -} - -void CBattleOptionsWindow::show(SDL_Surface *to) -{ - if(!to) //"evaluating" to - to = screen; - - SDL_BlitSurface(background, NULL, to, &pos); - - setToDefault->show(to); - exit->show(to); - viewGrid->show(to); - movementShadow->show(to); - animSpeeds->show(to); - mouseShadow->show(to); -} - -void CBattleOptionsWindow::bDefaultf() -{ -} - -void CBattleOptionsWindow::bExitf() -{ - deactivate(); - - for(int g=0; gobjsToBlit.size(); ++g) - { - if(dynamic_cast(LOCPLINT->objsToBlit[g])) - { - LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g); - break; - } - } - - delete this; - LOCPLINT->curint->activate(); -} +#include "CBattleInterface.h" +#include "CGameInfo.h" +#include "hch/CLodHandler.h" +#include "SDL_Extensions.h" +#include "CAdvmapInterface.h" +#include "AdventureMapButton.h" +#include "hch/CObjectHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CDefHandler.h" +#include "hch/CSpellHandler.h" +#include "CCursorHandler.h" +#include "CCallback.h" +#include "CGameState.h" +#include "hch/CGeneralTextHandler.h" +#include "client/CCreatureAnimation.h" +#include "client/Graphics.h" +#include "client/CSpellWindow.h" +#include +#include +#include "lib/CondSh.h" +#include "lib/NetPacks.h" +#include +#ifndef __GNUC__ +const double M_PI = 3.14159265358979323846; +#else +#define _USE_MATH_DEFINES +#include +#endif + +extern SDL_Surface * screen; +extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; +extern SDL_Color zwykly; + +struct CMP_stack2 +{ + inline bool operator ()(const CStack& a, const CStack& b) + { + return (a.speed())>(b.speed()); + } +} cmpst2 ; + +CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) +: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), + attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true), + printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1) +{ + strongInterest = true; + givenCommand = new CondSh(NULL); + //initializing armies + this->army1 = army1; + this->army2 = army2; + std::map stacks = LOCPLINT->cb->battleGetStacks(); + for(std::map::iterator b=stacks.begin(); b!=stacks.end(); ++b) + { + std::pair coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature); + creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName)); + creAnims[b->second.ID]->setType(2); + creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second); + creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner; + } + //preparing menu background and terrain + std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; + background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); + menu = BitmapHandler::loadBitmap("CBAR.BMP"); + graphics->blueToPlayersAdv(menu, hero1->tempOwner); + + //preparing graphics for displaying amounts of creatures + amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); + CSDL_Ext::alphaTransform(amountNormal); + for(int g=0; gformat->palette->ncolors; ++g) + { + if((amountNormal->format->palette->colors+g)->b != 132 && + (amountNormal->format->palette->colors+g)->g != 231 && + (amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border + { + (amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f; + (amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f; + (amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f; + } + } + amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); + CSDL_Ext::alphaTransform(amountPositive); + for(int g=0; gformat->palette->ncolors; ++g) + { + if((amountPositive->format->palette->colors+g)->b != 132 && + (amountPositive->format->palette->colors+g)->g != 231 && + (amountPositive->format->palette->colors+g)->r != 255) //it's not yellow border + { + (amountPositive->format->palette->colors+g)->r = (float)((amountPositive->format->palette->colors+g)->r) * 0.18f; + (amountPositive->format->palette->colors+g)->g = (float)((amountPositive->format->palette->colors+g)->g) * 1.00f; + (amountPositive->format->palette->colors+g)->b = (float)((amountPositive->format->palette->colors+g)->b) * 0.18f; + } + } + amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); + CSDL_Ext::alphaTransform(amountNegative); + for(int g=0; gformat->palette->ncolors; ++g) + { + if((amountNegative->format->palette->colors+g)->b != 132 && + (amountNegative->format->palette->colors+g)->g != 231 && + (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border + { + (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f; + (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 0.18f; + (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f; + } + } + amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); + CSDL_Ext::alphaTransform(amountNegative); + for(int g=0; gformat->palette->ncolors; ++g) + { + if((amountNegative->format->palette->colors+g)->b != 132 && + (amountNegative->format->palette->colors+g)->g != 231 && + (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border + { + (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f; + (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 1.00f; + (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f; + } + } + + ////blitting menu background and terrain + blitAt(background, 0, 0); + blitAt(menu, 0, 556); + CSDL_Ext::update(); + + //preparing buttons and console + bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o); + bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s); + bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r); + bAutofight = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a); + bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c); + bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w); + bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d); + bDefence->assignedKeys.insert(SDLK_SPACE); + bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP); + bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN); + bConsoleDown->bitmapOffset = 2; + console = new CBattleConsole(); + console->pos.x = 211; + console->pos.y = 560; + console->pos.w = 406; + console->pos.h = 38; + + //loading hero animations + if(hero1) // attacking hero + { + attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this); + attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0); + } + else + { + attackingHero = NULL; + } + if(hero2) // defending hero + { + defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this); + defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0); + } + else + { + defendingHero = NULL; + } + + //preparing cells and hexes + cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP"); + CSDL_Ext::alphaTransform(cellBorder); + cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP"); + CSDL_Ext::alphaTransform(cellShade); + for(int h=0; hh, cellShade->w, x, y); + bfield[h].accesible = true; + bfield[h].myInterface = this; + } + //locking occupied positions on batlefield + for(std::map::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function + { + bfield[it->second.position].accesible = false; + } + + //loading projectiles for units + for(std::map::iterator g = stacks.begin(); g != stacks.end(); ++g) + { + if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string()) + { + idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]); + + if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images + { + for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k) + { + Cimage ci; + ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap); + ci.groupNumber = 0; + ci.imName = std::string(); + idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci); + } + } + for(int s=0; ssecond.creature->idNumber]->ourImages.size(); ++s) //alpha transforming + { + CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap); + } + } + } + + + //preparing graphic with cell borders + cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder); + //copying palette + for(int g=0; gformat->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256 + { + cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g]; + } + //palette copied + for(int i=0; iw; ++cellX) + { + for(int cellY = 0; cellY < cellBorder->h; ++cellY) + { + if(y+cellY < cellBorders->h && x+cellX < cellBorders->w) + * ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX); + } + } + } + } + + backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen); +} + +CBattleInterface::~CBattleInterface() +{ + SDL_FreeSurface(background); + SDL_FreeSurface(menu); + SDL_FreeSurface(amountNormal); + SDL_FreeSurface(amountNegative); + SDL_FreeSurface(amountPositive); + SDL_FreeSurface(amountEffNeutral); + SDL_FreeSurface(cellBorders); + SDL_FreeSurface(backgroundWithHexes); + delete bOptions; + delete bSurrender; + delete bFlee; + delete bAutofight; + delete bSpell; + delete bWait; + delete bDefence; + delete bConsoleUp; + delete bConsoleDown; + delete console; + delete resWindow; + delete givenCommand; + + delete attackingHero; + delete defendingHero; + + SDL_FreeSurface(cellBorder); + SDL_FreeSurface(cellShade); + + for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g) + delete g->second; + + for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g) + delete g->second; +} + +void CBattleInterface::setPrintCellBorders(bool set) +{ + printCellBorders = set; + redrawBackgroundWithHexes(activeStack); +} + +void CBattleInterface::setPrintStackRange(bool set) +{ + printStackRange = set; + redrawBackgroundWithHexes(activeStack); +} + +void CBattleInterface::setPrintMouseShadow(bool set) +{ + printMouseShadow = set; +} + +void CBattleInterface::activate() +{ + KeyInterested::activate(); + MotionInterested::activate(); + subInt = NULL; + bOptions->activate(); + bSurrender->activate(); + bFlee->activate(); + bAutofight->activate(); + bSpell->activate(); + bWait->activate(); + bDefence->activate(); + bConsoleUp->activate(); + bConsoleDown->activate(); + for(int b=0; bactivate(); + if(defendingHero) + defendingHero->activate(); +} + +void CBattleInterface::deactivate() +{ + KeyInterested::deactivate(); + MotionInterested::deactivate(); + bOptions->deactivate(); + bSurrender->deactivate(); + bFlee->deactivate(); + bAutofight->deactivate(); + bSpell->deactivate(); + bWait->deactivate(); + bDefence->deactivate(); + bConsoleUp->deactivate(); + bConsoleDown->deactivate(); + for(int b=0; bdeactivate(); + if(defendingHero) + defendingHero->deactivate(); +} + +void CBattleInterface::show(SDL_Surface * to) +{ + std::map stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places + ++animCount; + if(!to) //"evaluating" to + to = screen; + + //printing background and hexes + if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range + { + blitAt(backgroundWithHexes, 0, 0, to); + } + else + { + //showing background + blitAt(background, 0, 0, to); + if(printCellBorders) + { + CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL); + } + } + //printing hovered cell + if(printMouseShadow) + { + for(int b=0; bh, cellShade->w, x, y)); + } + } + } + + + //showing menu background and console + blitAt(menu, 0, 556, to); + console->show(to); + + //showing buttons + bOptions->show(to); + bSurrender->show(to); + bFlee->show(to); + bAutofight->show(to); + bSpell->show(to); + bWait->show(to); + bDefence->show(to); + bConsoleUp->show(to); + bConsoleDown->show(to); + + //showing hero animations + if(attackingHero) + attackingHero->show(to); + if(defendingHero) + defendingHero->show(to); + + ////showing units //a lot of work... + std::vector stackAliveByHex[BFIELD_SIZE]; + //double loop because dead stacks should be printed first + for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) + { + if(j->second.alive()) + stackAliveByHex[j->second.position].push_back(j->second.ID); + } + std::vector stackDeadByHex[BFIELD_SIZE]; + for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) + { + if(!j->second.alive()) + stackDeadByHex[j->second.position].push_back(j->second.ID); + } + + attackingShowHelper(); // handle attack animation + + for(int b=0; bnextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died + } + } + for(int b=0; bgetType(); + bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3; + creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died + //printing amount + if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive + { + int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202; + + //blitting amoutn background box + SDL_Surface *amountBG = NULL; + if(stacks[stackAliveByHex[b][v]].effects.size() == 0) + { + amountBG = amountNormal; + } + else + { + int pos=0; //determining total positiveness of effects + for(int c=0; cspellh->spells[ stacks[stackAliveByHex[b][v]].effects[c].id ].positiveness; + } + if(pos > 0) + { + amountBG = amountPositive; + } + else if(pos < 0) + { + amountBG = amountNegative; + } + else + { + amountBG = amountEffNeutral; + } + } + SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260)); + //blitting amount + std::stringstream ss; + ss<pos.x + xAdd + 14, + creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, + GEOR13, + 20, + zwykly, + to + ); + } + } + } + //units shown + projectileShowHelper(to);//showing projectiles + + //showing spell effects + if(battleEffects.size()) + { + std::vector< std::list::iterator > toErase; + for(std::list::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it) + { + blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to); + ++(it->frame); + + if(it->frame == it->maxFrame) { + toErase.push_back(it); + } + } + for(size_t b=0; banim; + battleEffects.erase(toErase[b]); + } + } + + + //showing queue of stacks + if(showStackQueue) + { + int xPos = screen->w/2 - ( stacks.size() * 37 )/2; + int yPos = 10; + + std::vector stacksSorted; + stacksSorted = LOCPLINT->cb->battleGetStackQueue(); + int startFrom = -1; + for(size_t n=0; nsmallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos)); + //printing colored border + for(int xFrom = xPos-1; xFromplayerColors[stacksSorted[b % stacksSorted.size()].owner]; + } + else + { + pc = *graphics->neutralColor; + } + CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b); + } + } + } + //colored border printed + SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos)); + xPos += 37; + } + } + } + + //showing window with result of battle + if(resWindow) + { + resWindow->show(to); + } +} +void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key) +{ + if(key.keysym.sym == SDLK_q) { + showStackQueue = key.state==SDL_PRESSED; + } +} +void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) +{ + if(activeStack>=0 && !spellDestSelectMode) + { + int myNumber = -1; //number of hovered tile + for(int g=0; gcurh->changeGraphic(1, 6); + } + else + { + if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end()) + { + CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber); + if(shere) + { + if(shere->owner == LOCPLINT->playerID) //our stack + CGI->curh->changeGraphic(1,5); + else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy + CGI->curh->changeGraphic(1,3); + else if(isTileAttackable(myNumber)) //available enemy (melee attackable) + { + int fromHex = previouslyHoveredHex; + if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex)) + { + switch(BattleInfo::mutualPosition(fromHex, myNumber)) + { + case 0: + CGI->curh->changeGraphic(1,12); + break; + case 1: + CGI->curh->changeGraphic(1,7); + break; + case 2: + CGI->curh->changeGraphic(1,8); + break; + case 3: + CGI->curh->changeGraphic(1,9); + break; + case 4: + CGI->curh->changeGraphic(1,10); + break; + case 5: + CGI->curh->changeGraphic(1,11); + break; + } + } + } + else //unavailable enemy + CGI->curh->changeGraphic(1,0); + } + else //empty unavailable tile + CGI->curh->changeGraphic(1,0); + } + else //available tile + { + if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying()) + CGI->curh->changeGraphic(1,2); + else + CGI->curh->changeGraphic(1,1); + } + } + } + else if(spellDestSelectMode) + { + int myNumber = -1; //number of hovered tile + for(int g=0; gcurh->changeGraphic(1, 0); + } + else + { + switch(spellSelMode) + { + case 0: + CGI->curh->changeGraphic(3, 0); + break; + case 1: + if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(myNumber)->owner ) + CGI->curh->changeGraphic(3, 0); + else + CGI->curh->changeGraphic(1, 0); + break; + case 2: + if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(myNumber)->owner ) + CGI->curh->changeGraphic(3, 0); + else + CGI->curh->changeGraphic(1, 0); + break; + case 3: + if(LOCPLINT->cb->battleGetStackByPos(myNumber)) + CGI->curh->changeGraphic(3, 0); + else + CGI->curh->changeGraphic(1, 0); + break; + case 4: //TODO: implement this case + break; + } + } + } +} + +bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) +{ + if(creAnims[number]==NULL) + return false; //there is no such creature + creAnims[number]->setType(8); + int firstFrame = creAnims[number]->getFrame(); + for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + creDir[number] = !creDir[number]; + + CStack curs = *LOCPLINT->cb->battleGetStackByID(number); + std::pair coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature); + creAnims[number]->pos.x = coords.first; + //creAnims[number]->pos.y = coords.second; + + if(wideTrick && curs.creature->isDoubleWide()) + { + if(curs.attackerOwned) + { + if(!creDir[number]) + creAnims[number]->pos.x -= 44; + } + else + { + if(creDir[number]) + creAnims[number]->pos.x += 44; + } + } + + creAnims[number]->setType(7); + firstFrame = creAnims[number]->getFrame(); + for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + creAnims[number]->setType(2); + + return true; +} + +void CBattleInterface::bOptionsf() +{ + CGI->curh->changeGraphic(0,0); + deactivate(); + + SDL_Rect temp_rect = genRect(431, 481, 160, 84); + CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this); + optionsWin->activate(); + LOCPLINT->objsToBlit.push_back(optionsWin); +} + +void CBattleInterface::bSurrenderf() +{ +} + +void CBattleInterface::bFleef() +{ + CFunctionList ony = boost::bind(&CBattleInterface::activate,this); + ony += boost::bind(&CBattleInterface::reallyFlee,this); + LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, boost::bind(&CBattleInterface::activate,this), true, false); +} + +void CBattleInterface::reallyFlee() +{ + giveCommand(4,0,0); + CGI->curh->changeGraphic(0, 0); +} + +void CBattleInterface::bAutofightf() +{ +} + +void CBattleInterface::bSpellf() +{ + CGI->curh->changeGraphic(0,0); + deactivate(); + + const CGHeroInstance * chi = NULL; + if(attackingHeroInstance->tempOwner == LOCPLINT->playerID) + chi = attackingHeroInstance; + else + chi = defendingHeroInstance; + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), chi); + spellWindow->activate(); + LOCPLINT->objsToBlit.push_back(spellWindow); +} + +void CBattleInterface::bWaitf() +{ + giveCommand(8,0,activeStack); +} + +void CBattleInterface::bDefencef() +{ + giveCommand(3,0,activeStack); +} + +void CBattleInterface::bConsoleUpf() +{ + console->scrollUp(); +} + +void CBattleInterface::bConsoleDownf() +{ + console->scrollDown(); +} + +void CBattleInterface::newStack(CStack stack) +{ + creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName); + creAnims[stack.ID]->setType(2); + creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner; +} + +void CBattleInterface::stackRemoved(CStack stack) +{ + delete creAnims[stack.ID]; + creAnims.erase(stack.ID); +} + +void CBattleInterface::stackActivated(int number) +{ + //givenCommand = NULL; + activeStack = number; + myTurn = true; + redrawBackgroundWithHexes(number); + bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(number)->state,WAITING)); //block waiting button if stack has been already waiting +} + +void CBattleInterface::stackMoved(int number, int destHex, bool endMoving) +{ + bool startMoving = creAnims[number]->type==20; + //a few useful variables + int curStackPos = LOCPLINT->cb->battleGetPos(number); + int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1; + int hexWbase = 44, hexHbase = 42; + bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide(); + + if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier) + { + CGI->curh->hide(); + for(int i=0; iframesInGroup(20)*getAnimSpeedMultiplier()-1; ++i) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + if((animCount+1)%(4/animSpeed)==0) + creAnims[number]->incrementFrame(); + } + } + + int mutPos = BattleInfo::mutualPosition(curStackPos, destHex); + + { + switch(mutPos) //reverse unit if necessary + { + case 0: case 4: case 5: + if(creDir[number] == true) + reverseCreature(number, curStackPos, twoTiles); + break; + case 1: case 2: case 3: + if(creDir[number] == false) + reverseCreature(number, curStackPos, twoTiles); + break; + } + //moving instructions + creAnims[number]->setType(0); + float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;] + for(int i=0; ipos.x = posX; + posY -= ((float)hexHbase)/((float)steps); + creAnims[number]->pos.y = posY; + break; + case 1: + posX += ((float)hexWbase)/(2.0f*steps); + creAnims[number]->pos.x = posX; + posY -= ((float)hexHbase)/((float)steps); + creAnims[number]->pos.y = posY; + break; + case 2: + posX += ((float)hexWbase)/((float)steps); + creAnims[number]->pos.x = posX; + break; + case 3: + posX += ((float)hexWbase)/(2.0f*steps); + creAnims[number]->pos.x = posX; + posY += ((float)hexHbase)/((float)steps); + creAnims[number]->pos.y = posY; + break; + case 4: + posX -= ((float)hexWbase)/(2.0f*steps); + creAnims[number]->pos.x = posX; + posY += ((float)hexHbase)/((float)steps); + creAnims[number]->pos.y = posY; + break; + case 5: + posX -= ((float)hexWbase)/((float)steps); + creAnims[number]->pos.x = posX; + break; + } + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + if((animCount+1)%(4/animSpeed)==0) + creAnims[number]->incrementFrame(); + } + } + + if(endMoving) //animation of ending move + { + if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier) + { + creAnims[number]->setType(21); + for(int i=0; iframesInGroup(21)*getAnimSpeedMultiplier()-1; ++i) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + if((animCount+1)%(4/animSpeed)==0) + creAnims[number]->incrementFrame(); + } + } + creAnims[number]->setType(2); //resetting to default + CGI->curh->show(); + } + + CStack curs = *LOCPLINT->cb->battleGetStackByID(number); + if(endMoving) //resetting to default + { + if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner)) + reverseCreature(number, destHex, twoTiles); + } + std::pair coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature); + creAnims[number]->pos.x = coords.first; + if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed + creAnims[number]->pos.x -= 44; + creAnims[number]->pos.y = coords.second; +} + +void CBattleInterface::stacksAreAttacked(std::vector attackedInfos) +{ + //restoring default state of battleWindow by calling show func + while(true) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + + //checking break conditions + bool break_loop = true; + for(size_t g=0; ggetType() != 2) { + break_loop = false; + } + if(attackingInfo && attackingInfo->IDby == attackedInfos[g].IDby) { + break_loop = false; + } + } + if(break_loop) break; + } + if(attackedInfos.size() == 1 && attackedInfos[0].byShooting) //delay hit animation + { + CStack attacker = *LOCPLINT->cb->battleGetStackByID(attackedInfos[0].IDby); + while(true) + { + bool found = false; + for(std::list::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it) + { + if(it->creID == attacker.creature->idNumber) + { + found = true; + break; + } + } + if(!found) + break; + else + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + } + } + //initializing + std::map animLengths; + std::map increments; + int maxLen = 0; + for(size_t g=0; gsetType(5); //death + animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5); + } + else + { + creAnims[attackedInfos[g].ID]->setType(3); //getting hit + animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3); + } + animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen)); + increments.insert(std::make_pair(attackedInfos[g].ID, 0)); + if(animLen > maxLen) + { + maxLen = animLen; + } + } + //main showing loop + bool continueLoop = true; + while(continueLoop) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + for(size_t g=0; gincrementFrame(); + ++(increments[attackedInfos[g].ID]); + } + if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3) + creAnims[attackedInfos[g].ID]->setType(2); + } + bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued + for(size_t g=0; ggetType() == 3) + creAnims[attackedInfos[g].ID]->setType(2); + } + + //printing info to console + for(size_t g=0; ggetType()!=2) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack + int reversedShift = 0; //shift of attacking stack's position due to reversing + if(aStack.attackerOwned) + { + if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + reverseCreature(ID, aStack.position, true); + break; + case -1: + if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest + { + reverseCreature(ID, aStack.position, true); + reversedShift = (aStack.attackerOwned ? -1 : 1); + } + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + reverseCreature(ID, aStack.position, true); + break; + case 5: + reverseCreature(ID, aStack.position, true); + break; + } + } + } + else //if(aStack.attackerOwned) + { + if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + reverseCreature(ID, aStack.position, true); + break; + case 3: + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + //reverseCreature(ID, aStack.position, true); + break; + case -1: + if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest + { + reverseCreature(ID, aStack.position, true); + reversedShift = (aStack.attackerOwned ? -1 : 1); + } + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + reverseCreature(ID, aStack.position, true); + break; + case 2: + reverseCreature(ID, aStack.position, true); + break; + case 3: + reverseCreature(ID, aStack.position, true); + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + //reverseCreature(ID, aStack.position, true); + break; + } + } + } + + attackingInfo = new CAttHelper; + attackingInfo->dest = dest; + attackingInfo->frame = 0; + attackingInfo->hitCount = 0; + attackingInfo->ID = ID; + attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID; + attackingInfo->reversing = false; + attackingInfo->posShiftDueToDist = reversedShift; + attackingInfo->shooting = false; + + switch(BattleInfo::mutualPosition(aStack.position + reversedShift, dest)) //attack direction + { + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(13); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(13); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + default: + tlog1<<"Critical Error! Wrong dest in stackAttacking!"<addText(CGI->generaltexth->allTexts[412]); +} + +void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional) +{ + BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack() + ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; + ba->actionType = action; + ba->destinationTile = tile; + ba->stackNumber = stack; + ba->additionalInfo = additional; + givenCommand->setn(ba); + myTurn = false; + activeStack = -1; +} + +bool CBattleInterface::isTileAttackable(const int & number) const +{ + for(size_t b=0; bcb->battleGetStackByPos(whichOne) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne)->owner ) + allowCasting = false; + break; + case 2: + if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne)->owner ) + allowCasting = false; + break; + case 3: + if(!LOCPLINT->cb->battleGetStackByPos(whichOne)) + allowCasting = false; + break; + case 4: //TODO: implement this case + break; + } + //destination checked + if(allowCasting) + { + spellToCast->destinationTile = whichOne; + LOCPLINT->cb->battleMakeAction(spellToCast); + delete spellToCast; + spellToCast = NULL; + spellDestSelectMode = false; + CGI->curh->changeGraphic(1, 6); + } + } + else + { + CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one + if(!dest || !dest->alive()) //no creature at that tile + { + if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range + { + CGI->curh->changeGraphic(1, 6); //cursor should be changed + giveCommand(2,whichOne,activeStack); + } + } + else if(dest->owner != attackingHeroInstance->tempOwner + && LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting + { + CGI->curh->changeGraphic(1, 6); //cursor should be changed + giveCommand(7,whichOne,activeStack); + } + else if(dest->owner != attackingHeroInstance->tempOwner) //attacking + { + switch(CGI->curh->number) + { + case 12: + giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne); + break; + case 7: + giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne); + break; + case 8: + giveCommand(6,whichOne - 1,activeStack,whichOne); + break; + case 9: + giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne); + break; + case 10: + giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne); + break; + case 11: + giveCommand(6,whichOne + 1,activeStack,whichOne); + break; + } + CGI->curh->changeGraphic(1, 6); //cursor should be changed + } + } + } +} + +void CBattleInterface::stackIsShooting(int ID, int dest) +{ + if(attackingInfo != NULL) + { + return; //something went wrong + } + //projectile + float projectileAngle; //in radians; if positive, projectiles goes up + float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) + int fromHex = LOCPLINT->cb->battleGetPos(ID); + projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17)); + if(fromHex < dest) + projectileAngle = -projectileAngle; + + SProjectileInfo spi; + spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber; + + spi.step = 0; + spi.frameNum = 0; + spi.spin = CGI->creh->idToProjectileSpin[spi.creID]; + + std::pair xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID)); + std::pair destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID)); + destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot + + if(projectileAngle > straightAngle) //upper shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX; + spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY; + } + else if(projectileAngle < -straightAngle) //lower shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX; + spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY; + } + else //straight shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX; + spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY; + } + spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40; + if(spi.lastStep == 0) + spi.lastStep = 1; + spi.dx = (destcoord.first - spi.x) / spi.lastStep; + spi.dy = (destcoord.second - spi.y) / spi.lastStep; + //set starting frame + if(spi.spin) + { + spi.frameNum = 0; + } + else + { + spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1); + } + //set delay + spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame; + projectiles.push_back(spi); + + //attack aniamtion + attackingInfo = new CAttHelper; + attackingInfo->dest = dest; + attackingInfo->frame = 0; + attackingInfo->hitCount = 0; + attackingInfo->ID = ID; + attackingInfo->reversing = false; + attackingInfo->posShiftDueToDist = 0; + attackingInfo->shooting = true; + if(projectileAngle > straightAngle) //upper shot + attackingInfo->shootingGroup = 14; + else if(projectileAngle < -straightAngle) //lower shot + attackingInfo->shootingGroup = 16; + else //straight shot + attackingInfo->shootingGroup = 15; + attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup); +} + +void CBattleInterface::battleFinished(const BattleResult& br) +{ + deactivate(); + CGI->curh->changeGraphic(0,0); + + SDL_Rect temp_rect = genRect(561, 470, 165, 19); + resWindow = new CBattleReslutWindow(br, temp_rect, this); + resWindow->activate(); +} + +void CBattleInterface::spellCasted(SpellCasted * sc) +{ + std::vector< std::string > anims; //for magic arrow and ice bolt + switch(sc->id) + { + case 15: //magic arrow + { + //initialization of anims + anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF"); + } + case 16: //ice bolt + { + if(anims.size() == 0) //initialiaztion of anims + { + anims.push_back("C08SPW0.DEF"); anims.push_back("C08SPW1.DEF"); anims.push_back("C08SPW2.DEF"); anims.push_back("C08SPW3.DEF"); anims.push_back("C08SPW4.DEF"); + } + } //end of ice bolt only part + { //common ice bolt and magic arrow part + //initial variables + std::string animToDisplay; + std::pair srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60); + std::pair destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow + destcoord.first += 250; destcoord.second += 240; + + //animation angle + float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second)); + + //choosing animation by angle + if(angle > 1.50) + animToDisplay = anims[0]; + else if(angle > 1.20) + animToDisplay = anims[1]; + else if(angle > 0.90) + animToDisplay = anims[2]; + else if(angle > 0.60) + animToDisplay = anims[3]; + else + animToDisplay = anims[4]; + + //displaying animation + int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40; + if(steps <= 0) + steps = 1; + + CDefHandler * animDef = CDefHandler::giveDef(animToDisplay); + + int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps; + + for(int g=0; gourImages[g%animDef->ourImages.size()].bitmap->clip_rect; + SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy); + SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + + int b=0; //TODO use me + break; //for 15 and 16 cases + } + case 17: //lightning bolt + { + displayEffect(1, sc->tile); + break; + } + case 18: //implosion + { + displayEffect(10, sc->tile); + break; + } + case 27: //shield + { + displayEffect(27, sc->tile); + break; + } + case 28: //air shield + { + displayEffect(2, sc->tile); + break; + } + case 41: //bless + { + displayEffect(36, sc->tile); + break; + } + case 42: //curse + { + displayEffect(40, sc->tile); + break; + } + case 43: //bloodlust + { + displayEffect(4, sc->tile); //TODO: give better animation for this spell + break; + } + case 45: //weakness + { + displayEffect(56, sc->tile); //TODO: give better animation for this spell + break; + } + case 46: //stone skin + { + displayEffect(54, sc->tile); + break; + } + case 48: //prayer + { + displayEffect(0, sc->tile); + break; + } + case 53: //haste + { + displayEffect(31, sc->tile); + break; + } + case 54: //slow + { + displayEffect(19, sc->tile); + break; + } + case 56: //frenzy + { + displayEffect(17, sc->tile); + break; + } + case 61: //forgetfulness + { + displayEffect(42, sc->tile); + break; + } + } +} + +void CBattleInterface::castThisSpell(int spellID) +{ + BattleAction * ba = new BattleAction; + ba->actionType = 1; + ba->additionalInfo = spellID; //spell number + ba->destinationTile = -1; + ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2; + ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; + spellToCast = ba; + spellDestSelectMode = true; + + //choosing possible tragets + const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance; + spellSelMode = 0; + if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos) + { + switch(CGI->spellh->spells[spellID].positiveness) + { + case -1 : + spellSelMode = 2; + break; + case 0: + spellSelMode = 3; + break; + case 1: + spellSelMode = 1; + break; + } + } + if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos) + { + if(castingHero && castingHero->getSpellSecLevel(spellID) < 3) + { + switch(CGI->spellh->spells[spellID].positiveness) + { + case -1 : + spellSelMode = 2; + break; + case 0: + spellSelMode = 3; + break; + case 1: + spellSelMode = 1; + break; + } + } + else + { + spellSelMode = -1; + } + } + CGI->curh->changeGraphic(3, 0); +} + +void CBattleInterface::displayEffect(ui32 effect, int destTile) +{ + if(graphics->battleACToDef[effect].size() != 0) + { + SBattleEffect be; + be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]); + be.frame = 0; + be.maxFrame = be.anim->ourImages.size(); + be.x = 22 * ( ((destTile/BFIELD_WIDTH) + 1)%2 ) + 44 * (destTile % BFIELD_WIDTH) + 45; + be.y = 105 + 42 * (destTile/BFIELD_WIDTH); + + if(effect != 1 && effect != 0) + { + be.x -= be.anim->ourImages[0].bitmap->w/2; + be.y -= be.anim->ourImages[0].bitmap->h/2; + } + else if(effect == 1) + { + be.x -= be.anim->ourImages[0].bitmap->w; + be.y -= be.anim->ourImages[0].bitmap->h; + } + else if (effect == 0) + { + be.x -= be.anim->ourImages[0].bitmap->w/2; + be.y -= be.anim->ourImages[0].bitmap->h; + } + + battleEffects.push_back(be); + } + //battleEffects +} + +void CBattleInterface::setAnimSpeed(int set) +{ + animSpeed = set; +} + +int CBattleInterface::getAnimSpeed() const +{ + return animSpeed; +} + +float CBattleInterface::getAnimSpeedMultiplier() const +{ + switch(animSpeed) + { + case 1: + return 3.5f; + case 2: + return 2.2f; + case 4: + return 1.0f; + default: + return 0.0f; + } +} + +void CBattleInterface::attackingShowHelper() +{ + if(attackingInfo && !attackingInfo->reversing) + { + if(attackingInfo->frame == 0) + { + CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(attackingInfo->shooting) + { + creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup); + } + else + { + if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position+attackingInfo->posShiftDueToDist, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(11); + break; + case 1: + creAnims[attackingInfo->ID]->setType(11); + break; + case 2: + creAnims[attackingInfo->ID]->setType(12); + break; + case 3: + creAnims[attackingInfo->ID]->setType(13); + break; + case 4: + creAnims[attackingInfo->ID]->setType(13); + break; + case 5: + creAnims[attackingInfo->ID]->setType(12); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(11); + break; + case 1: + creAnims[attackingInfo->ID]->setType(11); + break; + case 2: + creAnims[attackingInfo->ID]->setType(12); + break; + case 3: + creAnims[attackingInfo->ID]->setType(13); + break; + case 4: + creAnims[attackingInfo->ID]->setType(13); + break; + case 5: + creAnims[attackingInfo->ID]->setType(12); + break; + } + } + } + } + else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) + { + attackingInfo->reversing = true; + + CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(aStackp == NULL) + return; + CStack aStack = *aStackp; + if(aStack.attackerOwned) + { + if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case -1: + if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest + { + reverseCreature(attackingInfo->ID, aStack.position, true); + } + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 5: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + } + } + } + else //if(aStack.attackerOwned) + { + if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 3: + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + //reverseCreature(ID, aStack.position, true); + break; + case -1: + if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest + { + reverseCreature(attackingInfo->ID, aStack.position, true); + } + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 2: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 3: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + //reverseCreature(ID, aStack.position, true); + break; + } + } + } + attackingInfo->reversing = false; + creAnims[attackingInfo->ID]->setType(2); + delete attackingInfo; + attackingInfo = NULL; + } + if(attackingInfo) + { + attackingInfo->hitCount++; + if(attackingInfo->hitCount%(4/animSpeed) == 0) + attackingInfo->frame++; + } + } +} + +void CBattleInterface::redrawBackgroundWithHexes(int activeStack) +{ + shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack); + + //preparating background graphic with hexes and shaded hexes + blitAt(background, 0, 0, backgroundWithHexes); + if(printCellBorders) + CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL); + + if(printStackRange) + { + for(size_t m=0; mh, cellShade->w, x, y)); + } + } +} + +void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby) +{ + char tabh[200]; + CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby); + CStack defender = *LOCPLINT->cb->battleGetStackByID(ID); + int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(), + (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()), + dmg); + if(killed > 0) + { + if(killed > 1) + { + sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str()); + } + else //killed == 1 + { + sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str()); + } + } + + console->addText(std::string(tabh)); +} + +void CBattleInterface::projectileShowHelper(SDL_Surface * to) +{ + if(to == NULL) + to = screen; + std::list< std::list::iterator > toBeDeleted; + for(std::list::iterator it=projectiles.begin(); it!=projectiles.end(); ++it) + { + if(it->animStartDelay>0) + { + --(it->animStartDelay); + continue; + } + SDL_Rect dst; + dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h; + dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w; + dst.x = it->x; + dst.y = it->y; + CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst); + //actualizing projectile + ++it->step; + if(it->step == it->lastStep) + { + toBeDeleted.insert(toBeDeleted.end(), it); + } + else + { + it->x += it->dx; + it->y += it->dy; + if(it->spin) + { + ++(it->frameNum); + it->frameNum %= idToProjectile[it->creID]->ourImages.size(); + } + } + } + for(std::list< std::list::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it) + { + projectiles.erase(*it); + } +} + +void CBattleHero::show(SDL_Surface *to) +{ + //animation of flag + if(flip) + { + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + 752, + 39 + ) + ); + } + else + { + CSDL_Ext::blit8bppAlphaTo24bpp( + flag->ourImages[flagAnim].bitmap, + NULL, + screen, + &genRect( + flag->ourImages[flagAnim].bitmap->h, + flag->ourImages[flagAnim].bitmap->w, + 31, + 39 + ) + ); + } + ++flagAnimCount; + if(flagAnimCount%4==0) + { + ++flagAnim; + flagAnim %= flag->ourImages.size(); + } + //animation of hero + int tick=-1; + for(int i=0; iourImages.size(); ++i) + { + if(dh->ourImages[i].groupNumber==phase) + ++tick; + if(tick==image) + { + SDL_Rect posb = pos; + CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); + ++image; + if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame + { + image = 0; + } + break; + } + } +} + +void CBattleHero::activate() +{ + ClickableL::activate(); +} +void CBattleHero::deactivate() +{ + ClickableL::deactivate(); +} + +void CBattleHero::setPhase(int newPhase) +{ + phase = newPhase; + image = 0; +} + +void CBattleHero::clickLeft(boost::logic::tribool down) +{ + if(!down && myHero) + { + for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) + return; + } + CGI->curh->changeGraphic(0,0); + LOCPLINT->curint->deactivate(); + + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero); + spellWindow->activate(); + LOCPLINT->objsToBlit.push_back(spellWindow); + } +} + +CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero), myOwner(owner) +{ + dh = CDefHandler::giveDef( defName ); + for(int i=0; iourImages.size(); ++i) //transforming images + { + if(flip) + { + SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); + SDL_FreeSurface(dh->ourImages[i].bitmap); + dh->ourImages[i].bitmap = hlp; + } + dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); + } + dh->alphaTransformed = true; + + if(flip) + flag = CDefHandler::giveDef("CMFLAGR.DEF"); + else + flag = CDefHandler::giveDef("CMFLAGL.DEF"); + + //coloring flag and adding transparency + for(int i=0; iourImages.size(); ++i) + { + flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); + graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); + } +} + +CBattleHero::~CBattleHero() +{ + delete dh; + delete flag; +} + +std::pair CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature) +{ + std::pair ret = std::make_pair(-500, -500); //returned value + ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y + //counting x + if(attacker) + { + ret.first = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); + } + else + { + ret.first = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH); + } + //shifting position for double - hex creatures + if(creature && creature->isDoubleWide()) + { + if(attacker) + { + ret.first -= 42; + } + else + { + ret.first += 42; + } + } + //returning + return ret; +} +void CBattleHex::activate() +{ + Hoverable::activate(); + MotionInterested::activate(); + ClickableL::activate(); + ClickableR::activate(); +} + +void CBattleHex::deactivate() +{ + Hoverable::deactivate(); + MotionInterested::deactivate(); + ClickableL::deactivate(); + ClickableR::deactivate(); +} + +void CBattleHex::hover(bool on) +{ + hovered = on; + Hoverable::hover(on); + if(!on && setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false) +{ +} + +void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) +{ + if(myInterface->cellShade) + { + if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex + { + strictHovered = false; + } + else //hovered pixel is inside hex + { + strictHovered = true; + } + } + + if(hovered && strictHovered) //print attacked creature to console + { + if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && + LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID && + LOCPLINT->cb->battleGetStackByPos(myNumber)->alive()) + { + char tabh[160]; + CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber); + const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; + sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); + myInterface->console->alterTxt = std::string(tabh); + setAlterText = true; + } + } + else if(setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } +} + +void CBattleHex::clickLeft(boost::logic::tribool down) +{ + if(!down && hovered && strictHovered) //we've been really clicked! + { + myInterface->hexLclicked(myNumber); + } +} + +void CBattleHex::clickRight(boost::logic::tribool down) +{ + int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile + if(hovered && strictHovered && stID!=-1) + { + CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info + if(!myst.alive()) return; + StackState *pom = NULL; + if(down) + { + pom = new StackState(); + const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance; + if(h) + { + pom->attackBonus = h->getPrimSkillLevel(0); + pom->defenseBonus = h->getPrimSkillLevel(1); + pom->luck = h->getCurrentLuck(); + pom->morale = h->getCurrentMorale(); + pom->shotsLeft = myst.shots; + for(int vb=0; vbeffects.insert(myst.effects[vb].id); + } + } + pom->currentHealth = myst.firstHPleft; + (new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function(),boost::function(),NULL)) + ->activate(); + } + delete pom; + } +} + +CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("") +{ +} + +CBattleConsole::~CBattleConsole() +{ + texts.clear(); +} + +void CBattleConsole::show(SDL_Surface * to) +{ + if(alterTxt.size()) + { + CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); + } + else if(texts.size()) + { + if(texts.size()==1) + { + CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); + } + else + { + CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); + CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to); + } + } +} + +bool CBattleConsole::addText(const std::string & text) +{ + if(text.size()>70) + return false; //text too long! + int firstInToken = 0; + for(int i=0; i= texts.size()) //no such pos + return; + texts[pos] = text; +} + +void CBattleConsole::scrollUp(unsigned int by) +{ + if(lastShown > by) + lastShown -= by; +} + +void CBattleConsole::scrollDown(unsigned int by) +{ + if(lastShown + by < texts.size()) + lastShown += by; +} + +CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner) +{ + this->pos = pos; + background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); + graphics->blueToPlayersAdv(background, LOCPLINT->playerID); + SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); + SDL_FreeSurface(background); + background = pom; + exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN); + + if(br.winner==0) //attacker won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background); + } + else //if(br.winner==1) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background); + } + + + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background); + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background); + + std::string attackerName, defenderName; + + if(owner->attackingHeroInstance) //a hero attacked + { + SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38)); + //setting attackerName + attackerName = owner->attackingHeroInstance->name; + } + else //a monster attacked + { + int bestMonsterID = -1; + int bestPower = 0; + for(std::map >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it) + { + if( CGI->creh->creatures[it->first].AIValue > bestPower) + { + bestPower = CGI->creh->creatures[it->first].AIValue; + bestMonsterID = it->first; + } + } + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38)); + //setting attackerName + attackerName = CGI->creh->creatures[bestMonsterID].namePl; + } + if(owner->defendingHeroInstance) //a hero defended + { + SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38)); + //setting defenderName + defenderName = owner->defendingHeroInstance->name; + } + else //a monster defended + { + int bestMonsterID = -1; + int bestPower = 0; + for(std::map >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it) + { + if( CGI->creh->creatures[it->second.first].AIValue > bestPower) + { + bestPower = CGI->creh->creatures[it->second.first].AIValue; + bestMonsterID = it->second.first; + } + } + SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38)); + //setting defenderName + defenderName = CGI->creh->creatures[bestMonsterID].namePl; + } + + //printing attacker and defender's names + CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background); + CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background); + //printing casualities + for(int step = 0; step < 2; ++step) + { + if(br.casualties[step].size()==0) + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background); + } + else + { + int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture + int yPos = 344 + step*97; + for(std::set >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) + { + blitAt(graphics->smallImgs[it->first], xPos, yPos, background); + std::stringstream amount; + amount<second; + CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background); + xPos += 42; + } + } + } + //printing result description + bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner); + switch(br.result) + { + case 0: //normal victory + if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background); + } + else + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background); + } + break; + case 1: //flee + if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background); + } + else + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background); + } + break; + case 2: //surrender + if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background); + } + else + { + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background); + } + break; + } +} + +CBattleReslutWindow::~CBattleReslutWindow() +{ + SDL_FreeSurface(background); +} + +void CBattleReslutWindow::activate() +{ + LOCPLINT->showingDialog->set(true); + exit->activate(); +} + +void CBattleReslutWindow::deactivate() +{ + exit->deactivate(); +} + +void CBattleReslutWindow::show(SDL_Surface *to) +{ + //evaluating to + if(!to) + to = screen; + + SDL_BlitSurface(background, NULL, to, &pos); + exit->show(to); +} + +void CBattleReslutWindow::bExitf() +{ + LOCPLINT->battleResultQuited(); +} + +CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner) +{ + pos = position; + background = BitmapHandler::loadBitmap("comopbck.bmp", true); + graphics->blueToPlayersAdv(background, LOCPLINT->playerID); + + viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false); + viewGrid->select(owner->printCellBorders); + movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false); + movementShadow->select(owner->printStackRange); + mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false); + mouseShadow->select(owner->printMouseShadow); + + animSpeeds = new CHighlightableButtonsGroup(0); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def",252, 309, 2); + animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",315, 309, 4); + animSpeeds->select(owner->getAnimSpeed(), 1); + animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1); + + setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[392].first, CGI->generaltexth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def"); + std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]); + exit = new AdventureMapButton (CGI->generaltexth->zelp[393].first, CGI->generaltexth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN); + std::swap(exit->imgs[0][0], exit->imgs[0][1]); + + //printing texts to background + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options + CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info + + //auto - combat options + CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures + CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells + CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult + CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista + CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent + + //creature info + CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats + CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only + + //general options + CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid + CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow + CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow + CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation + //texts printed +} + +CBattleOptionsWindow::~CBattleOptionsWindow() +{ + SDL_FreeSurface(background); + + delete setToDefault; + delete exit; + + delete viewGrid; + delete movementShadow; + delete animSpeeds; + delete mouseShadow; +} + +void CBattleOptionsWindow::activate() +{ + setToDefault->activate(); + exit->activate(); + viewGrid->activate(); + movementShadow->activate(); + animSpeeds->activate(); + mouseShadow->activate(); +} + +void CBattleOptionsWindow::deactivate() +{ + setToDefault->deactivate(); + exit->deactivate(); + viewGrid->deactivate(); + movementShadow->deactivate(); + animSpeeds->deactivate(); + mouseShadow->deactivate(); +} + +void CBattleOptionsWindow::show(SDL_Surface *to) +{ + if(!to) //"evaluating" to + to = screen; + + SDL_BlitSurface(background, NULL, to, &pos); + + setToDefault->show(to); + exit->show(to); + viewGrid->show(to); + movementShadow->show(to); + animSpeeds->show(to); + mouseShadow->show(to); +} + +void CBattleOptionsWindow::bDefaultf() +{ +} + +void CBattleOptionsWindow::bExitf() +{ + deactivate(); + + for(size_t g=0; gobjsToBlit.size(); ++g) + { + if(dynamic_cast(LOCPLINT->objsToBlit[g])) + { + LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g); + break; + } + } + + delete this; + LOCPLINT->curint->activate(); +} diff --git a/CBattleInterface.h b/CBattleInterface.h index 974c218f4..66ef37e4f 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -1,4 +1,11 @@ +#ifndef CBATTLEINTERFACE_H +#define CBATTLEINTERFACE_H + +#ifdef _MSC_VER #pragma once +#endif + + #include "global.h" #include "CPlayerInterface.h" #include @@ -251,3 +258,4 @@ public: friend class CBattleReslutWindow; friend class CPlayerInterface; }; +#endif //CBATTLEINTERFACE_H \ No newline at end of file diff --git a/CCallback.cpp b/CCallback.cpp index 8581343cb..4d4ab37cc 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -61,7 +61,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) } else if (idtype==1 && player>=0) //looking for it in local area { - for (int i=0; iplayers[player].heroes.size();i++) + for (size_t i=0; i < gs->players[player].heroes.size(); ++i) { if (gs->players[player].heroes[i]->type->ID == ID) hero = gs->players[player].heroes[i]; @@ -72,7 +72,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) for(std::map::iterator j=gs->players.begin(); j!=gs->players.end(); ++j) { - for (int i=0; i<(*j).second.heroes.size();i++) + for (size_t i=0; i < (*j).second.heroes.size(); ++i) { if ((*j).second.heroes[i]->type->ID == ID) { @@ -193,19 +193,23 @@ int CCallback::howManyHeroes() const } const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID { - boost::shared_lock lock(*gs->mx); + boost::shared_lock lock(*gs->mx); //TODO use me? //if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info // return NULL; if (!mode) //esrial id - if(valplayers[player].heroes.size()) + if(valplayers[player].heroes.size()) { return gs->players[player].heroes[val]; - else return NULL; + } + else { + return NULL; + } else if(mode==1) //it's hero type id { - for (int i=0; iplayers[player].heroes.size();i++) + for (size_t i=0; i < gs->players[player].heroes.size(); ++i) { - if (gs->players[player].heroes[i]->type->ID==val) + if (gs->players[player].heroes[i]->type->ID==val) { return gs->players[player].heroes[i]; + } } } else //object id @@ -242,7 +246,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) const } bool CCallback::verifyPath(CPath * path, bool blockSea) const { - for (int i=0;inodes.size();i++) + for (size_t i=0; i < path->nodes.size(); ++i) { if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked && (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable))) @@ -292,7 +296,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) cons std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>(); for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { - for (int j=0;j<(*i).second.towns.size();j++) + for (size_t j=0; j < (*i).second.towns.size(); ++j) { if ( ( isVisible((*i).second.towns[j],player) ) || (*i).first==player) { @@ -306,7 +310,7 @@ std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) con { boost::shared_lock lock(*gs->mx); std::vector < const CGHeroInstance *> ret; - for(int i=0;imap->heroes.size();i++) + for(size_t i=0;imap->heroes.size();i++) { if( (gs->map->heroes[i]->tempOwner==player) || (isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) ) @@ -346,7 +350,7 @@ int CCallback::getMyColor() const int CCallback::getHeroSerial(const CGHeroInstance * hero) const { boost::shared_lock lock(*gs->mx); - for (int i=0; iplayers[player].heroes.size();i++) + for (size_t i=0; iplayers[player].heroes.size();i++) { if (gs->players[player].heroes[i]==hero) return i; @@ -467,7 +471,7 @@ CStack* CCallback::battleGetStackByPos(int pos) int CCallback::battleGetPos(int stack) { boost::shared_lock lock(*gs->mx); - for(int g=0; gcurB->stacks.size(); ++g) + for(size_t g=0; gcurB->stacks.size(); ++g) { if(gs->curB->stacks[g]->ID == stack) return gs->curB->stacks[g]->position; @@ -484,7 +488,7 @@ std::map CCallback::battleGetStacks() return ret; } - for(int g=0; gcurB->stacks.size(); ++g) + for(size_t g=0; gcurB->stacks.size(); ++g) { ret[gs->curB->stacks[g]->ID] = *(gs->curB->stacks[g]); } @@ -498,8 +502,8 @@ std::vector CCallback::battleGetStackQueue() CCreature CCallback::battleGetCreature(int number) { - boost::shared_lock lock(*gs->mx); - for(int h=0; hcurB->stacks.size(); ++h) + boost::shared_lock lock(*gs->mx); //TODO use me? + for(size_t h=0; hcurB->stacks.size(); ++h) { if(gs->curB->stacks[h]->ID == number) //creature found return *(gs->curB->stacks[h]->creature); @@ -520,8 +524,8 @@ std::vector CCallback::battleGetAvailableHexes(int ID) bool CCallback::battleIsStackMine(int ID) { - boost::shared_lock lock(*gs->mx); - for(int h=0; hcurB->stacks.size(); ++h) + boost::shared_lock lock(*gs->mx); //TODO use me ? + for(size_t h=0; hcurB->stacks.size(); ++h) { if(gs->curB->stacks[h]->ID == ID) //creature found return gs->curB->stacks[h]->owner == player; @@ -530,11 +534,11 @@ bool CCallback::battleIsStackMine(int ID) } bool CCallback::battleCanShoot(int ID, int dest) { - boost::shared_lock lock(*gs->mx); + boost::shared_lock lock(*gs->mx); //TODO use me? CStack *our = battleGetStackByID(ID), *dst = battleGetStackByPos(dest); if(!our || !dst) return false; - for(int g=0; geffects.size(); ++g) + for(size_t g=0; geffects.size(); ++g) { if(61 == our->effects[g].id) //forgetfulness return false; @@ -611,7 +615,7 @@ std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos std::vector < const CGObjectInstance * > ret; std::vector < std::pair > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects; - for(int b=0; btempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1)) ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first); diff --git a/CCallback.h b/CCallback.h index 111cd1671..b4ee1e5f0 100644 --- a/CCallback.h +++ b/CCallback.h @@ -5,7 +5,9 @@ #ifdef _WIN32 #include "tchar.h" #else -#include "tchar_amigaos4.h" +#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true' +//support of unicode we should use ICU or some boost wraper areound it +//(boost using this lib during compilation i dont know what for exactly) #endif #include "CGameState.h" @@ -101,7 +103,7 @@ struct HeroMoveDetails class CCallback : public ICallback { private: - CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){}; + CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){}; CGameState * gs; CClient *cl; bool isVisible(int3 pos, int Player) const; @@ -175,7 +177,7 @@ public: bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest - +//XXX hmmm _tmain on _GNUC_ wtf? //friends friend class CClient; #ifndef __GNUC__ diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 0706be0e9..3ee7082dd 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -27,7 +27,7 @@ using namespace CSDL_Ext; extern TTF_Font * GEOR16; CBuildingRect::CBuildingRect(Structure *Str) -:str(Str), moi(false), offset(0) +:moi(false), offset(0), str(Str) { def = CDefHandler::giveDef(Str->defName); max = def->ourImages.size(); @@ -49,14 +49,18 @@ CBuildingRect::CBuildingRect(Structure *Str) area = border = NULL; return; } - if (border = BitmapHandler::loadBitmap(str->borderName)) + if (border = BitmapHandler::loadBitmap(str->borderName)) {//FIXME hmmm if '=' use () else '==' fatal mistake SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255)); - else + } + else { tlog2 << "Warning: no border for "<ID<areaName)) + } + if (area = BitmapHandler::loadBitmap(str->areaName)) { //FIXME look up ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255)); - else + } + else { tlog2 << "Warning: no area for "<ID<max - buildings[i]->offset)) + buildings[i]->offset; if(frame) @@ -706,8 +710,9 @@ void CCastleInterface::activate() LOCPLINT->statusbar = statusbar; exit->activate(); split->activate(); - for(int i=0;iactivate(); + } hslotdown.activate(); hslotup.activate(); showAll(0,true); @@ -724,8 +729,9 @@ void CCastleInterface::deactivate() garr->deactivate(); exit->deactivate(); split->deactivate(); - for(int i=0;ideactivate(); + } hslotdown.deactivate(); hslotup.deactivate(); } @@ -746,7 +752,7 @@ void CCastleInterface::removeBuilding(int bid) void CCastleInterface::recreateBuildings() { - for(int i=0;ideactivate(); @@ -784,14 +790,14 @@ void CCastleInterface::recreateBuildings() { if((*(CGI->townh->structures[town->subID][obecny->second])) < (*(CGI->townh->structures[town->subID][st->ID]))) //we have to replace old building with current one { - for(int itpb = 0; itpbstr->ID == obecny->second) { delete buildings[itpb]; buildings.erase(buildings.begin() + itpb); #ifndef __GNUC__ - obecny->second = st->ID; + obecny->second = st->ID; //XXX look closer! #else *(const_cast(&(obecny->second))) = st->ID; #endif @@ -818,7 +824,7 @@ void CCastleInterface::recreateBuildings() if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end())) { CBuildingRect *vortex = NULL; - for(int i=0;istr->ID==21) { @@ -841,7 +847,7 @@ void CCastleInterface::recreateBuildings() else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end())) { CBuildingRect *shipyard = NULL; - for(int i=0;istr->ID==6) { @@ -995,11 +1001,11 @@ CHallInterface::CHallInterface(CCastleInterface * owner) //preparing boxes with buildings// boxes.resize(5); - for(int i=0;i<5;i++) //for each row + for(size_t i=0;i<5;i++) //for each row { - for(int j=0; jbuildh->hall[owner->town->subID].second[i].size();j++) //for each box + for(size_t j=0; jbuildh->hall[owner->town->subID].second[i].size();j++) //for each box { - int k=0; + size_t k=0; for(;kbuildh->hall[owner->town->subID].second[i][j].size();k++)//we are looking for the first not build structure { if( @@ -1064,9 +1070,9 @@ CHallInterface::~CHallInterface() delete bars; delete status; SDL_FreeSurface(bg); - for(int i=0;icastleInt->activate(); } -void CHallInterface::show(SDL_Surface * to) +void CHallInterface::show(SDL_Surface * to) //TODO use me { blitAt(bg,pos); resdatabar.show(); exit->show(); for(int i=0; i<5; i++) { - for(int j=0;jshow(); } } void CHallInterface::activate() { for(int i=0;i<5;i++) - for(int j=0;jactivate(); + } exit->activate(); } void CHallInterface::deactivate() { for(int i=0;i<5;i++) { - for(int j=0;jdeactivate(); } @@ -1187,7 +1194,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state) } while(true) { - int czystych=0; + size_t czystych=0; for(std::set::iterator i=reqs.begin();i!=reqs.end();i++) { if(used.find(*i)==used.end()) //we haven't added requirements for this building @@ -1223,7 +1230,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state) return ret; } CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode) -:tid(Tid),bid(Bid),mode(Mode), state(State) +:tid(Tid), bid(Bid), state(State), mode(Mode) { SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp"); graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); @@ -1237,7 +1244,13 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap); CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap); CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->townh->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap); - int resamount=0; for(int i=0;i<7;i++) if(CGI->buildh->buildings[tid][bid]->resources[i]) resamount++; + int resamount=0; + + for(int i=0;i<7;i++) { + if(CGI->buildh->buildings[tid][bid]->resources[i]) { + resamount++; + } + } int ah = (resamount>4) ? 304 : 341; int cn=-1, it=0; int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45, @@ -1286,9 +1299,9 @@ CHallInterface::CBuildWindow::~CBuildWindow() CFortScreen::~CFortScreen() { LOCPLINT->curint->subInt = NULL; - for(int i=0;icurint->subInt = this; exit->activate(); - for (int i=0;iactivate(); } @@ -1323,7 +1336,7 @@ void CFortScreen::activate() void CFortScreen::deactivate() { exit->deactivate(); - for (int i=0;ideactivate(); } @@ -1435,7 +1448,7 @@ void CFortScreen::RecArea::clickLeft (tribool down) if(!down && pressedL) { LOCPLINT->curint->deactivate(); - CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); + //CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //TODO use me } ClickableL::clickLeft(down); } @@ -1467,10 +1480,10 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner) positions[3] += genRect(61,83,183,42), genRect(61,83,183,148), genRect(61,83,183,253); positions[4] += genRect(61,83,491,325), genRect(61,83,591,325); blitAt(view,332,76,bg); - for(int i=0; itown->town->mageLevel; i++) + for(size_t i=0; itown->town->mageLevel; i++) { - int sp = owner->town->spellsAtLevel(i+1,false); - for(int j=0; jtown->spellsAtLevel(i+1,false); //spell at level with -1 hmmm? + for(size_t j=0; jtown->mageGuildLevel() && owner->town->spells[i].size()>j) { @@ -1485,7 +1498,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner) } } SDL_FreeSurface(view); - for(int i=0;icastleInt->subInt = NULL; LOCPLINT->castleInt->activate(); } -void CMageGuildScreen::show(SDL_Surface * to) +void CMageGuildScreen::show(SDL_Surface * to) //TODO use me { blitAt(bg,pos); resdatabar.show(); @@ -1517,15 +1530,17 @@ void CMageGuildScreen::activate() LOCPLINT->objsToBlit += this; LOCPLINT->castleInt->subInt = this; exit->activate(); - for(int i=0;iobjsToBlit -= this; exit->deactivate(); - for(int i=0;i #include "CPlayerInterface.h" //#include "boost/tuple/tuple.hpp" class CGTownInstance; @@ -220,4 +227,5 @@ public: void show(SDL_Surface * to=NULL); void activate(); void deactivate(); -}; \ No newline at end of file +}; +#endif //CCASTLEINTERFACE_H \ No newline at end of file diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index 1581d39c5..6f88d77e3 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -43,7 +43,7 @@ void CCursorHandler::draw1() x-=12; y-=10; } - SDL_BlitSurface(screen,&genRect(32,32,x,y),help,&genRect(32,32,0,0)); + SDL_BlitSurface(screen, &genRect(32,32,x,y), help, &genRect(32,32,0,0)); blitAt(cursors[mode]->ourImages[number].bitmap,x,y); } void CCursorHandler::draw2() diff --git a/CGameInterface.cpp b/CGameInterface.cpp index 01177fd60..5990e87dc 100644 --- a/CGameInterface.cpp +++ b/CGameInterface.cpp @@ -27,8 +27,8 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname) char temp[50]; dllname = "AI/"+dllname; CGlobalAI * ret=NULL; - CGlobalAI*(*getAI)(); - void(*getName)(char*); + CGlobalAI*(*getAI)(); //TODO use me + void(*getName)(char*); //TODO use me #ifdef _WIN32 HINSTANCE dll = LoadLibraryA(dllname.c_str()); diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 5d65f182e..223401355 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -131,23 +131,25 @@ CHeroWindow::~CHeroWindow() delete leftArtRoll; delete rightArtRoll; - for(int g=0; gshow(); ourBar->show(); - for(int d=0; dshow(to); } - for(int d=0; dshow(to); } @@ -223,11 +225,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) garInt->update = false; gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function - for(int g=0; gbonus = hero->getPrimSkillLevel(g); } - for(int g=0; gsecSkills.size(); ++g) + for(size_t g=0; gsecSkills.size(); ++g) { secSkillAreas[g]->type = hero->secSkills[g].first; secSkillAreas[g]->bonus = hero->secSkills[g].second; @@ -244,11 +246,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) sprintf(bufor, CGI->generaltexth->allTexts[205].substr(1, CGI->generaltexth->allTexts[205].size()-2).c_str(), hero->name.c_str(), hero->mana, hero->getPrimSkillLevel(3)*10); spellPointsArea->text = std::string(bufor); - for(int g=0; gourWindow = this; } - for(int g=0; gslotID = g; if(artWorn[g]->ourArt) @@ -287,7 +289,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) } } - for(int s=0; s<5; ++s) + for(size_t s=0; s<5; ++s) { CArtPlace * add; if( s < curHero->artifacts.size() ) @@ -304,10 +306,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) add->pos.x = pos.x + 403 + 46*s; add->pos.y = pos.y + 365; add->pos.h = add->pos.w = 44; - if(sartifacts.size() && hero->artifacts[s]) + if(sartifacts.size() && hero->artifacts[s]) { add->text = hero->getArt(19+s)->Description(); - else + } + else { add->text = std::string(); + } add->ourWindow = this; add->slotID = 19+s; backpack.push_back(add); @@ -347,12 +351,12 @@ void CHeroWindow::quit() SDL_FreeSurface(curBack); curBack = NULL; - for(int g=0; gactivate(); LOCPLINT->statusbar = ourBar; - for(int v=0; vactivate(); } - for(int v=0; vsecSkills.size(); ++v) + for(size_t v=0; vsecSkills.size(); ++v) { secSkillAreas[v]->activate(); } redrawCurBack(); - for(int f=0; factivate(); } - for(int f=0; factivate(); } - for(int e=0; eactivate(); } @@ -423,26 +427,26 @@ void CHeroWindow::deactivate() garInt->deactivate(); - for(int v=0; vdeactivate(); } - for(int v=0; vsecSkills.size(); ++v) + for(size_t v=0; vsecSkills.size(); ++v) { secSkillAreas[v]->deactivate(); } - for(int f=0; fdeactivate(); } - for(int f=0; fdeactivate(); } - for(int e=0; edeactivate(); } @@ -464,7 +468,7 @@ void CHeroWindow::leftArtRoller() { backpackPos+=curHero->artifacts.size()-1; //set new offset - for(int s=0; s<5 && sartifacts.size(); ++s) //set new data + for(size_t s=0; s<5 && sartifacts.size(); ++s) //set new data { backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]; if(backpack[s]->ourArt) @@ -481,7 +485,7 @@ void CHeroWindow::rightArtRoller() { backpackPos+=1; //set new offset - for(int s=0; s<5 && sartifacts.size(); ++s) //set new data + for(size_t s=0; s<5 && sartifacts.size(); ++s) //set new data { backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ]; if(backpack[s]->ourArt) @@ -665,7 +669,7 @@ void CHeroWindow::redrawCurBack() CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack); } -CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false)/*, +CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*, spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false), warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false), misc5(false), feet(false), lRing(false), rRing(false), torso(false), @@ -733,7 +737,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down) else { int backID = -1; - for(int g=0; gbackpack.size(); ++g) + for(size_t g=0; gbackpack.size(); ++g) { if(ourWindow->backpack[g]==this) //if user wants to put something to backpack { diff --git a/CHeroWindow.h b/CHeroWindow.h index 8d3933119..7765d79c7 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -1,4 +1,10 @@ +#ifndef CHEROWINDOW_H +#define CHEROWINDOW_H + +#ifdef _MSC_VER #pragma once +#endif + #include "CPlayerInterface.h" class AdventureMapButton; @@ -127,3 +133,4 @@ public: friend void CArtPlace::clickLeft(tribool down); friend class CPlayerInterface; }; +#endif //CHEROWINDOW_H \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index beb562850..3c11588d3 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -11,8 +11,8 @@ #include #include #include -#include "SDL_ttf.h" -#include "SDL_mixer.h" +#include +#include #include "SDL_Extensions.h" #include "SDL_framerate.h" #include "CGameInfo.h" @@ -45,6 +45,8 @@ #include "lib/Connection.h" #include "lib/Interprocess.h" #include "lib/VCMI_Lib.h" +#include + std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; @@ -210,7 +212,7 @@ int main(int argc, char** argv) LOCPLINT->pim->lock(); SDL_Delay(750); tlog0 << "Ending...\n"; - exit(0); + exit(EXIT_SUCCESS); } eventsM.lock(); events.push(ev); @@ -232,11 +234,11 @@ void processCommand(const std::string &message, CClient *&client) readed >> cn; int3 src, dst; - int heronum; +// int heronum;//TODO use me int3 dest; if(message==std::string("die, fool")) - exit(0); + exit(EXIT_SUCCESS); else if(cn==std::string("activate")) { int what; diff --git a/CMessage.cpp b/CMessage.cpp index 53c97c1cc..3567f7b82 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -51,12 +51,12 @@ void CMessage::init() piecesOfBox.push_back(n); if (i==1) { - for (int j=0;jourImages.size();j++) + for (size_t j=0;jourImages.size();++j) { piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); } } - for (int j=0;jourImages.size();j++) + for (size_t j=0;jourImages.size();++j) { graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); @@ -74,7 +74,7 @@ void CMessage::dispose() { for (int i=0;iflags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); for (int i=0; ih)//background { - for (int j=0; jw-1) - SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); + for (int j=0; jw-1) { + SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary + } } drawBorder(playerColor, ret, w, h); return ret; } -std::vector * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor) +std::vector * CMessage::breakText(std::string text, size_t line, bool userBreak, bool ifor) //TODO userBreak -- use me { std::vector * ret = new std::vector(); while (text.length()>line) { int whereCut = -1, braces=0; bool pom = true, opened=false; - for (int i=0; i * CMessage::breakText(std::string text, int line, bool pom=false; break; } - else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces + else if (ifor && ((text[i]=='{') || (text[i]=='}'))) // ignore braces { if (text[i]=='{') opened=true; @@ -141,7 +142,7 @@ std::vector * CMessage::breakText(std::string text, int line, bool text.insert(0,"{"); } } - for (int i=0;i * CMessage::breakText(std::string text, int line, bool } if (text.length() > 0) ret->push_back(text); - for (int i=0; isize(); i++) + for (size_t i=0; isize(); i++) { boost::algorithm::trim((*ret)[i]); } @@ -161,11 +162,11 @@ std::vector * CMessage::breakText(std::string text, int line, bool std::pair CMessage::getMaxSizes(std::vector< std::vector > * komp) { std::pair ret; - for (int i=0;isize();i++) + for (size_t i=0;isize();i++) { int sumaw=0; int maxh=0; - for(int j=0;j<(*komp)[i].size();j++) + for(size_t j=0;j<(*komp)[i].size();j++) { sumaw += (*komp)[i][j]->getImg()->w; if (maxh < (*komp)[i][j]->getImg()->h) @@ -184,10 +185,10 @@ std::pair CMessage::getMaxSizes(std::vector > std::pair ret; ret.first = -1; ret.second=0; - for (int i=0; isize();i++) //szukamy najszerszej linii i lacznej wysokosci + for (size_t i=0; isize();i++) //szukamy najszerszej linii i lacznej wysokosci { int lw=0; - for (int j=0;j<(*txtg)[i].size();j++) + for (size_t j=0;j<(*txtg)[i].size();j++) { lw+=(*txtg)[i][j]->w; ret.second+=(*txtg)[i][j]->h; @@ -201,16 +202,16 @@ std::pair CMessage::getMaxSizes(std::vector > } SDL_Surface * CMessage::blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret) { - for (int i=0; isize();i++) + for (size_t i=0; isize();i++) { int lw=0; - for (int j=0;j<(*txtg)[i].size();j++) + for (size_t j=0;j<(*txtg)[i].size();j++) lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii int pw = ret->w/2; pw -= lw/2; //poczatek tekstu (x) int tw = pw; - for (int j=0;j<(*txtg)[i].size();j++) //blit text + for (size_t j=0;j<(*txtg)[i].size();j++) //blit text { blitAt((*txtg)[i][j],tw,curh+i*19,ret); tw+=(*txtg)[i][j]->w; @@ -223,15 +224,17 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector > * SDL_Surface * CMessage::blitCompsOnSur(std::vector & comps, int maxw, int inter, int & curh, SDL_Surface * ret) { std::vector * brdtext; - if (comps.size()) + if (comps.size()) { brdtext = breakText(comps[0]->subtitle,12,true,true); - else + } + else { brdtext = NULL; + } comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2); comps[0]->pos.y = curh; blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret); curh += comps[0]->getImg()->h + 5; //obrazek + przerwa - for (int i=0; isize();i++) //descr. + for (size_t i=0; i < brdtext->size(); ++i) //descr. { SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly); blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret); @@ -242,23 +245,26 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector & comps, int max } SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector > * komp, int inter, int &curh, SDL_Surface *ret) { - for (int i=0;isize();i++) + for (size_t i=0;isize();i++) { int totalw=0, maxh=0; - for(int j=0;j<(*komp)[i].size();j++) + for(size_t j=0;j<(*komp)[i].size();j++) { totalw+=(*komp)[i][j]->getImg()->w; - if(maxh<(*komp)[i][j]->getImg()->h) + if(maxh<(*komp)[i][j]->getImg()->h) { maxh=(*komp)[i][j]->getImg()->h; + } } - if(_or) + if(_or) { totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1); - else + } + else { totalw += (inter) * ((*komp)[i].size() - 1); + } curh+=maxh/2; int curw = (ret->w/2)-(totalw/2); - for(int j=0;j<(*komp)[i].size();j++) + for(size_t j=0;j<(*komp)[i].size();j++) { blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret); (*komp)[i][j]->pos.x = curw; @@ -285,11 +291,11 @@ std::vector > * CMessage::drawText(std::vector > * txtg = new std::vector >(); txtg->resize(brtext->size()); - for (int i=0; isize();i++) //foreach line + for (size_t i=0; isize();i++) //foreach line { while((*brtext)[i].length()) //jesli zostalo cos { - int z=0; bool br=true; + size_t z=0; bool br=true; while( ((*brtext)[i][z]) != ('{') ) { if (z >= (((*brtext)[i].length())-1)) @@ -339,7 +345,7 @@ std::vector< std::vector > * CMessage::breakComps(std::vectorresize(1); int rvi = 0; int curw = 0; - for(int i=0;igetImg()->w + 12 + (_or ? _or->w : 0)); if (curw > maxw) @@ -421,17 +427,17 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int { curh += 20; //to buttton int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them - for(int i=0; ibuttons.size(); i++) //and add buttons width + for(size_t i=0; ibuttons.size(); i++) //and add buttons width bw+=ret->buttons[i]->imgs[0][0]->w; bw = (ret->bitmap->w/2) - (bw/2); - for(int i=0; ibuttons.size(); i++) + for(size_t i=0; ibuttons.size(); i++) { ret->buttons[i]->pos.x = bw + ret->pos.x; ret->buttons[i]->pos.y = curh + ret->pos.y; bw += ret->buttons[i]->imgs[0][0]->w + 20; } } - for(int i=0; icomponents.size(); i++) + for(size_t i=0; icomponents.size(); i++) { ret->components[i]->pos.x += ret->pos.x; ret->components[i]->pos.y += ret->pos.y; @@ -510,7 +516,7 @@ SDL_Surface * CMessage::genMessage SDL_FreeSurface(titleText); } //draw text - for (int i=0; isize(); i++) + for (size_t i=0; isize(); i++) { int by = 37+i*21; if (title.length()) by+=40; diff --git a/CMessage.h b/CMessage.h index 77c8efe49..94bbeba36 100644 --- a/CMessage.h +++ b/CMessage.h @@ -3,7 +3,7 @@ #include "global.h" #include -#include "SDL.h" +#include #include "CPreGame.h" enum EWindowType {infoOnly, infoOK, yesOrNO}; @@ -41,7 +41,7 @@ public: static SDL_Surface * drawBox1(int w, int h, int playerColor=1); static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0); static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55); - static std::vector * breakText(std::string text, int line=30, bool userBreak=true, bool ifor=true); //line - chars per line + static std::vector * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line CMessage(); static void init(); static void dispose(); diff --git a/CPathfinder.cpp b/CPathfinder.cpp index bf0a44078..761cf71ac 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -49,28 +49,33 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u //graph initialization graph.resize(CGI->mh->sizes.x); - for(int i=0; imh->sizes.y); - for(int j=0; jmh->ttiles[i][j][src.z].tileInfo->blocked; - if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable) + if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable) { graph[i][j].accesible = true; //for allowing visiting objects + } graph[i][j].dist = -1; graph[i][j].theNodeBefore = NULL; graph[i][j].visited = false; graph[i][j].coord.x = i; graph[i][j].coord.y = j; graph[i][j].coord.z = dest.z; - if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock) + if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock) { graph[i][j].accesible = false; - if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water)) + } + if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water)) { graph[i][j].accesible = false; - else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water)) + } + else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water)) { graph[i][j].accesible = false; - if(graph[i][j].accesible) + } + if(graph[i][j].accesible) { graph[i][j].accesible = CGI->state->players[hero->tempOwner].fogOfWarMap[i][j][src.z]; + } } } @@ -81,7 +86,7 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u std::queue mq; mq.push(graph[src.x][src.y]); - unsigned int curDist = 4000000000; + unsigned int curDist = 4000000000; //XXX 2 147 483 648 // only in C90 //but numeric limit shows 0-4294967295...confused while(!mq.empty()) { diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 548b0f7e3..152ad17b8 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -311,14 +311,16 @@ CGarrisonInt::~CGarrisonInt() { if(sup) { - for(int i=0;isize();i++) + for(size_t i=0;isize();i++) { delete (*sup)[i]; + } delete sup; } if(sdown) { - for(int i=0;isize();i++) - delete (*sdown)[i]; + for(size_t i=0;isize();i++) { + delete (*sdown)[i]; //XXX what about smartpointers? boost or auto_ptr from std + } delete sdown; } } @@ -327,15 +329,18 @@ void CGarrisonInt::show() { if(sup) { - for(int i = 0; isize(); i++) - if((*sup)[i]) + for(size_t i = 0; isize(); i++) + if((*sup)[i]) { (*sup)[i]->show(); + } } if(sdown) { - for(int i = 0; isize(); i++) - if((*sdown)[i]) + for(size_t i = 0; isize(); i++) { + if((*sdown)[i]){ (*sdown)[i]->show(); + } + } } } void CGarrisonInt::deactiveteSlots() diff --git a/CPreGame.cpp b/CPreGame.cpp index 670bfae0f..d347dc9af 100644 --- a/CPreGame.cpp +++ b/CPreGame.cpp @@ -1,11 +1,11 @@ #include "stdafx.h" #include "CPreGame.h" #include "hch/CDefHandler.h" -#include "SDL.h" -#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations -#include "boost/algorithm/string.hpp" +#include +#include // includes all needed Boost.Filesystem declarations +#include //#include "boost/foreach.hpp" -#include "zlib.h" +#include #include "timeHandler.h" #include #include "SDL_Extensions.h" @@ -19,9 +19,12 @@ #include "client/Graphics.h" #include #include +#include + extern SDL_Surface * screen; extern SDL_Color tytulowy, tlo, zwykly ; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; + #ifdef min #undef min #endif @@ -270,7 +273,10 @@ void Slider::handleIt(SDL_Event sEvent) case (SDLK_DOWN): CPG->ourScenSel->mapsel.moveByOne(false); break; - } + default: + //TODO do something nasty here like logs entry.. + break; + } } else if (moving && sEvent.type==SDL_MOUSEMOTION) { @@ -538,13 +544,13 @@ void Options::OptionSwitch::press(bool down) void Options::PlayerFlag::press(bool down) { HighButton::press(down); - int i=0; + size_t i=0; for(;iret.playerInfos.size();i++) if(CPG->ret.playerInfos[i].color==color) break; if (CPG->ret.playerInfos[i].human || (!CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[CPG->ret.playerInfos[i].color].canHumanPlay)) return; //if this is already human player, or if human is forbidden - int j=0; + size_t j=0; for(;jret.playerInfos.size();j++) if(CPG->ret.playerInfos[j].human) break; @@ -583,7 +589,7 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1 else { ab = nr; - for (int i=0; iret.playerInfos.size();i++) + for (size_t i=0; iret.playerInfos.size();++i) { if (CPG->ret.playerInfos[i].color==nr) { @@ -661,11 +667,15 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1 } Options::~Options() { - if (!inited) return; - for (int i=0; iourScenSel->mapsel; blitAt(bg,3,6); CPG->ourScenSel->listShowed=false; - for (int i=0;ibtns.size();i++) + for (size_t i=0; i < CPG->btns.size(); ++i) { if (CPG->btns[i]->ID!=10) //leave only right panel buttons { @@ -728,12 +738,13 @@ void Options::show() CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX); CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration int playersSoFar=0; - for (int i=0;inr=playersSoFar; @@ -755,14 +766,17 @@ void Options::show() { poptions[poptions.size()-1]->flag.show(); CPG->btns.push_back(&poptions[poptions.size()-1]->flag); - if (ms.ourMaps[ms.selected].players[i].canComputerPlay) + if (ms.ourMaps[ms.selected].players[i].canComputerPlay) { CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly); - else + } + else { CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly); + } } - else + else { CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly); + } playersSoFar++; } CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly); @@ -771,8 +785,9 @@ void Options::show() CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[260].second),275,109,GEOR13,10); CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[261].second),354,109,GEOR13,10); turnLength->activate(); - for (int i=0;imoveDown(); //SDL_Flip(screen); @@ -780,23 +795,28 @@ void Options::show() } void Options::hide() { - if (!showed) return; + if (!showed) { + return; + } PreGameTab::hide(); - for (int i=0; ibtns.size();i++) + for (size_t i=0; i < CPG->btns.size(); ++i) if (CPG->btns[i]->ID==7) CPG->btns.erase(CPG->btns.begin()+i--); - for (int i=0;ideactivate(); } MapSel::~MapSel() { SDL_FreeSurface(bg); - for (int i=0;imapsel.select(0,false); - for (int i=0;ipos.w=btns[i]->imgs->ourImages[0].bitmap->w; btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h; @@ -1704,7 +1730,7 @@ void CPreGame::hideBox () SDL_BlitSurface(behindCurMes,NULL,screen,currentMessage); SDL_UpdateRect (screen,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h); - for (int i=0;iID==2) { @@ -1742,7 +1768,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT)) { - for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) { @@ -1766,7 +1792,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) ourScenSel->pressed->press(false); ourScenSel->pressed=NULL; } - for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) { @@ -1802,7 +1828,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) highlighted = NULL; } } - for (int i=0;ihighlightable) continue; @@ -1829,11 +1855,12 @@ StartInfo CPreGame::runLoop() menuItems * current = currentItems(); if(sEvent.type==SDL_QUIT) { - exit(0); + exit(EXIT_SUCCESS); return ret; } - for (int i=0;ihandleIt(sEvent); + } if (!current) { (this->*handleOther)(sEvent); @@ -1842,11 +1869,11 @@ StartInfo CPreGame::runLoop() { if (sEvent.key.keysym.sym==SDLK_q) { - exit(0); + exit(EXIT_SUCCESS); } if(sEvent.key.keysym.sym==SDLK_F4 && (sEvent.key.keysym.mod & KMOD_LALT)) //Alt+F4 { - exit(0); + exit(EXIT_SUCCESS); } /*if (state==EState::newGame) { @@ -1972,7 +1999,7 @@ StartInfo CPreGame::runLoop() else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT)) { mush->playClick(); - for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) { @@ -2010,7 +2037,7 @@ StartInfo CPreGame::runLoop() } else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT)) { - for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) ((Button*)btns[i])->fun(); @@ -2312,12 +2339,38 @@ ScenSel::ScenSel() selectedDiff=-77; difficulty->gdzie = &selectedDiff; - for (int i=0; iourImages.size(); i++) - CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios" - for (int i=0; iourImages.size(); i++) - CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,bRandom.imgs->ourImages[i].bitmap); - for (int i=0; iourImages.size(); i++) - CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options" + for (size_t i=0; i < bScens.imgs->ourImages.size(); ++i) { + CSDL_Ext::printAt( + CGI->generaltexth->allTexts[500], + 25+i, + 2+i, + GEOR13, + zwykly, + bScens.imgs->ourImages[i].bitmap + ); //"Show Available Scenarios" + } + + for (size_t i=0; i < bRandom.imgs->ourImages.size(); ++i) { + CSDL_Ext::printAt( + CGI->generaltexth->allTexts[740], + 25+i, + 2+i, + GEOR13, + zwykly, + bRandom.imgs->ourImages[i].bitmap + ); + } + + for (size_t i=0; i < bOptions.imgs->ourImages.size(); ++i) { + CSDL_Ext::printAt( + CGI->generaltexth->allTexts[501], + 25+i, + 2+i, + GEOR13, + zwykly, + bOptions.imgs->ourImages[i].bitmap + ); //"Show Advanced Options" + } } ScenSel::~ScenSel() diff --git a/CPreGame.h b/CPreGame.h index 4ebdb1afd..67d9a5923 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -2,13 +2,15 @@ #define CPREGAME_H #include "global.h" #include -#include "SDL.h" +#include #include "StartInfo.h" #include "CMessage.h" #include "map.h" #include "hch/CMusicHandler.h" #include #include +#include + class CPreGame; class CDefHandler; extern CPreGame * CPG; @@ -94,7 +96,7 @@ public: class CPoinGroup :public CGroup { public: - int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/) + int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/) void setYour(IntSelBut * your); }; struct IntSelBut: public Button @@ -268,7 +270,7 @@ public: void scenHandleEv(SDL_Event& sEvent); void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;}; void quitAskBox(); - void quit(){exit(0);}; + void quit(){exit(EXIT_SUCCESS);}; void initScenSel(); void showScenSel(); void showScenList(); diff --git a/CThreadHelper.h b/CThreadHelper.h index c89bf873a..ce8f6da97 100644 --- a/CThreadHelper.h +++ b/CThreadHelper.h @@ -1,3 +1,6 @@ +#ifndef CTHREADHELPER_H +#define CTHREADHELPER_H + #include "global.h" #include #include @@ -36,3 +39,4 @@ template inline void setData(T * data, boost::function func) (GET_DATA \ (CDefEssential*,DESTINATION,\ boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) +#endif //CTHREADHELPER_H diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 3b7ee7c2b..72ef8343e 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -74,18 +74,19 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font std::vector * ws = CMessage::breakText(text,charpr); std::vector wesu; wesu.resize(ws->size()); - for (int i=0;ih; if (tox < wesu[i]->w) tox=wesu[i]->w; } int evx, evy = y - (toy/2); - for (int i=0;iw)/2); blitAt(wesu[i],evx,evy,dst); @@ -93,7 +94,7 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font } - for (int i=0;i * ws = CMessage::breakText(text,charpr); std::vector wesu; wesu.resize(ws->size()); - for (int i=0;ih; } - for (int i=0;i & tor) { - for (int i=0;(irealSize]; memcpy(pcx,sign,3); - int res = fread((char*)pcx+3, 1, e->realSize-3, f); + int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me fclose(f); cp.openPCX((char*)pcx,e->realSize); return cp.getSurface(); diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h index 53114c138..cd6a6e3d7 100644 --- a/client/CBitmapHandler.h +++ b/client/CBitmapHandler.h @@ -1,4 +1,11 @@ +#ifndef CBITMAPHANDLER_H +#define CBITMAPHANDLER_H + +#ifdef _MSC_VER #pragma once +#endif + + #include "../global.h" struct SDL_Surface; class CLodHandler; @@ -36,4 +43,5 @@ namespace BitmapHandler { extern CLodHandler *bitmaph; SDL_Surface * loadBitmap(std::string fname, bool setKey=false); -}; \ No newline at end of file +}; +#endif //CBITMAPHANDLER_H \ No newline at end of file diff --git a/client/CConfigHandler.h b/client/CConfigHandler.h index 20209fc08..ba929fe45 100644 --- a/client/CConfigHandler.h +++ b/client/CConfigHandler.h @@ -1,3 +1,5 @@ +#ifndef CCONFIGHANDLER_H +#define CCONFIGHANDLER_H #pragma once #include "../global.h" class CAdvMapInt; @@ -61,4 +63,5 @@ namespace config ~CConfigHandler(void); }; } -extern config::CConfigHandler conf; \ No newline at end of file +extern config::CConfigHandler conf; +#endif //CCONFIGHANDLER_H \ No newline at end of file diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index 01858f428..a6301712c 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -14,7 +14,7 @@ void CCreatureAnimation::setType(int type) if(SEntries[curFrame].group!=type) //rewind { int j=-1; //first frame in displayed group - for(int g=0; g=frames) + if(curFrame>=frames) { curFrame = 0; + } } } @@ -67,8 +69,8 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL) SEntries.push_back(SEntry()); SEntries[j].group = group; } - int unknown2 = readNormalNr(i,4); i+=4; - int unknown3 = readNormalNr(i,4); i+=4; + int unknown2 = readNormalNr(i,4); i+=4; //TODO use me + int unknown3 = readNormalNr(i,4); i+=4; //TODO use me for (j=0; jpixels + ftcp*3; if(palc > 7) //normal color { diff --git a/client/CCreatureAnimation.h b/client/CCreatureAnimation.h index 13ec0624b..7f44387f3 100644 --- a/client/CCreatureAnimation.h +++ b/client/CCreatureAnimation.h @@ -1,4 +1,10 @@ +#ifndef CCREATUREANIMATION_H +#define CCREATUREANIMATION_H + +#ifdef _MSC_VER #pragma once +#endif + #include "../global.h" #include "../CPlayerInterface.h" #include "../hch/CDefHandler.h" @@ -19,12 +25,18 @@ private: std::vector SEntries ; std::string defName, curDir; 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; + 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 + int curFrame; //number of currently displayed frame unsigned int frames; //number of frames public: int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) @@ -42,3 +54,4 @@ public: int framesInGroup(int group) const; //retirns number of fromes in given group }; +#endif //CCREATUREANIMATION_H \ No newline at end of file diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index 99b218398..a5e415fc2 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -65,9 +65,14 @@ void SpellbookInteractiveArea::deactivate() Hoverable::deactivate(); } -CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4), spellSite(0), battleSpellsOnly(true) +CSpellWindow::CSpellWindow( + const SDL_Rect & myRect, + const CGHeroInstance * myHero): + battleSpellsOnly(true), + selectedTab(4), + spellSite(0) { - //for testing only + //XXX for testing only //mySpells = myHero->spells; for(ui32 v=0; vspellh->spells.size(); ++v) { @@ -76,7 +81,7 @@ CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHer } for(int b=0; b<4; ++b) schoolLvls[b] = 0; - for(int b=0; bsecSkills.size(); ++b) + for(size_t b=0; bsecSkills.size(); ++b) { switch(myHero->secSkills[b].first) { @@ -304,7 +309,7 @@ void CSpellWindow::fexitb() { deactivate(); - for(int g=0; gobjsToBlit.size(); ++g) + for(size_t g=0; gobjsToBlit.size(); ++g) //TODO what about { if(dynamic_cast(LOCPLINT->objsToBlit[g])) { @@ -415,7 +420,7 @@ void CSpellWindow::show(SDL_Surface *to) { if(spellAreas[b]->mySpell == -1) continue; - int b2 = -1; + //int b2 = -1; //TODO use me blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to); @@ -540,19 +545,21 @@ void CSpellWindow::computeSpellsPerArea() //applying if(selectedTab == 4 || spellSite != 0) { - for(int c=0; c<12; ++c) + for(size_t c=0; c<12; ++c) { - if(cmySpell = spellsCurSite[c]; - else + } + else { spellAreas[c]->mySpell = -1; + } } } else { spellAreas[0]->mySpell = -1; spellAreas[1]->mySpell = -1; - for(int c=0; c<10; ++c) + for(size_t c=0; c<10; ++c) { if(cmySpell = spellsCurSite[c]; diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index f25b7f2ea..0070ea804 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -1,4 +1,10 @@ +#ifndef CSPELLWINDOW_H +#define CSPELLWINDOW_H + +#ifdef _MSC_VER #pragma once +#endif + #include "../global.h" #include "../CPlayerInterface.h" @@ -86,3 +92,4 @@ public: void deactivate(); void show(SDL_Surface * to = NULL); }; +#endif //CSPELLWINDOW_H \ No newline at end of file diff --git a/client/Client.cpp b/client/Client.cpp index b87306c1a..dea02fce4 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -23,7 +23,7 @@ CSharedCond > mess(new std::set); std::string toString(MetaString &ms) { std::string ret; - for(int i=0;i0) { @@ -87,7 +87,7 @@ std::string toString(MetaString &ms) } } } - for(int i=0;i> pom8; if(pom8) throw "Server cannot open the map!"; c << ui8(si->playerInfos.size()+1); //number of players + neutral - for(int i=0;iplayerInfos.size();i++) + for(size_t i=0;iplayerInfos.size();i++) { c << ui8(si->playerInfos[i].color); //players + } c << ui8(255); // neutrals @@ -144,14 +145,16 @@ CClient::CClient(CConnection *con, StartInfo *si) CGI->mh->init(); tlog0 <<"Initializing mapHandler (together): "<state->scenarioOps->playerInfos.size();i++) //initializing interfaces for players + for (size_t i=0; istate->scenarioOps->playerInfos.size();++i) //initializing interfaces for players { ui8 color = gs->scenarioOps->playerInfos[i].color; CCallback *cb = new CCallback(gs,color,this); - if(!gs->scenarioOps->playerInfos[i].human) + if(!gs->scenarioOps->playerInfos[i].human) { playerint[color] = static_cast(CAIHandler::getNewAI(cb,conf.cc.defaultAI)); - else + } + else { playerint[color] = new CPlayerInterface(color,i); + } gs->currentPlayer = color; playerint[color]->init(cb); } @@ -200,8 +203,9 @@ void CClient::process(int what) InfoWindow iw; *serv >> iw; std::vector comps; - for(int i=0;ishowInfoDialog(str,comps); break; @@ -496,8 +500,9 @@ void CClient::process(int what) *serv >> sd; tlog5 << "Showing selection dialog " < comps; - for(int i=0;ishowSelDialog(str,comps,sd.id); break; @@ -508,8 +513,9 @@ void CClient::process(int what) *serv >> ynd; tlog5 << "Showing yes/no dialog " < comps; - for(int i=0;ishowYesNoDialog(str,comps,ynd.id); break; diff --git a/client/Client.h b/client/Client.h index 9052af776..aeddcaad2 100644 --- a/client/Client.h +++ b/client/Client.h @@ -1,4 +1,10 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#ifdef _MSC_VER #pragma once +#endif + #include "../global.h" #include struct StartInfo; @@ -56,3 +62,4 @@ public: friend class CScriptCallback; //for objects scripts friend void processCommand(const std::string &message, CClient *&client); //handling console }; +#endif //CLIENT_H \ No newline at end of file diff --git a/client/FunctionList.h b/client/FunctionList.h index 9a86ea897..56547aec0 100644 --- a/client/FunctionList.h +++ b/client/FunctionList.h @@ -1,4 +1,10 @@ +#ifndef FUNCTIONLIST_H +#define FUNCTIONLIST_H + +#ifdef _MSC_VER #pragma once +#endif + #include template @@ -38,15 +44,17 @@ public: void operator()() const { std::vector > funcs2 = funcs; //backup - for(int i=0;i void operator()(const Arg & a) const { std::vector > funcs2 = funcs; //backup - for(int i=0;i > funcs2 = funcs; //backup - for(int i=0;inotFreeImgs = true; - for (int i=0; iourImages.size(); i++) + for (size_t i=0; iourImages.size(); ++i) { smallImgs[i-2] = smi->ourImages[i].bitmap; } delete smi; smi2->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) + for (size_t i=0; iourImages.size(); ++i) { bigImgs[i-2] = smi2->ourImages[i].bitmap; } @@ -260,7 +260,7 @@ void Graphics::loadHeroPortraits() std::string path; of>>path; portraitSmall.push_back(BitmapHandler::loadBitmap(path)); - for(int ff=0; ff & anims) std::vector > rotations; //first - group number to be rotated1, second - group number after rotation1 rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12), std::make_pair(1,13), std::make_pair(2,14), std::make_pair(3,15); - for(int i=0; i & anims) } } } - for(int ff=0; ff<(*anims[i])->ourImages.size(); ++ff) + for(size_t ff=0; ff<(*anims[i])->ourImages.size(); ++ff) { CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap); } @@ -328,9 +328,9 @@ void Graphics::loadHeroFlags(std::pair Graphics::*, s rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12); for(int q=0; q<8; ++q) { - for(int o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o) + for(size_t o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o) { - for(int p=0;p*pr.first)[q]->ourImages[o].groupNumber==rotations[p].first) { @@ -348,7 +348,7 @@ void Graphics::loadHeroFlags(std::pair Graphics::*, s } if (mode) { - for(int o=0; oourImages.size(); ++o) + for(size_t o=0; oourImages.size(); ++o) { if(flags4[q]->ourImages[o].groupNumber==1) { @@ -388,7 +388,7 @@ void Graphics::loadHeroFlags(std::pair Graphics::*, s } } } - for(int ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff) + for(size_t ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff) { SDL_SetColorKey((this->*pr.first)[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, SDL_MapRGB((this->*pr.first)[q]->ourImages[ff].bitmap->format, 0, 255, 255) @@ -402,7 +402,7 @@ void Graphics::loadHeroFlags() { using namespace boost::assign; timeHandler th; - std::vector Graphics::*point; +// std::vector Graphics::*point; //TODO use me std::pair Graphics::*, std::vector > pr[4]; pr[0].first = &Graphics::flags1; pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"), diff --git a/client/Graphics.h b/client/Graphics.h index 01f3ff00e..bd6cbac3a 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -1,5 +1,13 @@ +#ifndef GRAPHICS_H +#define GRAPHICS_H + +#ifdef _MSC_VER #pragma once +#endif + #include "../global.h" + + class CDefEssential; struct SDL_Surface; class CGHeroInstance; @@ -57,4 +65,5 @@ public: void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player }; -extern Graphics * graphics; \ No newline at end of file +extern Graphics * graphics; +#endif //GRAPHICS_H \ No newline at end of file diff --git a/global.h b/global.h index 9655b0a6a..7894e6246 100644 --- a/global.h +++ b/global.h @@ -1,6 +1,7 @@ #ifndef GLOBAL_H #define GLOBAL_H #include +#include //std::find #include #include typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) @@ -127,7 +128,7 @@ namespace vstd template int findPos(const std::vector & c, const T2 &s) { - for(int i=0;i int findPos(const std::vector & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches { - for(int i=0;i CLogger & operator<<(const T & data) { - if(lvl < CONSOLE_LOGGING_LEVEL) - if(console) + if(lvl < CONSOLE_LOGGING_LEVEL) { + if(console) { console->print(data,lvl); - else + } + else { std::cout << data << std::flush; - if((lvl < FILE_LOGGING_LEVEL) && logfile) + } + } + if((lvl < FILE_LOGGING_LEVEL) && logfile) { *logfile << data << std::flush; + } return *this; } }; @@ -232,6 +237,7 @@ extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info +//XXX pls dont - 'debug macros' are usually more trubble then its worth #define HANDLE_EXCEPTION \ catch (const std::exception& e) { \ tlog1 << e.what() << std::endl; \ diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index 3e4f70578..b2a9547ed 100644 --- a/hch/CDefHandler.cpp +++ b/hch/CDefHandler.cpp @@ -26,7 +26,7 @@ CDefHandler::~CDefHandler() delete [] RWEntries; if (notFreeImgs) return; - for (int i=0; i #include "CSndHandler.h" class CMusicHandler diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index d154b0b92..747cc18dc 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -19,16 +19,17 @@ extern boost::rand48 ran; void CObjectHandler::loadObjects() { VLC->objh = this; - int ID=0; +// int ID=0; //TODO use me tlog5 << "\t\tReading OBJNAMES \n"; std::string buf = bitmaph->getTextFile("OBJNAMES.TXT"); - int it=0; + int it=0; //hope that -1 will not break this while (it150) ret = 150; break; + default: + //TODO do something nasty here throw maybe? or some def value asing + break; } break; case 2: //advanced switch(ttype) { - case rough: case sand: case snow: + case rough: + case sand: + case snow: ret = 100; break; case swamp: if(ret>125) ret = 125; break; + default: + //TODO look up + break; } break; case 3: //expert ret = 100; break; + default: + //TODO look up + break; } //calculating road influence @@ -230,13 +244,16 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad case cobblestoneRoad: ret*=0.5; break; + default: + //TODO killllll me + break; } return ret; } unsigned int CGHeroInstance::getLowestCreatureSpeed() { unsigned int sl = 100; - for(int h=0; hcreh->creatures[army.slots[h].first].speedcreh->creatures[army.slots[h].first].speed; @@ -258,9 +275,12 @@ int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifes } int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' { - if (h3m) + if (h3m) { return pos; - else return convertPosition(pos,false); + } + else { + return convertPosition(pos,false); + } } int CGHeroInstance::getSightDistance() const //returns sight distance of this hero { @@ -307,7 +327,7 @@ int CGHeroInstance::getPrimSkillLevel(int id) const } int CGHeroInstance::getSecSkillLevel(const int & ID) const { - for(int i=0;i #include #include + + class CCreature; class CCreatureSet //seven combined creatures { @@ -10,14 +12,15 @@ public: std::map > slots; //slots[slot_id]=> pair(creature_id,creature_quantity) bool formation; //false - wide, true - tight si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) //returns -1 if no slot available - { - - for(std::map >::iterator i=slots.begin(); i!=slots.end(); i++) - if(i->second.first == creature) + { + for(std::map >::iterator i=slots.begin(); i!=slots.end(); ++i) + if(i->second.first == creature) { return i->first; //if there is already such creature we return its slot id - for(si32 i=0; i void serialize(Handler &h, const int version) @@ -34,7 +37,7 @@ public: 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 + ~int3() {} // d-tor - does nothing 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 //returns int3 with coordinates increased by given numer diff --git a/map.h b/map.h index bd5741a40..fd220ca27 100644 --- a/map.h +++ b/map.h @@ -1,6 +1,8 @@ #ifndef MAPD_H #define MAPD_H +#ifdef _MSC_VER #pragma warning (disable : 4482) +#endif #include #include #include diff --git a/mapHandler.cpp b/mapHandler.cpp index f51103c61..75d851327 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -70,6 +70,12 @@ std::string nameFromType (int typ) return std::string("ROCKTL.DEF"); break; } + case border: + //TODO use me + break; + default: + //TODO do something here + break; } return std::string(); } @@ -134,23 +140,24 @@ void CMapHandler::prepareFOWDefs() partialHide->ourImages.push_back(nw); //necessaary rotations added - for(int i=0; iourImages.size(); ++i) + for(size_t i=0; iourImages.size(); ++i) { CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap); } hideBitmap.resize(CGI->mh->map->width); - for (int i=0;imh->map->height); } - for (int i=0; imh->map->height; ++j) + for (int j=0; j < CGI->mh->map->height; ++j) { hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1); - for(int k=0; kmh->map->twoLevel+1; ++k) + for(int k=0; kmh->map->twoLevel+1; ++k) { hideBitmap[i][j][k] = rand()%fullHide->ourImages.size(); + } } } } @@ -166,16 +173,16 @@ void CMapHandler::roadsRiverTerrainInit() staticRiverDefs.push_back(CDefHandler::giveDef("icyrvr.def")); staticRiverDefs.push_back(CDefHandler::giveDef("mudrvr.def")); staticRiverDefs.push_back(CDefHandler::giveDef("lavrvr.def")); - for(int g=0; gourImages.size(); ++h) + for(size_t h=0; h < staticRiverDefs[g]->ourImages.size(); ++h) { CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap); } } - for(int g=0; gourImages.size(); ++h) + for(size_t h=0; h < roadDefs[g]->ourImages.size(); ++h) { CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap); } @@ -280,7 +287,7 @@ void CMapHandler::borderAndTerrainBitmapInit() CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i)); terrainGraphics[i].resize(hlp->ourImages.size()); hlp->notFreeImgs = true; - for(int j=0; jourImages.size();j++) + for(size_t j=0; j < hlp->ourImages.size(); ++j) terrainGraphics[i][j] = hlp->ourImages[j].bitmap; delete hlp; } @@ -347,7 +354,7 @@ void CMapHandler::borderAndTerrainBitmapInit() void CMapHandler::initObjectRects() { //initializing objects / rects - for(int f=0; fobjects.size(); ++f) + for(size_t f=0; f < map->objects.size(); ++f) { if((map->objects[f]->ID==34 && static_cast(map->objects[f])->inTownGarrison) || !map->objects[f]->defInfo) @@ -410,7 +417,7 @@ void processDef (CGDefInfo* def) tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; if(!def->handler->alphaTransformed) { - for(int yy=0; yyhandler->ourImages.size(); ++yy) + for(size_t yy=0; yy < def->handler->ourImages.size(); ++yy) { def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap); def->handler->alphaTransformed = true; @@ -462,7 +469,7 @@ void CMapHandler::init() for(int i=0;iplayers[i].heroesNames.size();j++) + for(size_t j=0; j < map->players[i].heroesNames.size(); ++j) { usedHeroes.insert(map->players[i].heroesNames[j].heroID); } @@ -471,7 +478,7 @@ void CMapHandler::init() - for(int h=0; hdefy.size(); ++h) //initializing loaded def handler's info { + for(size_t h=0; hdefy.size(); ++h) //initializing loaded def handler's info { CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); tlog0<<"\tCollecting loaded def's handlers: "< & iv = themp->type->heroClass->moveAnim->ourImages; - int gg; + size_t gg; for(gg=0; ggmoveDir, !themp->isStanding)) @@ -628,8 +635,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, continue; std::vector & iv = themp->type->heroClass->moveAnim->ourImages; - int gg; - for(gg=0; ggmoveDir, !themp->isStanding)) { @@ -752,7 +759,7 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, const std::vector< std::ve d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456 d9 = (y>0 && x0) ? visibilityMap[x-1][y][lvl] : 0, - d5 = visibilityMap[x][y][lvl], + d5 = visibilityMap[x][y][lvl], //TODO use me - OMFG d6 = (x0 && y toAdd = std::make_pair(obj, cr); if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)pos.x + fx - curd->ourImages[0].bitmap->w/32] [obj->pos.y + fy - curd->ourImages[0].bitmap->h/32] @@ -1088,7 +1095,7 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj) if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1) > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects; - for(int dd=0; ddid==obj->id) ctile.erase(ctile.begin() + dd); @@ -1247,7 +1254,7 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b) void CMapHandler::updateWater() //shift colors in palettes of water tiles { SDL_Color palette[14]; - for(int j=0; j @@ -19,3 +23,5 @@ #include #include "global.h" // TODO: reference additional headers your program requires here + +#endif //_ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H \ No newline at end of file