CRmgTemplateZone.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. /*
  2. * CRmgTemplateZone.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 "CRmgTemplateZone.h"
  12. #include "../mapping/CMapEditManager.h"
  13. #include "../mapping/CMap.h"
  14. #include "../VCMI_Lib.h"
  15. #include "../CTownHandler.h"
  16. #include "../CCreatureHandler.h"
  17. #include "../CSpellHandler.h" //for choosing random spells
  18. class CMap;
  19. class CMapEditManager;
  20. CRmgTemplateZone::CTownInfo::CTownInfo() : townCount(0), castleCount(0), townDensity(0), castleDensity(0)
  21. {
  22. }
  23. int CRmgTemplateZone::CTownInfo::getTownCount() const
  24. {
  25. return townCount;
  26. }
  27. void CRmgTemplateZone::CTownInfo::setTownCount(int value)
  28. {
  29. if(value < 0)
  30. throw rmgException("Negative value for town count not allowed.");
  31. townCount = value;
  32. }
  33. int CRmgTemplateZone::CTownInfo::getCastleCount() const
  34. {
  35. return castleCount;
  36. }
  37. void CRmgTemplateZone::CTownInfo::setCastleCount(int value)
  38. {
  39. if(value < 0)
  40. throw rmgException("Negative value for castle count not allowed.");
  41. castleCount = value;
  42. }
  43. int CRmgTemplateZone::CTownInfo::getTownDensity() const
  44. {
  45. return townDensity;
  46. }
  47. void CRmgTemplateZone::CTownInfo::setTownDensity(int value)
  48. {
  49. if(value < 0)
  50. throw rmgException("Negative value for town density not allowed.");
  51. townDensity = value;
  52. }
  53. int CRmgTemplateZone::CTownInfo::getCastleDensity() const
  54. {
  55. return castleDensity;
  56. }
  57. void CRmgTemplateZone::CTownInfo::setCastleDensity(int value)
  58. {
  59. if(value < 0)
  60. throw rmgException("Negative value for castle density not allowed.");
  61. castleDensity = value;
  62. }
  63. CTileInfo::CTileInfo():nearestObjectDistance(INT_MAX), terrain(ETerrainType::WRONG)
  64. {
  65. occupied = ETileType::POSSIBLE; //all tiles are initially possible to place objects or passages
  66. }
  67. int CTileInfo::getNearestObjectDistance() const
  68. {
  69. return nearestObjectDistance;
  70. }
  71. void CTileInfo::setNearestObjectDistance(int value)
  72. {
  73. nearestObjectDistance = std::max(0, value); //never negative (or unitialized)
  74. }
  75. bool CTileInfo::shouldBeBlocked() const
  76. {
  77. return occupied == ETileType::BLOCKED;
  78. }
  79. bool CTileInfo::isBlocked() const
  80. {
  81. return occupied == ETileType::BLOCKED || occupied == ETileType::USED;
  82. }
  83. bool CTileInfo::isPossible() const
  84. {
  85. return occupied == ETileType::POSSIBLE;
  86. }
  87. bool CTileInfo::isFree() const
  88. {
  89. return occupied == ETileType::FREE;
  90. }
  91. void CTileInfo::setOccupied(ETileType::ETileType value)
  92. {
  93. occupied = value;
  94. }
  95. ETerrainType CTileInfo::getTerrainType() const
  96. {
  97. return terrain;
  98. }
  99. void CTileInfo::setTerrainType(ETerrainType value)
  100. {
  101. terrain = value;
  102. }
  103. CRmgTemplateZone::CRmgTemplateZone() : id(0), type(ETemplateZoneType::PLAYER_START), size(1),
  104. terrainType (ETerrainType::GRASS), townType(0), townsAreSameType(false), matchTerrainToTown(true), totalDensity(0),
  105. zoneMonsterStrength(EMonsterStrength::ZONE_NORMAL)
  106. {
  107. townTypes = getDefaultTownTypes();
  108. terrainTypes = getDefaultTerrainTypes();
  109. }
  110. TRmgTemplateZoneId CRmgTemplateZone::getId() const
  111. {
  112. return id;
  113. }
  114. void CRmgTemplateZone::setId(TRmgTemplateZoneId value)
  115. {
  116. if(value <= 0)
  117. throw rmgException(boost::to_string(boost::format("Zone %d id should be greater than 0.") %id));
  118. id = value;
  119. }
  120. ETemplateZoneType::ETemplateZoneType CRmgTemplateZone::getType() const
  121. {
  122. return type;
  123. }
  124. void CRmgTemplateZone::setType(ETemplateZoneType::ETemplateZoneType value)
  125. {
  126. type = value;
  127. }
  128. int CRmgTemplateZone::getSize() const
  129. {
  130. return size;
  131. }
  132. void CRmgTemplateZone::setSize(int value)
  133. {
  134. if(value <= 0)
  135. throw rmgException(boost::to_string(boost::format("Zone %d size needs to be greater than 0.") % id));
  136. size = value;
  137. }
  138. boost::optional<int> CRmgTemplateZone::getOwner() const
  139. {
  140. return owner;
  141. }
  142. void CRmgTemplateZone::setOwner(boost::optional<int> value)
  143. {
  144. if(!(*value >= 0 && *value <= PlayerColor::PLAYER_LIMIT_I))
  145. throw rmgException(boost::to_string(boost::format ("Owner of zone %d has to be in range 0 to max player count.") %id));
  146. owner = value;
  147. }
  148. const CRmgTemplateZone::CTownInfo & CRmgTemplateZone::getPlayerTowns() const
  149. {
  150. return playerTowns;
  151. }
  152. void CRmgTemplateZone::setPlayerTowns(const CTownInfo & value)
  153. {
  154. playerTowns = value;
  155. }
  156. const CRmgTemplateZone::CTownInfo & CRmgTemplateZone::getNeutralTowns() const
  157. {
  158. return neutralTowns;
  159. }
  160. void CRmgTemplateZone::setNeutralTowns(const CTownInfo & value)
  161. {
  162. neutralTowns = value;
  163. }
  164. bool CRmgTemplateZone::getTownsAreSameType() const
  165. {
  166. return townsAreSameType;
  167. }
  168. void CRmgTemplateZone::setTownsAreSameType(bool value)
  169. {
  170. townsAreSameType = value;
  171. }
  172. const std::set<TFaction> & CRmgTemplateZone::getTownTypes() const
  173. {
  174. return townTypes;
  175. }
  176. void CRmgTemplateZone::setTownTypes(const std::set<TFaction> & value)
  177. {
  178. townTypes = value;
  179. }
  180. std::set<TFaction> CRmgTemplateZone::getDefaultTownTypes() const
  181. {
  182. std::set<TFaction> defaultTowns;
  183. auto towns = VLC->townh->getDefaultAllowed();
  184. for(int i = 0; i < towns.size(); ++i)
  185. {
  186. if(towns[i]) defaultTowns.insert(i);
  187. }
  188. return defaultTowns;
  189. }
  190. bool CRmgTemplateZone::getMatchTerrainToTown() const
  191. {
  192. return matchTerrainToTown;
  193. }
  194. void CRmgTemplateZone::setMatchTerrainToTown(bool value)
  195. {
  196. matchTerrainToTown = value;
  197. }
  198. const std::set<ETerrainType> & CRmgTemplateZone::getTerrainTypes() const
  199. {
  200. return terrainTypes;
  201. }
  202. void CRmgTemplateZone::setTerrainTypes(const std::set<ETerrainType> & value)
  203. {
  204. assert(value.find(ETerrainType::WRONG) == value.end() && value.find(ETerrainType::BORDER) == value.end() &&
  205. value.find(ETerrainType::WATER) == value.end() && value.find(ETerrainType::ROCK) == value.end());
  206. terrainTypes = value;
  207. }
  208. std::set<ETerrainType> CRmgTemplateZone::getDefaultTerrainTypes() const
  209. {
  210. std::set<ETerrainType> terTypes;
  211. static const ETerrainType::EETerrainType allowedTerTypes[] = {ETerrainType::DIRT, ETerrainType::SAND, ETerrainType::GRASS, ETerrainType::SNOW,
  212. ETerrainType::SWAMP, ETerrainType::ROUGH, ETerrainType::SUBTERRANEAN, ETerrainType::LAVA};
  213. for (auto & allowedTerType : allowedTerTypes)
  214. terTypes.insert(allowedTerType);
  215. return terTypes;
  216. }
  217. void CRmgTemplateZone::setMinesAmount (TResource res, ui16 amount)
  218. {
  219. mines[res] = amount;
  220. }
  221. std::map<TResource, ui16> CRmgTemplateZone::getMinesInfo() const
  222. {
  223. return mines;
  224. }
  225. void CRmgTemplateZone::addConnection(TRmgTemplateZoneId otherZone)
  226. {
  227. connections.push_back (otherZone);
  228. }
  229. std::vector<TRmgTemplateZoneId> CRmgTemplateZone::getConnections() const
  230. {
  231. return connections;
  232. }
  233. void CRmgTemplateZone::setMonsterStrength (EMonsterStrength::EMonsterStrength val)
  234. {
  235. assert (vstd::iswithin(val, EMonsterStrength::ZONE_WEAK, EMonsterStrength::ZONE_STRONG));
  236. zoneMonsterStrength = val;
  237. }
  238. void CRmgTemplateZone::setTotalDensity (ui16 val)
  239. {
  240. totalDensity = val;
  241. }
  242. ui16 CRmgTemplateZone::getTotalDensity () const
  243. {
  244. return totalDensity;
  245. }
  246. void CRmgTemplateZone::addTreasureInfo(CTreasureInfo & info)
  247. {
  248. treasureInfo.push_back(info);
  249. }
  250. std::vector<CTreasureInfo> CRmgTemplateZone::getTreasureInfo()
  251. {
  252. return treasureInfo;
  253. }
  254. float3 CRmgTemplateZone::getCenter() const
  255. {
  256. return center;
  257. }
  258. void CRmgTemplateZone::setCenter(const float3 &f)
  259. {
  260. //limit boundaries to (0,1) square
  261. center = float3 (std::min(std::max(f.x, 0.f), 1.f), std::min(std::max(f.y, 0.f), 1.f), f.z);
  262. }
  263. bool CRmgTemplateZone::pointIsIn(int x, int y)
  264. {
  265. return true;
  266. }
  267. int3 CRmgTemplateZone::getPos() const
  268. {
  269. return pos;
  270. }
  271. void CRmgTemplateZone::setPos(const int3 &Pos)
  272. {
  273. pos = Pos;
  274. }
  275. void CRmgTemplateZone::addTile (const int3 &pos)
  276. {
  277. tileinfo.insert(pos);
  278. }
  279. std::set<int3> CRmgTemplateZone::getTileInfo () const
  280. {
  281. return tileinfo;
  282. }
  283. void CRmgTemplateZone::createBorder(CMapGenerator* gen)
  284. {
  285. for (auto tile : tileinfo)
  286. {
  287. gen->foreach_neighbour (tile, [this, gen](int3 &pos)
  288. {
  289. if (!vstd::contains(this->tileinfo, pos))
  290. {
  291. gen->foreach_neighbour (pos, [this, gen](int3 &pos)
  292. {
  293. if (gen->isPossible(pos))
  294. gen->setOccupied (pos, ETileType::BLOCKED);
  295. });
  296. }
  297. });
  298. }
  299. }
  300. void CRmgTemplateZone::fractalize(CMapGenerator* gen)
  301. {
  302. std::vector<int3> clearedTiles;
  303. std::set<int3> possibleTiles;
  304. std::set<int3> tilesToClear; //will be set clear
  305. std::set<int3> tilesToIgnore; //will be erased in this iteration
  306. const float minDistance = std::sqrt(totalDensity);
  307. for (auto tile : tileinfo)
  308. {
  309. if (gen->isFree(tile))
  310. clearedTiles.push_back(tile);
  311. else if (gen->isPossible(tile));
  312. possibleTiles.insert(tile);
  313. }
  314. if (clearedTiles.empty()) //this should come from zone connections
  315. {
  316. clearedTiles.push_back(pos); //zone center should be always clear
  317. }
  318. while (possibleTiles.size())
  319. {
  320. for (auto tileToMakePath : possibleTiles)
  321. {
  322. //find closest free tile
  323. float currentDistance = 1e10;
  324. int3 closestTile (-1,-1,-1);
  325. for (auto clearTile : clearedTiles)
  326. {
  327. float distance = tileToMakePath.dist2d(clearTile);
  328. if (distance < currentDistance)
  329. {
  330. currentDistance = distance;
  331. closestTile = clearTile;
  332. }
  333. if (currentDistance <= minDistance)
  334. {
  335. //this tile is close enough. Forget about it and check next one
  336. tilesToIgnore.insert (tileToMakePath);
  337. break;
  338. }
  339. }
  340. //if tiles is not close enough, make path to it
  341. if (currentDistance > minDistance)
  342. {
  343. crunchPath (gen, tileToMakePath, closestTile, id, &tilesToClear);
  344. break; //next iteration - use already cleared tiles
  345. }
  346. }
  347. for (auto tileToClear : tilesToClear)
  348. {
  349. //move cleared tiles from one set to another
  350. clearedTiles.push_back(tileToClear);
  351. vstd::erase_if_present(possibleTiles, tileToClear);
  352. }
  353. for (auto tileToClear : tilesToIgnore)
  354. {
  355. //these tiles are already connected, ignore them
  356. vstd::erase_if_present(possibleTiles, tileToClear);
  357. }
  358. if (tilesToClear.empty()) //nothing else can be done (?)
  359. break;
  360. tilesToClear.clear(); //empty this container
  361. tilesToIgnore.clear();
  362. }
  363. logGlobal->infoStream() << boost::format ("Zone %d subdivided fractally") %id;
  364. }
  365. bool CRmgTemplateZone::crunchPath (CMapGenerator* gen, const int3 &src, const int3 &dst, TRmgTemplateZoneId zone, std::set<int3>* clearedTiles)
  366. {
  367. /*
  368. make shortest path with free tiles, reachning dst or closest already free tile. Avoid blocks.
  369. do not leave zone border
  370. */
  371. bool result = false;
  372. bool end = false;
  373. int3 currentPos = src;
  374. float distance = currentPos.dist2dSQ (dst);
  375. while (!end)
  376. {
  377. if (currentPos == dst)
  378. {
  379. result = true;
  380. break;
  381. }
  382. auto lastDistance = distance;
  383. gen->foreach_neighbour (currentPos, [this, gen, &currentPos, dst, &distance, &result, &end, clearedTiles](int3 &pos)
  384. {
  385. if (!result) //not sure if lambda is worth it...
  386. {
  387. if (pos == dst)
  388. {
  389. result = true;
  390. end = true;
  391. }
  392. if (pos.dist2dSQ (dst) < distance)
  393. {
  394. if (!gen->isBlocked(pos))
  395. {
  396. if (vstd::contains (tileinfo, pos))
  397. {
  398. if (gen->isPossible(pos))
  399. {
  400. gen->setOccupied (pos, ETileType::FREE);
  401. if (clearedTiles)
  402. clearedTiles->insert(pos);
  403. currentPos = pos;
  404. distance = currentPos.dist2dSQ (dst);
  405. }
  406. else if (gen->isFree(pos))
  407. {
  408. end = true;
  409. result = true;
  410. }
  411. else
  412. throw rmgException(boost::to_string(boost::format("Tile %s of uknown type found on path") % pos()));
  413. }
  414. }
  415. }
  416. }
  417. });
  418. if (!(result || distance < lastDistance)) //we do not advance, use more avdnaced pathfinding algorithm?
  419. {
  420. logGlobal->warnStream() << boost::format ("No tile closer than %s found on path from %s to %s") %currentPos %src %dst;
  421. break;
  422. }
  423. }
  424. return result;
  425. }
  426. void CRmgTemplateZone::addRequiredObject(CGObjectInstance * obj, si32 strength)
  427. {
  428. requiredObjects.push_back(std::make_pair(obj, strength));
  429. }
  430. bool CRmgTemplateZone::addMonster(CMapGenerator* gen, int3 &pos, si32 strength)
  431. {
  432. //precalculate actual (randomized) monster strength based on this post
  433. //http://forum.vcmi.eu/viewtopic.php?p=12426#12426
  434. int mapMonsterStrength = gen->mapGenOptions->getMonsterStrength();
  435. int monsterStrength = zoneMonsterStrength + mapMonsterStrength - 1; //array index from 0 to 4
  436. static const int value1[] = {2500, 1500, 1000, 500, 0};
  437. static const int value2[] = {7500, 7500, 7500, 5000, 5000};
  438. static const float multiplier1[] = {0.5, 0.75, 1.0, 1.5, 1.5};
  439. static const float multiplier2[] = {0.5, 0.75, 1.0, 1.0, 1.5};
  440. int strength1 = std::max(0.f, (strength - value1[monsterStrength]) * multiplier1[monsterStrength]);
  441. int strength2 = std::max(0.f, (strength - value2[monsterStrength]) * multiplier2[monsterStrength]);
  442. strength = strength1 + strength2;
  443. if (strength < 2000)
  444. return false; //no guard at all
  445. CreatureID creId = CreatureID::NONE;
  446. int amount = 0;
  447. std::vector<CreatureID> possibleCreatures;
  448. for (auto cre : VLC->creh->creatures)
  449. {
  450. if (cre->special)
  451. continue;
  452. if ((cre->AIValue * (cre->ammMin + cre->ammMax) / 2 < strength) && (strength < cre->AIValue * 100)) //at least one full monster. size between minimum size of given stack and 100
  453. {
  454. possibleCreatures.push_back(cre->idNumber);
  455. }
  456. }
  457. if (possibleCreatures.size())
  458. {
  459. creId = *RandomGeneratorUtil::nextItem(possibleCreatures, gen->rand);
  460. amount = strength / VLC->creh->creatures[creId]->AIValue;
  461. if (amount >= 4)
  462. amount *= gen->rand.nextDouble(0.75, 1.25);
  463. }
  464. else //just pick any available creature
  465. {
  466. creId = CreatureID(132); //Azure Dragon
  467. amount = strength / VLC->creh->creatures[creId]->AIValue;
  468. }
  469. auto guard = new CGCreature();
  470. guard->ID = Obj::MONSTER;
  471. guard->subID = creId;
  472. auto hlp = new CStackInstance(creId, amount);
  473. //will be set during initialization
  474. guard->putStack(SlotID(0), hlp);
  475. placeObject(gen, guard, pos);
  476. return true;
  477. }
  478. bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
  479. {
  480. std::map<int3, CGObjectInstance *> treasures;
  481. std::set<int3> boundary;
  482. int3 guardPos (-1,-1,-1);
  483. int3 nextTreasurePos = pos;
  484. //default values
  485. int maxValue = 5000;
  486. int minValue = 1500;
  487. if (treasureInfo.size())
  488. {
  489. //roulette wheel
  490. int r = gen->rand.nextInt (1, totalDensity);
  491. for (auto t : treasureInfo)
  492. {
  493. if (r <= t.threshold)
  494. {
  495. maxValue = t.max;
  496. minValue = t.min;
  497. break;
  498. }
  499. }
  500. }
  501. int currentValue = 0;
  502. CGObjectInstance * object = nullptr;
  503. while (currentValue < minValue)
  504. {
  505. //TODO: this works only for 1-tile objects
  506. //make sure our shape is consistent
  507. treasures[nextTreasurePos] = nullptr;
  508. for (auto treasurePos : treasures)
  509. {
  510. gen->foreach_neighbour (treasurePos.first, [gen, &boundary](int3 pos)
  511. {
  512. boundary.insert(pos);
  513. });
  514. }
  515. for (auto treasurePos : treasures)
  516. {
  517. //leaving only boundary around objects
  518. vstd::erase_if_present (boundary, treasurePos.first);
  519. }
  520. for (auto tile : boundary)
  521. {
  522. //we can't extend boundary anymore
  523. if (!(gen->isBlocked(tile) || gen->isPossible(tile)))
  524. break;
  525. }
  526. int remaining = maxValue - currentValue;
  527. auto oi = getRandomObject(gen, remaining);
  528. object = oi.generateObject();
  529. if (!object)
  530. break;
  531. currentValue += oi.value;
  532. treasures[nextTreasurePos] = object;
  533. //now find place for next object
  534. int3 placeFound(-1,-1,-1);
  535. //FIXME: find out why teh following code causes crashes
  536. //std::vector<int3> boundaryVec(boundary.begin(), boundary.end());
  537. //RandomGeneratorUtil::randomShuffle(boundaryVec, gen->rand);
  538. //for (auto tile : boundaryVec)
  539. for (auto tile : boundary)
  540. {
  541. if (gen->isPossible(tile)) //we can place new treasure only on possible tile
  542. {
  543. bool here = true;
  544. gen->foreach_neighbour (tile, [gen, &here](int3 pos)
  545. {
  546. if (!(gen->isBlocked(pos) || gen->isPossible(pos)))
  547. here = false;
  548. });
  549. if (here)
  550. {
  551. placeFound = tile;
  552. break;
  553. }
  554. }
  555. }
  556. if (placeFound.valid())
  557. nextTreasurePos = placeFound;
  558. }
  559. if (treasures.size())
  560. {
  561. //find object closest to zone center, then con nect it to the middle of the zone
  562. int3 zoneCenter = getPos();
  563. int3 closestTile = int3(-1,-1,-1);
  564. float minDistance = 1e10;
  565. for (auto treasure : treasures)
  566. {
  567. if (zoneCenter.dist2d(treasure.first) < minDistance)
  568. {
  569. closestTile = treasure.first;
  570. minDistance = zoneCenter.dist2d(treasure.first);
  571. }
  572. }
  573. assert (closestTile.valid());
  574. if (!crunchPath (gen, closestTile, getPos(), id)) //make sure pile is connected to the middle of zone
  575. {
  576. for (auto treasure : treasures)
  577. {
  578. if (gen->isPossible(treasure.first))
  579. gen->setOccupied (treasure.first, ETileType::BLOCKED);
  580. }
  581. return true;
  582. }
  583. for (auto tile : boundary) //guard must be standing there
  584. {
  585. if (gen->isFree(tile)) //this tile could be already blocked, don't place a monster here
  586. {
  587. guardPos = tile;
  588. break;
  589. }
  590. }
  591. if (guardPos.valid())
  592. {
  593. for (auto treasure : treasures)
  594. {
  595. placeObject(gen, treasure.second, treasure.first - treasure.second->getVisitableOffset());
  596. }
  597. if (addMonster(gen, guardPos, currentValue))
  598. {//block only if the object is guarded
  599. for (auto tile : boundary)
  600. {
  601. if (gen->isPossible(tile))
  602. gen->setOccupied (tile, ETileType::BLOCKED);
  603. }
  604. }
  605. }
  606. else //we couldn't make a connection to this location, block it
  607. {
  608. for (auto treasure : treasures)
  609. {
  610. if (gen->isPossible(treasure.first))
  611. gen->setOccupied (treasure.first, ETileType::BLOCKED);
  612. }
  613. }
  614. return true;
  615. }
  616. else //we did not place eveyrthing successfully
  617. return false;
  618. }
  619. void CRmgTemplateZone::initTownType (CMapGenerator* gen)
  620. {
  621. if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
  622. {
  623. logGlobal->infoStream() << "Preparing playing zone";
  624. int player_id = *owner - 1;
  625. auto & playerInfo = gen->map->players[player_id];
  626. if (playerInfo.canAnyonePlay())
  627. {
  628. PlayerColor player(player_id);
  629. auto town = new CGTownInstance();
  630. town->ID = Obj::TOWN;
  631. townType = gen->mapGenOptions->getPlayersSettings().find(player)->second.getStartingTown();
  632. if(townType == CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
  633. townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand); // all possible towns, skip neutral
  634. town->subID = townType;
  635. town->tempOwner = player;
  636. town->builtBuildings.insert(BuildingID::FORT);
  637. town->builtBuildings.insert(BuildingID::DEFAULT);
  638. placeObject(gen, town, getPos() + town->getVisitableOffset()); //towns are big objects and should be centered around visitable position
  639. logGlobal->traceStream() << "Fill player info " << player_id;
  640. // Update player info
  641. playerInfo.allowedFactions.clear();
  642. playerInfo.allowedFactions.insert (townType);
  643. playerInfo.hasMainTown = true;
  644. playerInfo.posOfMainTown = town->pos - int3(2, 0, 0);
  645. playerInfo.generateHeroAtMainTown = true;
  646. //requiredObjects.push_back(town);
  647. }
  648. else
  649. {
  650. type = ETemplateZoneType::TREASURE;
  651. townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand);
  652. logGlobal->infoStream() << "Skipping this zone cause no player";
  653. }
  654. }
  655. else //no player
  656. {
  657. townType = *RandomGeneratorUtil::nextItem(VLC->townh->getAllowedFactions(), gen->rand);
  658. }
  659. }
  660. void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)
  661. {
  662. if (matchTerrainToTown)
  663. terrainType = VLC->townh->factions[townType]->nativeTerrain;
  664. else
  665. terrainType = *RandomGeneratorUtil::nextItem(terrainTypes, gen->rand);
  666. //paint zone with matching terrain
  667. std::vector<int3> tiles;
  668. for (auto tile : tileinfo)
  669. {
  670. tiles.push_back (tile);
  671. }
  672. gen->editManager->getTerrainSelection().setSelection(tiles);
  673. gen->editManager->drawTerrain(terrainType, &gen->rand);
  674. }
  675. bool CRmgTemplateZone::placeMines (CMapGenerator* gen)
  676. {
  677. std::vector<Res::ERes> required_mines;
  678. required_mines.push_back(Res::ERes::WOOD);
  679. required_mines.push_back(Res::ERes::ORE);
  680. static const Res::ERes woodOre[] = {Res::ERes::WOOD, Res::ERes::ORE};
  681. static const Res::ERes preciousResources[] = {Res::ERes::GEMS, Res::ERes::CRYSTAL, Res::ERes::MERCURY, Res::ERes::SULFUR};
  682. //TODO: factory / copy constructor?
  683. for (const auto & res : woodOre)
  684. {
  685. //TODO: these 2 should be close to town (within 12 tiles radius)
  686. for (int i = 0; i < mines[res]; i++)
  687. {
  688. auto mine = new CGMine();
  689. mine->ID = Obj::MINE;
  690. mine->subID = static_cast<si32>(res);
  691. mine->producedResource = res;
  692. mine->producedQuantity = mine->defaultResProduction();
  693. addRequiredObject(mine, 1500);
  694. }
  695. }
  696. for (const auto & res : preciousResources)
  697. {
  698. for (int i = 0; i < mines[res]; i++)
  699. {
  700. auto mine = new CGMine();
  701. mine->ID = Obj::MINE;
  702. mine->subID = static_cast<si32>(res);
  703. mine->producedResource = res;
  704. mine->producedQuantity = mine->defaultResProduction();
  705. addRequiredObject(mine, 3500);
  706. }
  707. }
  708. for (int i = 0; i < mines[Res::GOLD]; i++)
  709. {
  710. auto mine = new CGMine();
  711. mine->ID = Obj::MINE;
  712. mine->subID = static_cast<si32>(Res::GOLD);
  713. mine->producedResource = Res::GOLD;
  714. mine->producedQuantity = mine->defaultResProduction();
  715. addRequiredObject(mine, 7000);
  716. }
  717. return true;
  718. }
  719. bool CRmgTemplateZone::createRequiredObjects(CMapGenerator* gen)
  720. {
  721. logGlobal->infoStream() << "Creating required objects";
  722. for(const auto &obj : requiredObjects)
  723. {
  724. int3 pos;
  725. logGlobal->traceStream() << "Looking for place";
  726. if ( ! findPlaceForObject(gen, obj.first, 3, pos))
  727. {
  728. logGlobal->errorStream() << boost::format("Failed to fill zone %d due to lack of space") %id;
  729. //TODO CLEANUP!
  730. return false;
  731. }
  732. logGlobal->traceStream() << "Place found";
  733. placeObject(gen, obj.first, pos);
  734. guardObject (gen, obj.first, obj.second);
  735. }
  736. return true;
  737. }
  738. void CRmgTemplateZone::createTreasures(CMapGenerator* gen)
  739. {
  740. const double minDistance = 3;
  741. do {
  742. int3 pos;
  743. if ( ! findPlaceForTreasurePile(gen, minDistance, pos))
  744. {
  745. break;
  746. }
  747. createTreasurePile (gen, pos);
  748. } while(true);
  749. }
  750. void CRmgTemplateZone::createObstacles(CMapGenerator* gen)
  751. {
  752. auto sel = gen->editManager->getTerrainSelection();
  753. sel.clearSelection();
  754. for (auto tile : tileinfo)
  755. {
  756. //test code - block all the map to show paths clearly
  757. //if (gen->isPossible(tile))
  758. // gen->setOccupied(tile, ETileType::BLOCKED);
  759. if (gen->shouldBeBlocked(tile)) //fill tiles that should be blocked with obstacles
  760. {
  761. auto obj = new CGObjectInstance();
  762. obj->ID = static_cast<Obj>(130);
  763. obj->subID = 0;
  764. placeObject(gen, obj, tile);
  765. }
  766. }
  767. }
  768. bool CRmgTemplateZone::fill(CMapGenerator* gen)
  769. {
  770. addAllPossibleObjects (gen);
  771. initTownType(gen);
  772. initTerrainType(gen);
  773. placeMines(gen);
  774. createRequiredObjects(gen);
  775. fractalize(gen); //after required objects are created and linked with their own paths
  776. createTreasures(gen);
  777. createObstacles(gen);
  778. logGlobal->infoStream() << boost::format ("Zone %d filled successfully") %id;
  779. return true;
  780. }
  781. bool CRmgTemplateZone::findPlaceForTreasurePile(CMapGenerator* gen, si32 min_dist, int3 &pos)
  782. {
  783. //si32 min_dist = sqrt(tileinfo.size()/density);
  784. int best_distance = 0;
  785. bool result = false;
  786. //logGlobal->infoStream() << boost::format("Min dist for density %f is %d") % density % min_dist;
  787. for(auto tile : tileinfo)
  788. {
  789. auto dist = gen->getTile(tile).getNearestObjectDistance();
  790. if (gen->isPossible(tile) && (dist >= min_dist) && (dist > best_distance))
  791. {
  792. bool allTilesAvailable = true;
  793. gen->foreach_neighbour (tile, [&gen, &allTilesAvailable](int3 neighbour)
  794. {
  795. if (!(gen->isPossible(neighbour) || gen->isBlocked(neighbour)))
  796. {
  797. allTilesAvailable = false; //all present tiles must be already blocked or ready for new objects
  798. }
  799. });
  800. if (allTilesAvailable)
  801. {
  802. best_distance = dist;
  803. pos = tile;
  804. result = true;
  805. }
  806. }
  807. }
  808. if (result)
  809. {
  810. gen->setOccupied(pos, ETileType::BLOCKED); //block that tile
  811. }
  812. return result;
  813. }
  814. bool CRmgTemplateZone::findPlaceForObject(CMapGenerator* gen, CGObjectInstance* obj, si32 min_dist, int3 &pos)
  815. {
  816. //we need object apperance to deduce free tiles
  817. if (obj->appearance.id == Obj::NO_OBJ)
  818. {
  819. auto templates = VLC->dobjinfo->pickCandidates(obj->ID, obj->subID, gen->map->getTile(getPos()).terType);
  820. if (templates.empty())
  821. throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") %obj->ID %obj->subID %pos));
  822. obj->appearance = templates.front();
  823. }
  824. //si32 min_dist = sqrt(tileinfo.size()/density);
  825. int best_distance = 0;
  826. bool result = false;
  827. si32 w = gen->map->width;
  828. si32 h = gen->map->height;
  829. //logGlobal->infoStream() << boost::format("Min dist for density %f is %d") % density % min_dist;
  830. auto tilesBlockedByObject = obj->getBlockedOffsets();
  831. for (auto tile : tileinfo)
  832. {
  833. //object must be accessible from at least one surounding tile
  834. bool accessible = false;
  835. for (int x = -1; x < 2; x++)
  836. for (int y = -1; y <2; y++)
  837. {
  838. if (x && y) //check only if object is visitable from another tile
  839. {
  840. int3 offset = obj->getVisitableOffset() + int3(x, y, 0);
  841. if (!vstd::contains(tilesBlockedByObject, offset))
  842. {
  843. int3 nearbyPos = tile + offset;
  844. if (gen->map->isInTheMap(nearbyPos))
  845. {
  846. if (obj->appearance.isVisitableFrom(x, y) && !gen->isBlocked(nearbyPos))
  847. accessible = true;
  848. }
  849. }
  850. }
  851. };
  852. if (!accessible)
  853. continue;
  854. auto ti = gen->getTile(tile);
  855. auto dist = ti.getNearestObjectDistance();
  856. //avoid borders
  857. if (gen->isPossible(tile) && (dist >= min_dist) && (dist > best_distance))
  858. {
  859. bool allTilesAvailable = true;
  860. for (auto blockingTile : tilesBlockedByObject)
  861. {
  862. int3 t = tile + blockingTile;
  863. if (!gen->map->isInTheMap(t) || !gen->isPossible(t))
  864. {
  865. allTilesAvailable = false; //if at least one tile is not possible, object can't be placed here
  866. break;
  867. }
  868. }
  869. if (allTilesAvailable)
  870. {
  871. best_distance = dist;
  872. pos = tile;
  873. result = true;
  874. }
  875. }
  876. }
  877. if (result)
  878. {
  879. gen->setOccupied(pos, ETileType::BLOCKED); //block that tile
  880. }
  881. return result;
  882. }
  883. void CRmgTemplateZone::checkAndPlaceObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos)
  884. {
  885. if (!gen->map->isInTheMap(pos))
  886. throw rmgException(boost::to_string(boost::format("Position of object %d at %s is outside the map") % object->id % object->pos()));
  887. object->pos = pos;
  888. if (object->isVisitable() && !gen->map->isInTheMap(object->visitablePos()))
  889. throw rmgException(boost::to_string(boost::format("Visitable tile %s of object %d at %s is outside the map") % object->visitablePos() % object->id % object->pos()));
  890. for (auto tile : object->getBlockedPos())
  891. {
  892. if (!gen->map->isInTheMap(tile))
  893. throw rmgException(boost::to_string(boost::format("Tile %s of object %d at %s is outside the map") % tile() % object->id % object->pos()));
  894. }
  895. if (object->appearance.id == Obj::NO_OBJ)
  896. {
  897. auto templates = VLC->dobjinfo->pickCandidates(object->ID, object->subID, gen->map->getTile(pos).terType);
  898. if (templates.empty())
  899. throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") %object->ID %object->subID %pos));
  900. object->appearance = templates.front();
  901. }
  902. gen->map->addBlockVisTiles(object);
  903. gen->editManager->insertObject(object, pos);
  904. //logGlobal->traceStream() << boost::format ("Successfully inserted object (%d,%d) at pos %s") %object->ID %object->subID %pos();
  905. }
  906. void CRmgTemplateZone::placeObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos)
  907. {
  908. //logGlobal->traceStream() << boost::format("Inserting object at %d %d") % pos.x % pos.y;
  909. checkAndPlaceObject (gen, object, pos);
  910. auto points = object->getBlockedPos();
  911. if (object->isVisitable())
  912. points.insert(pos + object->getVisitableOffset());
  913. points.insert(pos);
  914. for(auto p : points)
  915. {
  916. if (gen->map->isInTheMap(p))
  917. {
  918. gen->setOccupied(p, ETileType::USED);
  919. }
  920. }
  921. for(auto tile : tileinfo)
  922. {
  923. si32 d = pos.dist2d(tile);
  924. gen->setNearestObjectDistance(tile, std::min(d, gen->getNearestObjectDistance(tile)));
  925. }
  926. }
  927. std::vector<int3> CRmgTemplateZone::getAccessibleOffsets (CMapGenerator* gen, CGObjectInstance* object)
  928. {
  929. //get all tiles from which this object can be accessed
  930. int3 visitable = object->visitablePos();
  931. std::vector<int3> tiles;
  932. auto tilesBlockedByObject = object->getBlockedPos(); //absolue value, as object is already placed
  933. gen->foreach_neighbour(visitable, [&](int3& pos)
  934. {
  935. if (gen->isPossible(pos))
  936. {
  937. if (!vstd::contains(tilesBlockedByObject, pos))
  938. {
  939. if (object->appearance.isVisitableFrom(pos.x - visitable.x, pos.y - visitable.y) && !gen->isBlocked(pos)) //TODO: refactor - info about visitability from absolute coordinates
  940. {
  941. tiles.push_back(pos);
  942. }
  943. }
  944. };
  945. });
  946. return tiles;
  947. }
  948. bool CRmgTemplateZone::guardObject(CMapGenerator* gen, CGObjectInstance* object, si32 str)
  949. {
  950. logGlobal->traceStream() << boost::format("Guard object at %s") % object->pos();
  951. std::vector<int3> tiles = getAccessibleOffsets (gen, object);
  952. int3 guardTile(-1,-1,-1);
  953. for (auto tile : tiles)
  954. {
  955. //crunching path may fail if center of teh zone is dirrectly over wide object
  956. if (crunchPath (gen, tile, getPos(), id)) //make sure object is accessible before surrounding it with blocked tiles
  957. {
  958. guardTile = tile;
  959. break;
  960. }
  961. }
  962. if (!guardTile.valid())
  963. {
  964. logGlobal->errorStream() << boost::format("Failed to crunch path to object at %s") % object->pos();
  965. return false;
  966. }
  967. if (addMonster (gen, guardTile, str)) //do not place obstacles around unguarded object
  968. {
  969. for (auto pos : tiles)
  970. {
  971. if (!gen->isFree(pos))
  972. gen->setOccupied(pos, ETileType::BLOCKED);
  973. }
  974. gen->setOccupied (guardTile, ETileType::USED);
  975. }
  976. else
  977. gen->setOccupied (guardTile, ETileType::FREE);
  978. return true;
  979. }
  980. ObjectInfo CRmgTemplateZone::getRandomObject (CMapGenerator* gen, ui32 value)
  981. {
  982. std::vector<std::pair<ui32, ObjectInfo>> tresholds;
  983. ui32 total = 0;
  984. ui32 minValue = 0.25f * value;
  985. //roulette wheel
  986. for (auto oi : possibleObjects)
  987. {
  988. if (oi.value >= minValue && oi.value <= value)
  989. {
  990. //TODO: check place for non-removable object
  991. //problem: we need at least template for the object that does not yet exist
  992. total += oi.probability;
  993. tresholds.push_back (std::make_pair (total, oi));
  994. }
  995. }
  996. //TODO: generate pandora box with gold if the value is very high
  997. if (tresholds.empty())
  998. {
  999. ObjectInfo oi;
  1000. if (minValue > 20000) //we don't have object valuable enough
  1001. {
  1002. oi.generateObject = [minValue]() -> CGObjectInstance *
  1003. {
  1004. auto obj = new CGPandoraBox();
  1005. obj->ID = Obj::PANDORAS_BOX;
  1006. obj->subID = 0;
  1007. obj->resources[Res::GOLD] = minValue;
  1008. return obj;
  1009. };
  1010. oi.value = minValue;
  1011. oi.probability = 0;
  1012. }
  1013. else
  1014. {
  1015. oi.generateObject = [gen]() -> CGObjectInstance *
  1016. {
  1017. return nullptr;
  1018. };
  1019. oi.value = 0;
  1020. oi.probability = 0;
  1021. }
  1022. return oi;
  1023. }
  1024. int r = gen->rand.nextInt (1, total);
  1025. for (auto t : tresholds)
  1026. {
  1027. if (r <= t.first)
  1028. return t.second;
  1029. }
  1030. }
  1031. void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen)
  1032. {
  1033. //TODO: move typical objects to config
  1034. ObjectInfo oi;
  1035. static const Res::ERes preciousRes[] = {Res::ERes::CRYSTAL, Res::ERes::GEMS, Res::ERes::MERCURY, Res::ERes::SULFUR};
  1036. for (int i = 0; i < 4; i++)
  1037. {
  1038. oi.generateObject = [i, gen]() -> CGObjectInstance *
  1039. {
  1040. auto obj = new CGResource();
  1041. obj->ID = Obj::RESOURCE;
  1042. obj->subID = static_cast<si32>(preciousRes[i]);
  1043. obj->amount = 0;
  1044. return obj;
  1045. };
  1046. oi.value = 1400;
  1047. oi.probability = 300;
  1048. possibleObjects.push_back (oi);
  1049. }
  1050. static const Res::ERes woodOre[] = {Res::ERes::WOOD, Res::ERes::ORE};
  1051. for (int i = 0; i < 2; i++)
  1052. {
  1053. oi.generateObject = [i, gen]() -> CGObjectInstance *
  1054. {
  1055. auto obj = new CGResource();
  1056. obj->ID = Obj::RESOURCE;
  1057. obj->subID = static_cast<si32>(woodOre[i]);
  1058. obj->amount = 0;
  1059. return obj;
  1060. };
  1061. oi.value = 1400;
  1062. oi.probability = 300;
  1063. possibleObjects.push_back (oi);
  1064. }
  1065. oi.generateObject = [gen]() -> CGObjectInstance *
  1066. {
  1067. auto obj = new CGResource();
  1068. obj->ID = Obj::RESOURCE;
  1069. obj->subID = static_cast<si32>(Res::ERes::GOLD);
  1070. obj->amount = 0;
  1071. return obj;
  1072. };
  1073. oi.value = 750;
  1074. oi.probability = 300;
  1075. possibleObjects.push_back (oi);
  1076. oi.generateObject = [gen]() -> CGObjectInstance *
  1077. {
  1078. auto obj = new CGPickable();
  1079. obj->ID = Obj::TREASURE_CHEST;
  1080. obj->subID = 0;
  1081. return obj;
  1082. };
  1083. oi.value = 1500;
  1084. oi.probability = 1000;
  1085. possibleObjects.push_back (oi);
  1086. oi.generateObject = [gen]() -> CGObjectInstance *
  1087. {
  1088. auto obj = new CGArtifact();
  1089. obj->ID = Obj::RANDOM_TREASURE_ART;
  1090. obj->subID = 0;
  1091. auto a = new CArtifactInstance();
  1092. gen->map->addNewArtifactInstance(a);
  1093. obj->storedArtifact = a;
  1094. return obj;
  1095. };
  1096. oi.value = 2000;
  1097. oi.probability = 150;
  1098. possibleObjects.push_back (oi);
  1099. oi.generateObject = [gen]() -> CGObjectInstance *
  1100. {
  1101. auto obj = new CGArtifact();
  1102. obj->ID = Obj::RANDOM_MINOR_ART;
  1103. obj->subID = 0;
  1104. auto a = new CArtifactInstance();
  1105. gen->map->addNewArtifactInstance(a);
  1106. obj->storedArtifact = a;
  1107. return obj;
  1108. };
  1109. oi.value = 5000;
  1110. oi.probability = 150;
  1111. possibleObjects.push_back (oi);
  1112. oi.generateObject = [gen]() -> CGObjectInstance *
  1113. {
  1114. auto obj = new CGArtifact();
  1115. obj->ID = Obj::RANDOM_MAJOR_ART;
  1116. obj->subID = 0;
  1117. auto a = new CArtifactInstance();
  1118. gen->map->addNewArtifactInstance(a);
  1119. obj->storedArtifact = a;
  1120. return obj;
  1121. };
  1122. oi.value = 10000;
  1123. oi.probability = 150;
  1124. possibleObjects.push_back (oi);
  1125. oi.generateObject = [gen]() -> CGObjectInstance *
  1126. {
  1127. auto obj = new CGArtifact();
  1128. obj->ID = Obj::RANDOM_RELIC_ART;
  1129. obj->subID = 0;
  1130. auto a = new CArtifactInstance();
  1131. gen->map->addNewArtifactInstance(a);
  1132. obj->storedArtifact = a;
  1133. return obj;
  1134. };
  1135. oi.value = 20000;
  1136. oi.probability = 150;
  1137. possibleObjects.push_back (oi);
  1138. static const int scrollValues[] = {500, 2000, 3000, 4000, 5000};
  1139. for (int i = 0; i < 5; i++)
  1140. {
  1141. oi.generateObject = [i, gen]() -> CGObjectInstance *
  1142. {
  1143. auto obj = new CGArtifact();
  1144. obj->ID = Obj::SPELL_SCROLL;
  1145. obj->subID = 0;
  1146. std::vector<SpellID> out;
  1147. //TODO: unify with cb->getAllowedSpells?
  1148. for (ui32 i = 0; i < gen->map->allowedSpell.size(); i++) //spellh size appears to be greater (?)
  1149. {
  1150. const CSpell *spell = SpellID(i).toSpell();
  1151. if (gen->map->allowedSpell[spell->id] && spell->level == i+1)
  1152. {
  1153. out.push_back(spell->id);
  1154. }
  1155. }
  1156. auto a = CArtifactInstance::createScroll(RandomGeneratorUtil::nextItem(out, gen->rand)->toSpell());
  1157. gen->map->addNewArtifactInstance(a);
  1158. obj->storedArtifact = a;
  1159. return obj;
  1160. };
  1161. oi.value = scrollValues[i];
  1162. oi.probability = 30;
  1163. possibleObjects.push_back (oi);
  1164. }
  1165. //non-removable object for test
  1166. //oi.generateObject = [gen]() -> CGObjectInstance *
  1167. //{
  1168. // auto obj = new CGMagicWell();
  1169. // obj->ID = Obj::MAGIC_WELL;
  1170. // obj->subID = 0;
  1171. // return obj;
  1172. //};
  1173. //oi.value = 250;
  1174. //oi.probability = 100;
  1175. //possibleObjects.push_back (oi);
  1176. //oi.generateObject = [gen]() -> CGObjectInstance *
  1177. //{
  1178. // auto obj = new CGObelisk();
  1179. // obj->ID = Obj::OBELISK;
  1180. // obj->subID = 0;
  1181. // return obj;
  1182. //};
  1183. //oi.value = 3500;
  1184. //oi.probability = 200;
  1185. //possibleObjects.push_back (oi);
  1186. //oi.generateObject = [gen]() -> CGObjectInstance *
  1187. //{
  1188. // auto obj = new CBank();
  1189. // obj->ID = Obj::CREATURE_BANK;
  1190. // obj->subID = 5; //naga bank
  1191. // return obj;
  1192. //};
  1193. //oi.value = 3000;
  1194. //oi.probability = 100;
  1195. //possibleObjects.push_back (oi);
  1196. }