瀏覽代碼

* cleaner code is better :)

mateuszb 14 年之前
父節點
當前提交
aac1c0b4e7
共有 5 個文件被更改,包括 10 次插入23 次删除
  1. 6 19
      lib/BattleState.cpp
  2. 1 1
      lib/BattleState.h
  3. 1 1
      lib/NetPacks.h
  4. 1 1
      server/CGameHandler.cpp
  5. 1 1
      server/CGameHandler.h

+ 6 - 19
lib/BattleState.cpp

@@ -2280,29 +2280,16 @@ 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));
-	}
+	THex occupied = occupiedHex();
+	if(occupied.isValid())
+		hexes.push_back(occupied);
+
 	return hexes;
 }
 
-bool CStack::coversPos(ui16 pos) const
+bool CStack::coversPos(THex pos) const
 {
-	if (pos == position)
-		return true;
-	if (doubleWide())
-	{
-		if (attackerOwned)
-			return (pos == position - 1);
-		else
-			return (pos == position + 1);
-	} 
-	else
-		return false;
+	return vstd::contains(getHexes(), pos);
 }
 
 std::vector<si32> CStack::activeSpells() const

+ 1 - 1
lib/BattleState.h

@@ -184,7 +184,7 @@ 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
+	bool coversPos(THex position) const; //checks also if unit is double-wide
 
 	void prepareAttacked(BattleStackAttacked &bsa) const; //requires bsa.damageAmout filled
 

+ 1 - 1
lib/NetPacks.h

@@ -1372,7 +1372,7 @@ struct BattleSpellCast : public CPackForClient//3009
 	ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
 	ui32 id; //id of spell
 	ui8 skill; //caster's skill level
-	ui16 tile; //destination tile (may not be set in some global/mass spells
+	THex tile; //destination tile (may not be set in some global/mass spells
 	std::vector<ui32> resisted; //ids of creatures that resisted this spell
 	std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
 	TCreature attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact)

+ 1 - 1
server/CGameHandler.cpp

@@ -3433,7 +3433,7 @@ void CGameHandler::playerMessage( ui8 player, const std::string &message )
 	}
 }
 
-void CGameHandler::handleSpellCasting( int spellID, int spellLvl, int destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack)
+void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack)
 {
 	const CSpell *spell = VLC->spellh->spells[spellID];
 

+ 1 - 1
server/CGameHandler.h

@@ -193,7 +193,7 @@ public:
 
 	void playerMessage( ui8 player, const std::string &message);
 	bool makeBattleAction(BattleAction &ba);
-	void handleSpellCasting(int spellID, int spellLvl, int destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack);
+	void handleSpellCasting(int spellID, int spellLvl, THex destination, ui8 casterSide, ui8 casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, int usedSpellPower, SpellCasting::ECastingMode mode, const CStack * stack);
 	bool makeCustomAction(BattleAction &ba);
 	bool queryReply( ui32 qid, ui32 answer );
 	bool hireHero( const CGObjectInstance *obj, ui8 hid, ui8 player );