summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp58
-rw-r--r--src/game.h2
2 files changed, 50 insertions, 10 deletions
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 @@
3#include <fov.h> 3#include <fov.h>
4#include <iostream> 4#include <iostream>
5#include <fstream> 5#include <fstream>
6#include <set>
7#include <deque>
6#include "util.h" 8#include "util.h"
7#include "renderer.h" 9#include "renderer.h"
8#include "consts.h" 10#include "consts.h"
@@ -14,20 +16,22 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) :
14{ 16{
15 losePopLampTimer.accumulate(losePopLampTimer.getDt()); 17 losePopLampTimer.accumulate(losePopLampTimer.getDt());
16 18
17 loadMap(); 19 do {
18 tick(); 20 loadMap();
19 tick(); 21 tick();
20 tick(); 22 tick();
23 tick();
21 24
22 for (int y = -1; y <= 1; y++) 25 for (int y = -1; y <= 1; y++)
23 {
24 for (int x = -1; x <= 1; x++)
25 { 26 {
26 map.tile(x,y) = Tile::Floor; 27 for (int x = -1; x <= 1; x++)
28 {
29 map.tile(x,y) = Tile::Floor;
30 }
27 } 31 }
28 }
29 32
30 tick(); 33 tick();
34 } while (!isInitialCaveBigEnough());
31 35
32 std::ifstream textFile("../res/childoflight.txt"); 36 std::ifstream textFile("../res/childoflight.txt");
33 std::string line; 37 std::string line;
@@ -167,6 +171,40 @@ void Game::tick(bool onlyDark)
167 onlyDark); 171 onlyDark);
168} 172}
169 173
174bool Game::isInitialCaveBigEnough() const {
175 std::set<coord> accessible;
176 std::deque<coord> search;
177 search.emplace_back(player_x, player_y);
178
179 auto check_fn = [&](int x, int y) {
180 coord potential = {x,y};
181 if (!accessible.count(potential) && !isTileSet(map, x, y)) {
182 accessible.insert(potential);
183 search.push_back(potential);
184 }
185 };
186
187 while (!search.empty()) {
188 auto [x,y] = search.front();
189 search.pop_front();
190
191 check_fn(x-1, y-1);
192 check_fn(x-1, y );
193 check_fn(x-1, y+1);
194 check_fn(x , y-1);
195 check_fn(x , y+1);
196 check_fn(x+1, y-1);
197 check_fn(x+1, y );
198 check_fn(x+1, y+1);
199
200 if (accessible.size() >= 200) {
201 return true;
202 }
203 }
204
205 return false;
206}
207
170bool Game::movePlayer(int x, int y) 208bool Game::movePlayer(int x, int y)
171{ 209{
172 if (map.tile(x,y) == Tile::Floor && !map.at(x,y).sign) 210 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:
126 126
127 void tick(bool onlyDark = false); 127 void tick(bool onlyDark = false);
128 128
129 bool isInitialCaveBigEnough() const;
130
129 bool movePlayer(int x, int y); 131 bool movePlayer(int x, int y);
130 132
131 void recalculateLighting(); 133 void recalculateLighting();