finished random map generation
This commit is contained in:
79
src/map.h
79
src/map.h
@ -7,6 +7,7 @@
|
||||
#include "display.h"
|
||||
#include "position.h"
|
||||
#include "rng.h"
|
||||
#include "fraction.h"
|
||||
|
||||
class game_map final {
|
||||
private:
|
||||
@ -16,12 +17,12 @@ private:
|
||||
static const int MAX_ROOM_WIDTH = 20;
|
||||
static const int MAX_ROOM_HEIGHT = 5;
|
||||
// setup safezones
|
||||
static const int ACTUAL_MAP_WIDTH = MAP_WIDTH - 4;
|
||||
static const int ACTUAL_MAP_HEIGHT = MAP_HEIGHT - 4;
|
||||
static const int MAP_PADDING = 2;
|
||||
static const int ACTUAL_MAP_WIDTH = MAP_WIDTH - 5;
|
||||
static const int ACTUAL_MAP_HEIGHT = MAP_HEIGHT - 5;
|
||||
static const int MAP_PADDING = 3;
|
||||
static const int MIN_ROOM_SPACING = 3;
|
||||
static const int WIDTH_RESERVED = 8;
|
||||
static const int HEIGHT_RESERVED = 4;
|
||||
static const int WIDTH_RESERVED = 6;
|
||||
static const int HEIGHT_RESERVED = 3;
|
||||
|
||||
const feature enabled_features;
|
||||
std::vector<char> map;
|
||||
@ -29,33 +30,16 @@ private:
|
||||
position_list empty_spots;
|
||||
position up_stairs;
|
||||
position down_stairs;
|
||||
int room_cnt;
|
||||
public:
|
||||
// randomly generate a map
|
||||
game_map(RNG *rng, const feature enabled_features);
|
||||
// read map from a string
|
||||
game_map(const std::string &map_data, RNG *rng,
|
||||
const feature enabled_features);
|
||||
|
||||
const position_list get_available_positions() const;
|
||||
bool is_available(const position &pos) const;
|
||||
|
||||
const std::vector<position_list> get_room_list() const;
|
||||
// IMPORTANT: always print a map before anything else
|
||||
void print(display *out) const;
|
||||
|
||||
position get_up_stairs() const;
|
||||
position get_down_stairs() const;
|
||||
|
||||
int get_up_stairs_room() const;
|
||||
int get_down_stairs_room() const;
|
||||
private:
|
||||
|
||||
struct room {
|
||||
int top;
|
||||
int left;
|
||||
int width;
|
||||
int height;
|
||||
position ldoor;
|
||||
position rdoor;
|
||||
position tdoor;
|
||||
position bdoor;
|
||||
bool operator!=(const room &r) {
|
||||
return !(*this == r);
|
||||
}
|
||||
@ -66,7 +50,29 @@ private:
|
||||
height == r.height;
|
||||
}
|
||||
};
|
||||
// randomly generate a map
|
||||
game_map(RNG *rng, const feature enabled_features);
|
||||
// read map from a string
|
||||
game_map(const std::string &map_data, RNG *rng,
|
||||
const feature enabled_features);
|
||||
|
||||
const position_list get_available_positions() const;
|
||||
bool is_available(const position &pos) const;
|
||||
|
||||
position_list get_room_list(int idx) const;
|
||||
// IMPORTANT: always print a map before anything else
|
||||
void print(display *out) const;
|
||||
|
||||
position get_up_stairs() const;
|
||||
position get_down_stairs() const;
|
||||
|
||||
int get_up_stairs_room() const;
|
||||
int get_down_stairs_room() const;
|
||||
|
||||
int get_room_cnt() const;
|
||||
room get_room(std::size_t idx) const;
|
||||
private:
|
||||
std::vector<room> room_data;
|
||||
position remap_index(const int idx) const {
|
||||
return {idx % MAP_WIDTH, idx / MAP_WIDTH};
|
||||
}
|
||||
@ -81,16 +87,33 @@ private:
|
||||
|
||||
std::vector<std::pair<position, int>> gen_room_dims(RNG *rng);
|
||||
std::vector<room> distr_rooms(RNG *rng,
|
||||
std::vector<std::pair<position, int>> &room_dims);
|
||||
std::vector<std::pair<position, int>> &room_dims,
|
||||
std::vector<std::pair<position, int>> &layer_data);
|
||||
|
||||
bool overlap_x(room &room1,
|
||||
room &room2);
|
||||
bool overlap_y(room &room1,
|
||||
room &room2);
|
||||
// has anything between the two
|
||||
bool between_x(room &room1,
|
||||
room &room2);
|
||||
bool between_y(room &room1,
|
||||
room &room2);
|
||||
|
||||
void jitter(RNG *rng, std::vector<room> &rooms);
|
||||
|
||||
void fill_room(const room &r, const int num);
|
||||
void gen_path(std::vector<room> &rooms);
|
||||
void fill_outline();
|
||||
|
||||
void gen_path(std::vector<std::pair<position, int>> &layer_data, RNG *rng);
|
||||
// IMPORTANT: assumes room1 is to the left of room 2
|
||||
void connect_x(room &room1, room &room2, RNG *rng);
|
||||
// IMPORTANT: assumes room1 is under room2
|
||||
void connect_y(room &room1, room &room2, RNG *rng);
|
||||
|
||||
void connect(position s, position t);
|
||||
room hit_room(const position &a);
|
||||
bool hit_room(const position &a, const room &r);
|
||||
};
|
||||
|
||||
const std::string default_map =
|
||||
|
Reference in New Issue
Block a user