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