Peoplemon  0.1.0
Peoplemon 3 game source documentation
CatchRegion.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
5 
6 namespace core
7 {
8 namespace map
9 {
10 namespace
11 {
12 constexpr std::uint16_t FreqRange = std::numeric_limits<std::uint16_t>::max() - 1;
13 static const pplmn::WildPeoplemon Ben{pplmn::Id::BenToo, 100, 100, 100};
14 } // namespace
15 
17  if (wilds.empty()) {
18  BL_LOG_ERROR << "Empty catch region, spawning your punishment";
19  return Ben;
20  }
21 
22  const std::uint16_t f = bl::util::Random::get<std::uint16_t>(0, FreqRange);
23  std::uint16_t count = 0;
24  for (const pplmn::WildPeoplemon& ppl : wilds) {
25  if (f < count + ppl.frequency) {
26  BL_LOG_INFO << "Selected wild " << pplmn::Peoplemon::name(ppl.id) << "(" << ppl.id
27  << ")";
28  return ppl;
29  }
30  count += ppl.frequency;
31  }
32 
33  BL_LOG_ERROR
34  << "Sum of wild peoplemon frequencies was less than 100% | Spawning your punishment";
35  return Ben;
36 }
37 
38 } // namespace map
39 } // namespace core
Core classes and functionality for both the editor and game.
const pplmn::WildPeoplemon & selectWild() const
Selects a wild peoplemon from the set based on frequency, or returns a level 100 Ben if the set is em...
Definition: CatchRegion.cpp:16
std::vector< pplmn::WildPeoplemon > wilds
Definition: CatchRegion.hpp:20
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
Definition: Peoplemon.cpp:126
Template struct to generate OwnedPeoplemon for random encounters.