CArtHandler.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. #include "StdInc.h"
  2. #include "CArtHandler.h"
  3. #include "CLodHandler.h"
  4. #include "CGeneralTextHandler.h"
  5. #include <boost/random/linear_congruential.hpp>
  6. #include "../lib/VCMI_Lib.h"
  7. #include "CSpellHandler.h"
  8. #include "CObjectHandler.h"
  9. #include "NetPacks.h"
  10. extern CLodHandler *bitmaph;
  11. using namespace boost::assign;
  12. /*
  13. * CArtHandler.cpp, part of VCMI engine
  14. *
  15. * Authors: listed in file AUTHORS in main folder
  16. *
  17. * License: GNU General Public License v2.0 or later
  18. * Full text of license available in license.txt file, in main folder
  19. *
  20. */
  21. extern boost::rand48 ran;
  22. const std::string & CArtifact::Name() const
  23. {
  24. if(name.size())
  25. return name;
  26. else
  27. return VLC->generaltexth->artifNames[id];
  28. }
  29. const std::string & CArtifact::Description() const
  30. {
  31. if(description.size())
  32. return description;
  33. else
  34. return VLC->generaltexth->artifDescriptions[id];
  35. }
  36. bool CArtifact::isBig () const
  37. {
  38. return VLC->arth->isBigArtifact(id);
  39. }
  40. //
  41. // bool CArtifact::isModable () const
  42. // {
  43. // return (bool)dynamic_cast<const IModableArt *>(this);
  44. // }
  45. // /**
  46. // * Checks whether the artifact fits at a given slot.
  47. // * @param artifWorn A hero's set of worn artifacts.
  48. // */
  49. // bool CArtifact::fitsAt (const std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
  50. // {
  51. // if (!vstd::contains(possibleSlots, slotID))
  52. // return false;
  53. //
  54. // // Can't put an artifact in a locked slot.
  55. // std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.find(slotID);
  56. // if (it != artifWorn.end() && it->second->id == 145)
  57. // return false;
  58. //
  59. // // Check if a combination artifact fits.
  60. // // TODO: Might want a more general algorithm?
  61. // // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates.
  62. // if (constituents != NULL)
  63. // {
  64. // std::map<ui16, const CArtifact*> tempArtifWorn = artifWorn;
  65. // const ui16 ringSlots[] = {6, 7};
  66. // const ui16 miscSlots[] = {9, 10, 11, 12, 18};
  67. // int rings = 0;
  68. // int misc = 0;
  69. //
  70. // VLC->arth->unequipArtifact(tempArtifWorn, slotID);
  71. //
  72. // BOOST_FOREACH(ui32 constituentID, *constituents)
  73. // {
  74. // const CArtifact& constituent = *VLC->arth->artifacts[constituentID];
  75. // const int slot = constituent.possibleSlots[0];
  76. //
  77. // if (slot == 6 || slot == 7)
  78. // rings++;
  79. // else if ((slot >= 9 && slot <= 12) || slot == 18)
  80. // misc++;
  81. // else if (tempArtifWorn.find(slot) != tempArtifWorn.end())
  82. // return false;
  83. // }
  84. //
  85. // // Ensure enough ring slots are free
  86. // for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++)
  87. // {
  88. // if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID)
  89. // rings--;
  90. // }
  91. // if (rings > 0)
  92. // return false;
  93. //
  94. // // Ensure enough misc slots are free.
  95. // for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++)
  96. // {
  97. // if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID)
  98. // misc--;
  99. // }
  100. // if (misc > 0)
  101. // return false;
  102. // }
  103. //
  104. // return true;
  105. // }
  106. // bool CArtifact::canBeAssembledTo (const std::map<ui16, const CArtifact*> &artifWorn, ui32 artifactID) const
  107. // {
  108. // if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID))
  109. // return false;
  110. //
  111. // const CArtifact &artifact = *VLC->arth->artifacts[artifactID];
  112. // assert(artifact.constituents);
  113. //
  114. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  115. // {
  116. // bool found = false;
  117. // for (std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it)
  118. // {
  119. // if (it->second->id == constituentID)
  120. // {
  121. // found = true;
  122. // break;
  123. // }
  124. // }
  125. // if (!found)
  126. // return false;
  127. // }
  128. //
  129. // return true;
  130. // }
  131. CArtifact::CArtifact()
  132. {
  133. setNodeType(ARTIFACT);
  134. }
  135. CArtifact::~CArtifact()
  136. {
  137. }
  138. int CArtifact::getArtClassSerial() const
  139. {
  140. if(id == 1)
  141. return 4;
  142. switch(aClass)
  143. {
  144. case ART_TREASURE:
  145. return 0;
  146. case ART_MINOR:
  147. return 1;
  148. case ART_MAJOR:
  149. return 2;
  150. case ART_RELIC:
  151. return 3;
  152. case ART_SPECIAL:
  153. return 5;
  154. }
  155. return -1;
  156. }
  157. std::string CArtifact::nodeName() const
  158. {
  159. return "Artifact: " + Name();
  160. }
  161. // void CArtifact::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
  162. // {
  163. // //combined artifact carries bonuses from its parts
  164. // if(constituents)
  165. // {
  166. // BOOST_FOREACH(ui32 id, *constituents)
  167. // out.insert(VLC->arth->artifacts[id]);
  168. // }
  169. // }
  170. // void CScroll::Init()
  171. // {
  172. // // addNewBonus (Bonus (Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT, 1, id, spellid, Bonus::INDEPENDENT_MAX));
  173. // // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name);
  174. // }
  175. void CArtifact::setDescription (std::string desc)
  176. {
  177. description = desc;
  178. }
  179. CArtHandler::CArtHandler()
  180. {
  181. VLC->arth = this;
  182. // War machines are the default big artifacts.
  183. for (ui32 i = 3; i <= 6; i++)
  184. bigArtifacts.insert(i);
  185. //modableArtifacts = boost::assign::map_list_of(1, 1)(146,3)(147,3)(148,3)(150,3)(151,3)(152,3)(154,3)(156,2);
  186. }
  187. CArtHandler::~CArtHandler()
  188. {
  189. for (std::vector< ConstTransitivePtr<CArtifact> >::iterator it = artifacts.begin(); it != artifacts.end(); ++it)
  190. {
  191. delete (*it)->constituents;
  192. delete (*it)->constituentOf;
  193. }
  194. }
  195. void CArtHandler::loadArtifacts(bool onlyTxt)
  196. {
  197. std::vector<ui16> slots;
  198. slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
  199. static std::map<char, CArtifact::EartClass> classes =
  200. map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
  201. std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
  202. int it=0;
  203. for(int i=0; i<2; ++i)
  204. {
  205. loadToIt(dump,buf,it,3);
  206. }
  207. VLC->generaltexth->artifNames.resize(GameConstants::ARTIFACTS_QUANTITY);
  208. VLC->generaltexth->artifDescriptions.resize(GameConstants::ARTIFACTS_QUANTITY);
  209. std::map<ui32,ui8>::iterator itr;
  210. for (int i=0; i<GameConstants::ARTIFACTS_QUANTITY; i++)
  211. {
  212. CArtifact *art = new CArtifact();
  213. CArtifact &nart = *art;
  214. nart.id=i;
  215. loadToIt(VLC->generaltexth->artifNames[i],buf,it,4);
  216. loadToIt(pom,buf,it,4);
  217. nart.price=atoi(pom.c_str());
  218. nart.possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
  219. nart.possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
  220. for(int j=0;j<slots.size();j++)
  221. {
  222. loadToIt(pom,buf,it,4);
  223. if(pom.size() && pom[0]=='x')
  224. nart.possibleSlots[ArtBearer::HERO].push_back(slots[j]);
  225. }
  226. loadToIt(pom,buf,it,4);
  227. nart.aClass = classes[pom[0]];
  228. //load description and remove quotation marks
  229. std::string &desc = VLC->generaltexth->artifDescriptions[i];
  230. loadToIt(desc,buf,it,3);
  231. if(desc[0] == '\"' && desc[desc.size()-1] == '\"')
  232. desc = desc.substr(1,desc.size()-2);
  233. if(onlyTxt)
  234. continue;
  235. // Fill in information about combined artifacts. Should perhaps be moved to a config file?
  236. nart.constituentOf = NULL;
  237. switch (nart.id)
  238. {
  239. case 129: // Angelic Alliance
  240. nart.constituents = new std::vector<ui32>();
  241. *nart.constituents += 31, 32, 33, 34, 35, 36;
  242. break;
  243. case 130: // Cloak of the Undead King
  244. nart.constituents = new std::vector<ui32>();
  245. *nart.constituents += 54, 55, 56;
  246. break;
  247. case 131: // Elixir of Life
  248. nart.constituents = new std::vector<ui32>();
  249. *nart.constituents += 94, 95, 96;
  250. break;
  251. case 132: // Armor of the Damned
  252. nart.constituents = new std::vector<ui32>();
  253. *nart.constituents += 8, 14, 20, 26;
  254. break;
  255. case 133: // Statue of Legion
  256. nart.constituents = new std::vector<ui32>();
  257. *nart.constituents += 118, 119, 120, 121, 122;
  258. break;
  259. case 134: // Power of the Dragon Father
  260. nart.constituents = new std::vector<ui32>();
  261. *nart.constituents += 37, 38, 39, 40, 41, 42, 43, 44, 45;
  262. break;
  263. case 135: // Titan's Thunder
  264. nart.constituents = new std::vector<ui32>();
  265. *nart.constituents += 12, 18, 24, 30;
  266. break;
  267. case 136: // Admiral's Hat
  268. nart.constituents = new std::vector<ui32>();
  269. *nart.constituents += 71, 123;
  270. break;
  271. case 137: // Bow of the Sharpshooter
  272. nart.constituents = new std::vector<ui32>();
  273. *nart.constituents += 60, 61, 62;
  274. break;
  275. case 138: // Wizards' Well
  276. nart.constituents = new std::vector<ui32>();
  277. *nart.constituents += 73, 74, 75;
  278. break;
  279. case 139: // Ring of the Magi
  280. nart.constituents = new std::vector<ui32>();
  281. *nart.constituents += 76, 77, 78;
  282. break;
  283. case 140: // Cornucopia
  284. nart.constituents = new std::vector<ui32>();
  285. *nart.constituents += 109, 110, 111, 113;
  286. break;
  287. // TODO: WoG combinationals
  288. default:
  289. nart.constituents = NULL;
  290. break;
  291. }
  292. artifacts.push_back(&nart);
  293. }
  294. sortArts();
  295. if(onlyTxt)
  296. return;
  297. addBonuses();
  298. // Populate reverse mappings of combinational artifacts.
  299. BOOST_FOREACH(CArtifact *artifact, artifacts)
  300. {
  301. if (artifact->constituents != NULL)
  302. {
  303. BOOST_FOREACH(ui32 constituentID, *artifact->constituents)
  304. {
  305. if (artifacts[constituentID]->constituentOf == NULL)
  306. artifacts[constituentID]->constituentOf = new std::vector<ui32>();
  307. artifacts[constituentID]->constituentOf->push_back(artifact->id);
  308. }
  309. }
  310. }
  311. }
  312. int CArtHandler::convertMachineID(int id, bool creToArt )
  313. {
  314. int dif = 142;
  315. if(creToArt)
  316. {
  317. switch (id)
  318. {
  319. case 147:
  320. dif--;
  321. break;
  322. case 148:
  323. dif++;
  324. break;
  325. }
  326. dif = -dif;
  327. }
  328. else
  329. {
  330. switch (id)
  331. {
  332. case 6:
  333. dif--;
  334. break;
  335. case 5:
  336. dif++;
  337. break;
  338. }
  339. }
  340. return id + dif;
  341. }
  342. void CArtHandler::sortArts()
  343. {
  344. //for (int i=0; i<allowedArtifacts.size(); ++i) //do 144, bo nie chcemy bzdurek
  345. //{
  346. // switch (allowedArtifacts[i]->aClass)
  347. // {
  348. // case CArtifact::ART_TREASURE:
  349. // treasures.push_back(allowedArtifacts[i]);
  350. // break;
  351. // case CArtifact::ART_MINOR:
  352. // minors.push_back(allowedArtifacts[i]);
  353. // break;
  354. // case CArtifact::ART_MAJOR:
  355. // majors.push_back(allowedArtifacts[i]);
  356. // break;
  357. // case CArtifact::ART_RELIC:
  358. // relics.push_back(allowedArtifacts[i]);
  359. // break;
  360. // }
  361. //}
  362. }
  363. void CArtHandler::erasePickedArt (si32 id)
  364. {
  365. std::vector<CArtifact*>* ptr;
  366. CArtifact *art = artifacts[id];
  367. switch (art->aClass)
  368. {
  369. case CArtifact::ART_TREASURE:
  370. ptr = &treasures;
  371. break;
  372. case CArtifact::ART_MINOR:
  373. ptr = &minors;
  374. break;
  375. case CArtifact::ART_MAJOR:
  376. ptr = &majors;
  377. break;
  378. case CArtifact::ART_RELIC:
  379. ptr = &relics;
  380. break;
  381. default: //special artifacts should not be erased
  382. return;
  383. }
  384. ptr->erase (std::find(ptr->begin(), ptr->end(), art)); //remove the artifact from available list
  385. }
  386. ui16 CArtHandler::getRandomArt(int flags)
  387. {
  388. std::vector<ConstTransitivePtr<CArtifact> > out;
  389. getAllowed(out, flags);
  390. ui16 id = out[ran() % out.size()]->id;
  391. erasePickedArt (id);
  392. return id;
  393. }
  394. ui16 CArtHandler::getArtSync (ui32 rand, int flags)
  395. {
  396. std::vector<ConstTransitivePtr<CArtifact> > out;
  397. getAllowed(out, flags);
  398. CArtifact *art = out[rand % out.size()];
  399. return art->id;
  400. }
  401. void CArtHandler::getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags)
  402. {
  403. if (flags & CArtifact::ART_TREASURE)
  404. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  405. if (flags & CArtifact::ART_MINOR)
  406. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  407. if (flags & CArtifact::ART_MAJOR)
  408. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  409. if (flags & CArtifact::ART_RELIC)
  410. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  411. if (!out.size()) //no artifact of specified rarity, we need to take another one
  412. {
  413. getAllowedArts (out, &treasures, CArtifact::ART_TREASURE);
  414. getAllowedArts (out, &minors, CArtifact::ART_MINOR);
  415. getAllowedArts (out, &majors, CArtifact::ART_MAJOR);
  416. getAllowedArts (out, &relics, CArtifact::ART_RELIC);
  417. }
  418. if (!out.size()) //no arts are available at all
  419. {
  420. out.resize (64);
  421. std::fill_n (out.begin(), 64, artifacts[2]); //Give Grail - this can't be banned (hopefully)
  422. }
  423. }
  424. void CArtHandler::getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag)
  425. {
  426. if (arts->empty()) //restock available arts
  427. {
  428. for (int i = 0; i < allowedArtifacts.size(); ++i)
  429. {
  430. if (allowedArtifacts[i]->aClass == flag)
  431. arts->push_back(allowedArtifacts[i]);
  432. }
  433. }
  434. for (int i = 0; i < arts->size(); ++i)
  435. {
  436. CArtifact *art = (*arts)[i];
  437. out.push_back(art);
  438. }
  439. }
  440. void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int subtype, int valType, ILimiter * limiter, int additionalInfo)
  441. {
  442. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
  443. added->additionalInfo = additionalInfo;
  444. added->valType = valType;
  445. added->limiter.reset(limiter);
  446. if(type == Bonus::MORALE || type == Bonus::LUCK)
  447. added->description = artifacts[aid]->Name() + (val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(val);
  448. else
  449. added->description = artifacts[aid]->Name();
  450. artifacts[aid]->addNewBonus(added);
  451. }
  452. void CArtHandler::giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator /*= NULL*/, int additionalInfo)
  453. {
  454. Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
  455. added->additionalInfo = additionalInfo;
  456. added->valType = Bonus::BASE_NUMBER;
  457. added->propagator.reset(propagator);
  458. if(type == Bonus::MORALE || type == Bonus::LUCK)
  459. added->description = artifacts[aid]->Name() + (val > 0 ? " +" : " ") + boost::lexical_cast<std::string>(val);
  460. else
  461. added->description = artifacts[aid]->Name();
  462. artifacts[aid]->addNewBonus(added);
  463. }
  464. void CArtHandler::makeItCreatureArt (int aid, bool onlyCreature /*=true*/)
  465. {
  466. CArtifact *a = artifacts[aid];
  467. if (onlyCreature)
  468. {
  469. a->possibleSlots[ArtBearer::HERO].clear();
  470. }
  471. a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
  472. };
  473. void CArtHandler::addBonuses()
  474. {
  475. #define ART_PRIM_SKILL(ID, whichSkill, val) giveArtBonus(ID,Bonus::PRIMARY_SKILL,val,whichSkill)
  476. #define ART_MORALE(ID, val) giveArtBonus(ID,Bonus::MORALE,val)
  477. #define ART_LUCK(ID, val) giveArtBonus(ID,Bonus::LUCK,val)
  478. #define ART_MORALE_AND_LUCK(ID, val) giveArtBonus(ID,Bonus::MORALE_AND_LUCK,val)
  479. #define ART_ALL_PRIM_SKILLS(ID, val) ART_PRIM_SKILL(ID,0,val); ART_PRIM_SKILL(ID,1,val); ART_PRIM_SKILL(ID,2,val); ART_PRIM_SKILL(ID,3,val)
  480. #define ART_ATTACK_AND_DEFENSE(ID, val) ART_PRIM_SKILL(ID,0,val); ART_PRIM_SKILL(ID,1,val)
  481. #define ART_POWER_AND_KNOWLEDGE(ID, val) ART_PRIM_SKILL(ID,2,val); ART_PRIM_SKILL(ID,3,val)
  482. //Attack bonus artifacts (Weapons)
  483. ART_PRIM_SKILL(7,0,+2); //Centaur Axe
  484. ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight
  485. ART_PRIM_SKILL(9,0,+4); //Greater Gnoll's Flail
  486. ART_PRIM_SKILL(10,0,+5); //Ogre's Club of Havoc
  487. ART_PRIM_SKILL(11,0,+6); //Sword of Hellfire
  488. ART_PRIM_SKILL(12,0,+12); //Titan's Gladius
  489. ART_PRIM_SKILL(12,1,-3); //Titan's Gladius
  490. //Defense bonus artifacts (Shields)
  491. ART_PRIM_SKILL(13,1,+2); //Shield of the Dwarven Lords
  492. ART_PRIM_SKILL(14,1,+3); //Shield of the Yawning Dead
  493. ART_PRIM_SKILL(15,1,+4); //Buckler of the Gnoll King
  494. ART_PRIM_SKILL(16,1,+5); //Targ of the Rampaging Ogre
  495. ART_PRIM_SKILL(17,1,+6); //Shield of the Damned
  496. ART_PRIM_SKILL(18,1,+12); //Sentinel's Shield
  497. ART_PRIM_SKILL(18,0,-3); //Sentinel's Shield
  498. //Knowledge bonus artifacts (Helmets)
  499. ART_PRIM_SKILL(19,3,+1); //Helm of the Alabaster Unicorn
  500. ART_PRIM_SKILL(20,3,+2); //Skull Helmet
  501. ART_PRIM_SKILL(21,3,+3); //Helm of Chaos
  502. ART_PRIM_SKILL(22,3,+4); //Crown of the Supreme Magi
  503. ART_PRIM_SKILL(23,3,+5); //Hellstorm Helmet
  504. ART_PRIM_SKILL(24,3,+10); //Thunder Helmet
  505. ART_PRIM_SKILL(24,2,-2); //Thunder Helmet
  506. //Spell power bonus artifacts (Armours)
  507. ART_PRIM_SKILL(25,2,+1); //Breastplate of Petrified Wood
  508. ART_PRIM_SKILL(26,2,+2); //Rib Cage
  509. ART_PRIM_SKILL(27,2,+3); //Scales of the Greater Basilisk
  510. ART_PRIM_SKILL(28,2,+4); //Tunic of the Cyclops King
  511. ART_PRIM_SKILL(29,2,+5); //Breastplate of Brimstone
  512. ART_PRIM_SKILL(30,2,+10); //Titan's Cuirass
  513. ART_PRIM_SKILL(30,3,-2); //Titan's Cuirass
  514. //All primary skills (various)
  515. ART_ALL_PRIM_SKILLS(31,+1); //Armor of Wonder
  516. ART_ALL_PRIM_SKILLS(32,+2); //Sandals of the Saint
  517. ART_ALL_PRIM_SKILLS(33,+3); //Celestial Necklace of Bliss
  518. ART_ALL_PRIM_SKILLS(34,+4); //Lion's Shield of Courage
  519. ART_ALL_PRIM_SKILLS(35,+5); //Sword of Judgement
  520. ART_ALL_PRIM_SKILLS(36,+6); //Helm of Heavenly Enlightenment
  521. //Attack and Defense (various)
  522. ART_ATTACK_AND_DEFENSE(37,+1); //Quiet Eye of the Dragon
  523. ART_ATTACK_AND_DEFENSE(38,+2); //Red Dragon Flame Tongue
  524. ART_ATTACK_AND_DEFENSE(39,+3); //Dragon Scale Shield
  525. ART_ATTACK_AND_DEFENSE(40,+4); //Dragon Scale Armor
  526. //Spell power and Knowledge (various)
  527. ART_POWER_AND_KNOWLEDGE(41,+1); //Dragonbone Greaves
  528. ART_POWER_AND_KNOWLEDGE(42,+2); //Dragon Wing Tabard
  529. ART_POWER_AND_KNOWLEDGE(43,+3); //Necklace of Dragonteeth
  530. ART_POWER_AND_KNOWLEDGE(44,+4); //Crown of Dragontooth
  531. //Luck and morale
  532. ART_MORALE(45,+1); //Still Eye of the Dragon
  533. ART_LUCK(45,+1); //Still Eye of the Dragon
  534. ART_LUCK(46,+1); //Clover of Fortune
  535. ART_LUCK(47,+1); //Cards of Prophecy
  536. ART_LUCK(48,+1); //Ladybird of Luck
  537. ART_MORALE(49,+1); //Badge of Courage -> +1 morale
  538. giveArtBonus(49,Bonus::MIND_IMMUNITY,0); //immunity to hostile mind spells:
  539. ART_MORALE(50,+1); //Crest of Valor
  540. ART_MORALE(51,+1); //Glyph of Gallantry
  541. giveArtBonus(52,Bonus::SIGHT_RADIOUS,+1);//Speculum
  542. giveArtBonus(53,Bonus::SIGHT_RADIOUS,+1);//Spyglass
  543. //necromancy bonus
  544. giveArtBonus(54,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Amulet of the Undertaker
  545. giveArtBonus(55,Bonus::SECONDARY_SKILL_PREMY,+10, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Vampire's Cowl
  546. giveArtBonus(56,Bonus::SECONDARY_SKILL_PREMY,+15, CGHeroInstance::NECROMANCY, Bonus::ADDITIVE_VALUE);//Dead Man's Boots
  547. giveArtBonus(57,Bonus::MAGIC_RESISTANCE,+5, 0);//Garniture of Interference
  548. giveArtBonus(58,Bonus::MAGIC_RESISTANCE,+10, 0);//Surcoat of Counterpoise
  549. giveArtBonus(59,Bonus::MAGIC_RESISTANCE,+15, 0);//Boots of Polarity
  550. //archery bonus
  551. giveArtBonus(60,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Bow of Elven Cherrywood
  552. giveArtBonus(61,Bonus::SECONDARY_SKILL_PREMY,+10,CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Bowstring of the Unicorn's Mane
  553. giveArtBonus(62,Bonus::SECONDARY_SKILL_PREMY,+15,CGHeroInstance::ARCHERY, Bonus::ADDITIVE_VALUE);//Angel Feather Arrows
  554. //eagle eye bonus
  555. giveArtBonus(63,Bonus::SECONDARY_SKILL_PREMY,+5, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Bird of Perception
  556. giveArtBonus(64,Bonus::SECONDARY_SKILL_PREMY,+10, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Stoic Watchman
  557. giveArtBonus(65,Bonus::SECONDARY_SKILL_PREMY,+15, CGHeroInstance::EAGLE_EYE, Bonus::ADDITIVE_VALUE);//Emblem of Cognizance
  558. //reducing cost of surrendering
  559. giveArtBonus(66,Bonus::SURRENDER_DISCOUNT,+10);//Statesman's Medal
  560. giveArtBonus(67,Bonus::SURRENDER_DISCOUNT,+10);//Diplomat's Ring
  561. giveArtBonus(68,Bonus::SURRENDER_DISCOUNT,+10);//Ambassador's Sash
  562. giveArtBonus(69,Bonus::STACKS_SPEED,+1);//Ring of the Wayfarer
  563. giveArtBonus(70,Bonus::LAND_MOVEMENT,+300);//Equestrian's Gloves
  564. giveArtBonus(71,Bonus::SEA_MOVEMENT,+1000);//Necklace of Ocean Guidance
  565. giveArtBonus(72,Bonus::FLYING_MOVEMENT, 0, 1);//Angel Wings
  566. giveArtBonus(73,Bonus::MANA_REGENERATION,+1);//Charm of Mana
  567. giveArtBonus(74,Bonus::MANA_REGENERATION,+2);//Talisman of Mana
  568. giveArtBonus(75,Bonus::MANA_REGENERATION,+3);//Mystic Orb of Mana
  569. giveArtBonus(76,Bonus::SPELL_DURATION,+1);//Collar of Conjuring
  570. giveArtBonus(77,Bonus::SPELL_DURATION,+2);//Ring of Conjuring
  571. giveArtBonus(78,Bonus::SPELL_DURATION,+3);//Cape of Conjuring
  572. giveArtBonus(79,Bonus::AIR_SPELL_DMG_PREMY,+50);//Orb of the Firmament
  573. giveArtBonus(80,Bonus::EARTH_SPELL_DMG_PREMY,+50);//Orb of Silt
  574. giveArtBonus(81,Bonus::FIRE_SPELL_DMG_PREMY,+50);//Orb of Tempestuous Fire
  575. giveArtBonus(82,Bonus::WATER_SPELL_DMG_PREMY,+50);//Orb of Driving Rain
  576. giveArtBonus(83,Bonus::LEVEL_SPELL_IMMUNITY,3,-1,Bonus::INDEPENDENT_MAX);//Recanter's Cloak
  577. giveArtBonus(84,Bonus::BLOCK_MORALE,0);//Spirit of Oppression
  578. giveArtBonus(85,Bonus::BLOCK_LUCK,0);//Hourglass of the Evil Hour
  579. giveArtBonus(86,Bonus::FIRE_SPELLS,0);//Tome of Fire Magic
  580. giveArtBonus(87,Bonus::AIR_SPELLS,0);//Tome of Air Magic
  581. giveArtBonus(88,Bonus::WATER_SPELLS,0);//Tome of Water Magic
  582. giveArtBonus(89,Bonus::EARTH_SPELLS,0);//Tome of Earth Magic
  583. giveArtBonus(90,Bonus::WATER_WALKING, 0, 1);//Boots of Levitation
  584. giveArtBonus(91,Bonus::NO_DISTANCE_PENALTY,0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));//Golden Bow
  585. giveArtBonus(91,Bonus::NO_WALL_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  586. giveArtBonus(92,Bonus::SPELL_IMMUNITY,0,35);//Sphere of Permanence
  587. giveArtBonus(93,Bonus::NEGATE_ALL_NATURAL_IMMUNITIES,0);//Orb of Vulnerability
  588. giveArtBonus(94,Bonus::STACK_HEALTH,+1);//Ring of Vitality
  589. giveArtBonus(95,Bonus::STACK_HEALTH,+1);//Ring of Life
  590. giveArtBonus(96,Bonus::STACK_HEALTH,+2);//Vial of Lifeblood
  591. giveArtBonus(97,Bonus::STACKS_SPEED,+1);//Necklace of Swiftness
  592. giveArtBonus(98,Bonus::LAND_MOVEMENT,+600);//Boots of Speed
  593. giveArtBonus(99,Bonus::STACKS_SPEED,+2);//Cape of Velocity
  594. giveArtBonus(100,Bonus::SPELL_IMMUNITY,0,59);//Pendant of Dispassion
  595. giveArtBonus(101,Bonus::SPELL_IMMUNITY,0,62);//Pendant of Second Sight
  596. giveArtBonus(102,Bonus::SPELL_IMMUNITY,0,42);//Pendant of Holiness
  597. giveArtBonus(103,Bonus::SPELL_IMMUNITY,0,24);//Pendant of Life
  598. giveArtBonus(104,Bonus::SPELL_IMMUNITY,0,25, 1, new HasAnotherBonusLimiter(Bonus::UNDEAD));//Pendant of Death does not display info for living stacks
  599. giveArtBonus(105,Bonus::SPELL_IMMUNITY,0,60);//Pendant of Free Will
  600. giveArtBonus(106,Bonus::SPELL_IMMUNITY,0,17);//Pendant of Negativity
  601. giveArtBonus(107,Bonus::SPELL_IMMUNITY,0,61);//Pendant of Total Recall
  602. giveArtBonus(108,Bonus::MORALE,+3);//Pendant of Courage
  603. giveArtBonus(108,Bonus::LUCK,+3);//Pendant of Courage
  604. giveArtBonus(109,Bonus::GENERATE_RESOURCE,+1,4); //Everflowing Crystal Cloak
  605. giveArtBonus(110,Bonus::GENERATE_RESOURCE,+1,5); //Ring of Infinite Gems
  606. giveArtBonus(111,Bonus::GENERATE_RESOURCE,+1,1); //Everpouring Vial of Mercury
  607. giveArtBonus(112,Bonus::GENERATE_RESOURCE,+1,2); //Inexhaustible Cart of Ore
  608. giveArtBonus(113,Bonus::GENERATE_RESOURCE,+1,3); //Eversmoking Ring of Sulfur
  609. giveArtBonus(114,Bonus::GENERATE_RESOURCE,+1,0); //Inexhaustible Cart of Lumber
  610. giveArtBonus(115,Bonus::GENERATE_RESOURCE,+1000, Res::GOLD); //Endless Sack of Gold
  611. giveArtBonus(116,Bonus::GENERATE_RESOURCE,+750, Res::GOLD); //Endless Bag of Gold
  612. giveArtBonus(117,Bonus::GENERATE_RESOURCE,+500, Res::GOLD); //Endless Purse of Gold
  613. giveArtBonus(118,Bonus::CREATURE_GROWTH,+5,1, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Legs of Legion
  614. giveArtBonus(119,Bonus::CREATURE_GROWTH,+4,2, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Loins of Legion
  615. giveArtBonus(120,Bonus::CREATURE_GROWTH,+3,3, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Torso of Legion
  616. giveArtBonus(121,Bonus::CREATURE_GROWTH,+2,4, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Arms of Legion
  617. giveArtBonus(122,Bonus::CREATURE_GROWTH,+1,5, new CPropagatorNodeType(CBonusSystemNode::TOWN_AND_VISITOR)); //Head of Legion
  618. //Sea Captain's Hat
  619. giveArtBonus(123,Bonus::WHIRLPOOL_PROTECTION,0);
  620. giveArtBonus(123,Bonus::SEA_MOVEMENT,+500);
  621. giveArtBonus(123,Bonus::SPELL,3,0, Bonus::INDEPENDENT_MAX);
  622. giveArtBonus(123,Bonus::SPELL,3,1, Bonus::INDEPENDENT_MAX);
  623. giveArtBonus(124,Bonus::SPELLS_OF_LEVEL,3,1); //Spellbinder's Hat
  624. giveArtBonus(125,Bonus::ENEMY_CANT_ESCAPE,0); //Shackles of War
  625. giveArtBonus(126,Bonus::LEVEL_SPELL_IMMUNITY,GameConstants::SPELL_LEVELS,-1,Bonus::INDEPENDENT_MAX);//Orb of Inhibition
  626. //vial of dragon blood
  627. giveArtBonus(127, Bonus::PRIMARY_SKILL, +5, PrimarySkill::ATTACK, Bonus::BASE_NUMBER, new HasAnotherBonusLimiter(Bonus::DRAGON_NATURE));
  628. giveArtBonus(127, Bonus::PRIMARY_SKILL, +5, PrimarySkill::DEFENSE, Bonus::BASE_NUMBER, new HasAnotherBonusLimiter(Bonus::DRAGON_NATURE));
  629. //Armageddon's Blade
  630. giveArtBonus(128, Bonus::SPELL, 3, 26, Bonus::INDEPENDENT_MAX);
  631. giveArtBonus(128, Bonus::SPELL_IMMUNITY,0, 26);
  632. ART_ATTACK_AND_DEFENSE(128, +3);
  633. ART_PRIM_SKILL(128, 2, +3);
  634. ART_PRIM_SKILL(128, 3, +6);
  635. //Angelic Alliance
  636. giveArtBonus(129, Bonus::NONEVIL_ALIGNMENT_MIX, 0);
  637. giveArtBonus(129, Bonus::OPENING_BATTLE_SPELL, 10, 48); // Prayer
  638. //Cloak of the Undead King
  639. giveArtBonus(130, Bonus::IMPROVED_NECROMANCY, 0);
  640. //Elixir of Life
  641. giveArtBonus(131, Bonus::STACK_HEALTH, +25, -1, Bonus::PERCENT_TO_BASE);
  642. giveArtBonus(131, Bonus::HP_REGENERATION, +50);
  643. //Armor of the Damned
  644. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 54); // Slow
  645. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 47); // Disrupting Ray
  646. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 45); // Weakness
  647. giveArtBonus(132, Bonus::OPENING_BATTLE_SPELL, 50, 52); // Misfortune
  648. // Statue of Legion - gives only 50% growth
  649. giveArtBonus(133, Bonus::CREATURE_GROWTH_PERCENT, 50, -1, new CPropagatorNodeType(CBonusSystemNode::PLAYER));
  650. //Power of the Dragon Father
  651. giveArtBonus(134, Bonus::LEVEL_SPELL_IMMUNITY, 4, -1, Bonus::INDEPENDENT_MAX);
  652. //Titan's Thunder
  653. giveArtBonus(135, Bonus::SPELL, 3, 57);
  654. //Admiral's Hat
  655. giveArtBonus(136, Bonus::FREE_SHIP_BOARDING, 0);
  656. //Bow of the Sharpshooter
  657. giveArtBonus(137, Bonus::NO_DISTANCE_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  658. giveArtBonus(137, Bonus::NO_WALL_PENALTY, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  659. giveArtBonus(137, Bonus::FREE_SHOOTING, 0, 0, 0, new HasAnotherBonusLimiter(Bonus::SHOOTER));
  660. //Wizard's Well
  661. giveArtBonus(138, Bonus::FULL_MANA_REGENERATION, 0);
  662. //Ring of the Magi
  663. giveArtBonus(139, Bonus::SPELL_DURATION, +50);
  664. //Cornucopia
  665. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::MERCURY);
  666. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::SULFUR);
  667. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::CRYSTAL);
  668. giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::GEMS);
  669. //Stack artifact test
  670. if (GameConstants::STACK_ARTIFACT)
  671. {
  672. makeItCreatureArt(141);
  673. makeItCreatureArt(142);
  674. makeItCreatureArt(143);
  675. makeItCreatureArt(156);
  676. //Magic Wand
  677. giveArtBonus(141, Bonus::CASTS, 10);
  678. giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::IMPLOSION);
  679. giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::FIREBALL);
  680. giveArtBonus(141, Bonus::RANDOM_SPELLCASTER, 0);
  681. giveArtBonus(141, Bonus::DAEMON_SUMMONING, 10, 63); //rise vampire lords
  682. giveArtBonus(141, Bonus::ENCHANTER, 0, Spells::LIGHTNING_BOLT, NULL, 2);
  683. giveArtBonus(141, Bonus::REBIRTH, 1, 1);
  684. giveArtBonus(141, Bonus::MANA_DRAIN, 10);
  685. giveArtBonus(141, Bonus::HEALER, 25);
  686. artifacts[141].get()->setDescription ("Casts Implosion / Fireball, random Genie spell, summons Vampire Lords from corpses, casts Lighthning Bolt every 2 turns, rebirths at least one creature, drains enemy mana and heals");
  687. //Tower Arrow
  688. giveArtBonus(142, Bonus::NO_DISTANCE_PENALTY, 0);
  689. giveArtBonus(142, Bonus::ADDITIONAL_ATTACK, 2);
  690. giveArtBonus(142, Bonus::SPELL_LIKE_ATTACK, 1, Spells::INFERNO);
  691. giveArtBonus(142, Bonus::CATAPULT, 0);
  692. giveArtBonus(142, Bonus::ACID_BREATH, 20);
  693. giveArtBonus(142, Bonus::SHOTS, 200, 0, Bonus::PERCENT_TO_BASE);
  694. giveArtBonus(142, Bonus::SPELL_BEFORE_ATTACK, 1, Spells::AGE, NULL, 50);
  695. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::BERSERK, NULL, 50);
  696. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::POISON, NULL, 50);
  697. giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::DISRUPTING_RAY, NULL, 50);
  698. artifacts[142].get()->setDescription ("Tripple shots, tripple attack, casts various spells during attack, attacks have range of Inferno, no distance penalty, catapult");
  699. //Monster's Power
  700. giveArtBonus(143, Bonus::STACK_HEALTH, +100, -1, Bonus::PERCENT_TO_BASE);
  701. giveArtBonus(143, Bonus::CREATURE_DAMAGE, +100, 2, Bonus::PERCENT_TO_ALL);
  702. giveArtBonus(143, Bonus::HP_REGENERATION, 50);
  703. giveArtBonus(143, Bonus::NO_RETALIATION, 0);
  704. giveArtBonus(143, Bonus::RETURN_AFTER_STRIKE, 0);
  705. giveArtBonus(143, Bonus::ATTACKS_ALL_ADJACENT, 0);
  706. giveArtBonus(143, Bonus::SPELL_RESISTANCE_AURA, 100);
  707. giveArtBonus(143, Bonus::DIRECT_DAMAGE_IMMUNITY, 0);
  708. artifacts[143].get()->setDescription ("Double health, double max damage, hp regeneration, can't retaliate, return after strike, attack all around, 100% spell reisstance aura, immune to direct damage spells");
  709. //Warlord's banner
  710. giveArtBonus(156, Bonus::STACK_HEALTH, +2);
  711. artifacts[156].get()->setDescription ("+2 stack HP");
  712. }
  713. }
  714. void CArtHandler::clear()
  715. {
  716. BOOST_FOREACH(CArtifact *art, artifacts)
  717. delete art;
  718. artifacts.clear();
  719. clearHlpLists();
  720. }
  721. // /**
  722. // * Locally equips an artifact to a hero's worn slots. Unequips an already present artifact.
  723. // * Does not test if the operation is legal.
  724. // * @param artifWorn A hero's set of worn artifacts.
  725. // * @param bonuses Optional list of bonuses to update.
  726. // */
  727. // void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art ) const
  728. // {
  729. // unequipArtifact(artifWorn, slotID);
  730. //
  731. // if (art) //false when artifact is NULL -> slot set to empty
  732. // {
  733. // const CArtifact &artifact = *art;
  734. //
  735. // // Add artifact.
  736. // artifWorn[slotID] = art;
  737. //
  738. // // Add locks, in reverse order of being removed.
  739. // if (artifact.constituents != NULL)
  740. // {
  741. // bool destConsumed = false; // Determines which constituent that will be counted for together with the artifact.
  742. //
  743. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  744. // {
  745. // const CArtifact &constituent = *artifacts[constituentID];
  746. //
  747. // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
  748. // {
  749. // destConsumed = true;
  750. // }
  751. // else
  752. // {
  753. // BOOST_FOREACH(ui16 slot, constituent.possibleSlots)
  754. // {
  755. // if (!vstd::contains(artifWorn, slot))
  756. // {
  757. // artifWorn[slot] = VLC->arth->artifacts[145]; //lock
  758. // break;
  759. // }
  760. // }
  761. // }
  762. // }
  763. // }
  764. // }
  765. // }
  766. //
  767. // /**
  768. // * Locally unequips an artifact from a hero's worn slots.
  769. // * Does not test if the operation is legal.
  770. // * @param artifWorn A hero's set of worn artifacts.
  771. // * @param bonuses Optional list of bonuses to update.
  772. // */
  773. // void CArtHandler::unequipArtifact(std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
  774. // {
  775. // if (!vstd::contains(artifWorn, slotID))
  776. // return;
  777. //
  778. // const CArtifact &artifact = *artifWorn[slotID];
  779. //
  780. // // Remove artifact, if it's not already removed.
  781. // artifWorn.erase(slotID);
  782. //
  783. // // Remove locks, in reverse order of being added.
  784. // if (artifact.constituents != NULL)
  785. // {
  786. // bool destConsumed = false;
  787. //
  788. // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
  789. // {
  790. // const CArtifact &constituent = *artifacts[constituentID];
  791. //
  792. // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
  793. // {
  794. // destConsumed = true;
  795. // }
  796. // else
  797. // {
  798. // BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots)
  799. // {
  800. // if (vstd::contains(artifWorn, slot) && artifWorn[slot]->id == 145)
  801. // {
  802. // artifWorn.erase(slot);
  803. // break;
  804. // }
  805. // }
  806. // }
  807. // }
  808. // }
  809. // }
  810. void CArtHandler::clearHlpLists()
  811. {
  812. treasures.clear();
  813. minors.clear();
  814. majors.clear();
  815. relics.clear();
  816. }
  817. void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
  818. {
  819. allowedArtifacts.clear();
  820. clearHlpLists();
  821. for (int i=0; i<144; ++i) //yes, 144
  822. {
  823. if (allowed[i])
  824. allowedArtifacts.push_back(artifacts[i]);
  825. }
  826. }
  827. CArtifactInstance::CArtifactInstance()
  828. {
  829. init();
  830. }
  831. CArtifactInstance::CArtifactInstance( CArtifact *Art)
  832. {
  833. init();
  834. setType(Art);
  835. }
  836. // CArtifactInstance::CArtifactInstance(int aid)
  837. // {
  838. // init();
  839. // setType(VLC->arth->artifacts[aid]);
  840. // }
  841. void CArtifactInstance::setType( CArtifact *Art )
  842. {
  843. artType = Art;
  844. attachTo(Art);
  845. }
  846. std::string CArtifactInstance::nodeName() const
  847. {
  848. return "Artifact instance of " + (artType ? artType->Name() : std::string("uninitialized")) + " type";
  849. }
  850. CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s)
  851. {
  852. CArtifactInstance *ret = new CArtifactInstance(VLC->arth->artifacts[1]);
  853. Bonus *b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, 1, s->id);
  854. ret->addNewBonus(b);
  855. return ret;
  856. }
  857. void CArtifactInstance::init()
  858. {
  859. id = -1;
  860. setNodeType(ARTIFACT_INSTANCE);
  861. }
  862. int CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const
  863. {
  864. BOOST_FOREACH(ui16 slot, artType->possibleSlots[h->bearerType()])
  865. {
  866. if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
  867. {
  868. //we've found a free suitable slot.
  869. return slot;
  870. }
  871. }
  872. //if haven't find proper slot, use backpack
  873. return firstBackpackSlot(h);
  874. }
  875. int CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
  876. {
  877. if(!artType->isBig()) //discard big artifact
  878. return GameConstants::BACKPACK_START + h->artifactsInBackpack.size();
  879. return -1;
  880. }
  881. bool CArtifactInstance::canBePutAt(const ArtifactLocation al, bool assumeDestRemoved /*= false*/) const
  882. {
  883. return canBePutAt(al.getHolderArtSet(), al.slot, assumeDestRemoved);
  884. }
  885. bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  886. {
  887. if(slot >= GameConstants::BACKPACK_START)
  888. {
  889. if(artType->isBig())
  890. return false;
  891. //TODO backpack limit
  892. return true;
  893. }
  894. if(!vstd::contains(artType->possibleSlots[artSet->bearerType()], slot))
  895. return false;
  896. return artSet->isPositionFree(slot, assumeDestRemoved);
  897. }
  898. void CArtifactInstance::putAt(ArtifactLocation al)
  899. {
  900. assert(canBePutAt(al));
  901. al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
  902. if(al.slot < GameConstants::BACKPACK_START)
  903. al.getHolderNode()->attachTo(this);
  904. }
  905. void CArtifactInstance::removeFrom(ArtifactLocation al)
  906. {
  907. assert(al.getHolderArtSet()->getArt(al.slot) == this);
  908. al.getHolderArtSet()->eraseArtSlot(al.slot);
  909. if(al.slot < GameConstants::BACKPACK_START)
  910. al.getHolderNode()->detachFrom(this);
  911. //TODO delete me?
  912. }
  913. bool CArtifactInstance::canBeDisassembled() const
  914. {
  915. return artType->constituents && artType->constituentOf->size();
  916. }
  917. std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
  918. {
  919. std::vector<const CArtifact *> ret;
  920. if(!artType->constituentOf //not a part of combined artifact
  921. || artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
  922. return ret;
  923. BOOST_FOREACH(ui32 possibleCombinedArt, *artType->constituentOf)
  924. {
  925. const CArtifact * const artifact = VLC->arth->artifacts[possibleCombinedArt];
  926. assert(artifact->constituents);
  927. bool possible = true;
  928. BOOST_FOREACH(ui32 constituentID, *artifact->constituents) //check if all constituents are available
  929. {
  930. if(!h->hasArt(constituentID, true)) //constituent must be equipped
  931. {
  932. possible = false;
  933. break;
  934. }
  935. }
  936. if(possible)
  937. ret.push_back(artifact);
  938. }
  939. return ret;
  940. }
  941. void CArtifactInstance::move(ArtifactLocation src, ArtifactLocation dst)
  942. {
  943. removeFrom(src);
  944. putAt(dst);
  945. }
  946. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(CArtifact *Art)
  947. {
  948. if(!Art->constituents)
  949. return new CArtifactInstance(Art);
  950. else
  951. {
  952. CCombinedArtifactInstance * ret = new CCombinedArtifactInstance(Art);
  953. ret->createConstituents();
  954. return ret;
  955. }
  956. }
  957. CArtifactInstance * CArtifactInstance::createNewArtifactInstance(int aid)
  958. {
  959. return createNewArtifactInstance(VLC->arth->artifacts[aid]);
  960. }
  961. void CArtifactInstance::deserializationFix()
  962. {
  963. setType(artType);
  964. }
  965. int CArtifactInstance::getGivenSpellID() const
  966. {
  967. const Bonus * b = getBonus(Selector::type(Bonus::SPELL));
  968. if(!b)
  969. {
  970. tlog3 << "Warning: " << nodeName() << " doesn't bear any spell!\n";
  971. return -1;
  972. }
  973. return b->subtype;
  974. }
  975. bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  976. {
  977. return supposedPart == this;
  978. }
  979. bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
  980. {
  981. bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
  982. if(!canMainArtifactBePlaced)
  983. return false; //no is no...
  984. if(slot >= GameConstants::BACKPACK_START)
  985. return true; //we can always remove combined art to the backapck
  986. assert(artType->constituents);
  987. std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
  988. //it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
  989. //so we remove from the list all constituents that are already present on dst hero in the form of locks
  990. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  991. {
  992. if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
  993. constituentsToBePlaced -= constituent;
  994. }
  995. //we iterate over all active slots and check if constituents fits them
  996. for (int i = 0; i < GameConstants::BACKPACK_START; i++)
  997. {
  998. for(std::vector<ConstituentInfo>::iterator art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
  999. {
  1000. if(art->art->canBePutAt(artSet, i, i == slot)) // i == al.slot because we can remove already worn artifact only from that slot that is our main destination
  1001. {
  1002. constituentsToBePlaced.erase(art);
  1003. break;
  1004. }
  1005. }
  1006. }
  1007. return constituentsToBePlaced.empty();
  1008. }
  1009. bool CCombinedArtifactInstance::canBeDisassembled() const
  1010. {
  1011. return true;
  1012. }
  1013. CCombinedArtifactInstance::CCombinedArtifactInstance(CArtifact *Art)
  1014. : CArtifactInstance(Art) //TODO: seems unued, but need to be written
  1015. {
  1016. }
  1017. CCombinedArtifactInstance::CCombinedArtifactInstance()
  1018. {
  1019. }
  1020. void CCombinedArtifactInstance::createConstituents()
  1021. {
  1022. assert(artType);
  1023. assert(artType->constituents);
  1024. BOOST_FOREACH(ui32 a, *artType->constituents)
  1025. {
  1026. addAsConstituent(CArtifactInstance::createNewArtifactInstance(a), -1);
  1027. }
  1028. }
  1029. void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, int slot)
  1030. {
  1031. assert(vstd::contains(*artType->constituents, art->artType->id));
  1032. assert(art->getParentNodes().size() == 1 && art->getParentNodes().front() == art->artType);
  1033. constituentsInfo.push_back(ConstituentInfo(art, slot));
  1034. attachTo(art);
  1035. }
  1036. void CCombinedArtifactInstance::putAt(ArtifactLocation al)
  1037. {
  1038. if(al.slot >= GameConstants::BACKPACK_START)
  1039. {
  1040. CArtifactInstance::putAt(al);
  1041. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1042. ci.slot = -1;
  1043. }
  1044. else
  1045. {
  1046. CArtifactInstance *mainConstituent = figureMainConstituent(al); //it'll be replaced with combined artifact, not a lock
  1047. CArtifactInstance::putAt(al); //puts combined art (this)
  1048. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1049. {
  1050. if(ci.art != mainConstituent)
  1051. {
  1052. const ArtifactLocation suggestedPos(al.artHolder, ci.slot);
  1053. const bool inActiveSlot = vstd::isbetween(ci.slot, 0, GameConstants::BACKPACK_START);
  1054. const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
  1055. int pos = -1;
  1056. if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
  1057. pos = ci.slot;
  1058. else
  1059. ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
  1060. assert(pos < GameConstants::BACKPACK_START);
  1061. al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
  1062. }
  1063. else
  1064. {
  1065. ci.slot = -1;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
  1071. {
  1072. if(al.slot >= GameConstants::BACKPACK_START)
  1073. {
  1074. CArtifactInstance::removeFrom(al);
  1075. }
  1076. else
  1077. {
  1078. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1079. {
  1080. if(ci.slot >= 0)
  1081. {
  1082. al.getHolderArtSet()->eraseArtSlot(ci.slot);
  1083. ci.slot = -1;
  1084. }
  1085. else
  1086. {
  1087. //main constituent
  1088. CArtifactInstance::removeFrom(al);
  1089. }
  1090. }
  1091. }
  1092. }
  1093. CArtifactInstance * CCombinedArtifactInstance::figureMainConstituent(const ArtifactLocation al)
  1094. {
  1095. CArtifactInstance *mainConstituent = NULL; //it'll be replaced with combined artifact, not a lock
  1096. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1097. if(ci.slot == al.slot)
  1098. mainConstituent = ci.art;
  1099. if(!mainConstituent)
  1100. {
  1101. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1102. {
  1103. if(vstd::contains(ci.art->artType->possibleSlots[al.getHolderArtSet()->bearerType()], al.slot))
  1104. {
  1105. mainConstituent = ci.art;
  1106. }
  1107. }
  1108. }
  1109. return mainConstituent;
  1110. }
  1111. void CCombinedArtifactInstance::deserializationFix()
  1112. {
  1113. BOOST_FOREACH(ConstituentInfo &ci, constituentsInfo)
  1114. attachTo(ci.art);
  1115. }
  1116. bool CCombinedArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
  1117. {
  1118. bool me = CArtifactInstance::isPart(supposedPart);
  1119. if(me)
  1120. return true;
  1121. //check for constituents
  1122. BOOST_FOREACH(const ConstituentInfo &constituent, constituentsInfo)
  1123. if(constituent.art == supposedPart)
  1124. return true;
  1125. return false;
  1126. }
  1127. CCombinedArtifactInstance::ConstituentInfo::ConstituentInfo(CArtifactInstance *Art /*= NULL*/, ui16 Slot /*= -1*/)
  1128. {
  1129. art = Art;
  1130. slot = Slot;
  1131. }
  1132. bool CCombinedArtifactInstance::ConstituentInfo::operator==(const ConstituentInfo &rhs) const
  1133. {
  1134. return art == rhs.art && slot == rhs.slot;
  1135. }
  1136. const CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/) const
  1137. {
  1138. if(const ArtSlotInfo *si = getSlot(pos))
  1139. {
  1140. if(si->artifact && (!excludeLocked || !si->locked))
  1141. return si->artifact;
  1142. }
  1143. return NULL;
  1144. }
  1145. CArtifactInstance* CArtifactSet::getArt(ui16 pos, bool excludeLocked /*= true*/)
  1146. {
  1147. return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
  1148. }
  1149. si32 CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) const
  1150. {
  1151. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1152. if(i->second.artifact->artType->id == aid)
  1153. return i->first;
  1154. if(onlyWorn)
  1155. return -1;
  1156. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1157. if(artifactsInBackpack[i].artifact->artType->id == aid)
  1158. return GameConstants::BACKPACK_START + i;
  1159. return -1;
  1160. }
  1161. si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
  1162. {
  1163. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1164. if(i->second.artifact == art)
  1165. return i->first;
  1166. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1167. if(artifactsInBackpack[i].artifact == art)
  1168. return GameConstants::BACKPACK_START + i;
  1169. return -1;
  1170. }
  1171. const CArtifactInstance * CArtifactSet::getArtByInstanceId(int artInstId) const
  1172. {
  1173. for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1174. if(i->second.artifact->id == artInstId)
  1175. return i->second.artifact;
  1176. for(int i = 0; i < artifactsInBackpack.size(); i++)
  1177. if(artifactsInBackpack[i].artifact->id == artInstId)
  1178. return artifactsInBackpack[i].artifact;
  1179. return NULL;
  1180. }
  1181. bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
  1182. {
  1183. return getArtPos(aid, onlyWorn) != -1;
  1184. }
  1185. const ArtSlotInfo * CArtifactSet::getSlot(ui16 pos) const
  1186. {
  1187. if(vstd::contains(artifactsWorn, pos))
  1188. return &artifactsWorn[pos];
  1189. if(pos >= ArtifactPosition::AFTER_LAST )
  1190. {
  1191. int backpackPos = (int)pos - GameConstants::BACKPACK_START;
  1192. if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
  1193. return NULL;
  1194. else
  1195. return &artifactsInBackpack[backpackPos];
  1196. }
  1197. return NULL;
  1198. }
  1199. bool CArtifactSet::isPositionFree(ui16 pos, bool onlyLockCheck /*= false*/) const
  1200. {
  1201. if(const ArtSlotInfo *s = getSlot(pos))
  1202. return (onlyLockCheck || !s->artifact) && !s->locked;
  1203. return true; //no slot means not used
  1204. }
  1205. si32 CArtifactSet::getArtTypeId(ui16 pos) const
  1206. {
  1207. const CArtifactInstance * const a = getArt(pos);
  1208. if(!a)
  1209. {
  1210. tlog2 << (dynamic_cast<const CGHeroInstance*>(this))->name << " has no artifact at " << pos << " (getArtTypeId)\n";
  1211. return -1;
  1212. }
  1213. return a->artType->id;
  1214. }
  1215. CArtifactSet::~CArtifactSet()
  1216. {
  1217. }
  1218. ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
  1219. {
  1220. assert(!vstd::contains(artifactsWorn, slot));
  1221. ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
  1222. ? artifactsWorn[slot]
  1223. : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
  1224. return ret;
  1225. }
  1226. void CArtifactSet::setNewArtSlot(ui16 slot, CArtifactInstance *art, bool locked)
  1227. {
  1228. ArtSlotInfo &asi = retreiveNewArtSlot(slot);
  1229. asi.artifact = art;
  1230. asi.locked = locked;
  1231. }
  1232. void CArtifactSet::eraseArtSlot(ui16 slot)
  1233. {
  1234. if(slot < GameConstants::BACKPACK_START)
  1235. {
  1236. artifactsWorn.erase(slot);
  1237. }
  1238. else
  1239. {
  1240. slot -= GameConstants::BACKPACK_START;
  1241. artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
  1242. }
  1243. }
  1244. void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
  1245. {
  1246. for(bmap<ui16, ArtSlotInfo>::iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
  1247. if(i->second.artifact && !i->second.locked)
  1248. node->attachTo(i->second.artifact);
  1249. }