Преглед изворни кода

vcmi: replace school bonuses to unified ones

Except immunity now
Konstantin P пре 2 година
родитељ
комит
9e1cdc410f

+ 16 - 8
config/artifacts.json

@@ -1184,7 +1184,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "AIR_SPELL_DMG_PREMY",
+				"type" : "SPELL_DAMAGE",
+				"subtype" : 0,
 				"val" : 50,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1196,7 +1197,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "EARTH_SPELL_DMG_PREMY",
+				"type" : "SPELL_DAMAGE",
+				"subtype" : 3,
 				"val" : 50,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1208,7 +1210,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "FIRE_SPELL_DMG_PREMY",
+				"type" : "SPELL_DAMAGE",
+				"subtype" : 1,
 				"val" : 50,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1220,7 +1223,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "WATER_SPELL_DMG_PREMY",
+				"type" : "SPELL_DAMAGE",
+				"subtype" : 2,
 				"val" : 50,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1271,7 +1275,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "FIRE_SPELLS",
+				"type" : "SPELLS_OF_SCHOOL",
+				"subtype" : 1,
 				"val" : 0,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1283,7 +1288,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "AIR_SPELLS",
+				"type" : "SPELLS_OF_SCHOOL",
+				"subtype" : 0,
 				"val" : 0,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1295,7 +1301,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "WATER_SPELLS",
+				"type" : "SPELLS_OF_SCHOOL",
+				"subtype" : 2,
 				"val" : 0,
 				"valueType" : "BASE_NUMBER"
 			}
@@ -1307,7 +1314,8 @@
 	{
 		"bonuses" : [
 			{
-				"type" : "EARTH_SPELLS",
+				"type" : "SPELLS_OF_SCHOOL",
+				"subtype" : 3,
 				"val" : 0,
 				"valueType" : "BASE_NUMBER"
 			}

+ 0 - 20
lib/bonuses/Bonus.cpp

@@ -31,26 +31,6 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-const std::set<std::string> deprecatedBonusSet = {
-	"SECONDARY_SKILL_PREMY",
-	"SECONDARY_SKILL_VAL2",
-	"MAXED_SPELL",
-	"LAND_MOVEMENT",
-	"SEA_MOVEMENT",
-	"SIGHT_RADIOUS",
-	"NO_TYPE",
-	"SPECIAL_SECONDARY_SKILL",
-	"FULL_HP_REGENERATION",
-	"KING1",
-	"KING2",
-	"KING3",
-	"BLOCK_MORALE",
-	"BLOCK_LUCK",
-	"SELF_MORALE",
-	"SELF_LUCK",
-	"DIRECT_DAMAGE_IMMUNITY"
-};
-
 //This constructor should be placed here to avoid side effects
 CAddInfo::CAddInfo() = default;
 

+ 0 - 2
lib/bonuses/Bonus.h

@@ -187,6 +187,4 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
 
 DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus);
 
-extern DLL_LINKAGE const std::set<std::string> deprecatedBonusSet;
-
 VCMI_LIB_NAMESPACE_END

+ 6 - 13
lib/bonuses/BonusEnum.h

@@ -10,10 +10,10 @@
 
 #pragma once
 
-VCMI_LIB_NAMESPACE_BEGIN
-
 #include "../JsonNode.h"
 
+VCMI_LIB_NAMESPACE_BEGIN
+
 #define BONUS_LIST										\
 	BONUS_NAME(NONE) 									\
 	BONUS_NAME(LEVEL_COUNTER) /* for commander artifacts*/ \
@@ -22,29 +22,22 @@ VCMI_LIB_NAMESPACE_BEGIN
 	BONUS_NAME(LUCK) \
 	BONUS_NAME(PRIMARY_SKILL) /*uses subtype to pick skill; additional info if set: 1 - only melee, 2 - only distance*/  \
 	BONUS_NAME(SIGHT_RADIUS) \
-	BONUS_NAME(MANA_REGENERATION) /*points per turn apart from normal (1 + mysticism)*/  \
+	BONUS_NAME(MANA_REGENERATION) /*points per turn*/  \
 	BONUS_NAME(FULL_MANA_REGENERATION) /*all mana points are replenished every day*/  \
 	BONUS_NAME(NONEVIL_ALIGNMENT_MIX) /*good and neutral creatures can be mixed without morale penalty*/  \
 	BONUS_NAME(SURRENDER_DISCOUNT) /*%*/  \
 	BONUS_NAME(STACKS_SPEED)  /*additional info - percent of speed bonus applied after direct bonuses; >0 - added, <0 - subtracted to this part*/ \
 	BONUS_NAME(FLYING_MOVEMENT) /*value - penalty percentage*/ \
 	BONUS_NAME(SPELL_DURATION) \
-	BONUS_NAME(AIR_SPELL_DMG_PREMY) \
-	BONUS_NAME(EARTH_SPELL_DMG_PREMY) \
-	BONUS_NAME(FIRE_SPELL_DMG_PREMY) \
-	BONUS_NAME(WATER_SPELL_DMG_PREMY) \
 	BONUS_NAME(WATER_WALKING) /*value - penalty percentage*/ \
 	BONUS_NAME(NEGATE_ALL_NATURAL_IMMUNITIES) \
 	BONUS_NAME(STACK_HEALTH) \
-	BONUS_NAME(FIRE_SPELLS) \
-	BONUS_NAME(AIR_SPELLS) \
-	BONUS_NAME(WATER_SPELLS) \
-	BONUS_NAME(EARTH_SPELLS) \
 	BONUS_NAME(GENERATE_RESOURCE) /*daily value, uses subtype (resource type)*/  \
 	BONUS_NAME(CREATURE_GROWTH) /*for legion artifacts: value - week growth bonus, subtype - monster level if aplicable*/  \
 	BONUS_NAME(WHIRLPOOL_PROTECTION) /*hero won't lose army when teleporting through whirlpool*/  \
 	BONUS_NAME(SPELL) /*hero knows spell, val - skill level (0 - 3), subtype - spell id*/  \
 	BONUS_NAME(SPELLS_OF_LEVEL) /*hero knows all spells of given level, val - skill level; subtype - level*/  \
+	BONUS_NAME(SPELLS_OF_SCHOOL) /*hero knows all spells of given school, subtype - spell school; 0 - air, 1 - fire, 2 - water, 3 - earth*/  \
 	BONUS_NAME(BATTLE_NO_FLEEING) /*for shackles of war*/ \
 	BONUS_NAME(MAGIC_SCHOOL_SKILL) /* //eg. for magic plains terrain, subtype: school of magic (0 - all, 1 - fire, 2 - air, 4 - water, 8 - earth), value - level*/ \
 	BONUS_NAME(FREE_SHOOTING) /*stacks can shoot even if otherwise blocked (sharpshooter's bow effect)*/ \
@@ -81,7 +74,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 	BONUS_NAME(SPELL_LIKE_ATTACK) /*subtype - spell, value - spell level; range is taken from spell, but damage from creature; eg. magog*/ \
 	BONUS_NAME(THREE_HEADED_ATTACK) /*eg. cerberus*/	\
 	BONUS_NAME(GENERAL_DAMAGE_PREMY)						\
-	BONUS_NAME(FIRE_IMMUNITY)	/*subtype 0 - all, 1 - all except positive, 2 - only damage spells*/						\
+	BONUS_NAME(FIRE_IMMUNITY)	/*subtype 0 - all, 1 - all except positive*/						\
 	BONUS_NAME(WATER_IMMUNITY)							\
 	BONUS_NAME(EARTH_IMMUNITY)							\
 	BONUS_NAME(AIR_IMMUNITY)							\
@@ -122,7 +115,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 	BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \
 	BONUS_NAME(DARKNESS) /*val = radius */ \
 	BONUS_NAME(SPECIAL_SPELL_LEV) /*subtype = id, val = value per level in percent*/\
-	BONUS_NAME(SPELL_DAMAGE) /*val = value, now works for sorcery*/\
+	BONUS_NAME(SPELL_DAMAGE) /*val = value, now works for sorcery, subtype - spell school; -1 - all, 0 - air, 1 - fire, 2 - water, 3 - earth*/\
 	BONUS_NAME(SPECIFIC_SPELL_DAMAGE) /*subtype = id of spell, val = value*/\
 	BONUS_NAME(SPECIAL_PECULIAR_ENCHANT) /*blesses and curses with id = val dependent on unit's level, subtype = 0 or 1 for Coronius*/\
 	BONUS_NAME(SPECIAL_UPGRADE) /*subtype = base, additionalInfo = target */\

+ 76 - 0
lib/bonuses/BonusParams.cpp

@@ -17,6 +17,34 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
+const std::set<std::string> deprecatedBonusSet = {
+	"SECONDARY_SKILL_PREMY",
+	"SECONDARY_SKILL_VAL2",
+	"MAXED_SPELL",
+	"LAND_MOVEMENT",
+	"SEA_MOVEMENT",
+	"SIGHT_RADIOUS",
+	"NO_TYPE",
+	"SPECIAL_SECONDARY_SKILL",
+	"FULL_HP_REGENERATION",
+	"KING1",
+	"KING2",
+	"KING3",
+	"BLOCK_MORALE",
+	"BLOCK_LUCK",
+	"SELF_MORALE",
+	"SELF_LUCK",
+	"DIRECT_DAMAGE_IMMUNITY",
+	"AIR_SPELL_DMG_PREMY",
+	"EARTH_SPELL_DMG_PREMY"
+	"FIRE_SPELL_DMG_PREMY"
+	"WATER_SPELL_DMG_PREMY",
+	"FIRE_SPELLS",
+	"AIR_SPELLS",
+	"WATER_SPELLS",
+	"EARTH_SPELLS"
+};
+
 BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSubtypeStr, int deprecatedSubtype):
 	isConverted(true)
 {
@@ -222,6 +250,54 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
 		val = 100;
 		valRelevant = true;
 	}
+	else if (deprecatedTypeStr == "AIR_SPELL_DMG_PREMY")
+	{
+		type = BonusType::SPELL_DAMAGE;
+		subtypeRelevant = true;
+		subtype = 0;
+	}
+	else if (deprecatedTypeStr == "FIRE_SPELL_DMG_PREMY")
+	{
+		type = BonusType::SPELL_DAMAGE;
+		subtypeRelevant = true;
+		subtype = 1;
+	}
+	else if (deprecatedTypeStr == "WATER_SPELL_DMG_PREMY")
+	{
+		type = BonusType::SPELL_DAMAGE;
+		subtypeRelevant = true;
+		subtype = 2;
+	}
+	else if (deprecatedTypeStr == "EARTH_SPELL_DMG_PREMY")
+	{
+		type = BonusType::SPELL_DAMAGE;
+		subtypeRelevant = true;
+		subtype = 3;
+	}
+	else if (deprecatedTypeStr == "AIR_SPELLS")
+	{
+		type = BonusType::SPELLS_OF_SCHOOL;
+		subtypeRelevant = true;
+		subtype = 0;
+	}
+	else if (deprecatedTypeStr == "FIRE_SPELLS")
+	{
+		type = BonusType::SPELLS_OF_SCHOOL;
+		subtypeRelevant = true;
+		subtype = 1;
+	}
+	else if (deprecatedTypeStr == "WATER_SPELLS")
+	{
+		type = BonusType::SPELLS_OF_SCHOOL;
+		subtypeRelevant = true;
+		subtype = 2;
+	}
+	else if (deprecatedTypeStr == "EARTH_SPELLS")
+	{
+		type = BonusType::SPELLS_OF_SCHOOL;
+		subtypeRelevant = true;
+		subtype = 3;
+	}
 	else
 		isConverted = false;
 }

+ 2 - 0
lib/bonuses/BonusParams.h

@@ -38,4 +38,6 @@ private:
 	bool jsonCreated = false;
 };
 
+extern DLL_LINKAGE const std::set<std::string> deprecatedBonusSet;
+
 VCMI_LIB_NAMESPACE_END

+ 2 - 2
lib/mapObjects/CGHeroInstance.cpp

@@ -619,7 +619,7 @@ int64_t CGHeroInstance::getSpellBonus(const spells::Spell * spell, int64_t base,
 
 	spell->forEachSchool([&maxSchoolBonus, this](const spells::SchoolInfo & cnf, bool & stop)
 	{
-		vstd::amax(maxSchoolBonus, valOfBonuses(cnf.damagePremyBonus));
+		vstd::amax(maxSchoolBonus, valOfBonuses(BonusType::SPELL_DAMAGE, vstd::to_underlying(cnf.id)));
 	});
 
 	base = static_cast<int64_t>(base * (100 + maxSchoolBonus) / 100.0);
@@ -708,7 +708,7 @@ bool CGHeroInstance::canCastThisSpell(const spells::Spell * spell) const
 
 	spell->forEachSchool([this, &schoolBonus](const spells::SchoolInfo & cnf, bool & stop)
 	{
-		if(hasBonusOfType(cnf.knoledgeBonus))
+		if(hasBonusOfType(BonusType::SPELLS_OF_SCHOOL, vstd::to_underlying(cnf.id)))
 		{
 			schoolBonus = stop = true;
 		}

+ 4 - 16
lib/spells/CSpellHandler.cpp

@@ -42,35 +42,23 @@ static const spells::SchoolInfo SCHOOL[4] =
 {
 	{
 		ESpellSchool::AIR,
-		BonusType::AIR_SPELL_DMG_PREMY,
 		BonusType::AIR_IMMUNITY,
-		"air",
-		SecondarySkill::AIR_MAGIC,
-		BonusType::AIR_SPELLS
+		"air"
 	},
 	{
 		ESpellSchool::FIRE,
-		BonusType::FIRE_SPELL_DMG_PREMY,
 		BonusType::FIRE_IMMUNITY,
-		"fire",
-		SecondarySkill::FIRE_MAGIC,
-		BonusType::FIRE_SPELLS
+		"fire"
 	},
 	{
 		ESpellSchool::WATER,
-		BonusType::WATER_SPELL_DMG_PREMY,
 		BonusType::WATER_IMMUNITY,
-		"water",
-		SecondarySkill::WATER_MAGIC,
-		BonusType::WATER_SPELLS
+		"water"
 	},
 	{
 		ESpellSchool::EARTH,
-		BonusType::EARTH_SPELL_DMG_PREMY,
 		BonusType::EARTH_IMMUNITY,
-		"earth",
-		SecondarySkill::EARTH_MAGIC,
-		BonusType::EARTH_SPELLS
+		"earth"
 	}
 };
 

+ 0 - 3
lib/spells/CSpellHandler.h

@@ -44,11 +44,8 @@ class IBattleCast;
 struct SchoolInfo
 {
 	ESpellSchool id; //backlink
-	BonusType damagePremyBonus;
 	BonusType immunityBonus;
 	std::string jsonName;
-	SecondarySkill::ESecondarySkill skill;
-	BonusType knoledgeBonus;
 };
 
 }