IGameCallback.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. #define VCMI_DLL
  2. #include "IGameCallback.h"
  3. #include "../lib/CGameState.h"
  4. #include "../lib/map.h"
  5. #include "CObjectHandler.h"
  6. #include "CHeroHandler.h"
  7. #include "../StartInfo.h"
  8. #include "CArtHandler.h"
  9. #include "CSpellHandler.h"
  10. #include "../lib/VCMI_Lib.h"
  11. #include <boost/random/linear_congruential.hpp>
  12. #include "CTownHandler.h"
  13. #include "BattleState.h"
  14. #include <boost/foreach.hpp>
  15. #include "NetPacks.h"
  16. #include <boost/bind.hpp>
  17. #include "CBuildingHandler.h"
  18. /*
  19. * IGameCallback.cpp, part of VCMI engine
  20. *
  21. * Authors: listed in file AUTHORS in main folder
  22. *
  23. * License: GNU General Public License v2.0 or later
  24. * Full text of license available in license.txt file, in main folder
  25. *
  26. */
  27. //TODO make clean
  28. #define ERROR_SILENT_RET_VAL_IF(cond, txt, retVal) do {if(cond){return retVal;}} while(0)
  29. #define ERROR_VERBOSE_OR_NOT_RET_VAL_IF(cond, verbose, txt, retVal) do {if(cond){if(verbose)tlog1 << BOOST_CURRENT_FUNCTION << ": " << txt << std::endl; return retVal;}} while(0)
  30. #define ERROR_RET_IF(cond, txt) do {if(cond){tlog1 << BOOST_CURRENT_FUNCTION << ": " << txt << std::endl; return;}} while(0)
  31. #define ERROR_RET_VAL_IF(cond, txt, retVal) do {if(cond){tlog1 << BOOST_CURRENT_FUNCTION << ": " << txt << std::endl; return retVal;}} while(0)
  32. extern boost::rand48 ran;
  33. si8 CBattleInfoCallback::battleHasDistancePenalty( const CStack * stack, THex destHex )
  34. {
  35. return gs->curB->hasDistancePenalty(stack, destHex);
  36. }
  37. si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, THex destHex )
  38. {
  39. return gs->curB->hasWallPenalty(stack, destHex);
  40. }
  41. si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, THex destHex, int telportLevel)
  42. {
  43. return gs->curB->canTeleportTo(stack, destHex, telportLevel);
  44. }
  45. std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
  46. {
  47. if(!hex.isValid())
  48. hex = stack->position;
  49. std::vector<int> ret;
  50. bool ac[BFIELD_SIZE] = {0};
  51. std::set<THex> occupyable;
  52. gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack);
  53. THex pr[BFIELD_SIZE];
  54. int dist[BFIELD_SIZE];
  55. gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
  56. for(int i=0; i<BFIELD_SIZE; ++i)
  57. {
  58. if(pr[i] == -1)
  59. ret.push_back(-1);
  60. else
  61. ret.push_back(dist[i]);
  62. }
  63. if(predecessors)
  64. {
  65. memcpy(predecessors, pr, BFIELD_SIZE * sizeof(THex));
  66. }
  67. return ret;
  68. }
  69. SpellCasting::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell( const CSpell * spell )
  70. {
  71. if(!gs->curB)
  72. {
  73. tlog1 << "battleCanCastThisSpell called when there is no battle!\n";
  74. return SpellCasting::NO_HERO_TO_CAST_SPELL;
  75. }
  76. return gs->curB->battleCanCastThisSpell(player, spell, SpellCasting::HERO_CASTING);
  77. }
  78. si8 CBattleInfoCallback::battleGetTacticDist()
  79. {
  80. if (!gs->curB)
  81. {
  82. tlog1 << "battleGetTacticDist called when no battle!\n";
  83. return 0;
  84. }
  85. if (gs->curB->sides[gs->curB->tacticsSide] == player)
  86. {
  87. return gs->curB->tacticDistance;
  88. }
  89. return 0;
  90. }
  91. ui8 CBattleInfoCallback::battleGetMySide()
  92. {
  93. if (!gs->curB)
  94. {
  95. tlog1 << "battleGetMySide called when no battle!\n";
  96. return 0;
  97. }
  98. return gs->curB->sides[1] == player;
  99. }
  100. int CBattleInfoCallback::battleGetSurrenderCost()
  101. {
  102. if (!gs->curB)
  103. {
  104. tlog1 << "battleGetSurrenderCost called when no battle!\n";
  105. return -1;
  106. }
  107. return gs->curB->getSurrenderingCost(player);
  108. }
  109. int CBattleInfoCallback::battleGetBattlefieldType()
  110. {
  111. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  112. //return gs->battleGetBattlefieldType();
  113. if(!gs->curB)
  114. {
  115. tlog2<<"battleGetBattlefieldType called when there is no battle!"<<std::endl;
  116. return -1;
  117. }
  118. return gs->curB->battlefieldType;
  119. }
  120. int CBattleInfoCallback::battleGetObstaclesAtTile(THex tile) //returns bitfield
  121. {
  122. //TODO - write
  123. return -1;
  124. }
  125. std::vector<CObstacleInstance> CBattleInfoCallback::battleGetAllObstacles()
  126. {
  127. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  128. if(gs->curB)
  129. return gs->curB->obstacles;
  130. else
  131. return std::vector<CObstacleInstance>();
  132. }
  133. const CStack* CBattleInfoCallback::battleGetStackByID(int ID, bool onlyAlive)
  134. {
  135. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  136. if(!gs->curB) return NULL;
  137. return gs->curB->getStack(ID, onlyAlive);
  138. }
  139. const CStack* CBattleInfoCallback::battleGetStackByPos(THex pos, bool onlyAlive)
  140. {
  141. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  142. return gs->curB->battleGetStack(pos, onlyAlive);
  143. }
  144. THex CBattleInfoCallback::battleGetPos(int stack)
  145. {
  146. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  147. if(!gs->curB)
  148. {
  149. tlog2<<"battleGetPos called when there is no battle!"<<std::endl;
  150. return THex::INVALID;
  151. }
  152. for(size_t g=0; g<gs->curB->stacks.size(); ++g)
  153. {
  154. if(gs->curB->stacks[g]->ID == stack)
  155. return gs->curB->stacks[g]->position;
  156. }
  157. return THex::INVALID;
  158. }
  159. TStacks CBattleInfoCallback::battleGetStacks(EStackOwnership whose /*= MINE_AND_ENEMY*/, bool onlyAlive /*= true*/)
  160. {
  161. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  162. TStacks ret;
  163. if(!gs->curB) //there is no battle
  164. {
  165. tlog2<<"battleGetStacks called when there is no battle!"<<std::endl;
  166. return ret;
  167. }
  168. BOOST_FOREACH(const CStack *s, gs->curB->stacks)
  169. {
  170. bool ownerMatches = whose == MINE_AND_ENEMY || whose == ONLY_MINE && s->owner == player || whose == ONLY_ENEMY && s->owner != player;
  171. bool alivenessMatches = s->alive() || !onlyAlive;
  172. if(ownerMatches && alivenessMatches)
  173. ret.push_back(s);
  174. }
  175. return ret;
  176. }
  177. void CBattleInfoCallback::getStackQueue( std::vector<const CStack *> &out, int howMany )
  178. {
  179. if(!gs->curB)
  180. {
  181. tlog2 << "battleGetStackQueue called when there is not battle!" << std::endl;
  182. return;
  183. }
  184. gs->curB->getStackQueue(out, howMany);
  185. }
  186. std::vector<THex> CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable)
  187. {
  188. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  189. if(!gs->curB)
  190. {
  191. tlog2<<"battleGetAvailableHexes called when there is no battle!"<<std::endl;
  192. return std::vector<THex>();
  193. }
  194. return gs->curB->getAccessibility(stack, addOccupiable, attackable);
  195. //return gs->battleGetRange(ID);
  196. }
  197. bool CBattleInfoCallback::battleCanShoot(const CStack * stack, THex dest)
  198. {
  199. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  200. if(!gs->curB) return false;
  201. return gs->curB->battleCanShoot(stack, dest);
  202. }
  203. bool CBattleInfoCallback::battleCanCastSpell()
  204. {
  205. if(!gs->curB) //there is no battle
  206. return false;
  207. return gs->curB->battleCanCastSpell(player, SpellCasting::HERO_CASTING) == SpellCasting::OK;
  208. }
  209. bool CBattleInfoCallback::battleCanFlee()
  210. {
  211. return gs->curB->battleCanFlee(player);
  212. }
  213. const CGTownInstance *CBattleInfoCallback::battleGetDefendedTown()
  214. {
  215. if(!gs->curB || gs->curB->town == NULL)
  216. return NULL;
  217. return gs->curB->town;
  218. }
  219. ui8 CBattleInfoCallback::battleGetWallState(int partOfWall)
  220. {
  221. if(!gs->curB || gs->curB->siege == 0)
  222. {
  223. return 0;
  224. }
  225. return gs->curB->si.wallState[partOfWall];
  226. }
  227. int CBattleInfoCallback::battleGetWallUnderHex(THex hex)
  228. {
  229. if(!gs->curB || gs->curB->siege == 0)
  230. {
  231. return -1;
  232. }
  233. return gs->curB->hexToWallPart(hex);
  234. }
  235. TDmgRange CBattleInfoCallback::battleEstimateDamage(const CStack * attacker, const CStack * defender, TDmgRange * retaliationDmg)
  236. {
  237. if(!gs->curB)
  238. return std::make_pair(0, 0);
  239. const CGHeroInstance * attackerHero, * defenderHero;
  240. bool shooting = battleCanShoot(attacker, defender->position);
  241. if(gs->curB->sides[0] == attacker->owner)
  242. {
  243. attackerHero = gs->curB->heroes[0];
  244. defenderHero = gs->curB->heroes[1];
  245. }
  246. else
  247. {
  248. attackerHero = gs->curB->heroes[1];
  249. defenderHero = gs->curB->heroes[0];
  250. }
  251. TDmgRange ret = gs->curB->calculateDmgRange(attacker, defender, attackerHero, defenderHero, shooting, 0, false, false);
  252. if(retaliationDmg)
  253. {
  254. if(shooting)
  255. {
  256. retaliationDmg->first = retaliationDmg->second = 0;
  257. }
  258. else
  259. {
  260. ui32 TDmgRange::* pairElems[] = {&TDmgRange::first, &TDmgRange::second};
  261. for (int i=0; i<2; ++i)
  262. {
  263. BattleStackAttacked bsa;
  264. bsa.damageAmount = ret.*pairElems[i];
  265. retaliationDmg->*pairElems[!i] = gs->curB->calculateDmgRange(defender, attacker, bsa.newAmount, attacker->count, attackerHero, defenderHero, false, false, false, false).*pairElems[!i];
  266. }
  267. }
  268. }
  269. return ret;
  270. }
  271. ui8 CBattleInfoCallback::battleGetSiegeLevel()
  272. {
  273. if(!gs->curB)
  274. return 0;
  275. return gs->curB->siege;
  276. }
  277. const CGHeroInstance * CBattleInfoCallback::battleGetFightingHero(ui8 side) const
  278. {
  279. if(!gs->curB)
  280. return 0;
  281. return gs->curB->heroes[side];
  282. }
  283. CGameState *const CPrivilagedInfoCallback::gameState ()
  284. {
  285. return gs;
  286. }
  287. int CGameInfoCallback::getOwner(int heroID) const
  288. {
  289. const CGObjectInstance *obj = getObj(heroID);
  290. ERROR_RET_VAL_IF(!obj, "No such object!", -1);
  291. return gs->map->objects[heroID]->tempOwner;
  292. }
  293. int CGameInfoCallback::getResource(int Player, int which) const
  294. {
  295. const PlayerState *p = getPlayer(Player);
  296. ERROR_RET_VAL_IF(!p, "No player info!", -1);
  297. ERROR_RET_VAL_IF(p->resources.size() <= which || which < 0, "No such resource!", -1);
  298. return p->resources[which];
  299. }
  300. const CGHeroInstance* CGameInfoCallback::getSelectedHero( int Player ) const
  301. {
  302. const PlayerState *p = getPlayer(Player);
  303. ERROR_RET_VAL_IF(!p, "No player info!", NULL);
  304. return getHero(p->currentSelection);
  305. }
  306. const CGHeroInstance* CGameInfoCallback::getSelectedHero() const
  307. {
  308. return getSelectedHero(gs->currentPlayer);
  309. }
  310. const PlayerSettings * CGameInfoCallback::getPlayerSettings(int color) const
  311. {
  312. return &gs->scenarioOps->getIthPlayersSettings(color);
  313. }
  314. void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ ) const
  315. {
  316. if(player >= PLAYER_LIMIT)
  317. {
  318. tlog1 << "Illegal call to getTilesInRange!\n";
  319. return;
  320. }
  321. if (radious == -1) //reveal entire map
  322. getAllTiles (tiles, player, -1, 0);
  323. else
  324. {
  325. const TeamState * team = gs->getPlayerTeam(player);
  326. for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++)
  327. {
  328. for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(pos.y + radious, gs->map->height - 1); yd++)
  329. {
  330. double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5;
  331. if(distance <= radious)
  332. {
  333. if(player < 0
  334. || (mode == 1 && team->fogOfWarMap[xd][yd][pos.z]==0)
  335. || (mode == -1 && team->fogOfWarMap[xd][yd][pos.z]==1)
  336. )
  337. tiles.insert(int3(xd,yd,pos.z));
  338. }
  339. }
  340. }
  341. }
  342. }
  343. void CPrivilagedInfoCallback::getAllTiles (boost::unordered_set<int3, ShashInt3> &tiles, int Player/*=-1*/, int level, int surface ) const
  344. {
  345. if(Player >= PLAYER_LIMIT)
  346. {
  347. tlog1 << "Illegal call to getAllTiles !\n";
  348. return;
  349. }
  350. bool water = surface == 0 || surface == 2,
  351. land = surface == 0 || surface == 1;
  352. std::vector<int> floors;
  353. if(level == -1)
  354. {
  355. for (int xd = 0; xd <= gs->map->width - 1; xd++)
  356. for(int b=0; b<gs->map->twoLevel + 1; ++b) //if gs->map->twoLevel is false then false (0) + 1 is 1, if it's true (1) then we have 2
  357. {
  358. floors.push_back(b);
  359. }
  360. }
  361. else
  362. floors.push_back(level);
  363. for (std::vector<int>::const_iterator i = floors.begin(); i!= floors.end(); i++)
  364. {
  365. register int zd = *i;
  366. for (int xd = 0; xd < gs->map->width; xd++)
  367. {
  368. for (int yd = 0; yd < gs->map->height; yd++)
  369. {
  370. if ((getTile (int3 (xd,yd,zd))->tertype == 8 && water)
  371. || (getTile (int3 (xd,yd,zd))->tertype != 8 && land))
  372. tiles.insert(int3(xd,yd,zd));
  373. }
  374. }
  375. }
  376. }
  377. void CPrivilagedInfoCallback::getFreeTiles (std::vector<int3> &tiles) const
  378. {
  379. std::vector<int> floors;
  380. for (int b=0; b<gs->map->twoLevel + 1; ++b) //if gs->map->twoLevel is false then false (0) + 1 is 1, if it's true (1) then we have 2
  381. {
  382. floors.push_back(b);
  383. }
  384. const TerrainTile *tinfo;
  385. for (std::vector<int>::const_iterator i = floors.begin(); i!= floors.end(); i++)
  386. {
  387. register int zd = *i;
  388. for (int xd = 0; xd < gs->map->width; xd++)
  389. {
  390. for (int yd = 0; yd < gs->map->height; yd++)
  391. {
  392. tinfo = getTile(int3 (xd,yd,zd));
  393. if (tinfo->tertype != 8 && !tinfo->blocked) //land and free
  394. tiles.push_back (int3 (xd,yd,zd));
  395. }
  396. }
  397. }
  398. }
  399. bool CGameInfoCallback::isAllowed( int type, int id )
  400. {
  401. switch(type)
  402. {
  403. case 0:
  404. return gs->map->allowedSpell[id];
  405. case 1:
  406. return gs->map->allowedArtifact[id];
  407. case 2:
  408. return gs->map->allowedAbilities[id];
  409. default:
  410. ERROR_RET_VAL_IF(1, "Wrong type!", false);
  411. }
  412. }
  413. void CPrivilagedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact*> &out)
  414. {
  415. for (int i = 0; i < 2; i++)
  416. {
  417. for (int j = 0; j < 3 ; j++)
  418. {
  419. out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_TREASURE << i)]);
  420. }
  421. }
  422. out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_MAJOR)]);
  423. }
  424. ui16 CPrivilagedInfoCallback::getRandomArt (int flags)
  425. {
  426. return VLC->arth->getRandomArt(flags);
  427. }
  428. ui16 CPrivilagedInfoCallback::getArtSync (ui32 rand, int flags)
  429. {
  430. return VLC->arth->getArtSync (rand, flags);
  431. }
  432. void CPrivilagedInfoCallback::erasePickedArt (si32 id)
  433. {
  434. VLC->arth->erasePickedArt(id);
  435. }
  436. void CPrivilagedInfoCallback::getAllowedSpells(std::vector<ui16> &out, ui16 level)
  437. {
  438. CSpell *spell;
  439. for (int i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?)
  440. {
  441. spell = VLC->spellh->spells[i];
  442. if (isAllowed (0, spell->id) && spell->level == level)
  443. {
  444. out.push_back(spell->id);
  445. }
  446. }
  447. }
  448. inline TerrainTile * CNonConstInfoCallback::getTile( int3 pos )
  449. {
  450. if(!gs->map->isInTheMap(pos))
  451. return NULL;
  452. return &gs->map->getTile(pos);
  453. }
  454. const PlayerState * CGameInfoCallback::getPlayer(int color, bool verbose) const
  455. {
  456. ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", NULL);
  457. ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!vstd::contains(gs->players,color), verbose, "Cannot find player " << color << "info!", NULL);
  458. return &gs->players[color];
  459. }
  460. const CTown * CGameInfoCallback::getNativeTown(int color) const
  461. {
  462. const PlayerSettings *ps = getPlayerSettings(color);
  463. ERROR_RET_VAL_IF(!ps, "There is no such player!", NULL);
  464. return &VLC->townh->towns[ps->castle];
  465. }
  466. const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(int identifier) const
  467. {
  468. ERROR_RET_VAL_IF(!vstd::contains(gs->map->questIdentifierToId, identifier), "There is no object with such quest identifier!", NULL);
  469. return getObj(gs->map->questIdentifierToId[identifier]);
  470. }
  471. /************************************************************************/
  472. /* */
  473. /************************************************************************/
  474. const CGObjectInstance* CGameInfoCallback::getObj(int objid, bool verbose) const
  475. {
  476. if(objid < 0 || objid >= gs->map->objects.size())
  477. {
  478. if(verbose)
  479. tlog1 << "Cannot get object with id " << objid << std::endl;
  480. return NULL;
  481. }
  482. const CGObjectInstance *ret = gs->map->objects[objid];
  483. if(!ret)
  484. {
  485. if(verbose)
  486. tlog1 << "Cannot get object with id " << objid << ". Object was removed.\n";
  487. return NULL;
  488. }
  489. if(!isVisible(ret, player))
  490. {
  491. if(verbose)
  492. tlog1 << "Cannot get object with id " << objid << ". Object is not visible.\n";
  493. return NULL;
  494. }
  495. return ret;
  496. }
  497. const CGHeroInstance* CGameInfoCallback::getHero(int objid) const
  498. {
  499. const CGObjectInstance *obj = getObj(objid, false);
  500. if(obj)
  501. return dynamic_cast<const CGHeroInstance*>(obj);
  502. else
  503. return NULL;
  504. }
  505. const CGTownInstance* CGameInfoCallback::getTown(int objid) const
  506. {
  507. const CGObjectInstance *obj = getObj(objid, false);
  508. if(obj)
  509. return dynamic_cast<const CGTownInstance*>(gs->map->objects[objid].get());
  510. else
  511. return NULL;
  512. }
  513. void CGameInfoCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos, UpgradeInfo &out) const
  514. {
  515. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  516. ERROR_RET_IF(!canGetFullInfo(obj), "Cannot get info about not owned object!");
  517. ERROR_RET_IF(!obj->hasStackAtSlot(stackPos), "There is no such stack!");
  518. out = gs->getUpgradeInfo(obj->getStack(stackPos));
  519. //return gs->getUpgradeInfo(obj->getStack(stackPos));
  520. }
  521. const StartInfo * CGameInfoCallback::getStartInfo() const
  522. {
  523. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  524. return gs->scenarioOps;
  525. }
  526. int CGameInfoCallback::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const
  527. {
  528. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  529. ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
  530. //if there is a battle
  531. if(gs->curB)
  532. return gs->curB->getSpellCost(sp, caster);
  533. //if there is no battle
  534. return caster->getSpellCost(sp);
  535. }
  536. int CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
  537. {
  538. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  539. ERROR_RET_VAL_IF(hero && !canGetFullInfo(hero), "Cannot get info about caster!", -1);
  540. if(!gs->curB) //no battle
  541. {
  542. if (hero) //but we see hero's spellbook
  543. return gs->curB->calculateSpellDmg(sp, hero, NULL, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(2));
  544. else
  545. return 0; //mage guild
  546. }
  547. //gs->getHero(gs->currentPlayer)
  548. //const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1];
  549. const CGHeroInstance * ourHero = hero;
  550. return gs->curB->calculateSpellDmg(sp, ourHero, NULL, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(2));
  551. }
  552. void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
  553. {
  554. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  555. ERROR_RET_IF(!obj, "No guild object!");
  556. ERROR_RET_IF(obj->ID == TOWNI_TYPE && !canGetFullInfo(obj), "Cannot get info about town guild object!");
  557. //TODO: advmap object -> check if they're visited by our hero
  558. if(obj->ID == TOWNI_TYPE || obj->ID == 95) //it is a town or adv map tavern
  559. {
  560. gs->obtainPlayersStats(thi, gs->players[obj->tempOwner].towns.size());
  561. }
  562. else if(obj->ID == 97) //Den of Thieves
  563. {
  564. gs->obtainPlayersStats(thi, 20);
  565. }
  566. }
  567. int CGameInfoCallback::howManyTowns(int Player) const
  568. {
  569. ERROR_RET_VAL_IF(!hasAccess(Player), "Access forbidden!", -1);
  570. return gs->players[Player].towns.size();
  571. }
  572. bool CGameInfoCallback::getTownInfo( const CGObjectInstance *town, InfoAboutTown &dest ) const
  573. {
  574. ERROR_RET_VAL_IF(!isVisible(town, player), "Town is not visible!", false); //it's not a town or it's not visible for layer
  575. bool detailed = hasAccess(town->tempOwner);
  576. //TODO vision support
  577. if(town->ID == TOWNI_TYPE)
  578. dest.initFromTown(static_cast<const CGTownInstance *>(town), detailed);
  579. else if(town->ID == 33 || town->ID == 219)
  580. dest.initFromGarrison(static_cast<const CGGarrison *>(town), detailed);
  581. else
  582. return false;
  583. return true;
  584. }
  585. int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const
  586. {
  587. ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", int3(-1,-1,-1));
  588. return gs->guardingCreaturePosition(pos);
  589. }
  590. bool CGameInfoCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero &dest ) const
  591. {
  592. const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(hero);
  593. ERROR_RET_VAL_IF(!h, "That's not a hero!", false);
  594. ERROR_RET_VAL_IF(!isVisible(h->getPosition(false)), "That hero is not visible!", false);
  595. //TODO vision support
  596. dest.initFromHero(h, hasAccess(h->tempOwner));
  597. return true;
  598. }
  599. int CGameInfoCallback::getDate(int mode) const
  600. {
  601. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  602. return gs->getDate(mode);
  603. }
  604. std::vector < std::string > CGameInfoCallback::getObjDescriptions(int3 pos) const
  605. {
  606. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  607. std::vector<std::string> ret;
  608. const TerrainTile *t = getTile(pos);
  609. ERROR_RET_VAL_IF(!t, "Not a valid tile given!", ret);
  610. BOOST_FOREACH(const CGObjectInstance * obj, t->blockingObjects)
  611. ret.push_back(obj->getHoverText());
  612. return ret;
  613. }
  614. bool CGameInfoCallback::verifyPath(CPath * path, bool blockSea) const
  615. {
  616. for (size_t i=0; i < path->nodes.size(); ++i)
  617. {
  618. const TerrainTile *t = getTile(path->nodes[i].coord); //current tile
  619. ERROR_RET_VAL_IF(!t, "Path contains not visible tile: " << path->nodes[i].coord << "!", false);
  620. if (t->blocked && !t->visitable)
  621. return false; //path is wrong - one of the tiles is blocked
  622. if (blockSea)
  623. {
  624. if (i==0)
  625. continue;
  626. const TerrainTile *prev = getTile(path->nodes[i-1].coord); //tile of previous node on the path
  627. if (( t->tertype == TerrainTile::water && prev->tertype != TerrainTile::water)
  628. || (t->tertype != TerrainTile::water && prev->tertype == TerrainTile::water)
  629. || prev->tertype == TerrainTile::rock
  630. )
  631. return false;
  632. }
  633. }
  634. return true;
  635. }
  636. bool CGameInfoCallback::isVisible(int3 pos, int Player) const
  637. {
  638. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  639. return gs->map->isInTheMap(pos) && (Player == -1 || gs->isVisible(pos, Player));
  640. }
  641. bool CGameInfoCallback::isVisible(int3 pos) const
  642. {
  643. return isVisible(pos,player);
  644. }
  645. bool CGameInfoCallback::isVisible( const CGObjectInstance *obj, int Player ) const
  646. {
  647. return gs->isVisible(obj, Player);
  648. }
  649. bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
  650. {
  651. return isVisible(obj, player);
  652. }
  653. // const CCreatureSet* CInfoCallback::getGarrison(const CGObjectInstance *obj) const
  654. // {
  655. // //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  656. // if()
  657. // const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
  658. // if(!armi)
  659. // return NULL;
  660. // else
  661. // return armi;
  662. // }
  663. std::vector < const CGObjectInstance * > CGameInfoCallback::getBlockingObjs( int3 pos ) const
  664. {
  665. std::vector<const CGObjectInstance *> ret;
  666. const TerrainTile *t = getTile(pos);
  667. ERROR_RET_VAL_IF(!t, "Not a valid tile requested!", ret);
  668. BOOST_FOREACH(const CGObjectInstance * obj, t->blockingObjects)
  669. ret.push_back(obj);
  670. return ret;
  671. }
  672. std::vector < const CGObjectInstance * > CGameInfoCallback::getVisitableObjs( int3 pos ) const
  673. {
  674. std::vector<const CGObjectInstance *> ret;
  675. const TerrainTile *t = getTile(pos);
  676. ERROR_RET_VAL_IF(!t, "Not a valid tile requested!", ret);
  677. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  678. BOOST_FOREACH(const CGObjectInstance * obj, t->visitableObjects)
  679. ret.push_back(obj);
  680. return ret;
  681. }
  682. std::vector < const CGObjectInstance * > CGameInfoCallback::getFlaggableObjects(int3 pos) const
  683. {
  684. std::vector<const CGObjectInstance *> ret;
  685. const TerrainTile *t = getTile(pos);
  686. ERROR_RET_VAL_IF(!t, "Not a valid tile requested!", ret);
  687. BOOST_FOREACH(const CGObjectInstance *obj, t->blockingObjects)
  688. if(obj->tempOwner != 254)
  689. ret.push_back(obj);
  690. // const std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
  691. // for(size_t b=0; b<objs.size(); ++b)
  692. // {
  693. // if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
  694. // ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);
  695. // }
  696. return ret;
  697. }
  698. int3 CGameInfoCallback::getMapSize() const
  699. {
  700. return int3(gs->map->width, gs->map->height, gs->map->twoLevel+1);
  701. }
  702. std::vector<const CGHeroInstance *> CGameInfoCallback::getAvailableHeroes(const CGObjectInstance * townOrTavern) const
  703. {
  704. std::vector<const CGHeroInstance *> ret;
  705. ERROR_RET_VAL_IF(!isOwnedOrVisited(townOrTavern), "Town or tavern must be owned or visited!", ret);
  706. ret.resize(gs->players[player].availableHeroes.size());
  707. std::copy(gs->players[player].availableHeroes.begin(),gs->players[player].availableHeroes.end(),ret.begin());
  708. return ret;
  709. }
  710. const TerrainTile * CGameInfoCallback::getTile( int3 tile, bool verbose) const
  711. {
  712. ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!isVisible(tile), verbose, tile << " is not visible!", NULL);
  713. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  714. return &gs->map->getTile(tile);
  715. }
  716. int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID )
  717. {
  718. ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", -1);
  719. int ret = Buildings::ALLOWED;
  720. if(t->builded >= MAX_BUILDING_PER_TURN)
  721. ret = Buildings::CANT_BUILD_TODAY; //building limit
  722. CBuilding * pom = VLC->buildh->buildings[t->subID][ID];
  723. if(!pom)
  724. return Buildings::ERROR;
  725. //checking resources
  726. for(int res=0; res<RESOURCE_QUANTITY; res++)
  727. {
  728. if(pom->resources[res] > getResource(t->tempOwner, res))
  729. ret = Buildings::NO_RESOURCES; //lack of res
  730. }
  731. //checking for requirements
  732. std::set<int> reqs = getBuildingRequiments(t, ID);//getting all requirements
  733. for( std::set<int>::iterator ri = reqs.begin(); ri != reqs.end(); ri++ )
  734. {
  735. if(t->builtBuildings.find(*ri)==t->builtBuildings.end())
  736. ret = Buildings::PREREQUIRES; //lack of requirements - cannot build
  737. }
  738. //can we build it?
  739. if(t->forbiddenBuildings.find(ID)!=t->forbiddenBuildings.end())
  740. ret = Buildings::FORBIDDEN; //forbidden
  741. if(ID == 13) //capitol
  742. {
  743. const PlayerState *ps = getPlayer(t->tempOwner);
  744. if(ps)
  745. {
  746. BOOST_FOREACH(const CGTownInstance *t, ps->towns)
  747. {
  748. if(vstd::contains(t->builtBuildings, 13))
  749. {
  750. ret = Buildings::HAVE_CAPITAL; //no more than one capitol
  751. break;
  752. }
  753. }
  754. }
  755. }
  756. else if(ID == 6) //shipyard
  757. {
  758. const TerrainTile *tile = getTile(t->bestLocation());
  759. if(!tile || tile->tertype != TerrainTile::water )
  760. ret = Buildings::NO_WATER; //lack of water
  761. }
  762. if(t->builtBuildings.find(ID)!=t->builtBuildings.end()) //already built
  763. ret = Buildings::ALREADY_PRESENT;
  764. return ret;
  765. }
  766. std::set<int> CGameInfoCallback::getBuildingRequiments( const CGTownInstance *t, int ID )
  767. {
  768. ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", std::set<int>());
  769. std::set<int> used;
  770. used.insert(ID);
  771. std::set<int> reqs = VLC->townh->requirements[t->subID][ID];
  772. while(true)
  773. {
  774. size_t noloop=0;
  775. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  776. {
  777. if(used.find(*i)==used.end()) //we haven't added requirements for this building
  778. {
  779. used.insert(*i);
  780. for(
  781. std::set<int>::iterator j=VLC->townh->requirements[t->subID][*i].begin();
  782. j!=VLC->townh->requirements[t->subID][*i].end();
  783. j++)
  784. {
  785. reqs.insert(*j);//creating full list of requirements
  786. }
  787. }
  788. else
  789. {
  790. noloop++;
  791. }
  792. }
  793. if(noloop==reqs.size())
  794. break;
  795. }
  796. return reqs;
  797. }
  798. const CMapHeader * CGameInfoCallback::getMapHeader() const
  799. {
  800. return gs->map;
  801. }
  802. bool CGameInfoCallback::hasAccess(int playerId) const
  803. {
  804. return player < 0 || gs->getPlayerRelations( playerId, player );
  805. }
  806. int CGameInfoCallback::getPlayerStatus(int player) const
  807. {
  808. const PlayerState *ps = gs->getPlayer(player, false);
  809. if(!ps)
  810. return -1;
  811. return ps->status;
  812. }
  813. std::string CGameInfoCallback::getTavernGossip(const CGObjectInstance * townOrTavern) const
  814. {
  815. return "GOSSIP TEST";
  816. }
  817. int CGameInfoCallback::getPlayerRelations( ui8 color1, ui8 color2 ) const
  818. {
  819. return gs->getPlayerRelations(color1, color2);
  820. }
  821. bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const
  822. {
  823. return !obj || hasAccess(obj->tempOwner);
  824. }
  825. int CGameInfoCallback::getHeroCount( int player, bool includeGarrisoned ) const
  826. {
  827. int ret = 0;
  828. const PlayerState *p = gs->getPlayer(player);
  829. ERROR_RET_VAL_IF(!p, "No such player!", -1);
  830. if(includeGarrisoned)
  831. return p->heroes.size();
  832. else
  833. for(int i=0; i < p->heroes.size(); i++)
  834. if(!p->heroes[i]->inTownGarrison)
  835. ret++;
  836. return ret;
  837. }
  838. bool CGameInfoCallback::isOwnedOrVisited(const CGObjectInstance *obj) const
  839. {
  840. if(canGetFullInfo(obj))
  841. return true;
  842. const TerrainTile *t = getTile(obj->visitablePos()); //get entrance tile
  843. const CGObjectInstance *visitor = t->visitableObjects.back(); //visitong hero if present or the obejct itself at last
  844. return visitor->ID == HEROI_TYPE && canGetFullInfo(visitor); //owned or allied hero is a visitor
  845. }
  846. int CGameInfoCallback::getCurrentPlayer() const
  847. {
  848. return gs->currentPlayer;
  849. }
  850. CGameInfoCallback::CGameInfoCallback()
  851. {
  852. }
  853. const std::vector< std::vector< std::vector<unsigned char> > > & CPlayerSpecificInfoCallback::getVisibilityMap() const
  854. {
  855. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  856. return gs->getPlayerTeam(player)->fogOfWarMap;
  857. }
  858. int CPlayerSpecificInfoCallback::howManyTowns() const
  859. {
  860. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  861. ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1);
  862. return CGameInfoCallback::howManyTowns(player);
  863. }
  864. std::vector < const CGTownInstance *> CPlayerSpecificInfoCallback::getTownsInfo(bool onlyOur) const
  865. {
  866. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  867. std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
  868. for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
  869. {
  870. for (size_t j=0; j < (*i).second.towns.size(); ++j)
  871. {
  872. if ((*i).first==player
  873. || (isVisible((*i).second.towns[j],player) && !onlyOur))
  874. {
  875. ret.push_back((*i).second.towns[j]);
  876. }
  877. }
  878. } // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
  879. return ret;
  880. }
  881. std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo(bool onlyOur) const
  882. {
  883. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  884. std::vector < const CGHeroInstance *> ret;
  885. for(size_t i=0;i<gs->map->heroes.size();i++)
  886. {
  887. if( (gs->map->heroes[i]->tempOwner==player) ||
  888. (isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) )
  889. {
  890. ret.push_back(gs->map->heroes[i]);
  891. }
  892. }
  893. return ret;
  894. }
  895. int CPlayerSpecificInfoCallback::getMyColor() const
  896. {
  897. return player;
  898. }
  899. int CPlayerSpecificInfoCallback::getHeroSerial(const CGHeroInstance * hero) const
  900. {
  901. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  902. for (size_t i=0; i<gs->players[player].heroes.size();i++)
  903. {
  904. if (gs->players[player].heroes[i]==hero)
  905. return i;
  906. }
  907. return -1;
  908. }
  909. int3 CPlayerSpecificInfoCallback::getGrailPos( float &outKnownRatio )
  910. {
  911. if (CGObelisk::obeliskCount == 0)
  912. {
  913. outKnownRatio = 0.0f;
  914. }
  915. else
  916. {
  917. outKnownRatio = (float)CGObelisk::visited[gs->getPlayerTeam(player)->id] / CGObelisk::obeliskCount;
  918. }
  919. return gs->map->grailPos;
  920. }
  921. std::vector < const CGObjectInstance * > CPlayerSpecificInfoCallback::getMyObjects() const
  922. {
  923. std::vector < const CGObjectInstance * > ret;
  924. BOOST_FOREACH(const CGObjectInstance * obj, gs->map->objects)
  925. {
  926. if(obj && obj->tempOwner == player)
  927. ret.push_back(obj);
  928. }
  929. return ret;
  930. }
  931. std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings() const
  932. {
  933. std::vector < const CGDwelling * > ret;
  934. BOOST_FOREACH(CGDwelling * dw, gs->getPlayer(player)->dwellings)
  935. {
  936. ret.push_back(dw);
  937. }
  938. return ret;
  939. }
  940. int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
  941. {
  942. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  943. ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1);
  944. return getHeroCount(player,includeGarrisoned);
  945. }
  946. const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId) const
  947. {
  948. const PlayerState *p = getPlayer(serialId);
  949. ERROR_RET_VAL_IF(!p, "No player info", NULL);
  950. ERROR_RET_VAL_IF(serialId < 0 || serialId >= p->heroes.size(), "No player info", NULL);
  951. return p->heroes[serialId];
  952. }
  953. const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId) const
  954. {
  955. const PlayerState *p = getPlayer(serialId);
  956. ERROR_RET_VAL_IF(!p, "No player info", NULL);
  957. ERROR_RET_VAL_IF(serialId < 0 || serialId >= p->towns.size(), "No player info", NULL);
  958. return p->towns[serialId];
  959. }
  960. int CPlayerSpecificInfoCallback::getResourceAmount(int type) const
  961. {
  962. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  963. ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1);
  964. return getResource(player, type);
  965. }
  966. std::vector<si32> CPlayerSpecificInfoCallback::getResourceAmount() const
  967. {
  968. //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
  969. ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", std::vector<si32>());
  970. return gs->players[player].resources;
  971. }
  972. CGHeroInstance *CNonConstInfoCallback::getHero(int objid)
  973. {
  974. return const_cast<CGHeroInstance*>(CGameInfoCallback::getHero(objid));
  975. }
  976. CGTownInstance *CNonConstInfoCallback::getTown(int objid)
  977. {
  978. return const_cast<CGTownInstance*>(CGameInfoCallback::getTown(objid));
  979. }
  980. TeamState *CNonConstInfoCallback::getTeam(ui8 teamID)
  981. {
  982. return const_cast<TeamState*>(CGameInfoCallback::getTeam(teamID));
  983. }
  984. TeamState *CNonConstInfoCallback::getPlayerTeam(ui8 color)
  985. {
  986. return const_cast<TeamState*>(CGameInfoCallback::getPlayerTeam(color));
  987. }
  988. PlayerState * CNonConstInfoCallback::getPlayer( ui8 color, bool verbose )
  989. {
  990. return const_cast<PlayerState*>(CGameInfoCallback::getPlayer(color, verbose));
  991. }
  992. const TeamState * CGameInfoCallback::getTeam( ui8 teamID ) const
  993. {
  994. ERROR_RET_VAL_IF(!vstd::contains(gs->teams, teamID), "Cannot find info for team " << int(teamID), NULL);
  995. const TeamState *ret = &gs->teams[teamID];
  996. ERROR_RET_VAL_IF(player != -1 && !vstd::contains(ret->players, player), "Illegal attempt to access team data!", NULL);
  997. return ret;
  998. }
  999. const TeamState * CGameInfoCallback::getPlayerTeam( ui8 teamID ) const
  1000. {
  1001. const PlayerState * ps = getPlayer(teamID);
  1002. if (ps)
  1003. return getTeam(ps->team);
  1004. return NULL;
  1005. }
  1006. const CGHeroInstance* CGameInfoCallback::getHeroWithSubid( int subid ) const
  1007. {
  1008. BOOST_FOREACH(const CGHeroInstance *h, gs->map->heroes)
  1009. if(h->subID == subid)
  1010. return h;
  1011. }
  1012. void IGameEventRealizer::showInfoDialog( InfoWindow *iw )
  1013. {
  1014. commitPackage(iw);
  1015. }