CTownHandler.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. /*
  2. * CTownHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CTownHandler.h"
  12. #include "VCMI_Lib.h"
  13. #include "CGeneralTextHandler.h"
  14. #include "JsonNode.h"
  15. #include "StringConstants.h"
  16. #include "CCreatureHandler.h"
  17. #include "CModHandler.h"
  18. #include "CHeroHandler.h"
  19. #include "CArtHandler.h"
  20. #include "GameSettings.h"
  21. #include "TerrainHandler.h"
  22. #include "spells/CSpellHandler.h"
  23. #include "filesystem/Filesystem.h"
  24. #include "bonuses/Bonus.h"
  25. #include "bonuses/Propagators.h"
  26. #include "ResourceSet.h"
  27. #include "mapObjectConstructors/AObjectTypeHandler.h"
  28. #include "mapObjectConstructors/CObjectClassesHandler.h"
  29. VCMI_LIB_NAMESPACE_BEGIN
  30. const int NAMES_PER_TOWN=16; // number of town names per faction in H3 files. Json can define any number
  31. const std::map<std::string, CBuilding::EBuildMode> CBuilding::MODES =
  32. {
  33. { "normal", CBuilding::BUILD_NORMAL },
  34. { "auto", CBuilding::BUILD_AUTO },
  35. { "special", CBuilding::BUILD_SPECIAL },
  36. { "grail", CBuilding::BUILD_GRAIL }
  37. };
  38. const std::map<std::string, CBuilding::ETowerHeight> CBuilding::TOWER_TYPES =
  39. {
  40. { "low", CBuilding::HEIGHT_LOW },
  41. { "average", CBuilding::HEIGHT_AVERAGE },
  42. { "high", CBuilding::HEIGHT_HIGH },
  43. { "skyship", CBuilding::HEIGHT_SKYSHIP }
  44. };
  45. std::string CBuilding::getJsonKey() const
  46. {
  47. return modScope + ':' + identifier;;
  48. }
  49. std::string CBuilding::getNameTranslated() const
  50. {
  51. return VLC->generaltexth->translate(getNameTextID());
  52. }
  53. std::string CBuilding::getDescriptionTranslated() const
  54. {
  55. return VLC->generaltexth->translate(getDescriptionTextID());
  56. }
  57. std::string CBuilding::getBaseTextID() const
  58. {
  59. return TextIdentifier("building", modScope, town->faction->identifier, identifier).get();
  60. }
  61. std::string CBuilding::getNameTextID() const
  62. {
  63. return TextIdentifier(getBaseTextID(), "name").get();
  64. }
  65. std::string CBuilding::getDescriptionTextID() const
  66. {
  67. return TextIdentifier(getBaseTextID(), "description").get();
  68. }
  69. BuildingID CBuilding::getBase() const
  70. {
  71. const CBuilding * build = this;
  72. while (build->upgrade >= 0)
  73. {
  74. build = build->town->buildings.at(build->upgrade);
  75. }
  76. return build->bid;
  77. }
  78. si32 CBuilding::getDistance(const BuildingID & buildID) const
  79. {
  80. const CBuilding * build = town->buildings.at(buildID);
  81. int distance = 0;
  82. while (build->upgrade >= 0 && build != this)
  83. {
  84. build = build->town->buildings.at(build->upgrade);
  85. distance++;
  86. }
  87. if (build == this)
  88. return distance;
  89. return -1;
  90. }
  91. void CBuilding::addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const
  92. {
  93. bonusList.push_back(b);
  94. }
  95. CFaction::~CFaction()
  96. {
  97. delete town;
  98. }
  99. int32_t CFaction::getIndex() const
  100. {
  101. return index;
  102. }
  103. int32_t CFaction::getIconIndex() const
  104. {
  105. return index; //???
  106. }
  107. std::string CFaction::getJsonKey() const
  108. {
  109. return modScope + ':' + identifier;;
  110. }
  111. void CFaction::registerIcons(const IconRegistar & cb) const
  112. {
  113. if(town)
  114. {
  115. auto & info = town->clientInfo;
  116. cb(info.icons[0][0], 0, "ITPT", info.iconLarge[0][0]);
  117. cb(info.icons[0][1], 0, "ITPT", info.iconLarge[0][1]);
  118. cb(info.icons[1][0], 0, "ITPT", info.iconLarge[1][0]);
  119. cb(info.icons[1][1], 0, "ITPT", info.iconLarge[1][1]);
  120. cb(info.icons[0][0] + 2, 0, "ITPA", info.iconSmall[0][0]);
  121. cb(info.icons[0][1] + 2, 0, "ITPA", info.iconSmall[0][1]);
  122. cb(info.icons[1][0] + 2, 0, "ITPA", info.iconSmall[1][0]);
  123. cb(info.icons[1][1] + 2, 0, "ITPA", info.iconSmall[1][1]);
  124. cb(index, 1, "CPRSMALL", info.towerIconSmall);
  125. cb(index, 1, "TWCRPORT", info.towerIconLarge);
  126. }
  127. }
  128. std::string CFaction::getNameTranslated() const
  129. {
  130. return VLC->generaltexth->translate(getNameTextID());
  131. }
  132. std::string CFaction::getNameTextID() const
  133. {
  134. return TextIdentifier("faction", modScope, identifier, "name").get();
  135. }
  136. FactionID CFaction::getId() const
  137. {
  138. return FactionID(index);
  139. }
  140. FactionID CFaction::getFaction() const
  141. {
  142. return FactionID(index);
  143. }
  144. bool CFaction::hasTown() const
  145. {
  146. return town != nullptr;
  147. }
  148. EAlignment CFaction::getAlignment() const
  149. {
  150. return alignment;
  151. }
  152. EBoatId CFaction::getBoatType() const
  153. {
  154. return boatType.toEnum();
  155. }
  156. TerrainId CFaction::getNativeTerrain() const
  157. {
  158. return nativeTerrain;
  159. }
  160. void CFaction::updateFrom(const JsonNode & data)
  161. {
  162. }
  163. void CFaction::serializeJson(JsonSerializeFormat & handler)
  164. {
  165. }
  166. CTown::CTown()
  167. : faction(nullptr), mageLevel(0), primaryRes(0), moatAbility(SpellID::NONE), defaultTavernChance(0)
  168. {
  169. }
  170. CTown::~CTown()
  171. {
  172. for(auto & build : buildings)
  173. build.second.dellNull();
  174. for(auto & str : clientInfo.structures)
  175. str.dellNull();
  176. }
  177. std::string CTown::getRandomNameTranslated(size_t index) const
  178. {
  179. return VLC->generaltexth->translate(getRandomNameTextID(index));
  180. }
  181. std::string CTown::getRandomNameTextID(size_t index) const
  182. {
  183. return TextIdentifier("faction", faction->modScope, faction->identifier, "randomName", index).get();
  184. }
  185. size_t CTown::getRandomNamesCount() const
  186. {
  187. return namesCount;
  188. }
  189. std::string CTown::getBuildingScope() const
  190. {
  191. if(faction == nullptr)
  192. //no faction == random faction
  193. return "building";
  194. else
  195. return "building." + faction->getJsonKey();
  196. }
  197. std::set<si32> CTown::getAllBuildings() const
  198. {
  199. std::set<si32> res;
  200. for(const auto & b : buildings)
  201. {
  202. res.insert(b.first.num);
  203. }
  204. return res;
  205. }
  206. const CBuilding * CTown::getSpecialBuilding(BuildingSubID::EBuildingSubID subID) const
  207. {
  208. for(const auto & kvp : buildings)
  209. {
  210. if(kvp.second->subId == subID)
  211. return buildings.at(kvp.first);
  212. }
  213. return nullptr;
  214. }
  215. BuildingID::EBuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const
  216. {
  217. const auto * building = getSpecialBuilding(subID);
  218. return building == nullptr ? BuildingID::NONE : building->bid.num;
  219. }
  220. std::string CTown::getGreeting(BuildingSubID::EBuildingSubID subID) const
  221. {
  222. return CTownHandler::getMappedValue<const std::string, BuildingSubID::EBuildingSubID>(subID, std::string(), specialMessages, false);
  223. }
  224. void CTown::setGreeting(BuildingSubID::EBuildingSubID subID, const std::string & message) const
  225. {
  226. specialMessages.insert(std::pair<BuildingSubID::EBuildingSubID, const std::string>(subID, message));
  227. }
  228. CTownHandler::CTownHandler():
  229. randomTown(new CTown()),
  230. randomFaction(new CFaction())
  231. {
  232. randomFaction->town = randomTown;
  233. randomTown->faction = randomFaction;
  234. randomFaction->identifier = "random";
  235. randomFaction->modScope = "core";
  236. }
  237. CTownHandler::~CTownHandler()
  238. {
  239. delete randomTown;
  240. }
  241. JsonNode readBuilding(CLegacyConfigParser & parser)
  242. {
  243. JsonNode ret;
  244. JsonNode & cost = ret["cost"];
  245. //note: this code will try to parse mithril as well but wil always return 0 for it
  246. for(const std::string & resID : GameConstants::RESOURCE_NAMES)
  247. cost[resID].Float() = parser.readNumber();
  248. cost.Struct().erase("mithril"); // erase mithril to avoid confusing validator
  249. parser.endLine();
  250. return ret;
  251. }
  252. TPropagatorPtr & CTownHandler::emptyPropagator()
  253. {
  254. static TPropagatorPtr emptyProp(nullptr);
  255. return emptyProp;
  256. }
  257. std::vector<JsonNode> CTownHandler::loadLegacyData()
  258. {
  259. size_t dataSize = VLC->settings()->getInteger(EGameSettings::TEXTS_FACTION);
  260. std::vector<JsonNode> dest(dataSize);
  261. objects.resize(dataSize);
  262. auto getBuild = [&](size_t town, size_t building) -> JsonNode &
  263. {
  264. return dest[town]["town"]["buildings"][EBuildingType::names[building]];
  265. };
  266. CLegacyConfigParser parser("DATA/BUILDING.TXT");
  267. parser.endLine(); // header
  268. parser.endLine();
  269. //Unique buildings
  270. for (size_t town=0; town<dataSize; town++)
  271. {
  272. parser.endLine(); //header
  273. parser.endLine();
  274. int buildID = 17;
  275. do
  276. {
  277. getBuild(town, buildID) = readBuilding(parser);
  278. buildID++;
  279. }
  280. while (!parser.isNextEntryEmpty());
  281. }
  282. // Common buildings
  283. parser.endLine(); // header
  284. parser.endLine();
  285. parser.endLine();
  286. int buildID = 0;
  287. do
  288. {
  289. JsonNode building = readBuilding(parser);
  290. for (size_t town=0; town<dataSize; town++)
  291. getBuild(town, buildID) = building;
  292. buildID++;
  293. }
  294. while (!parser.isNextEntryEmpty());
  295. parser.endLine(); //header
  296. parser.endLine();
  297. //Dwellings
  298. for (size_t town=0; town<dataSize; town++)
  299. {
  300. parser.endLine(); //header
  301. parser.endLine();
  302. for (size_t i=0; i<14; i++)
  303. {
  304. getBuild(town, 30+i) = readBuilding(parser);
  305. }
  306. }
  307. {
  308. CLegacyConfigParser parser("DATA/BLDGNEUT.TXT");
  309. for(int building=0; building<15; building++)
  310. {
  311. std::string name = parser.readString();
  312. std::string descr = parser.readString();
  313. parser.endLine();
  314. for(int j=0; j<dataSize; j++)
  315. {
  316. getBuild(j, building)["name"].String() = name;
  317. getBuild(j, building)["description"].String() = descr;
  318. }
  319. }
  320. parser.endLine(); // silo
  321. parser.endLine(); // blacksmith //unused entries
  322. parser.endLine(); // moat
  323. //shipyard with the ship
  324. std::string name = parser.readString();
  325. std::string descr = parser.readString();
  326. parser.endLine();
  327. for(int town=0; town<dataSize; town++)
  328. {
  329. getBuild(town, 20)["name"].String() = name;
  330. getBuild(town, 20)["description"].String() = descr;
  331. }
  332. //blacksmith
  333. for(int town=0; town<dataSize; town++)
  334. {
  335. getBuild(town, 16)["name"].String() = parser.readString();
  336. getBuild(town, 16)["description"].String() = parser.readString();
  337. parser.endLine();
  338. }
  339. }
  340. {
  341. CLegacyConfigParser parser("DATA/BLDGSPEC.TXT");
  342. for(int town=0; town<dataSize; town++)
  343. {
  344. for(int build=0; build<9; build++)
  345. {
  346. getBuild(town, 17 + build)["name"].String() = parser.readString();
  347. getBuild(town, 17 + build)["description"].String() = parser.readString();
  348. parser.endLine();
  349. }
  350. getBuild(town, 26)["name"].String() = parser.readString(); // Grail
  351. getBuild(town, 26)["description"].String() = parser.readString();
  352. parser.endLine();
  353. getBuild(town, 15)["name"].String() = parser.readString(); // Resource silo
  354. getBuild(town, 15)["description"].String() = parser.readString();
  355. parser.endLine();
  356. }
  357. }
  358. {
  359. CLegacyConfigParser parser("DATA/DWELLING.TXT");
  360. for(int town=0; town<dataSize; town++)
  361. {
  362. for(int build=0; build<14; build++)
  363. {
  364. getBuild(town, 30 + build)["name"].String() = parser.readString();
  365. getBuild(town, 30 + build)["description"].String() = parser.readString();
  366. parser.endLine();
  367. }
  368. }
  369. }
  370. {
  371. CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT");
  372. CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT");
  373. size_t townID=0;
  374. do
  375. {
  376. dest[townID]["name"].String() = typeParser.readString();
  377. for (int i=0; i<NAMES_PER_TOWN; i++)
  378. {
  379. JsonNode name;
  380. name.String() = nameParser.readString();
  381. dest[townID]["town"]["names"].Vector().push_back(name);
  382. nameParser.endLine();
  383. }
  384. townID++;
  385. }
  386. while (typeParser.endLine());
  387. }
  388. return dest;
  389. }
  390. void CTownHandler::loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad) const
  391. {
  392. if (source.isNull())
  393. return;
  394. BuildingRequirementsHelper hlp;
  395. hlp.building = building;
  396. hlp.town = building->town;
  397. hlp.json = source;
  398. bidsToLoad.push_back(hlp);
  399. }
  400. template<typename R, typename K>
  401. R CTownHandler::getMappedValue(const K key, const R defval, const std::map<K, R> & map, bool required)
  402. {
  403. auto it = map.find(key);
  404. if(it != map.end())
  405. return it->second;
  406. if(required)
  407. logMod->warn("Warning: Property: '%s' is unknown. Correct the typo or update VCMI.", key);
  408. return defval;
  409. }
  410. template<typename R>
  411. R CTownHandler::getMappedValue(const JsonNode & node, const R defval, const std::map<std::string, R> & map, bool required)
  412. {
  413. if(!node.isNull() && node.getType() == JsonNode::JsonType::DATA_STRING)
  414. return getMappedValue<R, std::string>(node.String(), defval, map, required);
  415. return defval;
  416. }
  417. void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
  418. {
  419. std::shared_ptr<Bonus> b;
  420. static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
  421. if(building->bid == BuildingID::TAVERN)
  422. {
  423. b = createBonus(building, BonusType::MORALE, +1);
  424. }
  425. switch(building->subId)
  426. {
  427. case BuildingSubID::BROTHERHOOD_OF_SWORD:
  428. b = createBonus(building, BonusType::MORALE, +2);
  429. building->overrideBids.insert(BuildingID::TAVERN);
  430. break;
  431. case BuildingSubID::FOUNTAIN_OF_FORTUNE:
  432. b = createBonus(building, BonusType::LUCK, +2);
  433. break;
  434. case BuildingSubID::SPELL_POWER_GARRISON_BONUS:
  435. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER);
  436. break;
  437. case BuildingSubID::ATTACK_GARRISON_BONUS:
  438. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::ATTACK);
  439. break;
  440. case BuildingSubID::DEFENSE_GARRISON_BONUS:
  441. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::DEFENSE);
  442. break;
  443. case BuildingSubID::LIGHTHOUSE:
  444. b = createBonus(building, BonusType::MOVEMENT, +500, playerPropagator, 0);
  445. break;
  446. }
  447. if(b)
  448. building->addNewBonus(b, building->buildingBonuses);
  449. }
  450. std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, int subtype) const
  451. {
  452. return createBonus(build, type, val, emptyPropagator(), subtype);
  453. }
  454. std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, TPropagatorPtr & prop, int subtype) const
  455. {
  456. std::ostringstream descr;
  457. descr << build->getNameTranslated();
  458. return createBonusImpl(build->bid, type, val, prop, descr.str(), subtype);
  459. }
  460. std::shared_ptr<Bonus> CTownHandler::createBonusImpl(const BuildingID & building,
  461. BonusType type,
  462. int val,
  463. TPropagatorPtr & prop,
  464. const std::string & description,
  465. int subtype) const
  466. {
  467. auto b = std::make_shared<Bonus>(BonusDuration::PERMANENT, type, BonusSource::TOWN_STRUCTURE, val, building, description, subtype);
  468. if(prop)
  469. b->addPropagator(prop);
  470. return b;
  471. }
  472. void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building)
  473. {
  474. for(const auto & b : source.Vector())
  475. {
  476. auto bonus = JsonUtils::parseBuildingBonus(b, building->bid, building->getNameTranslated());
  477. if(bonus == nullptr)
  478. continue;
  479. bonus->sid = Bonus::getSid32(building->town->faction->getIndex(), building->bid);
  480. //JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty.
  481. if(bonus->propagator != nullptr
  482. && bonus->propagator->getPropagatorType() == CBonusSystemNode::ENodeTypes::UNKNOWN)
  483. bonus->addPropagator(emptyPropagator());
  484. building->addNewBonus(bonus, bonusList);
  485. }
  486. }
  487. void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source)
  488. {
  489. assert(stringID.find(':') == std::string::npos);
  490. assert(!source.meta.empty());
  491. auto * ret = new CBuilding();
  492. ret->bid = getMappedValue<BuildingID, std::string>(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false);
  493. ret->subId = BuildingSubID::NONE;
  494. if(ret->bid == BuildingID::NONE && !source["id"].isNull())
  495. {
  496. logMod->warn("Building %s: id field is deprecated", stringID);
  497. ret->bid = source["id"].isNull() ? BuildingID(BuildingID::NONE) : BuildingID(source["id"].Float());
  498. }
  499. if (ret->bid == BuildingID::NONE)
  500. logMod->error("Building '%s' isn't recognized and won't work properly. Correct the typo or update VCMI.", stringID);
  501. ret->mode = ret->bid == BuildingID::GRAIL
  502. ? CBuilding::BUILD_GRAIL
  503. : getMappedValue<CBuilding::EBuildMode>(source["mode"], CBuilding::BUILD_NORMAL, CBuilding::MODES);
  504. ret->height = getMappedValue<CBuilding::ETowerHeight>(source["height"], CBuilding::HEIGHT_NO_TOWER, CBuilding::TOWER_TYPES);
  505. ret->identifier = stringID;
  506. ret->modScope = source.meta;
  507. ret->town = town;
  508. VLC->generaltexth->registerString(source.meta, ret->getNameTextID(), source["name"].String());
  509. VLC->generaltexth->registerString(source.meta, ret->getDescriptionTextID(), source["description"].String());
  510. ret->resources = TResources(source["cost"]);
  511. ret->produce = TResources(source["produce"]);
  512. if(ret->bid == BuildingID::TAVERN)
  513. addBonusesForVanilaBuilding(ret);
  514. else if(ret->bid.IsSpecialOrGrail())
  515. {
  516. loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
  517. if(ret->buildingBonuses.empty())
  518. {
  519. ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS);
  520. addBonusesForVanilaBuilding(ret);
  521. }
  522. loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret);
  523. if(!ret->onVisitBonuses.empty())
  524. {
  525. if(ret->subId == BuildingSubID::NONE)
  526. ret->subId = BuildingSubID::CUSTOM_VISITING_BONUS;
  527. for(auto & bonus : ret->onVisitBonuses)
  528. bonus->sid = Bonus::getSid32(ret->town->faction->getIndex(), ret->bid);
  529. }
  530. if(source["type"].String() == "configurable" && ret->subId == BuildingSubID::NONE)
  531. {
  532. ret->subId = BuildingSubID::CUSTOM_VISITING_REWARD;
  533. ret->rewardableObjectInfo.init(source, ret->getBaseTextID());
  534. }
  535. }
  536. //MODS COMPATIBILITY FOR 0.96
  537. if(!ret->produce.nonZero())
  538. {
  539. switch (ret->bid) {
  540. break; case BuildingID::VILLAGE_HALL: ret->produce[EGameResID::GOLD] = 500;
  541. break; case BuildingID::TOWN_HALL : ret->produce[EGameResID::GOLD] = 1000;
  542. break; case BuildingID::CITY_HALL : ret->produce[EGameResID::GOLD] = 2000;
  543. break; case BuildingID::CAPITOL : ret->produce[EGameResID::GOLD] = 4000;
  544. break; case BuildingID::GRAIL : ret->produce[EGameResID::GOLD] = 5000;
  545. break; case BuildingID::RESOURCE_SILO :
  546. {
  547. switch (ret->town->primaryRes.toEnum())
  548. {
  549. case EGameResID::GOLD:
  550. ret->produce[ret->town->primaryRes] = 500;
  551. break;
  552. case EGameResID::WOOD_AND_ORE:
  553. ret->produce[EGameResID::WOOD] = 1;
  554. ret->produce[EGameResID::ORE] = 1;
  555. break;
  556. default:
  557. ret->produce[ret->town->primaryRes] = 1;
  558. break;
  559. }
  560. }
  561. }
  562. }
  563. loadBuildingRequirements(ret, source["requires"], requirementsToLoad);
  564. if(ret->bid.IsSpecialOrGrail())
  565. loadBuildingRequirements(ret, source["overrides"], overriddenBidsToLoad);
  566. if (!source["upgrades"].isNull())
  567. {
  568. // building id and upgrades can't be the same
  569. if(stringID == source["upgrades"].String())
  570. {
  571. throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") %
  572. stringID % ret->town->faction->getNameTranslated()));
  573. }
  574. VLC->modh->identifiers.requestIdentifier(ret->town->getBuildingScope(), source["upgrades"], [=](si32 identifier)
  575. {
  576. ret->upgrade = BuildingID(identifier);
  577. });
  578. }
  579. else
  580. ret->upgrade = BuildingID::NONE;
  581. ret->town->buildings[ret->bid] = ret;
  582. registerObject(source.meta, ret->town->getBuildingScope(), ret->identifier, ret->bid);
  583. }
  584. void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
  585. {
  586. if(source.isStruct())
  587. {
  588. for(const auto & node : source.Struct())
  589. {
  590. if (!node.second.isNull())
  591. loadBuilding(town, node.first, node.second);
  592. }
  593. }
  594. }
  595. void CTownHandler::loadStructure(CTown &town, const std::string & stringID, const JsonNode & source) const
  596. {
  597. auto * ret = new CStructure();
  598. ret->building = nullptr;
  599. ret->buildable = nullptr;
  600. VLC->modh->identifiers.tryRequestIdentifier( source.meta, "building." + town.faction->getJsonKey(), stringID, [=, &town](si32 identifier) mutable
  601. {
  602. ret->building = town.buildings[BuildingID(identifier)];
  603. });
  604. if (source["builds"].isNull())
  605. {
  606. VLC->modh->identifiers.tryRequestIdentifier( source.meta, "building." + town.faction->getJsonKey(), stringID, [=, &town](si32 identifier) mutable
  607. {
  608. ret->building = town.buildings[BuildingID(identifier)];
  609. });
  610. }
  611. else
  612. {
  613. VLC->modh->identifiers.requestIdentifier("building." + town.faction->getJsonKey(), source["builds"], [=, &town](si32 identifier) mutable
  614. {
  615. ret->buildable = town.buildings[BuildingID(identifier)];
  616. });
  617. }
  618. ret->identifier = stringID;
  619. ret->pos.x = static_cast<si32>(source["x"].Float());
  620. ret->pos.y = static_cast<si32>(source["y"].Float());
  621. ret->pos.z = static_cast<si32>(source["z"].Float());
  622. ret->hiddenUpgrade = source["hidden"].Bool();
  623. ret->defName = source["animation"].String();
  624. ret->borderName = source["border"].String();
  625. ret->areaName = source["area"].String();
  626. town.clientInfo.structures.emplace_back(ret);
  627. }
  628. void CTownHandler::loadStructures(CTown &town, const JsonNode & source) const
  629. {
  630. for(const auto & node : source.Struct())
  631. {
  632. if (!node.second.isNull())
  633. loadStructure(town, node.first, node.second);
  634. }
  635. }
  636. void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) const
  637. {
  638. auto & dstSlots = town.clientInfo.hallSlots;
  639. const auto & srcSlots = source.Vector();
  640. dstSlots.resize(srcSlots.size());
  641. for(size_t i=0; i<dstSlots.size(); i++)
  642. {
  643. auto & dstRow = dstSlots[i];
  644. const auto & srcRow = srcSlots[i].Vector();
  645. dstRow.resize(srcRow.size());
  646. for(size_t j=0; j < dstRow.size(); j++)
  647. {
  648. auto & dstBox = dstRow[j];
  649. const auto & srcBox = srcRow[j].Vector();
  650. dstBox.resize(srcBox.size());
  651. for(size_t k=0; k<dstBox.size(); k++)
  652. {
  653. auto & dst = dstBox[k];
  654. const auto & src = srcBox[k];
  655. VLC->modh->identifiers.requestIdentifier("building." + town.faction->getJsonKey(), src, [&](si32 identifier)
  656. {
  657. dst = BuildingID(identifier);
  658. });
  659. }
  660. }
  661. }
  662. }
  663. Point JsonToPoint(const JsonNode & node)
  664. {
  665. if(!node.isStruct())
  666. return Point::makeInvalid();
  667. Point ret;
  668. ret.x = static_cast<si32>(node["x"].Float());
  669. ret.y = static_cast<si32>(node["y"].Float());
  670. return ret;
  671. }
  672. void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source) const
  673. {
  674. town.clientInfo.siegePrefix = source["imagePrefix"].String();
  675. town.clientInfo.towerIconSmall = source["towerIconSmall"].String();
  676. town.clientInfo.towerIconLarge = source["towerIconLarge"].String();
  677. VLC->modh->identifiers.requestIdentifier("creature", source["shooter"], [&town](si32 creature)
  678. {
  679. auto crId = CreatureID(creature);
  680. if((*VLC->creh)[crId]->animation.missleFrameAngles.empty())
  681. logMod->error("Mod '%s' error: Creature '%s' on the Archer's tower is not a shooter. Mod should be fixed. Siege will not work properly!"
  682. , town.faction->getNameTranslated()
  683. , (*VLC->creh)[crId]->getNameSingularTranslated());
  684. town.clientInfo.siegeShooter = crId;
  685. });
  686. auto & pos = town.clientInfo.siegePositions;
  687. pos.resize(21);
  688. pos[8] = JsonToPoint(source["towers"]["top"]["tower"]);
  689. pos[17] = JsonToPoint(source["towers"]["top"]["battlement"]);
  690. pos[20] = JsonToPoint(source["towers"]["top"]["creature"]);
  691. pos[2] = JsonToPoint(source["towers"]["keep"]["tower"]);
  692. pos[15] = JsonToPoint(source["towers"]["keep"]["battlement"]);
  693. pos[18] = JsonToPoint(source["towers"]["keep"]["creature"]);
  694. pos[3] = JsonToPoint(source["towers"]["bottom"]["tower"]);
  695. pos[16] = JsonToPoint(source["towers"]["bottom"]["battlement"]);
  696. pos[19] = JsonToPoint(source["towers"]["bottom"]["creature"]);
  697. pos[9] = JsonToPoint(source["gate"]["gate"]);
  698. pos[10] = JsonToPoint(source["gate"]["arch"]);
  699. pos[7] = JsonToPoint(source["walls"]["upper"]);
  700. pos[6] = JsonToPoint(source["walls"]["upperMid"]);
  701. pos[5] = JsonToPoint(source["walls"]["bottomMid"]);
  702. pos[4] = JsonToPoint(source["walls"]["bottom"]);
  703. pos[13] = JsonToPoint(source["moat"]["moat"]);
  704. pos[14] = JsonToPoint(source["moat"]["bank"]);
  705. pos[11] = JsonToPoint(source["static"]["bottom"]);
  706. pos[12] = JsonToPoint(source["static"]["top"]);
  707. pos[1] = JsonToPoint(source["static"]["background"]);
  708. }
  709. static void readIcon(JsonNode source, std::string & small, std::string & large)
  710. {
  711. if (source.getType() == JsonNode::JsonType::DATA_STRUCT) // don't crash on old format
  712. {
  713. small = source["small"].String();
  714. large = source["large"].String();
  715. }
  716. }
  717. void CTownHandler::loadClientData(CTown &town, const JsonNode & source) const
  718. {
  719. CTown::ClientInfo & info = town.clientInfo;
  720. readIcon(source["icons"]["village"]["normal"], info.iconSmall[0][0], info.iconLarge[0][0]);
  721. readIcon(source["icons"]["village"]["built"], info.iconSmall[0][1], info.iconLarge[0][1]);
  722. readIcon(source["icons"]["fort"]["normal"], info.iconSmall[1][0], info.iconLarge[1][0]);
  723. readIcon(source["icons"]["fort"]["built"], info.iconSmall[1][1], info.iconLarge[1][1]);
  724. info.hallBackground = source["hallBackground"].String();
  725. info.musicTheme = source["musicTheme"].String();
  726. info.townBackground = source["townBackground"].String();
  727. info.guildWindow = source["guildWindow"].String();
  728. info.buildingsIcons = source["buildingsIcons"].String();
  729. //left for back compatibility - will be removed later
  730. if(!source["guildBackground"].String().empty())
  731. info.guildBackground = source["guildBackground"].String();
  732. else
  733. info.guildBackground = "TPMAGE.bmp";
  734. if(!source["tavernVideo"].String().empty())
  735. info.tavernVideo = source["tavernVideo"].String();
  736. else
  737. info.tavernVideo = "TAVERN.BIK";
  738. //end of legacy assignment
  739. loadTownHall(town, source["hallSlots"]);
  740. loadStructures(town, source["structures"]);
  741. loadSiegeScreen(town, source["siege"]);
  742. }
  743. void CTownHandler::loadTown(CTown * town, const JsonNode & source)
  744. {
  745. const auto * resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String());
  746. if(resIter == std::end(GameConstants::RESOURCE_NAMES))
  747. town->primaryRes = GameResID(EGameResID::WOOD_AND_ORE); //Wood + Ore
  748. else
  749. town->primaryRes = GameResID(resIter - std::begin(GameConstants::RESOURCE_NAMES));
  750. warMachinesToLoad[town] = source["warMachine"];
  751. town->mageLevel = static_cast<ui32>(source["mageGuild"].Float());
  752. town->namesCount = 0;
  753. for(const auto & name : source["names"].Vector())
  754. {
  755. VLC->generaltexth->registerString(town->faction->modScope, town->getRandomNameTextID(town->namesCount), name.String());
  756. town->namesCount += 1;
  757. }
  758. if (!source["moatAbility"].isNull()) // VCMI 1.2 compatibility code
  759. {
  760. VLC->modh->identifiers.requestIdentifier( "spell", source["moatAbility"], [=](si32 ability)
  761. {
  762. town->moatAbility = SpellID(ability);
  763. });
  764. }
  765. else
  766. {
  767. VLC->modh->identifiers.requestIdentifier( source.meta, "spell", "castleMoat", [=](si32 ability)
  768. {
  769. town->moatAbility = SpellID(ability);
  770. });
  771. }
  772. // Horde building creature level
  773. for(const JsonNode &node : source["horde"].Vector())
  774. town->hordeLvl[static_cast<int>(town->hordeLvl.size())] = static_cast<int>(node.Float());
  775. // town needs to have exactly 2 horde entries. Validation will take care of 2+ entries
  776. // but anything below 2 must be handled here
  777. for (size_t i=source["horde"].Vector().size(); i<2; i++)
  778. town->hordeLvl[static_cast<int>(i)] = -1;
  779. const JsonVector & creatures = source["creatures"].Vector();
  780. town->creatures.resize(creatures.size());
  781. for (size_t i=0; i< creatures.size(); i++)
  782. {
  783. const JsonVector & level = creatures[i].Vector();
  784. town->creatures[i].resize(level.size());
  785. for (size_t j=0; j<level.size(); j++)
  786. {
  787. VLC->modh->identifiers.requestIdentifier("creature", level[j], [=](si32 creature)
  788. {
  789. town->creatures[i][j] = CreatureID(creature);
  790. });
  791. }
  792. }
  793. town->defaultTavernChance = static_cast<ui32>(source["defaultTavern"].Float());
  794. /// set chance of specific hero class to appear in this town
  795. for(const auto & node : source["tavern"].Struct())
  796. {
  797. int chance = static_cast<int>(node.second.Float());
  798. VLC->modh->identifiers.requestIdentifier(node.second.meta, "heroClass",node.first, [=](si32 classID)
  799. {
  800. VLC->heroh->classes[HeroClassID(classID)]->selectionProbability[town->faction->getId()] = chance;
  801. });
  802. }
  803. for(const auto & node : source["guildSpells"].Struct())
  804. {
  805. int chance = static_cast<int>(node.second.Float());
  806. VLC->modh->identifiers.requestIdentifier(node.second.meta, "spell", node.first, [=](si32 spellID)
  807. {
  808. VLC->spellh->objects.at(spellID)->probabilities[town->faction->getId()] = chance;
  809. });
  810. }
  811. for(const JsonNode & d : source["adventureMap"]["dwellings"].Vector())
  812. {
  813. town->dwellings.push_back(d["graphics"].String());
  814. town->dwellingNames.push_back(d["name"].String());
  815. }
  816. loadBuildings(town, source["buildings"]);
  817. loadClientData(*town, source);
  818. }
  819. void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source) const
  820. {
  821. faction.puzzleMap.reserve(GameConstants::PUZZLE_MAP_PIECES);
  822. std::string prefix = source["prefix"].String();
  823. for(const JsonNode &piece : source["pieces"].Vector())
  824. {
  825. size_t index = faction.puzzleMap.size();
  826. SPuzzleInfo spi;
  827. spi.x = static_cast<si16>(piece["x"].Float());
  828. spi.y = static_cast<si16>(piece["y"].Float());
  829. spi.whenUncovered = static_cast<ui16>(piece["index"].Float());
  830. spi.number = static_cast<ui16>(index);
  831. // filename calculation
  832. std::ostringstream suffix;
  833. suffix << std::setfill('0') << std::setw(2) << index;
  834. spi.filename = prefix + suffix.str();
  835. faction.puzzleMap.push_back(spi);
  836. }
  837. assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES);
  838. }
  839. CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode & source, const std::string & identifier, size_t index)
  840. {
  841. assert(identifier.find(':') == std::string::npos);
  842. auto * faction = new CFaction();
  843. faction->index = static_cast<FactionID>(index);
  844. faction->modScope = scope;
  845. faction->identifier = identifier;
  846. VLC->generaltexth->registerString(scope, faction->getNameTextID(), source["name"].String());
  847. faction->creatureBg120 = source["creatureBackground"]["120px"].String();
  848. faction->creatureBg130 = source["creatureBackground"]["130px"].String();
  849. faction->boatType = EBoatId::NONE;
  850. if (!source["boat"].isNull())
  851. {
  852. VLC->modh->identifiers.requestIdentifier("core:boat", source["boat"], [=](int32_t boatTypeID)
  853. {
  854. faction->boatType = BoatId(boatTypeID);
  855. });
  856. }
  857. int alignment = vstd::find_pos(GameConstants::ALIGNMENT_NAMES, source["alignment"].String());
  858. if (alignment == -1)
  859. faction->alignment = EAlignment::NEUTRAL;
  860. else
  861. faction->alignment = static_cast<EAlignment>(alignment);
  862. auto preferUndergound = source["preferUndergroundPlacement"];
  863. faction->preferUndergroundPlacement = preferUndergound.isNull() ? false : preferUndergound.Bool();
  864. // NOTE: semi-workaround - normally, towns are supposed to have native terrains.
  865. // Towns without one are exceptions. So, vcmi requires nativeTerrain to be defined
  866. // But allows it to be defined with explicit value of "none" if town should not have native terrain
  867. // This is better than allowing such terrain-less towns silently, leading to issues with RMG
  868. faction->nativeTerrain = ETerrainId::NONE;
  869. if ( !source["nativeTerrain"].isNull() && source["nativeTerrain"].String() != "none")
  870. {
  871. VLC->modh->identifiers.requestIdentifier("terrain", source["nativeTerrain"], [=](int32_t index){
  872. faction->nativeTerrain = TerrainId(index);
  873. auto const & terrain = VLC->terrainTypeHandler->getById(faction->nativeTerrain);
  874. if (!terrain->isSurface() && !terrain->isUnderground())
  875. logMod->warn("Faction %s has terrain %s as native, but terrain is not suitable for either surface or subterranean layers!", faction->getJsonKey(), terrain->getJsonKey());
  876. });
  877. }
  878. if (!source["town"].isNull())
  879. {
  880. faction->town = new CTown();
  881. faction->town->faction = faction;
  882. loadTown(faction->town, source["town"]);
  883. }
  884. else
  885. faction->town = nullptr;
  886. if (!source["puzzleMap"].isNull())
  887. loadPuzzle(*faction, source["puzzleMap"]);
  888. return faction;
  889. }
  890. void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  891. {
  892. auto * object = loadFromJson(scope, data, name, objects.size());
  893. objects.emplace_back(object);
  894. if (object->town)
  895. {
  896. auto & info = object->town->clientInfo;
  897. info.icons[0][0] = 8 + object->index * 4 + 0;
  898. info.icons[0][1] = 8 + object->index * 4 + 1;
  899. info.icons[1][0] = 8 + object->index * 4 + 2;
  900. info.icons[1][1] = 8 + object->index * 4 + 3;
  901. VLC->modh->identifiers.requestIdentifier(scope, "object", "town", [=](si32 index)
  902. {
  903. // register town once objects are loaded
  904. JsonNode config = data["town"]["mapObject"];
  905. config["faction"].String() = name;
  906. config["faction"].meta = scope;
  907. if (config.meta.empty())// MODS COMPATIBILITY FOR 0.96
  908. config.meta = scope;
  909. VLC->objtypeh->loadSubObject(object->identifier, config, index, object->index);
  910. // MODS COMPATIBILITY FOR 0.96
  911. const auto & advMap = data["town"]["adventureMap"];
  912. if (!advMap.isNull())
  913. {
  914. logMod->warn("Outdated town mod. Will try to generate valid templates out of fort");
  915. JsonNode config;
  916. config["animation"] = advMap["castle"];
  917. VLC->objtypeh->getHandlerFor(index, object->index)->addTemplate(config);
  918. }
  919. });
  920. }
  921. registerObject(scope, "faction", name, object->index);
  922. }
  923. void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  924. {
  925. auto * object = loadFromJson(scope, data, name, index);
  926. if (objects.size() > index)
  927. assert(objects[index] == nullptr); // ensure that this id was not loaded before
  928. else
  929. objects.resize(index + 1);
  930. objects[index] = object;
  931. if (object->town)
  932. {
  933. auto & info = object->town->clientInfo;
  934. info.icons[0][0] = (GameConstants::F_NUMBER + object->index) * 2 + 0;
  935. info.icons[0][1] = (GameConstants::F_NUMBER + object->index) * 2 + 1;
  936. info.icons[1][0] = object->index * 2 + 0;
  937. info.icons[1][1] = object->index * 2 + 1;
  938. VLC->modh->identifiers.requestIdentifier(scope, "object", "town", [=](si32 index)
  939. {
  940. // register town once objects are loaded
  941. JsonNode config = data["town"]["mapObject"];
  942. config["faction"].String() = name;
  943. config["faction"].meta = scope;
  944. VLC->objtypeh->loadSubObject(object->identifier, config, index, object->index);
  945. });
  946. }
  947. registerObject(scope, "faction", name, object->index);
  948. }
  949. void CTownHandler::loadRandomFaction()
  950. {
  951. static const ResourceID randomFactionPath("config/factions/random.json");
  952. JsonNode randomFactionJson(randomFactionPath);
  953. randomFactionJson.setMeta(CModHandler::scopeBuiltin(), true);
  954. loadBuildings(randomTown, randomFactionJson["random"]["town"]["buildings"]);
  955. }
  956. void CTownHandler::loadCustom()
  957. {
  958. loadRandomFaction();
  959. }
  960. void CTownHandler::afterLoadFinalization()
  961. {
  962. initializeRequirements();
  963. initializeOverridden();
  964. initializeWarMachines();
  965. }
  966. void CTownHandler::initializeRequirements()
  967. {
  968. // must be done separately after all ID's are known
  969. for (auto & requirement : requirementsToLoad)
  970. {
  971. requirement.building->requirements = CBuilding::TRequired(requirement.json, [&](const JsonNode & node) -> BuildingID
  972. {
  973. if (node.Vector().size() > 1)
  974. {
  975. logMod->warn("Unexpected length of town buildings requirements: %d", node.Vector().size());
  976. logMod->warn("Entry contains: ");
  977. logMod->warn(node.toJson());
  978. }
  979. return BuildingID(VLC->modh->identifiers.getIdentifier(requirement.town->getBuildingScope(), node.Vector()[0]).value());
  980. });
  981. }
  982. requirementsToLoad.clear();
  983. }
  984. void CTownHandler::initializeOverridden()
  985. {
  986. for(auto & bidHelper : overriddenBidsToLoad)
  987. {
  988. auto jsonNode = bidHelper.json;
  989. auto scope = bidHelper.town->getBuildingScope();
  990. for(const auto & b : jsonNode.Vector())
  991. {
  992. auto bid = BuildingID(VLC->modh->identifiers.getIdentifier(scope, b).value());
  993. bidHelper.building->overrideBids.insert(bid);
  994. }
  995. }
  996. overriddenBidsToLoad.clear();
  997. }
  998. void CTownHandler::initializeWarMachines()
  999. {
  1000. // must be done separately after all objects are loaded
  1001. for(auto & p : warMachinesToLoad)
  1002. {
  1003. CTown * t = p.first;
  1004. JsonNode creatureKey = p.second;
  1005. auto ret = VLC->modh->identifiers.getIdentifier("creature", creatureKey, false);
  1006. if(ret)
  1007. {
  1008. const CCreature * creature = CreatureID(*ret).toCreature();
  1009. t->warMachine = creature->warMachine;
  1010. }
  1011. }
  1012. warMachinesToLoad.clear();
  1013. }
  1014. std::vector<bool> CTownHandler::getDefaultAllowed() const
  1015. {
  1016. std::vector<bool> allowedFactions;
  1017. allowedFactions.reserve(objects.size());
  1018. for(auto town : objects)
  1019. {
  1020. allowedFactions.push_back(town->town != nullptr);
  1021. }
  1022. return allowedFactions;
  1023. }
  1024. std::set<FactionID> CTownHandler::getAllowedFactions(bool withTown) const
  1025. {
  1026. std::set<FactionID> allowedFactions;
  1027. std::vector<bool> allowed;
  1028. if (withTown)
  1029. allowed = getDefaultAllowed();
  1030. else
  1031. allowed.resize( objects.size(), true);
  1032. for (size_t i=0; i<allowed.size(); i++)
  1033. if (allowed[i])
  1034. allowedFactions.insert(static_cast<FactionID>(i));
  1035. return allowedFactions;
  1036. }
  1037. const std::vector<std::string> & CTownHandler::getTypeNames() const
  1038. {
  1039. static const std::vector<std::string> typeNames = { "faction", "town" };
  1040. return typeNames;
  1041. }
  1042. VCMI_LIB_NAMESPACE_END