MiscObjects.cpp 34 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/IGameInfoCallback.h"
  14. #include "../callback/IGameEventCallback.h"
  15. #include "../callback/IGameRandomizer.h"
  16. #include "../constants/StringConstants.h"
  17. #include "../entities/artifact/ArtifactUtils.h"
  18. #include "../entities/artifact/CArtifact.h"
  19. #include "../CConfigHandler.h"
  20. #include "../texts/CGeneralTextHandler.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 "../networkPacks/PacksForClient.h"
  32. #include "../networkPacks/PacksForClientBattle.h"
  33. #include "../networkPacks/StackLocation.h"
  34. #include "../lib/gameState/UpgradeInfo.h"
  35. #include <vstd/RNG.h>
  36. VCMI_LIB_NAMESPACE_BEGIN
  37. ///helpers
  38. static std::string visitedTxt(const bool visited)
  39. {
  40. int id = visited ? 352 : 353;
  41. return LIBRARY->generaltexth->allTexts[id];
  42. }
  43. void CTeamVisited::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
  44. {
  45. if(what == ObjProperty::VISITED)
  46. players.insert(identifier.as<PlayerColor>());
  47. }
  48. bool CTeamVisited::wasVisited(PlayerColor player) const
  49. {
  50. return wasVisited(cb->getPlayerState(player)->team);
  51. }
  52. bool CTeamVisited::wasVisited(const CGHeroInstance * h) const
  53. {
  54. return wasVisited(h->tempOwner);
  55. }
  56. bool CTeamVisited::wasVisited(const TeamID & team) const
  57. {
  58. for(const auto & i : players)
  59. {
  60. if(cb->getPlayerState(i)->team == team)
  61. return true;
  62. }
  63. return false;
  64. }
  65. //CGMine
  66. void CGMine::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  67. {
  68. auto relations = cb->getPlayerRelations(h->tempOwner, tempOwner);
  69. if(relations == PlayerRelations::SAME_PLAYER) //we're visiting our mine
  70. {
  71. gameEvents.showGarrisonDialog(id,h->id,true);
  72. return;
  73. }
  74. else if (relations == PlayerRelations::ALLIES)//ally
  75. return;
  76. if(stacksCount()) //Mine is guarded
  77. {
  78. BlockingDialog ynd(true,false);
  79. ynd.player = h->tempOwner;
  80. ynd.text.appendLocalString(EMetaText::ADVOB_TXT, isAbandoned() ? 84 : 187);
  81. gameEvents.showBlockingDialog(this, &ynd);
  82. return;
  83. }
  84. flagMine(gameEvents, h->tempOwner);
  85. }
  86. void CGMine::initObj(IGameRandomizer & gameRandomizer)
  87. {
  88. if(isAbandoned())
  89. {
  90. //set guardians
  91. int howManyTroglodytes = gameRandomizer.getDefault().nextInt(100, 199);
  92. auto troglodytes = std::make_unique<CStackInstance>(cb, CreatureID::TROGLODYTES, howManyTroglodytes);
  93. putStack(SlotID(0), std::move(troglodytes));
  94. assert(!abandonedMineResources.empty());
  95. if (!abandonedMineResources.empty())
  96. {
  97. producedResource = *RandomGeneratorUtil::nextItem(abandonedMineResources, gameRandomizer.getDefault());
  98. }
  99. else
  100. {
  101. logGlobal->error("Abandoned mine at (%s) has no valid resource candidates!", anchorPos().toString());
  102. producedResource = GameResID::GOLD;
  103. }
  104. }
  105. else
  106. {
  107. producedResource = GameResID(getObjTypeIndex().getNum());
  108. }
  109. producedQuantity = defaultResProduction();
  110. }
  111. bool CGMine::isAbandoned() const
  112. {
  113. return subID.getNum() >= 7;
  114. }
  115. const IOwnableObject * CGMine::asOwnable() const
  116. {
  117. return this;
  118. }
  119. std::vector<CreatureID> CGMine::providedCreatures() const
  120. {
  121. return {};
  122. }
  123. ResourceSet CGMine::dailyIncome() const
  124. {
  125. ResourceSet result;
  126. result[producedResource] += defaultResProduction();
  127. const auto & playerSettings = cb->getPlayerSettings(getOwner());
  128. result.applyHandicap(playerSettings->handicap.percentIncome);
  129. return result;
  130. }
  131. std::string CGMine::getObjectName() const
  132. {
  133. return LIBRARY->generaltexth->translate("core.minename", getObjTypeIndex());
  134. }
  135. std::string CGMine::getHoverText(PlayerColor player) const
  136. {
  137. std::string hoverName = CArmedInstance::getHoverText(player);
  138. if (tempOwner != PlayerColor::NEUTRAL)
  139. hoverName += "\n(" + LIBRARY->generaltexth->restypes[producedResource.getNum()] + ")";
  140. if(stacksCount())
  141. {
  142. hoverName += "\n";
  143. hoverName += LIBRARY->generaltexth->allTexts[202]; //Guarded by
  144. hoverName += " ";
  145. hoverName += getArmyDescription();
  146. }
  147. return hoverName;
  148. }
  149. void CGMine::flagMine(IGameEventCallback & gameEvents, const PlayerColor & player) const
  150. {
  151. assert(tempOwner != player);
  152. gameEvents.setOwner(this, player); //not ours? flag it!
  153. InfoWindow iw;
  154. iw.type = EInfoWindowMode::AUTO;
  155. iw.text.appendTextID(TextIdentifier("core.mineevnt", producedResource.getNum()).get()); //not use subID, abandoned mines uses default mine texts
  156. iw.player = player;
  157. iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, getProducedQuantity());
  158. gameEvents.showInfoDialog(&iw);
  159. }
  160. ui32 CGMine::defaultResProduction() const
  161. {
  162. switch(producedResource.toEnum())
  163. {
  164. case EGameResID::WOOD:
  165. case EGameResID::ORE:
  166. return 2;
  167. case EGameResID::GOLD:
  168. return 1000;
  169. default:
  170. return 1;
  171. }
  172. }
  173. ui32 CGMine::getProducedQuantity() const
  174. {
  175. auto * playerSettings = cb->getPlayerSettings(getOwner());
  176. // always round up income - we don't want mines to always produce zero if handicap in use
  177. return vstd::divideAndCeil(producedQuantity * playerSettings->handicap.percentIncome, 100);
  178. }
  179. void CGMine::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  180. {
  181. if(result.winner == BattleSide::ATTACKER) //attacker won
  182. {
  183. if(isAbandoned())
  184. {
  185. hero->showInfoDialog(gameEvents, 85);
  186. }
  187. flagMine(gameEvents, hero->tempOwner);
  188. }
  189. }
  190. void CGMine::blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const
  191. {
  192. if(answer)
  193. gameEvents.startBattle(hero, this);
  194. }
  195. void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
  196. {
  197. CArmedInstance::serializeJsonOptions(handler);
  198. serializeJsonOwner(handler);
  199. if(isAbandoned())
  200. {
  201. if(handler.saving)
  202. {
  203. JsonNode node;
  204. for(const auto & resID : abandonedMineResources)
  205. node.Vector().emplace_back(GameConstants::RESOURCE_NAMES[resID.getNum()]);
  206. handler.serializeRaw("possibleResources", node, std::nullopt);
  207. }
  208. else
  209. {
  210. auto guard = handler.enterArray("possibleResources");
  211. const JsonNode & node = handler.getCurrent();
  212. auto names = node.convertTo<std::vector<std::string>>();
  213. for(const std::string & s : names)
  214. {
  215. int raw_res = vstd::find_pos(GameConstants::RESOURCE_NAMES, s);
  216. if(raw_res < 0)
  217. logGlobal->error("Invalid resource name: %s", s);
  218. else
  219. abandonedMineResources.emplace(raw_res);
  220. }
  221. }
  222. }
  223. }
  224. bool CGTeleport::isEntrance() const
  225. {
  226. return type == BOTH || type == ENTRANCE;
  227. }
  228. bool CGTeleport::isExit() const
  229. {
  230. return type == BOTH || type == EXIT;
  231. }
  232. bool CGTeleport::isChannelEntrance(const ObjectInstanceID & id) const
  233. {
  234. return vstd::contains(getAllEntrances(), id);
  235. }
  236. bool CGTeleport::isChannelExit(const ObjectInstanceID & id) const
  237. {
  238. return vstd::contains(getAllExits(), id);
  239. }
  240. std::vector<ObjectInstanceID> CGTeleport::getAllEntrances(bool excludeCurrent) const
  241. {
  242. auto ret = cb->getTeleportChannelEntrances(channel);
  243. if(excludeCurrent)
  244. vstd::erase_if_present(ret, id);
  245. return ret;
  246. }
  247. std::vector<ObjectInstanceID> CGTeleport::getAllExits(bool excludeCurrent) const
  248. {
  249. auto ret = cb->getTeleportChannelExits(channel);
  250. if(excludeCurrent)
  251. vstd::erase_if_present(ret, id);
  252. return ret;
  253. }
  254. ObjectInstanceID CGTeleport::getRandomExit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  255. {
  256. auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true));
  257. if(!passableExits.empty())
  258. return *RandomGeneratorUtil::nextItem(passableExits, gameEvents.getRandomGenerator());
  259. return ObjectInstanceID();
  260. }
  261. bool CGTeleport::isTeleport(const CGObjectInstance * obj)
  262. {
  263. return dynamic_cast<const CGTeleport *>(obj) != nullptr;
  264. }
  265. bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst)
  266. {
  267. return src && dst && src->isChannelExit(dst->id);
  268. }
  269. bool CGTeleport::isConnected(const CGObjectInstance * src, const CGObjectInstance * dst)
  270. {
  271. const auto * srcObj = dynamic_cast<const CGTeleport *>(src);
  272. const auto * dstObj = dynamic_cast<const CGTeleport *>(dst);
  273. return isConnected(srcObj, dstObj);
  274. }
  275. bool CGTeleport::isExitPassable(const IGameInfoCallback & gameInfo, const CGHeroInstance * h, const CGObjectInstance * obj)
  276. {
  277. ObjectInstanceID topObjectID = gameInfo.getTile(obj->visitablePos())->topVisitableObj();
  278. const CGObjectInstance * topObject = gameInfo.getObjInstance(topObjectID);
  279. if(topObject->ID == Obj::HERO)
  280. {
  281. if(h->id == topObject->id) // Just to be sure it's won't happen.
  282. return false;
  283. // Check if it's friendly hero or not
  284. if(gameInfo.getPlayerRelations(h->tempOwner, topObject->tempOwner) != PlayerRelations::ENEMIES)
  285. {
  286. // Exchange between heroes only possible via subterranean gates
  287. if(!dynamic_cast<const CGSubterraneanGate *>(obj))
  288. return false;
  289. }
  290. }
  291. return true;
  292. }
  293. std::vector<ObjectInstanceID> CGTeleport::getPassableExits(const IGameInfoCallback & gameInfo, const CGHeroInstance * h, std::vector<ObjectInstanceID> exits)
  294. {
  295. vstd::erase_if(exits, [&](const ObjectInstanceID & exit) -> bool
  296. {
  297. return !isExitPassable(gameInfo, h, gameInfo.getObj(exit));
  298. });
  299. return exits;
  300. }
  301. void CGTeleport::addToChannel(std::map<TeleportChannelID, std::shared_ptr<TeleportChannel> > &channelsList, const CGTeleport * obj)
  302. {
  303. std::shared_ptr<TeleportChannel> tc;
  304. if(channelsList.find(obj->channel) == channelsList.end())
  305. {
  306. tc = std::make_shared<TeleportChannel>();
  307. channelsList.insert(std::make_pair(obj->channel, tc));
  308. }
  309. else
  310. tc = channelsList[obj->channel];
  311. if(obj->isEntrance() && !vstd::contains(tc->entrances, obj->id))
  312. tc->entrances.push_back(obj->id);
  313. if(obj->isExit() && !vstd::contains(tc->exits, obj->id))
  314. tc->exits.push_back(obj->id);
  315. if(!tc->entrances.empty() && !tc->exits.empty()
  316. && (tc->entrances.size() != 1 || tc->entrances != tc->exits))
  317. {
  318. tc->passability = TeleportChannel::PASSABLE;
  319. }
  320. }
  321. TeleportChannelID CGMonolith::findMeChannel(const std::vector<Obj> & IDs, MapObjectSubID SubID) const
  322. {
  323. for(auto teleportObj : cb->gameState().getMap().getObjects<CGMonolith>())
  324. {
  325. if(vstd::contains(IDs, teleportObj->ID) && teleportObj->subID == SubID)
  326. return teleportObj->channel;
  327. }
  328. return TeleportChannelID();
  329. }
  330. void CGMonolith::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  331. {
  332. TeleportDialog td(h->id, channel);
  333. if(isEntrance())
  334. {
  335. if(cb->isTeleportChannelBidirectional(channel) && 1 < cb->getTeleportChannelExits(channel).size())
  336. {
  337. auto exits = cb->getTeleportChannelExits(channel);
  338. for(const auto & exit : exits)
  339. {
  340. td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos()));
  341. }
  342. }
  343. if(cb->isTeleportChannelImpassable(channel))
  344. {
  345. logGlobal->debug("Cannot find corresponding exit monolith for %d at %s", id.getNum(), anchorPos().toString());
  346. td.impassable = true;
  347. }
  348. else if(getRandomExit(gameEvents, h) == ObjectInstanceID())
  349. logGlobal->debug("All exits blocked for monolith %d at %s", id.getNum(), anchorPos().toString());
  350. }
  351. else
  352. h->showInfoDialog(gameEvents, 70);
  353. gameEvents.showTeleportDialog(&td);
  354. }
  355. void CGMonolith::teleportDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const
  356. {
  357. int3 dPos;
  358. auto randomExit = getRandomExit(gameEvents, hero);
  359. auto realExits = getAllExits(true);
  360. if(!isEntrance() // Do nothing if hero visited exit only object
  361. || (exits.empty() && realExits.empty()) // Do nothing if there no exits on this channel
  362. || ObjectInstanceID() == randomExit) // Do nothing if all exits are blocked by friendly hero and it's not subterranean gate
  363. {
  364. return;
  365. }
  366. else if(vstd::isValidIndex(exits, answer))
  367. dPos = exits[answer].second;
  368. else
  369. dPos = cb->getObj(randomExit)->visitablePos();
  370. gameEvents.moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
  371. }
  372. void CGMonolith::initObj(IGameRandomizer & gameRandomizer)
  373. {
  374. std::vector<Obj> IDs;
  375. IDs.push_back(ID);
  376. switch(ID.toEnum())
  377. {
  378. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  379. type = ENTRANCE;
  380. IDs.emplace_back(Obj::MONOLITH_ONE_WAY_EXIT);
  381. break;
  382. case Obj::MONOLITH_ONE_WAY_EXIT:
  383. type = EXIT;
  384. IDs.emplace_back(Obj::MONOLITH_ONE_WAY_ENTRANCE);
  385. break;
  386. case Obj::MONOLITH_TWO_WAY:
  387. default:
  388. type = BOTH;
  389. break;
  390. }
  391. channel = findMeChannel(IDs, subID);
  392. if(channel == TeleportChannelID())
  393. channel = TeleportChannelID(static_cast<si32>(cb->gameState().getMap().teleportChannels.size()));
  394. addToChannel(cb->gameState().getMap().teleportChannels, this);
  395. }
  396. void CGSubterraneanGate::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  397. {
  398. TeleportDialog td(h->id, channel);
  399. if(cb->isTeleportChannelImpassable(channel))
  400. {
  401. h->showInfoDialog(gameEvents, 153);//Just inside the entrance you find a large pile of rubble blocking the tunnel. You leave discouraged.
  402. logGlobal->debug("Cannot find exit subterranean gate for %d at %s", id.getNum(), anchorPos().toString());
  403. td.impassable = true;
  404. }
  405. else
  406. {
  407. auto exit = getRandomExit(gameEvents, h);
  408. td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos()));
  409. }
  410. gameEvents.showTeleportDialog(&td);
  411. }
  412. void CGSubterraneanGate::initObj(IGameRandomizer & gameRandomizer)
  413. {
  414. type = BOTH;
  415. }
  416. void CGSubterraneanGate::postInit(IGameInfoCallback * cb) //matches subterranean gates into pairs
  417. {
  418. //split on underground and surface gates
  419. std::vector<CGSubterraneanGate *> gatesSplit[2]; //surface and underground gates
  420. for(auto gate : cb->gameState().getMap().getObjects<CGSubterraneanGate>())
  421. {
  422. gatesSplit[gate->visitablePos().z].push_back(gate);
  423. }
  424. //sort by position
  425. std::sort(gatesSplit[0].begin(), gatesSplit[0].end(), [](const CGObjectInstance * a, const CGObjectInstance * b)
  426. {
  427. return a->visitablePos() < b->visitablePos();
  428. });
  429. auto assignToChannel = [&](CGSubterraneanGate * obj)
  430. {
  431. if(obj->channel == TeleportChannelID())
  432. { // if object not linked to channel then create new channel
  433. obj->channel = TeleportChannelID(static_cast<si32>(cb->gameState().getMap().teleportChannels.size()));
  434. addToChannel(cb->gameState().getMap().teleportChannels, obj);
  435. }
  436. };
  437. for(size_t i = 0; i < gatesSplit[0].size(); i++)
  438. {
  439. CGSubterraneanGate * objCurrent = gatesSplit[0][i];
  440. //find nearest underground exit
  441. std::pair<int, si32> best(-1, std::numeric_limits<si32>::max()); //pair<pos_in_vector, distance^2>
  442. for(int j = 0; j < gatesSplit[1].size(); j++)
  443. {
  444. CGSubterraneanGate *checked = gatesSplit[1][j];
  445. if(checked->channel != TeleportChannelID())
  446. continue;
  447. si32 hlp = checked->visitablePos().dist2dSQ(objCurrent->visitablePos());
  448. if(hlp < best.second)
  449. {
  450. best.first = j;
  451. best.second = hlp;
  452. }
  453. }
  454. assignToChannel(objCurrent);
  455. if(best.first >= 0) //found pair
  456. {
  457. gatesSplit[1][best.first]->channel = objCurrent->channel;
  458. addToChannel(cb->gameState().getMap().teleportChannels, gatesSplit[1][best.first]);
  459. }
  460. }
  461. // we should assign empty channels to underground gates if they don't have matching overground gates
  462. for(auto & i : gatesSplit[1])
  463. assignToChannel(i);
  464. }
  465. void CGWhirlpool::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  466. {
  467. TeleportDialog td(h->id, channel);
  468. if(cb->isTeleportChannelImpassable(channel))
  469. {
  470. logGlobal->debug("Cannot find exit whirlpool for %d at %s", id.getNum(), anchorPos().toString());
  471. td.impassable = true;
  472. }
  473. else if(getRandomExit(gameEvents, h) == ObjectInstanceID())
  474. logGlobal->debug("All exits are blocked for whirlpool %d at %s", id.getNum(), anchorPos().toString());
  475. if(!isProtected(h))
  476. {
  477. SlotID targetstack = h->Slots().begin()->first; //slot numbers may vary
  478. for(auto i = h->Slots().rbegin(); i != h->Slots().rend(); i++)
  479. {
  480. if(h->getPower(targetstack) > h->getPower(i->first))
  481. targetstack = (i->first);
  482. }
  483. auto countToTake = static_cast<TQuantity>(h->getStackCount(targetstack) * 0.5);
  484. vstd::amax(countToTake, 1);
  485. InfoWindow iw;
  486. iw.type = EInfoWindowMode::AUTO;
  487. iw.player = h->tempOwner;
  488. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 168);
  489. iw.components.emplace_back(ComponentType::CREATURE, h->getCreature(targetstack)->getId(), -countToTake);
  490. gameEvents.showInfoDialog(&iw);
  491. gameEvents.changeStackCount(StackLocation(h->id, targetstack), -countToTake, ChangeValueMode::RELATIVE);
  492. }
  493. else
  494. {
  495. auto exits = getAllExits();
  496. for(const auto & exit : exits)
  497. {
  498. auto blockedPosList = cb->getObj(exit)->getBlockedPos();
  499. for(const auto & bPos : blockedPosList)
  500. td.exits.push_back(std::make_pair(exit, bPos));
  501. }
  502. }
  503. gameEvents.showTeleportDialog(&td);
  504. }
  505. void CGWhirlpool::teleportDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const
  506. {
  507. int3 dPos;
  508. auto realExits = getAllExits();
  509. if(exits.empty() && realExits.empty())
  510. return;
  511. else if(vstd::isValidIndex(exits, answer))
  512. dPos = exits[answer].second;
  513. else
  514. {
  515. auto exit = getRandomExit(gameEvents, hero);
  516. if(exit == ObjectInstanceID())
  517. return;
  518. const auto * obj = cb->getObj(exit);
  519. std::set<int3> tiles = obj->getBlockedPos();
  520. dPos = *RandomGeneratorUtil::nextItem(tiles, gameEvents.getRandomGenerator());
  521. }
  522. gameEvents.moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
  523. }
  524. bool CGWhirlpool::isProtected(const CGHeroInstance * h)
  525. {
  526. return h->hasBonusOfType(BonusType::WHIRLPOOL_PROTECTION)
  527. || (h->stacksCount() == 1 && h->Slots().begin()->second->getCount() == 1)
  528. || (h->stacksCount() == 0 && h->getCommander() && h->getCommander()->alive);
  529. }
  530. const CArtifactInstance * CGArtifact::getArtifactInstance() const
  531. {
  532. return cb->getArtInstance(storedArtifact);
  533. }
  534. ArtifactID CGArtifact::getArtifactType() const
  535. {
  536. if(ID == Obj::SPELL_SCROLL)
  537. return ArtifactID::SPELL_SCROLL;
  538. else
  539. return getObjTypeIndex().getNum();
  540. }
  541. void CGArtifact::pickRandomObject(IGameRandomizer & gameRandomizer)
  542. {
  543. switch(ID.toEnum())
  544. {
  545. case MapObjectID::RANDOM_ART:
  546. subID = gameRandomizer.rollArtifact();
  547. break;
  548. case MapObjectID::RANDOM_TREASURE_ART:
  549. subID = gameRandomizer.rollArtifact(EArtifactClass::ART_TREASURE);
  550. break;
  551. case MapObjectID::RANDOM_MINOR_ART:
  552. subID = gameRandomizer.rollArtifact(EArtifactClass::ART_MINOR);
  553. break;
  554. case MapObjectID::RANDOM_MAJOR_ART:
  555. subID = gameRandomizer.rollArtifact(EArtifactClass::ART_MAJOR);
  556. break;
  557. case MapObjectID::RANDOM_RELIC_ART:
  558. subID = gameRandomizer.rollArtifact(EArtifactClass::ART_RELIC);
  559. break;
  560. }
  561. if (ID != MapObjectID::SPELL_SCROLL && ID != MapObjectID::ARTIFACT)
  562. {
  563. ID = MapObjectID::ARTIFACT;
  564. setType(ID, subID);
  565. }
  566. else if (ID != MapObjectID::SPELL_SCROLL)
  567. ID = MapObjectID::ARTIFACT;
  568. }
  569. void CGArtifact::setArtifactInstance(const CArtifactInstance * instance)
  570. {
  571. storedArtifact = instance->getId();
  572. }
  573. void CGArtifact::initObj(IGameRandomizer & gameRandomizer)
  574. {
  575. blockVisit = true;
  576. if(ID == Obj::ARTIFACT)
  577. {
  578. assert(getArtifactType().hasValue());
  579. if (!storedArtifact.hasValue())
  580. setArtifactInstance(cb->gameState().createArtifact(getArtifactType()));
  581. }
  582. if(ID == Obj::SPELL_SCROLL)
  583. subID = 1;
  584. assert(getArtifactInstance()->getType());
  585. assert(!getArtifactInstance()->getParentNodes().empty());
  586. }
  587. std::string CGArtifact::getObjectName() const
  588. {
  589. return getArtifactType().toEntity(LIBRARY)->getNameTranslated();
  590. }
  591. std::string CGArtifact::getPopupText(PlayerColor player) const
  592. {
  593. if (settings["general"]["enableUiEnhancements"].Bool())
  594. {
  595. std::string description = getArtifactType().toEntity(LIBRARY)->getDescriptionTranslated();
  596. if (getArtifactType() == ArtifactID::SPELL_SCROLL)
  597. ArtifactUtils::insertScrrollSpellName(description, SpellID::NONE); // erase text placeholder
  598. return description;
  599. }
  600. else
  601. return getObjectName();
  602. }
  603. std::string CGArtifact::getPopupText(const CGHeroInstance * hero) const
  604. {
  605. return getPopupText(hero->getOwner());
  606. }
  607. std::vector<Component> CGArtifact::getPopupComponents(PlayerColor player) const
  608. {
  609. return {
  610. Component(ComponentType::ARTIFACT, getArtifactType())
  611. };
  612. }
  613. void CGArtifact::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  614. {
  615. if(!stacksCount())
  616. {
  617. InfoWindow iw;
  618. iw.type = EInfoWindowMode::AUTO;
  619. iw.player = h->tempOwner;
  620. if(getArtifactInstance()->getType()->canBePutAt(h))
  621. {
  622. switch (ID.toEnum())
  623. {
  624. case Obj::ARTIFACT:
  625. {
  626. iw.components.emplace_back(ComponentType::ARTIFACT, getArtifactType());
  627. if(!message.empty())
  628. iw.text = message;
  629. else
  630. iw.text.appendTextID(getArtifactType().toArtifact()->getEventTextID());
  631. }
  632. break;
  633. case Obj::SPELL_SCROLL:
  634. {
  635. SpellID spell = getArtifactInstance()->getScrollSpellID();
  636. iw.components.emplace_back(ComponentType::SPELL, spell);
  637. if(!message.empty())
  638. iw.text = message;
  639. else
  640. {
  641. iw.text.appendLocalString(EMetaText::ADVOB_TXT,135);
  642. iw.text.replaceName(spell);
  643. }
  644. }
  645. break;
  646. }
  647. }
  648. else
  649. {
  650. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 2);
  651. }
  652. gameEvents.showInfoDialog(&iw);
  653. pick(gameEvents, h);
  654. }
  655. else
  656. {
  657. switch(ID.toEnum())
  658. {
  659. case Obj::ARTIFACT:
  660. {
  661. BlockingDialog ynd(true,false);
  662. ynd.player = h->getOwner();
  663. if(!message.empty())
  664. ynd.text = message;
  665. else
  666. {
  667. // TODO: Guard text is more complex in H3, see mantis issue 2325 for details
  668. ynd.text.appendLocalString(EMetaText::GENERAL_TXT, 420);
  669. ynd.text.replaceRawString("");
  670. ynd.text.replaceRawString(getArmyDescription());
  671. ynd.text.replaceLocalString(EMetaText::GENERAL_TXT, 43); // creatures
  672. }
  673. gameEvents.showBlockingDialog(this, &ynd);
  674. }
  675. break;
  676. case Obj::SPELL_SCROLL:
  677. {
  678. if(!message.empty())
  679. {
  680. BlockingDialog ynd(true,false);
  681. ynd.player = h->getOwner();
  682. ynd.text = message;
  683. gameEvents.showBlockingDialog(this, &ynd);
  684. }
  685. else
  686. blockingDialogAnswered(gameEvents, h, true);
  687. }
  688. break;
  689. }
  690. }
  691. }
  692. void CGArtifact::pick(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  693. {
  694. if(gameEvents.putArtifact(ArtifactLocation(h->id, ArtifactPosition::FIRST_AVAILABLE), getArtifactInstance()->getId()))
  695. gameEvents.removeObject(this, h->getOwner());
  696. }
  697. BattleField CGArtifact::getBattlefield() const
  698. {
  699. return BattleField::NONE;
  700. }
  701. void CGArtifact::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  702. {
  703. if(result.winner == BattleSide::ATTACKER) //attacker won
  704. pick(gameEvents, hero);
  705. }
  706. void CGArtifact::blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const
  707. {
  708. if(answer)
  709. gameEvents.startBattle(hero, this);
  710. }
  711. void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
  712. {
  713. handler.serializeStruct("guardMessage", message);
  714. CArmedInstance::serializeJsonOptions(handler);
  715. if(!handler.saving && !handler.getCurrent()["guards"].Vector().empty())
  716. CCreatureSet::serializeJson(handler, "guards", 7);
  717. if(handler.saving && ID == Obj::SPELL_SCROLL)
  718. {
  719. const auto & b = getArtifactInstance()->getFirstBonus(Selector::type()(BonusType::SPELL));
  720. SpellID spellId(b->subtype.as<SpellID>());
  721. handler.serializeId("spell", spellId, SpellID::NONE);
  722. }
  723. }
  724. void CGSignBottle::initObj(IGameRandomizer & gameRandomizer)
  725. {
  726. //if no text is set than we pick random from the predefined ones
  727. if(message.empty())
  728. {
  729. auto vector = LIBRARY->generaltexth->findStringsWithPrefix("core.randsign");
  730. std::string messageIdentifier = *RandomGeneratorUtil::nextItem(vector, gameRandomizer.getDefault());
  731. message.appendTextID(messageIdentifier);
  732. }
  733. if(ID == Obj::OCEAN_BOTTLE)
  734. {
  735. blockVisit = true;
  736. }
  737. }
  738. void CGSignBottle::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  739. {
  740. InfoWindow iw;
  741. iw.player = h->getOwner();
  742. iw.text = message;
  743. gameEvents.showInfoDialog(&iw);
  744. if(ID == Obj::OCEAN_BOTTLE)
  745. gameEvents.removeObject(this, h->getOwner());
  746. }
  747. void CGSignBottle::serializeJsonOptions(JsonSerializeFormat& handler)
  748. {
  749. handler.serializeStruct("text", message);
  750. }
  751. const IOwnableObject * CGGarrison::asOwnable() const
  752. {
  753. return this;
  754. }
  755. ResourceSet CGGarrison::dailyIncome() const
  756. {
  757. return {};
  758. }
  759. std::vector<CreatureID> CGGarrison::providedCreatures() const
  760. {
  761. return {};
  762. }
  763. void CGGarrison::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  764. {
  765. auto relations = cb->getPlayerRelations(h->tempOwner, tempOwner);
  766. if (relations == PlayerRelations::ENEMIES && stacksCount() > 0) {
  767. //TODO: Find a way to apply magic garrison effects in battle.
  768. gameEvents.startBattle(h, this);
  769. return;
  770. }
  771. //New owner.
  772. if (relations == PlayerRelations::ENEMIES)
  773. gameEvents.setOwner(this, h->tempOwner);
  774. gameEvents.showGarrisonDialog(id, h->id, removableUnits);
  775. }
  776. bool CGGarrison::passableFor(PlayerColor player) const
  777. {
  778. //FIXME: identical to same method in CGTownInstance
  779. if ( !stacksCount() )//empty - anyone can visit
  780. return true;
  781. if ( tempOwner == PlayerColor::NEUTRAL )//neutral guarded - no one can visit
  782. return false;
  783. if (cb->getPlayerRelations(tempOwner, player) != PlayerRelations::ENEMIES)
  784. return true;
  785. return false;
  786. }
  787. void CGGarrison::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  788. {
  789. if (result.winner == BattleSide::ATTACKER)
  790. onHeroVisit(gameEvents, hero);
  791. }
  792. void CGGarrison::serializeJsonOptions(JsonSerializeFormat& handler)
  793. {
  794. handler.serializeBool("removableUnits", removableUnits);
  795. serializeJsonOwner(handler);
  796. CArmedInstance::serializeJsonOptions(handler);
  797. }
  798. void CGGarrison::initObj(IGameRandomizer & gameRandomizer)
  799. {
  800. if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic"))
  801. addAntimagicGarrisonBonus();
  802. }
  803. void CGGarrison::addAntimagicGarrisonBonus()
  804. {
  805. auto bonus = std::make_shared<Bonus>();
  806. bonus->type = BonusType::BLOCK_ALL_MAGIC;
  807. bonus->source = BonusSource::OBJECT_TYPE;
  808. bonus->sid = BonusSourceID(this->ID);
  809. bonus->propagator = std::make_shared<CPropagatorNodeType>(BonusNodeType::BATTLE_WIDE);
  810. bonus->duration = BonusDuration::PERMANENT;
  811. this->addNewBonus(bonus);
  812. }
  813. void CGMagi::initObj(IGameRandomizer & gameRandomizer)
  814. {
  815. if (ID == Obj::EYE_OF_MAGI)
  816. blockVisit = true;
  817. }
  818. void CGMagi::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  819. {
  820. if (ID == Obj::HUT_OF_MAGI)
  821. {
  822. h->showInfoDialog(gameEvents, 61);
  823. std::vector<const CGObjectInstance *> eyes;
  824. for (const auto & object : cb->gameState().getMap().getObjects<CGMagi>())
  825. {
  826. if (object->ID == Obj::EYE_OF_MAGI && object->subID == this->subID)
  827. eyes.push_back(object);
  828. }
  829. if (!eyes.empty())
  830. {
  831. CenterView cv;
  832. cv.player = h->tempOwner;
  833. cv.focusTime = 2000;
  834. FoWChange fw;
  835. fw.player = h->tempOwner;
  836. fw.mode = ETileVisibility::REVEALED;
  837. fw.waitForDialogs = true;
  838. for(const auto & eye : eyes)
  839. {
  840. cb->getTilesInRange (fw.tiles, eye->visitablePos(), 10, ETileVisibility::HIDDEN, h->tempOwner);
  841. gameEvents.sendAndApply(fw);
  842. cv.pos = eye->visitablePos();
  843. gameEvents.sendAndApply(cv);
  844. }
  845. cv.pos = h->visitablePos();
  846. cv.focusTime = 0;
  847. gameEvents.sendAndApply(cv);
  848. }
  849. }
  850. else if (ID == Obj::EYE_OF_MAGI)
  851. {
  852. h->showInfoDialog(gameEvents, 48);
  853. }
  854. }
  855. CGBoat::CGBoat(IGameInfoCallback * cb)
  856. : CGObjectInstance(cb)
  857. , CBonusSystemNode(BonusNodeType::BOAT)
  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(IGameRandomizer & gameRandomizer)
  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, ChangeValueMode::RELATIVE);
  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->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. const TeamState *ts = cb->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(IGameRandomizer & gameRandomizer)
  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