mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Move TargetInfo initialization to constructor
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
| 	TargetInfo info(this, level); | ||||
| 	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; | ||||
| 	} | ||||
| 	 | ||||
| 	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 ¢er, const int3 &pos) | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user