From 81e8c1dae2e7e4be632d6e81d765b5dd43ea3927 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 19 Mar 2022 11:30:22 -0400 Subject: game tries to make sure initial cave is not tiny --- src/game.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---------- src/game.h | 2 ++ 2 files changed, 50 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index f048400..f8508c2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "util.h" #include "renderer.h" #include "consts.h" @@ -14,20 +16,22 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : { losePopLampTimer.accumulate(losePopLampTimer.getDt()); - loadMap(); - tick(); - tick(); - tick(); + do { + loadMap(); + tick(); + tick(); + tick(); - for (int y = -1; y <= 1; y++) - { - for (int x = -1; x <= 1; x++) + for (int y = -1; y <= 1; y++) { - map.tile(x,y) = Tile::Floor; + for (int x = -1; x <= 1; x++) + { + map.tile(x,y) = Tile::Floor; + } } - } - tick(); + tick(); + } while (!isInitialCaveBigEnough()); std::ifstream textFile("../res/childoflight.txt"); std::string line; @@ -167,6 +171,40 @@ void Game::tick(bool onlyDark) onlyDark); } +bool Game::isInitialCaveBigEnough() const { + std::set accessible; + std::deque search; + search.emplace_back(player_x, player_y); + + auto check_fn = [&](int x, int y) { + coord potential = {x,y}; + if (!accessible.count(potential) && !isTileSet(map, x, y)) { + accessible.insert(potential); + search.push_back(potential); + } + }; + + while (!search.empty()) { + auto [x,y] = search.front(); + search.pop_front(); + + check_fn(x-1, y-1); + check_fn(x-1, y ); + check_fn(x-1, y+1); + check_fn(x , y-1); + check_fn(x , y+1); + check_fn(x+1, y-1); + check_fn(x+1, y ); + check_fn(x+1, y+1); + + if (accessible.size() >= 200) { + return true; + } + } + + return false; +} + bool Game::movePlayer(int x, int y) { if (map.tile(x,y) == Tile::Floor && !map.at(x,y).sign) diff --git a/src/game.h b/src/game.h index a70f57e..5f13672 100644 --- a/src/game.h +++ b/src/game.h @@ -126,6 +126,8 @@ private: void tick(bool onlyDark = false); + bool isInitialCaveBigEnough() const; + bool movePlayer(int x, int y); void recalculateLighting(); -- cgit 1.4.1