From 9bc1170f31868ac7e25534f5d891cd8f580b7f18 Mon Sep 17 00:00:00 2001 From: a25liang Date: Wed, 17 Jul 2024 20:09:16 -0400 Subject: [PATCH] clean potions contants --- src/potion.h | 1 + src/potions/boost_atk.cc | 11 ++++------- src/potions/boost_atk.h | 1 + src/potions/boost_def.cc | 11 +++-------- src/potions/boost_def.h | 1 + src/potions/poison_health.cc | 8 +++----- src/potions/poison_health.h | 1 + src/potions/restore_health.cc | 8 +++----- src/potions/restore_health.h | 1 + src/potions/wound_atk.cc | 8 +++----- src/potions/wound_atk.h | 1 + src/potions/wound_def.cc | 10 +++------- src/potions/wound_def.h | 1 + 13 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/potion.h b/src/potion.h index fd3de67..191fba6 100644 --- a/src/potion.h +++ b/src/potion.h @@ -20,6 +20,7 @@ protected: potion_type type; int remaining_duration; position pos; + constexpr static const float DROW_POTION_MUL = 1.5f; public: potion(const potion &p); potion(potion &&p); diff --git a/src/potions/boost_atk.cc b/src/potions/boost_atk.cc index 9740bb1..a8dc37b 100644 --- a/src/potions/boost_atk.cc +++ b/src/potions/boost_atk.cc @@ -3,8 +3,7 @@ #include #include "../constants.h" -const int BOOST_ATK = 5; -const int BOOST_ATK_DROW = 7; + boost_atk::boost_atk(const position &pos): potion{potion_type::boost_atk, -1, pos} {} @@ -12,11 +11,9 @@ boost_atk::boost_atk(const position &pos): void boost_atk::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - ATK += BOOST_ATK_DROW; - else - ATK += BOOST_ATK; - + int tmp = BOOST_ATK; + if (race == rdrow) tmp *= DROW_POTION_MUL; + ATK += tmp; --remaining_duration; } } diff --git a/src/potions/boost_atk.h b/src/potions/boost_atk.h index c13e109..ad8740d 100644 --- a/src/potions/boost_atk.h +++ b/src/potions/boost_atk.h @@ -4,6 +4,7 @@ #include "../potion.h" class boost_atk final: public potion { + static const int BOOST_ATK = 5; public: boost_atk(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF, diff --git a/src/potions/boost_def.cc b/src/potions/boost_def.cc index 669327d..14aed11 100644 --- a/src/potions/boost_def.cc +++ b/src/potions/boost_def.cc @@ -3,9 +3,6 @@ #include #include "../constants.h" -// TODO: move into class def as static constants -const int BOOST_DEF = 5; -const int BOOST_DEF_DROW = 7; boost_def::boost_def(const position &pos): potion{potion_type::boost_def, -1, pos} {} @@ -13,11 +10,9 @@ boost_def::boost_def(const position &pos): void boost_def::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - DEF += BOOST_DEF_DROW; - else - DEF += BOOST_DEF; - + int tmp = BOOST_DEF; + if (race == rdrow) tmp *= DROW_POTION_MUL; + DEF += tmp; --remaining_duration; } } diff --git a/src/potions/boost_def.h b/src/potions/boost_def.h index 14eca61..cd0d1f2 100644 --- a/src/potions/boost_def.h +++ b/src/potions/boost_def.h @@ -4,6 +4,7 @@ #include "../potion.h" class boost_def final: public potion { + static const int BOOST_DEF = 5; public: boost_def(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF, diff --git a/src/potions/poison_health.cc b/src/potions/poison_health.cc index 02d3965..bfa5569 100644 --- a/src/potions/poison_health.cc +++ b/src/potions/poison_health.cc @@ -9,11 +9,9 @@ poison_health::poison_health(const position &pos): void poison_health::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - HP = std::max(HP - 7, 0); - else - HP = std::max(HP - 5, 0); - + int tmp = LOSE_HEALTH; + if (race == rdrow) tmp *= DROW_POTION_MUL; + HP = std::max(HP - tmp, 0); --remaining_duration; } } diff --git a/src/potions/poison_health.h b/src/potions/poison_health.h index 83cdf85..ae74eb6 100644 --- a/src/potions/poison_health.h +++ b/src/potions/poison_health.h @@ -4,6 +4,7 @@ #include "../potion.h" class poison_health final: public potion { + static const int LOSE_HEALTH = 5; public: poison_health(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF, diff --git a/src/potions/restore_health.cc b/src/potions/restore_health.cc index 95b15ff..6dd36e9 100644 --- a/src/potions/restore_health.cc +++ b/src/potions/restore_health.cc @@ -9,11 +9,9 @@ restore_health::restore_health(const position &pos): void restore_health::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - HP = std::min(HP + 7, MAX_HP[race]); - else - HP = std::min(HP + 5, MAX_HP[race]); - + int tmp = GAIN_HEALTH; + if (race == rdrow) tmp *= DROW_POTION_MUL; + HP = std::min(HP + tmp, MAX_HP[race]); --remaining_duration; } } diff --git a/src/potions/restore_health.h b/src/potions/restore_health.h index d4670f1..303bc59 100644 --- a/src/potions/restore_health.h +++ b/src/potions/restore_health.h @@ -4,6 +4,7 @@ #include "../potion.h" class restore_health final: public potion { + static const int GAIN_HEALTH = 5; public: restore_health(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF, diff --git a/src/potions/wound_atk.cc b/src/potions/wound_atk.cc index 2eef100..bd76d30 100644 --- a/src/potions/wound_atk.cc +++ b/src/potions/wound_atk.cc @@ -12,11 +12,9 @@ wound_atk::wound_atk(const position &pos): void wound_atk::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - ATK = std::max(ATK - WOUND_ATK_DROW, 0); - else - ATK = std::max(ATK - WOUND_ATK, 0); - + int tmp = WOUND_ATK; + if (race == rdrow) tmp *= DROW_POTION_MUL; + ATK = std::max(ATK - tmp, 0); --remaining_duration; } } diff --git a/src/potions/wound_atk.h b/src/potions/wound_atk.h index a8ea133..8b25c98 100644 --- a/src/potions/wound_atk.h +++ b/src/potions/wound_atk.h @@ -4,6 +4,7 @@ #include "../potion.h" class wound_atk final: public potion { + static const int WOUND_ATK = 5; public: wound_atk(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF, diff --git a/src/potions/wound_def.cc b/src/potions/wound_def.cc index 561133b..aa2517b 100644 --- a/src/potions/wound_def.cc +++ b/src/potions/wound_def.cc @@ -3,8 +3,6 @@ #include #include "../constants.h" -const int WOUND_DEF = 5; -const int WOUND_DEF_DROW = 7; wound_def::wound_def(const position &pos): potion{potion_type::wound_def, -1, pos} {} @@ -12,11 +10,9 @@ wound_def::wound_def(const position &pos): void wound_def::apply(const enum race &race, int &HP, int &ATK, int &DEF, fraction &base_hit_rate) { if (remaining_duration != 0) { - if (race == rdrow) - DEF = std::max(DEF - WOUND_DEF_DROW, 0); - else - DEF = std::max(DEF - WOUND_DEF, 0); - + int tmp = WOUND_DEF; + if (race == rdrow) tmp *= DROW_POTION_MUL; + DEF = std::max(DEF - tmp, 0); --remaining_duration; } } diff --git a/src/potions/wound_def.h b/src/potions/wound_def.h index a4d8564..12ecded 100644 --- a/src/potions/wound_def.h +++ b/src/potions/wound_def.h @@ -4,6 +4,7 @@ #include "../potion.h" class wound_def final: public potion { + static const int WOUND_DEF = 5; public: wound_def(const position &pos); void apply(const enum race &race, int &HP, int &ATK, int &DEF,