2
0

IObjectInterface.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * IObjectInterface.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 "IObjectInterface.h"
  12. #include "CGTownInstance.h"
  13. #include "MiscObjects.h"
  14. #include "../NetPacks.h"
  15. #include "../IGameCallback.h"
  16. #include "../TerrainHandler.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. IGameCallback * IObjectInterface::cb = nullptr;
  19. void IObjectInterface::showInfoDialog(const ui32 txtID, const ui16 soundID, EInfoWindowMode mode) const
  20. {
  21. InfoWindow iw;
  22. iw.soundID = soundID;
  23. iw.player = getOwner();
  24. iw.type = mode;
  25. iw.text.appendLocalString(EMetaText::ADVOB_TXT,txtID);
  26. IObjectInterface::cb->sendAndApply(&iw);
  27. }
  28. ///IObjectInterface
  29. void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
  30. {}
  31. void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
  32. {}
  33. void IObjectInterface::newTurn(CRandomGenerator & rand) const
  34. {}
  35. void IObjectInterface::initObj(CRandomGenerator & rand)
  36. {}
  37. void IObjectInterface::setProperty( ui8 what, ui32 val )
  38. {}
  39. bool IObjectInterface::wasVisited (PlayerColor player) const
  40. {
  41. return false;
  42. }
  43. bool IObjectInterface::wasVisited (const CGHeroInstance * h) const
  44. {
  45. return false;
  46. }
  47. void IObjectInterface::postInit()
  48. {}
  49. void IObjectInterface::preInit()
  50. {}
  51. void IObjectInterface::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
  52. {}
  53. void IObjectInterface::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
  54. {}
  55. void IObjectInterface::garrisonDialogClosed(const CGHeroInstance *hero) const
  56. {}
  57. void IObjectInterface::heroLevelUpDone(const CGHeroInstance *hero) const
  58. {}
  59. int3 IBoatGenerator::bestLocation() const
  60. {
  61. std::vector<int3> offsets;
  62. getOutOffsets(offsets);
  63. for (auto & offset : offsets)
  64. {
  65. int3 targetTile = getObject()->visitablePos() + offset;
  66. const TerrainTile *tile = getObject()->cb->getTile(targetTile, false);
  67. if(tile) //tile is in the map
  68. {
  69. if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat
  70. return targetTile;
  71. }
  72. }
  73. return int3 (-1,-1,-1);
  74. }
  75. IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const
  76. {
  77. int3 tile = bestLocation();
  78. if(!tile.valid())
  79. return TILE_BLOCKED; //no available water
  80. const TerrainTile *t = IObjectInterface::cb->getTile(tile);
  81. if(!t)
  82. return TILE_BLOCKED; //no available water
  83. if(t->blockingObjects.empty())
  84. return GOOD; //OK
  85. if(t->blockingObjects.front()->ID == Obj::BOAT)
  86. return BOAT_ALREADY_BUILT; //blocked with boat
  87. return TILE_BLOCKED; //blocked
  88. }
  89. void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visitor) const
  90. {
  91. switch(shipyardStatus())
  92. {
  93. case BOAT_ALREADY_BUILT:
  94. out.appendLocalString(EMetaText::GENERAL_TXT, 51);
  95. break;
  96. case TILE_BLOCKED:
  97. if(visitor)
  98. {
  99. out.appendLocalString(EMetaText::GENERAL_TXT, 134);
  100. out.replaceRawString(visitor->getNameTranslated());
  101. }
  102. else
  103. out.appendLocalString(EMetaText::ADVOB_TXT, 189);
  104. break;
  105. case NO_WATER:
  106. logGlobal->error("Shipyard without water at tile %s! ", getObject()->getPosition().toString());
  107. return;
  108. }
  109. }
  110. void IShipyard::getBoatCost(TResources & cost) const
  111. {
  112. cost[EGameResID::WOOD] = 10;
  113. cost[EGameResID::GOLD] = 1000;
  114. }
  115. const IShipyard * IShipyard::castFrom( const CGObjectInstance *obj )
  116. {
  117. return dynamic_cast<const IShipyard *>(obj);
  118. }
  119. VCMI_LIB_NAMESPACE_END