CArtHandler.cpp 27 KB

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