Peoplemon  0.1.0
Peoplemon 3 game source documentation
Move.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/FileUtil.hpp>
4 #include <BLIB/Util/Random.hpp>
5 #include <Core/Properties.hpp>
6 
7 namespace core
8 {
9 namespace pplmn
10 {
11 namespace
12 {
13 const std::string Invalid = "<INVALID>";
14 std::vector<MoveId> allIds;
15 
16 void refreshIds(const std::unordered_map<MoveId, std::string>* names) {
17  allIds.clear();
18  allIds.reserve(names->size());
19  for (const auto& p : *names) { allIds.emplace_back(p.first); }
20 }
21 } // namespace
22 
23 std::unordered_map<MoveId, std::string>* Move::names = nullptr;
24 std::unordered_map<MoveId, std::string>* Move::descriptions = nullptr;
25 std::unordered_map<MoveId, Type>* Move::types = nullptr;
26 std::unordered_map<MoveId, int>* Move::damages = nullptr;
27 std::unordered_map<MoveId, int>* Move::accuracies = nullptr;
28 std::unordered_map<MoveId, int>* Move::priorities = nullptr;
29 std::unordered_map<MoveId, unsigned int>* Move::pps = nullptr;
30 std::unordered_map<MoveId, bool>* Move::contactors = nullptr;
31 std::unordered_map<MoveId, bool>* Move::specials = nullptr;
32 std::unordered_map<MoveId, MoveEffect>* Move::effects = nullptr;
33 std::unordered_map<MoveId, int>* Move::effectChances = nullptr;
34 std::unordered_map<MoveId, int>* Move::effectIntensities = nullptr;
35 std::unordered_map<MoveId, bool>* Move::effectSelves = nullptr;
36 
37 MoveId Move::cast(unsigned int id) {
38  const MoveId r = static_cast<MoveId>(id);
39  if (r == MoveId::_INVALID_1 || r == MoveId::_INVALID_2 || r == MoveId::_INVALID_3 ||
40  r >= MoveId::_NUM_MOVES) {
41  if (names->find(r) == names->end()) return MoveId::Unknown;
42  }
43  return r;
44 }
45 
47  names = &db.names;
48  descriptions = &db.descriptions;
49  types = &db.types;
50  damages = &db.damages;
51  accuracies = &db.accuracies;
52  priorities = &db.priorities;
53  pps = &db.pps;
54  contactors = &db.contactors;
55  specials = &db.specials;
56  effects = &db.effects;
57  effectChances = &db.effectChances;
58  effectIntensities = &db.effectIntensities;
59  effectSelves = &db.effectSelves;
60 
61  refreshIds(names);
62 }
63 
64 const std::vector<MoveId>& Move::validIds() {
65 #ifdef PEOPLEMON_DEBUG
66  refreshIds(names);
67 #endif
68  return allIds;
69 }
70 
71 const std::string& Move::name(MoveId id) {
72  const auto it = names->find(id);
73  return it != names->end() ? it->second : Invalid;
74 }
75 
76 const std::string& Move::description(MoveId id) {
77  const auto it = descriptions->find(id);
78  return it != descriptions->end() ? it->second : Invalid;
79 }
80 
82  const auto it = types->find(id);
83  return it != types->end() ? it->second : Type::None;
84 }
85 
87  const auto it = damages->find(id);
88  return it != damages->end() ? it->second : 0;
89 }
90 
92  const auto it = accuracies->find(id);
93  return it != accuracies->end() ? it->second : 0;
94 }
95 
97  const auto it = priorities->find(id);
98  return it != priorities->end() ? it->second : 0;
99 }
100 
101 unsigned int Move::pp(MoveId id) {
102  const auto it = pps->find(id);
103  return it != pps->end() ? it->second : 0;
104 }
105 
107  const auto it = contactors->find(id);
108  return it != contactors->end() ? it->second : false;
109 }
110 
112  const auto it = specials->find(id);
113  return it != specials->end() ? it->second : false;
114 }
115 
117  const auto it = effects->find(id);
118  return it != effects->end() ? it->second : MoveEffect::None;
119 }
120 
122  const auto it = effectChances->find(id);
123  return it != effectChances->end() ? it->second : 0;
124 }
125 
127  const auto it = effectIntensities->find(id);
128  return it != effectIntensities->end() ? it->second : 0;
129 }
130 
132  const auto it = effectSelves->find(id);
133  return it != effectSelves->end() ? it->second : false;
134 }
135 
137  const std::string f1 = bl::util::FileUtil::joinPath(Properties::AnimationPath(), "Moves");
138  const std::string f2 = bl::util::FileUtil::joinPath(f1, name(move));
139  return bl::util::FileUtil::joinPath(f2, "Front/Background.anim");
140 }
141 
143  const std::string f1 = bl::util::FileUtil::joinPath(Properties::AnimationPath(), "Moves");
144  const std::string f2 = bl::util::FileUtil::joinPath(f1, name(move));
145  return bl::util::FileUtil::joinPath(f2, "Front/Foreground.anim");
146 }
147 
149  const std::string f1 = bl::util::FileUtil::joinPath(Properties::AnimationPath(), "Moves");
150  const std::string f2 = bl::util::FileUtil::joinPath(f1, name(move));
151  return bl::util::FileUtil::joinPath(f2, "Back/Background.anim");
152 }
153 
155  const std::string f1 = bl::util::FileUtil::joinPath(Properties::AnimationPath(), "Moves");
156  const std::string f2 = bl::util::FileUtil::joinPath(f1, name(move));
157  return bl::util::FileUtil::joinPath(f2, "Back/Foreground.anim");
158 }
159 
161  MoveId ret;
162  do {
163  ret = allIds[bl::util::Random::get<std::size_t>(0, allIds.size() - 1)];
164  } while (!ir && (effect(ret) == MoveEffect::RandomMove || effect(ret) == MoveEffect::Charge));
165  return ret;
166 }
167 
168 } // namespace pplmn
169 } // namespace core
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
MoveEffect
Represents an effect that a move can have. Copied verbatim from Peoplemon 2, may refactor later when ...
Definition: MoveEffect.hpp:17
Core classes and functionality for both the editor and game.
Stores the metadata of all peoplemon moves.
Definition: MoveDB.hpp:22
std::unordered_map< pplmn::MoveId, bool > specials
Definition: MoveDB.hpp:71
std::unordered_map< pplmn::MoveId, bool > contactors
Definition: MoveDB.hpp:70
std::unordered_map< pplmn::MoveId, std::int32_t > damages
Definition: MoveDB.hpp:66
std::unordered_map< pplmn::MoveId, std::uint32_t > pps
Definition: MoveDB.hpp:69
std::unordered_map< pplmn::MoveId, std::int32_t > accuracies
Definition: MoveDB.hpp:67
std::unordered_map< pplmn::MoveId, std::string > descriptions
Definition: MoveDB.hpp:64
std::unordered_map< pplmn::MoveId, std::int32_t > effectChances
Definition: MoveDB.hpp:73
std::unordered_map< pplmn::MoveId, std::int32_t > priorities
Definition: MoveDB.hpp:68
std::unordered_map< pplmn::MoveId, pplmn::MoveEffect > effects
Definition: MoveDB.hpp:72
std::unordered_map< pplmn::MoveId, std::int32_t > effectIntensities
Definition: MoveDB.hpp:74
std::unordered_map< pplmn::MoveId, std::string > names
Definition: MoveDB.hpp:63
std::unordered_map< pplmn::MoveId, pplmn::Type > types
Definition: MoveDB.hpp:65
std::unordered_map< pplmn::MoveId, bool > effectSelves
Definition: MoveDB.hpp:75
static unsigned int pp(MoveId move)
Returns the max pp of the given move.
Definition: Move.cpp:101
static int damage(MoveId move)
Returns the damage of the given move.
Definition: Move.cpp:86
static const std::string & description(MoveId move)
Returns the description of the given move.
Definition: Move.cpp:76
static int accuracy(MoveId move)
Returns the accuracy of the given move.
Definition: Move.cpp:91
static std::string playerAnimationBackground(MoveId move)
Returns the path to the animation for when the local player uses the move.
Definition: Move.cpp:136
static const std::vector< MoveId > & validIds()
Returns the list of all valid move ids.
Definition: Move.cpp:64
static int priority(MoveId move)
Returns the priority of the given move.
Definition: Move.cpp:96
static bool makesContact(MoveId move)
Returns whether or not the given move makes physical contact when used.
Definition: Move.cpp:106
static int effectIntensity(MoveId move)
Returns the effect intensity of the given move.
Definition: Move.cpp:126
static std::string playerAnimationForeground(MoveId move)
Returns the path to the animation for when the local player uses the move.
Definition: Move.cpp:142
static void setDataSource(file::MoveDB &source)
Set the data source for each method.
Definition: Move.cpp:46
static MoveEffect effect(MoveId move)
Returns the effect of the given move.
Definition: Move.cpp:116
static MoveId getRandomMove(bool allowRandomEffect=false)
Returns a random, valid move. Optionally filters moves that have the Random effect.
Definition: Move.cpp:160
static const std::string & name(MoveId move)
Returns the name of the given move.
Definition: Move.cpp:71
static Type type(MoveId move)
Returns the type of the given move.
Definition: Move.cpp:81
static int effectChance(MoveId move)
Returns the effect chance of the given move.
Definition: Move.cpp:121
static bool isSpecial(MoveId move)
Returns whether or not the given move is special.
Definition: Move.cpp:111
static std::string opponentAnimationForeground(MoveId move)
Returns the path to the animation for when the opponent uses the move.
Definition: Move.cpp:154
static std::string opponentAnimationBackground(MoveId move)
Returns the path to the animation for when the opponent uses the move.
Definition: Move.cpp:148
static MoveId cast(unsigned int id)
Converts the given raw id to a move id, or Unknown if invalid.
Definition: Move.cpp:37
static bool affectsUser(MoveId move)
Returns whether or not the given move affects the user or the opponent.
Definition: Move.cpp:131
static const std::string & AnimationPath()
Definition: Properties.cpp:327