Angband
cave.h
Go to the documentation of this file.
1 
19 #ifndef CAVE_H
20 #define CAVE_H
21 
22 #include "z-type.h"
23 #include "z-bitflag.h"
24 
25 struct player;
26 struct monster;
27 
28 const s16b ddd[9];
29 const s16b ddx[10];
30 const s16b ddy[10];
31 const s16b ddx_ddd[9];
32 const s16b ddy_ddd[9];
33 
38 enum
39 {
40  #define SQUARE(a,b) SQUARE_##a,
41  #include "list-square-flags.h"
42  #undef SQUARE
44 };
45 
46 #define SQUARE_SIZE FLAG_SIZE(SQUARE_MAX)
47 
48 #define sqinfo_has(f, flag) flag_has_dbg(f, SQUARE_SIZE, flag, #f, #flag)
49 #define sqinfo_next(f, flag) flag_next(f, SQUARE_SIZE, flag)
50 #define sqinfo_is_empty(f) flag_is_empty(f, SQUARE_SIZE)
51 #define sqinfo_is_full(f) flag_is_full(f, SQUARE_SIZE)
52 #define sqinfo_is_inter(f1, f2) flag_is_inter(f1, f2, SQUARE_SIZE)
53 #define sqinfo_is_subset(f1, f2) flag_is_subset(f1, f2, SQUARE_SIZE)
54 #define sqinfo_is_equal(f1, f2) flag_is_equal(f1, f2, SQUARE_SIZE)
55 #define sqinfo_on(f, flag) flag_on_dbg(f, SQUARE_SIZE, flag, #f, #flag)
56 #define sqinfo_off(f, flag) flag_off(f, SQUARE_SIZE, flag)
57 #define sqinfo_wipe(f) flag_wipe(f, SQUARE_SIZE)
58 #define sqinfo_setall(f) flag_setall(f, SQUARE_SIZE)
59 #define sqinfo_negate(f) flag_negate(f, SQUARE_SIZE)
60 #define sqinfo_copy(f1, f2) flag_copy(f1, f2, SQUARE_SIZE)
61 #define sqinfo_union(f1, f2) flag_union(f1, f2, SQUARE_SIZE)
62 #define sqinfo_comp_union(f1, f2) flag_comp_union(f1, f2, SQUARE_SIZE)
63 #define sqinfo_inter(f1, f2) flag_inter(f1, f2, SQUARE_SIZE)
64 #define sqinfo_diff(f1, f2) flag_diff(f1, f2, SQUARE_SIZE)
65 
66 
70 enum
71 {
72  #define TF(a,b) TF_##a,
73  #include "list-terrain-flags.h"
74  #undef TF
75  TF_MAX
76 };
77 
78 #define TF_SIZE FLAG_SIZE(TF_MAX)
79 
80 #define tf_has(f, flag) flag_has_dbg(f, TF_SIZE, flag, #f, #flag)
81 
88 typedef struct feature
89 {
90  char *name;
91  int fidx;
92 
93  struct feature *next;
94 
104  wchar_t d_char;
105 } feature_type;
106 
107 extern feature_type *f_info;
108 
110 {
111  LIGHTING_LOS = 0, /* line of sight */
112  LIGHTING_TORCH, /* torchlight */
113  LIGHTING_LIT, /* permanently lit (when not in line of sight) */
114  LIGHTING_DARK, /* dark */
116 };
117 
118 typedef struct
119 {
120  u32b m_idx; /* Monster index */
121  u32b f_idx; /* Feature index */
122  struct object_kind *first_kind; /* The kind of the first item on the grid */
123  struct trap *trap; /* Trap */
124  bool multiple_objects; /* Is there more than one item there? */
125  bool unseen_object; /* Is there an unaware object there? */
126  bool unseen_money; /* Is there some unaware money there? */
127 
128  enum grid_light_level lighting; /* Light level */
129  bool in_view; /* Can the player can currently see the grid? */
130  bool is_player;
133 } grid_data;
134 
135 struct square {
141  struct object *obj;
142  struct trap *trap;
143 };
144 
145 struct chunk {
146  char *name;
148  int depth;
149 
153  bool good_item;
154 
155  int height;
156  int width;
157 
158  u16b feeling_squares; /* How many feeling squares the player has visited */
160 
163 
164  struct square **squares;
165 
166  struct monster *monsters;
170 };
171 
172 /*** Feature Indexes (see "lib/edit/terrain.txt") ***/
173 
174 /* Nothing */
176 
177 /* Various */
184 
185 /* Secret door */
187 
188 /* Rubble */
190 
191 /* Mineral seams */
196 
197 /* Walls */
200 
201 /* Special trap detect features - should be replaced with square flags */
204 
205 
206 /* Real cave */
207 struct chunk *cave;
208 /* Known cave */
209 struct chunk *cave_k;
210 struct chunk **chunk_list;
212 
213 /* cave-view.c */
214 int distance(int y1, int x1, int y2, int x2);
215 bool los(struct chunk *c, int y1, int x1, int y2, int x2);
216 void forget_view(struct chunk *c);
217 void update_view(struct chunk *c, struct player *p);
218 bool player_has_los_bold(int y, int x);
219 bool player_can_see_bold(int y, int x);
220 bool no_light(void);
221 
222 /* cave-map.c */
223 void map_info(unsigned x, unsigned y, grid_data *g);
224 void square_note_spot(struct chunk *c, int y, int x);
225 void square_light_spot(struct chunk *c, int y, int x);
226 void light_room(int y1, int x1, bool light);
227 void wiz_light(struct chunk *c, bool full);
228 void wiz_dark(void);
229 void cave_illuminate(struct chunk *c, bool daytime);
230 void cave_update_flow(struct chunk *c);
231 void cave_forget_flow(struct chunk *c);
232 
233 /* cave-square.c */
238 typedef bool (*square_predicate)(struct chunk *c, int y, int x);
239 
240 /* FEATURE PREDICATES */
241 bool feat_is_magma(int feat);
242 bool feat_is_quartz(int feat);
243 bool feat_is_treasure(int feat);
244 bool feat_is_wall(int feat);
246 bool feat_is_shop(int feat);
247 bool feat_is_passable(int feat);
248 bool feat_is_projectable(int feat);
249 bool feat_isboring(feature_type *f_ptr);
250 
251 /* SQUARE FEATURE PREDICATES */
252 bool square_isfloor(struct chunk *c, int y, int x);
253 bool square_isrock(struct chunk *c, int y, int x);
254 bool square_isperm(struct chunk *c, int y, int x);
255 bool square_ismagma(struct chunk *c, int y, int x);
256 bool square_isquartz(struct chunk *c, int y, int x);
257 bool square_ismineral(struct chunk *c, int y, int x);
258 bool square_hasgoldvein(struct chunk *c, int y, int x);
259 bool square_isrubble(struct chunk *c, int y, int x);
260 bool square_issecretdoor(struct chunk *c, int y, int x);
261 bool square_isopendoor(struct chunk *c, int y, int x);
262 bool square_iscloseddoor(struct chunk *c, int y, int x);
263 bool square_islockeddoor(struct chunk *c, int y, int x);
264 bool square_isbrokendoor(struct chunk *c, int y, int x);
265 bool square_isdoor(struct chunk *c, int y, int x);
266 bool square_isstairs(struct chunk *c, int y, int x);
267 bool square_isupstairs(struct chunk *c, int y, int x);
268 bool square_isdownstairs(struct chunk *c, int y, int x);
269 bool square_isshop(struct chunk *c, int y, int x);
270 bool square_noticeable(struct chunk *c, int y, int x);
271 bool square_isplayer(struct chunk *c, int y, int x);
272 
273 /* SQUARE INFO PREDICATES */
274 bool square_ismark(struct chunk *c, int y, int x);
275 bool square_isglow(struct chunk *c, int y, int x);
276 bool square_isvault(struct chunk *c, int y, int x);
277 bool square_isroom(struct chunk *c, int y, int x);
278 bool square_isseen(struct chunk *c, int y, int x);
279 bool square_isview(struct chunk *c, int y, int x);
280 bool square_wasseen(struct chunk *c, int y, int x);
281 bool square_isdtrap(struct chunk *c, int y, int x);
282 bool square_isfeel(struct chunk *c, int y, int x);
283 bool square_isdedge(struct chunk *c, int y, int x);
284 bool square_istrap(struct chunk *c, int y, int x);
285 bool square_isinvis(struct chunk *c, int y, int x);
286 bool square_iswall_inner(struct chunk *c, int y, int x);
287 bool square_iswall_outer(struct chunk *c, int y, int x);
288 bool square_iswall_solid(struct chunk *c, int y, int x);
289 bool square_ismon_restrict(struct chunk *c, int y, int x);
290 bool square_isno_teleport(struct chunk *c, int y, int x);
291 bool square_isno_map(struct chunk *c, int y, int x);
292 bool square_isno_esp(struct chunk *c, int y, int x);
293 bool square_isproject(struct chunk *c, int y, int x);
294 
295 /* SQUARE BEHAVIOR PREDICATES */
296 bool square_isopen(struct chunk *c, int y, int x);
297 bool square_isempty(struct chunk *c, int y, int x);
298 bool square_canputitem(struct chunk *c, int y, int x);
299 bool square_isdiggable(struct chunk *c, int y, int x);
300 bool square_is_monster_walkable(struct chunk *c, int y, int x);
301 bool square_ispassable(struct chunk *c, int y, int x);
302 bool square_isprojectable(struct chunk *c, int y, int x);
303 bool square_iswall(struct chunk *c, int y, int x);
304 bool square_isstrongwall(struct chunk *c, int y, int x);
305 bool square_isboring(struct chunk *c, int y, int x);
306 bool square_iswarded(struct chunk *c, int y, int x);
307 bool square_canward(struct chunk *c, int y, int x);
308 bool square_seemslikewall(struct chunk *c, int y, int x);
309 bool square_isinteresting(struct chunk *c, int y, int x);
310 bool square_isplayertrap(struct chunk *c, int y, int x);
311 bool square_isvisibletrap(struct chunk *c, int y, int x);
312 bool square_issecrettrap(struct chunk *c, int y, int x);
313 bool square_isknowntrap(struct chunk *c, int y, int x);
314 bool square_changeable(struct chunk *c, int y, int x);
315 bool square_dtrap_edge(struct chunk *c, int y, int x);
316 bool square_in_bounds(struct chunk *c, int y, int x);
317 bool square_in_bounds_fully(struct chunk *c, int y, int x);
318 
319 struct feature *square_feat(struct chunk *c, int y, int x);
320 struct monster *square_monster(struct chunk *c, int y, int x);
321 struct object *square_object(struct chunk *c, int y, int x);
322 bool square_holds_object(struct chunk *c, int y, int x, struct object *obj);
323 void square_excise_object(struct chunk *c, int y, int x, struct object *obj);
324 
325 void square_set_feat(struct chunk *c, int y, int x, int feat);
326 
327 /* Feature placers */
328 void square_add_trap(struct chunk *c, int y, int x);
329 void square_add_ward(struct chunk *c, int y, int x);
330 void square_add_stairs(struct chunk *c, int y, int x, int depth);
331 void square_add_door(struct chunk *c, int y, int x, bool closed);
332 
333 /* Feature modifiers */
334 void square_open_door(struct chunk *c, int y, int x);
335 void square_close_door(struct chunk *c, int y, int x);
336 void square_smash_door(struct chunk *c, int y, int x);
337 void square_lock_door(struct chunk *c, int y, int x, int power);
338 void square_unlock_door(struct chunk *c, int y, int x);
339 void square_destroy_door(struct chunk *c, int y, int x);
340 void square_show_trap(struct chunk *c, int y, int x, int type);
341 void square_destroy_trap(struct chunk *c, int y, int x);
342 void square_tunnel_wall(struct chunk *c, int y, int x);
343 void square_destroy_wall(struct chunk *c, int y, int x);
344 void square_destroy(struct chunk *c, int y, int x);
345 void square_earthquake(struct chunk *c, int y, int x);
346 void square_remove_ward(struct chunk *c, int y, int x);
347 void square_upgrade_mineral(struct chunk *c, int y, int x);
348 void square_destroy_rubble(struct chunk *c, int y, int x);
349 void square_force_floor(struct chunk *c, int y, int x);
350 
351 
352 int square_shopnum(struct chunk *c, int y, int x);
353 int square_digging(struct chunk *c, int y, int x);
354 const char *square_apparent_name(struct chunk *c, struct player *p, int y, int x);
355 
356 /* cave.c */
357 void set_terrain(void);
358 struct chunk *cave_new(int height, int width);
359 void cave_free(struct chunk *c);
360 void scatter(struct chunk *c, int *yp, int *xp, int y, int x, int d, bool need_los);
361 
362 struct monster *cave_monster(struct chunk *c, int idx);
363 int cave_monster_max(struct chunk *c);
364 int cave_monster_count(struct chunk *c);
365 
366 int count_feats(int *y, int *x, bool (*test)(struct chunk *cave, int y, int x), bool under);
367 
368 void cave_generate(struct chunk **c, struct player *p);
369 bool is_quest(int level);
370 
371 void cave_known(void);
372 
373 #endif /* !CAVE_H */