From f582bfde49a33cc90ab9286e6759de9d2f43b646 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Mon, 3 Aug 2009 14:29:29 +0000 Subject: [PATCH] * fixed all problems in engine with wide creatures (I hope) (except problem with range of flying wide creatures) --- client/CBattleInterface.cpp | 63 +++++++++++++++++++------------------ client/CBattleInterface.h | 2 ++ client/CPlayerInterface.cpp | 4 +++ lib/CGameState.cpp | 5 +++ server/CGameHandler.cpp | 26 +++++++++++++-- 5 files changed, 67 insertions(+), 33 deletions(-) diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index c8fab4fa3..d5c091920 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -1134,41 +1134,16 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving, int d SDL_framerateDelay(LOCPLINT->mainFPSmng); } //unit moved - - if(endMoving) //animation of ending move + if(endMoving) { - if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier) - { - if (movedStack->creature->sounds.endMoving) { - CGI->soundh->playSound(movedStack->creature->sounds.endMoving); - } - - creAnims[number]->setType(21); - - //for(int i=0; iframesInGroup(21)*getAnimSpeedMultiplier()-1; ++i) - while(!creAnims[number]->onLastFrameInGroup()) - { - show(screen); - CSDL_Ext::update(screen); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } - } - creAnims[number]->setType(2); //resetting to default - CGI->curh->show(); - CGI->soundh->stopSound(moveSh); + handleEndOfMove(number, destHex); } - 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); + std::pair coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], movedStack->creature); creAnims[number]->pos.x = coords.first; - if(!endMoving && twoTiles && (curs.owner == attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed + if(!endMoving && twoTiles && (movedStack->owner == attackingHeroInstance->tempOwner) && (creDir[number] != (movedStack->owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed creAnims[number]->pos.x -= 44; - else if(!endMoving && twoTiles && (curs.owner != attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big defender creature is reversed + else if(!endMoving && twoTiles && (movedStack->owner != attackingHeroInstance->tempOwner) && (creDir[number] != (movedStack->owner == attackingHeroInstance->tempOwner))) //big defender creature is reversed creAnims[number]->pos.x += 44; creAnims[number]->pos.y = coords.second; } @@ -1474,6 +1449,34 @@ bool CBattleInterface::isTileAttackable(const int & number) const return false; } +void CBattleInterface::handleEndOfMove(int stackNumber, int destinationTile) +{ + CStack * movedStack = LOCPLINT->cb->battleGetStackByID(stackNumber); + if(creAnims[stackNumber]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier) + { + if (movedStack->creature->sounds.endMoving) + { + CGI->soundh->playSound(movedStack->creature->sounds.endMoving); + } + + creAnims[stackNumber]->setType(21); + + //for(int i=0; iframesInGroup(21)*getAnimSpeedMultiplier()-1; ++i) + while(!creAnims[stackNumber]->onLastFrameInGroup()) + { + show(screen); + CSDL_Ext::update(screen); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + } + creAnims[stackNumber]->setType(2); //resetting to default + CGI->curh->show(); + CGI->soundh->stopSound(moveSh); + + if(creDir[stackNumber] != (movedStack->owner == attackingHeroInstance->tempOwner)) + reverseCreature(stackNumber, destinationTile, movedStack->creature->isDoubleWide()); +} + void CBattleInterface::hexLclicked(int whichOne) { if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack diff --git a/client/CBattleInterface.h b/client/CBattleInterface.h index 9a04f590d..89914be68 100644 --- a/client/CBattleInterface.h +++ b/client/CBattleInterface.h @@ -215,6 +215,8 @@ private: void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1); bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles + void handleEndOfMove(int stackNumber, int destinationTile); //helper function + struct SBattleEffect { int x, y; //position on the screen diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index cac3bc31a..108ffa75d 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1240,6 +1240,10 @@ void CPlayerInterface::actionFinished(const BattleAction* action) else battleInt->attackingHero->setPhase(0); } + if(action->actionType == 6 || action->actionType == 2 && battleInt->creAnims[action->stackNumber]->getType() != 2) //walk or walk & attack + { + battleInt->handleEndOfMove(action->stackNumber, action->destinationTile); + } } BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index ea42def08..df279ee93 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -478,6 +478,11 @@ std::pair< std::vector, int > BattleInfo::getPath(int start, int dest, bool { makeBFS(start, accessibility, predecessor, dist, twoHex, attackerOwned); } + + if(predecessor[dest] == -1) //cannot reach destination + { + return std::make_pair(std::vector(), 0); + } //making the Path std::vector path; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index c00215779..447f007da 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -570,10 +570,21 @@ void CGameHandler::moveStack(int stack, int dest) if((stackAtEnd && stackAtEnd!=curStack && stackAtEnd->alive()) || !accessibility[dest]) return; + bool accessibilityWithOccupyable[BFIELD_SIZE]; + std::vector accOc = gs->curB->getAccessibility(curStack->ID, true); + for(int b=0; b curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex // return false; - std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibility, curStack->creature->isFlying(), curStack->creature->isDoubleWide(), curStack->attackerOwned); + std::pair< std::vector, int > path = gs->curB->getPath(curStack->position, dest, accessibilityWithOccupyable, curStack->creature->isFlying(), curStack->creature->isDoubleWide(), curStack->attackerOwned); if(curStack->creature->isFlying()) { if(path.second <= curStack->Speed() && path.first.size() > 0) @@ -2306,8 +2317,12 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) if(curStack->position != ba.destinationTile) //we wasn't able to reach destination tile { - tlog3<<"We cannot move this stack to its destination "<creature->namePl<creature->namePl; + tlog3 << problem << std::endl; + complain(problem); ok = false; + sendAndApply(&EndAction()); + break; } if(curStack->ID == stackAtEnd->ID) //we should just move, it will be handled by following check @@ -2317,8 +2332,13 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) if(!stackAtEnd) { - tlog3 << "There is no stack on " << ba.additionalInfo << " tile (no attack)!"; + std::ostringstream problem; + problem << "There is no stack on " << ba.additionalInfo << " tile (no attack)!"; + std::string probl = problem.str(); + tlog3 << probl << std::endl; + complain(probl); ok = false; + sendAndApply(&EndAction()); break; }