forked from Whales/Cataclysm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.h
225 lines (183 loc) · 7.02 KB
/
map.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#ifndef _MAP_H_
#define _MAP_H_
#define SUBMAP_SIZE 25
#define MAP_SIZE 13
#define VERTICAL_MAP_SIZE 3
#include "window.h"
#include "terrain.h"
#include "world_terrain.h"
#include "mapgen.h"
#include "worldmap.h"
#include "item.h"
#include "enum.h"
#include "geometry.h"
#include "attack.h"
#include "pathfind.h"
#include "field.h"
class Entity_pool;
struct Tile
{
Terrain *terrain;
std::vector<Item> items;
Field field;
int hp;
Tile() { hp = 0; }
~Tile() { }
void set_terrain(Terrain* ter);
glyph top_glyph();
int move_cost();
int get_height();
std::string get_name();
bool blocks_sense(Sense_type sense = SENSE_SIGHT);
bool has_flag(Terrain_flag flag);
bool has_field();
bool is_smashable();
std::string smash(Damage_set dam); // Returns the sound
bool damage(Damage_set dam); // Returns true on destruction
bool damage(Damage_type type, int dam); // Returns true on destruction
void open();
void close();
bool tool_action_applies(std::string act);
void apply_tool_action (std::string act);
};
struct Submap
{
Tile tiles[SUBMAP_SIZE][SUBMAP_SIZE];
/* spec_used is the Mapgen_spec used to generate this. It's tracked strictly
* for debugging purposes.
* Subname is the specific flavor of the mapgen_spec used here. This is used
* when building second stories; so only use house_wood to build the 2nd floor
* of a house_wood map.
* rotation and level are used to further match to the floor below.
*/
Mapgen_spec* spec_used;
std::string subname;
Direction rotation;
int level;
Submap();
~Submap();
void generate_empty();
void generate_open();
void generate(Worldmap* map, int posx, int posy, int posz = 0);
void generate(World_terrain* terrain[5], int posz = 0);
//void generate(std::string terrain_name);
void generate(Mapgen_spec* spec);
void generate_adjacent(Mapgen_spec* spec);
void generate_above(World_terrain* type, Submap* below);
bool add_item(Item item, int x, int y);
int item_count(int x, int y);
std::vector<Item>* items_at(int x, int y);
Point random_empty_tile();
std::string get_spec_name();
std::string get_world_ter_name();
};
struct Submap_pool
{
public:
Submap_pool();
~Submap_pool();
Submap* at_location(int x, int y, int z = 0);
Submap* at_location(Point p);
Submap* at_location(Tripoint p);
std::list<Submap*> instances;
private:
std::map<Tripoint,Submap*,Tripointcomp> point_map;
};
class Map
{
public:
Map();
~Map();
// Generation
void generate_empty();
//void test_generate(std::string terrain_name);
void generate(Worldmap *world, int wposx = -999, int wposy = -999,
int wposz = -999);
void shift(Worldmap *world, int shiftx, int shifty, int shiftz = 0);
void spawn_monsters(Worldmap *world, int worldx, int worldy,
int subx, int suby, int zlevel);
// Mapping & pathing
Generic_map get_dijkstra_map(Tripoint target, int weight,
bool include_smashable = true);
Generic_map get_movement_map(Entity_AI AI, Tripoint origin, Tripoint target);
bool senses(int x0, int y0, int x1, int y1, int range, Sense_type sense);
bool senses(int x0, int y0, int z0, int x1, int y1, int z1, int range,
Sense_type sense);
bool senses(Point origin, Point target, int range, Sense_type sense);
bool senses(Tripoint origin, Tripoint target, int range, Sense_type sense);
std::vector<Tripoint> line_of_sight(int x0, int y0, int x1, int y1);
std::vector<Tripoint> line_of_sight(int x0, int y0, int z0,
int x1, int y1, int z1);
std::vector<Tripoint> line_of_sight(Point origin, Point target);
std::vector<Tripoint> line_of_sight(Tripoint origin, Tripoint target);
// Tile information
int move_cost(Tripoint pos);
int move_cost(int x, int y, int z = 999);
int get_height(Tripoint pos);
int get_height(int x, int y, int z = 999);
bool is_smashable(Tripoint pos);
bool is_smashable(int x, int y, int z = 999);
bool has_flag(Terrain_flag flag, Tripoint pos);
bool has_flag(Terrain_flag flag, int x, int y, int z = 999);
bool blocks_sense(Sense_type sense, Tripoint pos);
bool blocks_sense(Sense_type sense, int x, int y, int z = 999);
bool add_item(Item item, Tripoint pos);
bool add_item(Item item, int x, int y, int z = 999);
bool add_field(Field_type* type, Tripoint pos, std::string creator = "");
bool add_field(Field_type* type, int x, int y, int z = 999,
std::string creator = "");
bool add_field(Field field, Tripoint pos);
bool add_field(Field field, int x, int y, int z = 999);
int item_count(Tripoint pos);
int item_count(int x, int y, int z = 999);
std::vector<Item>* items_at(Tripoint pos);
std::vector<Item>* items_at(int x, int y, int z = 999);
bool contains_field(Tripoint pos);
bool contains_field(int x, int y, int z = 999);
Field* field_at(Tripoint pos);
Field* field_at(int x, int y, int z = 999);
int field_uid_at(Tripoint pos);
int field_uid_at(int x, int y, int z = 999);
Tile* get_tile(Tripoint pos);
Tile* get_tile(int x, int y, int z = 999);
std::string get_name(Tripoint pos);
std::string get_name(int x, int y, int z = 999);
// Map-altering
void smash(int x, int y, Damage_set dam, bool make_sound = true);
void smash(int x, int y, int z, Damage_set dam, bool make_sound = true);
void smash(Tripoint pos, Damage_set dam, bool make_sound = true);
void damage(int x, int y, Damage_set dam);
void damage(int x, int y, int z, Damage_set dam);
void damage(Tripoint pos, Damage_set dam);
bool open (Tripoint pos);
bool open (int x, int y, int z = 999);
bool close(Tripoint pos);
bool close(int x, int y, int z = 999);
bool apply_tool_action(std::string act, Tripoint pos);
bool apply_tool_action(std::string act, int x, int y, int z = 999);
// Regularly-run functions
void process_fields();
// Output
void draw(Window *w, Entity_pool *entities, Tripoint ref,
int range = -1, Sense_type sense = SENSE_SIGHT);
void draw(Window *w, Entity_pool *entities, int refx, int refy, int refz,
int range = -1, Sense_type sense = SENSE_SIGHT);
void draw_area(Window *w, Entity_pool *entities, Tripoint ref,
int minx, int miny, int maxx, int maxy,
int range = -1, Sense_type sense = SENSE_SIGHT);
void draw_area(Window *w, Entity_pool *entities, int refx, int refy, int refz,
int minx, int miny, int maxx, int maxy,
int range = -1, Sense_type sense = SENSE_SIGHT);
void draw_tile(Window* w, Entity_pool *entities, int tilex, int tiley,
int refx, int refy, bool invert, bool gray = false);
void draw_tile(Window* w, Entity_pool *entities,
int tilex, int tiley, int tilez,
int refx, int refy, bool invert, bool gray = false);
Submap* get_center_submap(); // i.e. the one the player is in
Point get_center_point();
int posx, posy, posz;
private:
Submap* submaps[MAP_SIZE][MAP_SIZE][VERTICAL_MAP_SIZE * 2 + 1];
Tile tile_oob;
};
#endif