OSDN Git Service

import nethack-3.6.0
[jnethack/source.git] / include / sp_lev.h
1 /* NetHack 3.6  sp_lev.h        $NHDT-Date: 1432512780 2015/05/25 00:13:00 $  $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */
2 /* Copyright (c) 1989 by Jean-Christophe Collet                   */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 #ifndef SP_LEV_H
6 #define SP_LEV_H
7
8 /* wall directions */
9 #define W_NORTH 1
10 #define W_SOUTH 2
11 #define W_EAST 4
12 #define W_WEST 8
13 #define W_ANY (W_NORTH | W_SOUTH | W_EAST | W_WEST)
14
15 /* MAP limits */
16 #define MAP_X_LIM 76
17 #define MAP_Y_LIM 21
18
19 /* Per level flags */
20 #define NOTELEPORT 0x00000001L
21 #define HARDFLOOR 0x00000002L
22 #define NOMMAP 0x00000004L
23 #define SHORTSIGHTED 0x00000008L
24 #define ARBOREAL 0x00000010L
25 #define MAZELEVEL 0x00000020L
26 #define PREMAPPED 0x00000040L /* premapped level & sokoban rules */
27 #define SHROUD 0x00000080L
28 #define GRAVEYARD 0x00000100L
29 #define ICEDPOOLS 0x00000200L /* for ice locations: ICED_POOL vs ICED_MOAT \
30                                  */
31 #define SOLIDIFY 0x00000400L  /* outer areas are nondiggable & nonpasswall */
32 #define CORRMAZE 0x00000800L  /* for maze levels only */
33 #define CHECK_INACCESSIBLES 0x00001000L /* check for inaccessible areas and
34    generate ways to escape from them */
35
36 /* different level layout initializers */
37 #define LVLINIT_NONE 0
38 #define LVLINIT_SOLIDFILL 1
39 #define LVLINIT_MAZEGRID 2
40 #define LVLINIT_MINES 3
41 #define LVLINIT_ROGUE 4
42
43 /* max. layers of object containment */
44 #define MAX_CONTAINMENT 10
45
46 /* max. # of random registers */
47 #define MAX_REGISTERS 10
48
49 /* max. nested depth of subrooms */
50 #define MAX_NESTED_ROOMS 5
51
52 /* max. # of opcodes per special level */
53 #define SPCODER_MAX_RUNTIME 65536
54
55 /* Opcodes for creating the level
56  * If you change these, also change opcodestr[] in util/lev_main.c
57  */
58 enum opcode_defs {
59     SPO_NULL = 0,
60     SPO_MESSAGE,
61     SPO_MONSTER,
62     SPO_OBJECT,
63     SPO_ENGRAVING,
64     SPO_ROOM,
65     SPO_SUBROOM,
66     SPO_DOOR,
67     SPO_STAIR,
68     SPO_LADDER,
69     SPO_ALTAR,
70     SPO_FOUNTAIN,
71     SPO_SINK,
72     SPO_POOL,
73     SPO_TRAP,
74     SPO_GOLD,
75     SPO_CORRIDOR,
76     SPO_LEVREGION,
77     SPO_DRAWBRIDGE,
78     SPO_MAZEWALK,
79     SPO_NON_DIGGABLE,
80     SPO_NON_PASSWALL,
81     SPO_WALLIFY,
82     SPO_MAP,
83     SPO_ROOM_DOOR,
84     SPO_REGION,
85     SPO_MINERALIZE,
86     SPO_CMP,
87     SPO_JMP,
88     SPO_JL,
89     SPO_JLE,
90     SPO_JG,
91     SPO_JGE,
92     SPO_JE,
93     SPO_JNE,
94     SPO_TERRAIN,
95     SPO_REPLACETERRAIN,
96     SPO_EXIT,
97     SPO_ENDROOM,
98     SPO_POP_CONTAINER,
99     SPO_PUSH,
100     SPO_POP,
101     SPO_RN2,
102     SPO_DEC,
103     SPO_INC,
104     SPO_MATH_ADD,
105     SPO_MATH_SUB,
106     SPO_MATH_MUL,
107     SPO_MATH_DIV,
108     SPO_MATH_MOD,
109     SPO_MATH_SIGN,
110     SPO_COPY,
111     SPO_END_MONINVENT,
112     SPO_GRAVE,
113     SPO_FRAME_PUSH,
114     SPO_FRAME_POP,
115     SPO_CALL,
116     SPO_RETURN,
117     SPO_INITLEVEL,
118     SPO_LEVEL_FLAGS,
119     SPO_VAR_INIT, /* variable_name data */
120     SPO_SHUFFLE_ARRAY,
121     SPO_DICE,
122
123     SPO_SEL_ADD,
124     SPO_SEL_POINT,
125     SPO_SEL_RECT,
126     SPO_SEL_FILLRECT,
127     SPO_SEL_LINE,
128     SPO_SEL_RNDLINE,
129     SPO_SEL_GROW,
130     SPO_SEL_FLOOD,
131     SPO_SEL_RNDCOORD,
132     SPO_SEL_ELLIPSE,
133     SPO_SEL_FILTER,
134     SPO_SEL_GRADIENT,
135     SPO_SEL_COMPLEMENT,
136
137     MAX_SP_OPCODES
138 };
139
140 /* MONSTER and OBJECT can take a variable number of parameters,
141  * they also pop different # of values from the stack. So,
142  * first we pop a value that tells what the _next_ value will
143  * mean.
144  */
145 /* MONSTER */
146 #define SP_M_V_PEACEFUL 0
147 #define SP_M_V_ALIGN 1
148 #define SP_M_V_ASLEEP 2
149 #define SP_M_V_APPEAR 3
150 #define SP_M_V_NAME 4
151
152 #define SP_M_V_FEMALE 5
153 #define SP_M_V_INVIS 6
154 #define SP_M_V_CANCELLED 7
155 #define SP_M_V_REVIVED 8
156 #define SP_M_V_AVENGE 9
157 #define SP_M_V_FLEEING 10
158 #define SP_M_V_BLINDED 11
159 #define SP_M_V_PARALYZED 12
160 #define SP_M_V_STUNNED 13
161 #define SP_M_V_CONFUSED 14
162 #define SP_M_V_SEENTRAPS 15
163
164 #define SP_M_V_END 16 /* end of variable parameters */
165
166 /* OBJECT */
167 #define SP_O_V_SPE 0
168 #define SP_O_V_CURSE 1
169 #define SP_O_V_CORPSENM 2
170 #define SP_O_V_NAME 3
171 #define SP_O_V_QUAN 4
172 #define SP_O_V_BURIED 5
173 #define SP_O_V_LIT 6
174 #define SP_O_V_ERODED 7
175 #define SP_O_V_LOCKED 8
176 #define SP_O_V_TRAPPED 9
177 #define SP_O_V_RECHARGED 10
178 #define SP_O_V_INVIS 11
179 #define SP_O_V_GREASED 12
180 #define SP_O_V_BROKEN 13
181 #define SP_O_V_COORD 14
182 #define SP_O_V_END 15 /* end of variable parameters */
183
184 /* When creating objects, we need to know whether
185  * it's a container and/or contents.
186  */
187 #define SP_OBJ_CONTENT 0x1
188 #define SP_OBJ_CONTAINER 0x2
189
190 /* SPO_FILTER types */
191 #define SPOFILTER_PERCENT 0
192 #define SPOFILTER_SELECTION 1
193 #define SPOFILTER_MAPCHAR 2
194
195 /* gradient filter types */
196 #define SEL_GRADIENT_RADIAL 0
197 #define SEL_GRADIENT_SQUARE 1
198
199 /* variable types */
200 #define SPOVAR_NULL 0x00
201 #define SPOVAR_INT 0x01      /* l */
202 #define SPOVAR_STRING 0x02   /* str */
203 #define SPOVAR_VARIABLE 0x03 /* str (contains the variable name) */
204 #define SPOVAR_COORD \
205     0x04 /* coordinate, encoded in l; use SP_COORD_X() and SP_COORD_Y() */
206 #define SPOVAR_REGION 0x05  /* region, encoded in l; use SP_REGION_X1() etc \
207                                */
208 #define SPOVAR_MAPCHAR 0x06 /* map char, in l */
209 #define SPOVAR_MONST                                                         \
210     0x07 /* monster class & specific monster, encoded in l; use SP_MONST_... \
211             */
212 #define SPOVAR_OBJ                                                 \
213     0x08 /* object class & specific object type, encoded in l; use \
214             SP_OBJ_... */
215 #define SPOVAR_SEL 0x09   /* selection. char[COLNO][ROWNO] in str */
216 #define SPOVAR_ARRAY 0x40 /* used in splev_var & lc_vardefs, not in opvar */
217
218 #define SP_COORD_IS_RANDOM 0x01000000
219 /* Humidity flags for get_location() and friends, used with
220  * SP_COORD_PACK_RANDOM() */
221 #define DRY 0x1
222 #define WET 0x2
223 #define HOT 0x4
224 #define SOLID 0x8
225 #define ANY_LOC 0x10     /* even outside the level */
226 #define NO_LOC_WARN 0x20 /* no complaints and set x & y to -1, if no loc */
227
228 #define SP_COORD_X(l) (l & 0xff)
229 #define SP_COORD_Y(l) ((l >> 16) & 0xff)
230 #define SP_COORD_PACK(x, y) (((x) &0xff) + (((y) &0xff) << 16))
231 #define SP_COORD_PACK_RANDOM(f) (SP_COORD_IS_RANDOM | (f))
232
233 #define SP_REGION_X1(l) (l & 0xff)
234 #define SP_REGION_Y1(l) ((l >> 8) & 0xff)
235 #define SP_REGION_X2(l) ((l >> 16) & 0xff)
236 #define SP_REGION_Y2(l) ((l >> 24) & 0xff)
237 #define SP_REGION_PACK(x1, y1, x2, y2)                         \
238     (((x1) &0xff) + (((y1) &0xff) << 8) + (((x2) &0xff) << 16) \
239      + (((y2) &0xff) << 24))
240
241 #define SP_MONST_CLASS(l) (l & 0xff)
242 #define SP_MONST_PM(l) ((l >> 8) & 0xffff)
243 #define SP_MONST_PACK(m, c) (((m) << 8) + ((char) (c)))
244
245 #define SP_OBJ_CLASS(l) (l & 0xff)
246 #define SP_OBJ_TYP(l) ((l >> 8) & 0xffff)
247 #define SP_OBJ_PACK(o, c) (((o) << 8) + ((char) (c)))
248
249 #define SP_MAPCHAR_TYP(l) (l & 0xff)
250 #define SP_MAPCHAR_LIT(l) ((l >> 8) & 0xff)
251 #define SP_MAPCHAR_PACK(typ, lit) (((lit) << 8) + ((char) (typ)))
252
253 struct opvar {
254     xchar spovartyp; /* one of SPOVAR_foo */
255     union {
256         char *str;
257         long l;
258     } vardata;
259 };
260
261 struct splev_var {
262     struct splev_var *next;
263     char *name;
264     xchar svtyp; /* SPOVAR_foo */
265     union {
266         struct opvar *value;
267         struct opvar **arrayvalues;
268     } data;
269     long array_len;
270 };
271
272 struct splevstack {
273     long depth;
274     long depth_alloc;
275     struct opvar **stackdata;
276 };
277
278 struct sp_frame {
279     struct sp_frame *next;
280     struct splevstack *stack;
281     struct splev_var *variables;
282     long n_opcode;
283 };
284
285 struct sp_coder {
286     struct splevstack *stack;
287     struct sp_frame *frame;
288     int premapped;
289     boolean solidify;
290     struct mkroom *croom;
291     struct mkroom *tmproomlist[MAX_NESTED_ROOMS + 1];
292     boolean failed_room[MAX_NESTED_ROOMS + 1];
293     int n_subroom;
294     boolean exit_script;
295     int lvl_is_joined;
296     boolean check_inaccessibles;
297
298     int opcode;          /* current opcode */
299     struct opvar *opdat; /* current push data (req. opcode == SPO_PUSH) */
300 };
301
302 /* special level coder CPU flags */
303 #define SP_CPUFLAG_LT 1
304 #define SP_CPUFLAG_GT 2
305 #define SP_CPUFLAG_EQ 4
306 #define SP_CPUFLAG_ZERO 8
307
308 /*
309  * Structures manipulated by the special levels loader & compiler
310  */
311
312 #define packed_coord long
313 typedef struct {
314     xchar is_random;
315     long getloc_flags;
316     int x, y;
317 } unpacked_coord;
318
319 typedef struct {
320     int cmp_what;
321     int cmp_val;
322 } opcmp;
323
324 typedef struct {
325     long jmp_target;
326 } opjmp;
327
328 typedef union str_or_len {
329     char *str;
330     int len;
331 } Str_or_Len;
332
333 typedef struct {
334     xchar init_style; /* one of LVLINIT_foo */
335     long flags;
336     schar filling;
337     boolean init_present, padding;
338     char fg, bg;
339     boolean smoothed, joined;
340     xchar lit, walled;
341     boolean icedpools;
342 } lev_init;
343
344 typedef struct {
345     xchar wall, pos, secret, mask;
346 } room_door;
347
348 typedef struct {
349     packed_coord coord;
350     xchar x, y, type;
351 } trap;
352
353 typedef struct {
354     Str_or_Len name, appear_as;
355     short id;
356     aligntyp align;
357     packed_coord coord;
358     xchar x, y, class, appear;
359     schar peaceful, asleep;
360     short female, invis, cancelled, revived, avenge, fleeing, blinded,
361         paralyzed, stunned, confused;
362     long seentraps;
363     short has_invent;
364 } monster;
365
366 typedef struct {
367     Str_or_Len name;
368     int corpsenm;
369     short id, spe;
370     packed_coord coord;
371     xchar x, y, class, containment;
372     schar curse_state;
373     int quan;
374     short buried;
375     short lit;
376     short eroded, locked, trapped, recharged, invis, greased, broken;
377 } object;
378
379 typedef struct {
380     packed_coord coord;
381     xchar x, y;
382     aligntyp align;
383     xchar shrine;
384 } altar;
385
386 typedef struct {
387     xchar x1, y1, x2, y2;
388     xchar rtype, rlit, rirreg;
389 } region;
390
391 typedef struct {
392     xchar ter, tlit;
393 } terrain;
394
395 typedef struct {
396     xchar chance;
397     xchar x1, y1, x2, y2;
398     xchar fromter, toter, tolit;
399 } replaceterrain;
400
401 /* values for rtype are defined in dungeon.h */
402 typedef struct {
403     struct {
404         xchar x1, y1, x2, y2;
405     } inarea;
406     struct {
407         xchar x1, y1, x2, y2;
408     } delarea;
409     boolean in_islev, del_islev;
410     xchar rtype, padding;
411     Str_or_Len rname;
412 } lev_region;
413
414 typedef struct {
415     struct {
416         xchar room;
417         xchar wall;
418         xchar door;
419     } src, dest;
420 } corridor;
421
422 typedef struct _room {
423     Str_or_Len name;
424     Str_or_Len parent;
425     xchar x, y, w, h;
426     xchar xalign, yalign;
427     xchar rtype, chance, rlit, filled, joined;
428 } room;
429
430 typedef struct {
431     schar zaligntyp;
432     schar keep_region;
433     schar halign, valign;
434     char xsize, ysize;
435     char **map;
436 } mazepart;
437
438 typedef struct {
439     int opcode;
440     struct opvar *opdat;
441 } _opcode;
442
443 typedef struct {
444     _opcode *opcodes;
445     long n_opcodes;
446 } sp_lev;
447
448 typedef struct {
449     xchar x, y, direction, count, lit;
450     char typ;
451 } spill;
452
453 /* only used by lev_comp */
454 struct lc_funcdefs_parm {
455     char *name;
456     char parmtype;
457     struct lc_funcdefs_parm *next;
458 };
459
460 struct lc_funcdefs {
461     struct lc_funcdefs *next;
462     char *name;
463     long addr;
464     sp_lev code;
465     long n_called;
466     struct lc_funcdefs_parm *params;
467     long n_params;
468 };
469
470 struct lc_vardefs {
471     struct lc_vardefs *next;
472     char *name;
473     long var_type; /* SPOVAR_foo */
474     long n_used;
475 };
476
477 struct lc_breakdef {
478     struct lc_breakdef *next;
479     struct opvar *breakpoint;
480     int break_depth;
481 };
482
483 /*
484  * Quick! Avert your eyes while you still have a chance!
485  */
486 #ifdef SPEC_LEV
487 /* compiling lev_comp rather than nethack */
488 #ifdef USE_OLDARGS
489 #undef VA_ARGS
490 #undef VA_DECL
491 #undef VA_DECL2
492 #undef VA_SHIFT
493 #define VA_ARGS                                                         \
494     arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, \
495         arg12, arg13, arg14
496 #define VA_DECL(typ1, var1)                                             \
497     (var1, VA_ARGS) typ1 var1;                                          \
498     char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9, \
499         *arg10, *arg11, *arg12, *arg13, *arg14;                         \
500     {
501 #define VA_DECL2(typ1, var1, typ2, var2)                                \
502     (var1, var2, VA_ARGS) typ1 var1;                                    \
503     typ2 var2;                                                          \
504     char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9, \
505         *arg10, *arg11, *arg12, *arg13, *arg14;                         \
506     {
507 /* unlike in the core, lev_comp's VA_SHIFT is completely safe,
508    because callers always pass all these arguments */
509 #define VA_SHIFT()                                                       \
510     (arg1 = arg2, arg2 = arg3, arg3 = arg4, arg4 = arg5, arg5 = arg6,    \
511      arg6 = arg7, arg7 = arg8, arg8 = arg9, arg9 = arg10, arg10 = arg11, \
512      arg11 = arg12, arg12 = arg13, arg13 = arg14, arg14 = 0)
513 /* standard NULL may be either (void *)0 or plain 0, both of
514    which would need to be explicitly cast to (char *) here */
515 typedef char *Va;
516 #define VA_PASS1(a1)                                                         \
517     (Va) a1, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
518         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
519 #define VA_PASS2(a1, a2)                                              \
520     (Va) a1, (Va) a2, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
521         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
522 #define VA_PASS3(a1, a2, a3)                                           \
523     (Va) a1, (Va) a2, (Va) a3, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
524         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
525 #define VA_PASS4(a1, a2, a3, a4)                                        \
526     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
527         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
528 #define VA_PASS5(a1, a2, a3, a4, a5)                                     \
529     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) 0, (Va) 0, (Va) 0, \
530         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
531 #define VA_PASS7(a1, a2, a3, a4, a5, a6, a7)                               \
532     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) 0, \
533         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
534 #define VA_PASS8(a1, a2, a3, a4, a5, a6, a7, a8)                            \
535     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
536         (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
537 #define VA_PASS9(a1, a2, a3, a4, a5, a6, a7, a8, a9)                        \
538     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
539         (Va) a9, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
540 #define VA_PASS14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13,   \
541                   a14)                                                      \
542     (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
543         (Va) a9, (Va) a10, (Va) a11, (Va) a12, (Va) a13, (Va) a14
544 #else /*!USE_OLDARGS*/
545 /* USE_STDARG and USE_VARARGS don't need to pass dummy arguments
546    or cast real ones */
547 #define VA_PASS1(a1) a1
548 #define VA_PASS2(a1, a2) a1, a2
549 #define VA_PASS3(a1, a2, a3) a1, a2, a3
550 #define VA_PASS4(a1, a2, a3, a4) a1, a2, a3, a4
551 #define VA_PASS5(a1, a2, a3, a4, a5) a1, a2, a3, a4, a5
552 #define VA_PASS7(a1, a2, a3, a4, a5, a6, a7) a1, a2, a3, a4, a5, a6, a7
553 #define VA_PASS8(a1, a2, a3, a4, a5, a6, a7, a8) \
554     a1, a2, a3, a4, a5, a6, a7, a8
555 #define VA_PASS9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
556     a1, a2, a3, a4, a5, a6, a7, a8, a9
557 #define VA_PASS14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, \
558                   a14)                                                    \
559     a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14
560 #endif /*?USE_OLDARGS*/
561 /* You were warned to avert your eyes.... */
562 #endif /*SPEC_LEV*/
563
564 #endif /* SP_LEV_H */