under_the_ashland_dome/src/game/map.hpp

96 lines
2.4 KiB
C++

#pragma once
#include <vector>
#include <utility>
#include <string>
#include <random>
#include <algorithm>
#include <fmt/core.h>
#include "algos/point.hpp"
#include "graphics/lights.hpp"
#include "algos/pathing.hpp"
#include "algos/matrix.hpp"
#include "constants.hpp"
using lighting::LightSource;
struct Room {
size_t x = 0;
size_t y = 0;
size_t width = 0;
size_t height = 0;
bool contains(Point at) {
return at.x >= x
&& at.x <= x + width -1
&& at.y >= y
&& at.y <= y + height - 1;
}
bool overlaps(Room other) {
return
// other left > this right == other too far right
!( other.x > x + width
// other right < this left == other too far left
|| other.x + other.width < x
// other top > this bottom == too far below
|| other.y > y + height
// other bottom < this top == too far above
|| other.y + other.height < y);
}
bool operator==(const Room&) const = default;
};
using EntityGrid = std::unordered_map<Point, wchar_t>;
class Map {
public:
size_t $width;
size_t $height;
Matrix $walls;
Matrix $tiles;
Pathing $paths;
std::vector<Room> $rooms;
std::vector<Point> $dead_ends;
std::unordered_map<Point, bool> $doors;
Map(size_t width, size_t height);
Map(Matrix &walls, Pathing &paths);
Matrix& paths() { return $paths.paths(); }
Matrix& input_map() { return $paths.input(); }
Matrix& walls() { return $walls; }
Matrix& tiles() { return $tiles; }
std::vector<Room>& rooms() { return $rooms; }
size_t width() { return $width; }
size_t height() { return $height; }
int distance(Point to) { return $paths.distance(to); }
Room &room(size_t at) { return $rooms[at]; }
size_t room_count() { return $rooms.size(); }
bool place_entity(size_t room_index, Point &out);
bool inmap(size_t x, size_t y);
bool iswall(size_t x, size_t y);
bool can_move(Point move_to);
bool random_walk(Point &out, bool random=false, int direction=PATHING_TOWARD);
void make_paths();
void set_target(const Point &at, int value=0);
void clear_target(const Point &at);
Point map_to_camera(const Point &loc, const Point &cam_orig);
Point center_camera(const Point &around, size_t view_x, size_t view_y);
void dump(int show_x=-1, int show_y=-1);
bool INVARIANT();
void init_tiles();
void add_room(Room &room);
void invert_space();
};