浏览代码

Removed object recycling that was causing #796. Fixed text nr typo.
Corrected json include in client/Client.cpp.

Michał W. Urbańczyk 14 年之前
父节点
当前提交
20a53b04fd
共有 5 个文件被更改,包括 31 次插入18 次删除
  1. 1 1
      client/CPlayerInterface.cpp
  2. 1 1
      client/Client.cpp
  3. 8 0
      lib/BattleState.cpp
  4. 1 0
      lib/BattleState.h
  5. 20 16
      server/CGameHandler.cpp

+ 1 - 1
client/CPlayerInterface.cpp

@@ -850,7 +850,7 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba)
 	if (ba->deathBlow())
 	{
 		const CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
-		std::string hlp = CGI->generaltexth->allTexts[(stack->count != 1) ? 336 : 335];
+		std::string hlp = CGI->generaltexth->allTexts[(stack->count != 1) ? 366 : 365];
 		boost::algorithm::replace_first(hlp,"%s", (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str());
 		battleInt->console->addText(hlp);
 		for (std::vector<BattleStackAttacked>::const_iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)

+ 1 - 1
client/Client.cpp

@@ -20,7 +20,7 @@
 #include "../lib/NetPacks.h"
 #include "../lib/VCMI_Lib.h"
 #include "../lib/map.h"
-#include "../lib/JsonNode.cpp"
+#include "../lib/JsonNode.h"
 #include "mapHandler.h"
 #include "CConfigHandler.h"
 #include "Client.h"

+ 8 - 0
lib/BattleState.cpp

@@ -2562,6 +2562,14 @@ bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defen
 		
 }
 
+bool CStack::ableToRetaliate() const
+{
+	return alive() 
+		&& (counterAttacks > 0 || hasBonusOfType(Bonus::UNLIMITED_RETALIATIONS))
+		&& !hasBonusOfType(Bonus::SIEGE_WEAPON)
+		&& !hasBonusOfType(Bonus::HYPNOTIZED);
+}
+
 bool CMP_stack::operator()( const CStack* a, const CStack* b )
 {
 	switch(phase)

+ 1 - 0
lib/BattleState.h

@@ -161,6 +161,7 @@ public:
 	const Bonus * getEffect(ui16 id, int turn = 0) const; //effect id (SP)
 	ui8 howManyEffectsSet(ui16 id) const; //returns amount of effects with given id set for this stack
 	bool willMove(int turn = 0) const; //if stack has remaining move this turn
+	bool ableToRetaliate() const; //if stack can retaliate after attacked
 	bool moved(int turn = 0) const; //if stack was already moved this turn
 	bool canMove(int turn = 0) const; //if stack can move
 	ui32 Speed(int turn = 0) const; //get speed of creature with all modificators

+ 20 - 16
server/CGameHandler.cpp

@@ -3055,19 +3055,19 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 			}
 
 			//attack
-			BattleAttack bat;
-			prepareAttack(bat, curStack, stackAtEnd, distance, ba.additionalInfo);
-			handleAttackBeforeCasting(bat); //only before first attack
-			sendAndApply(&bat);
-			handleAfterAttackCasting(bat);
+			{
+				BattleAttack bat;
+				prepareAttack(bat, curStack, stackAtEnd, distance, ba.additionalInfo);
+				handleAttackBeforeCasting(bat); //only before first attack
+				sendAndApply(&bat);
+				handleAfterAttackCasting(bat);
+			}
 
 			//counterattack
 			if(!curStack->hasBonusOfType(Bonus::BLOCKS_RETALIATION)
-				&& stackAtEnd->alive()
-				&& ( stackAtEnd->counterAttacks > 0 || stackAtEnd->hasBonusOfType(Bonus::UNLIMITED_RETALIATIONS) )
-				&& !stackAtEnd->hasBonusOfType(Bonus::SIEGE_WEAPON)
-				&& !stackAtEnd->hasBonusOfType(Bonus::HYPNOTIZED))
+				&& stackAtEnd->ableToRetaliate())
 			{
+				BattleAttack bat;
 				prepareAttack(bat, stackAtEnd, curStack, 0, curStack->position);
 				bat.flags |= BattleAttack::COUNTER;
 				sendAndApply(&bat);
@@ -3080,7 +3080,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 				&& curStack->alive()
 				&& stackAtEnd->alive()  )
 			{
-				bat.flags = 0;
+				BattleAttack bat;
 				prepareAttack(bat, curStack, stackAtEnd, 0, ba.additionalInfo);
 				sendAndApply(&bat);
 				handleAfterAttackCasting(bat);
@@ -3105,12 +3105,14 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 			StartAction start_action(ba);
 			sendAndApply(&start_action); //start shooting
 
-			BattleAttack bat;
-			bat.flags |= BattleAttack::SHOT;
-			prepareAttack(bat, curStack, destStack, 0, ba.destinationTile);
-			handleAttackBeforeCasting(bat);
-			sendAndApply(&bat);
-			handleAfterAttackCasting(bat);
+			{
+				BattleAttack bat;
+				bat.flags |= BattleAttack::SHOT;
+				prepareAttack(bat, curStack, destStack, 0, ba.destinationTile);
+				handleAttackBeforeCasting(bat);
+				sendAndApply(&bat);
+				handleAfterAttackCasting(bat);
+			}
 
 			//ballista & artillery handling
 			if(destStack->alive() && curStack->getCreature()->idNumber == 146)
@@ -3127,6 +3129,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 				&& curStack->shots
 				)
 			{
+				BattleAttack bat;
+				bat.flags |= BattleAttack::SHOT;
 				prepareAttack(bat, curStack, destStack, 0, ba.destinationTile);
 				sendAndApply(&bat);
 				handleAfterAttackCasting(bat);