CCallbackBase.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #define ASSERT_IF_CALLED_WITH_PLAYER if(!player) {logGlobal->error(BOOST_CURRENT_FUNCTION); assert(0);}
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class IBattleInfo;
  16. class BattleInfo;
  17. class CBattleInfoEssentials;
  18. //Basic class for various callbacks (interfaces called by players to get info about game and so forth)
  19. class DLL_LINKAGE CCallbackBase
  20. {
  21. const IBattleInfo * battle = nullptr; //battle to which the player is engaged, nullptr if none or not applicable
  22. const IBattleInfo * getBattle() const;
  23. protected:
  24. boost::optional<PlayerColor> player; // not set gives access to all information, otherwise callback provides only information "visible" for player
  25. CCallbackBase(boost::optional<PlayerColor> Player);
  26. CCallbackBase() = default;
  27. void setBattle(const IBattleInfo * B);
  28. bool duringBattle() const;
  29. public:
  30. boost::optional<PlayerColor> getPlayerID() const;
  31. friend class CBattleInfoEssentials;
  32. };
  33. VCMI_LIB_NAMESPACE_END