CModHandler.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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, size_t size, std::string objectName):
  157. handler(handler),
  158. objectName(objectName),
  159. originalData(handler->loadLegacyData(size))
  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, GameConstants::F_NUMBER * 2, "heroClass")));
  222. handlers.insert(std::make_pair("artifacts", ContentTypeHandler(VLC->arth, GameConstants::ARTIFACTS_QUANTITY, "artifact")));
  223. handlers.insert(std::make_pair("creatures", ContentTypeHandler(VLC->creh, GameConstants::CREATURES_COUNT, "creature")));
  224. handlers.insert(std::make_pair("factions", ContentTypeHandler(VLC->townh, GameConstants::F_NUMBER, "faction")));
  225. handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, GameConstants::HEROES_QUANTITY, "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. loadConfigFromFile ("defaultMods");
  251. }
  252. void CModHandler::loadConfigFromFile (std::string name)
  253. {
  254. const JsonNode config(ResourceID("config/" + name + ".json"));
  255. const JsonNode & hardcodedFeatures = config["hardcodedFeatures"];
  256. settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
  257. settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
  258. settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
  259. settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
  260. settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
  261. settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
  262. const JsonNode & gameModules = config["modules"];
  263. modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
  264. modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
  265. modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
  266. modules.MITHRIL = gameModules["MITHRIL"].Bool();
  267. }
  268. // currentList is passed by value to get current list of depending mods
  269. bool CModHandler::hasCircularDependency(TModID modID, std::set <TModID> currentList) const
  270. {
  271. const CModInfo & mod = allMods.at(modID);
  272. // Mod already present? We found a loop
  273. if (vstd::contains(currentList, modID))
  274. {
  275. logGlobal->errorStream() << "Error: Circular dependency detected! Printing dependency list:";
  276. logGlobal->errorStream() << "\t" << mod.name << " -> ";
  277. return true;
  278. }
  279. currentList.insert(modID);
  280. // recursively check every dependency of this mod
  281. BOOST_FOREACH(const TModID & dependency, mod.dependencies)
  282. {
  283. if (hasCircularDependency(dependency, currentList))
  284. {
  285. logGlobal->errorStream() << "\t" << mod.name << " ->\n"; // conflict detected, print dependency list
  286. return true;
  287. }
  288. }
  289. return false;
  290. }
  291. bool CModHandler::checkDependencies(const std::vector <TModID> & input) const
  292. {
  293. BOOST_FOREACH(const TModID & id, input)
  294. {
  295. const CModInfo & mod = allMods.at(id);
  296. BOOST_FOREACH(const TModID & dep, mod.dependencies)
  297. {
  298. if (!vstd::contains(input, dep))
  299. {
  300. logGlobal->errorStream() << "Error: Mod " << mod.name << " requires missing " << dep << "!";
  301. return false;
  302. }
  303. }
  304. BOOST_FOREACH(const TModID & conflicting, mod.conflicts)
  305. {
  306. if (vstd::contains(input, conflicting))
  307. {
  308. logGlobal->errorStream() << "Error: Mod " << mod.name << " conflicts with " << allMods.at(conflicting).name << "!";
  309. return false;
  310. }
  311. }
  312. if (hasCircularDependency(id))
  313. return false;
  314. }
  315. return true;
  316. }
  317. std::vector <TModID> CModHandler::resolveDependencies(std::vector <TModID> input) const
  318. {
  319. // Topological sort algorithm
  320. // May not be the fastest one but VCMI does not needs any speed here
  321. // Unless user have dozens of mods with complex dependencies this code should be fine
  322. // first - sort input to have input strictly based on name (and not on hashmap or anything else)
  323. boost::range::sort(input);
  324. std::vector <TModID> output;
  325. output.reserve(input.size());
  326. std::set <TModID> resolvedMods;
  327. // Check if all mod dependencies are resolved (moved to resolvedMods)
  328. auto isResolved = [&](const CModInfo mod) -> bool
  329. {
  330. BOOST_FOREACH(const TModID & dependency, mod.dependencies)
  331. {
  332. if (!vstd::contains(resolvedMods, dependency))
  333. return false;
  334. }
  335. return true;
  336. };
  337. while (!input.empty())
  338. {
  339. std::set <TModID> toResolve; // list of mods resolved on this iteration
  340. for (auto it = input.begin(); it != input.end();)
  341. {
  342. if (isResolved(allMods.at(*it)))
  343. {
  344. toResolve.insert(*it);
  345. output.push_back(*it);
  346. it = input.erase(it);
  347. continue;
  348. }
  349. it++;
  350. }
  351. resolvedMods.insert(toResolve.begin(), toResolve.end());
  352. }
  353. return output;
  354. }
  355. void CModHandler::initialize(std::vector<std::string> availableMods)
  356. {
  357. std::string confName = "config/modSettings.json";
  358. JsonNode modConfig;
  359. // Porbably new install. Create initial configuration
  360. if (!CResourceHandler::get()->existsResource(ResourceID(confName)))
  361. CResourceHandler::get()->createResource(confName);
  362. else
  363. modConfig = JsonNode(ResourceID(confName));
  364. const JsonNode & modList = modConfig["activeMods"];
  365. JsonNode resultingList;
  366. std::vector <TModID> detectedMods;
  367. BOOST_FOREACH(std::string name, availableMods)
  368. {
  369. boost::to_lower(name);
  370. std::string modFileName = "mods/" + name + "/mod.json";
  371. if (CResourceHandler::get()->existsResource(ResourceID(modFileName)))
  372. {
  373. const JsonNode config = JsonNode(ResourceID(modFileName));
  374. if (config.isNull())
  375. continue;
  376. if (!modList[name].isNull() && modList[name].Bool() == false )
  377. {
  378. resultingList[name].Bool() = false;
  379. continue; // disabled mod
  380. }
  381. resultingList[name].Bool() = true;
  382. CModInfo & mod = allMods[name];
  383. mod.identifier = name;
  384. mod.name = config["name"].String();
  385. mod.description = config["description"].String();
  386. mod.dependencies = config["depends"].convertTo<std::set<std::string> >();
  387. mod.conflicts = config["conflicts"].convertTo<std::set<std::string> >();
  388. detectedMods.push_back(name);
  389. }
  390. else
  391. logGlobal->warnStream() << "\t\t Directory " << name << " does not contains VCMI mod";
  392. }
  393. if (!checkDependencies(detectedMods))
  394. {
  395. logGlobal->errorStream() << "Critical error: failed to load mods! Exiting...";
  396. exit(1);
  397. }
  398. activeMods = resolveDependencies(detectedMods);
  399. modConfig["activeMods"] = resultingList;
  400. CResourceHandler::get()->createResource("CONFIG/modSettings.json");
  401. std::ofstream file(CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::trunc);
  402. file << modConfig;
  403. }
  404. std::vector<std::string> CModHandler::getActiveMods()
  405. {
  406. return activeMods;
  407. }
  408. CModInfo & CModHandler::getModData(TModID modId)
  409. {
  410. CModInfo & mod = allMods.at(modId);
  411. assert(vstd::contains(activeMods, modId)); // not really necessary but won't hurt
  412. return mod;
  413. }
  414. template<typename Handler>
  415. void CModHandler::handleData(Handler handler, const JsonNode & source, std::string listName, std::string schemaName)
  416. {
  417. JsonNode config = JsonUtils::assembleFromFiles(source[listName].convertTo<std::vector<std::string> >());
  418. BOOST_FOREACH(auto & entry, config.Struct())
  419. {
  420. if (!entry.second.isNull()) // may happens if mod removed object by setting json entry to null
  421. {
  422. JsonUtils::validate(entry.second, schemaName, entry.first);
  423. handler->load(entry.first, entry.second);
  424. }
  425. }
  426. }
  427. void CModHandler::loadGameContent()
  428. {
  429. CStopWatch timer, totalTime;
  430. CContentHandler content;
  431. logGlobal->infoStream() << "\tInitializing content hander: " << timer.getDiff() << " ms";
  432. // first - load virtual "core" mod that contains all data
  433. // TODO? move all data into real mods? RoE, AB, SoD, WoG
  434. content.preloadModData("core", JsonNode(ResourceID("config/gameConfig.json")));
  435. logGlobal->infoStream() << "\tParsing original game data: " << timer.getDiff() << " ms";
  436. BOOST_FOREACH(const TModID & modName, activeMods)
  437. {
  438. logGlobal->infoStream() << "\t\t" << allMods[modName].name;
  439. std::string modFileName = "mods/" + modName + "/mod.json";
  440. const JsonNode config = JsonNode(ResourceID(modFileName));
  441. JsonUtils::validate(config, "vcmi:mod", modName);
  442. content.preloadModData(modName, config);
  443. }
  444. logGlobal->infoStream() << "\tParsing mod data: " << timer.getDiff() << " ms";
  445. content.loadMod("core");
  446. logGlobal->infoStream() << "\tLoading original game data: " << timer.getDiff() << " ms";
  447. BOOST_FOREACH(const TModID & modName, activeMods)
  448. {
  449. content.loadMod(modName);
  450. logGlobal->infoStream() << "\t\t" << allMods[modName].name;
  451. }
  452. logGlobal->infoStream() << "\tLoading mod data: " << timer.getDiff() << "ms";
  453. VLC->creh->loadCrExpBon();
  454. VLC->creh->buildBonusTreeForTiers(); //do that after all new creatures are loaded
  455. identifiers.finalize();
  456. logGlobal->infoStream() << "\tResolving identifiers: " << timer.getDiff() << " ms";
  457. logGlobal->infoStream() << "\tAll game content loaded in " << totalTime.getDiff() << " ms";
  458. }
  459. void CModHandler::reload()
  460. {
  461. {
  462. //recreate adventure map defs
  463. assert(!VLC->dobjinfo->gobjs[Obj::MONSTER].empty()); //make sure that at least some def info was found
  464. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::MONSTER].begin()->second;
  465. BOOST_FOREACH(auto & crea, VLC->creh->creatures)
  466. {
  467. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::MONSTER], crea->idNumber)) // no obj info for this type
  468. {
  469. CGDefInfo * info = new CGDefInfo(*baseInfo);
  470. info->subid = crea->idNumber;
  471. info->name = crea->advMapDef;
  472. VLC->dobjinfo->gobjs[Obj::MONSTER][crea->idNumber] = info;
  473. }
  474. }
  475. }
  476. {
  477. assert(!VLC->dobjinfo->gobjs[Obj::ARTIFACT].empty());
  478. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::ARTIFACT].begin()->second;
  479. BOOST_FOREACH(auto & art, VLC->arth->artifacts)
  480. {
  481. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::ARTIFACT], art->id)) // no obj info for this type
  482. {
  483. CGDefInfo * info = new CGDefInfo(*baseInfo);
  484. info->subid = art->id;
  485. info->name = art->advMapDef;
  486. VLC->dobjinfo->gobjs[Obj::ARTIFACT][art->id] = info;
  487. }
  488. }
  489. }
  490. {
  491. assert(!VLC->dobjinfo->gobjs[Obj::TOWN].empty()); //make sure that at least some def info was found
  492. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::TOWN].begin()->second;
  493. auto & townInfos = VLC->dobjinfo->gobjs[Obj::TOWN];
  494. BOOST_FOREACH(auto & faction, VLC->townh->factions)
  495. {
  496. TFaction index = faction->index;
  497. CTown * town = faction->town;
  498. if (town)
  499. {
  500. auto & cientInfo = town->clientInfo;
  501. if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::TOWN], index)) // no obj info for this type
  502. {
  503. CGDefInfo * info = new CGDefInfo(*baseInfo);
  504. info->subid = index;
  505. townInfos[index] = info;
  506. }
  507. townInfos[index]->name = cientInfo.advMapCastle;
  508. VLC->dobjinfo->villages[index] = new CGDefInfo(*townInfos[index]);
  509. VLC->dobjinfo->villages[index]->name = cientInfo.advMapVillage;
  510. VLC->dobjinfo->capitols[index] = new CGDefInfo(*townInfos[index]);
  511. VLC->dobjinfo->capitols[index]->name = cientInfo.advMapCapitol;
  512. for (int i = 0; i < town->dwellings.size(); ++i)
  513. {
  514. const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::CREATURE_GENERATOR1][i]; //get same blockmap as first dwelling of tier i
  515. BOOST_FOREACH (auto cre, town->creatures[i]) //both unupgraded and upgraded get same dwelling
  516. {
  517. CGDefInfo * info = new CGDefInfo(*baseInfo);
  518. info->subid = cre;
  519. info->name = town->dwellings[i];
  520. VLC->dobjinfo->gobjs[Obj::CREATURE_GENERATOR1][cre] = info;
  521. VLC->objh->cregens[cre] = cre; //map of dwelling -> creature id
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }