supplementary_data.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * supplementary_data.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 "BAI/v13/attack_log.h"
  12. #include "BAI/v13/battlefield.h"
  13. #include "BAI/v13/global_stats.h"
  14. #include "BAI/v13/player_stats.h"
  15. #include "schema/v13/types.h"
  16. namespace MMAI::BAI::V13
  17. {
  18. using Side = Schema::Side;
  19. using ErrorCode = Schema::V13::ErrorCode;
  20. // match sides for convenience when determining winner (see `victory`)
  21. static_assert(EI(CombatResult::LEFT_WINS) == EI(Side::LEFT));
  22. static_assert(EI(CombatResult::RIGHT_WINS) == EI(Side::RIGHT));
  23. class SupplementaryData : public Schema::V13::ISupplementaryData
  24. {
  25. public:
  26. SupplementaryData() = delete;
  27. // Called on activeStack (complete battlefield info)
  28. SupplementaryData(
  29. const std::string & colorname_,
  30. Side side_,
  31. const GlobalStats * gstats_,
  32. const PlayerStats * lpstats_,
  33. const PlayerStats * rpstats_,
  34. const Battlefield * battlefield_,
  35. const std::vector<std::shared_ptr<AttackLog>> & attackLogs_,
  36. const std::vector<std::tuple<Schema::Action, std::shared_ptr<Schema::ActionMask>, std::shared_ptr<Schema::BattlefieldState>>> & transitions_,
  37. CombatResult result
  38. )
  39. : colorname(colorname_)
  40. , side(side_)
  41. , battlefield(battlefield_)
  42. , gstats(gstats_)
  43. , lpstats(lpstats_)
  44. , rpstats(rpstats_)
  45. , attackLogs(attackLogs_)
  46. , transitions(transitions_)
  47. , ended(result != CombatResult::NONE)
  48. , victory(EI(result) == EI(side)) {};
  49. // impl ISupplementaryData
  50. Type getType() const override
  51. {
  52. return type;
  53. };
  54. Side getSide() const override
  55. {
  56. return side;
  57. };
  58. std::string getColor() const override
  59. {
  60. return colorname;
  61. };
  62. ErrorCode getErrorCode() const override
  63. {
  64. return errcode;
  65. };
  66. bool getIsBattleEnded() const override
  67. {
  68. return ended;
  69. };
  70. bool getIsVictorious() const override
  71. {
  72. return victory;
  73. };
  74. Schema::V13::Stacks getStacks() const override;
  75. Schema::V13::Hexes getHexes() const override;
  76. Schema::V13::AllLinks getAllLinks() const override;
  77. Schema::V13::AttackLogs getAttackLogs() const override;
  78. Schema::V13::StateTransitions getStateTransitions() const override;
  79. const Schema::V13::IGlobalStats * getGlobalStats() const override
  80. {
  81. return gstats;
  82. }
  83. const Schema::V13::IPlayerStats * getLeftPlayerStats() const override
  84. {
  85. return lpstats;
  86. }
  87. const Schema::V13::IPlayerStats * getRightPlayerStats() const override
  88. {
  89. return rpstats;
  90. }
  91. std::string getAnsiRender() const override
  92. {
  93. return ansiRender;
  94. }
  95. const std::string colorname;
  96. const Side side;
  97. const Battlefield * const battlefield;
  98. const GlobalStats * const gstats;
  99. const PlayerStats * const lpstats;
  100. const PlayerStats * const rpstats;
  101. const std::vector<std::shared_ptr<AttackLog>> attackLogs;
  102. const std::vector<std::tuple<Schema::Action, std::shared_ptr<Schema::ActionMask>, std::shared_ptr<Schema::BattlefieldState>>> transitions;
  103. const bool ended = false;
  104. const bool victory = false;
  105. // Optionally modified (during activeStack if action was invalid)
  106. ErrorCode errcode = ErrorCode::OK;
  107. // Optionally modified (during activeStack if action was RENDER)
  108. Type type = Type::REGULAR;
  109. std::string ansiRender;
  110. };
  111. }