Jelajahi Sumber

Improvement for multiple-hex effects.

TODO: Attacker must know exact attacked tile, not only the stack.
DjWarmonger 14 tahun lalu
induk
melakukan
57a36e77f3
4 mengubah file dengan 38 tambahan dan 4 penghapusan
  1. 1 1
      client/CPlayerInterface.cpp
  2. 29 0
      lib/BattleState.cpp
  3. 2 0
      lib/BattleState.h
  4. 6 3
      server/CGameHandler.cpp

+ 1 - 1
client/CPlayerInterface.cpp

@@ -792,7 +792,7 @@ void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacke
 		const CStack *attacker = cb->battleGetStackByID(i->attackerID, false);
 		if(i->isEffect() && i->effect != 12) //and not armageddon
 		{
-			if (defender != NULL)
+			if (defender && !i->isSecondary())
 				battleInt->displayEffect(i->effect, defender->position);
 		}
 		SStackAttackedInfo to_put = {defender, i->damageAmount, i->killedAmount, attacker, LOCPLINT->curAction->actionType==7, i->killed()};

+ 29 - 0
lib/BattleState.cpp

@@ -2276,6 +2276,35 @@ THex CStack::occupiedHex() const
 	}
 }
 
+std::vector<THex> CStack::getHexes() const
+{
+	std::vector<THex> hexes;
+	hexes.push_back(THex(position));
+	if (doubleWide())
+	{
+		if (attackerOwned)
+			hexes.push_back(THex(position - 1));
+		else
+			hexes.push_back(THex(position + 1));
+	}
+	return hexes;
+}
+
+bool CStack::coversPos(ui16 pos) const
+{
+	if (pos == position)
+		return true;
+	if (doubleWide())
+	{
+		if (attackerOwned)
+			return (pos == position - 1);
+		else
+			return (pos == position + 1);
+	} 
+	else
+		return false;
+}
+
 std::vector<si32> CStack::activeSpells() const
 {
 	std::vector<si32> ret;

+ 2 - 0
lib/BattleState.h

@@ -183,6 +183,8 @@ public:
 
 	bool doubleWide() const;
 	THex occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1
+	std::vector<THex> getHexes() const; //up to two occupied hexes, starting from front
+	bool coversPos(ui16 position) const; //checks also if unit is double-wide
 
 	void prepareAttacked(BattleStackAttacked &bsa) const; //requires bsa.damageAmout filled
 

+ 6 - 3
server/CGameHandler.cpp

@@ -551,6 +551,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CSt
 
 		BattleStackAttacked bss = *bsa; // copy some parameters, such as attacker
 		std::set<CStack*> attackedCreatures = gs->curB->getAttackedCreatures(VLC->spellh->spells[bonus->subtype], bonus->val, att->owner, def->position);
+		//TODO: get exact attacked hex for defender
 
 		BOOST_FOREACH(CStack * stack, attackedCreatures)
 		{
@@ -3492,9 +3493,11 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, int destinatio
 					continue;
 
 				BattleStackAttacked bsa;
-				//TODO: display effect only upon primary target of area spell
-				bsa.flags |= BattleStackAttacked::EFFECT;
-				bsa.effect = spell->mainEffectAnim;
+				if (destination > -1 && (*it)->coversPos(destination)) //display effect only upon primary target of area spell
+				{
+					bsa.flags |= BattleStackAttacked::EFFECT;
+					bsa.effect = spell->mainEffectAnim;
+				}
 				bsa.damageAmount = gs->curB->calculateSpellDmg(spell, caster, *it, spellLvl, usedSpellPower);
 				bsa.stackAttacked = (*it)->ID;
 				bsa.attackerID = -1;