IObjectInterface.h 3.7 KB

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