CArtHandler.cpp 49 KB

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