CArtHandler.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. #include "StdInc.h"
  2. #include "CArtHandler.h"
  3. #include "CLodHandler.h"
  4. #include "CGeneralTextHandler.h"
  5. #include <boost/random/linear_congruential.hpp>
  6. #include "../lib/VCMI_Lib.h"
  7. #include "CSpellHandler.h"
  8. #include "CObjectHandler.h"
  9. #include "NetPacks.h"
  10. extern CLodHandler *bitmaph;
  11. using namespace boost::assign;
  12. /*
  13. * CArtHandler.cpp, part of VCMI engine
  14. *
  15. * Authors: listed in file AUTHORS in main folder
  16. *
  17. * License: GNU General Public License v2.0 or later
  18. * Full text of license available in license.txt file, in main folder
  19. *
  20. */
  21. extern boost::rand48 ran;
  22. const std::string & CArtifact::Name() const
  23. {
  24. if(name.size())
  25. return name;
  26. else
  27. return VLC->generaltexth->artifNames[id];
  28. }
  29. const std::string & CArtifact::Description() const
  30. {
  31. if(description.size())
  32. return description;
  33. else
  34. return VLC->generaltexth->artifDescriptions[id];
  35. }
  36. bool CArtifact::isBig () const
  37. {
  38. return VLC->arth->isBigArtifact(id);
  39. }
  40. //
  41. // bool CArtifact::isModable () const
  42. // {
  43. // return (bool)dynamic_cast<const IModableArt *>(this);
  44. // }
  45. // /**
  46. // * Checks whether the artifact fits at a given slot.
  47. // * @param artifWorn A hero's set of worn artifacts.
  48. // */
  49. // bool CArtifact::fitsAt (const std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
  50. // {
  51. // if (!vstd::contains(possibleSlots, slotID))
  52. // return false;
  53. //
  54. // // Can't put an artifact in a locked slot.
  55. // std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.find(slotID);
  56. // if (it != artifWorn.end() && it->second->id == 145)
  57. // return false;
  58. //
  59. // // Check if a combination artifact fits.
  60. // // TODO: Might want a more general algorithm?
  61. // // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates.
  62. // if (constituents != NULL)
  63. // {
  64. // std::map<ui16, const CArtifact*> tempArtifWorn = artifWorn;
  65. // const ui16 ringSlots[] = {6, 7};
  66. // const ui16 miscSlots[] = {9, 10, 11, 12, 18};
  67. // int rings = 0;
  68. // int misc = 0;
  69. //
  70. // VLC->arth->unequipArtifact(tempArtifWorn, slotID);
  71. //
  72. // BOOST_FOREACH(ui32 constituentID, *constituents)
  73. // {
  74. // const CArtifact& constituent = *VLC->arth->artifacts[constituentID];
  75. // const int slot = constituent.possibleSlots[0];
  76. //
  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. //
  85. // // Ensure enough ring slots are free
  86. // for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++)
  87. // {
  88. // if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID)
  89. // rings--;
  90. // }
  91. // if (rings > 0)
  92. // return false;
  93. //
  94. // // Ensure enough misc slots are free.
  95. // for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++)
  96. // {
  97. // if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID)
  98. // misc--;
  99. // }
  100. // if (misc > 0)
  101. // return false;
  102. // }
  103. //
  104. // return true;
  105. // }
  106. // bool CArtifact::canBeAssembledTo (const std::map<ui16, const CArtifact*> &artifWorn, ui32 artifactID) const
  107. // {
  108. // if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID))
  109. // return false;
  110. //
  111. // const CArtifact &artifact = *VLC->arth->artifacts[artifactID];
  112. // assert(artifact.constituents);
  113. //
  114. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  115. // {
  116. // bool found = false;
  117. // for (std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it)
  118. // {
  119. // if (it->second->id == constituentID)
  120. // {
  121. // found = true;
  122. // break;
  123. // }
  124. // }
  125. // if (!found)
  126. // return false;
  127. // }
  128. //
  129. // return true;
  130. // }
  131. CArtifact::CArtifact()
  132. {
  133. setNodeType(ARTIFACT);
  134. }
  135. CArtifact::~CArtifact()
  136. {
  137. }
  138. int CArtifact::getArtClassSerial() const
  139. {
  140. if(id == 1)
  141. return 4;
  142. switch(aClass)
  143. {
  144. case ART_TREASURE:
  145. return 0;
  146. case ART_MINOR:
  147. return 1;
  148. case ART_MAJOR:
  149. return 2;
  150. case ART_RELIC:
  151. return 3;
  152. case ART_SPECIAL:
  153. return 5;
  154. }
  155. return -1;
  156. }
  157. std::string CArtifact::nodeName() const
  158. {
  159. return "Artifact: " + Name();
  160. }
  161. // void CArtifact::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
  162. // {
  163. // //combined artifact carries bonuses from its parts
  164. // if(constituents)
  165. // {
  166. // BOOST_FOREACH(ui32 id, *constituents)
  167. // out.insert(VLC->arth->artifacts[id]);
  168. // }
  169. // }
  170. // void CScroll::Init()
  171. // {
  172. // // addNewBonus (Bonus (Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT, 1, id, spellid, Bonus::INDEPENDENT_MAX));
  173. // // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name);
  174. // }
  175. void CArtifact::setDescription (std::string desc)
  176. {
  177. description = desc;
  178. }
  179. CArtHandler::CArtHandler()
  180. {
  181. VLC->arth = this;
  182. // War machines are the default big artifacts.
  183. for (ui32 i = 3; i <= 6; i++)
  184. bigArtifacts.insert(i);
  185. //modableArtifacts = boost::assign::map_list_of(1, 1)(146,3)(147,3)(148,3)(150,3)(151,3)(152,3)(154,3)(156,2);
  186. }
  187. CArtHandler::~CArtHandler()
  188. {
  189. for (std::vector< ConstTransitivePtr<CArtifact> >::iterator it = artifacts.begin(); it != artifacts.end(); ++it)
  190. {
  191. delete (*it)->constituents;
  192. delete (*it)->constituentOf;
  193. }
  194. }
  195. void CArtHandler::loadArtifacts(bool onlyTxt)
  196. {
  197. std::vector<ui16> slots;
  198. slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
  199. static std::map<char, CArtifact::EartClass> classes =
  200. map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
  201. std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
  202. int it=0;
  203. for(int i=0; i<2; ++i)
  204. {
  205. loadToIt(dump,buf,it,3);
  206. }
  207. VLC->generaltexth->artifNames.resize(GameConstants::ARTIFACTS_QUANTITY);
  208. VLC->generaltexth->artifDescriptions.resize(GameConstants::ARTIFACTS_QUANTITY);
  209. std::map<ui32,ui8>::iterator itr;
  210. for (int i=0; i<GameConstants::ARTIFACTS_QUANTITY; i++)
  211. {
  212. CArtifact *art = new CArtifact();
  213. CArtifact &nart = *art;
  214. nart.id=i;
  215. loadToIt(VLC->generaltexth->artifNames[i],buf,it,4);
  216. loadToIt(pom,buf,it,4);
  217. nart.price=atoi(pom.c_str());
  218. nart.possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
  219. nart.possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
  220. //nart.possibleSlots[ArtBearer::COMMANDER];
  221. for(int j=0;j<slots.size();j++)
  222. {
  223. loadToIt(pom,buf,it,4);
  224. if(pom.size() && pom[0]=='x')
  225. nart.possibleSlots[ArtBearer::HERO].push_back(slots[j]);
  226. }
  227. loadToIt(pom,buf,it,4);
  228. nart.aClass = classes[pom[0]];
  229. //load description and remove quotation marks
  230. std::string &desc = VLC->generaltexth->artifDescriptions[i];
  231. loadToIt(desc,buf,it,3);
  232. if(desc[0] == '\"' && desc[desc.size()-1] == '\"')
  233. desc = desc.substr(1,desc.size()-2);
  234. if(onlyTxt)
  235. continue;
  236. // Fill in information about combined artifacts. Should perhaps be moved to a config file?
  237. nart.constituentOf = NULL;
  238. switch (nart.id)
  239. {
  240. case 129: // Angelic Alliance
  241. nart.constituents = new std::vector<ui32>();
  242. *nart.constituents += 31, 32, 33, 34, 35, 36;
  243. break;
  244. case 130: // Cloak of the Undead King
  245. nart.constituents = new std::vector<ui32>();
  246. *nart.constituents += 54, 55, 56;
  247. break;
  248. case 131: // Elixir of Life
  249. nart.constituents = new std::vector<ui32>();
  250. *nart.constituents += 94, 95, 96;
  251. break;
  252. case 132: // Armor of the Damned
  253. nart.constituents = new std::vector<ui32>();
  254. *nart.constituents += 8, 14, 20, 26;
  255. break;
  256. case 133: // Statue of Legion
  257. nart.constituents = new std::vector<ui32>();
  258. *nart.constituents += 118, 119, 120, 121, 122;
  259. break;
  260. case 134: // Power of the Dragon Father
  261. nart.constituents = new std::vector<ui32>();
  262. *nart.constituents += 37, 38, 39, 40, 41, 42, 43, 44, 45;
  263. break;
  264. case 135: // Titan's Thunder
  265. nart.constituents = new std::vector<ui32>();
  266. *nart.constituents += 12, 18, 24, 30;
  267. break;
  268. case 136: // Admiral's Hat
  269. nart.constituents = new std::vector<ui32>();
  270. *nart.constituents += 71, 123;
  271. break;
  272. case 137: // Bow of the Sharpshooter
  273. nart.constituents = new std::vector<ui32>();
  274. *nart.constituents += 60, 61, 62;
  275. break;
  276. case 138: // Wizards' Well
  277. nart.constituents = new std::vector<ui32>();
  278. *nart.constituents += 73, 74, 75;
  279. break;
  280. case 139: // Ring of the Magi
  281. nart.constituents = new std::vector<ui32>();
  282. *nart.constituents += 76, 77, 78;
  283. break;
  284. case 140: // Cornucopia
  285. nart.constituents = new std::vector<ui32>();
  286. *nart.constituents += 109, 110, 111, 113;
  287. break;
  288. // TODO: WoG combinationals
  289. default:
  290. nart.constituents = NULL;
  291. break;
  292. }
  293. artifacts.push_back(&nart);
  294. }
  295. sortArts();
  296. if(onlyTxt)
  297. return;
  298. addBonuses();
  299. // Populate reverse mappings of combinational artifacts.
  300. BOOST_FOREACH(CArtifact *artifact, artifacts)
  301. {
  302. if (artifact->constituents != NULL)
  303. {
  304. BOOST_FOREACH(ui32 constituentID, *artifact->constituents)
  305. {
  306. if (artifacts[constituentID]->constituentOf == NULL)
  307. artifacts[constituentID]->constituentOf = new std::vector<ui32>();
  308. artifacts[constituentID]->constituentOf->push_back(artifact->id);
  309. }
  310. }
  311. }
  312. }
  313. int CArtHandler::convertMachineID(int id, bool creToArt )
  314. {
  315. int dif = 142;
  316. if(creToArt)
  317. {
  318. switch (id)
  319. {
  320. case 147:
  321. dif--;
  322. break;
  323. case 148:
  324. dif++;
  325. break;
  326. }
  327. dif = -dif;
  328. }
  329. else
  330. {
  331. switch (id)
  332. {
  333. case 6:
  334. dif--;
  335. break;
  336. case 5:
  337. dif++;
  338. break;
  339. }
  340. }
  341. return id + dif;
  342. }
  343. void CArtHandler::sortArts()
  344. {
  345. //for (int i=0; i<allowedArtifacts.size(); ++i) //do 144, bo nie chcemy bzdurek
  346. //{
  347. // switch (allowedArtifacts[i]->aClass)
  348. // {
  349. // case CArtifact::ART_TREASURE:
  350. // treasures.push_back(allowedArtifacts[i]);
  351. // break;
  352. // case CArtifact::ART_MINOR:
  353. // minors.push_back(allowedArtifacts[i]);
  354. // break;
  355. // case CArtifact::ART_MAJOR:
  356. // majors.push_back(allowedArtifacts[i]);
  357. // break;
  358. // case CArtifact::ART_RELIC:
  359. // relics.push_back(allowedArtifacts[i]);
  360. // break;
  361. // }
  362. //}
  363. }
  364. void CArtHandler::erasePickedArt (si32 id)
  365. {
  366. std::vector<CArtifact*>* ptr;
  367. CArtifact *art = artifacts[id];
  368. switch (art->aClass)
  369. {
  370. case CArtifact::ART_TREASURE:
  371. ptr = &treasures;
  372. break;
  373. case CArtifact::ART_MINOR:
  374. ptr = &minors;
  375. break;
  376. case CArtifact::ART_MAJOR:
  377. ptr = &majors;
  378. break;
  379. case CArtifact::ART_RELIC:
  380. ptr = &relics;
  381. break;
  382. default: //special artifacts should not be erased
  383. return;
  384. }
  385. ptr->erase (std::find(ptr->begin(), ptr->end(), art)); //remove the artifact from available list
  386. }
  387. ui16 CArtHandler::getRandomArt(int flags)
  388. {
  389. std::vector<ConstTransitivePtr<CArtifact> > out;
  390. getAllowed(out, flags);
  391. ui16 id = out[ran() % out.size()]->id;
  392. erasePickedArt (id);
  393. return id;
  394. }
  395. ui16 CArtHandler::getArtSync (ui32 rand, int flags)
  396. {
  397. std::vector<ConstTransitivePtr<CArtifact> > out;
  398. getAllowed(out, flags);
  399. CArtifact *art = out[rand % out.size()];
  400. return art->id;
  401. }
  402. void CArtHandler::getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags)
  403. {
  404. if (flags & CArtifact::ART_TREASURE)
  405. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  406. if (flags & CArtifact::ART_MINOR)
  407. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  408. if (flags & CArtifact::ART_MAJOR)
  409. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  410. if (flags & CArtifact::ART_RELIC)
  411. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  412. if (!out.size()) //no artifact of specified rarity, we need to take another one
  413. {
  414. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  415. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  416. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  417. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  418. }
  419. if (!out.size()) //no arts are available at all
  420. {
  421. out.resize (64);
  422. std::fill_n (out.begin(), 64, artifacts[2]); //Give Grail - this can't be banned (hopefully)
  423. }
  424. }
  425. void CArtHandler::getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag)
  426. {
  427. if (arts->empty()) //restock available arts
  428. {
  429. for (int i = 0; i < allowedArtifacts.size(); ++i)
  430. {
  431. if (allowedArtifacts[i]->aClass == flag)
  432. arts->push_back(allowedArtifacts[i]);
  433. }
  434. }
  435. for (int i = 0; i < arts->size(); ++i)
  436. {
  437. CArtifact *art = (*arts)[i];
  438. out.push_back(art);
  439. }
  440. }
  441. void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int subtype, int valType, ILimiter * limiter, int additionalInfo)
  442. {
  443. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
  444. added->additionalInfo = additionalInfo;
  445. added->valType = valType;
  446. added->limiter.reset(limiter);
  447. if(type == Bonus::MORALE || type == Bonus::LUCK)
  448. added->description = artifacts[aid]->Name() + (val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(val);
  449. else
  450. added->description = artifacts[aid]->Name();
  451. artifacts[aid]->addNewBonus(added);
  452. }
  453. void CArtHandler::giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator /*= NULL*/, int additionalInfo)
  454. {
  455. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
  456. added->additionalInfo = additionalInfo;
  457. added->valType = Bonus::BASE_NUMBER;
  458. added->propagator.reset(propagator);
  459. if(type == Bonus::MORALE || type == Bonus::LUCK)
  460. added->description = artifacts[aid]->Name() + (val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(val);
  461. else
  462. added->description = artifacts[aid]->Name();
  463. artifacts[aid]->addNewBonus(added);
  464. }
  465. void CArtHandler::makeItCreatureArt (int aid, bool onlyCreature /*=true*/)
  466. {
  467. CArtifact *a = artifacts[aid];
  468. if (onlyCreature)
  469. {
  470. a->possibleSlots[ArtBearer::HERO].clear();
  471. //a->possibleSlots[ArtBearer::COMMANDER].clear();
  472. }
  473. a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
  474. };
  475. void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/)
  476. {
  477. //CArtifact *a = artifacts[aid];
  478. //if (onlyCommander)
  479. //{
  480. // a->possibleSlots[ArtBearer::HERO].clear();
  481. // a->possibleSlots[ArtBearer::CREATURE].clear();
  482. //}
  483. //for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
  484. // a->possibleSlots[ArtBearer::COMMANDER].push_back(i);
  485. };
  486. void CArtHandler::addBonuses()
  487. {
  488. #define ART_PRIM_SKILL(ID, whichSkill, val) giveArtBonus(ID,Bonus::PRIMARY_SKILL,val,whichSkill)
  489. #define ART_MORALE(ID, val) giveArtBonus(ID,Bonus::MORALE,val)
  490. #define ART_LUCK(ID, val) giveArtBonus(ID,Bonus::LUCK,val)
  491. #define ART_MORALE_AND_LUCK(ID, val) giveArtBonus(ID,Bonus::MORALE_AND_LUCK,val)
  492. #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)
  493. #define ART_ATTACK_AND_DEFENSE(ID, val) ART_PRIM_SKILL(ID,0,val); ART_PRIM_SKILL(ID,1,val)
  494. #define ART_POWER_AND_KNOWLEDGE(ID, val) ART_PRIM_SKILL(ID,2,val); ART_PRIM_SKILL(ID,3,val)
  495. //Attack bonus artifacts (Weapons)
  496. ART_PRIM_SKILL(7,0,+2); //Centaur Axe
  497. ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight
  498. ART_PRIM_SKILL(9,0,+4); //Greater Gnoll's Flail
  499. ART_PRIM_SKILL(10,0,+5); //Ogre's Club of Havoc
  500. ART_PRIM_SKILL(11,0,+6); //Sword of Hellfire
  501. ART_PRIM_SKILL(12,0,+12); //Titan's Gladius
  502. ART_PRIM_SKILL(12,1,-3); //Titan's Gladius
  503. //Defense bonus artifacts (Shields)
  504. ART_PRIM_SKILL(13,1,+2); //Shield of the Dwarven Lords
  505. ART_PRIM_SKILL(14,1,+3); //Shield of the Yawning Dead
  506. ART_PRIM_SKILL(15,1,+4); //Buckler of the Gnoll King
  507. ART_PRIM_SKILL(16,1,+5); //Targ of the Rampaging Ogre
  508. ART_PRIM_SKILL(17,1,+6); //Shield of the Damned
  509. ART_PRIM_SKILL(18,1,+12); //Sentinel's Shield
  510. ART_PRIM_SKILL(18,0,-3); //Sentinel's Shield
  511. //Knowledge bonus artifacts (Helmets)
  512. ART_PRIM_SKILL(19,3,+1); //Helm of the Alabaster Unicorn
  513. ART_PRIM_SKILL(20,3,+2); //Skull Helmet
  514. ART_PRIM_SKILL(21,3,+3); //Helm of Chaos
  515. ART_PRIM_SKILL(22,3,+4); //Crown of the Supreme Magi
  516. ART_PRIM_SKILL(23,3,+5); //Hellstorm Helmet
  517. ART_PRIM_SKILL(24,3,+10); //Thunder Helmet
  518. ART_PRIM_SKILL(24,2,-2); //Thunder Helmet
  519. //Spell power bonus artifacts (Armours)
  520. ART_PRIM_SKILL(25,2,+1); //Breastplate of Petrified Wood
  521. ART_PRIM_SKILL(26,2,+2); //Rib Cage
  522. ART_PRIM_SKILL(27,2,+3); //Scales of the Greater Basilisk
  523. ART_PRIM_SKILL(28,2,+4); //Tunic of the Cyclops King
  524. ART_PRIM_SKILL(29,2,+5); //Breastplate of Brimstone
  525. ART_PRIM_SKILL(30,2,+10); //Titan's Cuirass
  526. ART_PRIM_SKILL(30,3,-2); //Titan's Cuirass
  527. //All primary skills (various)
  528. ART_ALL_PRIM_SKILLS(31,+1); //Armor of Wonder
  529. ART_ALL_PRIM_SKILLS(32,+2); //Sandals of the Saint
  530. ART_ALL_PRIM_SKILLS(33,+3); //Celestial Necklace of Bliss
  531. ART_ALL_PRIM_SKILLS(34,+4); //Lion's Shield of Courage
  532. ART_ALL_PRIM_SKILLS(35,+5); //Sword of Judgement
  533. ART_ALL_PRIM_SKILLS(36,+6); //Helm of Heavenly Enlightenment
  534. //Attack and Defense (various)
  535. ART_ATTACK_AND_DEFENSE(37,+1); //Quiet Eye of the Dragon
  536. ART_ATTACK_AND_DEFENSE(38,+2); //Red Dragon Flame Tongue
  537. ART_ATTACK_AND_DEFENSE(39,+3); //Dragon Scale Shield
  538. ART_ATTACK_AND_DEFENSE(40,+4); //Dragon Scale Armor
  539. //Spell power and Knowledge (various)
  540. ART_POWER_AND_KNOWLEDGE(41,+1); //Dragonbone Greaves
  541. ART_POWER_AND_KNOWLEDGE(42,+2); //Dragon Wing Tabard
  542. ART_POWER_AND_KNOWLEDGE(43,+3); //Necklace of Dragonteeth
  543. ART_POWER_AND_KNOWLEDGE(44,+4); //Crown of Dragontooth
  544. //Luck and morale
  545. ART_MORALE(45,+1); //Still Eye of the Dragon
  546. ART_LUCK(45,+1); //Still Eye of the Dragon
  547. ART_LUCK(46,+1); //Clover of Fortune
  548. ART_LUCK(47,+1); //Cards of Prophecy
  549. ART_LUCK(48,+1); //Ladybird of Luck
  550. ART_MORALE(49,+1); //Badge of Courage -> +1 morale
  551. giveArtBonus(49,Bonus::MIND_IMMUNITY,0); //immunity to hostile mind spells:
  552. ART_MORALE(50,+1); //Crest of Valor
  553. ART_MORALE(51,+1); //Glyph of Gallantry
  554. giveArtBonus(52,Bonus::SIGHT_RADIOUS,+1);//Speculum
  555. giveArtBonus(53,Bonus::SIGHT_RADIOUS,+1);//Spyglass
  556. //necromancy bonus
  557. giveArtBonus(54,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Amulet of the Undertaker
  558. giveArtBonus(55,Bonus::SECONDARY_SKILL_PREMY,+10, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Vampire's Cowl
  559. giveArtBonus(56,Bonus::SECONDARY_SKILL_PREMY,+15, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Dead Man's Boots
  560. giveArtBonus(57,Bonus::MAGIC_RESISTANCE,+5, 0);//Garniture of Interference
  561. giveArtBonus(58,Bonus::MAGIC_RESISTANCE,+10, 0);//Surcoat of Counterpoise
  562. giveArtBonus(59,Bonus::MAGIC_RESISTANCE,+15, 0);//Boots of Polarity
  563. //archery bonus
  564. giveArtBonus(60,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Bow of Elven Cherrywood
  565. giveArtBonus(61,Bonus::SECONDARY_SKILL_PREMY,+10,CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Bowstring of the Unicorn's Mane
  566. giveArtBonus(62,Bonus::SECONDARY_SKILL_PREMY,+15,CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Angel Feather Arrows
  567. //eagle eye bonus
  568. giveArtBonus(63,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Bird of Perception
  569. giveArtBonus(64,Bonus::SECONDARY_SKILL_PREMY,+10, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Stoic Watchman
  570. giveArtBonus(65,Bonus::SECONDARY_SKILL_PREMY,+15, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Emblem of Cognizance
  571. //reducing cost of surrendering
  572. giveArtBonus(66,Bonus::SURRENDER_DISCOUNT,+10);//Statesman's Medal
  573. giveArtBonus(67,Bonus::SURRENDER_DISCOUNT,+10);//Diplomat's Ring
  574. giveArtBonus(68,Bonus::SURRENDER_DISCOUNT,+10);//Ambassador's Sash
  575. giveArtBonus(69,Bonus::STACKS_SPEED,+1);//Ring of the Wayfarer
  576. giveArtBonus(70,Bonus::LAND_MOVEMENT,+300);//Equestrian's Gloves
  577. giveArtBonus(71,Bonus::SEA_MOVEMENT,+1000);//Necklace of Ocean Guidance
  578. giveArtBonus(72,Bonus::FLYING_MOVEMENT, 0, 1);//Angel Wings
  579. giveArtBonus(73,Bonus::MANA_REGENERATION,+1);//Charm of Mana
  580. giveArtBonus(74,Bonus::MANA_REGENERATION,+2);//Talisman of Mana
  581. giveArtBonus(75,Bonus::MANA_REGENERATION,+3);//Mystic Orb of Mana
  582. giveArtBonus(76,Bonus::SPELL_DURATION,+1);//Collar of Conjuring
  583. giveArtBonus(77,Bonus::SPELL_DURATION,+2);//Ring of Conjuring
  584. giveArtBonus(78,Bonus::SPELL_DURATION,+3);//Cape of Conjuring
  585. giveArtBonus(79,Bonus::AIR_SPELL_DMG_PREMY,+50);//Orb of the Firmament
  586. giveArtBonus(80,Bonus::EARTH_SPELL_DMG_PREMY,+50);//Orb of Silt
  587. giveArtBonus(81,Bonus::FIRE_SPELL_DMG_PREMY,+50);//Orb of Tempestuous Fire
  588. giveArtBonus(82,Bonus::WATER_SPELL_DMG_PREMY,+50);//Orb of Driving Rain
  589. giveArtBonus(83,Bonus::LEVEL_SPELL_IMMUNITY,3,-1,Bonus::INDEPENDENT_MAX);//Recanter's Cloak
  590. giveArtBonus(84,Bonus::BLOCK_MORALE,0);//Spirit of Oppression
  591. giveArtBonus(85,Bonus::BLOCK_LUCK,0);//Hourglass of the Evil Hour
  592. giveArtBonus(86,Bonus::FIRE_SPELLS,0);//Tome of Fire Magic
  593. giveArtBonus(87,Bonus::AIR_SPELLS,0);//Tome of Air Magic
  594. giveArtBonus(88,Bonus::WATER_SPELLS,0);//Tome of Water Magic
  595. giveArtBonus(89,Bonus::EARTH_SPELLS,0);//Tome of Earth Magic
  596. giveArtBonus(90,Bonus::WATER_WALKING, 0, 1);//Boots of Levitation
  597. giveArtBonus(91,Bonus::NO_DISTANCE_PENALTY,0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));//Golden Bow
  598. giveArtBonus(91,Bonus::NO_WALL_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  599. giveArtBonus(92,Bonus::SPELL_IMMUNITY,0,35);//Sphere of Permanence
  600. giveArtBonus(93,Bonus::NEGATE_ALL_NATURAL_IMMUNITIES,0);//Orb of Vulnerability
  601. giveArtBonus(94,Bonus::STACK_HEALTH,+1);//Ring of Vitality
  602. giveArtBonus(95,Bonus::STACK_HEALTH,+1);//Ring of Life
  603. giveArtBonus(96,Bonus::STACK_HEALTH,+2);//Vial of Lifeblood
  604. giveArtBonus(97,Bonus::STACKS_SPEED,+1);//Necklace of Swiftness
  605. giveArtBonus(98,Bonus::LAND_MOVEMENT,+600);//Boots of Speed
  606. giveArtBonus(99,Bonus::STACKS_SPEED,+2);//Cape of Velocity
  607. giveArtBonus(100,Bonus::SPELL_IMMUNITY,0,59);//Pendant of Dispassion
  608. giveArtBonus(101,Bonus::SPELL_IMMUNITY,0,62);//Pendant of Second Sight
  609. giveArtBonus(102,Bonus::SPELL_IMMUNITY,0,42);//Pendant of Holiness
  610. giveArtBonus(103,Bonus::SPELL_IMMUNITY,0,24);//Pendant of Life
  611. giveArtBonus(104,Bonus::SPELL_IMMUNITY,0,25, 1, new HasAnotherBonusLimiter(Bonus::UNDEAD));//Pendant of Death does not display info for living stacks
  612. giveArtBonus(105,Bonus::SPELL_IMMUNITY,0,60);//Pendant of Free Will
  613. giveArtBonus(106,Bonus::SPELL_IMMUNITY,0,17);//Pendant of Negativity
  614. giveArtBonus(107,Bonus::SPELL_IMMUNITY,0,61);//Pendant of Total Recall
  615. giveArtBonus(108,Bonus::MORALE,+3);//Pendant of Courage
  616. giveArtBonus(108,Bonus::LUCK,+3);//Pendant of Courage
  617. giveArtBonus(109,Bonus::GENERATE_RESOURCE,+1,4); //Everflowing Crystal Cloak
  618. giveArtBonus(110,Bonus::GENERATE_RESOURCE,+1,5); //Ring of Infinite Gems
  619. giveArtBonus(111,Bonus::GENERATE_RESOURCE,+1,1); //Everpouring Vial of Mercury
  620. giveArtBonus(112,Bonus::GENERATE_RESOURCE,+1,2); //Inexhaustible Cart of Ore
  621. giveArtBonus(113,Bonus::GENERATE_RESOURCE,+1,3); //Eversmoking Ring of Sulfur
  622. giveArtBonus(114,Bonus::GENERATE_RESOURCE,+1,0); //Inexhaustible Cart of Lumber
  623. giveArtBonus(115,Bonus::GENERATE_RESOURCE,+1000, Res::GOLD); //Endless Sack of Gold
  624. giveArtBonus(116,Bonus::GENERATE_RESOURCE,+750, Res::GOLD); //Endless Bag of Gold
  625. giveArtBonus(117,Bonus::GENERATE_RESOURCE,+500, Res::GOLD); //Endless Purse of Gold
  626. giveArtBonus(118,Bonus::CREATURE_GROWTH,+5,1, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Legs of Legion
  627. giveArtBonus(119,Bonus::CREATURE_GROWTH,+4,2, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Loins of Legion
  628. giveArtBonus(120,Bonus::CREATURE_GROWTH,+3,3, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Torso of Legion
  629. giveArtBonus(121,Bonus::CREATURE_GROWTH,+2,4, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Arms of Legion
  630. giveArtBonus(122,Bonus::CREATURE_GROWTH,+1,5, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Head of Legion
  631. //Sea Captain's Hat
  632. giveArtBonus(123,Bonus::WHIRLPOOL_PROTECTION,0);
  633. giveArtBonus(123,Bonus::SEA_MOVEMENT,+500);
  634. giveArtBonus(123,Bonus::SPELL,3,0, Bonus::INDEPENDENT_MAX);
  635. giveArtBonus(123,Bonus::SPELL,3,1, Bonus::INDEPENDENT_MAX);
  636. giveArtBonus(124,Bonus::SPELLS_OF_LEVEL,3,1); //Spellbinder's Hat
  637. giveArtBonus(125,Bonus::ENEMY_CANT_ESCAPE,0); //Shackles of War
  638. giveArtBonus(126,Bonus::LEVEL_SPELL_IMMUNITY,GameConstants::SPELL_LEVELS,-1,Bonus::INDEPENDENT_MAX);//Orb of Inhibition
  639. //vial of dragon blood
  640. giveArtBonus(127, Bonus::PRIMARY_SKILL, +5, PrimarySkill::ATTACK, Bonus::BASE_NUMBER, new HasAnotherBonusLimiter(Bonus::DRAGON_NATURE));
  641. giveArtBonus(127, Bonus::PRIMARY_SKILL, +5, PrimarySkill::DEFENSE, Bonus::BASE_NUMBER, new HasAnotherBonusLimiter(Bonus::DRAGON_NATURE));
  642. //Armageddon's Blade
  643. giveArtBonus(128, Bonus::SPELL, 3, 26, Bonus::INDEPENDENT_MAX);
  644. giveArtBonus(128, Bonus::SPELL_IMMUNITY,0, 26);
  645. ART_ATTACK_AND_DEFENSE(128, +3);
  646. ART_PRIM_SKILL(128, 2, +3);
  647. ART_PRIM_SKILL(128, 3, +6);
  648. //Angelic Alliance
  649. giveArtBonus(129, Bonus::NONEVIL_ALIGNMENT_MIX, 0);
  650. giveArtBonus(129, Bonus::OPENING_BATTLE_SPELL, 10, 48); // Prayer
  651. //Cloak of the Undead King
  652. giveArtBonus(130, Bonus::IMPROVED_NECROMANCY, 0);
  653. //Elixir of Life
  654. giveArtBonus(131, Bonus::STACK_HEALTH, +25, -1, Bonus::PERCENT_TO_BASE);
  655. giveArtBonus(131, Bonus::HP_REGENERATION, +50);
  656. //Armor of the Damned
  657. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 54); // Slow
  658. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 47); // Disrupting Ray
  659. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 45); // Weakness
  660. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 52); // Misfortune
  661. // Statue of Legion - gives only 50% growth
  662. giveArtBonus(133, Bonus::CREATURE_GROWTH_PERCENT, 50, -1, new CPropagatorNodeType(CBonusSystemNode::PLAYER));
  663. //Power of the Dragon Father
  664. giveArtBonus(134, Bonus::LEVEL_SPELL_IMMUNITY, 4, -1, Bonus::INDEPENDENT_MAX);
  665. //Titan's Thunder
  666. giveArtBonus(135, Bonus::SPELL, 3, 57);
  667. //Admiral's Hat
  668. giveArtBonus(136, Bonus::FREE_SHIP_BOARDING, 0);
  669. //Bow of the Sharpshooter
  670. giveArtBonus(137, Bonus::NO_DISTANCE_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  671. giveArtBonus(137, Bonus::NO_WALL_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  672. giveArtBonus(137, Bonus::FREE_SHOOTING, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  673. //Wizard's Well
  674. giveArtBonus(138, Bonus::FULL_MANA_REGENERATION, 0);
  675. //Ring of the Magi
  676. giveArtBonus(139, Bonus::SPELL_DURATION, +50);
  677. //Cornucopia
  678. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::MERCURY);
  679. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::SULFUR);
  680. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::CRYSTAL);
  681. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::GEMS);
  682. //Stack artifact test
  683. if (GameConstants::STACK_ARTIFACT)
  684. {
  685. makeItCreatureArt(141);
  686. makeItCreatureArt(142);
  687. makeItCreatureArt(143);
  688. makeItCreatureArt(156);
  689. //Magic Wand
  690. giveArtBonus(141, Bonus::CASTS, 10);
  691. giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::IMPLOSION);
  692. giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::FIREBALL);
  693. giveArtBonus(141, Bonus::RANDOM_SPELLCASTER, 0);
  694. giveArtBonus(141, Bonus::DAEMON_SUMMONING, 10, 63); //rise vampire lords
  695. giveArtBonus(141, Bonus::ENCHANTER, 0, Spells::LIGHTNING_BOLT, NULL, 2);
  696. giveArtBonus(141, Bonus::REBIRTH, 1, 1);
  697. giveArtBonus(141, Bonus::MANA_DRAIN, 10);
  698. giveArtBonus(141, Bonus::HEALER, 25);
  699. artifacts[141].get()->setDescription ("Casts Implosion / Fireball, random Genie spell, summons Vampire Lords from corpses, casts Lighthning Bolt every 2 turns, rebirths at least one creature, drains enemy mana and heals");
  700. //Tower Arrow
  701. giveArtBonus(142, Bonus::NO_DISTANCE_PENALTY, 0);
  702. giveArtBonus(142, Bonus::ADDITIONAL_ATTACK, 2);
  703. giveArtBonus(142, Bonus::SPELL_LIKE_ATTACK, 1, Spells::INFERNO);
  704. giveArtBonus(142, Bonus::CATAPULT, 0);
  705. giveArtBonus(142, Bonus::ACID_BREATH, 20);
  706. giveArtBonus(142, Bonus::SHOTS, 200, 0, Bonus::PERCENT_TO_BASE);
  707. giveArtBonus(142, Bonus::SPELL_BEFORE_ATTACK, 50, Spells::AGE, NULL, 1);
  708. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 50, Spells::BERSERK, NULL, 1);
  709. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 50, Spells::POISON, NULL, 1);
  710. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 50, Spells::DISRUPTING_RAY, NULL, 1);
  711. artifacts[142].get()->setDescription ("Tripple shots, tripple attack, casts various spells during attack, attacks have range of Inferno, no distance penalty, catapult");
  712. //Monster's Power
  713. giveArtBonus(143, Bonus::STACK_HEALTH, +100, -1, Bonus::PERCENT_TO_BASE);
  714. giveArtBonus(143, Bonus::CREATURE_DAMAGE, +100, 2, Bonus::PERCENT_TO_ALL);
  715. giveArtBonus(143, Bonus::HP_REGENERATION, 50);
  716. giveArtBonus(143, Bonus::NO_RETALIATION, 0);
  717. giveArtBonus(143, Bonus::RETURN_AFTER_STRIKE, 0);
  718. giveArtBonus(143, Bonus::ATTACKS_ALL_ADJACENT, 0);
  719. giveArtBonus(143, Bonus::SPELL_RESISTANCE_AURA, 100);
  720. giveArtBonus(143, Bonus::DIRECT_DAMAGE_IMMUNITY, 0);
  721. artifacts[143].get()->setDescription ("Double health, double max damage, hp regeneration, can't retaliate, return after strike, attack all around, 100% spell reisstance aura, immune to direct damage spells");
  722. //Warlord's banner
  723. giveArtBonus(156, Bonus::STACK_HEALTH, +2);
  724. artifacts[156].get()->setDescription ("+2 stack HP");
  725. }
  726. if (GameConstants::COMMANDERS)
  727. {
  728. for (int i = 146; i <= 155; ++i)
  729. {
  730. makeItCommanderArt (i);
  731. }
  732. }
  733. }
  734. void CArtHandler::clear()
  735. {
  736. BOOST_FOREACH(CArtifact *art, artifacts)
  737. delete art;
  738. artifacts.clear();
  739. clearHlpLists();
  740. }
  741. // /**
  742. // * Locally equips an artifact to a hero's worn slots. Unequips an already present artifact.
  743. // * Does not test if the operation is legal.
  744. // * @param artifWorn A hero's set of worn artifacts.
  745. // * @param bonuses Optional list of bonuses to update.
  746. // */
  747. // void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art ) const
  748. // {
  749. // unequipArtifact(artifWorn, slotID);
  750. //
  751. // if (art) //false when artifact is NULL -> slot set to empty
  752. // {
  753. // const CArtifact &artifact = *art;
  754. //
  755. // // Add artifact.
  756. // artifWorn[slotID] = art;
  757. //
  758. // // Add locks, in reverse order of being removed.
  759. // if (artifact.constituents != NULL)
  760. // {
  761. // bool destConsumed = false; // Determines which constituent that will be counted for together with the artifact.
  762. //
  763. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  764. // {
  765. // const CArtifact &constituent = *artifacts[constituentID];
  766. //
  767. // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
  768. // {
  769. // destConsumed = true;
  770. // }
  771. // else
  772. // {
  773. // BOOST_FOREACH(ui16 slot, constituent.possibleSlots)
  774. // {
  775. // if (!vstd::contains(artifWorn, slot))
  776. // {
  777. // artifWorn[slot] = VLC->arth->artifacts[145]; //lock
  778. // break;
  779. // }
  780. // }
  781. // }
  782. // }
  783. // }
  784. // }
  785. // }
  786. //
  787. // /**
  788. // * Locally unequips an artifact from a hero's worn slots.
  789. // * Does not test if the operation is legal.
  790. // * @param artifWorn A hero's set of worn artifacts.
  791. // * @param bonuses Optional list of bonuses to update.
  792. // */
  793. // void CArtHandler::unequipArtifact(std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
  794. // {
  795. // if (!vstd::contains(artifWorn, slotID))
  796. // return;
  797. //
  798. // const CArtifact &artifact = *artifWorn[slotID];
  799. //
  800. // // Remove artifact, if it's not already removed.
  801. // artifWorn.erase(slotID);
  802. //
  803. // // Remove locks, in reverse order of being added.
  804. // if (artifact.constituents != NULL)
  805. // {
  806. // bool destConsumed = false;
  807. //
  808. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  809. // {
  810. // const CArtifact &constituent = *artifacts[constituentID];
  811. //
  812. // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
  813. // {
  814. // destConsumed = true;
  815. // }
  816. // else
  817. // {
  818. // BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots)
  819. // {
  820. // if (vstd::contains(artifWorn, slot) && artifWorn[slot]->id == 145)
  821. // {
  822. // artifWorn.erase(slot);
  823. // break;
  824. // }
  825. // }
  826. // }
  827. // }
  828. // }
  829. // }
  830. void CArtHandler::clearHlpLists()
  831. {
  832. treasures.clear();
  833. minors.clear();
  834. majors.clear();
  835. relics.clear();
  836. }
  837. void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
  838. {
  839. allowedArtifacts.clear();
  840. clearHlpLists();
  841. for (int i=0; i<144; ++i) //yes, 144
  842. {
  843. if (allowed[i])
  844. allowedArtifacts.push_back(artifacts[i]);
  845. }
  846. //if (GameConstants::COMMANDERS) //allow all commander artifacts for testing
  847. //{
  848. // for (int i = 146; i <= 155; ++i)
  849. // {
  850. // allowedArtifacts.push_back(artifacts[i]);
  851. // }
  852. //}
  853. }
  854. CArtifactInstance::CArtifactInstance()
  855. {
  856. init();
  857. }
  858. CArtifactInstance::CArtifactInstance( CArtifact *Art)
  859. {
  860. init();
  861. setType(Art);
  862. }
  863. // CArtifactInstance::CArtifactInstance(int aid)
  864. // {
  865. // init();
  866. // setType(VLC->arth->artifacts[aid]);
  867. // }
  868. void CArtifactInstance::setType( CArtifact *Art )
  869. {
  870. artType = Art;
  871. attachTo(Art);
  872. }
  873. std::string CArtifactInstance::nodeName() const
  874. {
  875. return "Artifact instance of " + (artType ? artType->Name() : std::string("uninitialized")) + " type";
  876. }
  877. CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s)
  878. {
  879. CArtifactInstance *ret = new CArtifactInstance(VLC->arth->artifacts[1]);
  880. Bonus *b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, 1, s->id);
  881. ret->addNewBonus(b);
  882. return ret;
  883. }
  884. void CArtifactInstance::init()
  885. {
  886. id = -1;
  887. setNodeType(ARTIFACT_INSTANCE);
  888. }
  889. int CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
  890. {
  891. BOOST_FOREACH(ui16 slot, artType->possibleSlots[h->bearerType()])
  892. {
  893. if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
  894. {
  895. //we've found a free suitable slot.
  896. return slot;
  897. }
  898. }
  899. //if haven't find proper slot, use backpack
  900. return firstBackpackSlot(h);
  901. }
  902. int CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
  903. {
  904. if(!artType->isBig()) //discard big artifact
  905. return GameConstants::BACKPACK_START + h->artifactsInBackpack.size();
  906. return -1;
  907. }
  908. bool CArtifactInstance::canBePutAt(const ArtifactLocation al, bool assumeDestRemoved /*= false*/) const
  909. {
  910. return canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
  911. }
  912. bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  913. {
  914. if(slot >= GameConstants::BACKPACK_START)
  915. {
  916. if(artType->isBig())
  917. return false;
  918. //TODO backpack limit
  919. return true;
  920. }
  921. if(!vstd::contains(artType->possibleSlots[artSet->bearerType()], slot))
  922. return false;
  923. return artSet->isPositionFree(slot, assumeDestRemoved);
  924. }
  925. void CArtifactInstance::putAt(ArtifactLocation al)
  926. {
  927. assert(canBePutAt(al));
  928. al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
  929. if(al.slot < GameConstants::BACKPACK_START)
  930. al.getHolderNode()->attachTo(this);
  931. }
  932. void CArtifactInstance::removeFrom(ArtifactLocation al)
  933. {
  934. assert(al.getHolderArtSet()->getArt(al.slot) == this);
  935. al.getHolderArtSet()->eraseArtSlot(al.slot);
  936. if(al.slot < GameConstants::BACKPACK_START)
  937. al.getHolderNode()->detachFrom(this);
  938. //TODO delete me?
  939. }
  940. bool CArtifactInstance::canBeDisassembled() const
  941. {
  942. return artType->constituents && artType->constituentOf->size();
  943. }
  944. std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
  945. {
  946. std::vector<const CArtifact *> ret;
  947. if(!artType->constituentOf //not a part of combined artifact
  948. || artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
  949. return ret;
  950. BOOST_FOREACH(ui32 possibleCombinedArt, *artType->constituentOf)
  951. {
  952. const CArtifact * const artifact = VLC->arth->artifacts[possibleCombinedArt];
  953. assert(artifact->constituents);
  954. bool possible = true;
  955. BOOST_FOREACH(ui32 constituentID, *artifact->constituents) //check if all constituents are available
  956. {
  957. if(!h->hasArt(constituentID, true)) //constituent must be equipped
  958. {
  959. possible = false;
  960. break;
  961. }
  962. }
  963. if(possible)
  964. ret.push_back(artifact);
  965. }
  966. return ret;
  967. }
  968. void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
  969. {
  970. removeFrom(src);
  971. putAt(dst);
  972. }
  973. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
  974. {
  975. if(!Art->constituents)
  976. return new CArtifactInstance(Art);
  977. else
  978. {
  979. CCombinedArtifactInstance * ret = new CCombinedArtifactInstance(Art);
  980. ret->createConstituents();
  981. return ret;
  982. }
  983. }
  984. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(int aid)
  985. {
  986. return createNewArtifactInstance(VLC->arth->artifacts[aid]);
  987. }
  988. void CArtifactInstance::deserializationFix()
  989. {
  990. setType(artType);
  991. }
  992. int CArtifactInstance::getGivenSpellID() const
  993. {
  994. const Bonus * b = getBonus(Selector::type(Bonus::SPELL));
  995. if(!b)
  996. {
  997. tlog3 << "Warning: " << nodeName() << " doesn't bear any spell!\n";
  998. return -1;
  999. }
  1000. return b->subtype;
  1001. }
  1002. bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  1003. {
  1004. return supposedPart == this;
  1005. }
  1006. bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  1007. {
  1008. bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
  1009. if(!canMainArtifactBePlaced)
  1010. return false; //no is no...
  1011. if(slot >= GameConstants::BACKPACK_START)
  1012. return true; //we can always remove combined art to the backapck
  1013. assert(artType->constituents);
  1014. std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
  1015. //it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
  1016. //so we remove from the list all constituents that are already present on dst hero in the form of locks
  1017. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  1018. {
  1019. if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
  1020. constituentsToBePlaced -= constituent;
  1021. }
  1022. //we iterate over all active slots and check if constituents fits them
  1023. for (int i = 0; i < GameConstants::BACKPACK_START; i++)
  1024. {
  1025. for(std::vector<ConstituentInfo>::iterator art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
  1026. {
  1027. if(art->art->canBePutAt(artSet, i, i == slot)) // i == al.slot because we can remove already worn artifact only from that slot that is our main destination
  1028. {
  1029. constituentsToBePlaced.erase(art);
  1030. break;
  1031. }
  1032. }
  1033. }
  1034. return constituentsToBePlaced.empty();
  1035. }
  1036. bool CCombinedArtifactInstance::canBeDisassembled() const
  1037. {
  1038. return true;
  1039. }
  1040. CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
  1041. : CArtifactInstance(Art) //TODO: seems unued, but need to be written
  1042. {
  1043. }
  1044. CCombinedArtifactInstance::CCombinedArtifactInstance()
  1045. {
  1046. }
  1047. void CCombinedArtifactInstance::createConstituents()
  1048. {
  1049. assert(artType);
  1050. assert(artType->constituents);
  1051. BOOST_FOREACH(ui32 a, *artType->constituents)
  1052. {
  1053. addAsConstituent(CArtifactInstance::createNewArtifactInstance(a), -1);
  1054. }
  1055. }
  1056. void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, int slot)
  1057. {
  1058. assert(vstd::contains(*artType->constituents, art->artType->id));
  1059. assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
  1060. constituentsInfo.push_back(ConstituentInfo(art, slot));
  1061. attachTo(art);
  1062. }
  1063. void CCombinedArtifactInstance::putAt(ArtifactLocation al)
  1064. {
  1065. if(al.slot >= GameConstants::BACKPACK_START)
  1066. {
  1067. CArtifactInstance::putAt(al);
  1068. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1069. ci.slot = -1;
  1070. }
  1071. else
  1072. {
  1073. CArtifactInstance *mainConstituent = figureMainConstituent(al); //it'll be replaced with combined artifact, not a lock
  1074. CArtifactInstance::putAt(al); //puts combined art (this)
  1075. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1076. {
  1077. if(ci.art != mainConstituent)
  1078. {
  1079. const ArtifactLocation suggestedPos(al.artHolder, ci.slot);
  1080. const bool inActiveSlot = vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START);
  1081. const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
  1082. int pos = -1;
  1083. if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
  1084. pos = ci.slot;
  1085. else
  1086. ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
  1087. assert(pos < GameConstants::BACKPACK_START);
  1088. al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
  1089. }
  1090. else
  1091. {
  1092. ci.slot = -1;
  1093. }
  1094. }
  1095. }
  1096. }
  1097. void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
  1098. {
  1099. if(al.slot >= GameConstants::BACKPACK_START)
  1100. {
  1101. CArtifactInstance::removeFrom(al);
  1102. }
  1103. else
  1104. {
  1105. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1106. {
  1107. if(ci.slot >= 0)
  1108. {
  1109. al.getHolderArtSet()->eraseArtSlot(ci.slot);
  1110. ci.slot = -1;
  1111. }
  1112. else
  1113. {
  1114. //main constituent
  1115. CArtifactInstance::removeFrom(al);
  1116. }
  1117. }
  1118. }
  1119. }
  1120. CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
  1121. {
  1122. CArtifactInstance *mainConstituent = NULL; //it'll be replaced with combined artifact, not a lock
  1123. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1124. if(ci.slot == al.slot)
  1125. mainConstituent = ci.art;
  1126. if(!mainConstituent)
  1127. {
  1128. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1129. {
  1130. if(vstd::contains(ci.art->artType->possibleSlots[al.getHolderArtSet()->bearerType()], al.slot))
  1131. {
  1132. mainConstituent = ci.art;
  1133. }
  1134. }
  1135. }
  1136. return mainConstituent;
  1137. }
  1138. void CCombinedArtifactInstance::deserializationFix()
  1139. {
  1140. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1141. attachTo(ci.art);
  1142. }
  1143. bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  1144. {
  1145. bool me = CArtifactInstance::isPart(supposedPart);
  1146. if(me)
  1147. return true;
  1148. //check for constituents
  1149. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  1150. if(constituent.art == supposedPart)
  1151. return true;
  1152. return false;
  1153. }
  1154. CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art /*= NULL*/, ui16 Slot /*= -1*/)
  1155. {
  1156. art = Art;
  1157. slot = Slot;
  1158. }
  1159. bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
  1160. {
  1161. return art == rhs.art && slot == rhs.slot;
  1162. }
  1163. const CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/) const
  1164. {
  1165. if(const ArtSlotInfo *si = getSlot(pos))
  1166. {
  1167. if(si->artifact && (!excludeLocked || !si->locked))
  1168. return si->artifact;
  1169. }
  1170. return NULL;
  1171. }
  1172. CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/)
  1173. {
  1174. return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
  1175. }
  1176. si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
  1177. {
  1178. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1179. if(i->second.artifact->artType->id == aid)
  1180. return i->first;
  1181. if(onlyWorn)
  1182. return -1;
  1183. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1184. if(artifactsInBackpack[i].artifact->artType->id == aid)
  1185. return GameConstants::BACKPACK_START + i;
  1186. return -1;
  1187. }
  1188. si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
  1189. {
  1190. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1191. if(i->second.artifact == art)
  1192. return i->first;
  1193. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1194. if(artifactsInBackpack[i].artifact == art)
  1195. return GameConstants::BACKPACK_START + i;
  1196. return -1;
  1197. }
  1198. const CArtifactInstance * CArtifactSet::getArtByInstanceId(int artInstId) const
  1199. {
  1200. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1201. if(i->second.artifact->id == artInstId)
  1202. return i->second.artifact;
  1203. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1204. if(artifactsInBackpack[i].artifact->id == artInstId)
  1205. return artifactsInBackpack[i].artifact;
  1206. return NULL;
  1207. }
  1208. bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
  1209. {
  1210. return getArtPos(aid, onlyWorn) != -1;
  1211. }
  1212. const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
  1213. {
  1214. if(vstd::contains(artifactsWorn, pos))
  1215. return &artifactsWorn[pos];
  1216. if(pos >= ArtifactPosition::AFTER_LAST )
  1217. {
  1218. int backpackPos = (int)pos - GameConstants::BACKPACK_START;
  1219. if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
  1220. return NULL;
  1221. else
  1222. return &artifactsInBackpack[backpackPos];
  1223. }
  1224. return NULL;
  1225. }
  1226. bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
  1227. {
  1228. if(const ArtSlotInfo *s = getSlot(pos))
  1229. return (onlyLockCheck || !s->artifact) && !s->locked;
  1230. return true; //no slot means not used
  1231. }
  1232. si32 CArtifactSet::getArtTypeId(ui16 pos) const
  1233. {
  1234. const CArtifactInstance * const a = getArt(pos);
  1235. if(!a)
  1236. {
  1237. tlog2 << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)\n";
  1238. return -1;
  1239. }
  1240. return a->artType->id;
  1241. }
  1242. CArtifactSet::~CArtifactSet()
  1243. {
  1244. }
  1245. ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
  1246. {
  1247. assert(!vstd::contains(artifactsWorn, slot));
  1248. ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
  1249. ? artifactsWorn[slot]
  1250. : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
  1251. return ret;
  1252. }
  1253. void CArtifactSet::setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked)
  1254. {
  1255. ArtSlotInfo &asi = retreiveNewArtSlot(slot);
  1256. asi.artifact = art;
  1257. asi.locked = locked;
  1258. }
  1259. void CArtifactSet::eraseArtSlot(ui16 slot)
  1260. {
  1261. if(slot < GameConstants::BACKPACK_START)
  1262. {
  1263. artifactsWorn.erase(slot);
  1264. }
  1265. else
  1266. {
  1267. slot -= GameConstants::BACKPACK_START;
  1268. artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
  1269. }
  1270. }
  1271. void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
  1272. {
  1273. for(bmap<ui16, ArtSlotInfo>::iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1274. if(i->second.artifact && !i->second.locked)
  1275. node->attachTo(i->second.artifact);
  1276. }