CArtHandler.cpp 26 KB

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