CGameInterface.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef __CGAMEINTERFACE_H__
  2. #define __CGAMEINTERFACE_H__
  3. #include "global.h"
  4. #include <set>
  5. #include <vector>
  6. #include "lib/BattleAction.h"
  7. #include "client/FunctionList.h"
  8. #include "lib/IGameEventsReceiver.h"
  9. /*
  10. * CGameInterface.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. using namespace boost::logic;
  19. class CCallback;
  20. class CBattleCallback;
  21. class ICallback;
  22. class CGlobalAI;
  23. struct Component;
  24. class CSelectableComponent;
  25. struct TryMoveHero;
  26. class CGHeroInstance;
  27. class CGTownInstance;
  28. class CGObjectInstance;
  29. class CGBlackMarket;
  30. class CGDwelling;
  31. class CCreatureSet;
  32. class CArmedInstance;
  33. class IShipyard;
  34. class IMarket;
  35. struct BattleResult;
  36. struct BattleAttack;
  37. struct BattleStackAttacked;
  38. struct BattleSpellCast;
  39. struct SetStackEffect;
  40. struct Bonus;
  41. struct PackageApplied;
  42. struct SetObjectProperty;
  43. struct CatapultAttack;
  44. struct BattleStacksRemoved;
  45. struct StackLocation;
  46. class CStackInstance;
  47. class CStack;
  48. class CCreature;
  49. class CLoadFile;
  50. class CSaveFile;
  51. typedef si32 TQuantity;
  52. template <typename Serializer> class CISer;
  53. template <typename Serializer> class COSer;
  54. struct ArtifactLocation;
  55. class CScriptingModule;
  56. class CBattleGameInterface : public IBattleEventsReceiver
  57. {
  58. public:
  59. bool human;
  60. int playerID;
  61. std::string dllName;
  62. virtual ~CBattleGameInterface() {};
  63. virtual void init(CBattleCallback * CB){};
  64. //battle call-ins
  65. virtual BattleAction activeStack(const CStack * stack)=0; //called when it's turn of that stack
  66. };
  67. /// Central class for managing human player / AI interface logic
  68. class CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
  69. {
  70. public:
  71. virtual void init(CCallback * CB){};
  72. virtual void yourTurn(){};
  73. virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
  74. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) = 0; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  75. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done
  76. virtual void serialize(COSer<CSaveFile> &h, const int version){}; //saving
  77. virtual void serialize(CISer<CLoadFile> &h, const int version){}; //loading
  78. };
  79. class CDynLibHandler
  80. {
  81. public:
  82. static CGlobalAI * getNewAI(std::string dllname);
  83. static CBattleGameInterface * getNewBattleAI(std::string dllname);
  84. static CScriptingModule * getNewScriptingModule(std::string dllname);
  85. };
  86. class CGlobalAI : public CGameInterface // AI class (to derivate)
  87. {
  88. public:
  89. //CGlobalAI();
  90. virtual void yourTurn() OVERRIDE{};
  91. virtual void heroKilled(const CGHeroInstance*){};
  92. virtual void heroCreated(const CGHeroInstance*) OVERRIDE{};
  93. virtual void battleStackMoved(const CStack * stack, THex dest, int distance, bool end) OVERRIDE{};
  94. virtual void battleStackAttacking(int ID, int dest) {};
  95. virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) OVERRIDE{};
  96. virtual BattleAction activeStack(const CStack * stack) OVERRIDE;
  97. };
  98. #endif // __CGAMEINTERFACE_H__