IObjectInterface.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * IObjectInterface.h, 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. #pragma once
  11. #include "../callback/GameCallbackHolder.h"
  12. #include "../constants/EntityIdentifiers.h"
  13. #include "../networkPacks/EInfoWindowMode.h"
  14. #include "../networkPacks/ObjProperty.h"
  15. #include "../serializer/Serializeable.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. namespace vstd
  18. {
  19. class RNG;
  20. }
  21. struct BattleResult;
  22. class UpgradeInfo;
  23. class BoatId;
  24. class CGObjectInstance;
  25. class CStackInstance;
  26. class CGHeroInstance;
  27. class IGameInfoCallback;
  28. class IGameEventCallback;
  29. class ResourceSet;
  30. class int3;
  31. class MetaString;
  32. class PlayerColor;
  33. class IOwnableObject;
  34. class DLL_LINKAGE IObjectInterface : public GameCallbackHolder, public virtual Serializeable
  35. {
  36. public:
  37. using GameCallbackHolder::GameCallbackHolder;
  38. virtual ~IObjectInterface() = default;
  39. virtual MapObjectID getObjGroupIndex() const = 0;
  40. virtual MapObjectSubID getObjTypeIndex() const = 0;
  41. virtual PlayerColor getOwner() const = 0;
  42. virtual int3 visitablePos() const = 0;
  43. virtual int3 anchorPos() const = 0;
  44. virtual void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  45. virtual void onHeroLeave(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  46. /// Called on new turn by server. This method can not modify object state on its own
  47. /// Instead all changes must be propagated via netpacks
  48. virtual void newTurn(IGameEventCallback & gameEvents) const;
  49. virtual void initObj(vstd::RNG & rand); //synchr
  50. virtual void pickRandomObject(vstd::RNG & rand);
  51. virtual void setProperty(ObjProperty what, ObjPropertyID identifier);//synchr
  52. //Called when queries created DURING HERO VISIT are resolved
  53. //First parameter is always hero that visited object and triggered the query
  54. virtual void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const;
  55. virtual void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const;
  56. virtual void garrisonDialogClosed(IGameEventCallback & gameEvents, const CGHeroInstance *hero) const;
  57. virtual void heroLevelUpDone(IGameEventCallback & gameEvents, const CGHeroInstance *hero) const;
  58. //unified helper to show info dialog for object owner
  59. virtual void showInfoDialog(IGameEventCallback & gameEvents, const ui32 txtID, const ui16 soundID = 0, EInfoWindowMode mode = EInfoWindowMode::AUTO) const;
  60. virtual const IOwnableObject * asOwnable() const = 0;
  61. //unified interface, AI helpers
  62. virtual bool wasVisited (PlayerColor player) const;
  63. virtual bool wasVisited (const CGHeroInstance * h) const;
  64. static void preInit(); //called before objs receive their initObj
  65. static void postInit();//called after objs receive their initObj
  66. template <typename Handler> void serialize(Handler &h)
  67. {
  68. logGlobal->error("IObjectInterface serialized, unexpected, should not happen!");
  69. }
  70. };
  71. class DLL_LINKAGE ICreatureUpgrader
  72. {
  73. public:
  74. virtual void fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const = 0;
  75. virtual ~ICreatureUpgrader() = default;
  76. };
  77. class DLL_LINKAGE IBoatGenerator
  78. {
  79. public:
  80. virtual ~IBoatGenerator() = default;
  81. virtual const IObjectInterface * getObject() const = 0;
  82. virtual BoatId getBoatType() const = 0; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  83. virtual void getOutOffsets(std::vector<int3> & offsets) const = 0; //offsets to obj pos when we boat can be placed
  84. int3 bestLocation() const; //returns location when the boat should be placed
  85. enum EGeneratorState {GOOD, BOAT_ALREADY_BUILT, TILE_BLOCKED, NO_WATER, UNKNOWN};
  86. virtual EGeneratorState shipyardStatus() const;
  87. void getProblemText(MetaString &out, const CGHeroInstance *visitor = nullptr) const;
  88. };
  89. class DLL_LINKAGE IShipyard : public IBoatGenerator
  90. {
  91. public:
  92. virtual void getBoatCost(ResourceSet & cost) const;
  93. };
  94. VCMI_LIB_NAMESPACE_END