浏览代码

Move isCastableBy logic back to CGHeroInstance - it is Hero-specific
* When and if canCastThisSpell will also be implmented for creatures common part may be moved to CSpell class.

AlexVinS 10 年之前
父节点
当前提交
9e0fd70208
共有 3 个文件被更改,包括 40 次插入47 次删除
  1. 40 1
      lib/mapObjects/CGHeroInstance.cpp
  2. 0 44
      lib/spells/CSpellHandler.cpp
  3. 0 2
      lib/spells/CSpellHandler.h

+ 40 - 1
lib/mapObjects/CGHeroInstance.cpp

@@ -905,7 +905,46 @@ ui32 CGHeroInstance::getSpellBonus(const CSpell * spell, ui32 base, const CStack
 
 bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
 {
-	return spell->isCastableBy(this, nullptr !=getArt(ArtifactPosition::SPELLBOOK), spells);
+	if(nullptr == getArt(ArtifactPosition::SPELLBOOK))
+		return false;
+
+	const bool isAllowed = IObjectInterface::cb->isAllowed(0, spell->id);
+
+	const bool inSpellBook = vstd::contains(spells, spell->id);
+	const bool specificBonus = hasBonusOfType(Bonus::SPELL, spell->id);
+
+	bool schoolBonus = false;
+
+	spell->forEachSchool([this, &schoolBonus](const SpellSchoolInfo & cnf, bool & stop)
+	{
+		if(hasBonusOfType(cnf.knoledgeBonus))
+		{
+			schoolBonus = stop = true;
+		}
+	});
+
+	const bool levelBonus = hasBonusOfType(Bonus::SPELLS_OF_LEVEL, spell->level);
+
+    if (spell->isSpecialSpell())
+    {
+        if (inSpellBook)
+        {//hero has this spell in spellbook
+            logGlobal->errorStream() << "Special spell " << spell->name << "in spellbook.";
+        }
+        return specificBonus;
+    }
+    else if(!isAllowed)
+    {
+        if (inSpellBook)
+        {//hero has this spell in spellbook
+            logGlobal->errorStream() << "Banned spell " << spell->name << " in spellbook.";
+        }
+        return specificBonus;
+    }
+    else
+    {
+		return inSpellBook || schoolBonus || specificBonus || levelBonus;
+    }
 }
 
 /**

+ 0 - 44
lib/spells/CSpellHandler.cpp

@@ -127,50 +127,6 @@ void CSpell::battleCast(const SpellCastEnvironment * env, BattleSpellCastParamet
 	mechanics->battleCast(env, parameters);
 }
 
-bool CSpell::isCastableBy(const IBonusBearer * caster, bool hasSpellBook, const std::set<SpellID> & spellBook) const
-{
-	if(!hasSpellBook)
-		return false;
-
-	const bool isAllowed = IObjectInterface::cb->isAllowed(0, id);
-
-	const bool inSpellBook = vstd::contains(spellBook, id);
-	const bool specificBonus = caster->hasBonusOfType(Bonus::SPELL, id);
-
-	bool schoolBonus = false;
-
-	forEachSchool([&](const SpellSchoolInfo & cnf, bool & stop)
-	{
-		if(caster->hasBonusOfType(cnf.knoledgeBonus))
-		{
-			schoolBonus = stop = true;
-		}
-	});
-
-	const bool levelBonus = caster->hasBonusOfType(Bonus::SPELLS_OF_LEVEL, level);
-
-    if (isSpecialSpell())
-    {
-        if (inSpellBook)
-        {//hero has this spell in spellbook
-            logGlobal->errorStream() << "Special spell " << name << "in spellbook.";
-        }
-        return specificBonus;
-    }
-    else if(!isAllowed)
-    {
-        if (inSpellBook)
-        {//hero has this spell in spellbook
-            logGlobal->errorStream() << "Banned spell " << name << " in spellbook.";
-        }
-        return specificBonus;
-    }
-    else
-    {
-       return inSpellBook || schoolBonus || specificBonus || levelBonus;
-    }
-}
-
 const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const
 {
 	if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)

+ 0 - 2
lib/spells/CSpellHandler.h

@@ -228,8 +228,6 @@ public:
 	CSpell();
 	~CSpell();
 
-	bool isCastableBy(const IBonusBearer * caster, bool hasSpellBook, const std::set<SpellID> & spellBook) const;
-
 	std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr ) const; //convert range to specific hexes; last optional out parameter is set to true, if spell would cover unavailable hexes (that are not included in ret)
 	ETargetType getTargetType() const; //deprecated