BonusParams.cpp 11 KB

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