From 5a157290d9ff6ca3d6d0edff52a2eb097c9ac286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 31 Aug 2012 16:33:30 +0000 Subject: [PATCH] Fixed crash occurring after casting Armageddon and killing all stacks. Removed some commented-out code. --- .../CBattleInterfaceClasses.cpp | 11 +- lib/BattleState.cpp | 201 ------------------ lib/CBattleCallback.cpp | 41 +--- 3 files changed, 17 insertions(+), 236 deletions(-) diff --git a/client/BattleInterface/CBattleInterfaceClasses.cpp b/client/BattleInterface/CBattleInterfaceClasses.cpp index b7913bb2d..dff8feecb 100644 --- a/client/BattleInterface/CBattleInterfaceClasses.cpp +++ b/client/BattleInterface/CBattleInterfaceClasses.cpp @@ -614,9 +614,16 @@ void CStackQueue::update() { stacksSorted.clear(); owner->curInt->cb->battleGetStackQueue(stacksSorted, stackBoxes.size()); - for (int i = 0; i < stackBoxes.size() ; i++) + if(stacksSorted.size()) { - stackBoxes[i]->setStack(stacksSorted[i]); + for (int i = 0; i < stackBoxes.size() ; i++) + { + stackBoxes[i]->setStack(stacksSorted[i]); + } + } + else + { + //no stacks on battlefield... what to do with queue? } } diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 98f53f8af..3d23bb6b9 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -36,157 +36,6 @@ const CStack * BattleInfo::getNextStack() const return NULL; } - -// const CStack * BattleInfo::getStackT(BattleHex tileID, bool onlyAlive) const -// { -// return const_cast(this)->getStackT(tileID, onlyAlive); -// } - -// void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool attackerOwned, bool addOccupiable, std::set & occupyable, bool flying, const CStack * stackToOmmit) const -// { -// memset(accessibility, 1, GameConstants::BFIELD_SIZE); //initialize array with trues -// -// //removing accessibility for side columns of hexes -// for(int v = 0; v < GameConstants::BFIELD_SIZE; ++v) -// { -// if( v % GameConstants::BFIELD_WIDTH == 0 || v % GameConstants::BFIELD_WIDTH == (GameConstants::BFIELD_WIDTH - 1) ) -// accessibility[v] = false; -// } -// -// for(ui32 g=0; galive() || (stackToOmmit && stacks[g]->ID==stackToOmmit->ID) || stacks[g]->position < 0) //we don't want to lock position of this stack (eg. if it's a turret) -// continue; -// -// accessibility[stacks[g]->position] = false; -// if(stacks[g]->doubleWide()) //if it's a double hex creature -// { -// if(stacks[g]->attackerOwned) -// accessibility[stacks[g]->position-1] = false; -// else -// accessibility[stacks[g]->position+1] = false; -// } -// } -// //obstacles -// BOOST_FOREACH(const auto &obstacle, obstacles) -// { -// BOOST_FOREACH(BattleHex hex, obstacle->getBlockedTiles()) -// { -// assert(hex.isValid()); -// accessibility[hex] = false; -// } -// } -// -// //walls -// if(siege > 0) -// { -// static const int permanentlyLocked[] = {12, 45, 78, 112, 147, 165}; -// for(int b=0; b lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed -// {std::make_pair(2, BattleHex(182)), std::make_pair(3, BattleHex(130)), -// std::make_pair(4, BattleHex(62)), std::make_pair(5, BattleHex(29))}; -// for(int b=0; b rem; //tiles to unlock -// for(int h=0; h::const_iterator it = rem.begin(); it != rem.end(); ++it) -// { -// accessibility[*it] = true; -// }*/ -// } -// } - -// bool BattleInfo::isAccessible(BattleHex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos) -// { -// if(flying && !lastPos) -// return true; -// -// if(twoHex) -// { -// //if given hex is accessible and appropriate adjacent one is free too -// return accessibility[hex] && accessibility[hex + (attackerOwned ? -1 : 1 )]; -// } -// else -// { -// return accessibility[hex]; -// } -// } - -// void BattleInfo::makeBFS(BattleHex start, bool *accessibility, BattleHex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const //both pointers must point to the at least 187-elements int arrays -// { -// std::set quicksands = getStoppers(!attackerOwned); -// -// //inits -// for(int b=0; b > hexq; //bfs queue (second filed used only if fillPredecessors is true) -// hexq.push(std::make_pair(start, true)); -// dists[hexq.front().first] = 0; -// int curNext = -1; //for bfs loop only (helper var) -// while(!hexq.empty()) //bfs loop -// { -// std::pair curHex = hexq.front(); -// std::vector neighbours = curHex.first.neighbouringTiles(); -// hexq.pop(); -// if(curHex.first != start && !flying && vstd::contains(quicksands, curHex.first)) //walking stack can't step past the quicksands -// continue; -// -// for(ui32 nr=0; nr=dists[curNext]) -// bool accessible = isAccessible(curNext, accessibility, twoHex, attackerOwned, flying, dists[curHex.first]+1 == dists[curNext]); -// if( dists[curHex.first]+1 >= dists[curNext] ) -// continue; -// if(accessible && curHex.second) -// { -// hexq.push(std::make_pair(curNext, true)); -// dists[curNext] = dists[curHex.first] + 1; -// } -// else if(fillPredecessors && !(accessible && !curHex.second)) -// { -// hexq.push(std::make_pair(curNext, false)); -// dists[curNext] = dists[curHex.first] + 1; -// } -// predecessor[curNext] = curHex.first; -// } -// } -// }; -// - BattleHex BattleInfo::getClosestTile(bool attackerOwned, BattleHex initialPos, std::set & possibilities) const { std::vector sortedTiles (possibilities.begin(), possibilities.end()); //set can't be sorted properly :( @@ -460,56 +309,6 @@ CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, bool at return ret; } -// std::pair BattleInfo::getNearestStack(const CStack * closest, boost::logic::tribool attackerOwned) const -// { -// bool ac[GameConstants::BFIELD_SIZE]; -// std::set occupyable; -// -// getAccessibilityMap(ac, closest->doubleWide(), closest->attackerOwned, false, occupyable, closest->hasBonusOfType(Bonus::FLYING), closest); -// -// BattleHex predecessor[GameConstants::BFIELD_SIZE]; -// int dist[GameConstants::BFIELD_SIZE]; -// makeBFS(closest->position, ac, predecessor, dist, closest->doubleWide(), closest->attackerOwned, closest->hasBonusOfType(Bonus::FLYING), true); -// -// std::vector< std::pair< std::pair, const CStack *> > stackPairs; //pairs <, stack> -// for(int g=0; gID == closest->ID) //if there is not stack or we are the closest one -// continue; -// if(boost::logic::indeterminate(attackerOwned) || atG->attackerOwned == attackerOwned) -// { -// if(predecessor[g] == -1) //TODO: is it really the best solution? -// continue; -// stackPairs.push_back( std::make_pair( std::make_pair(dist[predecessor[g]], g), atG) ); -// } -// } -// -// if(stackPairs.size() > 0) -// { -// std::vector< std::pair< std::pair, const CStack *> > minimalPairs; -// minimalPairs.push_back(stackPairs[0]); -// -// for(int b=1; b, const CStack *> minPair = minimalPairs[minimalPairs.size()/2]; -// -// return std::make_pair(minPair.second, predecessor[minPair.first.second]); -// } -// -// return std::make_pair(NULL, BattleHex::INVALID); -// } ui32 BattleInfo::calculateSpellBonus(ui32 baseDamage, const CSpell * sp, const CGHeroInstance * caster, const CStack * affectedCreature) const { ui32 ret = baseDamage; diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 2b5efd20c..3203bedfa 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -405,39 +405,6 @@ si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, BattleHex des return true; } -// std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, BattleHex hex /*= BattleHex::INVALID*/, BattleHex * predecessors /*= NULL*/) -// { -// // FIXME - This method is broken, hex argument is not used. However AI depends on that wrong behaviour. -// -// if(!hex.isValid()) -// hex = stack->position; -// -// std::vector ret(GameConstants::BFIELD_SIZE, -1); //fill initial ret with -1's -// -// if(!hex.isValid()) //stack has bad position? probably castle turret, return initial values (they can't move) -// return ret; -// -// bool ac[GameConstants::BFIELD_SIZE] = {0}; -// std::set occupyable; -// getBattle()->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack); -// BattleHex pr[GameConstants::BFIELD_SIZE]; -// int dist[GameConstants::BFIELD_SIZE]; -// getBattle()->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false); -// -// for(int i=0; i CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos /*= BattleHex::INVALID*/) const { std::set attackedHexes; @@ -564,6 +531,14 @@ void CBattleInfoCallback::battleGetStackQueue(std::vector &out, return; } + auto allStacks = battleGetAllStacks(); + if(!vstd::contains_if(allStacks, [](const CStack *stack) { return stack->willMove(100000); })) //little evil, but 100000 should be enough for all effects to disappear + { + //No stack will be able to move, battle is over. + out.clear(); + return; + } + BOOST_FOREACH(auto s, battleGetAllStacks()) { if((turn <= 0 && !s->willMove()) //we are considering current round and stack won't move