aboutsummaryrefslogtreecommitdiff
path: root/frontend/generate_dungeon.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 18:46:18 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-02 18:46:18 +0100
commitc17df7d3e28e0eeb21f7a62d1c66f525b487a5fa (patch)
tree897cc608add9682c0ae36d3b3552147706234602 /frontend/generate_dungeon.cpp
parent5e4dd0c0197f6273c61491a5b9a030c93f796a12 (diff)
implement dungeon generation
Diffstat (limited to 'frontend/generate_dungeon.cpp')
-rw-r--r--frontend/generate_dungeon.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/frontend/generate_dungeon.cpp b/frontend/generate_dungeon.cpp
index 7ce1754..5484b2c 100644
--- a/frontend/generate_dungeon.cpp
+++ b/frontend/generate_dungeon.cpp
@@ -1,6 +1,8 @@
+#include <map>
#include <memory>
#include "backend/Dungeon.h"
+#include "backend/RNG.h"
#include "backend/print.h"
#include "backend/Exception.h"
@@ -26,14 +28,49 @@ unique_ptr<Dungeon> generate_dungeon() {
throw Exception("meer dan 1 locatie nodig");
vector<string> locations = gd.random_locations(location_count);
+ struct TempData {
+ Location * location;
+ int edges[4] = { -1, -1, -1, -1 };
+ };
+ vector<TempData> temp_map;
+ temp_map.resize(location_count);
+
+ size_t index = 0;
+ RNG & rng = RNG::get();
for (const string & name : locations) {
Location * location = gd.create_location(name);
+
+ if (index % 3 == 0) {
+ location->add_enemy(gd.create_enemy(gd.random_enemy()));
+ }
+
+ for (const string & object : gd.random_objects(rng.rand_int(Range<int> { 0, 3 }))) {
+ location->add_visible_object(gd.create_object(object));
+ }
+
+ for (const string & object : gd.random_objects(rng.rand_int(Range<int> { 0, 2 }))) {
+ location->add_hidden_object(gd.create_object(object));
+ }
+
+ auto & temp = temp_map[index];
+ temp.location = location;
+ for (Direction direction : DIRECTIONS) {
+ if (rng.rand_double() < 0.5) continue;
+ temp.edges[direction] = rng.rand_int(location_count);
+ temp_map[temp.edges[direction]].edges[-direction] = index;
+ }
+
dungeon->add_location(location);
+ index++;
}
- // TODO: connect locations
- // TODO: optionally add enemy
- // TODO: generate items
+ for (auto & temp : temp_map) {
+ for (Direction direction : DIRECTIONS) {
+ unsigned id = temp.edges[direction];
+ if (temp.edges[direction] < 0) continue;
+ temp.location->set_exit(direction, temp_map[id].location);
+ }
+ }
return dungeon;
}