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