From 07b8a5b0baed8c7b23681c99f25f297045945bfc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 2 Nov 2024 22:19:15 +0100 Subject: fix more bugs --- frontend/cmd/hit.cpp | 6 ++++-- frontend/generate_dungeon.cpp | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'frontend') diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp index f4a78fd..dc28199 100644 --- a/frontend/cmd/hit.cpp +++ b/frontend/cmd/hit.cpp @@ -19,8 +19,10 @@ void GameController::cmd_hit(string & target_name) { throw Exception("vijand \"%s\" niet gevonden", target_name.c_str()); Enemy & enemy = **it; - if (enemy.is_dead()) - throw Exception("%s is al dood!", enemy.get_name().c_str()); + if (enemy.is_dead()) { + lprtf("%s is al dood!", enemy.get_name().c_str()); + return; + } if (rng.rand_double() > player.get_attack()) { lprtf("Je hebt gemist!\n"); diff --git a/frontend/generate_dungeon.cpp b/frontend/generate_dungeon.cpp index 5484b2c..6393abb 100644 --- a/frontend/generate_dungeon.cpp +++ b/frontend/generate_dungeon.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "backend/Dungeon.h" @@ -12,6 +12,12 @@ using namespace std; +static vector shuffled_directions() { + vector out = { NORTH, EAST, SOUTH, WEST }; + shuffle(out.begin(), out.end(), RNG::get_engine()); + return out; +} + unique_ptr generate_dungeon() { unique_ptr dungeon = make_unique(); GameData & gd = GameData::get_instance(); @@ -54,10 +60,19 @@ unique_ptr generate_dungeon() { 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); + for (Direction direction : shuffled_directions()) { + // skip over already connected edges + if (temp.edges[direction] >= 0) continue; + + // find another random location that is NOT here + int connection = rng.rand_int(location_count - 1); + if (connection == index) connection++; + + // make a bidirectional connection + temp.edges[direction] = connection; temp_map[temp.edges[direction]].edges[-direction] = index; + + if (rng.rand_double() < 0.8) break; } dungeon->add_location(location); -- cgit v1.2.3