CModHandler.cpp 20 KB

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