Peoplemon  0.1.0
Peoplemon 3 game source documentation
Type.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Logging.hpp>
4 #include <array>
5 
6 namespace core
7 {
8 namespace pplmn
9 {
10 namespace
11 {
12 float compareSingleEffective(Type move, Type ppl) {
13  switch (move) {
14  case Type::None:
15  return 1.f;
16 
17  case Type::Normal:
18  if (ppl == Type::Awkward) return 0.f;
19  break;
20 
21  case Type::Intelligent:
22  if (ppl == Type::Funny) return 0.5f;
23  if (ppl == Type::Athletic) return 2.f;
24  break;
25 
26  case Type::Funny:
27  switch (ppl) {
28  case Type::Intelligent:
29  return 2.f;
30  case Type::Awkward:
31  case Type::Quiet:
32  return 0.5f;
33  default:
34  return 1.f;
35  }
36 
37  case Type::Athletic:
38  switch (ppl) {
39  case Type::Normal:
40  return 2.f;
41  case Type::Intelligent:
42  case Type::Awkward:
43  return 0.5f;
44  default:
45  return 1.f;
46  }
47 
48  case Type::Quiet:
49  if (ppl == Type::PartyAnimal) return 2.f;
50  break;
51 
52  case Type::Awkward:
53  switch (ppl) {
54  case Type::Normal:
55  case Type::Quiet:
56  return 0.f;
57  case Type::Funny:
58  case Type::Awkward:
59  return 2.f;
60  default:
61  return 1.f;
62  }
63 
64  case Type::PartyAnimal:
65  switch (ppl) {
66  case Type::Awkward:
67  return 2.f;
68  case Type::Quiet:
69  return 0.5f;
70  default:
71  return 1.f;
72  }
73 
74  default:
75  return 1.f;
76  }
77 
78  return 1.f;
79 }
80 
81 constexpr std::array<Type, 7> TypeList = {Type::Normal,
88 
89 std::string singleTypeString(Type type) {
90  switch (type) {
91  case Type::Normal:
92  return "Normal";
93  case Type::Intelligent:
94  return "Intelligent";
95  case Type::Funny:
96  return "Funny";
97  case Type::Athletic:
98  return "Athletic";
99  case Type::Quiet:
100  return "Quiet";
101  case Type::Awkward:
102  return "Awkward";
103  case Type::PartyAnimal:
104  return "Party Animal";
105  default:
106  return "???";
107  }
108 }
109 
110 } // namespace
111 
112 float TypeUtil::getStab(Type move, Type ppl) { return isType(ppl, move) ? 1.5f : 1.f; }
113 
114 float TypeUtil::getSuperMult(Type move, Type ppl) {
115  float m = 1.f;
116  for (unsigned int i = 0; i <= 6; ++i) {
117  const Type type = static_cast<Type>(0x1 << i);
118  if (isType(ppl, type)) { m *= compareSingleEffective(move, type); }
119  }
120  return m;
121 }
122 
123 Type TypeUtil::legacyTypeToNew(unsigned int ogType) {
124  switch (ogType) {
125  case 8:
127  case 9:
129  case 10:
131  case 11:
132  return Type::Normal | Type::Quiet;
133  case 12:
134  return Type::Awkward | Type::Funny;
135  case 13:
137  case 14:
138  return Type::Athletic | Type::Normal;
139  case 15:
140  return Type::Funny | Type::Normal;
141  case 16:
142  return Type::Normal | Type::Awkward;
143  case 17:
144  return Type::Quiet | Type::Athletic;
145  case 18:
147  default:
148  if (ogType < 8) return static_cast<Type>(0x1 << ogType);
149  return Type::None;
150  }
151 }
152 
153 std::pair<Type, Type> TypeUtil::getTypes(Type type) {
154  std::pair<Type, Type> p(Type::None, Type::None);
155  for (Type c : TypeList) {
156  if (isType(type, c)) {
157  if (p.first == Type::None) { p.first = c; }
158  else if (p.second == Type::None) {
159  p.second = c;
160  }
161  else {
162  BL_LOG_WARN << "Type " << type << " contains more than two types";
163  }
164  }
165  }
166  return p;
167 }
168 
169 std::string TypeUtil::getTypeString(Type type) {
170  std::string ts;
171  for (Type t : TypeList) {
172  if (isType(type, t)) {
173  ts = ts.empty() ? singleTypeString(t) : ts + " / " + singleTypeString(t);
174  }
175  }
176  return ts.empty() ? "???" : ts;
177 }
178 
179 } // namespace pplmn
180 } // namespace core
Type
Represents a type that a move or Peoplemon can be. Types may be combined.
Definition: Type.hpp:18
Core classes and functionality for both the editor and game.
static std::pair< Type, Type > getTypes(Type type)
Returns the primary and secondary type of the given composite type.
Definition: Type.cpp:153
static std::string getTypeString(Type type)
Returns the type as a user-facing text string.
Definition: Type.cpp:169
static float getStab(Type moveType, Type userType)
Returns the STAB multiplier for a move.
Definition: Type.cpp:112
static float getSuperMult(Type moveType, Type defenderType)
Returns the multiplier for if/when a move is super effective.
Definition: Type.cpp:114
static bool isType(Type type, Type check)
Checks whether the given type contains the type to check.
Definition: Type.hpp:91
static Type legacyTypeToNew(unsigned int ogType)
Helper method to convert old type ids to the new.
Definition: Type.cpp:123