aboutsummaryrefslogtreecommitdiff
path: root/frontend/GameData.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-03 12:43:18 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-03 12:43:18 +0100
commit5f5bf3ac7a85f8cde512ec44e3d55b93fb4354ba (patch)
tree517b955e4e2ecddf185dfd13dcdc4bcf57f4588a /frontend/GameData.cpp
parented78baff64fe45479ca6c480d985ce0f9c0c9515 (diff)
remove more pointers from frontend
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r--frontend/GameData.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp
index 635073a..f281737 100644
--- a/frontend/GameData.cpp
+++ b/frontend/GameData.cpp
@@ -19,7 +19,7 @@ GameData & GameData::get_instance() {
return instance;
}
-Enemy * GameData::create_enemy(const string & name) const {
+unique_ptr<Enemy> GameData::create_enemy(const string & name) const {
static DBStatement query = this->db.prepare(R"(
select
naam,
@@ -43,18 +43,18 @@ Enemy * GameData::create_enemy(const string & name) const {
auto enemy = unique_ptr<Enemy>{ EnemyFactory::create_enemy(row.col<const char *>(0), row.col<const char *>(1)) };
int object_count = RNG::get().rand_int(Range<int> { row.col<int>(2), row.col<int>(3) });
for (const string & name : this->random_objects(object_count))
- enemy->add_hidden_object(this->create_object(name));
+ enemy->add_hidden_object(this->create_object(name).release());
enemy->set_health(row.col<int>(4));
enemy->set_attack(static_cast<float>(row.col<int>(5)) / 100);
enemy->set_damage({ row.col<int>(6), row.col<int>(7) });
- return enemy.release();
+ return enemy;
} catch (Exception & e) {
printf("Fout bij aanmaken van vijand: %s\n", e.what());
- return EnemyFactory::create_enemy(name.c_str());
+ return unique_ptr<Enemy>{ EnemyFactory::create_enemy(name.c_str()) };
}
}
-Object * GameData::create_object(const string & name) const {
+unique_ptr<Object> GameData::create_object(const string & name) const {
static DBStatement query = this->db.prepare(R"(
select
omschrijving,
@@ -72,19 +72,19 @@ Object * GameData::create_object(const string & name) const {
try {
auto row = query.row();
- return ObjectFactory::create_object({
+ return unique_ptr<Object>(ObjectFactory::create_object({
.name = name.c_str(),
.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<unsigned int>(4),
- });
+ }));
} catch (Exception & e) {
- return ObjectFactory::create_object(name.c_str());
+ return unique_ptr<Object>{ ObjectFactory::create_object(name.c_str()) };
}
}
-Location * GameData::create_location(const string & name) const{
+unique_ptr<Location> GameData::create_location(const string & name) const{
static DBStatement query = this->db.prepare(R"(
select
naam,
@@ -99,9 +99,9 @@ Location * GameData::create_location(const string & name) const{
try {
auto row = query.row();
- return LocationFactory::create_location(row.col<const char *>(0), row.col<const char *>(1));
+ return unique_ptr<Location>{ LocationFactory::create_location(row.col<const char *>(0), row.col<const char *>(1)) };
} catch (...) {
- return LocationFactory::create_location(name.c_str());
+ return unique_ptr<Location>{ LocationFactory::create_location(name.c_str()) };
}
}