CArtHandler.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CArtHandler.h"
  4. #include "CLodHandler.h"
  5. #include "CGeneralTextHandler.h"
  6. #include <boost/bind.hpp>
  7. #include <boost/foreach.hpp>
  8. #include <boost/assign/std/vector.hpp>
  9. #include <boost/assign/list_of.hpp>
  10. #include <boost/lexical_cast.hpp>
  11. #include <boost/foreach.hpp>
  12. #include "../lib/VCMI_Lib.h"
  13. extern CLodHandler *bitmaph;
  14. using namespace boost::assign;
  15. /*
  16. * CArtHandler.cpp, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. const std::string & CArtifact::Name() const
  25. {
  26. if(name.size())
  27. return name;
  28. else
  29. return VLC->generaltexth->artifNames[id];
  30. }
  31. const std::string & CArtifact::Description() const
  32. {
  33. if(description.size())
  34. return description;
  35. else
  36. return VLC->generaltexth->artifDescriptions[id];
  37. }
  38. bool CArtifact::isBig () const
  39. {
  40. return VLC->arth->isBigArtifact(id);
  41. }
  42. /**
  43. * Checks whether the artifact fits at a given slot.
  44. * @param artifWorn A hero's set of worn artifacts.
  45. */
  46. bool CArtifact::fitsAt (const std::map<ui16, ui32> &artifWorn, ui16 slotID) const
  47. {
  48. if (!vstd::contains(possibleSlots, slotID))
  49. return false;
  50. // Can't put an artifact in a locked slot.
  51. std::map<ui16, ui32>::const_iterator it = artifWorn.find(slotID);
  52. if (it != artifWorn.end() && it->second == 145)
  53. return false;
  54. // Check if a combination artifact fits.
  55. // TODO: Might want a more general algorithm?
  56. // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates.
  57. if (constituents != NULL) {
  58. std::map<ui16, ui32> tempArtifWorn = artifWorn;
  59. const ui16 ringSlots[] = {6, 7};
  60. const ui16 miscSlots[] = {9, 10, 11, 12, 18};
  61. int rings = 0;
  62. int misc = 0;
  63. VLC->arth->unequipArtifact(tempArtifWorn, slotID);
  64. BOOST_FOREACH(ui32 constituentID, *constituents) {
  65. const CArtifact& constituent = VLC->arth->artifacts[constituentID];
  66. const int slot = constituent.possibleSlots[0];
  67. if (slot == 6 || slot == 7)
  68. rings++;
  69. else if (slot >= 9 && slot <= 12 || slot == 18)
  70. misc++;
  71. else if (tempArtifWorn.find(slot) != tempArtifWorn.end())
  72. return false;
  73. }
  74. // Ensure enough ring slots are free
  75. for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++) {
  76. if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID)
  77. rings--;
  78. }
  79. if (rings > 0)
  80. return false;
  81. // Ensure enough misc slots are free.
  82. for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++) {
  83. if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID)
  84. misc--;
  85. }
  86. if (misc > 0)
  87. return false;
  88. }
  89. return true;
  90. }
  91. bool CArtifact::canBeAssembledTo (const std::map<ui16, ui32> &artifWorn, ui32 artifactID) const
  92. {
  93. if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID))
  94. return false;
  95. const CArtifact &artifact = VLC->arth->artifacts[artifactID];
  96. assert(artifact.constituents);
  97. BOOST_FOREACH(ui32 constituentID, *artifact.constituents) {
  98. bool found = false;
  99. for (std::map<ui16, ui32>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it) {
  100. if (it->second == constituentID) {
  101. found = true;
  102. break;
  103. }
  104. }
  105. if (!found)
  106. return false;
  107. }
  108. return true;
  109. }
  110. /**
  111. * Adds all the bonuses of this artifact, including possible constituents, to
  112. * a bonus list.
  113. */
  114. void CArtifact::addBonusesTo (BonusList *otherBonuses) const
  115. {
  116. for(std::list<Bonus>::const_iterator i = bonuses.begin(); i != bonuses.end(); i++)
  117. otherBonuses->push_back(*i);
  118. if (constituents != NULL) {
  119. BOOST_FOREACH(ui32 artifactID, *constituents) {
  120. VLC->arth->artifacts[artifactID].addBonusesTo(otherBonuses);
  121. }
  122. }
  123. }
  124. /**
  125. * Removes all the bonuses of this artifact, including possible constituents, from
  126. * a bonus list.
  127. */
  128. void CArtifact::removeBonusesFrom (BonusList *otherBonuses) const
  129. {
  130. if (constituents != NULL) {
  131. BOOST_FOREACH(ui32 artifactID, *constituents) {
  132. VLC->arth->artifacts[artifactID].removeBonusesFrom(otherBonuses);
  133. }
  134. }
  135. while (1) {
  136. std::list<Bonus>::const_iterator it = std::find_if(otherBonuses->begin(), otherBonuses->end(),boost::bind(Bonus::IsFrom,_1,Bonus::ARTIFACT,id));
  137. if (it != otherBonuses->end())
  138. otherBonuses->erase(it);
  139. else
  140. break;
  141. }
  142. }
  143. CArtHandler::CArtHandler()
  144. {
  145. VLC->arth = this;
  146. // War machines are the default big artifacts.
  147. for (ui32 i = 3; i <= 6; i++)
  148. bigArtifacts.insert(i);
  149. }
  150. CArtHandler::~CArtHandler()
  151. {
  152. for (std::vector<CArtifact>::iterator it = artifacts.begin(); it != artifacts.end(); ++it) {
  153. delete it->constituents;
  154. delete it->constituentOf;
  155. }
  156. }
  157. void CArtHandler::loadArtifacts(bool onlyTxt)
  158. {
  159. std::vector<ui16> slots;
  160. slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
  161. static std::map<char, CArtifact::EartClass> classes =
  162. map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
  163. std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
  164. int it=0;
  165. for(int i=0; i<2; ++i)
  166. {
  167. loadToIt(dump,buf,it,3);
  168. }
  169. VLC->generaltexth->artifNames.resize(ARTIFACTS_QUANTITY);
  170. VLC->generaltexth->artifDescriptions.resize(ARTIFACTS_QUANTITY);
  171. for (int i=0; i<ARTIFACTS_QUANTITY; i++)
  172. {
  173. CArtifact nart;
  174. nart.id=i;
  175. loadToIt(VLC->generaltexth->artifNames[i],buf,it,4);
  176. loadToIt(pom,buf,it,4);
  177. nart.price=atoi(pom.c_str());
  178. for(int j=0;j<slots.size();j++)
  179. {
  180. loadToIt(pom,buf,it,4);
  181. if(pom.size() && pom[0]=='x')
  182. nart.possibleSlots.push_back(slots[j]);
  183. }
  184. loadToIt(pom,buf,it,4);
  185. nart.aClass = classes[pom[0]];
  186. //load description and remove quotation marks
  187. std::string &desc = VLC->generaltexth->artifDescriptions[i];
  188. loadToIt(desc,buf,it,3);
  189. if(desc[0] == '\"' && desc[desc.size()-1] == '\"')
  190. desc = desc.substr(1,desc.size()-2);
  191. // Fill in information about combined artifacts. Should perhaps be moved to a config file?
  192. nart.constituentOf = NULL;
  193. switch (nart.id) {
  194. case 129: // Angelic Alliance
  195. nart.constituents = new std::vector<ui32>();
  196. *nart.constituents += 31, 32, 33, 34, 35, 36;
  197. break;
  198. case 130: // Cloak of the Undead King
  199. nart.constituents = new std::vector<ui32>();
  200. *nart.constituents += 54, 55, 56;
  201. break;
  202. case 131: // Elixir of Life
  203. nart.constituents = new std::vector<ui32>();
  204. *nart.constituents += 94, 95, 96;
  205. break;
  206. case 132: // Armor of the Damned
  207. nart.constituents = new std::vector<ui32>();
  208. *nart.constituents += 8, 14, 20, 26;
  209. break;
  210. case 133: // Statue of Legion
  211. nart.constituents = new std::vector<ui32>();
  212. *nart.constituents += 118, 119, 120, 121, 122;
  213. break;
  214. case 134: // Power of the Dragon Father
  215. nart.constituents = new std::vector<ui32>();
  216. *nart.constituents += 37, 38, 39, 40, 41, 42, 43, 44, 45;
  217. break;
  218. case 135: // Titan's Thunder
  219. nart.constituents = new std::vector<ui32>();
  220. *nart.constituents += 12, 18, 24, 30;
  221. break;
  222. case 136: // Admiral's Hat
  223. nart.constituents = new std::vector<ui32>();
  224. *nart.constituents += 71, 123;
  225. break;
  226. case 137: // Bow of the Sharpshooter
  227. nart.constituents = new std::vector<ui32>();
  228. *nart.constituents += 60, 61, 62;
  229. break;
  230. case 138: // Wizards' Well
  231. nart.constituents = new std::vector<ui32>();
  232. *nart.constituents += 73, 74, 75;
  233. break;
  234. case 139: // Ring of the Magi
  235. nart.constituents = new std::vector<ui32>();
  236. *nart.constituents += 76, 77, 78;
  237. break;
  238. case 140: // Cornucopia
  239. nart.constituents = new std::vector<ui32>();
  240. *nart.constituents += 109, 110, 111, 113;
  241. break;
  242. // TODO: WoG combinationals
  243. default:
  244. nart.constituents = NULL;
  245. break;
  246. }
  247. if(!onlyTxt)
  248. artifacts.push_back(nart);
  249. }
  250. sortArts();
  251. if(!onlyTxt)
  252. addBonuses();
  253. // Populate reverse mappings of combinational artifacts.
  254. BOOST_FOREACH(CArtifact artifact, artifacts) {
  255. if (artifact.constituents != NULL) {
  256. BOOST_FOREACH(ui32 constituentID, *artifact.constituents) {
  257. if (artifacts[constituentID].constituentOf == NULL)
  258. artifacts[constituentID].constituentOf = new std::vector<ui32>();
  259. artifacts[constituentID].constituentOf->push_back(artifact.id);
  260. }
  261. }
  262. }
  263. }
  264. int CArtHandler::convertMachineID(int id, bool creToArt )
  265. {
  266. int dif = 142;
  267. if(creToArt)
  268. {
  269. switch (id)
  270. {
  271. case 147:
  272. dif--;
  273. break;
  274. case 148:
  275. dif++;
  276. break;
  277. }
  278. dif = -dif;
  279. }
  280. else
  281. {
  282. switch (id)
  283. {
  284. case 6:
  285. dif--;
  286. break;
  287. case 5:
  288. dif++;
  289. break;
  290. }
  291. }
  292. return id + dif;
  293. }
  294. void CArtHandler::sortArts()
  295. {
  296. for(int i=0;i<144;i++) //do 144, bo nie chcemy bzdurek
  297. {
  298. switch (artifacts[i].aClass)
  299. {
  300. case CArtifact::ART_TREASURE:
  301. treasures.push_back(&(artifacts[i]));
  302. break;
  303. case CArtifact::ART_MINOR:
  304. minors.push_back(&(artifacts[i]));
  305. break;
  306. case CArtifact::ART_MAJOR:
  307. majors.push_back(&(artifacts[i]));
  308. break;
  309. case CArtifact::ART_RELIC:
  310. relics.push_back(&(artifacts[i]));
  311. break;
  312. }
  313. }
  314. }
  315. void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int subtype, int valType )
  316. {
  317. Bonus added(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
  318. added.valType = valType;
  319. if(type == Bonus::MORALE || Bonus::LUCK)
  320. added.description = "\n" + artifacts[aid].Name() + (val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(val);
  321. artifacts[aid].bonuses.push_back(added);
  322. }
  323. void CArtHandler::addBonuses()
  324. {
  325. #define ART_PRIM_SKILL(ID, whichSkill, val) giveArtBonus(ID,Bonus::PRIMARY_SKILL,val,whichSkill)
  326. #define ART_MORALE(ID, val) giveArtBonus(ID,Bonus::MORALE,val)
  327. #define ART_LUCK(ID, val) giveArtBonus(ID,Bonus::LUCK,val)
  328. #define ART_MORALE_AND_LUCK(ID, val) giveArtBonus(ID,Bonus::MORALE_AND_LUCK,val)
  329. #define ART_ALL_PRIM_SKILLS(ID, val) ART_PRIM_SKILL(ID,0,val); ART_PRIM_SKILL(ID,1,val); ART_PRIM_SKILL(ID,2,val); ART_PRIM_SKILL(ID,3,val)
  330. #define ART_ATTACK_AND_DEFENSE(ID, val) ART_PRIM_SKILL(ID,0,val); ART_PRIM_SKILL(ID,1,val)
  331. #define ART_POWER_AND_KNOWLEDGE(ID, val) ART_PRIM_SKILL(ID,2,val); ART_PRIM_SKILL(ID,3,val)
  332. //Attack bonus artifacts (Weapons)
  333. ART_PRIM_SKILL(7,0,+2); //Centaur Axe
  334. ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight
  335. ART_PRIM_SKILL(9,0,+4); //Greater Gnoll's Flail
  336. ART_PRIM_SKILL(10,0,+5); //Ogre's Club of Havoc
  337. ART_PRIM_SKILL(11,0,+6); //Sword of Hellfire
  338. ART_PRIM_SKILL(12,0,+12); //Titan's Gladius
  339. ART_PRIM_SKILL(12,1,-3); //Titan's Gladius
  340. //Defense bonus artifacts (Shields)
  341. ART_PRIM_SKILL(13,1,+2); //Shield of the Dwarven Lords
  342. ART_PRIM_SKILL(14,1,+3); //Shield of the Yawning Dead
  343. ART_PRIM_SKILL(15,1,+4); //Buckler of the Gnoll King
  344. ART_PRIM_SKILL(16,1,+5); //Targ of the Rampaging Ogre
  345. ART_PRIM_SKILL(17,1,+6); //Shield of the Damned
  346. ART_PRIM_SKILL(18,1,+12); //Sentinel's Shield
  347. ART_PRIM_SKILL(18,0,-3); //Sentinel's Shield
  348. //Knowledge bonus artifacts (Helmets)
  349. ART_PRIM_SKILL(19,3,+1); //Helm of the Alabaster Unicorn
  350. ART_PRIM_SKILL(20,3,+2); //Skull Helmet
  351. ART_PRIM_SKILL(21,3,+3); //Helm of Chaos
  352. ART_PRIM_SKILL(22,3,+4); //Crown of the Supreme Magi
  353. ART_PRIM_SKILL(23,3,+5); //Hellstorm Helmet
  354. ART_PRIM_SKILL(24,3,+10); //Thunder Helmet
  355. ART_PRIM_SKILL(24,2,-2); //Thunder Helmet
  356. //Spell power bonus artifacts (Armours)
  357. ART_PRIM_SKILL(25,2,+1); //Breastplate of Petrified Wood
  358. ART_PRIM_SKILL(26,2,+2); //Rib Cage
  359. ART_PRIM_SKILL(27,2,+3); //Scales of the Greater Basilisk
  360. ART_PRIM_SKILL(28,2,+4); //Tunic of the Cyclops King
  361. ART_PRIM_SKILL(29,2,+5); //Breastplate of Brimstone
  362. ART_PRIM_SKILL(30,2,+10); //Titan's Cuirass
  363. ART_PRIM_SKILL(30,3,-2); //Titan's Cuirass
  364. //All primary skills (various)
  365. ART_ALL_PRIM_SKILLS(31,+1); //Armor of Wonder
  366. ART_ALL_PRIM_SKILLS(32,+2); //Sandals of the Saint
  367. ART_ALL_PRIM_SKILLS(33,+3); //Celestial Necklace of Bliss
  368. ART_ALL_PRIM_SKILLS(34,+4); //Lion's Shield of Courage
  369. ART_ALL_PRIM_SKILLS(35,+5); //Sword of Judgement
  370. ART_ALL_PRIM_SKILLS(36,+6); //Helm of Heavenly Enlightenment
  371. //Attack and Defense (various)
  372. ART_ATTACK_AND_DEFENSE(37,+1); //Quiet Eye of the Dragon
  373. ART_ATTACK_AND_DEFENSE(38,+2); //Red Dragon Flame Tongue
  374. ART_ATTACK_AND_DEFENSE(39,+3); //Dragon Scale Shield
  375. ART_ATTACK_AND_DEFENSE(40,+4); //Dragon Scale Armor
  376. //Spell power and Knowledge (various)
  377. ART_POWER_AND_KNOWLEDGE(41,+1); //Dragonbone Greaves
  378. ART_POWER_AND_KNOWLEDGE(42,+2); //Dragon Wing Tabard
  379. ART_POWER_AND_KNOWLEDGE(43,+3); //Necklace of Dragonteeth
  380. ART_POWER_AND_KNOWLEDGE(44,+4); //Crown of Dragontooth
  381. //Luck and morale
  382. ART_MORALE(45,+1); //Still Eye of the Dragon
  383. ART_LUCK(45,+1); //Still Eye of the Dragon
  384. ART_LUCK(46,+1); //Clover of Fortune
  385. ART_LUCK(47,+1); //Cards of Prophecy
  386. ART_LUCK(48,+1); //Ladybird of Luck
  387. ART_MORALE(49,+1); //Badge of Courage -> +1 morale and immunity to hostile mind spells:
  388. giveArtBonus(49,Bonus::SPELL_IMMUNITY,50);//sorrow
  389. giveArtBonus(49,Bonus::SPELL_IMMUNITY,59);//berserk
  390. giveArtBonus(49,Bonus::SPELL_IMMUNITY,60);//hypnotize
  391. giveArtBonus(49,Bonus::SPELL_IMMUNITY,61);//forgetfulness
  392. giveArtBonus(49,Bonus::SPELL_IMMUNITY,62);//blind
  393. ART_MORALE(50,+1); //Crest of Valor
  394. ART_MORALE(51,+1); //Glyph of Gallantry
  395. giveArtBonus(52,Bonus::SIGHT_RADIOUS,+1);//Speculum
  396. giveArtBonus(53,Bonus::SIGHT_RADIOUS,+1);//Spyglass
  397. //necromancy bonus
  398. giveArtBonus(54,Bonus::SECONDARY_SKILL_PREMY,+5,12);//Amulet of the Undertaker
  399. giveArtBonus(55,Bonus::SECONDARY_SKILL_PREMY,+10,12);//Vampire's Cowl
  400. giveArtBonus(56,Bonus::SECONDARY_SKILL_PREMY,+15,12);//Dead Man's Boots
  401. giveArtBonus(57,Bonus::MAGIC_RESISTANCE,+5);//Garniture of Interference
  402. giveArtBonus(58,Bonus::MAGIC_RESISTANCE,+10);//Surcoat of Counterpoise
  403. giveArtBonus(59,Bonus::MAGIC_RESISTANCE,+15);//Boots of Polarity
  404. //archery bonus
  405. giveArtBonus(60,Bonus::SECONDARY_SKILL_PREMY,+5,1);//Bow of Elven Cherrywood
  406. giveArtBonus(61,Bonus::SECONDARY_SKILL_PREMY,+10,1);//Bowstring of the Unicorn's Mane
  407. giveArtBonus(62,Bonus::SECONDARY_SKILL_PREMY,+15,1);//Angel Feather Arrows
  408. //eagle eye bonus
  409. giveArtBonus(63,Bonus::SECONDARY_SKILL_PREMY,+5,11);//Bird of Perception
  410. giveArtBonus(64,Bonus::SECONDARY_SKILL_PREMY,+10,11);//Stoic Watchman
  411. giveArtBonus(65,Bonus::SECONDARY_SKILL_PREMY,+15,11);//Emblem of Cognizance
  412. //reducing cost of surrendering
  413. giveArtBonus(66,Bonus::SURRENDER_DISCOUNT,+10);//Statesman's Medal
  414. giveArtBonus(67,Bonus::SURRENDER_DISCOUNT,+10);//Diplomat's Ring
  415. giveArtBonus(68,Bonus::SURRENDER_DISCOUNT,+10);//Ambassador's Sash
  416. giveArtBonus(69,Bonus::STACKS_SPEED,+1);//Ring of the Wayfarer
  417. giveArtBonus(70,Bonus::LAND_MOVEMENT,+300);//Equestrian's Gloves
  418. giveArtBonus(71,Bonus::SEA_MOVEMENT,+1000);//Necklace of Ocean Guidance
  419. giveArtBonus(72,Bonus::FLYING_MOVEMENT,+1);//Angel Wings
  420. giveArtBonus(73,Bonus::MANA_REGENERATION,+1);//Charm of Mana
  421. giveArtBonus(74,Bonus::MANA_REGENERATION,+2);//Talisman of Mana
  422. giveArtBonus(75,Bonus::MANA_REGENERATION,+3);//Mystic Orb of Mana
  423. giveArtBonus(76,Bonus::SPELL_DURATION,+1);//Collar of Conjuring
  424. giveArtBonus(77,Bonus::SPELL_DURATION,+2);//Ring of Conjuring
  425. giveArtBonus(78,Bonus::SPELL_DURATION,+3);//Cape of Conjuring
  426. giveArtBonus(79,Bonus::AIR_SPELL_DMG_PREMY,+50);//Orb of the Firmament
  427. giveArtBonus(80,Bonus::EARTH_SPELL_DMG_PREMY,+50);//Orb of Silt
  428. giveArtBonus(81,Bonus::FIRE_SPELL_DMG_PREMY,+50);//Orb of Tempestuous Fire
  429. giveArtBonus(82,Bonus::WATER_SPELL_DMG_PREMY,+50);//Orb of Driving Rain
  430. giveArtBonus(83,Bonus::BLOCK_SPELLS_ABOVE_LEVEL,3);//Recanter's Cloak
  431. giveArtBonus(84,Bonus::BLOCK_MORALE,0);//Spirit of Oppression
  432. giveArtBonus(85,Bonus::BLOCK_LUCK,0);//Hourglass of the Evil Hour
  433. giveArtBonus(86,Bonus::FIRE_SPELLS,0);//Tome of Fire Magic
  434. giveArtBonus(87,Bonus::AIR_SPELLS,0);//Tome of Air Magic
  435. giveArtBonus(88,Bonus::WATER_SPELLS,0);//Tome of Water Magic
  436. giveArtBonus(89,Bonus::EARTH_SPELLS,0);//Tome of Earth Magic
  437. giveArtBonus(90,Bonus::WATER_WALKING,0);//Boots of Levitation
  438. giveArtBonus(91,Bonus::NO_SHOTING_PENALTY,0);//Golden Bow
  439. giveArtBonus(92,Bonus::SPELL_IMMUNITY,35);//Sphere of Permanence
  440. giveArtBonus(93,Bonus::NEGATE_ALL_NATURAL_IMMUNITIES,0);//Orb of Vulnerability
  441. giveArtBonus(94,Bonus::STACK_HEALTH,+1);//Ring of Vitality
  442. giveArtBonus(95,Bonus::STACK_HEALTH,+1);//Ring of Life
  443. giveArtBonus(96,Bonus::STACK_HEALTH,+2);//Vial of Lifeblood
  444. giveArtBonus(97,Bonus::STACKS_SPEED,+1);//Necklace of Swiftness
  445. giveArtBonus(98,Bonus::LAND_MOVEMENT,+600);//Boots of Speed
  446. giveArtBonus(99,Bonus::STACKS_SPEED,+2);//Cape of Velocity
  447. giveArtBonus(100,Bonus::SPELL_IMMUNITY,59);//Pendant of Dispassion
  448. giveArtBonus(101,Bonus::SPELL_IMMUNITY,62);//Pendant of Second Sight
  449. giveArtBonus(102,Bonus::SPELL_IMMUNITY,42);//Pendant of Holiness
  450. giveArtBonus(103,Bonus::SPELL_IMMUNITY,24);//Pendant of Life
  451. giveArtBonus(104,Bonus::SPELL_IMMUNITY,25);//Pendant of Death
  452. giveArtBonus(105,Bonus::SPELL_IMMUNITY,60);//Pendant of Free Will
  453. giveArtBonus(106,Bonus::SPELL_IMMUNITY,17);//Pendant of Negativity
  454. giveArtBonus(107,Bonus::SPELL_IMMUNITY,61);//Pendant of Total Recall
  455. giveArtBonus(108,Bonus::MORALE,+3);//Pendant of Courage
  456. giveArtBonus(108,Bonus::LUCK,+3);//Pendant of Courage
  457. giveArtBonus(109,Bonus::GENERATE_RESOURCE,+1,4); //Everflowing Crystal Cloak
  458. giveArtBonus(110,Bonus::GENERATE_RESOURCE,+1,5); //Ring of Infinite Gems
  459. giveArtBonus(111,Bonus::GENERATE_RESOURCE,+1,1); //Everpouring Vial of Mercury
  460. giveArtBonus(112,Bonus::GENERATE_RESOURCE,+1,2); //Inexhaustible Cart of Ore
  461. giveArtBonus(113,Bonus::GENERATE_RESOURCE,+1,3); //Eversmoking Ring of Sulfur
  462. giveArtBonus(114,Bonus::GENERATE_RESOURCE,+1,0); //Inexhaustible Cart of Lumber
  463. giveArtBonus(115,Bonus::GENERATE_RESOURCE,+1000,6); //Endless Sack of Gold
  464. giveArtBonus(116,Bonus::GENERATE_RESOURCE,+750,6); //Endless Bag of Gold
  465. giveArtBonus(117,Bonus::GENERATE_RESOURCE,+500,6); //Endless Purse of Gold
  466. giveArtBonus(118,Bonus::CREATURE_GROWTH,+5,1); //Legs of Legion
  467. giveArtBonus(119,Bonus::CREATURE_GROWTH,+4,2); //Loins of Legion
  468. giveArtBonus(120,Bonus::CREATURE_GROWTH,+3,3); //Torso of Legion
  469. giveArtBonus(121,Bonus::CREATURE_GROWTH,+2,4); //Arms of Legion
  470. giveArtBonus(122,Bonus::CREATURE_GROWTH,+1,5); //Head of Legion
  471. //Sea Captain's Hat
  472. giveArtBonus(123,Bonus::WHIRLPOOL_PROTECTION,0);
  473. giveArtBonus(123,Bonus::SEA_MOVEMENT,+500);
  474. giveArtBonus(123,Bonus::SPELL,3,0);
  475. giveArtBonus(123,Bonus::SPELL,3,1);
  476. giveArtBonus(124,Bonus::SPELLS_OF_LEVEL,3,1); //Spellbinder's Hat
  477. giveArtBonus(125,Bonus::ENEMY_CANT_ESCAPE,0); //Shackles of War
  478. giveArtBonus(126,Bonus::BLOCK_SPELLS_ABOVE_LEVEL,0);//Orb of Inhibition
  479. //Armageddon's Blade
  480. giveArtBonus(128, Bonus::SPELL, 3, 26);
  481. giveArtBonus(128, Bonus::SPELL_IMMUNITY, 26);
  482. ART_ATTACK_AND_DEFENSE(128, +3);
  483. ART_PRIM_SKILL(128, 2, +3);
  484. ART_PRIM_SKILL(128, 3, +6);
  485. //Angelic Alliance
  486. giveArtBonus(129, Bonus::NONEVIL_ALIGNMENT_MIX, 0);
  487. giveArtBonus(129, Bonus::OPENING_BATTLE_SPELL, 10, 29); // Prayer
  488. //Cloak of the Undead King
  489. giveArtBonus(130, Bonus::IMPROVED_NECROMANCY, 0);
  490. //Elixir of Life
  491. giveArtBonus(131, Bonus::STACK_HEALTH, +25, -1, Bonus::PERCENT_TO_BASE);
  492. giveArtBonus(131, Bonus::HP_REGENERATION, +50);
  493. //Armor of the Damned
  494. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 54); // Slow
  495. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 47); // Disrupting Ray
  496. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 45); // Weakness
  497. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 52); // Misfortune
  498. // Statue of Legion - gives only 50% growth
  499. giveArtBonus(133, Bonus::CREATURE_GROWTH_PERCENT, 50);
  500. //Power of the Dragon Father
  501. giveArtBonus(134, Bonus::LEVEL_SPELL_IMMUNITY, 4);
  502. //Titan's Thunder
  503. // FIXME: should also add a permanent spell book, somehow.
  504. giveArtBonus(135, Bonus::SPELL, 3, 57);
  505. //Admiral's Hat
  506. giveArtBonus(136, Bonus::FREE_SHIP_BOARDING, 0);
  507. //Bow of the Sharpshooter
  508. giveArtBonus(137, Bonus::NO_SHOTING_PENALTY, 0);
  509. giveArtBonus(137, Bonus::FREE_SHOOTING, 0);
  510. //Wizard's Well
  511. giveArtBonus(138, Bonus::FULL_MANA_REGENERATION, 0);
  512. //Ring of the Magi
  513. giveArtBonus(139, Bonus::SPELL_DURATION, +50);
  514. //Cornucopia
  515. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 1);
  516. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 3);
  517. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 4);
  518. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, 5);
  519. }
  520. void CArtHandler::clear()
  521. {
  522. artifacts.clear();
  523. treasures.clear();
  524. minors.clear();
  525. majors.clear();
  526. relics.clear();
  527. }
  528. /**
  529. * Locally equips an artifact to a hero's worn slots. Unequips an already present artifact.
  530. * Does not test if the operation is legal.
  531. * @param artifWorn A hero's set of worn artifacts.
  532. * @param bonuses Optional list of bonuses to update.
  533. */
  534. void CArtHandler::equipArtifact
  535. (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID, BonusList *bonuses)
  536. {
  537. unequipArtifact(artifWorn, slotID, bonuses);
  538. const CArtifact &artifact = artifacts[artifactID];
  539. // Add artifact.
  540. artifWorn[slotID] = artifactID;
  541. // Add locks, in reverse order of being removed.
  542. if (artifact.constituents != NULL) {
  543. bool destConsumed = false; // Determines which constituent that will be counted for together with the artifact.
  544. BOOST_FOREACH(ui32 constituentID, *artifact.constituents) {
  545. const CArtifact &constituent = artifacts[constituentID];
  546. if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID)) {
  547. destConsumed = true;
  548. } else {
  549. BOOST_FOREACH(ui16 slot, constituent.possibleSlots) {
  550. if (!vstd::contains(artifWorn, slot)) {
  551. artifWorn[slot] = 145;
  552. break;
  553. }
  554. }
  555. }
  556. }
  557. }
  558. if (bonuses != NULL)
  559. artifact.addBonusesTo(bonuses);
  560. }
  561. /**
  562. * Locally unequips an artifact from a hero's worn slots.
  563. * Does not test if the operation is legal.
  564. * @param artifWorn A hero's set of worn artifacts.
  565. * @param bonuses Optional list of bonuses to update.
  566. */
  567. void CArtHandler::unequipArtifact
  568. (std::map<ui16, ui32> &artifWorn, ui16 slotID, BonusList *bonuses)
  569. {
  570. if (!vstd::contains(artifWorn, slotID))
  571. return;
  572. const CArtifact &artifact = artifacts[artifWorn[slotID]];
  573. // Remove artifact, if it's not already removed.
  574. artifWorn.erase(slotID);
  575. // Remove locks, in reverse order of being added.
  576. if (artifact.constituents != NULL) {
  577. bool destConsumed = false;
  578. BOOST_FOREACH(ui32 constituentID, *artifact.constituents) {
  579. const CArtifact &constituent = artifacts[constituentID];
  580. if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID)) {
  581. destConsumed = true;
  582. } else {
  583. BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots) {
  584. if (vstd::contains(artifWorn, slot) && artifWorn[slot] == 145) {
  585. artifWorn.erase(slot);
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. if (bonuses != NULL)
  593. artifact.removeBonusesFrom(bonuses);
  594. }