-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.h
125 lines (102 loc) · 3.37 KB
/
level.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include <deque>
#include <unordered_set>
#include <bitset>
#include <libtcod.hpp>
#include <queue>
#include <functional>
#include "config.h"
#include "common.h"
#include "graphs.h"
struct PeopleMapping;
struct Person;
struct LevelCreationEvent {};
struct Level
: public AccessWorld_ModifyWorld
, public AccessWorld_ModifyEntity
, public AccessWorld_UseUnique<Colors>
{
TCODMap* map;
float digability[MAP_WIDTH][MAP_HEIGHT] { 0.0f, };
char dig[MAP_WIDTH][MAP_HEIGHT]{ ' ', };
char memory[MAP_WIDTH][MAP_HEIGHT]{ ' ', };
float hues[MAP_WIDTH][MAP_HEIGHT]{ 0.0f };
float sats[MAP_WIDTH][MAP_HEIGHT]{ 0.0f };
float vals[MAP_WIDTH][MAP_HEIGHT]{ 0.0f };
char rooms[MAP_WIDTH][MAP_HEIGHT]{ ' ', };
char regions[MAP_WIDTH][MAP_HEIGHT]{ ' ', };
std::vector<WorldPosition> region_centers;
std::vector<WorldPosition> region_tiles[REGION_COUNT];
int tiles_in_room[ROOM_COUNT] { 0, };
std::vector<WorldPosition> tiles[ROOM_COUNT];
std::vector<WorldPosition> walkable;
std::bitset<MAP_WIDTH * MAP_HEIGHT> flood_fill_visited;
std::bitset<MAP_WIDTH * MAP_HEIGHT> flood_fill_candidate;
std::bitset<MAP_WIDTH * MAP_HEIGHT> bombs;
std::vector<XY> exploded_bombs;
graphs::Graph dig_plan;
std::deque<XY> flood_fill_freelist;
Level() {}
void init();
void gradient();
void flood_fill(int bomb_count);
void minesweep();
void connect();
void cellular_automata();
void flood_fill_rooms(int start_x, int start_y, char current_room);
void room_counting();
void force_connect();
void flood_fill_regions();
void generate();
void update_map_visibility();
};
struct LevelCreationSystem
: public OneOffSystem
, public AccessWorld_UseUnique<Calendar>
, public AccessWorld_UseUnique<Level>
, public AccessWorld_UseUnique<PeopleMapping>
, public AccessWorld_QueryAllEntitiesWith<Person>
, public AccessWorld_QueryAllEntitiesWith<WorldPosition>
, public AccessEvents_Listen<KeyEvent>
, public AccessEvents_Emit<LevelCreationEvent>
, public AccessWorld_ModifyWorld
, public AccessWorld_ModifyEntity
, public AccessYAML
{
template<typename T>
std::shared_ptr<T> add_pipeline()
{
std::shared_ptr<T> ptr{ new T };
pipeline.push_back(ptr);
return ptr;
}
void activate() override;
void react_to_event(KeyEvent& signal) override;
private:
std::vector<std::shared_ptr<CraftingPipeline>> pipeline;
};
using PlaceWeight = std::tuple<std::string, int>;
struct PlaceWeightSort
{
bool operator() (const PlaceWeight l, const PlaceWeight r)
{
auto lv = std::get<1>(l);
auto rv = std::get<1>(r);
return lv < rv;
}
};
using PlaceWeightQueue = std::priority_queue<PlaceWeight, std::vector<PlaceWeight>, PlaceWeightSort>;
struct LevelRenderSystem
: public RuntimeSystem
, public AccessConsole
, public AccessYAML
, public AccessWorld_QueryComponent<WorldPosition>
, public AccessWorld_QueryComponent<Sight>
, public AccessWorld_UseUnique<Level>
, public AccessWorld_UseUnique<Colors>
, public AccessWorld_UseUnique<PlayerFOV>
, public AccessWorld_QueryAllEntitiesWith<Player>
{
int tick;
void activate() override;
};