CArtHandler.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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, shared_ptr<ILimiter> limiter = 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, shared_ptr<IPropagator> propagator = 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, 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, 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. }
  649. CArtifactInstance::CArtifactInstance()
  650. {
  651. init();
  652. }
  653. CArtifactInstance::CArtifactInstance( CArtifact *Art)
  654. {
  655. init();
  656. setType(Art);
  657. }
  658. void CArtifactInstance::setType( CArtifact *Art )
  659. {
  660. artType = Art;
  661. attachTo(Art);
  662. }
  663. std::string CArtifactInstance::nodeName() const
  664. {
  665. return "Artifact instance of " + (artType ? artType->Name() : std::string("uninitialized")) + " type";
  666. }
  667. CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s)
  668. {
  669. auto ret = new CArtifactInstance(VLC->arth->artifacts[ArtifactID::SPELL_SCROLL]);
  670. auto b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, ArtifactID::SPELL_SCROLL, s->id);
  671. ret->addNewBonus(b);
  672. return ret;
  673. }
  674. void CArtifactInstance::init()
  675. {
  676. id = ArtifactInstanceID();
  677. id = static_cast<ArtifactInstanceID>(ArtifactID::NONE); //to be randomized
  678. setNodeType(ARTIFACT_INSTANCE);
  679. }
  680. ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
  681. {
  682. for(auto slot : artType->possibleSlots.at(h->bearerType()))
  683. {
  684. if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
  685. {
  686. //we've found a free suitable slot.
  687. return slot;
  688. }
  689. }
  690. //if haven't find proper slot, use backpack
  691. return firstBackpackSlot(h);
  692. }
  693. ArtifactPosition CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
  694. {
  695. if(!artType->isBig()) //discard big artifact
  696. return ArtifactPosition(
  697. GameConstants::BACKPACK_START + h->artifactsInBackpack.size());
  698. return ArtifactPosition::PRE_FIRST;
  699. }
  700. bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved /*= false*/) const
  701. {
  702. return canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
  703. }
  704. bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved /*= false*/) const
  705. {
  706. if(slot >= GameConstants::BACKPACK_START)
  707. {
  708. if(artType->isBig())
  709. return false;
  710. //TODO backpack limit
  711. return true;
  712. }
  713. auto possibleSlots = artType->possibleSlots.find(artSet->bearerType());
  714. if(possibleSlots == artType->possibleSlots.end())
  715. {
  716. logGlobal->warnStream() << "Warning: artifact " << artType->Name() << " doesn't have defined allowed slots for bearer of type "
  717. << artSet->bearerType();
  718. return false;
  719. }
  720. if(!vstd::contains(possibleSlots->second, slot))
  721. return false;
  722. return artSet->isPositionFree(slot, assumeDestRemoved);
  723. }
  724. void CArtifactInstance::putAt(ArtifactLocation al)
  725. {
  726. assert(canBePutAt(al));
  727. al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
  728. if(al.slot < GameConstants::BACKPACK_START)
  729. al.getHolderNode()->attachTo(this);
  730. }
  731. void CArtifactInstance::removeFrom(ArtifactLocation al)
  732. {
  733. assert(al.getHolderArtSet()->getArt(al.slot) == this);
  734. al.getHolderArtSet()->eraseArtSlot(al.slot);
  735. if(al.slot < GameConstants::BACKPACK_START)
  736. al.getHolderNode()->detachFrom(this);
  737. //TODO delete me?
  738. }
  739. bool CArtifactInstance::canBeDisassembled() const
  740. {
  741. return bool(artType->constituents);
  742. }
  743. std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
  744. {
  745. std::vector<const CArtifact *> ret;
  746. if(artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
  747. return ret;
  748. for(const CArtifact * artifact : artType->constituentOf)
  749. {
  750. assert(artifact->constituents);
  751. bool possible = true;
  752. for(const CArtifact * constituent : *artifact->constituents) //check if all constituents are available
  753. {
  754. if(!h->hasArt(constituent->id, true)) //constituent must be equipped
  755. {
  756. possible = false;
  757. break;
  758. }
  759. }
  760. if(possible)
  761. ret.push_back(artifact);
  762. }
  763. return ret;
  764. }
  765. void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
  766. {
  767. removeFrom(src);
  768. putAt(dst);
  769. }
  770. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
  771. {
  772. if(!Art->constituents)
  773. {
  774. auto ret = new CArtifactInstance(Art);
  775. if (dynamic_cast<CGrowingArtifact *>(Art))
  776. {
  777. auto bonus = new Bonus;
  778. bonus->type = Bonus::LEVEL_COUNTER;
  779. bonus->val = 0;
  780. ret->addNewBonus (bonus);
  781. }
  782. return ret;
  783. }
  784. else
  785. {
  786. auto ret = new CCombinedArtifactInstance(Art);
  787. ret->createConstituents();
  788. return ret;
  789. }
  790. }
  791. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(int aid)
  792. {
  793. return createNewArtifactInstance(VLC->arth->artifacts[aid]);
  794. }
  795. void CArtifactInstance::deserializationFix()
  796. {
  797. setType(artType);
  798. }
  799. SpellID CArtifactInstance::getGivenSpellID() const
  800. {
  801. const Bonus * b = getBonusLocalFirst(Selector::type(Bonus::SPELL));
  802. if(!b)
  803. {
  804. logGlobal->warnStream() << "Warning: " << nodeName() << " doesn't bear any spell!";
  805. return SpellID::NONE;
  806. }
  807. return SpellID(b->subtype);
  808. }
  809. bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  810. {
  811. return supposedPart == this;
  812. }
  813. bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved /*= false*/) const
  814. {
  815. bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
  816. if(!canMainArtifactBePlaced)
  817. return false; //no is no...
  818. if(slot >= GameConstants::BACKPACK_START)
  819. return true; //we can always remove combined art to the backapck
  820. assert(artType->constituents);
  821. std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
  822. //it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
  823. //so we remove from the list all constituents that are already present on dst hero in the form of locks
  824. for(const ConstituentInfo &constituent : constituentsInfo)
  825. {
  826. if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
  827. constituentsToBePlaced -= constituent;
  828. }
  829. //we iterate over all active slots and check if constituents fits them
  830. for (int i = 0; i < GameConstants::BACKPACK_START; i++)
  831. {
  832. for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
  833. {
  834. 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
  835. {
  836. constituentsToBePlaced.erase(art);
  837. break;
  838. }
  839. }
  840. }
  841. return constituentsToBePlaced.empty();
  842. }
  843. bool CCombinedArtifactInstance::canBeDisassembled() const
  844. {
  845. return true;
  846. }
  847. CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
  848. : CArtifactInstance(Art) //TODO: seems unued, but need to be written
  849. {
  850. }
  851. CCombinedArtifactInstance::CCombinedArtifactInstance()
  852. {
  853. }
  854. void CCombinedArtifactInstance::createConstituents()
  855. {
  856. assert(artType);
  857. assert(artType->constituents);
  858. for(const CArtifact * art : *artType->constituents)
  859. {
  860. addAsConstituent(CArtifactInstance::createNewArtifactInstance(art->id), ArtifactPosition::PRE_FIRST);
  861. }
  862. }
  863. void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, ArtifactPosition slot)
  864. {
  865. assert(vstd::contains(*artType->constituents, art->artType.get()));
  866. assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
  867. constituentsInfo.push_back(ConstituentInfo(art, slot));
  868. attachTo(art);
  869. }
  870. void CCombinedArtifactInstance::putAt(ArtifactLocation al)
  871. {
  872. if(al.slot >= GameConstants::BACKPACK_START)
  873. {
  874. CArtifactInstance::putAt(al);
  875. for(ConstituentInfo &ci : constituentsInfo)
  876. ci.slot = ArtifactPosition::PRE_FIRST;
  877. }
  878. else
  879. {
  880. CArtifactInstance *mainConstituent = figureMainConstituent(al); //it'll be replaced with combined artifact, not a lock
  881. CArtifactInstance::putAt(al); //puts combined art (this)
  882. for(ConstituentInfo &ci : constituentsInfo)
  883. {
  884. if(ci.art != mainConstituent)
  885. {
  886. const ArtifactLocation suggestedPos(al.artHolder, ci.slot);
  887. const bool inActiveSlot = vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START);
  888. const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
  889. ArtifactPosition pos = ArtifactPosition::PRE_FIRST;
  890. if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
  891. pos = ci.slot;
  892. else
  893. ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
  894. assert(pos < GameConstants::BACKPACK_START);
  895. al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
  896. }
  897. else
  898. {
  899. ci.slot = ArtifactPosition::PRE_FIRST;
  900. }
  901. }
  902. }
  903. }
  904. void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
  905. {
  906. if(al.slot >= GameConstants::BACKPACK_START)
  907. {
  908. CArtifactInstance::removeFrom(al);
  909. }
  910. else
  911. {
  912. for(ConstituentInfo &ci : constituentsInfo)
  913. {
  914. if(ci.slot >= 0)
  915. {
  916. al.getHolderArtSet()->eraseArtSlot(ci.slot);
  917. ci.slot = ArtifactPosition::PRE_FIRST;
  918. }
  919. else
  920. {
  921. //main constituent
  922. CArtifactInstance::removeFrom(al);
  923. }
  924. }
  925. }
  926. }
  927. CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
  928. {
  929. CArtifactInstance *mainConstituent = nullptr; //it'll be replaced with combined artifact, not a lock
  930. for(ConstituentInfo &ci : constituentsInfo)
  931. if(ci.slot == al.slot)
  932. mainConstituent = ci.art;
  933. if(!mainConstituent)
  934. {
  935. for(ConstituentInfo &ci : constituentsInfo)
  936. {
  937. if(vstd::contains(ci.art->artType->possibleSlots[al.getHolderArtSet()->bearerType()], al.slot))
  938. {
  939. mainConstituent = ci.art;
  940. }
  941. }
  942. }
  943. return mainConstituent;
  944. }
  945. void CCombinedArtifactInstance::deserializationFix()
  946. {
  947. for(ConstituentInfo &ci : constituentsInfo)
  948. attachTo(ci.art);
  949. }
  950. bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  951. {
  952. bool me = CArtifactInstance::isPart(supposedPart);
  953. if(me)
  954. return true;
  955. //check for constituents
  956. for(const ConstituentInfo &constituent : constituentsInfo)
  957. if(constituent.art == supposedPart)
  958. return true;
  959. return false;
  960. }
  961. CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art /*= nullptr*/, ArtifactPosition Slot /*= -1*/)
  962. {
  963. art = Art;
  964. slot = Slot;
  965. }
  966. bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
  967. {
  968. return art == rhs.art && slot == rhs.slot;
  969. }
  970. const CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked /*= true*/) const
  971. {
  972. if(const ArtSlotInfo *si = getSlot(pos))
  973. {
  974. if(si->artifact && (!excludeLocked || !si->locked))
  975. return si->artifact;
  976. }
  977. return nullptr;
  978. }
  979. CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked /*= true*/)
  980. {
  981. return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
  982. }
  983. ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
  984. {
  985. for(auto i = artifactsWorn.cbegin(); i != artifactsWorn.cend(); i++)
  986. if(i->second.artifact->artType->id == aid)
  987. return i->first;
  988. if(onlyWorn)
  989. return ArtifactPosition::PRE_FIRST;
  990. for(int i = 0; i < artifactsInBackpack.size(); i++)
  991. if(artifactsInBackpack[i].artifact->artType->id == aid)
  992. return ArtifactPosition(GameConstants::BACKPACK_START + i);
  993. return ArtifactPosition::PRE_FIRST;
  994. }
  995. ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const
  996. {
  997. for(auto i : artifactsWorn)
  998. if(i.second.artifact == art)
  999. return i.first;
  1000. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1001. if(artifactsInBackpack[i].artifact == art)
  1002. return ArtifactPosition(GameConstants::BACKPACK_START + i);
  1003. return ArtifactPosition::PRE_FIRST;
  1004. }
  1005. const CArtifactInstance * CArtifactSet::getArtByInstanceId( ArtifactInstanceID artInstId ) const
  1006. {
  1007. for(auto i : artifactsWorn)
  1008. if(i.second.artifact->id == artInstId)
  1009. return i.second.artifact;
  1010. for(auto i : artifactsInBackpack)
  1011. if(i.artifact->id == artInstId)
  1012. return i.artifact;
  1013. return nullptr;
  1014. }
  1015. bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
  1016. {
  1017. return getArtPos(aid, onlyWorn) != ArtifactPosition::PRE_FIRST;
  1018. }
  1019. const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
  1020. {
  1021. if(vstd::contains(artifactsWorn, pos))
  1022. return &artifactsWorn.at(pos);
  1023. if(pos >= ArtifactPosition::AFTER_LAST )
  1024. {
  1025. int backpackPos = (int)pos - GameConstants::BACKPACK_START;
  1026. if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
  1027. return nullptr;
  1028. else
  1029. return &artifactsInBackpack[backpackPos];
  1030. }
  1031. return nullptr;
  1032. }
  1033. bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck /*= false*/) const
  1034. {
  1035. if(const ArtSlotInfo *s = getSlot(pos))
  1036. return (onlyLockCheck || !s->artifact) && !s->locked;
  1037. return true; //no slot means not used
  1038. }
  1039. si32 CArtifactSet::getArtTypeId(ArtifactPosition pos) const
  1040. {
  1041. const CArtifactInstance * const a = getArt(pos);
  1042. if(!a)
  1043. {
  1044. logGlobal->warnStream() << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)";
  1045. return -1;
  1046. }
  1047. return a->artType->id;
  1048. }
  1049. CArtifactSet::~CArtifactSet()
  1050. {
  1051. }
  1052. ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ArtifactPosition slot)
  1053. {
  1054. assert(!vstd::contains(artifactsWorn, slot));
  1055. ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
  1056. ? artifactsWorn[slot]
  1057. : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
  1058. return ret;
  1059. }
  1060. void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked)
  1061. {
  1062. ArtSlotInfo &asi = retreiveNewArtSlot(slot);
  1063. asi.artifact = art;
  1064. asi.locked = locked;
  1065. }
  1066. void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
  1067. {
  1068. if(slot < GameConstants::BACKPACK_START)
  1069. {
  1070. artifactsWorn.erase(slot);
  1071. }
  1072. else
  1073. {
  1074. slot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
  1075. artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
  1076. }
  1077. }
  1078. void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
  1079. {
  1080. for(auto & elem : artifactsWorn)
  1081. if(elem.second.artifact && !elem.second.locked)
  1082. node->attachTo(elem.second.artifact);
  1083. }