Browse Source

Implemented #1379
+ added new flag for special spells. Special spells can be obtained only with BONUS::SPELL.
* made Titans` thunder special.

alexvins 11 years ago
parent
commit
afcb7072eb
5 changed files with 43 additions and 13 deletions
  1. 4 0
      config/schemas/spell.json
  2. 2 1
      config/spell_info.json
  3. 26 11
      lib/CObjectHandler.cpp
  4. 1 1
      lib/CSpellHandler.cpp
  5. 10 0
      lib/CSpellHandler.h

+ 4 - 0
config/schemas/spell.json

@@ -150,6 +150,10 @@
                                 "rising":{
                                         "type":"boolean",
                                         "description": "Rising spell (implicitly sets positive)"
+                                },
+                                "special":{
+                                        "type": "boolean",
+                                        "description": "Special spell. Can be given only by Bonus::SPELL"
                                 }
                         }
                 },

+ 2 - 1
config/spell_info.json

@@ -2170,7 +2170,8 @@
 		"flags" : {
 			"damage": true,
 			"offensive": true,
-			"negative": true
+			"negative": true,
+                        "special": true
 		}
 	},
 	"counterstrike" : {

+ 26 - 11
lib/CObjectHandler.cpp

@@ -1375,17 +1375,32 @@ bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
 	if(!getArt(ArtifactPosition::SPELLBOOK)) //if hero has no spellbook
 		return false;
 
-	if(vstd::contains(spells, spell->id) //hero has this spell in spellbook
-		|| (spell->air && hasBonusOfType(Bonus::AIR_SPELLS)) // this is air spell and hero can cast all air spells
-		|| (spell->fire && hasBonusOfType(Bonus::FIRE_SPELLS)) // this is fire spell and hero can cast all fire spells
-		|| (spell->water && hasBonusOfType(Bonus::WATER_SPELLS)) // this is water spell and hero can cast all water spells
-		|| (spell->earth && hasBonusOfType(Bonus::EARTH_SPELLS)) // this is earth spell and hero can cast all earth spells
-		|| hasBonusOfType(Bonus::SPELL, spell->id)
-		|| hasBonusOfType(Bonus::SPELLS_OF_LEVEL, spell->level)
-		)
-		return true;
-
-	return false;
+    if (spell->isSpecialSpell())
+    {
+        if (vstd::contains(spells, spell->id))
+        {//hero has this spell in spellbook
+            logGlobal->errorStream() << "Special spell in spellbook "<<spell->name;
+        }
+
+        if (hasBonusOfType(Bonus::SPELL, spell->id))
+            return true;
+
+        return false;
+    }
+    else
+    {
+        if(vstd::contains(spells, spell->id) //hero has this spell in spellbook
+            || (spell->air && hasBonusOfType(Bonus::AIR_SPELLS)) // this is air spell and hero can cast all air spells
+            || (spell->fire && hasBonusOfType(Bonus::FIRE_SPELLS)) // this is fire spell and hero can cast all fire spells
+            || (spell->water && hasBonusOfType(Bonus::WATER_SPELLS)) // this is water spell and hero can cast all water spells
+            || (spell->earth && hasBonusOfType(Bonus::EARTH_SPELLS)) // this is earth spell and hero can cast all earth spells
+            || hasBonusOfType(Bonus::SPELL, spell->id)
+            || hasBonusOfType(Bonus::SPELLS_OF_LEVEL, spell->level)
+            )
+            return true;
+
+        return false;
+    }
 }
 
 /**

+ 1 - 1
lib/CSpellHandler.cpp

@@ -701,7 +701,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
         logGlobal->errorStream() << "No positiveness specified, assumed NEUTRAL";
     }
 
-
+    spell->isSpecial = readFlag(flags,"special");
 
     auto find_in_map = [&](std::string name, std::vector<Bonus::BonusType> &vec)
     {

+ 10 - 0
lib/CSpellHandler.h

@@ -76,6 +76,8 @@ public:
 	inline bool isDamageSpell() const;
 	inline bool isOffensiveSpell() const;
 
+	inline bool isSpecialSpell() const;
+
 	inline bool hasEffects() const;
 	void getEffects(std::vector<Bonus> &lst, const int level) const;
 
@@ -110,6 +112,8 @@ public:
 		h & effects & immunities & limiters;
 		h & iconImmune;
         h & absoluteImmunities & defaultProbability;
+
+        h & isSpecial;
 	}
 	friend class CSpellHandler;
 
@@ -127,6 +131,7 @@ private:
 	bool isRising;
 	bool isDamage;
 	bool isOffensive;
+	bool isSpecial;
 
 	std::string attributes; //reference only attributes //todo: remove or include in configuration format, currently unused
 
@@ -189,6 +194,11 @@ bool CSpell::isOffensiveSpell() const
 	return isOffensive;
 }
 
+bool CSpell::isSpecialSpell() const
+{
+    return isSpecial;
+}
+
 bool CSpell::hasEffects() const
 {
 	return effects.size() && effects[0].size();