Merge remote-tracking branch 'origin/vendor/LIBEDIT'
[dragonfly.git] / games / hack / hack.h
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.h - version 1.0.3 */
3
4 #include "config.h"
5 #include <fcntl.h>
6 #include <signal.h>
7 #include <stdarg.h>
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13
14 #include "def.objclass.h"
15
16 typedef struct {
17         xchar x, y;
18 } coord;
19
20 #include "def.monst.h"  /* uses coord */
21 #include "def.gold.h"
22 #include "def.trap.h"
23 #include "def.obj.h"
24 #include "def.flag.h"
25 #include "def.mkroom.h"
26 #include "def.wseg.h"
27
28 #define plur(x) (((x) == 1) ? "" : "s")
29
30 #define BUFSZ   256     /* for getlin buffers */
31 #define PL_NSIZ 32      /* name of player, ghost, shopkeeper */
32
33 #include "def.rm.h"
34 #include "def.permonst.h"
35
36 extern xchar xdnstair, ydnstair, xupstair, yupstair; /* stairs up and down. */
37
38 #define newstring(x)    alloc((unsigned)(x))
39 #include "hack.onames.h"
40
41 #define ON      1
42 #define OFF     0
43
44 extern struct obj *invent, *uwep, *uarm, *uarm2, *uarmh, *uarms, *uarmg,
45         *uleft, *uright, *fcobj;
46 extern struct obj *uchain;      /* defined iff PUNISHED */
47 extern struct obj *uball;       /* defined if PUNISHED */
48
49 struct prop {
50 #define TIMEOUT         007777  /* mask */
51 #define LEFT_RING       W_RINGL /* 010000L */
52 #define RIGHT_RING      W_RINGR /* 020000L */
53 #define INTRINSIC       040000L
54 #define LEFT_SIDE       LEFT_RING
55 #define RIGHT_SIDE      RIGHT_RING
56 #define BOTH_SIDES      (LEFT_SIDE | RIGHT_SIDE)
57         long p_flgs;
58         void (*p_tofn)(void);   /* called after timeout */
59 };
60
61 struct you {
62         xchar ux, uy;
63         schar dx, dy, dz;       /* direction of move (or zap or ... ) */
64 #ifdef QUEST
65         schar di;               /* direction of FF */
66         xchar ux0, uy0;         /* initial position FF */
67 #endif /* QUEST */
68         xchar udisx, udisy;     /* last display pos */
69         char usym;              /* usually '@' */
70         schar uluck;
71 #define LUCKMAX         10      /* on moonlit nights 11 */
72 #define LUCKMIN         (-10)
73         int last_str_turn:3;    /* 0: none, 1: half turn, 2: full turn */
74                                 /* +: turn right, -: turn left */
75         unsigned udispl:1;      /* @ on display */
76         unsigned ulevel:4;      /* 1 - 14 */
77 #ifdef QUEST
78         unsigned uhorizon:7;
79 #endif /* QUEST */
80         unsigned utrap:3;       /* trap timeout */
81         unsigned utraptype:1;   /* defined if utrap nonzero */
82 #define TT_BEARTRAP     0
83 #define TT_PIT          1
84         unsigned uinshop:6;     /* used only in shk.c - (roomno+1) of shop */
85
86
87 /* perhaps these #define's should also be generated by makedefs */
88 #define TELEPAT         LAST_RING               /* not a ring */
89 #define Telepat         u.uprops[TELEPAT].p_flgs
90 #define FAST            (LAST_RING+1)           /* not a ring */
91 #define Fast            u.uprops[FAST].p_flgs
92 #define CONFUSION       (LAST_RING+2)           /* not a ring */
93 #define Confusion       u.uprops[CONFUSION].p_flgs
94 #define INVIS           (LAST_RING+3)           /* not a ring */
95 #define Invis           u.uprops[INVIS].p_flgs
96 #define Invisible       (Invis && !See_invisible)
97 #define GLIB            (LAST_RING+4)           /* not a ring */
98 #define Glib            u.uprops[GLIB].p_flgs
99 #define PUNISHED        (LAST_RING+5)           /* not a ring */
100 #define Punished        u.uprops[PUNISHED].p_flgs
101 #define SICK            (LAST_RING+6)           /* not a ring */
102 #define Sick            u.uprops[SICK].p_flgs
103 #define BLIND           (LAST_RING+7)           /* not a ring */
104 #define Blind           u.uprops[BLIND].p_flgs
105 #define WOUNDED_LEGS    (LAST_RING+8)           /* not a ring */
106 #define Wounded_legs    u.uprops[WOUNDED_LEGS].p_flgs
107 #define STONED          (LAST_RING+9)           /* not a ring */
108 #define Stoned          u.uprops[STONED].p_flgs
109 #define PROP(x)         (x-RIN_ADORNMENT)       /* convert ring to index in uprops */
110         unsigned umconf:1;
111         const char *usick_cause;
112         struct prop uprops[LAST_RING+10];
113
114         unsigned uswallow:1;            /* set if swallowed by a monster */
115         unsigned uswldtim:4;            /* time you have been swallowed */
116         unsigned uhs:3;                 /* hunger state - see hack.eat.c */
117         schar ustr, ustrmax;
118         schar udaminc;
119         schar uac;
120         int uhp, uhpmax;
121         long int ugold, ugold0, uexp, urexp;
122         int uhunger;                    /* refd only in eat.c and shk.c */
123         int uinvault;
124         struct monst *ustuck;
125         int nr_killed[CMNUM+2];         /* used for experience bookkeeping */
126 };
127
128 extern struct you u;
129
130 extern const char *traps[];
131 extern char vowels[];
132
133 extern xchar curx, cury;        /* cursor location on screen */
134
135 extern coord bhitpos;   /* place where thrown weapon falls to the ground */
136
137 extern xchar seehx, seelx, seehy, seely; /* where to see*/
138 extern const char *save_cm, *killer, *nomovemsg;
139
140 extern xchar dlevel, maxdlevel; /* dungeon level */
141
142 extern long moves;
143
144 extern int multi;
145
146 extern char lock[];
147
148 extern const char *occtxt;
149 extern const char *hu_stat[];
150
151 #define DIST(x1,y1,x2,y2)       (((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2)))
152
153 #define PL_CSIZ         20      /* sizeof pl_character */
154 #define MAX_CARR_CAP    120     /* so that boulders can be heavier */
155 #define MAXLEVEL        40
156 #define FAR     (COLNO+2)       /* position outside screen */
157
158 extern schar xdir[], ydir[];
159 extern int hackpid, locknum, doorindex, done_stopprint;
160 extern char mlarge[], pl_character[PL_CSIZ], genocided[60], fut_geno[60];
161 extern char *hname, morc, plname[PL_NSIZ], sdir[];
162 extern boolean level_exists[], restoring, in_mklev;
163 extern struct permonst pm_eel, pm_ghost;
164 extern void (*afternmv)(void);
165 extern struct monst *mydogs;
166 extern bool (*occupation)(void);
167
168 /* Non-static function prototypes */
169
170 /* alloc.c */
171 void    *alloc(size_t);
172
173 /* hack.apply.c */
174 int     doapply(void);
175 int     holetime(void);
176 void    dighole(void);
177
178 /* hack.bones.c */
179 void    savebones(void);
180 int     getbones(void);
181
182 /* hack.c */
183 void    unsee(void);
184 void    seeoff(bool);
185 void    domove(void);
186 int     dopickup(void);
187 void    pickup(int);
188 void    lookaround(void);
189 bool    monster_nearby(void);
190 bool    cansee(xchar, xchar);
191 int     sgn(int);
192 void    setsee(void);
193 void    nomul(int);
194 int     abon(void);
195 int     dbon(void);
196 void    losestr(int);
197 void    losehp(int, const char *);
198 void    losehp_m(int, struct monst *);
199 void    losexp(void);
200 int     inv_weight(void);
201 long    newuexp(void);
202
203 /* hack.cmd.c */
204 void    rhack(const char *);
205 bool    movecmd(char);
206 bool    getdir(bool);
207 void    confdir(void);
208 #ifdef QUEST
209 void    finddir(void);
210 #endif
211 bool    isok(int, int);
212
213 /* hack.do.c */
214 int              dodrop(void);
215 void             dropx(struct obj *);
216 int              doddrop(void);
217 int              dodown(void);
218 int              doup(void);
219 void             goto_level(int, bool);
220 int              donull(void);
221 int              dopray(void);
222 int              dothrow(void);
223 struct obj      *splitobj(struct obj *, int);
224 void             more_experienced(int, int);
225 void             set_wounded_legs(long, int);
226 void             heal_legs(void);
227
228 /* hack.do_name.c */
229 coord    getpos(int, const char *);
230 int      do_mname(void);
231 int      ddocall(void);
232 void     docall(struct obj *);
233 char    *monnam(struct monst *);
234 char    *Monnam(struct monst *);
235 char    *amonnam(struct monst *, const char *);
236 char    *Amonnam(struct monst *, const char *);
237 char    *Xmonnam(struct monst *);
238
239 /* hack.do_wear.c */
240 int              doremarm(void);
241 int              doremring(void);
242 bool             armoroff(struct obj *);
243 int              doweararm(void);
244 int              dowearring(void);
245 void             ringoff(struct obj *);
246 void             find_ac(void);
247 void             glibr(void);
248 struct obj      *some_armor(void);
249 void             corrode_armor(void);
250
251 /* hack.dog.c */
252 void    makedog(void);
253 void    losedogs(void);
254 void    keepdogs(void);
255 void    fall_down(struct monst *);
256 int     dog_move(struct monst *, int);
257 int     inroom(xchar, xchar);
258 bool    tamedog(struct monst *, struct obj *);
259
260 /* hack.eat.c */
261 void    init_uhunger(void);
262 int     doeat(void);
263 void    gethungry(void);
264 void    morehungry(int);
265 void    lesshungry(int);
266 bool    poisonous(struct obj *);
267
268 /* hack.end.c */
269 void     done1(int);
270 void     done_in_by(struct monst *);
271 void     done(const char *);
272 void     clearlocks(void);
273 #ifdef NOSAVEONHANGUP
274 void     hangup(int) __dead2;
275 #endif
276 char    *eos(char *);
277 void     charcat(char *, char);
278 void     prscore(int, char **);
279
280 /* hack.engrave.c */
281 bool    sengr_at(const char *, xchar, xchar);
282 void    u_wipe_engr(int);
283 void    wipe_engr_at(xchar, xchar, xchar);
284 void    read_engr_at(int, int);
285 void    make_engr_at(int, int, const char *);
286 int     doengrave(void);
287 void    save_engravings(int);
288 void    rest_engravings(int);
289
290 /* hack.fight.c */
291 int     hitmm(struct monst *, struct monst *);
292 void    mondied(struct monst *);
293 int     fightm(struct monst *);
294 bool    thitu(int, int, const char *);
295 bool    hmon(struct monst *, struct obj *, int);
296 bool    attack(struct monst *);
297
298 /* hack.invent.c */
299 struct obj      *addinv(struct obj *);
300 void             useup(struct obj *);
301 void             freeinv(struct obj *);
302 void             delobj(struct obj *);
303 void             freeobj(struct obj *);
304 void             freegold(struct gold *);
305 void             deltrap(struct trap *);
306 struct monst    *m_at(int, int);
307 struct obj      *o_at(int, int);
308 struct obj      *sobj_at(int, int, int);
309 bool             carried(struct obj *);
310 bool             carrying(int);
311 struct obj      *o_on(unsigned int, struct obj *);
312 struct trap     *t_at(int, int);
313 struct gold     *g_at(int, int);
314 struct obj      *getobj(const char *, const char *);
315 int              ggetobj(const char *, int (*)(struct obj *), int);
316 int              askchain(struct obj *, char *, int, int (*)(struct obj *),
317                           bool (*)(struct obj *), int);
318 void             prinv(struct obj *);
319 int              ddoinv(void);
320 int              dotypeinv(void);
321 int              dolook(void);
322 void             stackobj(struct obj *);
323 int              doprgold(void);
324 int              doprwep(void);
325 int              doprarm(void);
326 int              doprring(void);
327 bool             digit(char);
328
329 /* hack.ioctl.c */
330 void    getioctls(void);
331 void    setioctls(void);
332 #ifdef SUSPEND
333 int     dosuspend(void);
334 #endif
335
336 /* hack.lev.c */
337 void    savelev(int, xchar);
338 void    bwrite(int, char *, unsigned int);
339 void    saveobjchn(int, struct obj *);
340 void    savemonchn(int, struct monst *);
341 void    getlev(int, int, xchar);
342 void    mread(int, char *, unsigned int);
343 void    mklev(void);
344
345 /* hack.main.c */
346 void    glo(int);
347 void    askname(void);
348 void    impossible(const char *, ...) __printflike(1, 2);
349 void    stop_occupation(void);
350
351 /* hack.makemon.c */
352 struct monst    *makemon(struct permonst *, int, int);
353 coord            enexto(xchar, xchar);
354 bool             goodpos(int, int);
355 void             rloc(struct monst *);
356 struct monst    *mkmon_at(char, int, int);
357
358 /* hack.mhitu.c */
359 bool    mhitu(struct monst *);
360 bool    hitu(struct monst *, int);
361
362 /* hack.mklev.c */
363 void    makelevel(void);
364 void    mktrap(int, int, struct mkroom *);
365
366 /* hack.mkmaze.c */
367 void    makemaz(void);
368 coord   mazexy(void);
369
370 /* hack.mkobj.c */
371 struct obj      *mkobj_at(int, int, int);
372 void             mksobj_at(int, int, int);
373 struct obj      *mkobj(int);
374 struct obj      *mksobj(int);
375 bool             letter(char);
376 int              weight(struct obj *);
377 void             mkgold(long, int, int);
378
379 /* hack.mkshop.c */
380 #ifndef QUEST
381 void    mkshop(void);
382 void    mkzoo(int);
383 void    mkswamp(void);
384 #endif
385
386 /* hack.mon.c */
387 void    movemon(void);
388 void    justswld(struct monst *, const char *);
389 void    youswld(struct monst *, int, int, const char *);
390 bool    dochug(struct monst *);
391 int     m_move(struct monst *, int);
392 int     mfndpos(struct monst *, coord *, int *, int);
393 int     dist(int, int);
394 void    poisoned(const char *, const char *);
395 void    mondead(struct monst *);
396 void    replmon(struct monst *, struct monst *);
397 void    relmon(struct monst *);
398 void    monfree(struct monst *);
399 void    unstuck(struct monst *);
400 void    killed(struct monst *);
401 void    kludge(const char *, const char *);
402 void    rescham(void);
403 bool    newcham(struct monst *, struct permonst *);
404 void    mnexto(struct monst *);
405 void    setmangry(struct monst *);
406 bool    canseemon(struct monst *);
407
408 /* hack.o_init.c */
409 int     letindex(char);
410 void    init_objects(void);
411 int     probtype(char);
412 void    oinit(void);
413 void    savenames(int);
414 void    restnames(int);
415 int     dodiscovered(void);
416
417 /* hack.objnam.c */
418 char            *typename(int);
419 char            *xname(struct obj *);
420 char            *doname(struct obj *);
421 void             setan(const char *, char *);
422 char            *aobjnam(struct obj *, const char *);
423 char            *Doname(struct obj *);
424 struct obj      *readobjnam(char *);
425
426 /* hack.options.c */
427 void    initoptions(void);
428 int     doset(void);
429
430 /* hack.pager.c */
431 int     dowhatis(void);
432 void    set_whole_screen(void);
433 #ifdef NEWS
434 bool    readnews(void);
435 #endif
436 void    set_pager(int);
437 bool    page_line(const char *);
438 void    cornline(int, const char *);
439 int     dohelp(void);
440 bool    page_file(const char *, bool);
441 #ifdef UNIX
442 #ifdef SHELL
443 int     dosh(void);
444 #endif /* SHELL */
445 bool    child(bool);
446 #endif /* UNIX */
447
448 /* hack.potion.c */
449 int     dodrink(void);
450 void    pluslvl(void);
451 void    strange_feeling(struct obj *, const char *);
452 void    potionhit(struct monst *, struct obj *);
453 void    potionbreathe(struct obj *);
454 int     dodip(void);
455
456 /* hack.pri.c */
457 void    swallowed(void);
458 void    panic(const char *, ...) __printflike(1, 2);
459 void    atl(int, int, char);
460 void    on_scr(int, int);
461 void    tmp_at(schar, schar);
462 void    Tmp_at(schar, schar);
463 void    setclipped(void) __dead2;
464 void    at(xchar, xchar, char);
465 void    prme(void);
466 int     doredraw(void);
467 void    docrt(void);
468 void    docorner(int, int);
469 void    curs_on_u(void);
470 void    pru(void);
471 void    prl(int, int);
472 char    news0(xchar, xchar);
473 void    newsym(int, int);
474 void    mnewsym(int, int);
475 void    nosee(int, int);
476 #ifndef QUEST
477 void    prl1(int, int);
478 void    nose1(int, int);
479 #endif
480 bool    vism_at(int, int);
481 void    unpobj(struct obj *);
482 void    seeobjs(void);
483 void    seemons(void);
484 void    pmon(struct monst *);
485 void    unpmon(struct monst *);
486 void    nscr(void);
487 void    bot(void);
488 #ifdef WAN_PROBING
489 void    mstatusline(struct monst *);
490 #endif
491 void    cls(void);
492
493 /* hack.read.c */
494 int     doread(void);
495 int     identify(struct obj *);
496 void    litroom(bool);
497
498 /* hack.rip.c */
499 void    outrip(void);
500
501 /* hack.rumors.c */
502 void    outrumor(void);
503
504 /* hack.save.c */
505 int              dosave(void);
506 #ifndef NOSAVEONHANGUP
507 void             hangup(int) __dead2;
508 #endif
509 bool             dorecover(int);
510 struct obj      *restobjchn(int);
511 struct monst    *restmonchn(int);
512
513 /* hack.search.c */
514 int     findit(void);
515 int     dosearch(void);
516 int     doidtrap(void);
517 void    wakeup(struct monst *);
518 void    seemimic(struct monst *);
519
520 /* hack.shk.c */
521 #ifdef QUEST
522 void             obfree(struct obj *, struct obj *);
523 int              inshop(void);
524 void             shopdig(void);
525 void             addtobill(void);
526 void             subfrombill(void);
527 void             splitbill(void);
528 int              dopay(void);
529 void             paybill(void);
530 int              doinvbill(void);
531 void             shkdead(void);
532 int              shkcatch(void);
533 int              shk_move(void);
534 void             replshk(struct monst *, struct monst *);
535 const char      *shkname(void);
536 #else
537 char            *shkname(struct monst *);
538 void             shkdead(struct monst *);
539 void             replshk(struct monst *, struct monst *);
540 int              inshop(void);
541 void             obfree(struct obj *, struct obj *);
542 int              dopay(void);
543 void             paybill(void);
544 void             addtobill(struct obj *);
545 void             splitbill(struct obj *, struct obj *);
546 void             subfrombill(struct obj *);
547 int              doinvbill(int);
548 bool             shkcatch(struct obj *);
549 int              shk_move(struct monst *);
550 void             shopdig(int);
551 #endif
552 bool             online(int, int);
553 bool             follower(struct monst *);
554
555 /* hack.shknam.c */
556 void    findname(char *, char);
557
558 /* hack.steal.c */
559 long    somegold(void);
560 void    stealgold(struct monst *);
561 bool    steal(struct monst *);
562 void    mpickobj(struct monst *, struct obj *);
563 bool    stealamulet(struct monst *);
564 void    relobj(struct monst *, int);
565
566 /* hack.termcap.c */
567 void    startup(void);
568 void    start_screen(void);
569 void    end_screen(void);
570 void    curs(int, int);
571 void    cl_end(void);
572 void    clear_screen(void);
573 void    home(void);
574 void    standoutbeg(void);
575 void    standoutend(void);
576 void    backsp(void);
577 void    bell(void);
578 void    cl_eos(void);
579
580 /* hack.timeout.c */
581 void    p_timeout(void);
582
583 /* hack.topl.c */
584 int     doredotopl(void);
585 void    remember_topl(void);
586 void    addtopl(const char *);
587 void    more(void);
588 void    cmore(const char *);
589 void    clrlin(void);
590 void    pline(const char *, ...) __printflike(1, 2);
591 void    vpline(const char *, va_list) __printf0like(1, 0);
592 void    putsym(char);
593 void    putstr(const char *);
594
595 /* hack.track.c */
596 void     initrack(void);
597 void     settrack(void);
598 coord   *gettrack(int, int);
599
600 /* hack.trap.c */
601 struct trap     *maketrap(int, int, int);
602 void             dotrap(struct trap *);
603 int              mintrap(struct monst *);
604 void             selftouch(const char *);
605 void             float_up(void);
606 void             float_down(void);
607 void             tele(void);
608 int              dotele(void);
609 void             placebc(int);
610 void             unplacebc(void);
611 void             level_tele(void);
612 void             drown(void);
613
614 /* hack.tty.c */
615 void     gettty(void);
616 void     settty(const char *);
617 void     setftty(void);
618 void     error(const char *, ...) __printflike(1, 2) __dead2;
619 void     getlin(char *);
620 void     getret(void);
621 void     cgetret(const char *);
622 void     xwaitforspace(const char *);
623 char    *parse(void);
624 char     readchar(void);
625 void     end_of_input(void) __dead2;
626
627 /* hack.u_init.c */
628 void    u_init(void);
629 void    plnamesuffix(void);
630
631 /* hack.unix.c */
632 void     setrandom(void);
633 int      getyear(void);
634 char    *getdate(void);
635 int      phase_of_the_moon(void);
636 bool     night(void);
637 bool     midnight(void);
638 void     gethdate(const char *);
639 bool     uptodate(int);
640 void     getlock(void);
641 #ifdef MAIL
642 void     getmailstatus(void);
643 void     ckmailstatus(void);
644 void     readmail(void);
645 #endif
646 void     regularize(char *);
647
648 /* hack.vault.c */
649 void    setgd(void);
650 int     gd_move(void);
651 void    replgd(struct monst *, struct monst *);
652 void    invault(void);
653 #ifdef QUEST
654 void    gddead(struct monst *);
655 #else
656 void    gddead(void);
657 #endif
658
659 /* hack.version.c */
660 int     doversion(void);
661
662 /* hack.wield.c */
663 void    setuwep(struct obj *);
664 int     dowield(void);
665 void    corrode_weapon(void);
666 bool    chwepon(struct obj *, int);
667
668 /* hack.wizard.c */
669 void    amulet(void);
670 bool    wiz_hit(struct monst *);
671 void    inrange(struct monst *);
672
673 /* hack.worm.c */
674 #ifndef NOWORM
675 bool    getwn(struct monst *);
676 void    initworm(struct monst *);
677 void    worm_move(struct monst *);
678 void    worm_nomove(struct monst *);
679 void    wormdead(struct monst *);
680 void    wormhit(struct monst *);
681 void    wormsee(unsigned int);
682 void    pwseg(struct wseg *);
683 void    cutworm(struct monst *, xchar, xchar, uchar);
684 #endif
685
686 /* hack.worn.c */
687 void    setworn(struct obj *, long);
688 void    setnotworn(struct obj *);
689
690 /* hack.zap.c */
691 int              dozap(void);
692 const char      *exclam(int);
693 void             hit(const char *, struct monst *, const char *);
694 void             miss(const char *, struct monst *);
695 struct monst    *bhit(int, int, int, char,
696                       void (*)(struct monst *, struct obj *),
697                       bool (*)(struct obj *, struct obj *), struct obj *);
698 struct monst    *boomhit(int, int);
699 void             buzz(int, xchar, xchar, int, int);
700 void             fracture_rock(struct obj *);
701
702 /* rnd.c */
703 int     rn1(int, int);
704 int     rn2(int);
705 int     rnd(int);
706 int     d(int, int);