diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 22:19:15 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 22:19:15 +0100 |
commit | 07b8a5b0baed8c7b23681c99f25f297045945bfc (patch) | |
tree | 8383b4b675aba53d19a667f4713c3e73c32e9652 /frontend | |
parent | d554cb39a2f1ec97dd214a5dd200ae5f03cf616d (diff) |
fix more bugs
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/cmd/hit.cpp | 6 | ||||
-rw-r--r-- | frontend/generate_dungeon.cpp | 23 |
2 files changed, 23 insertions, 6 deletions
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 <map> +#include <algorithm> #include <memory> #include "backend/Dungeon.h" @@ -12,6 +12,12 @@ using namespace std; +static vector<Direction> shuffled_directions() { + vector<Direction> out = { NORTH, EAST, SOUTH, WEST }; + shuffle(out.begin(), out.end(), RNG::get_engine()); + return out; +} + unique_ptr<Dungeon> generate_dungeon() { unique_ptr<Dungeon> dungeon = make_unique<Dungeon>(); GameData & gd = GameData::get_instance(); @@ -54,10 +60,19 @@ unique_ptr<Dungeon> 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); |