EVictoryLossCheckResult.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * EVictoryLossCheckResult.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class DLL_LINKAGE EVictoryLossCheckResult
  13. {
  14. public:
  15. static EVictoryLossCheckResult victory(MetaString toSelf, MetaString toOthers)
  16. {
  17. return EVictoryLossCheckResult(VICTORY, toSelf, toOthers);
  18. }
  19. static EVictoryLossCheckResult defeat(MetaString toSelf, MetaString toOthers)
  20. {
  21. return EVictoryLossCheckResult(DEFEAT, toSelf, toOthers);
  22. }
  23. EVictoryLossCheckResult():
  24. intValue(0)
  25. {
  26. }
  27. bool operator==(EVictoryLossCheckResult const & other) const
  28. {
  29. return intValue == other.intValue;
  30. }
  31. bool operator!=(EVictoryLossCheckResult const & other) const
  32. {
  33. return intValue != other.intValue;
  34. }
  35. bool victory() const
  36. {
  37. return intValue == VICTORY;
  38. }
  39. bool loss() const
  40. {
  41. return intValue == DEFEAT;
  42. }
  43. EVictoryLossCheckResult invert() const
  44. {
  45. return EVictoryLossCheckResult(-intValue, messageToOthers, messageToSelf);
  46. }
  47. MetaString messageToSelf;
  48. MetaString messageToOthers;
  49. template <typename Handler> void serialize(Handler &h)
  50. {
  51. h & intValue;
  52. h & messageToSelf;
  53. h & messageToOthers;
  54. }
  55. private:
  56. enum EResult
  57. {
  58. DEFEAT = -1,
  59. INGAME = 0,
  60. VICTORY= +1
  61. };
  62. EVictoryLossCheckResult(si32 intValue, MetaString toSelf, MetaString toOthers):
  63. messageToSelf(toSelf),
  64. messageToOthers(toOthers),
  65. intValue(intValue)
  66. {
  67. }
  68. si32 intValue; // uses EResultult
  69. };
  70. VCMI_LIB_NAMESPACE_END