CArtHandler.cpp 35 KB

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