aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 22:19:15 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 22:19:15 +0100
commit07b8a5b0baed8c7b23681c99f25f297045945bfc (patch)
tree8383b4b675aba53d19a667f4713c3e73c32e9652 /backend
parentd554cb39a2f1ec97dd214a5dd200ae5f03cf616d (diff)
fix more bugs
Diffstat (limited to 'backend')
-rw-r--r--backend/ArmorObject.cpp5
-rw-r--r--backend/ArmorObject.h2
-rw-r--r--backend/Enemy.cpp6
-rw-r--r--backend/Enemy.h2
-rw-r--r--backend/GoldObject.cpp5
-rw-r--r--backend/GoldObject.h2
-rw-r--r--backend/Object.cpp5
-rw-r--r--backend/Object.h2
-rw-r--r--backend/RNG.cpp4
-rw-r--r--backend/RNG.h1
-rw-r--r--backend/WeaponObject.cpp5
-rw-r--r--backend/WeaponObject.h2
12 files changed, 20 insertions, 21 deletions
diff --git a/backend/ArmorObject.cpp b/backend/ArmorObject.cpp
index eb805e0..3e0a4e2 100644
--- a/backend/ArmorObject.cpp
+++ b/backend/ArmorObject.cpp
@@ -7,8 +7,7 @@ int ArmorObject::get_protection() const {
return this->protection;
}
-const String & ArmorObject::get_displayname() const {
- static String display = String::fmt("%s (%d bescherming)", this->get_name().c_str(), this->protection);
- return display;
+String ArmorObject::get_displayname() const {
+ return String::fmt("%s (%d bescherming)", this->get_name().c_str(), this->protection);
}
diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h
index 8889ed7..068594e 100644
--- a/backend/ArmorObject.h
+++ b/backend/ArmorObject.h
@@ -8,7 +8,7 @@ class ArmorObject : public Object {
public:
void set_protection(int protection);
int get_protection() const;
- virtual const String & get_displayname() const;
+ virtual String get_displayname() const;
private:
int protection = 0;
diff --git a/backend/Enemy.cpp b/backend/Enemy.cpp
index a2bab30..5f6f0cf 100644
--- a/backend/Enemy.cpp
+++ b/backend/Enemy.cpp
@@ -40,9 +40,7 @@ ListRange<Object *> Enemy::get_hidden_objects() {
return this->hidden_objects.range();
}
-const String & Enemy::get_displayname() const {
- static String displayname;
- displayname = String::fmt("%s%s", this->name.c_str(), this->health_points == 0 ? " [verslagen]" : "");
- return displayname;
+String Enemy::get_displayname() const {
+ return String::fmt("%s%s", this->name.c_str(), this->health_points == 0 ? " [verslagen]" : "");
}
diff --git a/backend/Enemy.h b/backend/Enemy.h
index f85172e..d3bd97a 100644
--- a/backend/Enemy.h
+++ b/backend/Enemy.h
@@ -16,7 +16,7 @@ public:
unsigned get_health() const;
bool is_dead() const;
void take_damage(unsigned int dmg);
- virtual const String & get_displayname() const;
+ virtual String get_displayname() const;
void set_attack(float attack_chance);
float get_attack() const;
void set_damage(const Range<int> & range);
diff --git a/backend/GoldObject.cpp b/backend/GoldObject.cpp
index 525b2f2..00ee205 100644
--- a/backend/GoldObject.cpp
+++ b/backend/GoldObject.cpp
@@ -7,8 +7,7 @@ int GoldObject::get_count() const {
return this->count;
}
-const String & GoldObject::get_displayname() const {
- static String display = String::fmt("%s (%d)", this->get_name().c_str(), this->count);
- return display;
+String GoldObject::get_displayname() const {
+ return String::fmt("%s (%d)", this->get_name().c_str(), this->count);
}
diff --git a/backend/GoldObject.h b/backend/GoldObject.h
index a532f07..535def9 100644
--- a/backend/GoldObject.h
+++ b/backend/GoldObject.h
@@ -8,7 +8,7 @@ class GoldObject : public Object {
public:
void set_count(const int & count);
int get_count() const;
- virtual const String & get_displayname() const;
+ virtual String get_displayname() const;
private:
int count = 0;
diff --git a/backend/Object.cpp b/backend/Object.cpp
index da1738c..398f970 100644
--- a/backend/Object.cpp
+++ b/backend/Object.cpp
@@ -8,9 +8,8 @@ void Object::set_name(const String & name) {
const String & Object::get_name() const {
return this->name;
}
-const String & Object::get_displayname() const {
- static String displayname = this->name;
- return displayname;
+String Object::get_displayname() const {
+ return this->name;
}
void Object::set_description(const String & description) {
diff --git a/backend/Object.h b/backend/Object.h
index 0cebd64..19472d0 100644
--- a/backend/Object.h
+++ b/backend/Object.h
@@ -10,7 +10,7 @@ private:
public:
void set_name(const String & name);
const String & get_name() const;
- virtual const String & get_displayname() const;
+ virtual String get_displayname() const;
void set_description(const String & description);
const String & get_description() const;
diff --git a/backend/RNG.cpp b/backend/RNG.cpp
index d804f7b..21d5090 100644
--- a/backend/RNG.cpp
+++ b/backend/RNG.cpp
@@ -10,6 +10,10 @@ RNG & RNG::get() {
return instance;
}
+std::mt19937 & RNG::get_engine() {
+ return RNG::get().rng;
+}
+
int RNG::rand_int(const int upper) {
return this->rand_int(0, upper);
}
diff --git a/backend/RNG.h b/backend/RNG.h
index 3c168bd..f6ae887 100644
--- a/backend/RNG.h
+++ b/backend/RNG.h
@@ -7,6 +7,7 @@
class RNG {
public:
static RNG & get();
+ static std::mt19937 & get_engine();
public:
int rand_int(const int upper);
diff --git a/backend/WeaponObject.cpp b/backend/WeaponObject.cpp
index a91b6bf..e1de42f 100644
--- a/backend/WeaponObject.cpp
+++ b/backend/WeaponObject.cpp
@@ -8,8 +8,7 @@ Range<int> WeaponObject::get_damage() const {
return { this->damage_min, this->damage_max };
}
-const String & WeaponObject::get_displayname() const {
- static String display = String::fmt("%s (%d - %d schade)", this->get_name().c_str(), this->damage_min, this->damage_max);
- return display;
+String WeaponObject::get_displayname() const {
+ return String::fmt("%s (%d - %d schade)", this->get_name().c_str(), this->damage_min, this->damage_max);
}
diff --git a/backend/WeaponObject.h b/backend/WeaponObject.h
index b54ab59..e7b7ed3 100644
--- a/backend/WeaponObject.h
+++ b/backend/WeaponObject.h
@@ -9,7 +9,7 @@ class WeaponObject : public Object {
public:
void set_damage(const Range<int> & range);
Range<int> get_damage() const;
- virtual const String & get_displayname() const;
+ virtual String get_displayname() const;
private:
int damage_min = 0;