3 #include <BLIB/Util/Random.hpp>
17 float statusBonus(
Ailment ail) {
38 , item(item::
Id::None)
39 , pendingEvolve(false) {}
50 bl::serial::binary::InputFile input(
52 if (!input.good())
return false;
54 if (!input.read(customName))
return false;
57 if (!input.read<std::uint16_t>(u16))
return false;
60 BL_LOG_ERROR <<
"Bad peoplemon id " << u16 <<
" in " << f;
64 if (!input.read<std::uint16_t>(u16))
return false;
66 if (!input.read<std::uint16_t>(u16))
return false;
68 if (!input.read<std::uint16_t>(u16))
return false;
69 if (!input.read<std::uint16_t>(u16))
return false;
73 if (!input.read<std::uint8_t>(u8))
return false;
74 ailment =
static_cast<Ailment>(u8);
76 if (!input.read<std::uint16_t>(u16))
return false;
79 BL_LOG_ERROR <<
"Bad item id " << u16 <<
" in " << f;
83 for (
int i = 0; i < 4; ++i) {
84 if (!input.read<std::uint16_t>(u16))
return false;
86 if (!input.read<std::uint16_t>(u16))
return false;
89 if (!input.read<std::uint16_t>(u16))
return false;
91 if (!input.read<std::uint16_t>(u16))
return false;
93 if (!input.read<std::uint16_t>(u16))
return false;
95 if (!input.read<std::uint16_t>(u16))
return false;
97 if (!input.read<std::uint16_t>(u16))
return false;
99 if (!input.read<std::uint16_t>(u16))
return false;
100 if (!input.read<std::uint16_t>(u16))
return false;
101 if (!input.read<std::uint16_t>(u16))
return false;
103 if (!input.read<std::uint16_t>(u16))
return false;
105 if (!input.read<std::uint16_t>(u16))
return false;
107 if (!input.read<std::uint16_t>(u16))
return false;
109 if (!input.read<std::uint16_t>(u16))
return false;
111 if (!input.read<std::uint16_t>(u16))
return false;
113 if (!input.read<std::uint16_t>(u16))
return false;
115 if (!input.read<std::uint16_t>(u16))
return false;
116 if (!input.read<std::uint16_t>(u16))
return false;
117 if (!input.read<std::uint16_t>(u16))
return false;
119 if (!input.read<std::uint16_t>(u16))
return false;
129 else { BL_LOG_ERROR <<
"Tried to evolve " << _id <<
" but it has no valid evolution!"; }
161 if (xp + award >= req) {
162 const unsigned int aa = req - xp;
183 std::uint16_t udmg = dmg;
184 udmg = std::min(udmg, hp);
205 for (
unsigned int i = 0; i < 4; ++i) {
206 if (moves[i].
id == m)
return true;
218 for (
int i = 0; i < 4; ++i) {
238 unsigned int xp = level;
239 if (trainer) { xp = xp * 3 / 2; }
254 for (
int i = 0; i < 4; ++i) {
255 if (moves[i].
id ==
id)
return &moves[i];
263 #ifdef PEOPLEMON_DEBUG
264 if (debug::DebugOverrides::get().alwaysCatch)
return true;
267 const float chp2 =
static_cast<float>(
currentHp()) * 2.f;
269 const float levelRatio =
static_cast<float>(opLevel) /
static_cast<float>(
currentLevel());
274 const int a = (mhp3 - chp2) * r * br / mhp3 * ar;
275 const int b = 1048560 /
static_cast<int>(std::sqrt(
static_cast<int>(std::sqrt(16711680 / a))));
276 const bool passed = a < 255 ? bl::util::Random::get<int>(0, 65535) < b :
true;
277 BL_LOG_INFO <<
"ModifiedCatchRate=" << a <<
" | ShakeProbability=" << b <<
" | "
278 << (passed ?
"Passed" :
"Failed");
Id
Represents an item in its simplist form.
Ailment
Represents an ailment that a Peoplemon can have.
Type
Represents a type that a move or Peoplemon can be. Types may be combined.
SpecialAbility
Represents a special ability that a Peoplemon may have.
Core classes and functionality for both the editor and game.
static float getPeopleballRate(Id ball, pplmn::Id ppl, int turnNumber, float levelRatio)
Returns the catch rate for the given peopleball.
static Id cast(unsigned int id)
Helper function to cast a raw id to an item Id.
static MoveId cast(unsigned int id)
Converts the given raw id to a move id, or Unknown if invalid.
Represents a move owned by a peoplemon.
Represents an instance of a peoplemon. Can be a wild peoplemon, trainer, or player peoplemon....
const Stats & currentEVs() const
Returns the current EVs of this peoplemon.
void evolve()
Changes this Peoplemon into it's evolved form if it has one.
Type type() const
Returns the type of the peoplemon.
bool loadLegacyFile(const std::string &file)
Loads the peoplemon from a legacy file.
bool & pendingEvolution()
Flag set by battle controller when this people is able to evolve after battle.
OwnedMove * findMove(MoveId id)
Returns the OwnedMove for the given move.
Ailment & currentAilment()
Access the current ailment of this peoplemon.
unsigned int awardXP(unsigned int xp)
Award XP to this peoplemon. A return of 0 indicates that all XP has been awarded. Non zero indicates ...
SpecialAbility ability() const
Returns the special ability of this peoplemon.
void applyDamage(int dmg)
Applies damage to the peoplemon. Ensures that the hp does not go negative.
unsigned int nextLevelXP() const
Returns the xp required to level up.
void setCustomName(const std::string &name)
Sets a custom name for this peoplemon.
bool canClone() const
Returns whether or not this peoplemon can be cloned.
std::uint16_t & currentHp()
Access the current HP.
MoveId levelUp()
Levels up the peoplemon.
OwnedPeoplemon()
Makes an empty peoplemon with id Unknown.
unsigned int currentLevel() const
Returns the current level of this peoplemon.
const Stats & currentIVs() const
Returns the current IVs of this peoplemon.
bool gainMove(MoveId move)
Attempts to learn the given move if there is an open slot.
void awardEVs(const Stats &evs)
Award EVs to this peoplemon.
Stats currentStats() const
Returns the computed stats for the peoplemon. Does not take into account changes during battle.
Id id() const
Returns the id of this peoplemon.
bool hasExpShare() const
Returns whether or not this peoplemon has an EXP share.
bool knowsMove(MoveId move) const
Returns whether or not this peoplemon knows the given move.
bool shakePasses(item::Id ball, int turnNumber, unsigned int opLevel)
Performs the check that a shake would occur with the given peopleball.
void learnMove(MoveId move, unsigned int i)
Teaches the peoplemon the given move, potentially replacing an existing one.
unsigned int currentXP() const
Returns the current XP of this peoplemon.
unsigned int xpYield(bool isTrainer) const
Returns the XP awarded by defeating this peoplemon.
unsigned int evolveLevel() const
Returns the level that this people can evolve at.
void giveHealth(int hp)
Restores HP and ensures it does not go over max HP.
Id evolvesInto() const
Returns the people that this evolves into. Returns Unknown if no evolution.
const OwnedMove * knownMoves() const
Returns the moves known by this Peoplemon.
item::Id & holdItem()
Access the current hold item of this peoplemon.
void heal()
Restores HP and removes ailments.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static bool canClone(Id id)
Returns whether or not the given Peoplemon may be cloned.
static unsigned int evolveLevel(Id id)
Returns the minimum level that the given peoplemon will evolve at.
static MoveId moveLearnedAtLevel(Id ppl, unsigned int level)
Returns the move the peoplemon learns at the given level, if any.
static float catchRate(Id id)
Returns the base catch rate for the given peoplemon.
static SpecialAbility specialAbility(Id id)
Returns the ability of the given peoplemon, if any.
static int xpYieldMultiplier(Id id)
Returns the multiplier used when computing the XP award for defeating the given peoplemon.
static Id evolvesInto(Id orig)
Returns what the given peoplemon will evolve into.
static unsigned int levelUpXp(Id id, unsigned int level)
Returns the XP required to level up the given peoplemon.
static const Stats & baseStats(Id id)
Returns the base stats for the given peoplemon.
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
static Type type(Id id)
Returns the type of the Peoplemon.
static Id cast(unsigned int id)
Casts an integer to a validated id. Returns Unknown if the id is invalid.
Stats for Peoplemon. This struct is used for base stats, EVs, IVs, battle increases/decreases,...
void randomize()
Generates random IV stats.
static Stats computeStats(const Stats &base, const Stats &evs, const Stats &ivs, unsigned int level, const Stats &stages={})
Helper method to compute a Peoplemon's current stats.
void addEVs(const Stats &evs)
Adds the given EV points to this set of stats while obeying the constraints on EV values and sums.
static const std::string & LegacyPeoplemonPath()