فهرست منبع

* fixed all problems in engine with wide creatures (I hope) (except problem with range of flying wide creatures)

mateuszb 16 سال پیش
والد
کامیت
f582bfde49
5فایلهای تغییر یافته به همراه67 افزوده شده و 33 حذف شده
  1. 33 30
      client/CBattleInterface.cpp
  2. 2 0
      client/CBattleInterface.h
  3. 4 0
      client/CPlayerInterface.cpp
  4. 5 0
      lib/CGameState.cpp
  5. 23 3
      server/CGameHandler.cpp

+ 33 - 30
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; i<creAnims[number]->framesInGroup(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 <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
+	std::pair <int, int> 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; i<creAnims[number]->framesInGroup(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

+ 2 - 0
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

+ 4 - 0
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

+ 5 - 0
lib/CGameState.cpp

@@ -478,6 +478,11 @@ std::pair< std::vector<int>, 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<int>(), 0);
+	}
 
 	//making the Path
 	std::vector<int> path;

+ 23 - 3
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<int> accOc = gs->curB->getAccessibility(curStack->ID, true);
+	for(int b=0; b<BFIELD_SIZE; ++b)
+	{
+		accessibilityWithOccupyable[b] = false;
+	}
+	for(int g=0; g<accOc.size(); ++g)
+	{
+		accessibilityWithOccupyable[accOc[g]] = true;
+	}
+
 	//if(dists[dest] > 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>, int > path = gs->curB->getPath(curStack->position, dest, accessibility, curStack->creature->isFlying(), curStack->creature->isDoubleWide(), curStack->attackerOwned);
+	std::pair< std::vector<int>, 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 "<<curStack->creature->namePl<<std::endl;
+				std::string problem = "We cannot move this stack to its destination " + curStack->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;
 			}