XJ music engine  1.9.6
In-game runtime engine for XJ music.
MarbleBag.h
Go to the documentation of this file.
1 // Copyright (c) XJ Music Inc. (https://xjmusic.com) All Rights Reserved.
2 
3 #ifndef XJMUSIC_UTIL_MARBLE_BAG_H
4 #define XJMUSIC_UTIL_MARBLE_BAG_H
5 
6 #include <map>
7 #include <optional>
8 #include <random>
9 
11 
12 namespace XJ {
13 
31  class MarbleBag {
32  std::map<int /*Phase*/, std::map<UUID /*Id*/, int /*Qty*/>> marbles;
33  std::random_device rd;
34  std::mt19937 gen{rd()};
35 
36  public:
40  MarbleBag() = default;
41 
45  MarbleBag(const MarbleBag &other);
46 
52  MarbleBag &operator=(const MarbleBag &other) {
53  if (this != &other) {
54  marbles = other.marbles;
55  }
56  return *this;
57  }
58 
62  UUID pick();
63 
70  void addAll(int phase, const std::map<UUID, int> &toAdd);
71 
78  void add(int phase, const UUID &id);
79 
87  void add(int phase, const UUID &id, int qty);
88 
94  int size() const;
95 
99  std::string toString() const;
100 
104  bool empty() const;
105 
109  bool isPresent() const;
110 
117  std::optional<UUID> pickPhase(int phase);
118 
123  static int quickPick(int total);
124 
131  static bool quickBooleanChanceOf(float probability);
132 
136  class Group {
137  public:
139  int from;
140  int to;
141 
142  Group(UUID id, int from, int to);
143  };
144  };
145 
146 }// namespace XJ
147 
148 #endif// XJMUSIC_UTIL_MARBLE_BAG_H
Definition: MarbleBag.h:136
Group(UUID id, int from, int to)
Definition: MarbleBag.cpp:156
int to
Definition: MarbleBag.h:140
int from
Definition: MarbleBag.h:139
UUID id
Definition: MarbleBag.h:138
Definition: MarbleBag.h:31
int size() const
Definition: MarbleBag.cpp:74
std::optional< UUID > pickPhase(int phase)
Definition: MarbleBag.cpp:128
static bool quickBooleanChanceOf(float probability)
Definition: MarbleBag.cpp:173
void addAll(int phase, const std::map< UUID, int > &toAdd)
Definition: MarbleBag.cpp:38
std::string toString() const
Definition: MarbleBag.cpp:87
void add(int phase, const UUID &id)
Definition: MarbleBag.cpp:49
bool isPresent() const
Definition: MarbleBag.cpp:118
MarbleBag()=default
MarbleBag & operator=(const MarbleBag &other)
Definition: MarbleBag.h:52
UUID pick()
Definition: MarbleBag.cpp:16
bool empty() const
Definition: MarbleBag.cpp:111
static int quickPick(int total)
Definition: MarbleBag.cpp:162
Definition: ActiveAudio.h:11
std::string UUID
Definition: EntityUtils.h:28