2
0

MiscObjects.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. /*
  2. * MiscObjects.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 "MiscObjects.h"
  12. #include "../bonuses/Propagators.h"
  13. #include "../callback/CGameInfoCallback.h"
  14. #include "../callback/IGameEventCallback.h"
  15. #include "../constants/StringConstants.h"
  16. #include "../entities/artifact/ArtifactUtils.h"
  17. #include "../entities/artifact/CArtifact.h"
  18. #include "../CConfigHandler.h"
  19. #include "../texts/CGeneralTextHandler.h"
  20. #include "../CSoundBase.h"
  21. #include "../CSkillHandler.h"
  22. #include "../spells/CSpellHandler.h"
  23. #include "../gameState/CGameState.h"
  24. #include "../mapping/CMap.h"
  25. #include "../CPlayerState.h"
  26. #include "../StartInfo.h"
  27. #include "../serializer/JsonSerializeFormat.h"
  28. #include "../mapObjectConstructors/AObjectTypeHandler.h"
  29. #include "../mapObjectConstructors/CObjectClassesHandler.h"
  30. #include "../mapObjects/CGHeroInstance.h"
  31. #include "../modding/ModScope.h"
  32. #include "../networkPacks/PacksForClient.h"
  33. #include "../networkPacks/PacksForClientBattle.h"
  34. #include "../networkPacks/StackLocation.h"
  35. #include "../lib/gameState/UpgradeInfo.h"
  36. #include <vstd/RNG.h>
  37. VCMI_LIB_NAMESPACE_BEGIN
  38. ///helpers
  39. static std::string visitedTxt(const bool visited)
  40. {
  41. int id = visited ? 352 : 353;
  42. return LIBRARY->generaltexth->allTexts[id];
  43. }
  44. void CTeamVisited::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
  45. {
  46. if(what == ObjProperty::VISITED)
  47. players.insert(identifier.as<PlayerColor>());
  48. }
  49. bool CTeamVisited::wasVisited(PlayerColor player) const
  50. {
  51. return wasVisited(cb->getPlayerState(player)->team);
  52. }
  53. bool CTeamVisited::wasVisited(const CGHeroInstance * h) const
  54. {
  55. return wasVisited(h->tempOwner);
  56. }
  57. bool CTeamVisited::wasVisited(const TeamID & team) const
  58. {
  59. for(const auto & i : players)
  60. {
  61. if(cb->getPlayerState(i)->team == team)
  62. return true;
  63. }
  64. return false;
  65. }
  66. //CGMine
  67. void CGMine::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  68. {
  69. auto relations = cb->gameState().getPlayerRelations(h->tempOwner, tempOwner);
  70. if(relations == PlayerRelations::SAME_PLAYER) //we're visiting our mine
  71. {
  72. gameEvents.showGarrisonDialog(id,h->id,true);
  73. return;
  74. }
  75. else if (relations == PlayerRelations::ALLIES)//ally
  76. return;
  77. if(stacksCount()) //Mine is guarded
  78. {
  79. BlockingDialog ynd(true,false);
  80. ynd.player = h->tempOwner;
  81. ynd.text.appendLocalString(EMetaText::ADVOB_TXT, isAbandoned() ? 84 : 187);
  82. gameEvents.showBlockingDialog(this, &ynd);
  83. return;
  84. }
  85. flagMine(gameEvents, h->tempOwner);
  86. }
  87. void CGMine::initObj(vstd::RNG & rand)
  88. {
  89. if(isAbandoned())
  90. {
  91. //set guardians
  92. int howManyTroglodytes = rand.nextInt(100, 199);
  93. auto troglodytes = std::make_unique<CStackInstance>(cb, CreatureID::TROGLODYTES, howManyTroglodytes);
  94. putStack(SlotID(0), std::move(troglodytes));
  95. assert(!abandonedMineResources.empty());
  96. if (!abandonedMineResources.empty())
  97. {
  98. producedResource = *RandomGeneratorUtil::nextItem(abandonedMineResources, rand);
  99. }
  100. else
  101. {
  102. logGlobal->error("Abandoned mine at (%s) has no valid resource candidates!", anchorPos().toString());
  103. producedResource = GameResID::GOLD;
  104. }
  105. }
  106. else
  107. {
  108. producedResource = GameResID(getObjTypeIndex().getNum());
  109. }
  110. producedQuantity = defaultResProduction();
  111. }
  112. bool CGMine::isAbandoned() const
  113. {
  114. return subID.getNum() >= 7;
  115. }
  116. const IOwnableObject * CGMine::asOwnable() const
  117. {
  118. return this;
  119. }
  120. std::vector<CreatureID> CGMine::providedCreatures() const
  121. {
  122. return {};
  123. }
  124. ResourceSet CGMine::dailyIncome() const
  125. {
  126. ResourceSet result;
  127. result[producedResource] += defaultResProduction();
  128. const auto & playerSettings = cb->getPlayerSettings(getOwner());
  129. result.applyHandicap(playerSettings->handicap.percentIncome);
  130. return result;
  131. }
  132. std::string CGMine::getObjectName() const
  133. {
  134. return LIBRARY->generaltexth->translate("core.minename", getObjTypeIndex());
  135. }
  136. std::string CGMine::getHoverText(PlayerColor player) const
  137. {
  138. std::string hoverName = CArmedInstance::getHoverText(player);
  139. if (tempOwner != PlayerColor::NEUTRAL)
  140. hoverName += "\n(" + LIBRARY->generaltexth->restypes[producedResource.getNum()] + ")";
  141. if(stacksCount())
  142. {
  143. hoverName += "\n";
  144. hoverName += LIBRARY->generaltexth->allTexts[202]; //Guarded by
  145. hoverName += " ";
  146. hoverName += getArmyDescription();
  147. }
  148. return hoverName;
  149. }
  150. void CGMine::flagMine(IGameEventCallback & gameEvents, const PlayerColor & player) const
  151. {
  152. assert(tempOwner != player);
  153. gameEvents.setOwner(this, player); //not ours? flag it!
  154. InfoWindow iw;
  155. iw.type = EInfoWindowMode::AUTO;
  156. iw.text.appendTextID(TextIdentifier("core.mineevnt", producedResource.getNum()).get()); //not use subID, abandoned mines uses default mine texts
  157. iw.player = player;
  158. iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, getProducedQuantity());
  159. gameEvents.showInfoDialog(&iw);
  160. }
  161. ui32 CGMine::defaultResProduction() const
  162. {
  163. switch(producedResource.toEnum())
  164. {
  165. case EGameResID::WOOD:
  166. case EGameResID::ORE:
  167. return 2;
  168. case EGameResID::GOLD:
  169. return 1000;
  170. default:
  171. return 1;
  172. }
  173. }
  174. ui32 CGMine::getProducedQuantity() const
  175. {
  176. auto * playerSettings = cb->getPlayerSettings(getOwner());
  177. // always round up income - we don't want mines to always produce zero if handicap in use
  178. return vstd::divideAndCeil(producedQuantity * playerSettings->handicap.percentIncome, 100);
  179. }
  180. void CGMine::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  181. {
  182. if(result.winner == BattleSide::ATTACKER) //attacker won
  183. {
  184. if(isAbandoned())
  185. {
  186. hero->showInfoDialog(gameEvents, 85);
  187. }
  188. flagMine(gameEvents, hero->tempOwner);
  189. }
  190. }
  191. void CGMine::blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const
  192. {
  193. if(answer)
  194. gameEvents.startBattle(hero, this);
  195. }
  196. void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
  197. {
  198. CArmedInstance::serializeJsonOptions(handler);
  199. serializeJsonOwner(handler);
  200. if(isAbandoned())
  201. {
  202. if(handler.saving)
  203. {
  204. JsonNode node;
  205. for(const auto & resID : abandonedMineResources)
  206. node.Vector().emplace_back(GameConstants::RESOURCE_NAMES[resID.getNum()]);
  207. handler.serializeRaw("possibleResources", node, std::nullopt);
  208. }
  209. else
  210. {
  211. auto guard = handler.enterArray("possibleResources");
  212. const JsonNode & node = handler.getCurrent();
  213. auto names = node.convertTo<std::vector<std::string>>();
  214. for(const std::string & s : names)
  215. {
  216. int raw_res = vstd::find_pos(GameConstants::RESOURCE_NAMES, s);
  217. if(raw_res < 0)
  218. logGlobal->error("Invalid resource name: %s", s);
  219. else
  220. abandonedMineResources.emplace(raw_res);
  221. }
  222. }
  223. }
  224. }
  225. bool CGTeleport::isEntrance() const
  226. {
  227. return type == BOTH || type == ENTRANCE;
  228. }
  229. bool CGTeleport::isExit() const
  230. {
  231. return type == BOTH || type == EXIT;
  232. }
  233. bool CGTeleport::isChannelEntrance(const ObjectInstanceID & id) const
  234. {
  235. return vstd::contains(getAllEntrances(), id);
  236. }
  237. bool CGTeleport::isChannelExit(const ObjectInstanceID & id) const
  238. {
  239. return vstd::contains(getAllExits(), id);
  240. }
  241. std::vector<ObjectInstanceID> CGTeleport::getAllEntrances(bool excludeCurrent) const
  242. {
  243. auto ret = cb->getTeleportChannelEntrances(channel);
  244. if(excludeCurrent)
  245. vstd::erase_if_present(ret, id);
  246. return ret;
  247. }
  248. std::vector<ObjectInstanceID> CGTeleport::getAllExits(bool excludeCurrent) const
  249. {
  250. auto ret = cb->getTeleportChannelExits(channel);
  251. if(excludeCurrent)
  252. vstd::erase_if_present(ret, id);
  253. return ret;
  254. }
  255. ObjectInstanceID CGTeleport::getRandomExit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  256. {
  257. auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true));
  258. if(!passableExits.empty())
  259. return *RandomGeneratorUtil::nextItem(passableExits, gameEvents.getRandomGenerator());
  260. return ObjectInstanceID();
  261. }
  262. bool CGTeleport::isTeleport(const CGObjectInstance * obj)
  263. {
  264. return dynamic_cast<const CGTeleport *>(obj) != nullptr;
  265. }
  266. bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst)
  267. {
  268. return src && dst && src->isChannelExit(dst->id);
  269. }
  270. bool CGTeleport::isConnected(const CGObjectInstance * src, const CGObjectInstance * dst)
  271. {
  272. const auto * srcObj = dynamic_cast<const CGTeleport *>(src);
  273. const auto * dstObj = dynamic_cast<const CGTeleport *>(dst);
  274. return isConnected(srcObj, dstObj);
  275. }
  276. bool CGTeleport::isExitPassable(const CGameState & gs, const CGHeroInstance * h, const CGObjectInstance * obj)
  277. {
  278. ObjectInstanceID topObjectID = gs.getMap().getTile(obj->visitablePos()).topVisitableObj();
  279. const CGObjectInstance * topObject = gs.getObjInstance(topObjectID);
  280. if(topObject->ID == Obj::HERO)
  281. {
  282. if(h->id == topObject->id) // Just to be sure it's won't happen.
  283. return false;
  284. // Check if it's friendly hero or not
  285. if(gs.getPlayerRelations(h->tempOwner, topObject->tempOwner) != PlayerRelations::ENEMIES)
  286. {
  287. // Exchange between heroes only possible via subterranean gates
  288. if(!dynamic_cast<const CGSubterraneanGate *>(obj))
  289. return false;
  290. }
  291. }
  292. return true;
  293. }
  294. std::vector<ObjectInstanceID> CGTeleport::getPassableExits(const CGameState & gs, const CGHeroInstance * h, std::vector<ObjectInstanceID> exits)
  295. {
  296. vstd::erase_if(exits, [&](const ObjectInstanceID & exit) -> bool
  297. {
  298. return !isExitPassable(gs, h, gs.getObj(exit));
  299. });
  300. return exits;
  301. }
  302. void CGTeleport::addToChannel(std::map<TeleportChannelID, std::shared_ptr<TeleportChannel> > &channelsList, const CGTeleport * obj)
  303. {
  304. std::shared_ptr<TeleportChannel> tc;
  305. if(channelsList.find(obj->channel) == channelsList.end())
  306. {
  307. tc = std::make_shared<TeleportChannel>();
  308. channelsList.insert(std::make_pair(obj->channel, tc));
  309. }
  310. else
  311. tc = channelsList[obj->channel];
  312. if(obj->isEntrance() && !vstd::contains(tc->entrances, obj->id))
  313. tc->entrances.push_back(obj->id);
  314. if(obj->isExit() && !vstd::contains(tc->exits, obj->id))
  315. tc->exits.push_back(obj->id);
  316. if(!tc->entrances.empty() && !tc->exits.empty()
  317. && (tc->entrances.size() != 1 || tc->entrances != tc->exits))
  318. {
  319. tc->passability = TeleportChannel::PASSABLE;
  320. }
  321. }
  322. TeleportChannelID CGMonolith::findMeChannel(const std::vector<Obj> & IDs, MapObjectSubID SubID) const
  323. {
  324. for(auto teleportObj : cb->gameState().getMap().getObjects<CGMonolith>())
  325. {
  326. if(vstd::contains(IDs, teleportObj->ID) && teleportObj->subID == SubID)
  327. return teleportObj->channel;
  328. }
  329. return TeleportChannelID();
  330. }
  331. void CGMonolith::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  332. {
  333. TeleportDialog td(h->id, channel);
  334. if(isEntrance())
  335. {
  336. if(cb->isTeleportChannelBidirectional(channel) && 1 < cb->getTeleportChannelExits(channel).size())
  337. {
  338. auto exits = cb->getTeleportChannelExits(channel);
  339. for(const auto & exit : exits)
  340. {
  341. td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos()));
  342. }
  343. }
  344. if(cb->isTeleportChannelImpassable(channel))
  345. {
  346. logGlobal->debug("Cannot find corresponding exit monolith for %d at %s", id.getNum(), anchorPos().toString());
  347. td.impassable = true;
  348. }
  349. else if(getRandomExit(gameEvents, h) == ObjectInstanceID())
  350. logGlobal->debug("All exits blocked for monolith %d at %s", id.getNum(), anchorPos().toString());
  351. }
  352. else
  353. h->showInfoDialog(gameEvents, 70);
  354. gameEvents.showTeleportDialog(&td);
  355. }
  356. void CGMonolith::teleportDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const
  357. {
  358. int3 dPos;
  359. auto randomExit = getRandomExit(gameEvents, hero);
  360. auto realExits = getAllExits(true);
  361. if(!isEntrance() // Do nothing if hero visited exit only object
  362. || (exits.empty() && realExits.empty()) // Do nothing if there no exits on this channel
  363. || ObjectInstanceID() == randomExit) // Do nothing if all exits are blocked by friendly hero and it's not subterranean gate
  364. {
  365. return;
  366. }
  367. else if(vstd::isValidIndex(exits, answer))
  368. dPos = exits[answer].second;
  369. else
  370. dPos = cb->getObj(randomExit)->visitablePos();
  371. gameEvents.moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
  372. }
  373. void CGMonolith::initObj(vstd::RNG & rand)
  374. {
  375. std::vector<Obj> IDs;
  376. IDs.push_back(ID);
  377. switch(ID.toEnum())
  378. {
  379. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  380. type = ENTRANCE;
  381. IDs.emplace_back(Obj::MONOLITH_ONE_WAY_EXIT);
  382. break;
  383. case Obj::MONOLITH_ONE_WAY_EXIT:
  384. type = EXIT;
  385. IDs.emplace_back(Obj::MONOLITH_ONE_WAY_ENTRANCE);
  386. break;
  387. case Obj::MONOLITH_TWO_WAY:
  388. default:
  389. type = BOTH;
  390. break;
  391. }
  392. channel = findMeChannel(IDs, subID);
  393. if(channel == TeleportChannelID())
  394. channel = TeleportChannelID(static_cast<si32>(cb->gameState().getMap().teleportChannels.size()));
  395. addToChannel(cb->gameState().getMap().teleportChannels, this);
  396. }
  397. void CGSubterraneanGate::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  398. {
  399. TeleportDialog td(h->id, channel);
  400. if(cb->isTeleportChannelImpassable(channel))
  401. {
  402. h->showInfoDialog(gameEvents, 153);//Just inside the entrance you find a large pile of rubble blocking the tunnel. You leave discouraged.
  403. logGlobal->debug("Cannot find exit subterranean gate for %d at %s", id.getNum(), anchorPos().toString());
  404. td.impassable = true;
  405. }
  406. else
  407. {
  408. auto exit = getRandomExit(gameEvents, h);
  409. td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos()));
  410. }
  411. gameEvents.showTeleportDialog(&td);
  412. }
  413. void CGSubterraneanGate::initObj(vstd::RNG & rand)
  414. {
  415. type = BOTH;
  416. }
  417. void CGSubterraneanGate::postInit(CGameInfoCallback * cb) //matches subterranean gates into pairs
  418. {
  419. //split on underground and surface gates
  420. std::vector<CGSubterraneanGate *> gatesSplit[2]; //surface and underground gates
  421. for(auto gate : cb->gameState().getMap().getObjects<CGSubterraneanGate>())
  422. {
  423. gatesSplit[gate->visitablePos().z].push_back(gate);
  424. }
  425. //sort by position
  426. std::sort(gatesSplit[0].begin(), gatesSplit[0].end(), [](const CGObjectInstance * a, const CGObjectInstance * b)
  427. {
  428. return a->visitablePos() < b->visitablePos();
  429. });
  430. auto assignToChannel = [&](CGSubterraneanGate * obj)
  431. {
  432. if(obj->channel == TeleportChannelID())
  433. { // if object not linked to channel then create new channel
  434. obj->channel = TeleportChannelID(static_cast<si32>(cb->gameState().getMap().teleportChannels.size()));
  435. addToChannel(cb->gameState().getMap().teleportChannels, obj);
  436. }
  437. };
  438. for(size_t i = 0; i < gatesSplit[0].size(); i++)
  439. {
  440. CGSubterraneanGate * objCurrent = gatesSplit[0][i];
  441. //find nearest underground exit
  442. std::pair<int, si32> best(-1, std::numeric_limits<si32>::max()); //pair<pos_in_vector, distance^2>
  443. for(int j = 0; j < gatesSplit[1].size(); j++)
  444. {
  445. CGSubterraneanGate *checked = gatesSplit[1][j];
  446. if(checked->channel != TeleportChannelID())
  447. continue;
  448. si32 hlp = checked->visitablePos().dist2dSQ(objCurrent->visitablePos());
  449. if(hlp < best.second)
  450. {
  451. best.first = j;
  452. best.second = hlp;
  453. }
  454. }
  455. assignToChannel(objCurrent);
  456. if(best.first >= 0) //found pair
  457. {
  458. gatesSplit[1][best.first]->channel = objCurrent->channel;
  459. addToChannel(cb->gameState().getMap().teleportChannels, gatesSplit[1][best.first]);
  460. }
  461. }
  462. // we should assign empty channels to underground gates if they don't have matching overground gates
  463. for(auto & i : gatesSplit[1])
  464. assignToChannel(i);
  465. }
  466. void CGWhirlpool::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  467. {
  468. TeleportDialog td(h->id, channel);
  469. if(cb->isTeleportChannelImpassable(channel))
  470. {
  471. logGlobal->debug("Cannot find exit whirlpool for %d at %s", id.getNum(), anchorPos().toString());
  472. td.impassable = true;
  473. }
  474. else if(getRandomExit(gameEvents, h) == ObjectInstanceID())
  475. logGlobal->debug("All exits are blocked for whirlpool %d at %s", id.getNum(), anchorPos().toString());
  476. if(!isProtected(h))
  477. {
  478. SlotID targetstack = h->Slots().begin()->first; //slot numbers may vary
  479. for(auto i = h->Slots().rbegin(); i != h->Slots().rend(); i++)
  480. {
  481. if(h->getPower(targetstack) > h->getPower(i->first))
  482. targetstack = (i->first);
  483. }
  484. auto countToTake = static_cast<TQuantity>(h->getStackCount(targetstack) * 0.5);
  485. vstd::amax(countToTake, 1);
  486. InfoWindow iw;
  487. iw.type = EInfoWindowMode::AUTO;
  488. iw.player = h->tempOwner;
  489. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 168);
  490. iw.components.emplace_back(ComponentType::CREATURE, h->getCreature(targetstack)->getId(), -countToTake);
  491. gameEvents.showInfoDialog(&iw);
  492. gameEvents.changeStackCount(StackLocation(h->id, targetstack), -countToTake);
  493. }
  494. else
  495. {
  496. auto exits = getAllExits();
  497. for(const auto & exit : exits)
  498. {
  499. auto blockedPosList = cb->getObj(exit)->getBlockedPos();
  500. for(const auto & bPos : blockedPosList)
  501. td.exits.push_back(std::make_pair(exit, bPos));
  502. }
  503. }
  504. gameEvents.showTeleportDialog(&td);
  505. }
  506. void CGWhirlpool::teleportDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const
  507. {
  508. int3 dPos;
  509. auto realExits = getAllExits();
  510. if(exits.empty() && realExits.empty())
  511. return;
  512. else if(vstd::isValidIndex(exits, answer))
  513. dPos = exits[answer].second;
  514. else
  515. {
  516. auto exit = getRandomExit(gameEvents, hero);
  517. if(exit == ObjectInstanceID())
  518. return;
  519. const auto * obj = cb->getObj(exit);
  520. std::set<int3> tiles = obj->getBlockedPos();
  521. dPos = *RandomGeneratorUtil::nextItem(tiles, gameEvents.getRandomGenerator());
  522. }
  523. gameEvents.moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
  524. }
  525. bool CGWhirlpool::isProtected(const CGHeroInstance * h)
  526. {
  527. return h->hasBonusOfType(BonusType::WHIRLPOOL_PROTECTION)
  528. || (h->stacksCount() == 1 && h->Slots().begin()->second->getCount() == 1)
  529. || (h->stacksCount() == 0 && h->getCommander() && h->getCommander()->alive);
  530. }
  531. const CArtifactInstance * CGArtifact::getArtifactInstance() const
  532. {
  533. return cb->getArtInstance(storedArtifact);
  534. }
  535. ArtifactID CGArtifact::getArtifactType() const
  536. {
  537. if(ID == Obj::SPELL_SCROLL)
  538. return ArtifactID::SPELL_SCROLL;
  539. else
  540. return getObjTypeIndex().getNum();
  541. }
  542. void CGArtifact::pickRandomObject(vstd::RNG & rand)
  543. {
  544. switch(ID.toEnum())
  545. {
  546. case MapObjectID::RANDOM_ART:
  547. subID = cb->gameState().pickRandomArtifact(rand, std::nullopt);
  548. break;
  549. case MapObjectID::RANDOM_TREASURE_ART:
  550. subID = cb->gameState().pickRandomArtifact(rand, EArtifactClass::ART_TREASURE);
  551. break;
  552. case MapObjectID::RANDOM_MINOR_ART:
  553. subID = cb->gameState().pickRandomArtifact(rand, EArtifactClass::ART_MINOR);
  554. break;
  555. case MapObjectID::RANDOM_MAJOR_ART:
  556. subID = cb->gameState().pickRandomArtifact(rand, EArtifactClass::ART_MAJOR);
  557. break;
  558. case MapObjectID::RANDOM_RELIC_ART:
  559. subID = cb->gameState().pickRandomArtifact(rand, EArtifactClass::ART_RELIC);
  560. break;
  561. }
  562. if (ID != MapObjectID::SPELL_SCROLL && ID != MapObjectID::ARTIFACT)
  563. {
  564. ID = MapObjectID::ARTIFACT;
  565. setType(ID, subID);
  566. }
  567. else if (ID != MapObjectID::SPELL_SCROLL)
  568. ID = MapObjectID::ARTIFACT;
  569. }
  570. void CGArtifact::setArtifactInstance(const CArtifactInstance * instance)
  571. {
  572. storedArtifact = instance->getId();
  573. }
  574. void CGArtifact::initObj(vstd::RNG & rand)
  575. {
  576. blockVisit = true;
  577. if(ID == Obj::ARTIFACT)
  578. {
  579. assert(getArtifactType().hasValue());
  580. if (!storedArtifact.hasValue())
  581. setArtifactInstance(cb->gameState().createArtifact(getArtifactType()));
  582. }
  583. if(ID == Obj::SPELL_SCROLL)
  584. subID = 1;
  585. assert(getArtifactInstance()->getType());
  586. assert(!getArtifactInstance()->getParentNodes().empty());
  587. }
  588. std::string CGArtifact::getObjectName() const
  589. {
  590. return getArtifactType().toEntity(LIBRARY)->getNameTranslated();
  591. }
  592. std::string CGArtifact::getPopupText(PlayerColor player) const
  593. {
  594. if (settings["general"]["enableUiEnhancements"].Bool())
  595. {
  596. std::string description = getArtifactType().toEntity(LIBRARY)->getDescriptionTranslated();
  597. if (getArtifactType() == ArtifactID::SPELL_SCROLL)
  598. ArtifactUtils::insertScrrollSpellName(description, SpellID::NONE); // erase text placeholder
  599. return description;
  600. }
  601. else
  602. return getObjectName();
  603. }
  604. std::string CGArtifact::getPopupText(const CGHeroInstance * hero) const
  605. {
  606. return getPopupText(hero->getOwner());
  607. }
  608. std::vector<Component> CGArtifact::getPopupComponents(PlayerColor player) const
  609. {
  610. return {
  611. Component(ComponentType::ARTIFACT, getArtifactType())
  612. };
  613. }
  614. void CGArtifact::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  615. {
  616. if(!stacksCount())
  617. {
  618. InfoWindow iw;
  619. iw.type = EInfoWindowMode::AUTO;
  620. iw.player = h->tempOwner;
  621. if(getArtifactInstance()->getType()->canBePutAt(h))
  622. {
  623. switch (ID.toEnum())
  624. {
  625. case Obj::ARTIFACT:
  626. {
  627. iw.components.emplace_back(ComponentType::ARTIFACT, getArtifactType());
  628. if(!message.empty())
  629. iw.text = message;
  630. else
  631. iw.text.appendTextID(getArtifactType().toArtifact()->getEventTextID());
  632. }
  633. break;
  634. case Obj::SPELL_SCROLL:
  635. {
  636. SpellID spell = getArtifactInstance()->getScrollSpellID();
  637. iw.components.emplace_back(ComponentType::SPELL, spell);
  638. if(!message.empty())
  639. iw.text = message;
  640. else
  641. {
  642. iw.text.appendLocalString(EMetaText::ADVOB_TXT,135);
  643. iw.text.replaceName(spell);
  644. }
  645. }
  646. break;
  647. }
  648. }
  649. else
  650. {
  651. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 2);
  652. }
  653. gameEvents.showInfoDialog(&iw);
  654. pick(gameEvents, h);
  655. }
  656. else
  657. {
  658. switch(ID.toEnum())
  659. {
  660. case Obj::ARTIFACT:
  661. {
  662. BlockingDialog ynd(true,false);
  663. ynd.player = h->getOwner();
  664. if(!message.empty())
  665. ynd.text = message;
  666. else
  667. {
  668. // TODO: Guard text is more complex in H3, see mantis issue 2325 for details
  669. ynd.text.appendLocalString(EMetaText::GENERAL_TXT, 420);
  670. ynd.text.replaceRawString("");
  671. ynd.text.replaceRawString(getArmyDescription());
  672. ynd.text.replaceLocalString(EMetaText::GENERAL_TXT, 43); // creatures
  673. }
  674. gameEvents.showBlockingDialog(this, &ynd);
  675. }
  676. break;
  677. case Obj::SPELL_SCROLL:
  678. {
  679. if(!message.empty())
  680. {
  681. BlockingDialog ynd(true,false);
  682. ynd.player = h->getOwner();
  683. ynd.text = message;
  684. gameEvents.showBlockingDialog(this, &ynd);
  685. }
  686. else
  687. blockingDialogAnswered(gameEvents, h, true);
  688. }
  689. break;
  690. }
  691. }
  692. }
  693. void CGArtifact::pick(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  694. {
  695. if(gameEvents.putArtifact(ArtifactLocation(h->id, ArtifactPosition::FIRST_AVAILABLE), getArtifactInstance()->getId()))
  696. gameEvents.removeObject(this, h->getOwner());
  697. }
  698. BattleField CGArtifact::getBattlefield() const
  699. {
  700. return BattleField::NONE;
  701. }
  702. void CGArtifact::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  703. {
  704. if(result.winner == BattleSide::ATTACKER) //attacker won
  705. pick(gameEvents, hero);
  706. }
  707. void CGArtifact::blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const
  708. {
  709. if(answer)
  710. gameEvents.startBattle(hero, this);
  711. }
  712. void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
  713. {
  714. handler.serializeStruct("guardMessage", message);
  715. CArmedInstance::serializeJsonOptions(handler);
  716. if(!handler.saving && !handler.getCurrent()["guards"].Vector().empty())
  717. CCreatureSet::serializeJson(handler, "guards", 7);
  718. if(handler.saving && ID == Obj::SPELL_SCROLL)
  719. {
  720. const auto & b = getArtifactInstance()->getFirstBonus(Selector::type()(BonusType::SPELL));
  721. SpellID spellId(b->subtype.as<SpellID>());
  722. handler.serializeId("spell", spellId, SpellID::NONE);
  723. }
  724. }
  725. void CGSignBottle::initObj(vstd::RNG & rand)
  726. {
  727. //if no text is set than we pick random from the predefined ones
  728. if(message.empty())
  729. {
  730. auto vector = LIBRARY->generaltexth->findStringsWithPrefix("core.randsign");
  731. std::string messageIdentifier = *RandomGeneratorUtil::nextItem(vector, rand);
  732. message.appendTextID(messageIdentifier);
  733. }
  734. if(ID == Obj::OCEAN_BOTTLE)
  735. {
  736. blockVisit = true;
  737. }
  738. }
  739. void CGSignBottle::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  740. {
  741. InfoWindow iw;
  742. iw.player = h->getOwner();
  743. iw.text = message;
  744. gameEvents.showInfoDialog(&iw);
  745. if(ID == Obj::OCEAN_BOTTLE)
  746. gameEvents.removeObject(this, h->getOwner());
  747. }
  748. void CGSignBottle::serializeJsonOptions(JsonSerializeFormat& handler)
  749. {
  750. handler.serializeStruct("text", message);
  751. }
  752. const IOwnableObject * CGGarrison::asOwnable() const
  753. {
  754. return this;
  755. }
  756. ResourceSet CGGarrison::dailyIncome() const
  757. {
  758. return {};
  759. }
  760. std::vector<CreatureID> CGGarrison::providedCreatures() const
  761. {
  762. return {};
  763. }
  764. void CGGarrison::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  765. {
  766. auto relations = cb->gameState().getPlayerRelations(h->tempOwner, tempOwner);
  767. if (relations == PlayerRelations::ENEMIES && stacksCount() > 0) {
  768. //TODO: Find a way to apply magic garrison effects in battle.
  769. gameEvents.startBattle(h, this);
  770. return;
  771. }
  772. //New owner.
  773. if (relations == PlayerRelations::ENEMIES)
  774. gameEvents.setOwner(this, h->tempOwner);
  775. gameEvents.showGarrisonDialog(id, h->id, removableUnits);
  776. }
  777. bool CGGarrison::passableFor(PlayerColor player) const
  778. {
  779. //FIXME: identical to same method in CGTownInstance
  780. if ( !stacksCount() )//empty - anyone can visit
  781. return true;
  782. if ( tempOwner == PlayerColor::NEUTRAL )//neutral guarded - no one can visit
  783. return false;
  784. if (cb->getPlayerRelations(tempOwner, player) != PlayerRelations::ENEMIES)
  785. return true;
  786. return false;
  787. }
  788. void CGGarrison::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  789. {
  790. if (result.winner == BattleSide::ATTACKER)
  791. onHeroVisit(gameEvents, hero);
  792. }
  793. void CGGarrison::serializeJsonOptions(JsonSerializeFormat& handler)
  794. {
  795. handler.serializeBool("removableUnits", removableUnits);
  796. serializeJsonOwner(handler);
  797. CArmedInstance::serializeJsonOptions(handler);
  798. }
  799. void CGGarrison::initObj(vstd::RNG &rand)
  800. {
  801. if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic"))
  802. addAntimagicGarrisonBonus();
  803. }
  804. void CGGarrison::addAntimagicGarrisonBonus()
  805. {
  806. auto bonus = std::make_shared<Bonus>();
  807. bonus->type = BonusType::BLOCK_ALL_MAGIC;
  808. bonus->source = BonusSource::OBJECT_TYPE;
  809. bonus->sid = BonusSourceID(this->ID);
  810. bonus->propagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE);
  811. bonus->duration = BonusDuration::PERMANENT;
  812. this->addNewBonus(bonus);
  813. }
  814. void CGMagi::initObj(vstd::RNG & rand)
  815. {
  816. if (ID == Obj::EYE_OF_MAGI)
  817. blockVisit = true;
  818. }
  819. void CGMagi::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  820. {
  821. if (ID == Obj::HUT_OF_MAGI)
  822. {
  823. h->showInfoDialog(gameEvents, 61);
  824. std::vector<const CGObjectInstance *> eyes;
  825. for (const auto & object : cb->gameState().getMap().getObjects<CGMagi>())
  826. {
  827. if (object->ID == Obj::EYE_OF_MAGI && object->subID == this->subID)
  828. eyes.push_back(object);
  829. }
  830. if (!eyes.empty())
  831. {
  832. CenterView cv;
  833. cv.player = h->tempOwner;
  834. cv.focusTime = 2000;
  835. FoWChange fw;
  836. fw.player = h->tempOwner;
  837. fw.mode = ETileVisibility::REVEALED;
  838. fw.waitForDialogs = true;
  839. for(const auto & eye : eyes)
  840. {
  841. cb->getTilesInRange (fw.tiles, eye->visitablePos(), 10, ETileVisibility::HIDDEN, h->tempOwner);
  842. gameEvents.sendAndApply(fw);
  843. cv.pos = eye->visitablePos();
  844. gameEvents.sendAndApply(cv);
  845. }
  846. cv.pos = h->visitablePos();
  847. cv.focusTime = 0;
  848. gameEvents.sendAndApply(cv);
  849. }
  850. }
  851. else if (ID == Obj::EYE_OF_MAGI)
  852. {
  853. h->showInfoDialog(gameEvents, 48);
  854. }
  855. }
  856. CGBoat::CGBoat(CGameInfoCallback * cb)
  857. : CGObjectInstance(cb)
  858. {
  859. direction = 4;
  860. layer = EPathfindingLayer::SAIL;
  861. }
  862. bool CGBoat::isCoastVisitable() const
  863. {
  864. return true;
  865. }
  866. void CGBoat::setBoardedHero(const CGHeroInstance * hero)
  867. {
  868. if (hero)
  869. boardedHeroID = hero->id;
  870. else
  871. boardedHeroID = ObjectInstanceID();
  872. }
  873. const CGHeroInstance * CGBoat::getBoardedHero() const
  874. {
  875. if (boardedHeroID.hasValue())
  876. return cb->getHero(boardedHeroID);
  877. else
  878. return nullptr;
  879. }
  880. void CGSirens::initObj(vstd::RNG & rand)
  881. {
  882. blockVisit = true;
  883. }
  884. std::string CGSirens::getHoverText(const CGHeroInstance * hero) const
  885. {
  886. return getObjectName() + " " + visitedTxt(hero->hasBonusFrom(BonusSource::OBJECT_TYPE, BonusSourceID(ID)));
  887. }
  888. void CGSirens::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  889. {
  890. InfoWindow iw;
  891. iw.player = h->tempOwner;
  892. if(h->hasBonusFrom(BonusSource::OBJECT_TYPE, BonusSourceID(ID))) //has already visited Sirens
  893. {
  894. iw.type = EInfoWindowMode::AUTO;
  895. iw.text.appendLocalString(EMetaText::ADVOB_TXT,133);
  896. }
  897. else
  898. {
  899. giveDummyBonus(gameEvents, h->id, BonusDuration::ONE_BATTLE);
  900. TExpType xp = 0;
  901. for (auto i = h->Slots().begin(); i != h->Slots().end(); i++)
  902. {
  903. // 1-sized stacks are not affected by sirens
  904. if (i->second->getCount() == 1)
  905. continue;
  906. // tested H3 behavior: 30% (rounded up) of stack drowns
  907. TQuantity drown = std::ceil(i->second->getCount() * 0.3);
  908. if(drown)
  909. {
  910. gameEvents.changeStackCount(StackLocation(h->id, i->first), -drown);
  911. xp += drown * i->second->getType()->getMaxHealth();
  912. }
  913. }
  914. if(xp)
  915. {
  916. xp = h->calculateXp(static_cast<int>(xp));
  917. iw.text.appendLocalString(EMetaText::ADVOB_TXT,132);
  918. iw.text.replaceNumber(static_cast<int>(xp));
  919. gameEvents.giveExperience(h, xp);
  920. }
  921. else
  922. {
  923. iw.text.appendLocalString(EMetaText::ADVOB_TXT,134);
  924. }
  925. }
  926. gameEvents.showInfoDialog(&iw);
  927. }
  928. void CGShipyard::getOutOffsets( std::vector<int3> &offsets ) const
  929. {
  930. // H J L K I
  931. // A x S x B
  932. // C E G F D
  933. offsets = {
  934. {-2, 0, 0}, // A
  935. {+2, 0, 0}, // B
  936. {-2, 1, 0}, // C
  937. {+2, 1, 0}, // D
  938. {-1, 1, 0}, // E
  939. {+1, 1, 0}, // F
  940. {0, 1, 0}, // G
  941. {-2, -1, 0}, // H
  942. {+2, -1, 0}, // I
  943. {-1, -1, 0}, // G
  944. {+1, -1, 0}, // K
  945. {0, -1, 0}, // L
  946. };
  947. }
  948. const IObjectInterface * CGShipyard::getObject() const
  949. {
  950. return this;
  951. }
  952. void CGShipyard::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  953. {
  954. if(cb->gameState().getPlayerRelations(tempOwner, h->tempOwner) == PlayerRelations::ENEMIES)
  955. gameEvents.setOwner(this, h->tempOwner);
  956. if(shipyardStatus() != IBoatGenerator::GOOD)
  957. {
  958. InfoWindow iw;
  959. iw.type = EInfoWindowMode::AUTO;
  960. iw.player = tempOwner;
  961. getProblemText(iw.text, h);
  962. gameEvents.showInfoDialog(&iw);
  963. }
  964. else
  965. {
  966. gameEvents.showObjectWindow(this, EOpenWindowMode::SHIPYARD_WINDOW, h, false);
  967. }
  968. }
  969. void CGShipyard::serializeJsonOptions(JsonSerializeFormat& handler)
  970. {
  971. serializeJsonOwner(handler);
  972. }
  973. BoatId CGShipyard::getBoatType() const
  974. {
  975. return createdBoat;
  976. }
  977. const IOwnableObject * CGShipyard::asOwnable() const
  978. {
  979. return this;
  980. }
  981. ResourceSet CGShipyard::dailyIncome() const
  982. {
  983. return {};
  984. }
  985. std::vector<CreatureID> CGShipyard::providedCreatures() const
  986. {
  987. return {};
  988. }
  989. void CGDenOfthieves::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  990. {
  991. gameEvents.showObjectWindow(this, EOpenWindowMode::THIEVES_GUILD, h, false);
  992. }
  993. void CGObelisk::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  994. {
  995. InfoWindow iw;
  996. iw.type = EInfoWindowMode::AUTO;
  997. iw.player = h->tempOwner;
  998. TeamState *ts = cb->gameState().getPlayerTeam(h->tempOwner);
  999. assert(ts);
  1000. TeamID team = ts->id;
  1001. if(!wasVisited(team))
  1002. {
  1003. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 96);
  1004. gameEvents.sendAndApply(iw);
  1005. // increment general visited obelisks counter
  1006. gameEvents.setObjPropertyID(id, ObjProperty::OBELISK_VISITED, team);
  1007. gameEvents.showObjectWindow(this, EOpenWindowMode::PUZZLE_MAP, h, false);
  1008. // mark that particular obelisk as visited for all players in the team
  1009. for(const auto & color : ts->players)
  1010. {
  1011. gameEvents.setObjPropertyID(id, ObjProperty::VISITED, color);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 97);
  1017. gameEvents.sendAndApply(iw);
  1018. }
  1019. }
  1020. void CGObelisk::initObj(vstd::RNG & rand)
  1021. {
  1022. cb->gameState().getMap().obeliskCount++;
  1023. }
  1024. std::string CGObelisk::getHoverText(PlayerColor player) const
  1025. {
  1026. return getObjectName() + " " + visitedTxt(wasVisited(player));
  1027. }
  1028. std::string CGObelisk::getObjectDescription(PlayerColor player) const
  1029. {
  1030. return visitedTxt(wasVisited(player));
  1031. }
  1032. void CGObelisk::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
  1033. {
  1034. switch(what)
  1035. {
  1036. case ObjProperty::OBELISK_VISITED:
  1037. {
  1038. auto progress = ++cb->gameState().getMap().obelisksVisited[identifier.as<TeamID>()];
  1039. logGlobal->debug("Player %d: obelisk progress %d / %d", identifier.getNum(), static_cast<int>(progress) , static_cast<int>(cb->gameState().getMap().obeliskCount));
  1040. if(progress > cb->gameState().getMap().obeliskCount)
  1041. {
  1042. logGlobal->error("Visited %d of %d", static_cast<int>(progress), cb->gameState().getMap().obeliskCount);
  1043. throw std::runtime_error("Player visited " + std::to_string(progress) + " obelisks out of " + std::to_string(cb->gameState().getMap().obeliskCount) + " present on map!");
  1044. }
  1045. break;
  1046. }
  1047. default:
  1048. CTeamVisited::setPropertyDer(what, identifier);
  1049. break;
  1050. }
  1051. }
  1052. void HillFort::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  1053. {
  1054. gameEvents.showObjectWindow(this, EOpenWindowMode::HILL_FORT_WINDOW, h, false);
  1055. }
  1056. void HillFort::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const
  1057. {
  1058. int32_t level = stack.getType()->getLevel();
  1059. int32_t index = std::clamp<int32_t>(level - 1, 0, upgradeCostPercentage.size() - 1);
  1060. int costModifier = upgradeCostPercentage[index];
  1061. for(const auto & nid : stack.getCreature()->upgrades)
  1062. {
  1063. info.addUpgrade(nid, stack.getType(), costModifier);
  1064. }
  1065. }
  1066. std::string HillFort::getPopupText(PlayerColor player) const
  1067. {
  1068. MetaString message = MetaString::createFromRawString("{%s}\r\n\r\n%s");
  1069. message.replaceName(ID, subID);
  1070. message.replaceTextID(getDescriptionToolTip());
  1071. return message.toString();
  1072. }
  1073. std::string HillFort::getPopupText(const CGHeroInstance * hero) const
  1074. {
  1075. return getPopupText(hero->getOwner());
  1076. }
  1077. std::string HillFort::getDescriptionToolTip() const
  1078. {
  1079. return TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get();
  1080. }
  1081. std::string HillFort::getUnavailableUpgradeMessage() const
  1082. {
  1083. assert(getObjectHandler()->getModScope() != "core");
  1084. return TextIdentifier(getObjectHandler()->getBaseTextID(), "unavailableUpgradeMessage").get();
  1085. }
  1086. VCMI_LIB_NAMESPACE_END