Peoplemon  0.1.0
Peoplemon 3 game source documentation
Peopledex.cpp
Go to the documentation of this file.
2 
3 #include <Core/Player/State.hpp>
4 
5 namespace core
6 {
7 namespace player
8 {
10 : playerState(state) {}
11 
12 unsigned int Peopledex::getSeen(pplmn::Id ppl) const {
13  const auto it = seenCounts.find(ppl);
14  return it != seenCounts.end() ? it->second : 0;
15 }
16 
17 const std::string& Peopledex::getFirstSeenLocation(pplmn::Id ppl) const {
18  static const std::string empty;
19  static const std::string unknown = "Unknown";
20  const auto it = firstSawLocations.find(ppl);
21  if (it != firstSawLocations.end()) return it->second;
22  if (getIntelLevel(ppl) != NoIntel) return unknown;
23  return empty;
24 }
25 
26 unsigned int Peopledex::getCaught(pplmn::Id ppl) const {
27  unsigned int c = 0;
28 
29  for (const auto& p : playerState.peoplemon) {
30  if (p.id() == ppl) ++c;
31  }
32 
33  for (unsigned int i = 0; i < StorageSystem::BoxCount; ++i) {
34  for (const auto& p : playerState.storage.getBox(i)) {
35  if (p.peoplemon.id() == ppl) ++c;
36  }
37  }
38 
39  return c;
40 }
41 
43  const unsigned int s = getSeen(ppl);
44  const unsigned int c = getCaught(ppl);
45  if (c > 0) return IntelLevel::FullIntel;
46  return s > 0 ? IntelLevel::LimitedIntel : IntelLevel::NoIntel;
47 }
48 
49 void Peopledex::registerSighting(pplmn::Id ppl, const std::string& location) {
50  auto it = seenCounts.find(ppl);
51  if (it == seenCounts.end()) { it = seenCounts.try_emplace(ppl, 0).first; }
52  it->second += 1;
53  if (it->second == 1) { firstSawLocations[ppl] = location; }
54 }
55 
56 } // namespace player
57 } // namespace core
Id
The id of a peoplemon.
Definition: Id.hpp:16
Core classes and functionality for both the editor and game.
void registerSighting(pplmn::Id peoplemon, const std::string &location)
Registers a sighting of the given peoplemon at the given location.
Definition: Peopledex.cpp:49
const std::string & getFirstSeenLocation(pplmn::Id peoplemon) const
Returns the name of the location the given peoplemon was first spotted at.
Definition: Peopledex.cpp:17
IntelLevel getIntelLevel(pplmn::Id peoplemon) const
Returns the level of intel on the given peoplemon.
Definition: Peopledex.cpp:42
unsigned int getSeen(pplmn::Id peoplemon) const
Returns how many of the given peoplemon have been seen.
Definition: Peopledex.cpp:12
unsigned int getCaught(pplmn::Id peoplemon) const
Returns how many of the given peoplemon have been caught.
Definition: Peopledex.cpp:26
Peopledex(State &playerState)
Construct a new Peopledex object.
Definition: Peopledex.cpp:9
IntelLevel
Represents an intel level on a given peoplemon.
Definition: Peopledex.hpp:27
Stores all player state.
Definition: State.hpp:21
StorageSystem storage
Definition: State.hpp:47
std::vector< pplmn::OwnedPeoplemon > peoplemon
Definition: State.hpp:46
static constexpr int BoxCount
const std::vector< pplmn::StoredPeoplemon > & getBox(unsigned int box) const
Returns the given box. Performs no bounds check.