CCallbackBase.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(...) if(!duringBattle()) {logGlobal->error("%s called when no battle!", __FUNCTION__); return __VA_ARGS__; }
  13. class IBattleInfo;
  14. class 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 IBattleInfo * battle; //battle to which the player is engaged, nullptr if none or not applicable
  20. const IBattleInfo * getBattle() const;
  21. protected:
  22. boost::optional<PlayerColor> player; // not set gives access to all information, otherwise callback provides only information "visible" for player
  23. CCallbackBase(boost::optional<PlayerColor> Player);
  24. CCallbackBase();
  25. void setBattle(const IBattleInfo * B);
  26. bool duringBattle() const;
  27. public:
  28. boost::optional<PlayerColor> getPlayerID() const;
  29. friend class CBattleInfoEssentials;
  30. };