definition.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <span>
  6. namespace sunrise::state::build_data::rewards {
  7. /** Native references use all bits set for an absent row. */
  8. inline constexpr std::uint16_t kAbsent = 0xFFFF;
  9. /** Bounds cover signed native indices and the flat banks they reference. */
  10. inline constexpr std::size_t kPoolCapacity = 4096;
  11. inline constexpr std::size_t kEntryCapacity = 32768;
  12. inline constexpr std::size_t kItemCapacity = 32768;
  13. inline constexpr std::size_t kInstructionCapacity = 131072;
  14. inline constexpr std::size_t kModifierCapacity = 32768;
  15. inline constexpr std::size_t kSocketOverrideCapacity = 32768;
  16. /** Native reward overrides address the 12 ordinary sockets on an item. */
  17. inline constexpr std::size_t kSocketsPerItem = 12;
  18. /** A wrapper can select independently from four reward categories. */
  19. inline constexpr std::size_t kSelectionCapacity = 4;
  20. /** A resolved grant fits one bounded inventory transaction. */
  21. inline constexpr std::size_t kGrantCapacity = 32;
  22. /** Nested pools and referenced conditions share a bounded traversal depth. */
  23. inline constexpr std::size_t kTraversalDepth = 32;
  24. struct Range {
  25. std::uint32_t first{};
  26. std::uint32_t count{};
  27. };
  28. struct Instruction {
  29. std::uint32_t opcode{};
  30. std::uint32_t operand{};
  31. };
  32. /** Resolved bank reads occupy a separate range from native expression operators. */
  33. enum class BankRead : std::uint32_t {
  34. accountFlag = 256,
  35. characterFlag,
  36. accountValue,
  37. characterValue,
  38. externalFlag,
  39. externalValue,
  40. characterClass,
  41. profileFlag,
  42. };
  43. /** A fixed override names its plug directly rather than selecting from a set. */
  44. inline constexpr std::uint32_t kFixedPlugSelection = 0xFFFFFFFFU;
  45. /** Wrappers without this bit remain inventory items until explicitly opened. */
  46. inline constexpr std::uint32_t kOpenOnAcquisition = 1;
  47. struct SocketOverride {
  48. std::uint16_t socketType{kAbsent};
  49. std::uint16_t plugItem{kAbsent};
  50. std::uint16_t plugSet{kAbsent};
  51. std::uint16_t rollSet{kAbsent};
  52. std::uint32_t selection{kFixedPlugSelection};
  53. };
  54. struct Modifier {
  55. Range condition{};
  56. std::uint16_t valueIndex{kAbsent};
  57. float value{};
  58. };
  59. struct Entry {
  60. std::uint16_t itemIndex{kAbsent};
  61. std::uint16_t poolIndex{kAbsent};
  62. std::uint16_t mappingIndex{kAbsent};
  63. std::uint32_t quantity{};
  64. std::uint32_t categoryHash{};
  65. float weight{};
  66. Range condition{};
  67. Range modifiers{};
  68. Range sockets{};
  69. };
  70. struct Pool {
  71. std::uint32_t definitionHash{};
  72. Range entries{};
  73. };
  74. struct Selection {
  75. std::uint32_t categoryHash{};
  76. std::uint32_t count{};
  77. };
  78. /** Dense item rows bind inventory definitions to their reward pools and acquisition flags. */
  79. struct Item {
  80. std::uint32_t definitionHash{};
  81. std::uint16_t poolIndex{kAbsent};
  82. std::uint16_t acquiredFlag{kAbsent};
  83. std::array<Selection, kSelectionCapacity> selections{};
  84. std::uint8_t selectionCount{};
  85. std::uint32_t flags{};
  86. };
  87. struct View {
  88. std::span<const Pool> pools;
  89. std::span<const Entry> entries;
  90. std::span<const Item> items;
  91. std::span<const Instruction> instructions;
  92. std::span<const Modifier> modifiers;
  93. std::span<const SocketOverride> sockets;
  94. };
  95. template <typename T> [[nodiscard]] constexpr bool fits(Range range, std::span<T> bank) noexcept {
  96. return range.first <= bank.size() && range.count <= bank.size() - range.first;
  97. }
  98. } // namespace sunrise::state::build_data::rewards