supplementary_data.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * supplementary_data.cpp, 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. #include "StdInc.h"
  11. #include "BAI/v13/supplementary_data.h"
  12. #include "common.h"
  13. namespace MMAI::BAI::V13
  14. {
  15. Schema::V13::Hexes SupplementaryData::getHexes() const
  16. {
  17. ASSERT(battlefield, "getHexes() called when battlefield is null");
  18. auto res = Schema::V13::Hexes{};
  19. for(int y = 0; y < battlefield->hexes->size(); ++y)
  20. {
  21. auto & hexrow = battlefield->hexes->at(y);
  22. auto & resrow = res.at(y);
  23. for(int x = 0; x < hexrow.size(); ++x)
  24. {
  25. resrow.at(x) = hexrow.at(x).get();
  26. }
  27. }
  28. return res;
  29. }
  30. Schema::V13::Stacks SupplementaryData::getStacks() const
  31. {
  32. ASSERT(battlefield, "getStacks() called when battlefield is null");
  33. auto res = Schema::V13::Stacks{};
  34. for(const auto & stack : battlefield->stacks)
  35. {
  36. res.push_back(stack.get());
  37. }
  38. return res;
  39. }
  40. Schema::V13::AllLinks SupplementaryData::getAllLinks() const
  41. {
  42. ASSERT(battlefield, "getAllLinks() called when battlefield is null");
  43. auto res = Schema::V13::AllLinks{};
  44. for(const auto & [lt, links] : battlefield->allLinks)
  45. {
  46. res[lt] = links.get();
  47. }
  48. return res;
  49. }
  50. Schema::V13::AttackLogs SupplementaryData::getAttackLogs() const
  51. {
  52. auto res = Schema::V13::AttackLogs{};
  53. res.reserve(attackLogs.size());
  54. for(const auto & al : attackLogs)
  55. res.push_back(al.get());
  56. return res;
  57. }
  58. Schema::V13::StateTransitions SupplementaryData::getStateTransitions() const
  59. {
  60. auto res = Schema::V13::StateTransitions{};
  61. res.reserve(transitions.size());
  62. for(const auto & [action, actmask, transition] : transitions)
  63. res.emplace_back(action, actmask.get(), transition.get());
  64. return res;
  65. }
  66. }