IObjectInterface.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "../NetPacksBase.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct BattleResult;
  14. class CGObjectInstance;
  15. class CRandomGenerator;
  16. class IGameCallback;
  17. class ResourceSet;
  18. class int3;
  19. class DLL_LINKAGE IObjectInterface
  20. {
  21. public:
  22. static IGameCallback *cb;
  23. virtual ~IObjectInterface() = default;
  24. virtual int32_t getObjGroupIndex() const = 0;
  25. virtual int32_t getObjTypeIndex() const = 0;
  26. virtual PlayerColor getOwner() const = 0;
  27. virtual int3 visitablePos() const = 0;
  28. virtual int3 getPosition() const = 0;
  29. virtual void onHeroVisit(const CGHeroInstance * h) const;
  30. virtual void onHeroLeave(const CGHeroInstance * h) const;
  31. virtual void newTurn(CRandomGenerator & rand) const;
  32. virtual void initObj(CRandomGenerator & rand); //synchr
  33. virtual void setProperty(ui8 what, ui32 val);//synchr
  34. //Called when queries created DURING HERO VISIT are resolved
  35. //First parameter is always hero that visited object and triggered the query
  36. virtual void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const;
  37. virtual void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const;
  38. virtual void garrisonDialogClosed(const CGHeroInstance *hero) const;
  39. virtual void heroLevelUpDone(const CGHeroInstance *hero) const;
  40. //unified helper to show info dialog for object owner
  41. virtual void showInfoDialog(const ui32 txtID, const ui16 soundID = 0, EInfoWindowMode mode = EInfoWindowMode::AUTO) const;
  42. //unified helper to show a specific window
  43. static void openWindow(const EOpenWindowMode type, const int id1, const int id2 = -1);
  44. //unified interface, AI helpers
  45. virtual bool wasVisited (PlayerColor player) const;
  46. virtual bool wasVisited (const CGHeroInstance * h) const;
  47. static void preInit(); //called before objs receive their initObj
  48. static void postInit();//called after objs receive their initObj
  49. template <typename Handler> void serialize(Handler &h, const int version)
  50. {
  51. logGlobal->error("IObjectInterface serialized, unexpected, should not happen!");
  52. }
  53. };
  54. class DLL_LINKAGE IBoatGenerator
  55. {
  56. public:
  57. const CGObjectInstance *o;
  58. IBoatGenerator(const CGObjectInstance *O);
  59. virtual ~IBoatGenerator() = default;
  60. virtual BoatId getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  61. virtual void getOutOffsets(std::vector<int3> &offsets) const =0; //offsets to obj pos when we boat can be placed
  62. int3 bestLocation() const; //returns location when the boat should be placed
  63. enum EGeneratorState {GOOD, BOAT_ALREADY_BUILT, TILE_BLOCKED, NO_WATER};
  64. EGeneratorState shipyardStatus() const; //0 - can buid, 1 - there is already a boat at dest tile, 2 - dest tile is blocked, 3 - no water
  65. void getProblemText(MetaString &out, const CGHeroInstance *visitor = nullptr) const;
  66. template <typename Handler> void serialize(Handler &h, const int version)
  67. {
  68. h & o;
  69. }
  70. };
  71. class DLL_LINKAGE IShipyard : public IBoatGenerator
  72. {
  73. public:
  74. IShipyard(const CGObjectInstance *O);
  75. virtual void getBoatCost(ResourceSet & cost) const;
  76. static const IShipyard *castFrom(const CGObjectInstance *obj);
  77. static IShipyard *castFrom(CGObjectInstance *obj);
  78. template <typename Handler> void serialize(Handler &h, const int version)
  79. {
  80. h & static_cast<IBoatGenerator&>(*this);
  81. }
  82. };
  83. VCMI_LIB_NAMESPACE_END