Peoplemon  0.1.0
Peoplemon 3 game source documentation
Peoplemon.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/FileUtil.hpp>
4 #include <Core/Properties.hpp>
5 
6 namespace core
7 {
8 namespace pplmn
9 {
10 namespace
11 {
12 const std::string InvalidStr = "<INVALID>";
13 std::vector<Id> allIds;
14 
15 void refreshIds(std::unordered_map<Id, std::string>* names) {
16  allIds.clear();
17  allIds.reserve(names->size());
18  for (const auto& p : *names) { allIds.emplace_back(p.first); }
19  std::sort(allIds.begin(), allIds.end());
20 }
21 
22 const std::pair<std::string, std::string> abilityTexts[43] = {
23  std::make_pair("No Ability", "This Peoplemon has no special talents to speak of"),
24  std::make_pair("Board Game Master", "The opposing Peoplemon cannot switch out"),
25  std::make_pair("Chillaxed", "Cannot receive critical hits"),
26  std::make_pair("Classy", "Cannot be Frustrated"),
27  std::make_pair("Goon", "Enemy Peoplemon take damage when they attack physically"),
28  std::make_pair("Quick Draw", "Attacks first on the first turn of every battle"),
29  std::make_pair("Always Friendly", "Is cured of all ailments when switched out"),
30  std::make_pair("Skipped Slot", "Id #7 is missing, it's Chris' fault"),
31  std::make_pair("Impulse Buy", "May purchase items at random in stores"),
32  std::make_pair("Run Away", "Always able to get away from battle"),
33  std::make_pair("Mr. Extra", "Occasionally finds items when exploring and pockets them"),
34  std::make_pair("Beefed Up", "Athletic type moves do more damage when below 25% HP"),
35  std::make_pair("Reserved", "Quiet type moves do more damage when below 25% HP"),
36  std::make_pair("Duke of Jokes", "Joke based moves do 50% more damage"),
37  std::make_pair(
38  "Engaging",
39  "Moves that otherwise would not affect enemy Peoplemon become Not Very Effective instead"),
40  std::make_pair("Snack Share", "Chance to give inflicted ailments to the attacker as well"),
41  std::make_pair("Derp Derp", "Chance to Confuse opponent when taking damage"),
42  std::make_pair("Klutz",
43  "Chance to drop hold item before battle, making it unusable for the battle"),
44  std::make_pair("Gender Bend", "Changes the gender of enemy Peoplemon"),
45  std::make_pair("Garbage", "This Peoplemon is garbage and has no special skills"),
46  std::make_pair("Bike Mechanic", "Can fix broken bikes"),
47  std::make_pair("Sidetrack Teach", "Teach based moves have a chance to Distract opponents"),
48  std::make_pair("No Joke Teach",
49  "Takes no damage from Joke based moves if a Teach based move was used"),
50  std::make_pair("Fiery Teach", "Teach based moves have a chance to raise Special Attack"),
51  std::make_pair("Experienced Teach", "Cannot be K.O'd if a Teach based move was used"),
52  std::make_pair("New Teach",
53  "Teach based moves used on the first turn of a battle have higher speed"),
54  std::make_pair("Doze Off",
55  "Teach based moves have a chance to make this Peoplemon fall asleep"),
56  std::make_pair("Douse Flames",
57  "Has a chance to reduce opponent Attack after taking physical damage"),
58  std::make_pair("Flirty",
59  "Has a chance to reduce opponent Special Attack after taking special damage"),
60  std::make_pair("Undying Faith", "Has a chance to survive a lethal attack"),
61  std::make_pair("Too Cool", "Cannot be Stunned"),
62  std::make_pair("Fake Study",
63  "If an attack misses the move used is not revealed to the opponent"),
64  std::make_pair("Alcoholic", "Consumes Alcohol based items at the beginning of each turn"),
65  std::make_pair("Total Bro", "Increases Bro Power of other Bros in your party"),
66  std::make_pair("Total Mom", "Restores some PP of the next Peoplemon when K.O'd"),
67  std::make_pair("Can't Swim",
68  "Has a chance to decrease opponents Attack when hit with a physical move"),
69  std::make_pair("All Nighter", "Cannot be put to sleep"),
70  std::make_pair("Ailment Saturated", "Can only ever have one Ailment at a time"),
71  std::make_pair("Adamant", "Can't be forced to switch out of battle by an opponent"),
72  std::make_pair("Absolute Pitch", "Super Effective moves do additional damage, but Not Very "
73  "Effective moves do even less damage"),
74  std::make_pair("GameMaker Virus", "Eliminates half of the PP of any moves that it gets hit by"),
75  std::make_pair("Snapshot",
76  "Cannot take Super Effective damage from the same move twice in a row"),
77  std::make_pair("Get Baked", "Automatically self-destructs if at 20% or less HP")};
78 } // namespace
79 
80 std::unordered_map<Id, std::string>* Peoplemon::names = nullptr;
81 std::unordered_map<Id, std::string>* Peoplemon::descriptions = nullptr;
82 std::unordered_map<Id, Type>* Peoplemon::types = nullptr;
83 std::unordered_map<Id, SpecialAbility>* Peoplemon::abilities = nullptr;
84 std::unordered_map<Id, Stats>* Peoplemon::stats = nullptr;
85 std::unordered_map<Id, std::unordered_set<MoveId>>* Peoplemon::validMoves = nullptr;
86 std::unordered_map<Id, std::unordered_map<unsigned int, MoveId>>* Peoplemon::learnedMoves = nullptr;
87 std::unordered_map<Id, unsigned int>* Peoplemon::evolveLevels = nullptr;
88 std::unordered_map<Id, Id>* Peoplemon::evolveIds = nullptr;
89 std::unordered_map<Id, Stats>* Peoplemon::evAwards = nullptr;
90 std::unordered_map<Id, unsigned int>* Peoplemon::xpGroups = nullptr;
91 std::unordered_map<Id, int>* Peoplemon::xpMults = nullptr;
92 std::unordered_map<Id, int>* Peoplemon::catchRates = nullptr;
93 
95  names = &db.names;
96  descriptions = &db.descriptions;
97  types = &db.types;
98  abilities = &db.abilities;
99  stats = &db.stats;
100  validMoves = &db.validMoves;
101  learnedMoves = &db.learnedMoves;
102  evolveLevels = &db.evolveLevels;
103  evolveIds = &db.evolveIds;
104  evAwards = &db.evAwards;
105  xpGroups = &db.xpGroups;
106  xpMults = &db.xpMults;
107  catchRates = &db.catchRates;
108 
109  refreshIds(names);
110 }
111 
112 Id Peoplemon::cast(unsigned int id) {
113  const Id r = static_cast<Id>(id);
114  if (names != nullptr && names->find(r) == names->end()) return Id::Unknown;
115  return r;
116 }
117 
118 const std::vector<Id>& Peoplemon::validIds() {
119 #ifdef PEOPLEMON_DEBUG
120  refreshIds(names);
121 #endif
122 
123  return allIds;
124 }
125 
126 const std::string& Peoplemon::name(Id id) {
127  const auto it = names->find(id);
128  return it != names->end() ? it->second : InvalidStr;
129 }
130 
131 const std::string& Peoplemon::description(Id id) {
132  const auto it = descriptions->find(id);
133  return it != descriptions->end() ? it->second : InvalidStr;
134 }
135 
137  const auto it = types->find(id);
138  return it != types->end() ? it->second : Type::None;
139 }
140 
142  const auto it = abilities->find(id);
143  return it != abilities->end() ? it->second : SpecialAbility::None;
144 }
145 
147  static const Stats Zero;
148  const auto it = stats->find(id);
149  return it != stats->end() ? it->second : Zero;
150 }
151 
153  const auto it = validMoves->find(id);
154  return it != validMoves->end() ? it->second.find(move) != it->second.end() : false;
155 }
156 
157 MoveId Peoplemon::moveLearnedAtLevel(Id id, unsigned int level) {
158  const auto it = learnedMoves->find(id);
159  if (it != learnedMoves->end()) {
160  const auto jit = it->second.find(level);
161  return jit != it->second.end() ? jit->second : MoveId::Unknown;
162  }
163  return MoveId::Unknown;
164 }
165 
166 unsigned int Peoplemon::evolveLevel(Id id) {
167  const auto it = evolveLevels->find(id);
168  return it != evolveLevels->end() ? it->second : 101;
169 }
170 
172  const auto it = evolveIds->find(id);
173  return it != evolveIds->end() ? it->second : Id::Unknown;
174 }
175 
177  static const Stats Zero;
178  const auto it = evAwards->find(id);
179  return it != evAwards->end() ? it->second : Zero;
180 }
181 
183  const auto it = xpMults->find(id);
184  return it != xpMults->end() ? it->second : 1;
185 }
186 
187 unsigned int Peoplemon::levelUpXp(Id id, unsigned int level) {
188  const auto it = xpGroups->find(id);
189  if (it == xpGroups->end()) return std::numeric_limits<unsigned int>::max();
190  switch (it->second) {
191  case 0:
192  return 5 * level * level * level / 4;
193  case 1:
194  return level * level * level;
195  case 2:
196  return 4 * level * level * level / 5;
197  default:
198  BL_LOG_ERROR << "Invalid xp group " << it->second << " for peoplemon "
199  << static_cast<unsigned int>(id);
200  return std::numeric_limits<unsigned int>::max();
201  }
202 }
203 
205  for (const auto& p : *evolveIds) {
206  if (p.second == id) return p.first;
207  }
208  return Id::Unknown;
209 }
210 
211 std::string Peoplemon::thumbnailImage(Id id) {
212  static const std::string missingno =
213  bl::util::FileUtil::joinPath(Properties::PeoplemonImageFolder(), "0.png");
214  const std::string f = bl::util::FileUtil::joinPath(
215  Properties::PeoplemonImageFolder(), std::to_string(static_cast<unsigned int>(id)) + ".png");
216  return bl::util::FileUtil::exists(f) ? f : missingno;
217 }
218 
219 std::string Peoplemon::playerImage(Id id) {
220  static const std::string rd =
221  bl::util::FileUtil::joinPath(Properties::ImagePath(), "Battle/Peoplemon/Player");
222  static const std::string missingno = bl::util::FileUtil::joinPath(rd, "0.png");
223  const std::string img =
224  bl::util::FileUtil::joinPath(rd, std::to_string(static_cast<unsigned int>(id)) + ".png");
225  return bl::util::FileUtil::exists(img) ? img : missingno;
226 }
227 
228 std::string Peoplemon::opponentImage(Id id) {
229  static const std::string rd =
230  bl::util::FileUtil::joinPath(Properties::ImagePath(), "Battle/Peoplemon/Opponent");
231  static const std::string missingno = bl::util::FileUtil::joinPath(rd, "0.png");
232  const std::string img =
233  bl::util::FileUtil::joinPath(rd, std::to_string(static_cast<unsigned int>(id)) + ".png");
234  return bl::util::FileUtil::exists(img) ? img : missingno;
235 }
236 
238  const auto it = catchRates->find(id);
239  return it != catchRates->end() ? static_cast<float>(it->second) : 48.f;
240 }
241 
242 bool Peoplemon::canClone(Id id) { return id != Id::Ben && id != Id::BenToo; }
243 
245  switch (ail) {
246  case Ailment::Annoyed:
247  return "Annoyed";
248  case Ailment::Frozen:
249  return "Frozen";
250  case Ailment::Frustrated:
251  return "Frustrated";
252  case Ailment::None:
253  return "Healthy";
254  case Ailment::Sleep:
255  return "Sleep";
256  case Ailment::Sticky:
257  return "Sticky";
258  default:
259  return "???";
260  }
261 }
262 
263 const std::string& Peoplemon::abilityName(SpecialAbility ability) {
264  const unsigned int i = static_cast<unsigned int>(ability);
265  return i < std::size(abilityTexts) ? abilityTexts[i].first : InvalidStr;
266 }
267 
268 const std::string& Peoplemon::abilityDescription(SpecialAbility ability) {
269  const unsigned int i = static_cast<unsigned int>(ability);
270  return i < std::size(abilityTexts) ? abilityTexts[i].second : InvalidStr;
271 }
272 
273 } // namespace pplmn
274 } // namespace core
Ailment
Represents an ailment that a Peoplemon can have.
Definition: Ailment.hpp:16
Type
Represents a type that a move or Peoplemon can be. Types may be combined.
Definition: Type.hpp:18
MoveId
The id of a move.
Definition: MoveId.hpp:16
SpecialAbility
Represents a special ability that a Peoplemon may have.
Id
The id of a peoplemon.
Definition: Id.hpp:16
Core classes and functionality for both the editor and game.
Data structure that holds the underlaying data for all the peoplemon.
Definition: PeoplemonDB.hpp:26
std::unordered_map< pplmn::Id, int > catchRates
Definition: PeoplemonDB.hpp:77
std::unordered_map< pplmn::Id, pplmn::Id > evolveIds
Definition: PeoplemonDB.hpp:73
std::unordered_map< pplmn::Id, pplmn::SpecialAbility > abilities
Definition: PeoplemonDB.hpp:68
std::unordered_map< pplmn::Id, int > xpMults
Definition: PeoplemonDB.hpp:76
std::unordered_map< pplmn::Id, pplmn::Type > types
Definition: PeoplemonDB.hpp:67
std::unordered_map< pplmn::Id, std::unordered_set< pplmn::MoveId > > validMoves
Definition: PeoplemonDB.hpp:70
std::unordered_map< pplmn::Id, unsigned int > xpGroups
Definition: PeoplemonDB.hpp:75
std::unordered_map< pplmn::Id, pplmn::Stats > stats
Definition: PeoplemonDB.hpp:69
std::unordered_map< pplmn::Id, unsigned int > evolveLevels
Definition: PeoplemonDB.hpp:72
std::unordered_map< pplmn::Id, pplmn::Stats > evAwards
Definition: PeoplemonDB.hpp:74
std::unordered_map< pplmn::Id, std::string > descriptions
Definition: PeoplemonDB.hpp:66
std::unordered_map< pplmn::Id, std::unordered_map< unsigned int, pplmn::MoveId > > learnedMoves
Definition: PeoplemonDB.hpp:71
std::unordered_map< pplmn::Id, std::string > names
Definition: PeoplemonDB.hpp:65
static bool canClone(Id id)
Returns whether or not the given Peoplemon may be cloned.
Definition: Peoplemon.cpp:242
static unsigned int evolveLevel(Id id)
Returns the minimum level that the given peoplemon will evolve at.
Definition: Peoplemon.cpp:166
static std::string playerImage(Id id)
Returns the full path to the image to use in battle for the player peoplemon.
Definition: Peoplemon.cpp:219
static void setDataSource(file::PeoplemonDB &data)
Sets the data source for all peoplemon. Must remain in scope.
Definition: Peoplemon.cpp:94
static MoveId moveLearnedAtLevel(Id ppl, unsigned int level)
Returns the move the peoplemon learns at the given level, if any.
Definition: Peoplemon.cpp:157
static float catchRate(Id id)
Returns the base catch rate for the given peoplemon.
Definition: Peoplemon.cpp:237
static SpecialAbility specialAbility(Id id)
Returns the ability of the given peoplemon, if any.
Definition: Peoplemon.cpp:141
static std::string opponentImage(Id id)
Returns the full path to the image to use in battle for the opponent peoplemon.
Definition: Peoplemon.cpp:228
static int xpYieldMultiplier(Id id)
Returns the multiplier used when computing the XP award for defeating the given peoplemon.
Definition: Peoplemon.cpp:182
static const std::string & abilityDescription(SpecialAbility ability)
Returns the description of the given special ability.
Definition: Peoplemon.cpp:268
static Id evolvesInto(Id orig)
Returns what the given peoplemon will evolve into.
Definition: Peoplemon.cpp:171
static Id evolvesFrom(Id evolved)
Returns what the given Peoplemon evolved from. This is expensive.
Definition: Peoplemon.cpp:204
static const std::string & description(Id id)
Returns the description of the given Peoplemon.
Definition: Peoplemon.cpp:131
static bool canLearnMove(Id ppl, MoveId move)
Returns whether or not the given Peoplemon can learn the given move.
Definition: Peoplemon.cpp:152
static std::string ailmentString(Ailment ailment)
Returns the name of the given ailment as a string.
Definition: Peoplemon.cpp:244
static unsigned int levelUpXp(Id id, unsigned int level)
Returns the XP required to level up the given peoplemon.
Definition: Peoplemon.cpp:187
static const std::vector< Id > & validIds()
Returtns the list of all valid ids.
Definition: Peoplemon.cpp:118
static const Stats & baseStats(Id id)
Returns the base stats for the given peoplemon.
Definition: Peoplemon.cpp:146
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
Definition: Peoplemon.cpp:126
static const Stats & evAward(Id id)
Returns the ev points awarded for defeating the given peoplemon.
Definition: Peoplemon.cpp:176
static Type type(Id id)
Returns the type of the Peoplemon.
Definition: Peoplemon.cpp:136
static const std::string & abilityName(SpecialAbility ability)
Returns the name of the given special ability.
Definition: Peoplemon.cpp:263
static Id cast(unsigned int id)
Casts an integer to a validated id. Returns Unknown if the id is invalid.
Definition: Peoplemon.cpp:112
static std::string thumbnailImage(Id id)
Returns the path of the image to render as the peoplemon thumbnail.
Definition: Peoplemon.cpp:211
Stats for Peoplemon. This struct is used for base stats, EVs, IVs, battle increases/decreases,...
Definition: Stats.hpp:19
static const std::string & ImagePath()
Definition: Properties.cpp:333
static const std::string & PeoplemonImageFolder()
Definition: Properties.cpp:672