Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site amdahl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!amdahl!gam From: gam@amdahl.UUCP (gam) Newsgroups: net.sources Subject: Re: hack: changes for SVR2 (3 of 3) Message-ID: <875@amdahl.UUCP> Date: Sun, 6-Jan-85 04:18:11 EST Article-I.D.: amdahl.875 Posted: Sun Jan 6 04:18:11 1985 Date-Received: Tue, 8-Jan-85 02:47:57 EST References: <873@amdahl.UUCP> <874@amdahl.UUCP> Distribution: net Organization: Blue Mouse Trailer Resort, Hellmouth, CA Lines: 1204 : This is a shar archive. Extract with sh, not csh. echo x - hack.termcap.c sed -e 's/^X//' > hack.termcap.c << '!Funky!Stuff!' X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ X X#define SINGLE X#includeX#include X#include "config.h" /* for ROWNO and COLNO */ X Xextern char *tparm(); Xextern char *getenv(); X Xshort ospeed; /* terminal baudrate; used by tputs */ Xchar *HO, *CL, *CE, *UP, *CM, *ND, *XD, *BC, *SO, *SE; Xchar PC = '\0'; X Xstartup() X{ X register char *tmp; X char *pc; X int tliberr; X X X if(!(tmp = getenv("TERM"))) X error("Can't get TERM."); X def_shell_mode(); X setupterm(tmp, 0, &tliberr); X gettty(); /* sets ospeed */ X X if(tliberr < 1) X error("Unknown terminal type: %s.", tmp); X if(pc = pad_char) X PC = *pc; X if(!(BC = cursor_left)){ X BC = "\b"; X } X HO = cursor_home; X if(columns < COLNO || lines < ROWNO+2) X error("Screen must be at least %d by %d!", X ROWNO+2, COLNO); X if(!(CL = clear_screen) || !(CE = clr_eol) || X !(ND = cursor_right) || X !(UP = cursor_up) || over_strike) X error("Hack needs clear_screen, clr_eol, cursor_up, cursor_right,\nand no over_strike."); X if(!(CM = cursor_address)) X error("Use of hack on terminals without cursor_motion is unsupported...\n"); X XD = cursor_down; X SO = enter_standout_mode; X SE = exit_standout_mode; X if(!SO || !SE) SO = SE = 0; X} X X/* Cursor movements */ Xextern xchar curx, cury; X Xcurs(x,y) Xregister int x,y; /* not xchar: perhaps xchar is unsigned and X curx-x would be unsigned as well */ X{ X X if (y == cury && x == curx) return; X if(abs(cury-y)<= 3 && abs(curx-x)<= 3) { X nocmov(x,y); X } else if((x <= 3 && abs(cury-y)<= 3) || (!CM && x x) { X while (curx > x) { /* Go to the left. */ X xputs(BC); X curx--; X } X } X if (cury > y) { X if(UP) { X while (cury > y) { /* Go up. */ X xputs(UP); X cury--; X } X } else cmov(x,y); X } else if (cury < y) { X if(XD) { X while(cury hack.tty.c << '!Funky!Stuff!' X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ X X#define SINGLE X#include X#include X#undef move X#include "hack.h" X Xextern short ospeed; X X Xgettty(){ X def_prog_mode(); X ospeed = cur_term->Nttyb.c_cflag & CBAUD; X/* X if(ospeed <= B300) flags.oneline = 1; X*/ X} X X/* reset terminal to original state */ Xsettty(s) char *s; { X clearscreen(); X if(s) printf(s); X (void) fflush(stdout); X reset_shell_mode(); X} X Xsetctty() X{ X reset_prog_mode(); X} X Xsetftty(){ Xregister int ef = (flags.echo == ON) ? ECHO : 0; Xregister int cf = (flags.cbreak == ON) ? 0 : ICANON; Xregister int change = 0; X if((cur_term->Nttyb.c_lflag & ECHO) != ef){ X cur_term->Nttyb.c_lflag &= ~ECHO; X cur_term->Nttyb.c_lflag |= ef; X change++; X } X if((cur_term->Nttyb.c_lflag & ICANON) != cf){ X cur_term->Nttyb.c_lflag &= ~ICANON; X cur_term->Nttyb.c_lflag |= cf; X if (cur_term->Nttyb.c_lflag & ICANON) { X cur_term->Nttyb.c_cc[VEOF] = cur_term->Ottyb.c_cc[VEOF]; X cur_term->Nttyb.c_cc[VEOL] = cur_term->Ottyb.c_cc[VEOL]; X } else { X cur_term->Nttyb.c_cc[VTIME] = 1; X cur_term->Nttyb.c_cc[VMIN] = 1; X } X change++; X } X if(change){ X setctty(); X } X} X Xecho(n) Xregister n; X{ X X if(n == ON) X doecho(); X else X donoecho(); X} X Xdoecho() X{ X cur_term->Nttyb.c_lflag |= ECHO; X setctty(); X} X Xdonoecho() X{ X cur_term->Nttyb.c_lflag &= ~ECHO; X setctty(); X} X Xgetlin(bufp) Xregister char *bufp; X{ X register char *obufp = bufp; X register int c; X X flags.topl = 2; /* nonempty, no --More-- required */ X for(;;) { X (void) fflush(stdout); X if((c = getchar()) == EOF) { X *bufp = 0; X return; X } X if(c == '\b') { X if(bufp != obufp) { X bufp--; X putstr("\b \b"); /* putsym converts \b */ X } else beep(); X } else if(c == '\n') { X *bufp = 0; X return; X } else { X *bufp = c; X bufp[1] = 0; X putstr(bufp); X if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO) X bufp++; X } X } X} X Xgetret() { X xgetret(TRUE); X} X Xcgetret() { X xgetret(FALSE); X} X Xxgetret(spaceflag) Xboolean spaceflag; /* TRUE if space (return) required */ X{ X printf("\nHit %s to continue: ", X flags.cbreak ? "space" : "return"); X xwaitforspace(spaceflag); X} X Xchar morc; /* tell the outside world what char he used */ X Xxwaitforspace(spaceflag) Xboolean spaceflag; X{ Xregister int c; X X (void) fflush(stdout); X morc = 0; X X while((c = getchar()) != '\n') { X if(c == EOF) { X settty("End of input?\n"); X exit(0); X } X if(flags.cbreak) { X if(c == ' ') break; X if(!spaceflag && letter(c)) { X morc = c; X break; X } X } X } X} X Xchar * Xparse() X{ X static char inline[COLNO]; X register foo; X X flags.move = 1; X if(!Invis) curs(u.ux,u.uy+2); else home(); X (void) fflush(stdout); X while((foo = getchar()) >= '0' && foo <= '9') X multi += 10*multi+foo-'0'; X if(multi) { X multi--; X save_cm = inline; X } X inline[0] = foo; X inline[1] = 0; X if(foo == EOF) { X settty("End of input?\n"); X exit(0); X } X if(foo == 'f' || foo == 'F'){ X inline[1] = getchar(); X#ifdef QUEST X if(inline[1] == foo) inline[2] = getchar(); else X#endif QUEST X inline[2] = 0; X } X if(foo == 'm' || foo == 'M'){ X inline[1] = getchar(); X inline[2] = 0; X } X clrlin(); X return(inline); X} X Xchar Xreadchar() { X register int sym; X (void) fflush(stdout); X if((sym = getchar()) == EOF) { X settty("End of input?\n"); X exit(0); X } X if(flags.topl == 1) flags.topl = 2; X return((char) sym); X} !Funky!Stuff! echo x - mklev.c sed -e 's/^X//' > mklev.c << '!Funky!Stuff!' X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ X X#include X#include "mklev.h" X#include "def.trap.h" X Xextern void exit(), X free(), X qsort(); X Xextern char *getlogin(); Xextern struct monst *makemon(); X Xchar *tfile,*tspe,**args; Xchar nul[40]; X X#include "savelev.h" X X#ifdef WIZARD Xboolean wizard; X#endif WIZARD X Xlong lrand48(); X X#define somex() (int)((lrand48()%(croom->hx-croom->lx+1))+croom->lx) X#define somey() (int)((lrand48()%(croom->hy-croom->ly+1))+croom->ly) X Xstruct rm levl[COLNO][ROWNO]; Xstruct monst *fmon; Xstruct obj *fobj; Xstruct gen *fgold, *ftrap; X Xchar *fut_geno; /* monsters that should not be created anymore */ X Xstruct mkroom rooms[MAXNROFROOMS+1], *croom, *troom; Xcoord doors[DOORMAX]; Xint doorindex = 0; Xint comp(); X Xxchar dlevel; Xschar nxcor,xx,yy,dx,dy,tx,ty; /* for corridors and other things... */ Xboolean goldseen; Xint nroom; X Xxchar xdnstair,xupstair,ydnstair,yupstair; X X Xmain(argc,argv) Xchar *argv[]; X{ X register unsigned tryct; X X if(argc < 6) panic("Too few arguments!!"); X args = argv; X tfile = argv[1]; X tspe = argv[2]; X dlevel = atoi(argv[3]); X if(dlevel < 1) panic("Bad level"); X fut_geno = argv[4]; X#ifdef WIZARD X wizard = (argv[5][0] == 'w'); X#endif WIZARD X (void) setrand(0L); X init_objects(); X rooms[0].hx = -1; /* in case we are in a maze */ X X /* a: normal; b: maze */ X if(*tspe == 'b') { X makemaz(); X savelev(); X exit(0); X } X X /* construct the rooms */ X while(nroom < (MAXNROFROOMS/3)) { X croom = rooms; X nroom = 0; X (void) makerooms(0); /* not secret */ X } X X /* for each room: put things inside */ X for(croom = rooms; croom->hx > 0; croom++) { X X /* put a sleeping monster inside */ X if(!rn2(3)) (void) X makemon((struct permonst *) 0, somex(), somey()); X X /* put traps and mimics inside */ X goldseen = FALSE; X while(!rn2(8-(dlevel/6))) mktrap(0,0); X if(!goldseen && !rn2(3)) mkgold(0,somex(),somey()); X if(!rn2(3)) { X mkobj_at(0, somex(), somey()); X tryct = 0; X while(!rn2(5)) { X if(++tryct > 100){ X printf("tryct overflow4\n"); X break; X } X mkobj_at(0, somex(), somey()); X } X } X } X tryct = 0; X do { X if(++tryct > 1000) panic("Cannot make dnstairs\n"); X croom = &rooms[rn2(nroom)]; X xdnstair = somex(); X ydnstair = somey(); X } while((*tspe =='n' && (!(xdnstair%2) || !(ydnstair%2))) || X g_at(xdnstair,ydnstair,ftrap)); X levl[xdnstair][ydnstair].scrsym ='>'; X levl[xdnstair][ydnstair].typ = STAIRS; X troom = croom; X do { X if(++tryct > 2000) panic("Cannot make upstairs\n"); X croom = &rooms[rn2(nroom)]; X xupstair = somex(); X yupstair = somey(); X } while(croom == troom || m_at(xupstair,yupstair) || X g_at(xupstair,yupstair,ftrap)); X levl[xupstair][yupstair].scrsym ='<'; X levl[xupstair][yupstair].typ = STAIRS; X X qsort((char *) rooms, (unsigned) nroom, X sizeof(struct mkroom), comp); X X croom = rooms; X troom = croom+1; X nxcor = 0; X mkpos(); X do makecor(); X while (croom->hx > 0 && troom->hx > 0); X X /* make a secret treasure vault, not connected to the rest */ X if(nroom < (2*MAXNROFROOMS/3)) if(!rn2(3)) { X register int x,y; X troom = croom = &rooms[nroom]; X if(makerooms(1)) { /* make secret room */ X troom->rtype = 6; /* treasure vault */ X for(x = troom->lx; x <= troom->hx; x++) X for(y = troom->ly; y <= troom->hy; y++) X mkgold(rnd(dlevel*100) + 50, x, y); X } X } X X#ifdef WIZARD X if(wizard){ X if(rn2(3)) mkshop(); else mkzoo(); X } else X#endif WIZARD X if(dlevel > 1 && dlevel < 20 && rn2(dlevel) < 2) mkshop(); X else X if(dlevel > 6 && (!rn2(7) || !strcmp("david", getlogin()))) X mkzoo(); X savelev(); X exit(0); X} X Xmakerooms(secret) int secret; { Xregister int lowx, lowy; Xregister int tryct = 0; X while(nroom < (MAXNROFROOMS/2) || secret) X for(lowy = rn1(3,3); lowy < ROWNO-7; lowy += rn1(2,4)) { X for(lowx = rn1(3,4); lowx < COLNO-10; lowx += rn1(2,7)) { X if(tryct++ > 10000) return(0); X if((lowy += (rn2(5)-2)) < 3) lowy = 3; X else if(lowy > ROWNO-6) lowy = ROWNO-6; X if(levl[lowx][lowy].typ) continue; X if((secret && maker(lowx, 1, lowy, 1)) || X (!secret && maker(lowx,rn1(9,2),lowy,rn1(4,2)) X && nroom+2 > MAXNROFROOMS)) return(1); X } X } X return(1); X} X Xcomp(x,y) Xregister struct mkroom *x,*y; X{ X if(x->lx < y->lx) return(-1); X return(x->lx > y->lx); X} X Xcoord Xfinddpos(xl,yl,xh,yh) { Xcoord ff; Xregister x,y; X ff.x = (xl == xh) ? xl : (xl + rn2(xh-xl+1)); X ff.y = (yl == yh) ? yl : (yl + rn2(yh-yl+1)); X if(okdoor(ff.x, ff.y)) return(ff); X if(xl < xh) for(x = xl; x <= xh; x++) X if(okdoor(x, ff.y)){ X ff.x = x; X return(ff); X } X if(yl < yh) for(y = yl; y <= yh; y++) X if(okdoor(ff.x, y)){ X ff.y = y; X return(ff); X } X return(ff); X} X X/* when croom and troom exist, find position for a door in croom X and direction for a corridor towards position [tx,ty] in the wall X of troom */ Xmkpos() X{ Xcoord cc,tt; X if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return; X if(troom->lx > croom->hx) { X dx = 1; X dy = 0; X xx = croom->hx+1; X tx = troom->lx-1; X cc = finddpos(xx,croom->ly,xx,croom->hy); X tt = finddpos(tx,troom->ly,tx,troom->hy); X } else if(troom->hy < croom->ly) { X dy = -1; X dx = 0; X yy = croom->ly-1; X cc = finddpos(croom->lx,yy,croom->hx,yy); X ty = troom->hy+1; X tt = finddpos(troom->lx,ty,troom->hx,ty); X } else if(troom->hx < croom->lx) { X dx = -1; X dy = 0; X xx = croom->lx-1; X tx = troom->hx+1; X cc = finddpos(xx,croom->ly,xx,croom->hy); X tt = finddpos(tx,troom->ly,tx,troom->hy); X } else { X dy = 1; X dx = 0; X yy = croom->hy+1; X ty = troom->ly-1; X cc = finddpos(croom->lx,yy,croom->hx,yy); X tt = finddpos(troom->lx,ty,troom->hx,ty); X } X xx = cc.x; X yy = cc.y; X tx = tt.x; X ty = tt.y; X if(levl[xx+dx][yy+dy].typ) { X if(nxcor) newloc(); X else { X dodoor(xx,yy,croom); X xx += dx; X yy += dy; X } X return; X } X dodoor(xx,yy,croom); X} X X/* if allowable, create a door at [x,y] */ Xokdoor(x,y) Xregister x,y; X{ X if(levl[x-1][y].typ == DOOR || levl[x+1][y].typ == DOOR || X levl[x][y+1].typ == DOOR || levl[x][y-1].typ == DOOR || X levl[x-1][y].typ == SDOOR || levl[x+1][y].typ == SDOOR || X levl[x][y-1].typ == SDOOR || levl[x][y+1].typ == SDOOR || X (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) || X doorindex >= DOORMAX) X return(0); X return(1); X} X Xdodoor(x,y,aroom) Xregister x,y; Xregister struct mkroom *aroom; X{ X register struct mkroom *broom; X register tmp; X if(doorindex >= DOORMAX) panic("DOORMAX exceeded?"); X if(!okdoor(x,y) && nxcor) return; X if(!rn2(8)) levl[x][y].typ = SDOOR; X else { X levl[x][y].scrsym ='+'; X levl[x][y].typ = DOOR; X } X aroom->doorct++; X broom = aroom+1; X if(broom->hx < 0) tmp = doorindex; else X for(tmp = doorindex; tmp > broom->fdoor; tmp--) X doors[tmp] = doors[tmp-1]; X doorindex++; X doors[tmp].x = x; X doors[tmp].y = y; X for( ; broom->hx >= 0; broom++) broom->fdoor++; X} X Xnewloc() X{ X register a,b; X register int tryct = 0; X X ++croom; X ++troom; X if(nxcor || croom->hx < 0 || troom->hx < 0) { X if(nxcor++ > rn1(nroom,4)) { X croom = &rooms[nroom]; X return; X } X do { X if(++tryct > 100){ X printf("tryct overflow5\n"); X croom = &rooms[nroom]; X return; X } X a = rn2(nroom); X b = rn2(nroom); X croom = &rooms[a]; X troom = &rooms[b]; X } while(croom == troom || (troom == croom+1 && !rn2(3))); X } X mkpos(); X} X X/* make a trap somewhere (in croom if mazeflag = 0) */ Xmktrap(num,mazeflag) Xregister num,mazeflag; X{ X register struct gen *gtmp; X register int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0; X register xchar mx,my; X X if(!num || num >= TRAPNUM) { X nopierc = (dlevel < 4) ? 1 : 0; X nomimic = (dlevel < 9 || goldseen ) ? 1 : 0; X if(index(fut_geno, 'M')) nomimic = 1; X kind = rn2(TRAPNUM - nopierc - nomimic); X /* note: PIERC = 7, MIMIC = 8, TRAPNUM = 9 */ X } else kind = num; X X if(kind == MIMIC) { X register struct monst *mtmp; X X fakedoor = (!rn2(3) && !mazeflag); X fakegold = (!fakedoor && !rn2(2)); X if(fakegold) goldseen = TRUE; X do { X if(++tryct > 200) return; X if(fakedoor) { X /* note: fakedoor maybe on actual door */ X if(rn2(2)){ X if(rn2(2)) X mx = croom->hx+1; X else mx = croom->lx-1; X my = somey(); X } else { X if(rn2(2)) X my = croom->hy+1; X else my = croom->ly-1; X mx = somex(); X } X } else if(mazeflag) { X extern coord mazexy(); X coord mm; X mm = mazexy(); X mx = mm.x; X my = mm.y; X } else { X mx = somex(); X my = somey(); X } X } while(m_at(mx,my)); X if(mtmp = makemon(PM_MIMIC,mx,my)) X mtmp->mimic = X fakegold ? '$' : fakedoor ? '+' : X (mazeflag && rn2(2)) ? AMULET_SYM : X "=/)%?![<>" [ rn2(9) ]; X return; X } X gtmp = newgen(); X gtmp->gflag = kind; X do { X if(++tryct > 200){ X printf("tryct overflow7\n"); X free((char *) gtmp); X return; X } X if(mazeflag){ X extern coord mazexy(); X coord mm; X mm = mazexy(); X gtmp->gx = mm.x; X gtmp->gy = mm.y; X } else { X gtmp->gx = somex(); X gtmp->gy = somey(); X } X } while(g_at(gtmp->gx, gtmp->gy, ftrap)); X gtmp->ngen = ftrap; X ftrap = gtmp; X if(mazeflag && !rn2(10) && gtmp->gflag < PIERC) gtmp->gflag |= SEEN; X} X X/*VARARGS1*/ Xpanic(str,arg1,arg2,arg3) Xchar *str,*arg1,*arg2,*arg3; X{ X char bufr[BUFSZ]; X extern int sprintf(); X (void) sprintf(bufr,str,arg1,arg2,arg3); X (void) write(1,"\nMKLEV ERROR: ",15); X puts(bufr); X (void) fflush(stdout); X exit(1); X} X Xmaker(lowx,ddx,lowy,ddy) Xschar lowx,ddx,lowy,ddy; X{ X register x, y, hix = lowx+ddx, hiy = lowy+ddy; X X if(nroom >= MAXNROFROOMS) return(0); X if(hix > COLNO-5) hix = COLNO-5; X if(hiy > ROWNO-4) hiy = ROWNO-4; Xchk: X if(hix <= lowx || hiy <= lowy) return(0); X X /* check area around room (and make room smaller if necessary) */ X for(x = lowx-4; x <= hix+4; x++) X for(y = lowy-3; y <= hiy+3; y++) X if(levl[x][y].typ) { X if(rn2(3)) return(0); X lowx = x+5; X lowy = y+4; X goto chk; X } X X /* on low levels the room is lit (usually) */ X /* secret vaults are always lit */ X if((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1)) X for(x = lowx-1; x <= hix+1; x++) X for(y = lowy-1; y <= hiy+1; y++) X levl[x][y].lit = 1; X croom->lx = lowx; X croom->hx = hix; X croom->ly = lowy; X croom->hy = hiy; X croom->rtype = croom->doorct = croom->fdoor = 0; X for(x = lowx-1; x <= hix+1; x++) X for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) { X levl[x][y].scrsym = '-'; X levl[x][y].typ = HWALL; X } X for(x = lowx-1; x <= hix+1; x += (hix-lowx+2)) X for(y = lowy; y <= hiy; y++) { X levl[x][y].scrsym = '|'; X levl[x][y].typ = VWALL; X } X for(x = lowx; x <= hix; x++) X for(y = lowy; y <= hiy; y++) { X levl[x][y].scrsym = '.'; X levl[x][y].typ = ROOM; X } X croom++; X croom->hx = -1; X nroom++; X return(1); X} X Xmakecor() { X register nx, ny; X register struct rm *crm; X register dix, diy, secondtry = 0; X Xtryagain: X nx = xx + dx; X ny = yy + dy; X X if(nxcor && !rn2(35)) { X newloc(); X return; X } X if(nx == COLNO-1 || nx == 0 || ny == 0 || ny == ROWNO-1) { X if(nxcor) { X newloc(); X return; X } else { X printf("something went wrong. we try again...\n"); X execl("./mklev",args[0],tfile,tspe,args[3],args[4],args[5],0); X panic("cannot execute ./mklev\n"); X } X } X X dix = abs(nx-tx); X diy = abs(ny-ty); X if(dy && dix > diy) { X dy = 0; X dx = (nx > tx) ? -1 : 1; X } else if(dx && diy > dix) { X dx = 0; X dy = (ny > ty) ? -1 : 1; X } X X crm = &levl[nx][ny]; X if(!(crm->typ)) { X if(rn2(100)) { X crm->typ = CORR; X crm->scrsym = CORR_SYM; X } else { X crm->typ = SCORR; X crm->scrsym = ' '; X } X xx = nx; X yy = ny; X if(nxcor && !rn2(50)) { X mkobj_at(ROCK_SYM, nx, ny); X } X return; X } X if(crm->typ == CORR || crm->typ == SCORR) { X xx = nx; X yy = ny; X return; X } X if(nx == tx && ny == ty) { X dodoor(nx,ny,troom); X newloc(); X return; X } X if(!secondtry++ && (nx != xx+dx || ny != yy+dy)) X goto tryagain; X if(dx) { X if(ty < ny) dy = -1; X else dy = levl[nx+dx][ny-1].typ == ROOM?1:-1; X dx = 0; X } else { X if(tx < nx) dx = -1; X else dx = levl[nx-1][ny+dy].typ == ROOM?1:-1; X dy = 0; X } X} X Xstruct monst * Xm_at(x,y) Xregister x,y; X{ X register struct monst *mtmp; X X for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) X if(mtmp->mx == x && mtmp->my == y) return(mtmp); X return(0); X} X Xstruct gen * Xg_at(x,y,ptr) Xregister x,y; Xregister struct gen *ptr; X{ X while(ptr) { X if(ptr->gx == x && ptr->gy == y) return(ptr); X ptr = ptr->ngen; X } X return(0); X} !Funky!Stuff! echo x - mklev.h sed -e 's/^X//' > mklev.h << '!Funky!Stuff!' X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ X X#include "config.h" X X#ifdef BSD X#include /* declarations for strcat etc. */ X#else X#include /* idem on System V */ X#define index strchr X#define rindex strrchr X#endif BSD X X#include "def.objclass.h" X Xtypedef struct { X xchar x,y; X} coord; X X#include "def.monst.h" /* uses coord */ X#include "def.gen.h" X#include "def.obj.h" X Xextern int sprintf(); X X#define BUFSZ 256 /* for getlin buffers */ X#define PL_NSIZ 32 /* name of player, ghost, shopkeeper */ X X#define HWALL 1 /* Level location types */ X#define VWALL 2 X#define SDOOR 3 X#define SCORR 4 X#define LDOOR 5 X#define DOOR 6 /* smallest accessible type */ X#define CORR 7 X#define ROOM 8 X#define STAIRS 9 X#ifdef QUEST X#define CORR_SYM ':' X#else X#define CORR_SYM '#' X#endif QUEST X X#define ERRCHAR '{' X X#define TRAPNUM 9 X Xstruct rm { X char scrsym; X unsigned typ:5; X unsigned new:1; X unsigned seen:1; X unsigned lit:1; X}; Xextern struct rm levl[COLNO][ROWNO]; X X#ifndef QUEST Xstruct mkroom { X xchar lx,hx,ly,hy; X schar rtype,rlit,doorct,fdoor; X}; X#define MAXNROFROOMS 15 Xextern struct mkroom rooms[MAXNROFROOMS+1]; X#define DOORMAX 100 Xextern coord doors[DOORMAX]; X#endif QUEST X X X#include "def.permonst.h" Xextern struct permonst mons[]; X#define PM_ACIDBLOB &mons[7] X#define PM_PIERC &mons[17] X#define PM_MIMIC &mons[37] X#define PM_CHAM &mons[47] X#define PM_DEMON &mons[54] X#define PM_MINOTAUR &mons[55] /* last in mons array */ X#define PM_SHK &mons[56] /* very last */ X#define CMNUM 55 /* number of common monsters */ X Xextern long *alloc(); X Xextern xchar xdnstair, ydnstair, xupstair, yupstair; /* stairs up and down. */ X Xextern xchar dlevel; X#ifdef WIZARD Xextern boolean wizard; X#endif WIZARD X#define newstring(x) (char *) alloc((unsigned)(x)) !Funky!Stuff! echo x - rnd.c sed -e 's/^X//' > rnd.c << '!Funky!Stuff!' X#include X#define RND(x) ((lrand48()>>3) % x) Xlong lrand48(); X Xsetrand(arg) Xlong arg; X{ X time_t time(); X void srand48(); X X if (arg) { X srand48(arg); X } else { X srand48(time(0)); X } X} X Xrn1(x,y) Xregister x,y; X{ X return(RND(x)+y); X} X Xrn2(x) Xregister x; X{ X return(RND(x)); X} X Xrnd(x) Xregister x; X{ X return(RND(x)+1); X} X Xd(n,x) Xregister n,x; X{ X register tmp = n; X X while(n--) tmp += RND(x); X return(tmp); X} !Funky!Stuff! echo x - savelev.h sed -e 's/^X//' > savelev.h << '!Funky!Stuff!' X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ X X#ifdef MKLEV X Xsavelev(){ X int fd; X X#else Xextern struct obj *billobjs; X Xsavelev(fd){ X#ifndef NOWORM X register struct wseg *wtmp, *wtmp2; X register tmp; X#endif NOWORM X X#endif MKLEV X X#ifdef MKLEV X if((fd = creat(tfile,FMASK)) < 0) panic("Cannot create %s\n", tfile); X#else X if(fd < 0) panic("Save on bad file!"); X#endif MKLEV X bwrite(fd,(char *) levl,sizeof(levl)); X#ifdef MKLEV X bwrite(fd,(char *) nul,sizeof(long)); X#else X bwrite(fd,(char *) &moves,sizeof(long)); X#endif MKLEV X bwrite(fd,(char *) &xupstair,sizeof(xupstair)); X bwrite(fd,(char *) &yupstair,sizeof(yupstair)); X bwrite(fd,(char *) &xdnstair,sizeof(xdnstair)); X bwrite(fd,(char *) &ydnstair,sizeof(ydnstair)); X savemonchn(fd, fmon); X savegenchn(fd, fgold); X savegenchn(fd, ftrap); X saveobjchn(fd, fobj); X#ifdef MKLEV X saveobjchn(fd, (struct obj *) 0); X bwrite(fd,(char *) nul, sizeof(unsigned)); X#else X saveobjchn(fd, billobjs); X billobjs = 0; X save_engravings(fd); X#endif MKLEV X#ifndef QUEST X bwrite(fd,(char *) rooms,sizeof(rooms)); X bwrite(fd,(char *) doors,sizeof(doors)); X#endif QUEST X fgold = ftrap = 0; X fmon = 0; X fobj = 0; X#ifndef MKLEV X/*--------------------------------------------------------------------*/ X#ifndef NOWORM X bwrite(fd,(char *) wsegs,sizeof(wsegs)); X for(tmp=1; tmp<32; tmp++){ X for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2){ X wtmp2 = wtmp->nseg; X bwrite(fd,(char *) wtmp,sizeof(struct wseg)); X } X wsegs[tmp] = 0; X } X bwrite(fd,(char *) wgrowtime,sizeof(wgrowtime)); X#endif NOWORM X/*--------------------------------------------------------------------*/ X#endif MKLEV X} X Xbwrite(fd,loc,num) Xregister fd; Xregister char *loc; Xregister unsigned num; X{ X if(write(fd, loc, num) != num) X panic("cannot write %d bytes to file #%d",num,fd); X} X Xsaveobjchn(fd,otmp) Xregister fd; Xregister struct obj *otmp; X{ X register struct obj *otmp2; X unsigned xl; X int minusone = -1; X X while(otmp) { X otmp2 = otmp->nobj; X xl = otmp->onamelth; X bwrite(fd, (char *) &xl, sizeof(int)); X bwrite(fd, (char *) otmp, xl + sizeof(struct obj)); X free((char *) otmp); X otmp = otmp2; X } X bwrite(fd, (char *) &minusone, sizeof(int)); X} X Xsavemonchn(fd,mtmp) Xregister fd; Xregister struct monst *mtmp; X{ X register struct monst *mtmp2; X unsigned xl; X int minusone = -1; X struct permonst *monbegin = &mons[0]; X X bwrite(fd, (char *) &monbegin, sizeof(monbegin)); X X while(mtmp) { X mtmp2 = mtmp->nmon; X xl = mtmp->mxlth + mtmp->mnamelth; X bwrite(fd, (char *) &xl, sizeof(int)); X bwrite(fd, (char *) mtmp, xl + sizeof(struct monst)); X if(mtmp->minvent) saveobjchn(fd,mtmp->minvent); X free((char *) mtmp); X mtmp = mtmp2; X } X bwrite(fd, (char *) &minusone, sizeof(int)); X} X Xsavegenchn(fd,gtmp) Xregister fd; Xregister struct gen *gtmp; X{ X register struct gen *gtmp2; X while(gtmp) { X gtmp2 = gtmp->ngen; X bwrite(fd, (char *) gtmp, sizeof(struct gen)); X free((char *) gtmp); X gtmp = gtmp2; X } X bwrite(fd, nul, sizeof(struct gen)); X} !Funky!Stuff! exit -- Gordon A. Moffett ...!{ihnp4,hplabs,sun}!amdahl!gam "Her name was McGill, and she called herself Lil, but everyone knew her as Nancy...."