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