2
0

EVictoryLossCheckResult.h 1.6 KB

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