소스 검색

Move TargetInfo initialization to constructor

AlexVinS 11 년 전
부모
커밋
b62ee20880
2개의 변경된 파일39개의 추가작업 그리고 30개의 파일을 삭제
  1. 32 29
      lib/CSpellHandler.cpp
  2. 7 1
      lib/CSpellHandler.h

+ 32 - 29
lib/CSpellHandler.cpp

@@ -388,7 +388,7 @@ std::set<const CStack* > CSpell::getAffectedStacks(const CBattleInfoCallback * c
 	const ui8 attackerSide = cb->playerToSide(casterColor) == 1;
 	const auto attackedHexes = rangeInHexes(destination, spellLvl, attackerSide);
 	
-	const CSpell::TargetInfo ti = getTargetInfoEx(spellLvl, mode);
+	const CSpell::TargetInfo ti(this, spellLvl, mode);
 	
 	
 	//TODO: more generic solution for mass spells
@@ -506,37 +506,10 @@ CSpell::ETargetType CSpell::getTargetType() const
 
 CSpell::TargetInfo CSpell::getTargetInfo(const int level) const
 {
-	TargetInfo info;
-
-	auto & levelInfo = getLevelInfo(level);
-
-	info.type = getTargetType();
-	info.smart = levelInfo.smartTarget;
-	info.massive = levelInfo.range == "X";
-	info.onlyAlive = !isRisingSpell();
-	info.alwaysHitDirectly = false;
-
-	return info;
-}
-
-CSpell::TargetInfo CSpell::getTargetInfoEx(const int level, ECastingMode::ECastingMode mode) const
-{
-	TargetInfo info = getTargetInfo(level);
-
-	if(mode == ECastingMode::ENCHANTER_CASTING)
-	{
-		info.smart = true; //FIXME: not sure about that, this makes all spells smart in this mode
-		info.massive = true;
-	}
-	else if(mode == ECastingMode::SPELL_LIKE_ATTACK)
-	{
-		info.alwaysHitDirectly = true;
-	}
-	
+	TargetInfo info(this, level);
 	return info;
 }
 
-
 bool CSpell::isCombatSpell() const
 {
 	return combatSpell;
@@ -807,6 +780,36 @@ void CSpell::setupMechanics()
 	
 }
 
+///CSpell::TargetInfo
+CSpell::TargetInfo::TargetInfo(const CSpell * spell, const int level)
+{
+	init(spell, level);
+}
+
+CSpell::TargetInfo::TargetInfo(const CSpell * spell, const int level, ECastingMode::ECastingMode mode)
+{
+	init(spell, level);
+	if(mode == ECastingMode::ENCHANTER_CASTING)
+	{
+		smart = true; //FIXME: not sure about that, this makes all spells smart in this mode
+		massive = true;
+	}
+	else if(mode == ECastingMode::SPELL_LIKE_ATTACK)
+	{
+		alwaysHitDirectly = true;
+	}	
+}
+
+void CSpell::TargetInfo::init(const CSpell * spell, const int level)
+{
+	auto & levelInfo = spell->getLevelInfo(level);
+
+	type = spell->getTargetType();
+	smart = levelInfo.smartTarget;
+	massive = levelInfo.range == "X";
+	onlyAlive = !spell->isRisingSpell();
+	alwaysHitDirectly = false;	
+}
 
 
 bool DLL_LINKAGE isInScreenRange(const int3 &center, const int3 &pos)

+ 7 - 1
lib/CSpellHandler.h

@@ -135,6 +135,12 @@ public:
 		bool onlyAlive;
 		///no immunity on primary target (mostly spell-like attack)
 		bool alwaysHitDirectly;
+		
+		TargetInfo(const CSpell * spell, const int level);
+		TargetInfo(const CSpell * spell, const int level, ECastingMode::ECastingMode mode);
+		
+	private:
+		void init(const CSpell * spell, const int level);
 	};
 
 	SpellID id;
@@ -167,7 +173,7 @@ public:
 	ETargetType getTargetType() const; //deprecated
 
 	CSpell::TargetInfo getTargetInfo(const int level) const;
-	CSpell::TargetInfo getTargetInfoEx(const int level, ECastingMode::ECastingMode mode) const;
+
 
 	bool isCombatSpell() const;
 	bool isAdventureSpell() const;