CCallbackBase.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * CCallbackBase.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 "../GameConstants.h"
  12. #define RETURN_IF_NOT_BATTLE(X) if(!duringBattle()) {logGlobal->error("%s called when no battle!", __FUNCTION__); return X; }
  13. class CGameState;
  14. struct BattleInfo;
  15. class CBattleInfoEssentials;
  16. //Basic class for various callbacks (interfaces called by players to get info about game and so forth)
  17. class DLL_LINKAGE CCallbackBase
  18. {
  19. const BattleInfo * battle; //battle to which the player is engaged, nullptr if none or not applicable
  20. const BattleInfo * getBattle() const;
  21. protected:
  22. CGameState * gs;
  23. boost::optional<PlayerColor> player; // not set gives access to all information, otherwise callback provides only information "visible" for player
  24. CCallbackBase(CGameState * GS, boost::optional<PlayerColor> Player);
  25. CCallbackBase();
  26. void setBattle(const BattleInfo * B);
  27. bool duringBattle() const;
  28. public:
  29. boost::optional<PlayerColor> getPlayerID() const;
  30. friend class CBattleInfoEssentials;
  31. };