CArtHandler.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. /*
  2. * CArtHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CArtHandler.h"
  12. #include "filesystem/Filesystem.h"
  13. #include "CGeneralTextHandler.h"
  14. #include "VCMI_Lib.h"
  15. #include "CModHandler.h"
  16. #include "spells/CSpellHandler.h"
  17. #include "mapObjects/MapObjects.h"
  18. #include "NetPacksBase.h"
  19. #include "GameConstants.h"
  20. #include "CRandomGenerator.h"
  21. #include "mapObjects/CObjectClassesHandler.h"
  22. // Note: list must match entries in ArtTraits.txt
  23. #define ART_POS_LIST \
  24. ART_POS(SPELLBOOK) \
  25. ART_POS(MACH4) \
  26. ART_POS(MACH3) \
  27. ART_POS(MACH2) \
  28. ART_POS(MACH1) \
  29. ART_POS(MISC5) \
  30. ART_POS(MISC4) \
  31. ART_POS(MISC3) \
  32. ART_POS(MISC2) \
  33. ART_POS(MISC1) \
  34. ART_POS(FEET) \
  35. ART_POS(LEFT_RING) \
  36. ART_POS(RIGHT_RING) \
  37. ART_POS(TORSO) \
  38. ART_POS(LEFT_HAND) \
  39. ART_POS(RIGHT_HAND) \
  40. ART_POS(NECK) \
  41. ART_POS(SHOULDERS) \
  42. ART_POS(HEAD)
  43. const std::string & CArtifact::Name() const
  44. {
  45. return name;
  46. }
  47. const std::string & CArtifact::Description() const
  48. {
  49. return description;
  50. }
  51. const std::string & CArtifact::EventText() const
  52. {
  53. return eventText;
  54. }
  55. bool CArtifact::isBig () const
  56. {
  57. return VLC->arth->isBigArtifact(id);
  58. }
  59. bool CArtifact::isTradable () const
  60. {
  61. return VLC->arth->isTradableArtifact(id);
  62. }
  63. CArtifact::CArtifact()
  64. {
  65. setNodeType(ARTIFACT);
  66. possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
  67. possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
  68. possibleSlots[ArtBearer::COMMANDER];
  69. }
  70. CArtifact::~CArtifact()
  71. {
  72. }
  73. int CArtifact::getArtClassSerial() const
  74. {
  75. if(id == ArtifactID::SPELL_SCROLL)
  76. return 4;
  77. switch(aClass)
  78. {
  79. case ART_TREASURE:
  80. return 0;
  81. case ART_MINOR:
  82. return 1;
  83. case ART_MAJOR:
  84. return 2;
  85. case ART_RELIC:
  86. return 3;
  87. case ART_SPECIAL:
  88. return 5;
  89. }
  90. return -1;
  91. }
  92. std::string CArtifact::nodeName() const
  93. {
  94. return "Artifact: " + Name();
  95. }
  96. void CArtifact::addNewBonus(Bonus *b)
  97. {
  98. b->source = Bonus::ARTIFACT;
  99. b->duration = Bonus::PERMANENT;
  100. b->description = name;
  101. CBonusSystemNode::addNewBonus(b);
  102. }
  103. void CGrowingArtifact::levelUpArtifact (CArtifactInstance * art)
  104. {
  105. Bonus b;
  106. b.type = Bonus::LEVEL_COUNTER;
  107. b.val = 1;
  108. b.duration = Bonus::COMMANDER_KILLED;
  109. art->accumulateBonus (b);
  110. for (auto bonus : bonusesPerLevel)
  111. {
  112. if (art->valOfBonuses(Bonus::LEVEL_COUNTER) % bonus.first == 0) //every n levels
  113. {
  114. art->accumulateBonus (bonus.second);
  115. }
  116. }
  117. for (auto bonus : thresholdBonuses)
  118. {
  119. if (art->valOfBonuses(Bonus::LEVEL_COUNTER) == bonus.first) //every n levels
  120. {
  121. art->addNewBonus (&bonus.second);
  122. }
  123. }
  124. }
  125. CArtHandler::CArtHandler()
  126. {
  127. //VLC->arth = this;
  128. // War machines are the default big artifacts.
  129. for (ArtifactID i = ArtifactID::CATAPULT; i <= ArtifactID::FIRST_AID_TENT; i.advance(1))
  130. bigArtifacts.insert(i);
  131. }
  132. CArtHandler::~CArtHandler()
  133. {
  134. for(CArtifact * art : artifacts)
  135. delete art;
  136. }
  137. std::vector<JsonNode> CArtHandler::loadLegacyData(size_t dataSize)
  138. {
  139. artifacts.resize(dataSize);
  140. std::vector<JsonNode> h3Data;
  141. h3Data.reserve(dataSize);
  142. #define ART_POS(x) #x ,
  143. const std::vector<std::string> artSlots = { ART_POS_LIST };
  144. #undef ART_POS
  145. static std::map<char, std::string> classes =
  146. {{'S',"SPECIAL"}, {'T',"TREASURE"},{'N',"MINOR"},{'J',"MAJOR"},{'R',"RELIC"},};
  147. CLegacyConfigParser parser("DATA/ARTRAITS.TXT");
  148. CLegacyConfigParser events("DATA/ARTEVENT.TXT");
  149. parser.endLine(); // header
  150. parser.endLine();
  151. for (size_t i = 0; i < dataSize; i++)
  152. {
  153. JsonNode artData;
  154. artData["text"]["name"].String() = parser.readString();
  155. artData["text"]["event"].String() = events.readString();
  156. artData["value"].Float() = parser.readNumber();
  157. for(auto & artSlot : artSlots)
  158. {
  159. if(parser.readString() == "x")
  160. {
  161. artData["slot"].Vector().push_back(JsonNode());
  162. artData["slot"].Vector().back().String() = artSlot;
  163. }
  164. }
  165. artData["class"].String() = classes[parser.readString()[0]];
  166. artData["text"]["description"].String() = parser.readString();
  167. parser.endLine();
  168. events.endLine();
  169. h3Data.push_back(artData);
  170. }
  171. return h3Data;
  172. }
  173. void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  174. {
  175. auto object = loadFromJson(data, name);
  176. object->id = ArtifactID(artifacts.size());
  177. object->iconIndex = object->id + 5;
  178. artifacts.push_back(object);
  179. VLC->modh->identifiers.requestIdentifier(scope, "object", "artifact", [=](si32 index)
  180. {
  181. JsonNode conf;
  182. conf.setMeta(scope);
  183. VLC->objtypeh->loadSubObject(object->identifier, conf, Obj::ARTIFACT, object->id.num);
  184. if (!object->advMapDef.empty())
  185. {
  186. JsonNode templ;
  187. templ.setMeta(scope);
  188. templ["animation"].String() = object->advMapDef;
  189. // add new template.
  190. // Necessary for objects added via mods that don't have any templates in H3
  191. VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, object->id)->addTemplate(templ);
  192. }
  193. // object does not have any templates - this is not usable object (e.g. pseudo-art like lock)
  194. if (VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, object->id)->getTemplates().empty())
  195. VLC->objtypeh->removeSubObject(Obj::ARTIFACT, object->id);
  196. });
  197. registerObject(scope, "artifact", object->identifier, object->id);
  198. }
  199. void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  200. {
  201. auto object = loadFromJson(data, name);
  202. object->id = ArtifactID(index);
  203. object->iconIndex = object->id;
  204. assert(artifacts[index] == nullptr); // ensure that this id was not loaded before
  205. artifacts[index] = object;
  206. VLC->modh->identifiers.requestIdentifier(scope, "object", "artifact", [=](si32 index)
  207. {
  208. JsonNode conf;
  209. conf.setMeta(scope);
  210. VLC->objtypeh->loadSubObject(object->identifier, conf, Obj::ARTIFACT, object->id.num);
  211. if (!object->advMapDef.empty())
  212. {
  213. JsonNode templ;
  214. templ.setMeta(scope);
  215. templ["animation"].String() = object->advMapDef;
  216. // add new template.
  217. // Necessary for objects added via mods that don't have any templates in H3
  218. VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, object->id)->addTemplate(templ);
  219. }
  220. // object does not have any templates - this is not usable object (e.g. pseudo-art like lock)
  221. if (VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, object->id)->getTemplates().empty())
  222. VLC->objtypeh->removeSubObject(Obj::ARTIFACT, object->id);
  223. });
  224. registerObject(scope, "artifact", object->identifier, object->id);
  225. }
  226. CArtifact * CArtHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
  227. {
  228. CArtifact * art;
  229. if (!VLC->modh->modules.COMMANDERS || node["growing"].isNull())
  230. art = new CArtifact();
  231. else
  232. {
  233. auto growing = new CGrowingArtifact();
  234. loadGrowingArt(growing, node);
  235. art = growing;
  236. }
  237. art->identifier = identifier;
  238. const JsonNode & text = node["text"];
  239. art->name = text["name"].String();
  240. art->description = text["description"].String();
  241. art->eventText = text["event"].String();
  242. const JsonNode & graphics = node["graphics"];
  243. art->image = graphics["image"].String();
  244. if (!graphics["large"].isNull())
  245. art->large = graphics["large"].String();
  246. else
  247. art->large = art->image;
  248. art->advMapDef = graphics["map"].String();
  249. art->price = node["value"].Float();
  250. loadSlots(art, node);
  251. loadClass(art, node);
  252. loadType(art, node);
  253. loadComponents(art, node);
  254. for (auto b : node["bonuses"].Vector())
  255. {
  256. auto bonus = JsonUtils::parseBonus (b);
  257. art->addNewBonus(bonus);
  258. }
  259. return art;
  260. }
  261. ArtifactPosition CArtHandler::stringToSlot(std::string slotName)
  262. {
  263. #define ART_POS(x) { #x, ArtifactPosition::x },
  264. static const std::map<std::string, ArtifactPosition> artifactPositionMap = { ART_POS_LIST };
  265. #undef ART_POS
  266. auto it = artifactPositionMap.find (slotName);
  267. if (it != artifactPositionMap.end())
  268. return it->second;
  269. logGlobal->warnStream() << "Warning! Artifact slot " << slotName << " not recognized!";
  270. return ArtifactPosition::PRE_FIRST;
  271. }
  272. void CArtHandler::addSlot(CArtifact * art, const std::string & slotID)
  273. {
  274. static const std::vector<ArtifactPosition> miscSlots =
  275. {
  276. ArtifactPosition::MISC1, ArtifactPosition::MISC2, ArtifactPosition::MISC3, ArtifactPosition::MISC4, ArtifactPosition::MISC5
  277. };
  278. static const std::vector<ArtifactPosition> ringSlots =
  279. {
  280. ArtifactPosition::LEFT_RING, ArtifactPosition::RIGHT_RING
  281. };
  282. if (slotID == "MISC")
  283. {
  284. vstd::concatenate(art->possibleSlots[ArtBearer::HERO], miscSlots);
  285. }
  286. else if (slotID == "RING")
  287. {
  288. vstd::concatenate(art->possibleSlots[ArtBearer::HERO], ringSlots);
  289. }
  290. else
  291. {
  292. auto slot = stringToSlot(slotID);
  293. if (slot != ArtifactPosition::PRE_FIRST)
  294. art->possibleSlots[ArtBearer::HERO].push_back (slot);
  295. }
  296. }
  297. void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node)
  298. {
  299. if (!node["slot"].isNull()) //we assume non-hero slots are irrelevant?
  300. {
  301. if (node["slot"].getType() == JsonNode::DATA_STRING)
  302. addSlot(art, node["slot"].String());
  303. else
  304. {
  305. for (const JsonNode & slot : node["slot"].Vector())
  306. addSlot(art, slot.String());
  307. }
  308. }
  309. }
  310. CArtifact::EartClass CArtHandler::stringToClass(std::string className)
  311. {
  312. static const std::map<std::string, CArtifact::EartClass> artifactClassMap =
  313. {
  314. {"TREASURE", CArtifact::ART_TREASURE},
  315. {"MINOR", CArtifact::ART_MINOR},
  316. {"MAJOR", CArtifact::ART_MAJOR},
  317. {"RELIC", CArtifact::ART_RELIC},
  318. {"SPECIAL", CArtifact::ART_SPECIAL}
  319. };
  320. auto it = artifactClassMap.find (className);
  321. if (it != artifactClassMap.end())
  322. return it->second;
  323. logGlobal->warnStream() << "Warning! Artifact rarity " << className << " not recognized!";
  324. return CArtifact::ART_SPECIAL;
  325. }
  326. void CArtHandler::loadClass(CArtifact * art, const JsonNode & node)
  327. {
  328. art->aClass = stringToClass(node["class"].String());
  329. }
  330. void CArtHandler::loadType(CArtifact * art, const JsonNode & node)
  331. {
  332. #define ART_BEARER(x) { #x, ArtBearer::x },
  333. static const std::map<std::string, int> artifactBearerMap = { ART_BEARER_LIST };
  334. #undef ART_BEARER
  335. for (const JsonNode & b : node["type"].Vector())
  336. {
  337. auto it = artifactBearerMap.find (b.String());
  338. if (it != artifactBearerMap.end())
  339. {
  340. int bearerType = it->second;
  341. switch (bearerType)
  342. {
  343. case ArtBearer::HERO://TODO: allow arts having several possible bearers
  344. break;
  345. case ArtBearer::COMMANDER:
  346. makeItCommanderArt (art); //original artifacts should have only one bearer type
  347. break;
  348. case ArtBearer::CREATURE:
  349. makeItCreatureArt (art);
  350. break;
  351. }
  352. }
  353. else
  354. logGlobal->warnStream() << "Warning! Artifact type " << b.String() << " not recognized!";
  355. }
  356. }
  357. void CArtHandler::loadComponents(CArtifact * art, const JsonNode & node)
  358. {
  359. if (!node["components"].isNull())
  360. {
  361. art->constituents.reset(new std::vector<CArtifact *>());
  362. for (auto component : node["components"].Vector())
  363. {
  364. VLC->modh->identifiers.requestIdentifier("artifact", component, [=](si32 id)
  365. {
  366. // when this code is called both combinational art as well as component are loaded
  367. // so it is safe to access any of them
  368. art->constituents->push_back(VLC->arth->artifacts[id]);
  369. VLC->arth->artifacts[id]->constituentOf.push_back(art);
  370. });
  371. }
  372. }
  373. }
  374. void CArtHandler::loadGrowingArt(CGrowingArtifact * art, const JsonNode & node)
  375. {
  376. for (auto b : node["growing"]["bonusesPerLevel"].Vector())
  377. {
  378. art->bonusesPerLevel.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *JsonUtils::parseBonus (b["bonus"])));
  379. }
  380. for (auto b : node["growing"]["thresholdBonuses"].Vector())
  381. {
  382. art->thresholdBonuses.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *JsonUtils::parseBonus (b["bonus"])));
  383. }
  384. }
  385. //TODO: use bimap
  386. ArtifactID CArtHandler::creatureToMachineID(CreatureID id)
  387. {
  388. switch (id)
  389. {
  390. case CreatureID::CATAPULT: //Catapult
  391. return ArtifactID::CATAPULT;
  392. break;
  393. case CreatureID::BALLISTA: //Ballista
  394. return ArtifactID::BALLISTA;
  395. break;
  396. case CreatureID::FIRST_AID_TENT: //First Aid tent
  397. return ArtifactID::FIRST_AID_TENT;
  398. break;
  399. case CreatureID::AMMO_CART: //Ammo cart
  400. return ArtifactID::AMMO_CART;
  401. break;
  402. }
  403. return ArtifactID::NONE; //this creature is not artifact
  404. }
  405. CreatureID CArtHandler::machineIDToCreature(ArtifactID id)
  406. {
  407. switch (id)
  408. {
  409. case ArtifactID::CATAPULT:
  410. return CreatureID::CATAPULT;
  411. break;
  412. case ArtifactID::BALLISTA:
  413. return CreatureID::BALLISTA;
  414. break;
  415. case ArtifactID::FIRST_AID_TENT:
  416. return CreatureID::FIRST_AID_TENT;
  417. break;
  418. case ArtifactID::AMMO_CART:
  419. return CreatureID::AMMO_CART;
  420. break;
  421. }
  422. return CreatureID::NONE; //this artifact is not a creature
  423. }
  424. ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags, std::function<bool(ArtifactID)> accepts)
  425. {
  426. auto getAllowedArts = [&](std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, CArtifact::EartClass flag)
  427. {
  428. if (arts->empty()) //restock available arts
  429. fillList(*arts, flag);
  430. for (auto & arts_i : *arts)
  431. {
  432. if (accepts(arts_i->id))
  433. {
  434. CArtifact *art = arts_i;
  435. out.push_back(art);
  436. }
  437. }
  438. };
  439. auto getAllowed = [&](std::vector<ConstTransitivePtr<CArtifact> > &out)
  440. {
  441. if (flags & CArtifact::ART_TREASURE)
  442. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  443. if (flags & CArtifact::ART_MINOR)
  444. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  445. if (flags & CArtifact::ART_MAJOR)
  446. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  447. if (flags & CArtifact::ART_RELIC)
  448. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  449. if (!out.size()) //no artifact of specified rarity, we need to take another one
  450. {
  451. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  452. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  453. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  454. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  455. }
  456. if (!out.size()) //no arts are available at all
  457. {
  458. out.resize (64);
  459. std::fill_n (out.begin(), 64, artifacts[2]); //Give Grail - this can't be banned (hopefully)
  460. }
  461. };
  462. std::vector<ConstTransitivePtr<CArtifact> > out;
  463. getAllowed(out);
  464. ArtifactID artID = (*RandomGeneratorUtil::nextItem(out, rand))->id;
  465. erasePickedArt(artID);
  466. return artID;
  467. }
  468. ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts)
  469. {
  470. return pickRandomArtifact(rand, 0xff, accepts);
  471. }
  472. ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags)
  473. {
  474. return pickRandomArtifact(rand, flags, [](ArtifactID){ return true;});
  475. }
  476. Bonus *createBonus(Bonus::BonusType type, int val, int subtype, Bonus::ValueType valType, std::shared_ptr<ILimiter> limiter = std::shared_ptr<ILimiter>(), int additionalInfo = 0)
  477. {
  478. auto added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,-1,subtype);
  479. added->additionalInfo = additionalInfo;
  480. added->valType = valType;
  481. added->limiter = limiter;
  482. return added;
  483. }
  484. Bonus *createBonus(Bonus::BonusType type, int val, int subtype, std::shared_ptr<IPropagator> propagator = std::shared_ptr<IPropagator>(), int additionalInfo = 0)
  485. {
  486. auto added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,-1,subtype);
  487. added->additionalInfo = additionalInfo;
  488. added->valType = Bonus::BASE_NUMBER;
  489. added->propagator = propagator;
  490. return added;
  491. }
  492. void CArtHandler::giveArtBonus( ArtifactID aid, Bonus::BonusType type, int val, int subtype, Bonus::ValueType valType, std::shared_ptr<ILimiter> limiter, int additionalInfo)
  493. {
  494. giveArtBonus(aid, createBonus(type, val, subtype, valType, limiter, additionalInfo));
  495. }
  496. void CArtHandler::giveArtBonus(ArtifactID aid, Bonus::BonusType type, int val, int subtype, std::shared_ptr<IPropagator> propagator /*= nullptr*/, int additionalInfo)
  497. {
  498. giveArtBonus(aid, createBonus(type, val, subtype, propagator, additionalInfo));
  499. }
  500. void CArtHandler::giveArtBonus(ArtifactID aid, Bonus *bonus)
  501. {
  502. bonus->sid = aid;
  503. if(bonus->subtype == Bonus::MORALE || bonus->type == Bonus::LUCK)
  504. bonus->description = artifacts[aid]->Name() + (bonus->val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(bonus->val);
  505. else
  506. bonus->description = artifacts[aid]->Name();
  507. artifacts[aid]->addNewBonus(bonus);
  508. }
  509. void CArtHandler::makeItCreatureArt (CArtifact * a, bool onlyCreature /*=true*/)
  510. {
  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::makeItCreatureArt (ArtifactID aid, bool onlyCreature /*=true*/)
  519. {
  520. CArtifact *a = artifacts[aid];
  521. makeItCreatureArt (a, onlyCreature);
  522. }
  523. void CArtHandler::makeItCommanderArt (CArtifact * a, bool onlyCommander /*= true*/ )
  524. {
  525. if (onlyCommander)
  526. {
  527. a->possibleSlots[ArtBearer::HERO].clear();
  528. a->possibleSlots[ArtBearer::CREATURE].clear();
  529. }
  530. for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
  531. a->possibleSlots[ArtBearer::COMMANDER].push_back(ArtifactPosition(i));
  532. }
  533. void CArtHandler::makeItCommanderArt( ArtifactID aid, bool onlyCommander /*= true*/ )
  534. {
  535. CArtifact *a = artifacts[aid];
  536. makeItCommanderArt (a, onlyCommander);
  537. }
  538. bool CArtHandler::legalArtifact(ArtifactID id)
  539. {
  540. auto art = artifacts[id];
  541. //assert ( (!art->constituents) || art->constituents->size() ); //artifacts is not combined or has some components
  542. return ((art->possibleSlots[ArtBearer::HERO].size() ||
  543. (art->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS) ||
  544. (art->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT)) &&
  545. !(art->constituents) && //no combo artifacts spawning
  546. art->aClass >= CArtifact::ART_TREASURE &&
  547. art->aClass <= CArtifact::ART_RELIC);
  548. }
  549. bool CArtHandler::isTradableArtifact(ArtifactID id) const
  550. {
  551. switch (id)
  552. {
  553. case ArtifactID::SPELLBOOK:
  554. case ArtifactID::GRAIL:
  555. case ArtifactID::CATAPULT:
  556. case ArtifactID::BALLISTA:
  557. case ArtifactID::AMMO_CART:
  558. case ArtifactID::FIRST_AID_TENT:
  559. return false;
  560. default:
  561. return true;
  562. }
  563. }
  564. void CArtHandler::initAllowedArtifactsList(const std::vector<bool> &allowed)
  565. {
  566. allowedArtifacts.clear();
  567. treasures.clear();
  568. minors.clear();
  569. majors.clear();
  570. relics.clear();
  571. for (ArtifactID i=ArtifactID::SPELLBOOK; i<ArtifactID::ART_SELECTION; i.advance(1))
  572. {
  573. //check artifacts allowed on a map
  574. //TODO: This line will be different when custom map format is implemented
  575. if (allowed[i] && legalArtifact(i))
  576. allowedArtifacts.push_back(artifacts[i]);
  577. }
  578. for (ArtifactID i = ArtifactID::ART_SELECTION; i<ArtifactID(artifacts.size()); i.advance(1)) //try to allow all artifacts added by mods
  579. {
  580. if (legalArtifact(ArtifactID(i)))
  581. allowedArtifacts.push_back(artifacts[i]);
  582. //keep im mind that artifact can be worn by more than one type of bearer
  583. }
  584. }
  585. std::vector<bool> CArtHandler::getDefaultAllowed() const
  586. {
  587. std::vector<bool> allowedArtifacts;
  588. allowedArtifacts.resize(127, true);
  589. allowedArtifacts.resize(141, false);
  590. allowedArtifacts.resize(GameConstants::ARTIFACTS_QUANTITY, true);
  591. return allowedArtifacts;
  592. }
  593. void CArtHandler::erasePickedArt(ArtifactID id)
  594. {
  595. CArtifact *art = artifacts[id];
  596. if(auto artifactList = listFromClass(art->aClass))
  597. {
  598. if(artifactList->empty())
  599. fillList(*artifactList, art->aClass);
  600. auto itr = vstd::find(*artifactList, art);
  601. if(itr != artifactList->end())
  602. {
  603. artifactList->erase(itr);
  604. }
  605. else
  606. logGlobal->warnStream() << "Problem: cannot erase artifact " << art->Name() << " from list, it was not present";
  607. }
  608. else
  609. logGlobal->warnStream() << "Problem: cannot find list for artifact " << art->Name() << ", strange class. (special?)";
  610. }
  611. boost::optional<std::vector<CArtifact*>&> CArtHandler::listFromClass( CArtifact::EartClass artifactClass )
  612. {
  613. switch(artifactClass)
  614. {
  615. case CArtifact::ART_TREASURE:
  616. return treasures;
  617. case CArtifact::ART_MINOR:
  618. return minors;
  619. case CArtifact::ART_MAJOR:
  620. return majors;
  621. case CArtifact::ART_RELIC:
  622. return relics;
  623. default: //special artifacts should not be erased
  624. return boost::optional<std::vector<CArtifact*>&>();
  625. }
  626. }
  627. void CArtHandler::fillList( std::vector<CArtifact*> &listToBeFilled, CArtifact::EartClass artifactClass )
  628. {
  629. assert(listToBeFilled.empty());
  630. for (auto & elem : allowedArtifacts)
  631. {
  632. if (elem->aClass == artifactClass)
  633. listToBeFilled.push_back(elem);
  634. }
  635. }
  636. void CArtHandler::afterLoadFinalization()
  637. {
  638. //All artifacts have their id, so we can properly update their bonuses' source ids.
  639. for(auto &art : artifacts)
  640. {
  641. for(auto &bonus : art->getExportedBonusList())
  642. {
  643. assert(art == artifacts[art->id]);
  644. assert(bonus->source == Bonus::ARTIFACT);
  645. bonus->sid = art->id;
  646. }
  647. }
  648. CBonusSystemNode::treeHasChanged();
  649. }
  650. CArtifactInstance::CArtifactInstance()
  651. {
  652. init();
  653. }
  654. CArtifactInstance::CArtifactInstance( CArtifact *Art)
  655. {
  656. init();
  657. setType(Art);
  658. }
  659. void CArtifactInstance::setType( CArtifact *Art )
  660. {
  661. artType = Art;
  662. attachTo(Art);
  663. }
  664. std::string CArtifactInstance::nodeName() const
  665. {
  666. return "Artifact instance of " + (artType ? artType->Name() : std::string("uninitialized")) + " type";
  667. }
  668. CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s)
  669. {
  670. auto ret = new CArtifactInstance(VLC->arth->artifacts[ArtifactID::SPELL_SCROLL]);
  671. auto b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, ArtifactID::SPELL_SCROLL, s->id);
  672. ret->addNewBonus(b);
  673. return ret;
  674. }
  675. void CArtifactInstance::init()
  676. {
  677. id = ArtifactInstanceID();
  678. id = static_cast<ArtifactInstanceID>(ArtifactID::NONE); //to be randomized
  679. setNodeType(ARTIFACT_INSTANCE);
  680. }
  681. ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
  682. {
  683. for(auto slot : artType->possibleSlots.at(h->bearerType()))
  684. {
  685. if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
  686. {
  687. //we've found a free suitable slot.
  688. return slot;
  689. }
  690. }
  691. //if haven't find proper slot, use backpack
  692. return firstBackpackSlot(h);
  693. }
  694. ArtifactPosition CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
  695. {
  696. if(!artType->isBig()) //discard big artifact
  697. return ArtifactPosition(
  698. GameConstants::BACKPACK_START + h->artifactsInBackpack.size());
  699. return ArtifactPosition::PRE_FIRST;
  700. }
  701. bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved /*= false*/) const
  702. {
  703. return canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
  704. }
  705. bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved /*= false*/) const
  706. {
  707. if(slot >= GameConstants::BACKPACK_START)
  708. {
  709. if(artType->isBig())
  710. return false;
  711. //TODO backpack limit
  712. return true;
  713. }
  714. auto possibleSlots = artType->possibleSlots.find(artSet->bearerType());
  715. if(possibleSlots == artType->possibleSlots.end())
  716. {
  717. logGlobal->warnStream() << "Warning: artifact " << artType->Name() << " doesn't have defined allowed slots for bearer of type "
  718. << artSet->bearerType();
  719. return false;
  720. }
  721. if(!vstd::contains(possibleSlots->second, slot))
  722. return false;
  723. return artSet->isPositionFree(slot, assumeDestRemoved);
  724. }
  725. void CArtifactInstance::putAt(ArtifactLocation al)
  726. {
  727. assert(canBePutAt(al));
  728. al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
  729. if(al.slot < GameConstants::BACKPACK_START)
  730. al.getHolderNode()->attachTo(this);
  731. }
  732. void CArtifactInstance::removeFrom(ArtifactLocation al)
  733. {
  734. assert(al.getHolderArtSet()->getArt(al.slot) == this);
  735. al.getHolderArtSet()->eraseArtSlot(al.slot);
  736. if(al.slot < GameConstants::BACKPACK_START)
  737. al.getHolderNode()->detachFrom(this);
  738. //TODO delete me?
  739. }
  740. bool CArtifactInstance::canBeDisassembled() const
  741. {
  742. return bool(artType->constituents);
  743. }
  744. std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
  745. {
  746. std::vector<const CArtifact *> ret;
  747. if(artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
  748. return ret;
  749. for(const CArtifact * artifact : artType->constituentOf)
  750. {
  751. assert(artifact->constituents);
  752. bool possible = true;
  753. for(const CArtifact * constituent : *artifact->constituents) //check if all constituents are available
  754. {
  755. if(!h->hasArt(constituent->id, true)) //constituent must be equipped
  756. {
  757. possible = false;
  758. break;
  759. }
  760. }
  761. if(possible)
  762. ret.push_back(artifact);
  763. }
  764. return ret;
  765. }
  766. void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
  767. {
  768. removeFrom(src);
  769. putAt(dst);
  770. }
  771. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
  772. {
  773. if(!Art->constituents)
  774. {
  775. auto ret = new CArtifactInstance(Art);
  776. if (dynamic_cast<CGrowingArtifact *>(Art))
  777. {
  778. auto bonus = new Bonus;
  779. bonus->type = Bonus::LEVEL_COUNTER;
  780. bonus->val = 0;
  781. ret->addNewBonus (bonus);
  782. }
  783. return ret;
  784. }
  785. else
  786. {
  787. auto ret = new CCombinedArtifactInstance(Art);
  788. ret->createConstituents();
  789. return ret;
  790. }
  791. }
  792. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(int aid)
  793. {
  794. return createNewArtifactInstance(VLC->arth->artifacts[aid]);
  795. }
  796. void CArtifactInstance::deserializationFix()
  797. {
  798. setType(artType);
  799. }
  800. SpellID CArtifactInstance::getGivenSpellID() const
  801. {
  802. const Bonus * b = getBonusLocalFirst(Selector::type(Bonus::SPELL));
  803. if(!b)
  804. {
  805. logGlobal->warnStream() << "Warning: " << nodeName() << " doesn't bear any spell!";
  806. return SpellID::NONE;
  807. }
  808. return SpellID(b->subtype);
  809. }
  810. bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  811. {
  812. return supposedPart == this;
  813. }
  814. bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved /*= false*/) const
  815. {
  816. bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
  817. if(!canMainArtifactBePlaced)
  818. return false; //no is no...
  819. if(slot >= GameConstants::BACKPACK_START)
  820. return true; //we can always remove combined art to the backapck
  821. assert(artType->constituents);
  822. std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
  823. //it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
  824. //so we remove from the list all constituents that are already present on dst hero in the form of locks
  825. for(const ConstituentInfo &constituent : constituentsInfo)
  826. {
  827. if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
  828. constituentsToBePlaced -= constituent;
  829. }
  830. //we iterate over all active slots and check if constituents fits them
  831. for (int i = 0; i < GameConstants::BACKPACK_START; i++)
  832. {
  833. for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
  834. {
  835. if(art->art->canBePutAt(artSet, ArtifactPosition(i), i == slot)) // i == al.slot because we can remove already worn artifact only from that slot that is our main destination
  836. {
  837. constituentsToBePlaced.erase(art);
  838. break;
  839. }
  840. }
  841. }
  842. return constituentsToBePlaced.empty();
  843. }
  844. bool CCombinedArtifactInstance::canBeDisassembled() const
  845. {
  846. return true;
  847. }
  848. CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
  849. : CArtifactInstance(Art) //TODO: seems unued, but need to be written
  850. {
  851. }
  852. CCombinedArtifactInstance::CCombinedArtifactInstance()
  853. {
  854. }
  855. void CCombinedArtifactInstance::createConstituents()
  856. {
  857. assert(artType);
  858. assert(artType->constituents);
  859. for(const CArtifact * art : *artType->constituents)
  860. {
  861. addAsConstituent(CArtifactInstance::createNewArtifactInstance(art->id), ArtifactPosition::PRE_FIRST);
  862. }
  863. }
  864. void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, ArtifactPosition slot)
  865. {
  866. assert(vstd::contains(*artType->constituents, art->artType.get()));
  867. assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
  868. constituentsInfo.push_back(ConstituentInfo(art, slot));
  869. attachTo(art);
  870. }
  871. void CCombinedArtifactInstance::putAt(ArtifactLocation al)
  872. {
  873. if(al.slot >= GameConstants::BACKPACK_START)
  874. {
  875. CArtifactInstance::putAt(al);
  876. for(ConstituentInfo &ci : constituentsInfo)
  877. ci.slot = ArtifactPosition::PRE_FIRST;
  878. }
  879. else
  880. {
  881. CArtifactInstance *mainConstituent = figureMainConstituent(al); //it'll be replaced with combined artifact, not a lock
  882. CArtifactInstance::putAt(al); //puts combined art (this)
  883. for(ConstituentInfo &ci : constituentsInfo)
  884. {
  885. if(ci.art != mainConstituent)
  886. {
  887. const ArtifactLocation suggestedPos(al.artHolder, ci.slot);
  888. const bool inActiveSlot = vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START);
  889. const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
  890. ArtifactPosition pos = ArtifactPosition::PRE_FIRST;
  891. if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
  892. pos = ci.slot;
  893. else
  894. ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
  895. assert(pos < GameConstants::BACKPACK_START);
  896. al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
  897. }
  898. else
  899. {
  900. ci.slot = ArtifactPosition::PRE_FIRST;
  901. }
  902. }
  903. }
  904. }
  905. void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
  906. {
  907. if(al.slot >= GameConstants::BACKPACK_START)
  908. {
  909. CArtifactInstance::removeFrom(al);
  910. }
  911. else
  912. {
  913. for(ConstituentInfo &ci : constituentsInfo)
  914. {
  915. if(ci.slot >= 0)
  916. {
  917. al.getHolderArtSet()->eraseArtSlot(ci.slot);
  918. ci.slot = ArtifactPosition::PRE_FIRST;
  919. }
  920. else
  921. {
  922. //main constituent
  923. CArtifactInstance::removeFrom(al);
  924. }
  925. }
  926. }
  927. }
  928. CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
  929. {
  930. CArtifactInstance *mainConstituent = nullptr; //it'll be replaced with combined artifact, not a lock
  931. for(ConstituentInfo &ci : constituentsInfo)
  932. if(ci.slot == al.slot)
  933. mainConstituent = ci.art;
  934. if(!mainConstituent)
  935. {
  936. for(ConstituentInfo &ci : constituentsInfo)
  937. {
  938. if(vstd::contains(ci.art->artType->possibleSlots[al.getHolderArtSet()->bearerType()], al.slot))
  939. {
  940. mainConstituent = ci.art;
  941. }
  942. }
  943. }
  944. return mainConstituent;
  945. }
  946. void CCombinedArtifactInstance::deserializationFix()
  947. {
  948. for(ConstituentInfo &ci : constituentsInfo)
  949. attachTo(ci.art);
  950. }
  951. bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  952. {
  953. bool me = CArtifactInstance::isPart(supposedPart);
  954. if(me)
  955. return true;
  956. //check for constituents
  957. for(const ConstituentInfo &constituent : constituentsInfo)
  958. if(constituent.art == supposedPart)
  959. return true;
  960. return false;
  961. }
  962. CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art /*= nullptr*/, ArtifactPosition Slot /*= -1*/)
  963. {
  964. art = Art;
  965. slot = Slot;
  966. }
  967. bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
  968. {
  969. return art == rhs.art && slot == rhs.slot;
  970. }
  971. const CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked /*= true*/) const
  972. {
  973. if(const ArtSlotInfo *si = getSlot(pos))
  974. {
  975. if(si->artifact && (!excludeLocked || !si->locked))
  976. return si->artifact;
  977. }
  978. return nullptr;
  979. }
  980. CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked /*= true*/)
  981. {
  982. return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
  983. }
  984. ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
  985. {
  986. for(auto i = artifactsWorn.cbegin(); i != artifactsWorn.cend(); i++)
  987. if(i->second.artifact->artType->id == aid)
  988. return i->first;
  989. if(onlyWorn)
  990. return ArtifactPosition::PRE_FIRST;
  991. for(int i = 0; i < artifactsInBackpack.size(); i++)
  992. if(artifactsInBackpack[i].artifact->artType->id == aid)
  993. return ArtifactPosition(GameConstants::BACKPACK_START + i);
  994. return ArtifactPosition::PRE_FIRST;
  995. }
  996. ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const
  997. {
  998. for(auto i : artifactsWorn)
  999. if(i.second.artifact == art)
  1000. return i.first;
  1001. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1002. if(artifactsInBackpack[i].artifact == art)
  1003. return ArtifactPosition(GameConstants::BACKPACK_START + i);
  1004. return ArtifactPosition::PRE_FIRST;
  1005. }
  1006. const CArtifactInstance * CArtifactSet::getArtByInstanceId( ArtifactInstanceID artInstId ) const
  1007. {
  1008. for(auto i : artifactsWorn)
  1009. if(i.second.artifact->id == artInstId)
  1010. return i.second.artifact;
  1011. for(auto i : artifactsInBackpack)
  1012. if(i.artifact->id == artInstId)
  1013. return i.artifact;
  1014. return nullptr;
  1015. }
  1016. bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
  1017. {
  1018. return getArtPos(aid, onlyWorn) != ArtifactPosition::PRE_FIRST;
  1019. }
  1020. const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
  1021. {
  1022. if(vstd::contains(artifactsWorn, pos))
  1023. return &artifactsWorn.at(pos);
  1024. if(pos >= ArtifactPosition::AFTER_LAST )
  1025. {
  1026. int backpackPos = (int)pos - GameConstants::BACKPACK_START;
  1027. if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
  1028. return nullptr;
  1029. else
  1030. return &artifactsInBackpack[backpackPos];
  1031. }
  1032. return nullptr;
  1033. }
  1034. bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck /*= false*/) const
  1035. {
  1036. if(const ArtSlotInfo *s = getSlot(pos))
  1037. return (onlyLockCheck || !s->artifact) && !s->locked;
  1038. return true; //no slot means not used
  1039. }
  1040. si32 CArtifactSet::getArtTypeId(ArtifactPosition pos) const
  1041. {
  1042. const CArtifactInstance * const a = getArt(pos);
  1043. if(!a)
  1044. {
  1045. logGlobal->warnStream() << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)";
  1046. return -1;
  1047. }
  1048. return a->artType->id;
  1049. }
  1050. CArtifactSet::~CArtifactSet()
  1051. {
  1052. }
  1053. ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ArtifactPosition slot)
  1054. {
  1055. assert(!vstd::contains(artifactsWorn, slot));
  1056. ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
  1057. ? artifactsWorn[slot]
  1058. : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
  1059. return ret;
  1060. }
  1061. void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked)
  1062. {
  1063. ArtSlotInfo &asi = retreiveNewArtSlot(slot);
  1064. asi.artifact = art;
  1065. asi.locked = locked;
  1066. }
  1067. void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
  1068. {
  1069. if(slot < GameConstants::BACKPACK_START)
  1070. {
  1071. artifactsWorn.erase(slot);
  1072. }
  1073. else
  1074. {
  1075. slot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
  1076. artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
  1077. }
  1078. }
  1079. void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
  1080. {
  1081. for(auto & elem : artifactsWorn)
  1082. if(elem.second.artifact && !elem.second.locked)
  1083. node->attachTo(elem.second.artifact);
  1084. }