diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 23:11:42 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 23:11:42 +0100 |
commit | ed78baff64fe45479ca6c480d985ce0f9c0c9515 (patch) | |
tree | b3224d0d01dc0c563c8e49751c628994b66f58b6 | |
parent | 07b8a5b0baed8c7b23681c99f25f297045945bfc (diff) |
more bug fixes
-rw-r--r-- | backend/ArmorObject.cpp | 4 | ||||
-rw-r--r-- | backend/ArmorObject.h | 6 | ||||
-rw-r--r-- | backend/ObjectFactory.h | 2 | ||||
-rw-r--r-- | backend/Player.cpp | 8 | ||||
-rw-r--r-- | frontend/DB.cpp | 9 | ||||
-rw-r--r-- | frontend/GameData.cpp | 2 | ||||
-rw-r--r-- | frontend/cmd/go.cpp | 5 |
7 files changed, 24 insertions, 12 deletions
diff --git a/backend/ArmorObject.cpp b/backend/ArmorObject.cpp index 3e0a4e2..a9fd51f 100644 --- a/backend/ArmorObject.cpp +++ b/backend/ArmorObject.cpp @@ -1,9 +1,9 @@ #include "ArmorObject.h" -void ArmorObject::set_protection(int protection) { +void ArmorObject::set_protection(unsigned int protection) { this->protection = protection; } -int ArmorObject::get_protection() const { +unsigned int ArmorObject::get_protection() const { return this->protection; } diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h index 068594e..74af728 100644 --- a/backend/ArmorObject.h +++ b/backend/ArmorObject.h @@ -6,12 +6,12 @@ class ArmorObject : public Object { using Object::Object; public: - void set_protection(int protection); - int get_protection() const; + void set_protection(unsigned int protection); + unsigned int get_protection() const; virtual String get_displayname() const; private: - int protection = 0; + unsigned int protection = 0; }; diff --git a/backend/ObjectFactory.h b/backend/ObjectFactory.h index 735ac1f..1578198 100644 --- a/backend/ObjectFactory.h +++ b/backend/ObjectFactory.h @@ -9,7 +9,7 @@ struct UniversalObject { String description; String type; Range<int> value; - int protection; + unsigned int protection; }; class ObjectFactory { diff --git a/backend/Player.cpp b/backend/Player.cpp index 6c2cf6b..66197fa 100644 --- a/backend/Player.cpp +++ b/backend/Player.cpp @@ -29,9 +29,13 @@ void Player::take_damage(unsigned int dmg) { if (this->cheating) return; if (this->is_dead()) return; - dmg = min(dmg, this->health_points); + // reduce damage by armor's protection value (if player is wearing any) if (this->armor != nullptr) - dmg = max(0u, dmg - this->armor->get_protection()); + dmg -= min(dmg, this->armor->get_protection()); + + // make sure health_points doesn't go below 0 + dmg = min(dmg, this->health_points); + this->health_points -= dmg; auto & hp = this->health_points; diff --git a/frontend/DB.cpp b/frontend/DB.cpp index 0f52433..1c8ab41 100644 --- a/frontend/DB.cpp +++ b/frontend/DB.cpp @@ -98,6 +98,15 @@ int DBQueryRow::col<int>(int index) const { return this->col<int>(index, 0); } +template <> +unsigned int DBQueryRow::col<unsigned int>(int index, const unsigned int & default_value) const { + return this->col<int>(index, default_value); +} +template <> +unsigned int DBQueryRow::col<unsigned int>(int index) const { + return this->col<unsigned int>(index, 0); +} + DBQueryRowRange DBStatement::rows() { return { *this }; } diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index 70a8058..635073a 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -77,7 +77,7 @@ Object * GameData::create_object(const string & name) const { .description = row.col<const char *>(0, nullptr), .type = row.col<const char *>(1, nullptr), .value = { row.col<int>(2), row.col<int>(3) }, - .protection = row.col<int>(4), + .protection = row.col<unsigned int>(4), }); } catch (Exception & e) { return ObjectFactory::create_object(name.c_str()); diff --git a/frontend/cmd/go.cpp b/frontend/cmd/go.cpp index b8bb7e2..6fb9105 100644 --- a/frontend/cmd/go.cpp +++ b/frontend/cmd/go.cpp @@ -14,11 +14,10 @@ static const unordered_map<string, Direction> direction_map = { { "west", Direction::WEST }, }; -void GameController::cmd_go(string & argv) { - string direction_str = str_consume_arg(argv); +void GameController::cmd_go(string & direction_str) { if (direction_str.size() == 0) throw Exception("dit commando heeft nog een argument met een richting nodig"); - if (!direction_map.contains(direction_str)) + if (!direction_map.contains(str_lower(direction_str))) throw Exception("onbekende richting \"%s\", probeer noord|zuid|oost|west", direction_str.c_str()); Player & player = this->dungeon->get_player(); |