aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 16:03:53 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 16:03:53 +0100
commita7e84b60366c78b131d43157980fbe4c2df655e6 (patch)
tree391099bfd358e04c8ef38f33311f92b2cd607afe /backend
parent798948dbe6f012e194f053c4e862cf697f30b793 (diff)
small cleanup + checks
Diffstat (limited to 'backend')
-rw-r--r--backend/ArmorObject.cpp4
-rw-r--r--backend/ArmorObject.h1
-rw-r--r--backend/Dungeon.cpp2
-rw-r--r--backend/Enemy.cpp14
-rw-r--r--backend/Enemy.h12
-rw-r--r--backend/Player.cpp2
6 files changed, 33 insertions, 2 deletions
diff --git a/backend/ArmorObject.cpp b/backend/ArmorObject.cpp
index 5b921fe..e6dc026 100644
--- a/backend/ArmorObject.cpp
+++ b/backend/ArmorObject.cpp
@@ -3,4 +3,6 @@
void ArmorObject::set_protection(int protection) {
this->protection = protection;
}
-
+int ArmorObject::get_protection() const {
+ return this->protection;
+}
diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h
index a476740..458b0ba 100644
--- a/backend/ArmorObject.h
+++ b/backend/ArmorObject.h
@@ -7,6 +7,7 @@ class ArmorObject : public Object {
public:
void set_protection(int protection);
+ int get_protection() const;
private:
int protection = 0;
diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp
index ad721b4..84f9c79 100644
--- a/backend/Dungeon.cpp
+++ b/backend/Dungeon.cpp
@@ -20,6 +20,7 @@ void Dungeon::update_attacks(ListRange<Enemy *> & enemies) {
lprtf(":: De vijand%s in je locatie vallen aan! ::\n", enemies.size() == 1 ? "" : "en");
RNG & rng = RNG::get();
for (Enemy * enemy : enemies) {
+ if (enemy->is_dead()) continue;
if (rng.rand_double() < enemy->get_attack()) continue;
unsigned damage = rng.rand_int(enemy->get_damage_min(), enemy->get_damage_max() + 1);
@@ -32,6 +33,7 @@ void Dungeon::update_movement() {
bool moved = false;
for (Location * location : this->locations) {
for (Enemy * enemy : location->get_enemies()) {
+ if (enemy->is_dead()) continue;
if (RNG::get().rand_double() < 0.5) continue;
if (!moved)
diff --git a/backend/Enemy.cpp b/backend/Enemy.cpp
index 9eadf01..c4bfff2 100644
--- a/backend/Enemy.cpp
+++ b/backend/Enemy.cpp
@@ -18,11 +18,25 @@ int Enemy::get_damage_min() const { return this->damage_min; }
void Enemy::set_damage_max(int damage_max) { this->damage_max = damage_max; }
int Enemy::get_damage_max() const { return this->damage_max; }
+void Enemy::set_health(unsigned health_points) { this->health_points = health_points; }
unsigned Enemy::get_health() const { return this->health_points; }
void Enemy::take_damage(unsigned int dmg) {
dmg = min(dmg, this->health_points);
this->health_points -= dmg;
}
+bool Enemy::is_dead() const {
+ return this->health_points == 0;
+}
+
+void Enemy::add_hidden_object(Object * object) {
+ this->hidden_objects.push_back(object);
+}
+void Enemy::remove_hidden_object(Object * object) {
+ this->hidden_objects.remove(object);
+}
+ListRange<Object *> Enemy::get_hidden_objects() {
+ return this->hidden_objects.range();
+}
const String & Enemy::get_displayname() const {
static String displayname;
diff --git a/backend/Enemy.h b/backend/Enemy.h
index 71ad437..4db2ae8 100644
--- a/backend/Enemy.h
+++ b/backend/Enemy.h
@@ -1,6 +1,9 @@
#pragma once
-#include "backend/String.h"
+#include "String.h"
+#include "PtrList.h"
+#include "ListIterator.h"
+#include "Object.h"
class Enemy {
public:
@@ -8,7 +11,9 @@ public:
const String & get_name() const;
void set_description(const String & description);
const String & get_description() const;
+ void set_health(unsigned);
unsigned get_health() const;
+ bool is_dead() const;
void take_damage(unsigned int dmg);
virtual const String & get_displayname() const;
void set_attack(float attack_chance);
@@ -18,6 +23,10 @@ public:
void set_damage_max(int damage_max);
int get_damage_max() const;
+ void add_hidden_object(Object *);
+ void remove_hidden_object(Object *);
+ ListRange<Object *> get_hidden_objects();
+
private:
friend class EnemyFactory;
Enemy(const String & name, const String & description);
@@ -27,6 +36,7 @@ public:
private:
String name;
String description;
+ PtrList<Object> hidden_objects;
unsigned int health_points = 0;
float attack_chance = 0.0;
int damage_min = 0;
diff --git a/backend/Player.cpp b/backend/Player.cpp
index a113a21..4180458 100644
--- a/backend/Player.cpp
+++ b/backend/Player.cpp
@@ -20,6 +20,8 @@ void Player::take_damage(unsigned int dmg) {
if (this->cheating) return;
dmg = min(dmg, this->health_points);
+ if (this->armor != nullptr)
+ dmg = max(0u, dmg - this->armor->get_protection());
this->health_points -= dmg;
lprtf("Je hebt nog %d levenspunten over.\n", this->health_points);