CArtHandler.cpp 28 KB

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