CModHandler.cpp 20 KB

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