Skip to content

Commit e0e549d

Browse files
committed
fix typos and remove isAlive field from Pokemon
1 parent d6311c8 commit e0e549d

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/models.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Pokemon::Pokemon(std::string name, const std::int32_t level, const std::int32_t
1414

1515
Move Pokemon::make_move(Pokemon& source, Pokemon& target)
1616
{
17-
if ((random_range<int>(0, 100) <= source.m_next_move.m_accuracy) && source.isAlive && target.isAlive)
17+
if ((random_range<int>(0, 100) <= source.m_next_move.m_accuracy) && source.m_hp > 0 && target.m_hp > 0)
1818
{
1919
switch (source.m_next_move.m_mt)
2020
{
@@ -30,27 +30,25 @@ Move Pokemon::make_move(Pokemon& source, Pokemon& target)
3030
return source.m_next_move;
3131
}
3232
}
33-
Move fail = Move("Failed", MoveTypes::NONE, 100, 0);
34-
return fail;
33+
34+
return Move("Failed", MoveTypes::NONE, 100, 0);
3535
}
3636

3737
Move Pokemon::attack(Pokemon& source, Pokemon& target)
3838
{
39-
/* (2 * Level / 5+2) * Attack * Power) / Defense) / 50) + 2) * random number(217-255)) / 255
40-
damage formula https://www.math.miami.edu/~jam/azure/compendium/battdam.htm*/
39+
4140
if (target.m_hp > 0)
4241
{
4342
int attack = source.m_attack;
4443
if (random_range<int>(random_range<int>(1, 20), 100))
4544
{
4645
attack *= 2; // crit damage
4746
}
47+
/* (2 * Level / 5+2) * Attack * Power) / Defense) / 50) + 2) * random number(217-255)) / 255
48+
damage formula https://www.math.miami.edu/~jam/azure/compendium/battdam.htm*/
4849
int damage = ((((((2 * source.m_level / 5 + 2) * attack * source.m_next_move.m_power) / target.m_def) / 50) + 2) * random_range<int>(217, 255)) / 255;
4950
target.m_hp -= damage;
50-
if (target.m_hp <= 0)
51-
{
52-
target.isAlive = false;
53-
}
51+
5452
return source.m_next_move;
5553
}
5654
return Move("Failed", MoveTypes::NONE, 100, 0);

src/models.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
enum class MoveTypes
88
{
99
NONE, // move failed or wasn't initialized
10-
ATTACK, // deals damange
10+
ATTACK, // deals damage
1111
DEFEND, // increase pokemon defense
1212
HEAL, // Increase pokemon health or remove status effects
1313
};
@@ -31,7 +31,6 @@ struct Pokemon
3131
std::int32_t m_max_hp = m_hp;
3232
std::int32_t m_def{};
3333
std::int32_t m_attack{};
34-
bool isAlive = true;
3534

3635
std::vector<Move> m_moveset;
3736
Move m_next_move = Move("None", MoveTypes::NONE, 100, 0);

0 commit comments

Comments
 (0)