CArtHandler.cpp 34 KB

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