فهرست منبع

* support for new spell: hypnotize

mateuszb 16 سال پیش
والد
کامیت
93f5c83d7c
4فایلهای تغییر یافته به همراه56 افزوده شده و 38 حذف شده
  1. 29 24
      client/CBattleInterface.cpp
  2. 9 9
      client/CPlayerInterface.cpp
  3. 12 3
      client/NetPacksClient.cpp
  4. 6 2
      server/CGameHandler.cpp

+ 29 - 24
client/CBattleInterface.cpp

@@ -1458,7 +1458,7 @@ void CBattleInterface::stackAttacking(int ID, int dest)
 	attackingInfo->frame = 0;
 	attackingInfo->hitCount = 0;
 	attackingInfo->ID = ID;
-	attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID;
+	attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest, false)->ID;
 	attackingInfo->reversing = false;
 	attackingInfo->posShiftDueToDist = reversedShift;
 	attackingInfo->shooting = false;
@@ -1586,7 +1586,7 @@ void CBattleInterface::hexLclicked(int whichOne)
 				endCastingSpell();
 			}
 		}
-		else
+		else //we don't cast any spell
 		{
 			const CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one
 			if(!dest || !dest->alive()) //no creature at that tile
@@ -1617,22 +1617,24 @@ void CBattleInterface::hexLclicked(int whichOne)
 			}
 			else if(dest->owner != attackingHeroInstance->tempOwner) //attacking
 			{
+				const CStack * actStack = LOCPLINT->cb->battleGetStackByID(activeStack);
+				int attackFromHex = -1; //hex from which we will attack chosen stack
 				switch(CGI->curh->number)
 				{
 				case 12: //from bottom right
 					{
 						int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 );
 						if(vstd::contains(shadedHexes, destHex))
-							giveCommand(6,destHex,activeStack,whichOne);
-						else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker
+							attackFromHex = destHex;
+						else if(actStack->attackerOwned) //if we are attacker
 						{
 							if(vstd::contains(shadedHexes, destHex+1))
-								giveCommand(6,destHex+1,activeStack,whichOne);
+								attackFromHex = destHex+1;
 						}
 						else //if we are defneder
 						{
 							if(vstd::contains(shadedHexes, destHex-1))
-								giveCommand(6,destHex-1,activeStack,whichOne);
+								attackFromHex = destHex-1;
 						}
 						break;
 					}
@@ -1640,16 +1642,16 @@ void CBattleInterface::hexLclicked(int whichOne)
 					{
 						int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH );
 						if(vstd::contains(shadedHexes, destHex))
-							giveCommand(6,destHex,activeStack,whichOne);
-						else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker
+							attackFromHex = destHex;
+						else if(actStack->attackerOwned) //if we are attacker
 						{
 							if(vstd::contains(shadedHexes, destHex+1))
-								giveCommand(6,destHex+1,activeStack,whichOne);
+								attackFromHex = destHex+1;
 						}
 						else //if we are defneder
 						{
 							if(vstd::contains(shadedHexes, destHex-1))
-								giveCommand(6,destHex-1,activeStack,whichOne);
+								attackFromHex = destHex-1;
 						}
 						break;
 					}
@@ -1658,29 +1660,29 @@ void CBattleInterface::hexLclicked(int whichOne)
 					{
 						std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
 						if(vstd::contains(acc, whichOne))
-							giveCommand(6,whichOne - 1,activeStack,whichOne);
+							attackFromHex = whichOne - 1;
 						else
-							giveCommand(6,whichOne - 2,activeStack,whichOne);
+							attackFromHex = whichOne - 2;
 					}
 					else
 					{
-						giveCommand(6,whichOne - 1,activeStack,whichOne);
+						attackFromHex = whichOne - 1;
 					}
 					break;
 				case 9: //from top left
 					{
 						int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH );
 						if(vstd::contains(shadedHexes, destHex))
-							giveCommand(6,destHex,activeStack,whichOne);
-						else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker
+							attackFromHex = destHex;
+						else if(actStack->attackerOwned) //if we are attacker
 						{
 							if(vstd::contains(shadedHexes, destHex+1))
-								giveCommand(6,destHex+1,activeStack,whichOne);
+								attackFromHex = destHex+1;
 						}
 						else //if we are defneder
 						{
 							if(vstd::contains(shadedHexes, destHex-1))
-								giveCommand(6,destHex-1,activeStack,whichOne);
+								attackFromHex = destHex-1;
 						}
 						break;
 					}
@@ -1688,16 +1690,16 @@ void CBattleInterface::hexLclicked(int whichOne)
 					{
 						int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 );
 						if(vstd::contains(shadedHexes, destHex))
-							giveCommand(6,destHex,activeStack,whichOne);
-						else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker
+							attackFromHex = destHex;
+						else if(actStack->attackerOwned) //if we are attacker
 						{
 							if(vstd::contains(shadedHexes, destHex+1))
-								giveCommand(6,destHex+1,activeStack,whichOne);
+								attackFromHex = destHex+1;
 						}
 						else //if we are defneder
 						{
 							if(vstd::contains(shadedHexes, destHex-1))
-								giveCommand(6,destHex-1,activeStack,whichOne);
+								attackFromHex = destHex-1;
 						}
 						break;
 					}
@@ -1706,16 +1708,19 @@ void CBattleInterface::hexLclicked(int whichOne)
 					{
 						std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
 						if(vstd::contains(acc, whichOne))
-							giveCommand(6,whichOne + 1,activeStack,whichOne);
+							attackFromHex = whichOne + 1;
 						else
-							giveCommand(6,whichOne + 2,activeStack,whichOne);
+							attackFromHex = whichOne + 2;
 					}
 					else
 					{
-						giveCommand(6,whichOne + 1,activeStack,whichOne);
+						attackFromHex = whichOne + 1;
 					}
 					break;
 				}
+
+				giveCommand(6, attackFromHex, activeStack, whichOne);
+
 				CGI->curh->changeGraphic(1, 6); //cursor should be changed
 			}
 		}

+ 9 - 9
client/CPlayerInterface.cpp

@@ -1170,15 +1170,15 @@ void CPlayerInterface::battleAttack(BattleAttack *ba)
 	else
 	{
 		const CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
-		int shift = 0;		
-		if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)		
-		{			
-			if(attacker->attackerOwned)				
-				shift = 1;			
-			else				
-				shift = -1;		
-		}		
-		battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo );	
+		int shift = 0;
+		if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
+		{
+			if( BattleInfo::mutualPosition(curAction->destinationTile + 1, attacker->position) >= 0 )
+				shift = 1;
+			else
+				shift = -1;
+		}
+		battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo );
 	}
 }
 

+ 12 - 3
client/NetPacksClient.cpp

@@ -349,9 +349,18 @@ void BattleNextRound::applyCl( CClient *cl )
 
 void BattleSetActiveStack::applyCl( CClient *cl )
 {
-	int owner = GS(cl)->curB->getStack(stack)->owner;
-	if(vstd::contains(cl->playerint,owner))
-		boost::thread(boost::bind(&CClient::waitForMoveAndSend,cl,owner));
+	CStack * activated = GS(cl)->curB->getStack(stack);
+	int playerToCall = -1; //player that will move activated stack
+	if( activated->hasFeatureOfType(StackFeature::HYPNOTIZED) )
+	{
+		playerToCall = ( GS(cl)->curB->side1 == activated->owner ? GS(cl)->curB->side2 : GS(cl)->curB->side1 );
+	}
+	else
+	{
+		playerToCall = activated->owner;
+	}
+	if( vstd::contains(cl->playerint, playerToCall) )
+		boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );
 }
 
 void BattleResult::applyFirstCl( CClient *cl )

+ 6 - 2
server/CGameHandler.cpp

@@ -2316,7 +2316,11 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 			CStack *curStack = gs->curB->getStack(ba.stackNumber),
 				*stackAtEnd = gs->curB->getStackT(ba.additionalInfo);
 
-			if(curStack->position != ba.destinationTile) //we wasn't able to reach destination tile
+			if(curStack->position != ba.destinationTile //we wasn't able to reach destination tile
+				&& !(curStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE)
+					&&  ( curStack->position == ba.destinationTile + (curStack->attackerOwned ?  +1 : -1 ) )
+						) //nor occupy specified hex
+				) 
 			{
 				std::string problem = "We cannot move this stack to its destination " + curStack->creature->namePl;
 				tlog3 << problem << std::endl;
@@ -2703,7 +2707,7 @@ static std::vector<ui32> calculateResistedStacks(const CSpell * sp, const CGHero
 		for(std::set<CStack*>::const_iterator it = affectedCreatures.begin(); it != affectedCreatures.end(); ++it)
 		{
 			if( (*it)->hasFeatureOfType(StackFeature::SPELL_IMMUNITY, sp->id) //100% sure spell immunity
-				|| (*it)->amount * (*it)->MaxHealth() + (*it)->firstHPleft 
+				|| ( (*it)->amount - 1 ) * (*it)->MaxHealth() + (*it)->firstHPleft 
 				> 
 				caster->getPrimSkillLevel(2) * 25 + sp->powers[caster->getSpellSchoolLevel(sp)]
 			)