Browse Source

* when active stack is killed by spell, game behaves properly

mateuszb 16 years ago
parent
commit
540e15d4ea
2 changed files with 21 additions and 14 deletions
  1. 16 13
      client/CBattleInterface.cpp
  2. 5 1
      server/CGameHandler.cpp

+ 16 - 13
client/CBattleInterface.cpp

@@ -1870,7 +1870,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 						console->whoSetAlter = 0;
 					}
 				}
-				else if( sactive->hasFeatureOfType(StackFeature::CATAPULT) && isCatapultAttackable(myNumber) ) //catapulting
+				else if( sactive && sactive->hasFeatureOfType(StackFeature::CATAPULT) && isCatapultAttackable(myNumber) ) //catapulting
 				{
 					CGI->curh->changeGraphic(1,16);
 					console->alterTxt = "";
@@ -1887,20 +1887,23 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 			{
 				//setting console text and cursor
 				const CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack);
-				char buf[500];
-				if(LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::FLYING))
-				{
-					CGI->curh->changeGraphic(1,2);
-					sprintf(buf, CGI->generaltexth->allTexts[295].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
-				}
-				else
+				if(sactive) //there can be a moment when stack is dead ut next is not yet activated
 				{
-					CGI->curh->changeGraphic(1,1);
-					sprintf(buf, CGI->generaltexth->allTexts[294].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
-				}
+					char buf[500];
+					if(sactive->hasFeatureOfType(StackFeature::FLYING))
+					{
+						CGI->curh->changeGraphic(1,2);
+						sprintf(buf, CGI->generaltexth->allTexts[295].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
+					}
+					else
+					{
+						CGI->curh->changeGraphic(1,1);
+						sprintf(buf, CGI->generaltexth->allTexts[294].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
+					}
 
-				console->alterTxt = buf;
-				console->whoSetAlter = 0;
+					console->alterTxt = buf;
+					console->whoSetAlter = 0;
+				}
 			}
 		}
 	}

+ 5 - 1
server/CGameHandler.cpp

@@ -443,7 +443,7 @@ askInterfaceForMove:
 				sas.stack = next->ID;
 				sendAndApply(&sas);
 				boost::unique_lock<boost::mutex> lock(battleMadeAction.mx);
-				while(!battleMadeAction.data  &&  !battleResult.get()) //active stack hasn't made its action and battle is still going
+				while(next->alive() && (!battleMadeAction.data  &&  !battleResult.get())) //active stack hasn't made its action and battle is still going
 					battleMadeAction.cond.wait(lock);
 				battleMadeAction.data = false;
 			}
@@ -3163,6 +3163,10 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
 				}
 			}
 			sendAndApply(&EndAction());
+			if( !gs->curB->getStack(gs->curB->activeStack, false)->alive() )
+			{
+				battleMadeAction.setn(true);
+			}
 			checkForBattleEnd(gs->curB->stacks);
 			if(battleResult.get())
 			{