CModHandler.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "StdInc.h"
  2. #include "CModHandler.h"
  3. #include "CDefObjInfoHandler.h"
  4. #include "JsonNode.h"
  5. #include "filesystem/CResourceLoader.h"
  6. #include "filesystem/ISimpleResourceLoader.h"
  7. #include "CCreatureHandler.h"
  8. #include "CArtHandler.h"
  9. #include "CTownHandler.h"
  10. #include "CHeroHandler.h"
  11. #include "CObjectHandler.h"
  12. #include "StringConstants.h"
  13. #include "CStopWatch.h"
  14. #include "IHandlerBase.h"
  15. /*
  16. * CModHandler.cpp, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. void CIdentifierStorage::checkIdentifier(std::string & ID)
  25. {
  26. if (boost::algorithm::ends_with(ID, "."))
  27. logGlobal->warnStream() << "BIG WARNING: identifier " << ID << " seems to be broken!";
  28. else
  29. {
  30. size_t pos = 0;
  31. do
  32. {
  33. if (std::tolower(ID[pos]) != ID[pos] ) //Not in camelCase
  34. {
  35. logGlobal->warnStream() << "Warning: identifier " << ID << " is not in camelCase!";
  36. ID[pos] = std::tolower(ID[pos]);// Try to fix the ID
  37. }
  38. pos = ID.find('.', pos);
  39. }
  40. while(pos++ != std::string::npos);
  41. }
  42. }
  43. CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope, std::string remoteScope, std::string type,
  44. std::string name, const boost::function<void(si32)> & callback):
  45. localScope(localScope),
  46. remoteScope(remoteScope),
  47. type(type),
  48. name(name),
  49. callback(callback)
  50. {}
  51. static std::pair<std::string, std::string> splitString(std::string input, char separator)
  52. {
  53. std::pair<std::string, std::string> ret;
  54. size_t splitPos = input.find(separator);
  55. if (splitPos == std::string::npos)
  56. {
  57. ret.first.clear();
  58. ret.second = input;
  59. }
  60. else
  61. {
  62. ret.first = input.substr(0, splitPos);
  63. ret.second = input.substr(splitPos + 1);
  64. }
  65. return ret;
  66. }
  67. void CIdentifierStorage::requestIdentifier(ObjectCallback callback)
  68. {
  69. checkIdentifier(callback.type);
  70. checkIdentifier(callback.name);
  71. assert(!callback.localScope.empty());
  72. scheduledRequests.push_back(callback);
  73. }
  74. void CIdentifierStorage::requestIdentifier(std::string scope, std::string type, std::string name, const boost::function<void(si32)> & callback)
  75. {
  76. auto pair = splitString(name, ':'); // remoteScope:name
  77. requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback));
  78. }
  79. void CIdentifierStorage::requestIdentifier(std::string type, const JsonNode & name, const boost::function<void(si32)> & callback)
  80. {
  81. auto pair = splitString(name.String(), ':'); // remoteScope:name
  82. requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback));
  83. }
  84. void CIdentifierStorage::requestIdentifier(const JsonNode & name, const boost::function<void(si32)> & callback)
  85. {
  86. auto pair = splitString(name.String(), ':'); // remoteScope:<type.name>
  87. auto pair2 = splitString(pair.second, '.'); // type.name
  88. requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback));
  89. }
  90. void CIdentifierStorage::registerObject(std::string scope, std::string type, std::string name, si32 identifier)
  91. {
  92. ObjectData data;
  93. data.scope = scope;
  94. data.id = identifier;
  95. std::string fullID = type + '.' + name;
  96. checkIdentifier(fullID);
  97. registeredObjects.insert(std::make_pair(fullID, data));
  98. }
  99. bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request)
  100. {
  101. std::set<std::string> allowedScopes;
  102. if (request.remoteScope.empty())
  103. {
  104. // normally ID's from all required mods, own mod and virtual "core" mod are allowed
  105. if (request.localScope != "core")
  106. allowedScopes = VLC->modh->getModData(request.localScope).dependencies;
  107. allowedScopes.insert(request.localScope);
  108. allowedScopes.insert("core");
  109. }
  110. else
  111. {
  112. // //...unless destination mod was specified explicitly
  113. allowedScopes.insert(request.remoteScope);
  114. }
  115. std::string fullID = request.type + '.' + request.name;
  116. auto entries = registeredObjects.equal_range(fullID);
  117. if (entries.first != entries.second)
  118. {
  119. for (auto it = entries.first; it != entries.second; it++)
  120. {
  121. if (vstd::contains(allowedScopes, it->second.scope))
  122. {
  123. request.callback(it->second.id);
  124. return true;
  125. }
  126. }
  127. // error found. Try to generate some debug info
  128. logGlobal->errorStream() << "Unknown identifier " << request.type << "." << request.name << " from mod " << request.localScope;
  129. for (auto it = entries.first; it != entries.second; it++)
  130. {
  131. logGlobal->errorStream() << "\tID is available in mod " << it->second.scope;
  132. }
  133. // temporary code to smooth 0.92->0.93 transition
  134. request.callback(entries.first->second.id);
  135. return true;
  136. }
  137. return false;
  138. }
  139. void CIdentifierStorage::finalize()
  140. {
  141. bool errorsFound = false;
  142. BOOST_FOREACH(const ObjectCallback & request, scheduledRequests)
  143. {
  144. errorsFound |= !resolveIdentifier(request);
  145. }
  146. if (errorsFound)
  147. {
  148. BOOST_FOREACH(auto object, registeredObjects)
  149. {
  150. logGlobal->traceStream() << object.first << " -> " << object.second.id;
  151. }
  152. logGlobal->errorStream() << "All known identifiers were dumped into log file";
  153. }
  154. assert(errorsFound == false);
  155. }
  156. CContentHandler::ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objectName):
  157. handler(handler),
  158. objectName(objectName),
  159. originalData(handler->loadLegacyData(VLC->modh->settings.data["textData"][objectName].Float()))
  160. {
  161. BOOST_FOREACH(auto & node, originalData)
  162. {
  163. node.setMeta("core");
  164. }
  165. }
  166. void CContentHandler::ContentTypeHandler::preloadModData(std::string modName, std::vector<std::string> fileList)
  167. {
  168. JsonNode data = JsonUtils::assembleFromFiles(fileList);
  169. data.setMeta(modName);
  170. ModInfo & modInfo = modData[modName];
  171. BOOST_FOREACH(auto entry, data.Struct())
  172. {
  173. size_t colon = entry.first.find(':');
  174. if (colon == std::string::npos)
  175. {
  176. // normal object, local to this mod
  177. modInfo.modData[entry.first].swap(entry.second);
  178. }
  179. else
  180. {
  181. std::string remoteName = entry.first.substr(0, colon);
  182. std::string objectName = entry.first.substr(colon + 1);
  183. // patching this mod? Send warning and continue - this situation can be handled normally
  184. if (remoteName == modName)
  185. logGlobal->warnStream() << "Redundant namespace definition for " << objectName;
  186. JsonNode & remoteConf = modData[remoteName].patches[objectName];
  187. JsonUtils::merge(remoteConf, entry.second);
  188. }
  189. }
  190. }
  191. void CContentHandler::ContentTypeHandler::loadMod(std::string modName)
  192. {
  193. ModInfo & modInfo = modData[modName];
  194. // apply patches
  195. if (!modInfo.patches.isNull())
  196. JsonUtils::merge(modInfo.modData, modInfo.patches);
  197. BOOST_FOREACH(auto entry, modInfo.modData.Struct())
  198. {
  199. const std::string & name = entry.first;
  200. JsonNode & data = entry.second;
  201. if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
  202. {
  203. // try to add H3 object data
  204. size_t index = data["index"].Float();
  205. if (originalData.size() > index)
  206. {
  207. JsonUtils::merge(originalData[index], data);
  208. JsonUtils::validate(originalData[index], "vcmi:" + objectName, name);
  209. handler->loadObject(modName, name, originalData[index], index);
  210. originalData[index].clear(); // do not use same data twice (same ID)
  211. continue;
  212. }
  213. }
  214. // normal new object
  215. JsonUtils::validate(data, "vcmi:" + objectName, name);
  216. handler->loadObject(modName, name, data);
  217. }
  218. }
  219. CContentHandler::CContentHandler()
  220. {
  221. handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(&VLC->heroh->classes, "heroClass")));
  222. handlers.insert(std::make_pair("artifacts", ContentTypeHandler(VLC->arth, "artifact")));
  223. handlers.insert(std::make_pair("creatures", ContentTypeHandler(VLC->creh, "creature")));
  224. handlers.insert(std::make_pair("factions", ContentTypeHandler(VLC->townh, "faction")));
  225. handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero")));
  226. //TODO: spells, bonuses, something else?
  227. }
  228. void CContentHandler::preloadModData(std::string modName, JsonNode modConfig)
  229. {
  230. BOOST_FOREACH(auto & handler, handlers)
  231. {
  232. handler.second.preloadModData(modName, modConfig[handler.first].convertTo<std::vector<std::string> >());
  233. }
  234. }
  235. void CContentHandler::loadMod(std::string modName)
  236. {
  237. BOOST_FOREACH(auto & handler, handlers)
  238. {
  239. handler.second.loadMod(modName);
  240. }
  241. }
  242. CModHandler::CModHandler()
  243. {
  244. for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
  245. {
  246. identifiers.registerObject("core", "resource", GameConstants::RESOURCE_NAMES[i], i);
  247. }
  248. for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i)
  249. identifiers.registerObject("core", "primSkill", PrimarySkill::names[i], i);
  250. }
  251. void CModHandler::loadConfigFromFile (std::string name)
  252. {
  253. settings.data = JsonUtils::assembleFromFiles("config/" + name);
  254. const JsonNode & hardcodedFeatures = settings.data["hardcodedFeatures"];
  255. settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
  256. settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
  257. settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
  258. settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
  259. settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
  260. settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
  261. const JsonNode & gameModules = settings.data["modules"];
  262. modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
  263. modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
  264. modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
  265. modules.MITHRIL = gameModules["MITHRIL"].Bool();
  266. }
  267. // currentList is passed by value to get current list of depending mods
  268. bool CModHandler::hasCircularDependency(TModID modID, std::set <TModID> currentList) const
  269. {
  270. const CModInfo & mod = allMods.at(modID);
  271. // Mod already present? We found a loop
  272. if (vstd::contains(currentList, modID))
  273. {
  274. logGlobal->errorStream() << "Error: Circular dependency detected! Printing dependency list:";
  275. logGlobal->errorStream() << "\t" << mod.name << " -> ";
  276. return true;
  277. }
  278. currentList.insert(modID);
  279. // recursively check every dependency of this mod
  280. BOOST_FOREACH(const TModID & dependency, mod.dependencies)
  281. {
  282. if (hasCircularDependency(dependency, currentList))
  283. {
  284. logGlobal->errorStream() << "\t" << mod.name << " ->\n"; // conflict detected, print dependency list
  285. return true;
  286. }
  287. }
  288. return false;
  289. }
  290. bool CModHandler::checkDependencies(const std::vector <TModID> & input) const
  291. {
  292. BOOST_FOREACH(const TModID & id, input)
  293. {
  294. const CModInfo & mod = allMods.at(id);
  295. BOOST_FOREACH(const TModID & dep, mod.dependencies)
  296. {
  297. if (!vstd::contains(input, dep))
  298. {
  299. logGlobal->errorStream() << "Error: Mod " << mod.name << " requires missing " << dep << "!";
  300. return false;
  301. }
  302. }
  303. BOOST_FOREACH(const TModID & conflicting, mod.conflicts)
  304. {
  305. if (vstd::contains(input, conflicting))
  306. {
  307. logGlobal->errorStream() << "Error: Mod " << mod.name << " conflicts with " << allMods.at(conflicting).name << "!";
  308. return false;
  309. }
  310. }
  311. if (hasCircularDependency(id))
  312. return false;
  313. }
  314. return true;
  315. }
  316. std::vector <TModID> CModHandler::resolveDependencies(std::vector <TModID> input) const
  317. {
  318. // Topological sort algorithm
  319. // May not be the fastest one but VCMI does not needs any speed here
  320. // Unless user have dozens of mods with complex dependencies this code should be fine
  321. // first - sort input to have input strictly based on name (and not on hashmap or anything else)
  322. boost::range::sort(input);
  323. std::vector <TModID> output;
  324. output.reserve(input.size());
  325. std::set <TModID> resolvedMods;
  326. // Check if all mod dependencies are resolved (moved to resolvedMods)
  327. auto isResolved = [&](const CModInfo mod) -> bool
  328. {
  329. BOOST_FOREACH(const TModID & dependency, mod.dependencies)
  330. {
  331. if (!vstd::contains(resolvedMods, dependency))
  332. return false;
  333. }
  334. return true;
  335. };
  336. while (!input.empty())
  337. {
  338. std::set <TModID> toResolve; // list of mods resolved on this iteration
  339. for (auto it = input.begin(); it != input.end();)
  340. {
  341. if (isResolved(allMods.at(*it)))
  342. {
  343. toResolve.insert(*it);
  344. output.push_back(*it);
  345. it = input.erase(it);
  346. continue;
  347. }
  348. it++;
  349. }
  350. resolvedMods.insert(toResolve.begin(), toResolve.end());
  351. }
  352. return output;
  353. }
  354. void CModHandler::initialize(std::vector<std::string> availableMods)
  355. {
  356. std::string confName = "config/modSettings.json";
  357. JsonNode modConfig;
  358. // Porbably new install. Create initial configuration
  359. if (!CResourceHandler::get()->existsResource(ResourceID(confName)))
  360. CResourceHandler::get()->createResource(confName);
  361. else
  362. modConfig = JsonNode(ResourceID(confName));
  363. const JsonNode & modList = modConfig["activeMods"];
  364. JsonNode resultingList;
  365. std::vector <TModID> detectedMods;
  366. BOOST_FOREACH(std::string name, availableMods)
  367. {
  368. boost::to_lower(name);
  369. std::string modFileName = "mods/" + name + "/mod.json";
  370. if (CResourceHandler::get()->existsResource(ResourceID(modFileName)))
  371. {
  372. const JsonNode config = JsonNode(ResourceID(modFileName));
  373. if (config.isNull())
  374. continue;
  375. if (!modList[name].isNull() && modList[name].Bool() == false )
  376. {
  377. resultingList[name].Bool() = false;
  378. continue; // disabled mod
  379. }
  380. resultingList[name].Bool() = true;
  381. CModInfo & mod = allMods[name];
  382. mod.identifier = name;
  383. mod.name = config["name"].String();
  384. mod.description = config["description"].String();
  385. mod.dependencies = config["depends"].convertTo<std::set<std::string> >();
  386. mod.conflicts = config["conflicts"].convertTo<std::set<std::string> >();
  387. detectedMods.push_back(name);
  388. }
  389. else
  390. logGlobal->warnStream() << "\t\t Directory " << name << " does not contains VCMI mod";
  391. }
  392. if (!checkDependencies(detectedMods))
  393. {
  394. logGlobal->errorStream() << "Critical error: failed to load mods! Exiting...";
  395. exit(1);
  396. }
  397. activeMods = resolveDependencies(detectedMods);
  398. modConfig["activeMods"] = resultingList;
  399. CResourceHandler::get()->createResource("CONFIG/modSettings.json");
  400. std::ofstream file(CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::trunc);
  401. file << modConfig;
  402. }
  403. std::vector<std::string> CModHandler::getActiveMods()
  404. {
  405. return activeMods;
  406. }
  407. CModInfo & CModHandler::getModData(TModID modId)
  408. {
  409. CModInfo & mod = allMods.at(modId);
  410. assert(vstd::contains(activeMods, modId)); // not really necessary but won't hurt
  411. return mod;
  412. }
  413. template<typename Handler>
  414. void CModHandler::handleData(Handler handler, const JsonNode & source, std::string listName, std::string schemaName)
  415. {
  416. JsonNode config = JsonUtils::assembleFromFiles(source[listName].convertTo<std::vector<std::string> >());
  417. BOOST_FOREACH(auto & entry, config.Struct())
  418. {
  419. if (!entry.second.isNull()) // may happens if mod removed object by setting json entry to null
  420. {
  421. JsonUtils::validate(entry.second, schemaName, entry.first);
  422. handler->load(entry.first, entry.second);
  423. }
  424. }
  425. }
  426. void CModHandler::beforeLoad()
  427. {
  428. loadConfigFromFile("defaultMods.json");
  429. }
  430. void CModHandler::loadGameContent()
  431. {
  432. CStopWatch timer, totalTime;
  433. CContentHandler content;
  434. logGlobal->infoStream() << "\tInitializing content hander: " << timer.getDiff() << " ms";
  435. // first - load virtual "core" mod that contains all data
  436. // TODO? move all data into real mods? RoE, AB, SoD, WoG
  437. content.preloadModData("core", JsonNode(ResourceID("config/gameConfig.json")));
  438. logGlobal->infoStream() << "\tParsing original game data: " << timer.getDiff() << " ms";
  439. BOOST_FOREACH(const TModID & modName, activeMods)
  440. {
  441. logGlobal->infoStream() << "\t\t" << allMods[modName].name;
  442. std::string modFileName = "mods/" + modName + "/mod.json";
  443. const JsonNode config = JsonNode(ResourceID(modFileName));
  444. JsonUtils::validate(config, "vcmi:mod", modName);
  445. content.preloadModData(modName, config);
  446. }
  447. logGlobal->infoStream() << "\tParsing mod data: " << timer.getDiff() << " ms";
  448. content.loadMod("core");
  449. logGlobal->infoStream() << "\tLoading original game data: " << timer.getDiff() << " ms";
  450. BOOST_FOREACH(const TModID & modName, activeMods)
  451. {
  452. content.loadMod(modName);
  453. logGlobal->infoStream() << "\t\t" << allMods[modName].name;
  454. }
  455. logGlobal->infoStream() << "\tLoading mod data: " << timer.getDiff() << "ms";
  456. VLC->creh->loadCrExpBon();
  457. VLC->creh->buildBonusTreeForTiers(); //do that after all new creatures are loaded
  458. identifiers.finalize();
  459. logGlobal->infoStream() << "\tResolving identifiers: " << timer.getDiff() << " ms";
  460. logGlobal->infoStream() << "\tAll game content loaded in " << totalTime.getDiff() << " ms";
  461. }
  462. void CModHandler::reload()
  463. {
  464. {
  465. //recreate adventure map defs
  466. assert(!VLC->dobjinfo->gobjs[Obj::MONSTER].empty()); //make sure that at least some def info was found
  467. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::MONSTER].begin()->second;
  468. BOOST_FOREACH(auto & crea, VLC->creh->creatures)
  469. {
  470. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::MONSTER], crea->idNumber)) // no obj info for this type
  471. {
  472. CGDefInfo * info = new CGDefInfo(*baseInfo);
  473. info->subid = crea->idNumber;
  474. info->name = crea->advMapDef;
  475. VLC->dobjinfo->gobjs[Obj::MONSTER][crea->idNumber] = info;
  476. }
  477. }
  478. }
  479. {
  480. assert(!VLC->dobjinfo->gobjs[Obj::ARTIFACT].empty());
  481. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::ARTIFACT].begin()->second;
  482. BOOST_FOREACH(auto & art, VLC->arth->artifacts)
  483. {
  484. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::ARTIFACT], art->id)) // no obj info for this type
  485. {
  486. CGDefInfo * info = new CGDefInfo(*baseInfo);
  487. info->subid = art->id;
  488. info->name = art->advMapDef;
  489. VLC->dobjinfo->gobjs[Obj::ARTIFACT][art->id] = info;
  490. }
  491. }
  492. }
  493. {
  494. assert(!VLC->dobjinfo->gobjs[Obj::TOWN].empty()); //make sure that at least some def info was found
  495. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::TOWN].begin()->second;
  496. auto & townInfos = VLC->dobjinfo->gobjs[Obj::TOWN];
  497. BOOST_FOREACH(auto & faction, VLC->townh->factions)
  498. {
  499. TFaction index = faction->index;
  500. CTown * town = faction->town;
  501. if (town)
  502. {
  503. auto & cientInfo = town->clientInfo;
  504. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::TOWN], index)) // no obj info for this type
  505. {
  506. CGDefInfo * info = new CGDefInfo(*baseInfo);
  507. info->subid = index;
  508. townInfos[index] = info;
  509. }
  510. townInfos[index]->name = cientInfo.advMapCastle;
  511. VLC->dobjinfo->villages[index] = new CGDefInfo(*townInfos[index]);
  512. VLC->dobjinfo->villages[index]->name = cientInfo.advMapVillage;
  513. VLC->dobjinfo->capitols[index] = new CGDefInfo(*townInfos[index]);
  514. VLC->dobjinfo->capitols[index]->name = cientInfo.advMapCapitol;
  515. for (int i = 0; i < town->dwellings.size(); ++i)
  516. {
  517. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::CREATURE_GENERATOR1][i]; //get same blockmap as first dwelling of tier i
  518. BOOST_FOREACH (auto cre, town->creatures[i]) //both unupgraded and upgraded get same dwelling
  519. {
  520. CGDefInfo * info = new CGDefInfo(*baseInfo);
  521. info->subid = cre;
  522. info->name = town->dwellings[i];
  523. VLC->dobjinfo->gobjs[Obj::CREATURE_GENERATOR1][cre] = info;
  524. VLC->objh->cregens[cre] = cre; //map of dwelling -> creature id
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }