BonusParams.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * BonusParams.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "BonusParams.h"
  12. #include "BonusSelector.h"
  13. #include "../ResourceSet.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. const std::set<std::string> deprecatedBonusSet = {
  16. "SECONDARY_SKILL_PREMY",
  17. "SECONDARY_SKILL_VAL2",
  18. "MAXED_SPELL",
  19. "LAND_MOVEMENT",
  20. "SEA_MOVEMENT",
  21. "SIGHT_RADIOUS",
  22. "NO_TYPE",
  23. "SPECIAL_SECONDARY_SKILL",
  24. "FULL_HP_REGENERATION",
  25. "KING1",
  26. "KING2",
  27. "KING3",
  28. "BLOCK_MORALE",
  29. "BLOCK_LUCK",
  30. "SELF_MORALE",
  31. "SELF_LUCK",
  32. "DIRECT_DAMAGE_IMMUNITY",
  33. "AIR_SPELL_DMG_PREMY",
  34. "EARTH_SPELL_DMG_PREMY"
  35. "FIRE_SPELL_DMG_PREMY"
  36. "WATER_SPELL_DMG_PREMY",
  37. "FIRE_SPELLS",
  38. "AIR_SPELLS",
  39. "WATER_SPELLS",
  40. "EARTH_SPELLS"
  41. };
  42. BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSubtypeStr, int deprecatedSubtype):
  43. isConverted(true)
  44. {
  45. if(deprecatedTypeStr == "SECONDARY_SKILL_PREMY" || deprecatedTypeStr == "SPECIAL_SECONDARY_SKILL")
  46. {
  47. if(deprecatedSubtype == SecondarySkill::PATHFINDING || deprecatedSubtypeStr == "skill.pathfinding")
  48. type = BonusType::ROUGH_TERRAIN_DISCOUNT;
  49. else if(deprecatedSubtype == SecondarySkill::DIPLOMACY || deprecatedSubtypeStr == "skill.diplomacy")
  50. type = BonusType::WANDERING_CREATURES_JOIN_BONUS;
  51. else if(deprecatedSubtype == SecondarySkill::WISDOM || deprecatedSubtypeStr == "skill.wisdom")
  52. type = BonusType::MAX_LEARNABLE_SPELL_LEVEL;
  53. else if(deprecatedSubtype == SecondarySkill::MYSTICISM || deprecatedSubtypeStr == "skill.mysticism")
  54. type = BonusType::MANA_REGENERATION;
  55. else if(deprecatedSubtype == SecondarySkill::NECROMANCY || deprecatedSubtypeStr == "skill.necromancy")
  56. type = BonusType::UNDEAD_RAISE_PERCENTAGE;
  57. else if(deprecatedSubtype == SecondarySkill::LEARNING || deprecatedSubtypeStr == "skill.learning")
  58. type = BonusType::HERO_EXPERIENCE_GAIN_PERCENT;
  59. else if(deprecatedSubtype == SecondarySkill::RESISTANCE || deprecatedSubtypeStr == "skill.resistance")
  60. type = BonusType::MAGIC_RESISTANCE;
  61. else if(deprecatedSubtype == SecondarySkill::EAGLE_EYE || deprecatedSubtypeStr == "skill.eagleEye")
  62. type = BonusType::LEARN_BATTLE_SPELL_CHANCE;
  63. else if(deprecatedSubtype == SecondarySkill::SCOUTING || deprecatedSubtypeStr == "skill.scouting")
  64. type = BonusType::SIGHT_RADIUS;
  65. else if(deprecatedSubtype == SecondarySkill::INTELLIGENCE || deprecatedSubtypeStr == "skill.intelligence")
  66. {
  67. type = BonusType::MANA_PER_KNOWLEDGE;
  68. valueType = BonusValueType::PERCENT_TO_BASE;
  69. }
  70. else if(deprecatedSubtype == SecondarySkill::SORCERY || deprecatedSubtypeStr == "skill.sorcery")
  71. {
  72. type = BonusType::SPELL_DAMAGE;
  73. subtype = SpellSchool(ESpellSchool::ANY);
  74. }
  75. else if(deprecatedSubtype == SecondarySkill::SCHOLAR || deprecatedSubtypeStr == "skill.scholar")
  76. type = BonusType::LEARN_MEETING_SPELL_LIMIT;
  77. else if(deprecatedSubtype == SecondarySkill::ARCHERY|| deprecatedSubtypeStr == "skill.archery")
  78. {
  79. subtype = 1;
  80. type = BonusType::PERCENTAGE_DAMAGE_BOOST;
  81. }
  82. else if(deprecatedSubtype == SecondarySkill::OFFENCE || deprecatedSubtypeStr == "skill.offence")
  83. {
  84. subtype = 0;
  85. type = BonusType::PERCENTAGE_DAMAGE_BOOST;
  86. }
  87. else if(deprecatedSubtype == SecondarySkill::ARMORER || deprecatedSubtypeStr == "skill.armorer")
  88. {
  89. subtype = -1;
  90. type = BonusType::GENERAL_DAMAGE_REDUCTION;
  91. }
  92. else if(deprecatedSubtype == SecondarySkill::NAVIGATION || deprecatedSubtypeStr == "skill.navigation")
  93. {
  94. subtype = 0;
  95. valueType = BonusValueType::PERCENT_TO_BASE;
  96. type = BonusType::MOVEMENT;
  97. }
  98. else if(deprecatedSubtype == SecondarySkill::LOGISTICS || deprecatedSubtypeStr == "skill.logistics")
  99. {
  100. subtype = 1;
  101. valueType = BonusValueType::PERCENT_TO_BASE;
  102. type = BonusType::MOVEMENT;
  103. }
  104. else if(deprecatedSubtype == SecondarySkill::ESTATES || deprecatedSubtypeStr == "skill.estates")
  105. {
  106. type = BonusType::GENERATE_RESOURCE;
  107. subtype = GameResID(EGameResID::GOLD);
  108. }
  109. else if(deprecatedSubtype == SecondarySkill::AIR_MAGIC || deprecatedSubtypeStr == "skill.airMagic")
  110. {
  111. type = BonusType::MAGIC_SCHOOL_SKILL;
  112. subtype = SpellSchool(ESpellSchool::AIR);
  113. }
  114. else if(deprecatedSubtype == SecondarySkill::WATER_MAGIC || deprecatedSubtypeStr == "skill.waterMagic")
  115. {
  116. type = BonusType::MAGIC_SCHOOL_SKILL;
  117. subtype = SpellSchool(ESpellSchool::WATER);
  118. }
  119. else if(deprecatedSubtype == SecondarySkill::FIRE_MAGIC || deprecatedSubtypeStr == "skill.fireMagic")
  120. {
  121. type = BonusType::MAGIC_SCHOOL_SKILL;
  122. subtype = SpellSchool(ESpellSchool::FIRE);
  123. }
  124. else if(deprecatedSubtype == SecondarySkill::EARTH_MAGIC || deprecatedSubtypeStr == "skill.earthMagic")
  125. {
  126. type = BonusType::MAGIC_SCHOOL_SKILL;
  127. subtype = SpellSchool(ESpellSchool::EARTH);
  128. }
  129. else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
  130. {
  131. type = BonusType::BONUS_DAMAGE_CHANCE;
  132. subtypeStr = "core:creature.ballista";
  133. }
  134. else if (deprecatedSubtype == SecondarySkill::FIRST_AID || deprecatedSubtypeStr == "skill.firstAid")
  135. {
  136. type = BonusType::SPECIFIC_SPELL_POWER;
  137. subtypeStr = "core:spell.firstAid";
  138. }
  139. else if (deprecatedSubtype == SecondarySkill::BALLISTICS || deprecatedSubtypeStr == "skill.ballistics")
  140. {
  141. type = BonusType::CATAPULT_EXTRA_SHOTS;
  142. subtypeStr = "core:spell.catapultShot";
  143. }
  144. else
  145. isConverted = false;
  146. }
  147. else if (deprecatedTypeStr == "SECONDARY_SKILL_VAL2")
  148. {
  149. if(deprecatedSubtype == SecondarySkill::EAGLE_EYE || deprecatedSubtypeStr == "skill.eagleEye")
  150. type = BonusType::LEARN_BATTLE_SPELL_LEVEL_LIMIT;
  151. else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
  152. {
  153. type = BonusType::HERO_GRANTS_ATTACKS;
  154. subtypeStr = "core:creature.ballista";
  155. }
  156. else
  157. isConverted = false;
  158. }
  159. else if (deprecatedTypeStr == "SEA_MOVEMENT")
  160. {
  161. subtype = 0;
  162. valueType = BonusValueType::ADDITIVE_VALUE;
  163. type = BonusType::MOVEMENT;
  164. }
  165. else if (deprecatedTypeStr == "LAND_MOVEMENT")
  166. {
  167. subtype = 1;
  168. valueType = BonusValueType::ADDITIVE_VALUE;
  169. type = BonusType::MOVEMENT;
  170. }
  171. else if (deprecatedTypeStr == "MAXED_SPELL")
  172. {
  173. type = BonusType::SPELL;
  174. subtypeStr = deprecatedSubtypeStr;
  175. valueType = BonusValueType::INDEPENDENT_MAX;
  176. val = 3;
  177. }
  178. else if (deprecatedTypeStr == "FULL_HP_REGENERATION")
  179. {
  180. type = BonusType::HP_REGENERATION;
  181. val = 100000; //very high value to always chose stack health
  182. }
  183. else if (deprecatedTypeStr == "KING1")
  184. {
  185. type = BonusType::KING;
  186. val = 0;
  187. }
  188. else if (deprecatedTypeStr == "KING2")
  189. {
  190. type = BonusType::KING;
  191. val = 2;
  192. }
  193. else if (deprecatedTypeStr == "KING3")
  194. {
  195. type = BonusType::KING;
  196. val = 3;
  197. }
  198. else if (deprecatedTypeStr == "SIGHT_RADIOUS")
  199. type = BonusType::SIGHT_RADIUS;
  200. else if (deprecatedTypeStr == "SELF_MORALE")
  201. {
  202. type = BonusType::MORALE;
  203. val = 1;
  204. valueType = BonusValueType::INDEPENDENT_MAX;
  205. }
  206. else if (deprecatedTypeStr == "SELF_LUCK")
  207. {
  208. type = BonusType::LUCK;
  209. val = 1;
  210. valueType = BonusValueType::INDEPENDENT_MAX;
  211. }
  212. else if (deprecatedTypeStr == "DIRECT_DAMAGE_IMMUNITY")
  213. {
  214. type = BonusType::SPELL_DAMAGE_REDUCTION;
  215. subtype = SpellSchool(ESpellSchool::ANY);
  216. val = 100;
  217. }
  218. else if (deprecatedTypeStr == "AIR_SPELL_DMG_PREMY")
  219. {
  220. type = BonusType::SPELL_DAMAGE;
  221. subtype = SpellSchool(ESpellSchool::AIR);
  222. }
  223. else if (deprecatedTypeStr == "FIRE_SPELL_DMG_PREMY")
  224. {
  225. type = BonusType::SPELL_DAMAGE;
  226. subtype = SpellSchool(ESpellSchool::FIRE);
  227. }
  228. else if (deprecatedTypeStr == "WATER_SPELL_DMG_PREMY")
  229. {
  230. type = BonusType::SPELL_DAMAGE;
  231. subtype = SpellSchool(ESpellSchool::WATER);
  232. }
  233. else if (deprecatedTypeStr == "EARTH_SPELL_DMG_PREMY")
  234. {
  235. type = BonusType::SPELL_DAMAGE;
  236. subtype = SpellSchool(ESpellSchool::EARTH);
  237. }
  238. else if (deprecatedTypeStr == "AIR_SPELLS")
  239. {
  240. type = BonusType::SPELLS_OF_SCHOOL;
  241. subtype = SpellSchool(ESpellSchool::AIR);
  242. }
  243. else if (deprecatedTypeStr == "FIRE_SPELLS")
  244. {
  245. type = BonusType::SPELLS_OF_SCHOOL;
  246. subtype = SpellSchool(ESpellSchool::FIRE);
  247. }
  248. else if (deprecatedTypeStr == "WATER_SPELLS")
  249. {
  250. type = BonusType::SPELLS_OF_SCHOOL;
  251. subtype = SpellSchool(ESpellSchool::WATER);
  252. }
  253. else if (deprecatedTypeStr == "EARTH_SPELLS")
  254. {
  255. type = BonusType::SPELLS_OF_SCHOOL;
  256. subtype = SpellSchool(ESpellSchool::EARTH);
  257. }
  258. else
  259. isConverted = false;
  260. }
  261. const JsonNode & BonusParams::toJson()
  262. {
  263. assert(isConverted);
  264. if(ret.isNull())
  265. {
  266. ret["type"].String() = vstd::findKey(bonusNameMap, type);
  267. if(subtypeStr)
  268. ret["subtype"].String() = *subtypeStr;
  269. else if(subtype)
  270. ret["subtype"].Integer() = *subtype;
  271. if(valueType)
  272. ret["valueType"].String() = vstd::findKey(bonusValueMap, *valueType);
  273. if(val)
  274. ret["val"].Float() = *val;
  275. if(targetType)
  276. ret["targetSourceType"].String() = vstd::findKey(bonusSourceMap, *targetType);
  277. jsonCreated = true;
  278. }
  279. return ret;
  280. };
  281. CSelector BonusParams::toSelector()
  282. {
  283. assert(isConverted);
  284. if(subtypeStr)
  285. {
  286. subtype = -1;
  287. JsonUtils::resolveIdentifier(*subtype, toJson(), "subtype");
  288. }
  289. auto ret = Selector::type()(type);
  290. if(subtype)
  291. ret = ret.And(Selector::subtype()(*subtype));
  292. if(valueType)
  293. ret = ret.And(Selector::valueType(*valueType));
  294. if(targetType)
  295. ret = ret.And(Selector::targetSourceType()(*targetType));
  296. return ret;
  297. }
  298. VCMI_LIB_NAMESPACE_END