CArtHandler.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. 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::map<std::string, int> artRarityMap = boost::assign::map_list_of
  23. ("TREASURE", CArtifact::ART_TREASURE)
  24. ("MINOR", CArtifact::ART_MINOR)
  25. ("MAJOR", CArtifact::ART_MAJOR)
  26. ("RELIC", CArtifact::ART_RELIC)
  27. ("SPECIAL", CArtifact::ART_SPECIAL);
  28. #define ART_BEARER(x) ( #x, ArtBearer::x )
  29. const std::map<std::string, int> artifactBearerMap = boost::assign::map_list_of ART_BEARER_LIST;
  30. #undef ART_BEARER
  31. #define ART_POS(x) ( #x, ArtifactPosition::x )
  32. const std::map<std::string, int> artifactPositionMap = boost::assign::map_list_of
  33. ART_POS(HEAD)
  34. ART_POS(SHOULDERS)
  35. ART_POS(NECK)
  36. ART_POS(RIGHT_HAND)
  37. ART_POS(LEFT_HAND)
  38. ART_POS(TORSO)
  39. ART_POS(RIGHT_RING)
  40. ART_POS(LEFT_RING)
  41. ART_POS(FEET)
  42. ART_POS(MISC1)
  43. ART_POS(MISC2)
  44. ART_POS(MISC3)
  45. ART_POS(MISC4)
  46. ART_POS(MISC5)
  47. ART_POS(MACH1)
  48. ART_POS(MACH2)
  49. ART_POS(MACH3)
  50. ART_POS(MACH4)
  51. ART_POS(SPELLBOOK); //no need to specify commander / stack position?
  52. const std::string & CArtifact::Name() const
  53. {
  54. return name;
  55. }
  56. const std::string & CArtifact::Description() const
  57. {
  58. return description;
  59. }
  60. const std::string & CArtifact::EventText() const
  61. {
  62. return eventText;
  63. }
  64. bool CArtifact::isBig () const
  65. {
  66. return VLC->arth->isBigArtifact(id);
  67. }
  68. // /**
  69. // * Checks whether the artifact fits at a given slot.
  70. // * @param artifWorn A hero's set of worn artifacts.
  71. // */
  72. // bool CArtifact::fitsAt (const std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
  73. // {
  74. // if (!vstd::contains(possibleSlots, slotID))
  75. // return false;
  76. //
  77. // // Can't put an artifact in a locked slot.
  78. // std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.find(slotID);
  79. // if (it != artifWorn.end() && it->second->id == 145)
  80. // return false;
  81. //
  82. // // Check if a combination artifact fits.
  83. // // TODO: Might want a more general algorithm?
  84. // // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates.
  85. // if (constituents != NULL)
  86. // {
  87. // std::map<ui16, const CArtifact*> tempArtifWorn = artifWorn;
  88. // const ui16 ringSlots[] = {6, 7};
  89. // const ui16 miscSlots[] = {9, 10, 11, 12, 18};
  90. // int rings = 0;
  91. // int misc = 0;
  92. //
  93. // VLC->arth->unequipArtifact(tempArtifWorn, slotID);
  94. //
  95. // BOOST_FOREACH(ui32 constituentID, *constituents)
  96. // {
  97. // const CArtifact& constituent = *VLC->arth->artifacts[constituentID];
  98. // const int slot = constituent.possibleSlots[0];
  99. //
  100. // if (slot == 6 || slot == 7)
  101. // rings++;
  102. // else if ((slot >= 9 && slot <= 12) || slot == 18)
  103. // misc++;
  104. // else if (tempArtifWorn.find(slot) != tempArtifWorn.end())
  105. // return false;
  106. // }
  107. //
  108. // // Ensure enough ring slots are free
  109. // for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++)
  110. // {
  111. // if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID)
  112. // rings--;
  113. // }
  114. // if (rings > 0)
  115. // return false;
  116. //
  117. // // Ensure enough misc slots are free.
  118. // for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++)
  119. // {
  120. // if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID)
  121. // misc--;
  122. // }
  123. // if (misc > 0)
  124. // return false;
  125. // }
  126. //
  127. // return true;
  128. // }
  129. // bool CArtifact::canBeAssembledTo (const std::map<ui16, const CArtifact*> &artifWorn, ui32 artifactID) const
  130. // {
  131. // if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID))
  132. // return false;
  133. //
  134. // const CArtifact &artifact = *VLC->arth->artifacts[artifactID];
  135. // assert(artifact.constituents);
  136. //
  137. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  138. // {
  139. // bool found = false;
  140. // for (std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it)
  141. // {
  142. // if (it->second->id == constituentID)
  143. // {
  144. // found = true;
  145. // break;
  146. // }
  147. // }
  148. // if (!found)
  149. // return false;
  150. // }
  151. //
  152. // return true;
  153. // }
  154. CArtifact::CArtifact()
  155. {
  156. setNodeType(ARTIFACT);
  157. }
  158. CArtifact::~CArtifact()
  159. {
  160. }
  161. int CArtifact::getArtClassSerial() const
  162. {
  163. if(id == 1)
  164. return 4;
  165. switch(aClass)
  166. {
  167. case ART_TREASURE:
  168. return 0;
  169. case ART_MINOR:
  170. return 1;
  171. case ART_MAJOR:
  172. return 2;
  173. case ART_RELIC:
  174. return 3;
  175. case ART_SPECIAL:
  176. return 5;
  177. }
  178. return -1;
  179. }
  180. std::string CArtifact::nodeName() const
  181. {
  182. return "Artifact: " + Name();
  183. }
  184. // void CArtifact::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
  185. // {
  186. // //combined artifact carries bonuses from its parts
  187. // if(constituents)
  188. // {
  189. // BOOST_FOREACH(ui32 id, *constituents)
  190. // out.insert(VLC->arth->artifacts[id]);
  191. // }
  192. // }
  193. // void CScroll::Init()
  194. // {
  195. // // addNewBonus (Bonus (Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT, 1, id, spellid, Bonus::INDEPENDENT_MAX));
  196. // // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name);
  197. // }
  198. void CArtifact::addNewBonus(Bonus *b)
  199. {
  200. b->source = Bonus::ARTIFACT;
  201. b->duration = Bonus::PERMANENT;
  202. b->description = name;
  203. CBonusSystemNode::addNewBonus(b);
  204. }
  205. void CArtifact::setName (std::string desc)
  206. {
  207. name = desc;
  208. }
  209. void CArtifact::setDescription (std::string desc)
  210. {
  211. description = desc;
  212. }
  213. void CArtifact::setEventText (std::string desc)
  214. {
  215. eventText = desc;
  216. }
  217. void CGrowingArtifact::levelUpArtifact (CArtifactInstance * art)
  218. {
  219. Bonus b;
  220. b.type = Bonus::LEVEL_COUNTER;
  221. b.val = 1;
  222. b.duration = Bonus::COMMANDER_KILLED;
  223. art->accumulateBonus (b);
  224. BOOST_FOREACH (auto bonus, bonusesPerLevel)
  225. {
  226. if (art->valOfBonuses(Bonus::LEVEL_COUNTER) % bonus.first == 0) //every n levels
  227. {
  228. art->accumulateBonus (bonus.second);
  229. }
  230. }
  231. BOOST_FOREACH (auto bonus, thresholdBonuses)
  232. {
  233. if (art->valOfBonuses(Bonus::LEVEL_COUNTER) == bonus.first) //every n levels
  234. {
  235. art->addNewBonus (&bonus.second);
  236. }
  237. }
  238. }
  239. CArtHandler::CArtHandler()
  240. {
  241. VLC->arth = this;
  242. // War machines are the default big artifacts.
  243. for (ui32 i = 3; i <= 6; i++)
  244. bigArtifacts.insert(i);
  245. }
  246. CArtHandler::~CArtHandler()
  247. {
  248. for (std::vector< ConstTransitivePtr<CArtifact> >::iterator it = artifacts.begin(); it != artifacts.end(); ++it)
  249. {
  250. delete (*it)->constituents;
  251. delete (*it)->constituentOf;
  252. }
  253. }
  254. void CArtHandler::loadArtifacts(bool onlyTxt)
  255. {
  256. std::vector<ui16> slots;
  257. slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
  258. growingArtifacts += 146, 147, 148, 150, 151, 152, 153;
  259. static std::map<char, CArtifact::EartClass> classes =
  260. map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
  261. CLegacyConfigParser parser("DATA/ARTRAITS.TXT");
  262. CLegacyConfigParser events("DATA/ARTEVENT.TXT");
  263. parser.endLine(); // header
  264. parser.endLine();
  265. std::map<ui32,ui8>::iterator itr;
  266. for (int i=0; i<GameConstants::ARTIFACTS_QUANTITY; i++)
  267. {
  268. CArtifact *art;
  269. if (vstd::contains (growingArtifacts, i))
  270. {
  271. art = new CGrowingArtifact();
  272. }
  273. else
  274. {
  275. art = new CArtifact();
  276. }
  277. CArtifact &nart = *art;
  278. nart.id=i;
  279. nart.setName (parser.readString());
  280. nart.setEventText (events.readString());
  281. events.endLine();
  282. nart.price= parser.readNumber();
  283. nart.possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
  284. nart.possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
  285. nart.possibleSlots[ArtBearer::COMMANDER];
  286. for(int j=0;j<slots.size();j++)
  287. {
  288. if(parser.readString() == "x")
  289. nart.possibleSlots[ArtBearer::HERO].push_back(slots[j]);
  290. }
  291. nart.aClass = classes[parser.readString()[0]];
  292. //load description and remove quotation marks
  293. nart.setDescription (parser.readString());
  294. parser.endLine();
  295. if(onlyTxt)
  296. continue;
  297. // Fill in information about combined artifacts. Should perhaps be moved to a config file?
  298. nart.constituentOf = NULL;
  299. switch (nart.id)
  300. {
  301. case 129: // Angelic Alliance
  302. nart.constituents = new std::vector<ui32>();
  303. *nart.constituents += 31, 32, 33, 34, 35, 36;
  304. break;
  305. case 130: // Cloak of the Undead King
  306. nart.constituents = new std::vector<ui32>();
  307. *nart.constituents += 54, 55, 56;
  308. break;
  309. case 131: // Elixir of Life
  310. nart.constituents = new std::vector<ui32>();
  311. *nart.constituents += 94, 95, 96;
  312. break;
  313. case 132: // Armor of the Damned
  314. nart.constituents = new std::vector<ui32>();
  315. *nart.constituents += 8, 14, 20, 26;
  316. break;
  317. case 133: // Statue of Legion
  318. nart.constituents = new std::vector<ui32>();
  319. *nart.constituents += 118, 119, 120, 121, 122;
  320. break;
  321. case 134: // Power of the Dragon Father
  322. nart.constituents = new std::vector<ui32>();
  323. *nart.constituents += 37, 38, 39, 40, 41, 42, 43, 44, 45;
  324. break;
  325. case 135: // Titan's Thunder
  326. nart.constituents = new std::vector<ui32>();
  327. *nart.constituents += 12, 18, 24, 30;
  328. break;
  329. case 136: // Admiral's Hat
  330. nart.constituents = new std::vector<ui32>();
  331. *nart.constituents += 71, 123;
  332. break;
  333. case 137: // Bow of the Sharpshooter
  334. nart.constituents = new std::vector<ui32>();
  335. *nart.constituents += 60, 61, 62;
  336. break;
  337. case 138: // Wizards' Well
  338. nart.constituents = new std::vector<ui32>();
  339. *nart.constituents += 73, 74, 75;
  340. break;
  341. case 139: // Ring of the Magi
  342. nart.constituents = new std::vector<ui32>();
  343. *nart.constituents += 76, 77, 78;
  344. break;
  345. case 140: // Cornucopia
  346. nart.constituents = new std::vector<ui32>();
  347. *nart.constituents += 109, 110, 111, 113;
  348. break;
  349. // TODO: WoG combinationals
  350. default:
  351. nart.constituents = NULL;
  352. break;
  353. }
  354. artifacts.push_back(&nart);
  355. }
  356. if (VLC->modh->modules.COMMANDERS)
  357. { //TODO: move all artifacts config to separate json file
  358. const JsonNode config(ResourceID("config/commanders.json"));
  359. BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector())
  360. {
  361. auto ga = dynamic_cast <CGrowingArtifact *>(artifacts[artifact["id"].Float()].get());
  362. BOOST_FOREACH (auto b, artifact["bonusesPerLevel"].Vector())
  363. {
  364. ga->bonusesPerLevel.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *JsonUtils::parseBonus (b["bonus"].Vector())));
  365. }
  366. BOOST_FOREACH (auto b, artifact["thresholdBonuses"].Vector())
  367. {
  368. ga->thresholdBonuses.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *JsonUtils::parseBonus (b["bonus"].Vector())));
  369. }
  370. }
  371. }
  372. sortArts();
  373. if(onlyTxt)
  374. return;
  375. addBonuses();
  376. // Populate reverse mappings of combinational artifacts.
  377. BOOST_FOREACH(CArtifact *artifact, artifacts)
  378. {
  379. if (artifact->constituents != NULL)
  380. {
  381. BOOST_FOREACH(ui32 constituentID, *artifact->constituents)
  382. {
  383. if (artifacts[constituentID]->constituentOf == NULL)
  384. artifacts[constituentID]->constituentOf = new std::vector<ui32>();
  385. artifacts[constituentID]->constituentOf->push_back(artifact->id);
  386. }
  387. }
  388. }
  389. }
  390. void CArtHandler::load(const JsonNode & node)
  391. {
  392. BOOST_FOREACH(auto & entry, node.Struct())
  393. {
  394. if (!entry.second.isNull()) // may happens if mod removed creature by setting json entry to null
  395. {
  396. CArtifact * art = loadArtifact(entry.second);
  397. art->setName (entry.first);
  398. art->id = artifacts.size();
  399. artifacts.push_back(art);
  400. tlog3 << "Added artifact: " << entry.first << "\n";
  401. VLC->modh->identifiers.registerObject (std::string("artifact.") + art->Name(), art->id);
  402. }
  403. }
  404. }
  405. CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
  406. {
  407. CArtifact * art = new CArtifact;
  408. const JsonNode *value;
  409. const JsonNode & text = node["text"];
  410. art->setName (text["name"].String());
  411. art->setDescription (text["description"].String());
  412. art->setName (text["event"].String());
  413. const JsonNode & graphics = node["graphics"];
  414. art->iconIndex = graphics["iconIndex"].Float();
  415. art->image = graphics["image"].String();
  416. value = &graphics["large"];
  417. if (!value->isNull())
  418. art->large = value->String();
  419. art->price = node["value"].Float();
  420. int bearerType = -1;
  421. // FIXME FIXME FIXME: value is unitialized = crash!
  422. auto it = artifactBearerMap.find (value->String());
  423. if (it != artifactPositionMap.end())
  424. {
  425. bearerType = it->second;
  426. switch (bearerType)
  427. {
  428. case ArtBearer::HERO: //TODO: allow arts having several possible bearers
  429. break;
  430. case ArtBearer::COMMANDER:
  431. makeItCommanderArt(art->id); //TODO: when id is deduced?
  432. break;
  433. case ArtBearer::CREATURE:
  434. makeItCreatureArt(art->id);
  435. break;
  436. }
  437. }
  438. else
  439. tlog2 << "Warning! Artifact type " << value->String() << " not recognized!";
  440. value = &node["slot"];
  441. if (!value->isNull() && bearerType == ArtBearer::HERO) //we assume non-hero slots are irrelevant?
  442. {
  443. auto it = artifactPositionMap.find (value->String());
  444. if (it != artifactPositionMap.end())
  445. {
  446. auto slot = it->second;
  447. art->possibleSlots[ArtBearer::HERO].push_back (slot);
  448. }
  449. else
  450. tlog2 << "Warning! Artifact slot " << value->String() << " not recognized!";
  451. }
  452. BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector())
  453. {
  454. auto b = JsonUtils::parseBonus(bonus);
  455. //TODO: bonus->sid = art->id;
  456. art->addNewBonus(b);
  457. }
  458. return art;
  459. }
  460. int CArtHandler::convertMachineID(int id, bool creToArt )
  461. {
  462. int dif = 142;
  463. if(creToArt)
  464. {
  465. switch (id)
  466. {
  467. case 147:
  468. dif--;
  469. break;
  470. case 148:
  471. dif++;
  472. break;
  473. }
  474. dif = -dif;
  475. }
  476. else
  477. {
  478. switch (id)
  479. {
  480. case 6:
  481. dif--;
  482. break;
  483. case 5:
  484. dif++;
  485. break;
  486. }
  487. }
  488. return id + dif;
  489. }
  490. void CArtHandler::sortArts()
  491. {
  492. //for (int i=0; i<allowedArtifacts.size(); ++i) //do 144, bo nie chcemy bzdurek
  493. //{
  494. // switch (allowedArtifacts[i]->aClass)
  495. // {
  496. // case CArtifact::ART_TREASURE:
  497. // treasures.push_back(allowedArtifacts[i]);
  498. // break;
  499. // case CArtifact::ART_MINOR:
  500. // minors.push_back(allowedArtifacts[i]);
  501. // break;
  502. // case CArtifact::ART_MAJOR:
  503. // majors.push_back(allowedArtifacts[i]);
  504. // break;
  505. // case CArtifact::ART_RELIC:
  506. // relics.push_back(allowedArtifacts[i]);
  507. // break;
  508. // }
  509. //}
  510. }
  511. void CArtHandler::erasePickedArt( TArtifactInstanceID id )
  512. {
  513. std::vector<CArtifact*>* ptr;
  514. CArtifact *art = artifacts[id];
  515. switch (art->aClass)
  516. {
  517. case CArtifact::ART_TREASURE:
  518. ptr = &treasures;
  519. break;
  520. case CArtifact::ART_MINOR:
  521. ptr = &minors;
  522. break;
  523. case CArtifact::ART_MAJOR:
  524. ptr = &majors;
  525. break;
  526. case CArtifact::ART_RELIC:
  527. ptr = &relics;
  528. break;
  529. default: //special artifacts should not be erased
  530. return;
  531. }
  532. ptr->erase (std::find(ptr->begin(), ptr->end(), art)); //remove the artifact from available list
  533. }
  534. ui16 CArtHandler::getRandomArt(int flags)
  535. {
  536. std::vector<ConstTransitivePtr<CArtifact> > out;
  537. getAllowed(out, flags);
  538. ui16 id = out[ran() % out.size()]->id;
  539. erasePickedArt (id);
  540. return id;
  541. }
  542. ui16 CArtHandler::getArtSync (ui32 rand, int flags)
  543. {
  544. std::vector<ConstTransitivePtr<CArtifact> > out;
  545. getAllowed(out, flags);
  546. CArtifact *art = out[rand % out.size()];
  547. return art->id;
  548. }
  549. void CArtHandler::getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags)
  550. {
  551. if (flags & CArtifact::ART_TREASURE)
  552. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  553. if (flags & CArtifact::ART_MINOR)
  554. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  555. if (flags & CArtifact::ART_MAJOR)
  556. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  557. if (flags & CArtifact::ART_RELIC)
  558. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  559. if (!out.size()) //no artifact of specified rarity, we need to take another one
  560. {
  561. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  562. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  563. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  564. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  565. }
  566. if (!out.size()) //no arts are available at all
  567. {
  568. out.resize (64);
  569. std::fill_n (out.begin(), 64, artifacts[2]); //Give Grail - this can't be banned (hopefully)
  570. }
  571. }
  572. void CArtHandler::getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag)
  573. {
  574. if (arts->empty()) //restock available arts
  575. {
  576. for (int i = 0; i < allowedArtifacts.size(); ++i)
  577. {
  578. if (allowedArtifacts[i]->aClass == flag)
  579. arts->push_back(allowedArtifacts[i]);
  580. }
  581. }
  582. for (int i = 0; i < arts->size(); ++i)
  583. {
  584. CArtifact *art = (*arts)[i];
  585. out.push_back(art);
  586. }
  587. }
  588. Bonus *createBonus(Bonus::BonusType type, int val, int subtype, int valType, shared_ptr<ILimiter> limiter = shared_ptr<ILimiter>(), int additionalInfo = 0)
  589. {
  590. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,-1,subtype);
  591. added->additionalInfo = additionalInfo;
  592. added->valType = valType;
  593. added->limiter = limiter;
  594. return added;
  595. }
  596. Bonus *createBonus(Bonus::BonusType type, int val, int subtype, shared_ptr<IPropagator> propagator = shared_ptr<IPropagator>(), int additionalInfo = 0)
  597. {
  598. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,-1,subtype);
  599. added->additionalInfo = additionalInfo;
  600. added->valType = Bonus::BASE_NUMBER;
  601. added->propagator = propagator;
  602. return added;
  603. }
  604. void CArtHandler::giveArtBonus( TArtifactID aid, Bonus::BonusType type, int val, int subtype, int valType, shared_ptr<ILimiter> limiter, int additionalInfo)
  605. {
  606. giveArtBonus(aid, createBonus(type, val, subtype, valType, limiter, additionalInfo));
  607. }
  608. void CArtHandler::giveArtBonus(TArtifactID aid, Bonus::BonusType type, int val, int subtype, shared_ptr<IPropagator> propagator /*= NULL*/, int additionalInfo)
  609. {
  610. giveArtBonus(aid, createBonus(type, val, subtype, propagator, additionalInfo));
  611. }
  612. void CArtHandler::giveArtBonus(TArtifactID aid, Bonus *bonus)
  613. {
  614. bonus->sid = aid;
  615. if(bonus->subtype == Bonus::MORALE || bonus->type == Bonus::LUCK)
  616. bonus->description = artifacts[aid]->Name() + (bonus->val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(bonus->val);
  617. else
  618. bonus->description = artifacts[aid]->Name();
  619. artifacts[aid]->addNewBonus(bonus);
  620. }
  621. void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/)
  622. {
  623. CArtifact *a = artifacts[aid];
  624. if (onlyCreature)
  625. {
  626. a->possibleSlots[ArtBearer::HERO].clear();
  627. a->possibleSlots[ArtBearer::COMMANDER].clear();
  628. }
  629. a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
  630. }
  631. void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ )
  632. {
  633. CArtifact *a = artifacts[aid];
  634. if (onlyCommander)
  635. {
  636. a->possibleSlots[ArtBearer::HERO].clear();
  637. a->possibleSlots[ArtBearer::CREATURE].clear();
  638. }
  639. for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
  640. a->possibleSlots[ArtBearer::COMMANDER].push_back(i);
  641. }
  642. void CArtHandler::addBonuses()
  643. {
  644. const JsonNode config(ResourceID("config/artifacts.json"));
  645. BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector())
  646. {
  647. auto ga = artifacts[artifact["id"].Float()].get();
  648. BOOST_FOREACH (auto b, artifact["bonuses"].Vector())
  649. {
  650. auto bonus = JsonUtils::parseBonus (b);
  651. bonus->sid = ga->id;
  652. ga->addNewBonus (bonus);
  653. }
  654. if(artifact["type"].String() == "Creature")
  655. makeItCreatureArt(ga->id);
  656. else if(artifact["type"].String() == "Commander")
  657. makeItCommanderArt(ga->id);
  658. }
  659. }
  660. void CArtHandler::clear()
  661. {
  662. BOOST_FOREACH(CArtifact *art, artifacts)
  663. delete art;
  664. artifacts.clear();
  665. clearHlpLists();
  666. }
  667. void CArtHandler::clearHlpLists()
  668. {
  669. treasures.clear();
  670. minors.clear();
  671. majors.clear();
  672. relics.clear();
  673. }
  674. void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
  675. {
  676. allowedArtifacts.clear();
  677. clearHlpLists();
  678. for (int i=0; i<144; ++i) //yes, 144
  679. {
  680. if (allowed[i])
  681. allowedArtifacts.push_back(artifacts[i]);
  682. }
  683. if (VLC->modh->modules.COMMANDERS) //allow all commander artifacts for testing
  684. {
  685. for (int i = 146; i <= 155; ++i)
  686. {
  687. allowedArtifacts.push_back(artifacts[i]);
  688. }
  689. }
  690. }
  691. CArtifactInstance::CArtifactInstance()
  692. {
  693. init();
  694. }
  695. CArtifactInstance::CArtifactInstance( CArtifact *Art)
  696. {
  697. init();
  698. setType(Art);
  699. }
  700. // CArtifactInstance::CArtifactInstance(int aid)
  701. // {
  702. // init();
  703. // setType(VLC->arth->artifacts[aid]);
  704. // }
  705. void CArtifactInstance::setType( CArtifact *Art )
  706. {
  707. artType = Art;
  708. attachTo(Art);
  709. }
  710. std::string CArtifactInstance::nodeName() const
  711. {
  712. return "Artifact instance of " + (artType ? artType->Name() : std::string("uninitialized")) + " type";
  713. }
  714. CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s)
  715. {
  716. CArtifactInstance *ret = new CArtifactInstance(VLC->arth->artifacts[1]);
  717. Bonus *b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, 1, s->id);
  718. ret->addNewBonus(b);
  719. return ret;
  720. }
  721. void CArtifactInstance::init()
  722. {
  723. id = -1;
  724. setNodeType(ARTIFACT_INSTANCE);
  725. }
  726. int CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
  727. {
  728. BOOST_FOREACH(ui16 slot, artType->possibleSlots[h->bearerType()])
  729. {
  730. if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
  731. {
  732. //we've found a free suitable slot.
  733. return slot;
  734. }
  735. }
  736. //if haven't find proper slot, use backpack
  737. return firstBackpackSlot(h);
  738. }
  739. int CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
  740. {
  741. if(!artType->isBig()) //discard big artifact
  742. return GameConstants::BACKPACK_START + h->artifactsInBackpack.size();
  743. return -1;
  744. }
  745. bool CArtifactInstance::canBePutAt(const ArtifactLocation al, bool assumeDestRemoved /*= false*/) const
  746. {
  747. return canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
  748. }
  749. bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  750. {
  751. if(slot >= GameConstants::BACKPACK_START)
  752. {
  753. if(artType->isBig())
  754. return false;
  755. //TODO backpack limit
  756. return true;
  757. }
  758. auto possibleSlots = artType->possibleSlots.find(artSet->bearerType());
  759. if(possibleSlots == artType->possibleSlots.end())
  760. {
  761. tlog3 << "Warning: arrtifact " << artType->Name() << " doesn't have defined allowed slots for bearer of type "
  762. << artSet->bearerType() << std::endl;
  763. return false;
  764. }
  765. if(!vstd::contains(possibleSlots->second, slot))
  766. return false;
  767. return artSet->isPositionFree(slot, assumeDestRemoved);
  768. }
  769. void CArtifactInstance::putAt(ArtifactLocation al)
  770. {
  771. assert(canBePutAt(al));
  772. al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
  773. if(al.slot < GameConstants::BACKPACK_START)
  774. al.getHolderNode()->attachTo(this);
  775. }
  776. void CArtifactInstance::removeFrom(ArtifactLocation al)
  777. {
  778. assert(al.getHolderArtSet()->getArt(al.slot) == this);
  779. al.getHolderArtSet()->eraseArtSlot(al.slot);
  780. if(al.slot < GameConstants::BACKPACK_START)
  781. al.getHolderNode()->detachFrom(this);
  782. //TODO delete me?
  783. }
  784. bool CArtifactInstance::canBeDisassembled() const
  785. {
  786. return artType->constituents && artType->constituentOf->size();
  787. }
  788. std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
  789. {
  790. std::vector<const CArtifact *> ret;
  791. if(!artType->constituentOf //not a part of combined artifact
  792. || artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
  793. return ret;
  794. BOOST_FOREACH(ui32 possibleCombinedArt, *artType->constituentOf)
  795. {
  796. const CArtifact * const artifact = VLC->arth->artifacts[possibleCombinedArt];
  797. assert(artifact->constituents);
  798. bool possible = true;
  799. BOOST_FOREACH(ui32 constituentID, *artifact->constituents) //check if all constituents are available
  800. {
  801. if(!h->hasArt(constituentID, true)) //constituent must be equipped
  802. {
  803. possible = false;
  804. break;
  805. }
  806. }
  807. if(possible)
  808. ret.push_back(artifact);
  809. }
  810. return ret;
  811. }
  812. void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
  813. {
  814. removeFrom(src);
  815. putAt(dst);
  816. }
  817. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
  818. {
  819. if(!Art->constituents)
  820. {
  821. auto ret = new CArtifactInstance(Art);
  822. if (dynamic_cast<CGrowingArtifact *>(Art))
  823. {
  824. Bonus * bonus = new Bonus;
  825. bonus->type = Bonus::LEVEL_COUNTER;
  826. bonus->val = 0;
  827. ret->addNewBonus (bonus);
  828. }
  829. return ret;
  830. }
  831. else
  832. {
  833. CCombinedArtifactInstance * ret = new CCombinedArtifactInstance(Art);
  834. ret->createConstituents();
  835. return ret;
  836. }
  837. }
  838. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(int aid)
  839. {
  840. return createNewArtifactInstance(VLC->arth->artifacts[aid]);
  841. }
  842. void CArtifactInstance::deserializationFix()
  843. {
  844. setType(artType);
  845. }
  846. int CArtifactInstance::getGivenSpellID() const
  847. {
  848. const Bonus * b = getBonusLocalFirst(Selector::type(Bonus::SPELL));
  849. if(!b)
  850. {
  851. tlog3 << "Warning: " << nodeName() << " doesn't bear any spell!\n";
  852. return -1;
  853. }
  854. return b->subtype;
  855. }
  856. bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  857. {
  858. return supposedPart == this;
  859. }
  860. bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  861. {
  862. bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
  863. if(!canMainArtifactBePlaced)
  864. return false; //no is no...
  865. if(slot >= GameConstants::BACKPACK_START)
  866. return true; //we can always remove combined art to the backapck
  867. assert(artType->constituents);
  868. std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
  869. //it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
  870. //so we remove from the list all constituents that are already present on dst hero in the form of locks
  871. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  872. {
  873. if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
  874. constituentsToBePlaced -= constituent;
  875. }
  876. //we iterate over all active slots and check if constituents fits them
  877. for (int i = 0; i < GameConstants::BACKPACK_START; i++)
  878. {
  879. for(std::vector<ConstituentInfo>::iterator art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
  880. {
  881. 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
  882. {
  883. constituentsToBePlaced.erase(art);
  884. break;
  885. }
  886. }
  887. }
  888. return constituentsToBePlaced.empty();
  889. }
  890. bool CCombinedArtifactInstance::canBeDisassembled() const
  891. {
  892. return true;
  893. }
  894. CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
  895. : CArtifactInstance(Art) //TODO: seems unued, but need to be written
  896. {
  897. }
  898. CCombinedArtifactInstance::CCombinedArtifactInstance()
  899. {
  900. }
  901. void CCombinedArtifactInstance::createConstituents()
  902. {
  903. assert(artType);
  904. assert(artType->constituents);
  905. BOOST_FOREACH(ui32 a, *artType->constituents)
  906. {
  907. addAsConstituent(CArtifactInstance::createNewArtifactInstance(a), -1);
  908. }
  909. }
  910. void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, int slot)
  911. {
  912. assert(vstd::contains(*artType->constituents, art->artType->id));
  913. assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
  914. constituentsInfo.push_back(ConstituentInfo(art, slot));
  915. attachTo(art);
  916. }
  917. void CCombinedArtifactInstance::putAt(ArtifactLocation al)
  918. {
  919. if(al.slot >= GameConstants::BACKPACK_START)
  920. {
  921. CArtifactInstance::putAt(al);
  922. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  923. ci.slot = -1;
  924. }
  925. else
  926. {
  927. CArtifactInstance *mainConstituent = figureMainConstituent(al); //it'll be replaced with combined artifact, not a lock
  928. CArtifactInstance::putAt(al); //puts combined art (this)
  929. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  930. {
  931. if(ci.art != mainConstituent)
  932. {
  933. const ArtifactLocation suggestedPos(al.artHolder, ci.slot);
  934. const bool inActiveSlot = vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START);
  935. const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
  936. int pos = -1;
  937. if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
  938. pos = ci.slot;
  939. else
  940. ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
  941. assert(pos < GameConstants::BACKPACK_START);
  942. al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
  943. }
  944. else
  945. {
  946. ci.slot = -1;
  947. }
  948. }
  949. }
  950. }
  951. void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
  952. {
  953. if(al.slot >= GameConstants::BACKPACK_START)
  954. {
  955. CArtifactInstance::removeFrom(al);
  956. }
  957. else
  958. {
  959. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  960. {
  961. if(ci.slot >= 0)
  962. {
  963. al.getHolderArtSet()->eraseArtSlot(ci.slot);
  964. ci.slot = -1;
  965. }
  966. else
  967. {
  968. //main constituent
  969. CArtifactInstance::removeFrom(al);
  970. }
  971. }
  972. }
  973. }
  974. CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
  975. {
  976. CArtifactInstance *mainConstituent = NULL; //it'll be replaced with combined artifact, not a lock
  977. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  978. if(ci.slot == al.slot)
  979. mainConstituent = ci.art;
  980. if(!mainConstituent)
  981. {
  982. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  983. {
  984. if(vstd::contains(ci.art->artType->possibleSlots[al.getHolderArtSet()->bearerType()], al.slot))
  985. {
  986. mainConstituent = ci.art;
  987. }
  988. }
  989. }
  990. return mainConstituent;
  991. }
  992. void CCombinedArtifactInstance::deserializationFix()
  993. {
  994. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  995. attachTo(ci.art);
  996. }
  997. bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  998. {
  999. bool me = CArtifactInstance::isPart(supposedPart);
  1000. if(me)
  1001. return true;
  1002. //check for constituents
  1003. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  1004. if(constituent.art == supposedPart)
  1005. return true;
  1006. return false;
  1007. }
  1008. CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art /*= NULL*/, ui16 Slot /*= -1*/)
  1009. {
  1010. art = Art;
  1011. slot = Slot;
  1012. }
  1013. bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
  1014. {
  1015. return art == rhs.art && slot == rhs.slot;
  1016. }
  1017. const CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/) const
  1018. {
  1019. if(const ArtSlotInfo *si = getSlot(pos))
  1020. {
  1021. if(si->artifact && (!excludeLocked || !si->locked))
  1022. return si->artifact;
  1023. }
  1024. return NULL;
  1025. }
  1026. CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/)
  1027. {
  1028. return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
  1029. }
  1030. si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
  1031. {
  1032. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1033. if(i->second.artifact->artType->id == aid)
  1034. return i->first;
  1035. if(onlyWorn)
  1036. return -1;
  1037. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1038. if(artifactsInBackpack[i].artifact->artType->id == aid)
  1039. return GameConstants::BACKPACK_START + i;
  1040. return -1;
  1041. }
  1042. si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
  1043. {
  1044. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1045. if(i->second.artifact == art)
  1046. return i->first;
  1047. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1048. if(artifactsInBackpack[i].artifact == art)
  1049. return GameConstants::BACKPACK_START + i;
  1050. return -1;
  1051. }
  1052. const CArtifactInstance * CArtifactSet::getArtByInstanceId( TArtifactInstanceID artInstId ) const
  1053. {
  1054. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1055. if(i->second.artifact->id == artInstId)
  1056. return i->second.artifact;
  1057. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1058. if(artifactsInBackpack[i].artifact->id == artInstId)
  1059. return artifactsInBackpack[i].artifact;
  1060. return NULL;
  1061. }
  1062. bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
  1063. {
  1064. return getArtPos(aid, onlyWorn) != -1;
  1065. }
  1066. const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
  1067. {
  1068. if(vstd::contains(artifactsWorn, pos))
  1069. return &artifactsWorn[pos];
  1070. if(pos >= ArtifactPosition::AFTER_LAST )
  1071. {
  1072. int backpackPos = (int)pos - GameConstants::BACKPACK_START;
  1073. if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
  1074. return NULL;
  1075. else
  1076. return &artifactsInBackpack[backpackPos];
  1077. }
  1078. return NULL;
  1079. }
  1080. bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
  1081. {
  1082. if(const ArtSlotInfo *s = getSlot(pos))
  1083. return (onlyLockCheck || !s->artifact) && !s->locked;
  1084. return true; //no slot means not used
  1085. }
  1086. si32 CArtifactSet::getArtTypeId(ui16 pos) const
  1087. {
  1088. const CArtifactInstance * const a = getArt(pos);
  1089. if(!a)
  1090. {
  1091. tlog2 << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)\n";
  1092. return -1;
  1093. }
  1094. return a->artType->id;
  1095. }
  1096. CArtifactSet::~CArtifactSet()
  1097. {
  1098. }
  1099. ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
  1100. {
  1101. assert(!vstd::contains(artifactsWorn, slot));
  1102. ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
  1103. ? artifactsWorn[slot]
  1104. : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
  1105. return ret;
  1106. }
  1107. void CArtifactSet::setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked)
  1108. {
  1109. ArtSlotInfo &asi = retreiveNewArtSlot(slot);
  1110. asi.artifact = art;
  1111. asi.locked = locked;
  1112. }
  1113. void CArtifactSet::eraseArtSlot(ui16 slot)
  1114. {
  1115. if(slot < GameConstants::BACKPACK_START)
  1116. {
  1117. artifactsWorn.erase(slot);
  1118. }
  1119. else
  1120. {
  1121. slot -= GameConstants::BACKPACK_START;
  1122. artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
  1123. }
  1124. }
  1125. void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
  1126. {
  1127. for(bmap<ui16, ArtSlotInfo>::iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1128. if(i->second.artifact && !i->second.locked)
  1129. node->attachTo(i->second.artifact);
  1130. }