stack.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * stack.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 "CStack.h"
  12. #include "battle/IBattleInfoCallback.h"
  13. #include "BAI/v13/global_stats.h"
  14. #include "battle/ReachabilityInfo.h"
  15. #include "schema/v13/constants.h"
  16. #include "schema/v13/types.h"
  17. namespace MMAI::BAI::V13
  18. {
  19. namespace S13 = Schema::V13;
  20. using StackAttribute = Schema::V13::StackAttribute;
  21. using StackAttrs = Schema::V13::StackAttrs;
  22. using StackFlag1 = Schema::V13::StackFlag1;
  23. using StackFlag2 = Schema::V13::StackFlag2;
  24. using StackFlags1 = Schema::V13::StackFlags1;
  25. using StackFlags2 = Schema::V13::StackFlags2;
  26. using Queue = std::vector<uint32_t>; // item=unit id
  27. using BitQueue = std::bitset<S13::STACK_QUEUE_SIZE>;
  28. static_assert(1 << S13::STACK_QUEUE_SIZE < std::numeric_limits<int>::max(), "BitQueue must be convertible to int");
  29. /*
  30. * A wrapper around CStack
  31. */
  32. class Stack : public Schema::V13::IStack
  33. {
  34. public:
  35. static int GetValue(const CCreature * creature);
  36. // not the quantum version :)
  37. static std::pair<BitQueue, int> QBits(const CStack *, const Queue &);
  38. struct Stats
  39. {
  40. int dmgDealtNow = 0;
  41. int dmgDealtTotal = 0;
  42. int dmgReceivedNow = 0;
  43. int dmgReceivedTotal = 0;
  44. int valueKilledNow = 0;
  45. int valueKilledTotal = 0;
  46. int valueLostNow = 0;
  47. int valueLostTotal = 0;
  48. };
  49. // struct for reducing constructor args to avoid sonarcloud warning...
  50. struct StatsContainer
  51. {
  52. const GlobalStats * oldgstats;
  53. const GlobalStats * gstats;
  54. const Stats stackStats;
  55. };
  56. Stack(
  57. const CStack * cstack,
  58. const Queue & q,
  59. const StatsContainer & statsContainer,
  60. const ReachabilityInfo & rinfo,
  61. bool blocked,
  62. bool blocking,
  63. const DamageEstimation & estdmg
  64. );
  65. // IStack impl
  66. const StackAttrs & getAttrs() const override;
  67. int getAttr(StackAttribute a) const override;
  68. int getFlag(StackFlag1 sf) const override;
  69. int getFlag(StackFlag2 sf) const override;
  70. char getAlias() const override;
  71. char alias;
  72. const CStack * const cstack;
  73. const ReachabilityInfo rinfo;
  74. StackAttrs attrs = {};
  75. StackFlags1 flags1 = 0; //
  76. StackFlags2 flags2 = 0; //
  77. int attr(StackAttribute a) const;
  78. bool flag(StackFlag1 f) const;
  79. bool flag(StackFlag2 f) const;
  80. int shots;
  81. int qposFirst;
  82. private:
  83. void setflag(StackFlag1 f);
  84. void setflag(StackFlag2 f);
  85. void setattr(StackAttribute a, int value);
  86. void addattr(StackAttribute a, int value);
  87. void finalize();
  88. void processBonuses();
  89. };
  90. }