aboutsummaryrefslogtreecommitdiff
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
parent798948dbe6f012e194f053c4e862cf697f30b793 (diff)
small cleanup + checks
-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
-rw-r--r--frontend/GameController.cpp5
-rw-r--r--frontend/GameData.cpp9
-rw-r--r--frontend/cmd/query.cpp2
-rw-r--r--frontend/cmd/view.cpp15
10 files changed, 57 insertions, 9 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);
diff --git a/frontend/GameController.cpp b/frontend/GameController.cpp
index 5505380..a75767c 100644
--- a/frontend/GameController.cpp
+++ b/frontend/GameController.cpp
@@ -1,13 +1,18 @@
+#include "rl.h"
#include "GameData.h"
#include "strings.h"
#include "GameController.h"
+#include "backend/print.h"
#include "backend/WeaponObject.h"
#include "backend/Dungeon.h"
using namespace std;
GameController::GameController(Dungeon & dungeon) : dungeon(dungeon), player(dungeon.get_player()) {
+ lprtf("Wat is de naam van je karakter?\n");
+ string name = rl();
+ player.name = name.c_str();
cmdset_default();
player.set_location(dungeon.get_start_location());
player.equip(static_cast<WeaponObject *>(GameData::get_instance().create_object("Dolk")));
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp
index 4556621..e62cff1 100644
--- a/frontend/GameData.cpp
+++ b/frontend/GameData.cpp
@@ -41,8 +41,13 @@ Enemy * GameData::create_enemy(const string & name) {
try {
auto row = query.row();
- return EnemyFactory::create_enemy(row.col<const char *>(0), row.col<const char *>(1));
- // TODO: set all other properties
+ auto enemy = unique_ptr<Enemy>{ EnemyFactory::create_enemy(row.col<const char *>(0), row.col<const char *>(1)) };
+ // TODO: min/max objects(?)
+ enemy->set_health(row.col<int>(4));
+ enemy->set_attack(static_cast<float>(row.col<int>(5)) / 100);
+ enemy->set_damage_min(row.col<int>(6));
+ enemy->set_damage_max(row.col<int>(7));
+ return enemy.release();
} catch (...) {
return EnemyFactory::create_enemy(name.c_str());
}
diff --git a/frontend/cmd/query.cpp b/frontend/cmd/query.cpp
index f04e053..2a62b45 100644
--- a/frontend/cmd/query.cpp
+++ b/frontend/cmd/query.cpp
@@ -49,7 +49,7 @@ FollowupAction GameController::cmd_query(string &) {
size_t enemies = 0;
for (Enemy * enemy : location.get_enemies()) {
if (enemies > 0) lprtf(", ");
- lprtf("%s", enemy->get_name().c_str());
+ lprtf("%s", enemy->get_displayname().c_str());
enemies++;
}
if (enemies == 0)
diff --git a/frontend/cmd/view.cpp b/frontend/cmd/view.cpp
index 69eb96e..04ad6aa 100644
--- a/frontend/cmd/view.cpp
+++ b/frontend/cmd/view.cpp
@@ -33,7 +33,7 @@ FollowupAction GameController::cmd_view(string & target) {
lprtf("Je hebt %u goundstuk%s.\n", this->player.gold, this->player.gold == 1 ? "" : "ken");
size_t items = this->player.inventory.size();
- lprtf("Je hebt %d overige object%s%s\n", items, items == 1 ? "" : "en", items > 0 ? ":" : ".");
+ lprtf("Je hebt %d %s%s\n", items, items == 1 ? "overig object" : "overige objecten", items > 0 ? ":" : ".");
for (auto & object : this->player.inventory) {
lprtf("- %s\n", object->get_displayname().c_str());
}
@@ -64,9 +64,16 @@ FollowupAction GameController::cmd_view(string & target) {
lprtf("%s\n", enemy->get_description().c_str());
unsigned enemy_health = enemy->get_health();
lprtf("%s heeft %s levenspunten.\n", enemy->get_name().c_str(), enemy_health);
- // IF enemy_health == 0:
- // TODO: show enemy hidden objects
- // TODO: move enemy hidden objects to location visible objects
+
+ if (!enemy->is_dead()) return FollowupAction::NONE;
+ bool snatched = false;
+ for (Object * object : enemy->get_hidden_objects()) {
+ if (!snatched) lprtf("%s had de volgende voorwerpen:\n", enemy->get_displayname().c_str());
+ lprtf("- %s\n", object->get_displayname().c_str());
+ enemy->remove_hidden_object(object);
+ location.add_visible_object(object);
+ snatched = true;
+ }
return FollowupAction::NONE;
}