CArtHandler.cpp 23 KB

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