diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index e545adb94..46fa308c3 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -18,7 +18,7 @@ extern SDL_Color zwykly; SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade; CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) -: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL) +: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL) { //initializing armies this->army1 = army1; @@ -243,6 +243,9 @@ void CBattleInterface::show(SDL_Surface * to) { stackByHex[j->second.position] = j->second.ID; } + + attackingShowHelper(); // handle attack animation + for(int b=0; b<187; ++b) { if(stackByHex[b]!=-1) @@ -559,134 +562,97 @@ void CBattleInterface::stackAttacking(int ID, int dest) switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction { case 0: - //reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } //reverseCreature(ID, aStack.position, true); break; case 1: - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 2: - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 3: - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 4: - //reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } //reverseCreature(ID, aStack.position, true); break; case 5: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; } - creAnims[ID]->setType(2); } else //else for if(aStack.creature->isDoubleWide()) { switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction { case 0: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; case 1: - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 2: - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 3: - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 4: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; case 5: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; } - creAnims[ID]->setType(2); + } + + attackingInfo = new CAttHelper; + attackingInfo->dest = dest; + attackingInfo->frame = 0; + attackingInfo->ID = ID; + attackingInfo->reversing = false; + + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + } } } @@ -729,6 +695,121 @@ void CBattleInterface::showRange(SDL_Surface * to, int ID) } } + +void CBattleInterface::attackingShowHelper() +{ + if(attackingInfo && !attackingInfo->reversing) + { + if(attackingInfo->frame == 0) + { + CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } + } + } + else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) + { + attackingInfo->reversing = true; + CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::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; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::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; + } + } + attackingInfo->reversing = false; + creAnims[attackingInfo->ID]->setType(2); + delete attackingInfo; + attackingInfo = NULL; + } + if(attackingInfo) + { + attackingInfo->frame++; + } + } +} + void CBattleHero::show(SDL_Surface *to) { //animation of flag diff --git a/CBattleInterface.h b/CBattleInterface.h index 1fc55e3b7..8f405071f 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -81,6 +81,16 @@ private: int activeStack; //number of active stack; -1 - no one void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit + class CAttHelper + { + public: + int ID; //attacking stack + int dest; //atacked hex + int frame, maxframe; //frame of animation, number of frames of animation + bool reversing; + } * attackingInfo; + void attackingShowHelper(); + public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor