games@tekred.TEK.COM (10/29/88)
Submitted by: Mike Cuddy <cuddy@convex.uucp>
Comp.sources.games: Volume 5, Issue 80
Archive-name: xwanderer/Part02
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 5)."
# Contents: Makefile display.c gamedev.c helpscr.c jump.c m.c scores.c
# wanderer.help
# Wrapped by billr@saab on Fri Oct 28 16:31:11 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(4271 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#!/bin/make -f
X# Makefile for wanderer - modified by Bill Randle 6/30/88
X# completely re-written by Mike Cuddy (ihnp4!convex!cuddy) 7-22-88
X#
X# GOALS: the programs you want to make
X#
XGOALS = wanderer xwanderer dev xdev erase
X#GOALS = xwanderer
X#
X# HEADERS: the header files
X#
XHEADERS= wand_head.h
X#
X# CUR_OBJS: the object files for the curses based wanderer
X# XWIN_OBJS: object files for the X based wanderer
X# DEV_OBJS: object files for the curses base dev. utility
X# COM_OBJS: object files common to the X based progams and the curses base ones
X# ERASE_OBJS: object files for the erase utility
X#
XCUR_OBJS = displayC.o fallC.o gameC.o iconC.o jumpC.o mC.o read.o scoresC.o \
X helpscrC.o
XXWIN_OBJS = displayX.o fallX.o gameX.o iconX.o jumpX.o mX.o read.o scoresX.o \
X helpscrX.o
XDEV_OBJS= displayC.o iconC.o gameD.o mD.o fallC.o devread.o helpscrC.o
XXDEV_OBJS= displayX.o iconX.o gameXD.o mXD.o fallX.o devread.o helpscrX.o
XCOM_OBJS= read.o
XERASE_OBJS= erase.o
XSRCS= devread.c display.c erase.c fall.c game.c gamedev.c helpscr.c \
X icon.c jump.c m.c pixmapdecl.h read.c scores.c wand_head.h
X#
X# all of the object files
X#
XALLOBJS = $(CUR_OBJS) $(XWIN_OBJS) $(DEV_OBJS) $(COM_OBJS) $(ERASE_OBJS)
X#
X# flags for the compiler
X#
XCFLAGS = -g
X#
X# libraries for an X based program
X#
XXLIBS= -lX11
X#
X# libraries for a curses based program
X#
XCLIBS = -lcurses -ltermcap
X#
X# quiet rm -- doesn't complain when files aren't there
X#
XRM=rm -f
X#
X# BINDIR: where to put the executables
X# SCREENPATH: where to put the screens (see wand_head.h also)
X#
XBINDIR=/mnt/cuddy/bin
XSCREENPATH= /mnt/cuddy/lib/wanderer
X
Xall: $(GOALS)
X @echo DONE
X
Xwanderer: $(CUR_OBJS) $(COM_OBJS)
X $(CC) $(CFLAGS) -o wanderer $(CUR_OBJS) $(COM_OBJS) $(CLIBS)
X
Xxwanderer: $(XWIN_OBJS) $(COM_OBJS)
X $(CC) $(CFLAGS) -o xwanderer $(XWIN_OBJS) $(COM_OBJS) $(XLIBS)
X
Xerase: $(ERASE_OBJS)
X $(CC) $(CFLAGS) -o erase $(ERASE_OBJS)
X
Xdev: $(DEV_OBJS)
X $(CC) $(CFLAGS) -o dev $(DEV_OBJS) $(CLIBS)
Xxdev: $(XDEV_OBJS)
X $(CC) $(CFLAGS) -o xdev $(XDEV_OBJS) $(XLIBS)
X
Xinstall: $(GOALS)
X cp $(GOALS) $(BINDIR)
X @mkdir $(SCREENPATH)
X cp screens/* $(SCREENPATH)
X cp wanderer.help $(SCREENPATH)
X
Xdclean:
X $(RM) $(DEV_OBJS) $(COM_OBJS)
Xxdclean:
X $(RM) $(XDEV_OBJS) $(COM_OBJS)
Xwclean:
X $(RM) $(CUR_OBJS) $(COM_OBJS)
Xxclean:
X $(RM) $(XWIN_OBJS) $(COM_OBJS)
X
Xtags: $(SRCS)
X ctags $(SRCS)
X
Xclean: dclean wclean xclean xdclean
X $(RM) core make.out lint.out tags .#*
X
Xclobber: clean
X $(RM) dev xdev wanderer xwanderer erase
X
X$(COM_OBJS): $(HEADERS)
X#
X# special multiple compile targets
X#
XdisplayC.o: display.c $(HEADERS)
X cc -c display.c $(CFLAGS) -UXWANDER
X @mv display.o displayC.o
XdisplayX.o: display.c $(HEADERS)
X cc -c display.c $(CFLAGS) -DXWANDER
X @mv display.o displayX.o
XfallC.o: fall.c $(HEADERS)
X cc -c fall.c $(CFLAGS) -UXWANDER
X @mv fall.o fallC.o
XfallX.o: fall.c $(HEADERS)
X cc -c fall.c $(CFLAGS) -DXWANDER
X @mv fall.o fallX.o
XgameC.o: game.c $(HEADERS)
X cc -c game.c $(CFLAGS) -UXWANDER
X @mv game.o gameC.o
XgameD.o: game.c $(HEADERS)
X cc -c game.c $(CFLAGS) -DGAMEDEV
X @mv game.o gameD.o
XgameXD.o: game.c $(HEADERS)
X cc -c game.c $(CFLAGS) -DGAMEDEV -DXWANDER
X @mv game.o gameXD.o
XgameX.o: game.c $(HEADERS)
X cc -c game.c $(CFLAGS) -DXWANDER
X @mv game.o gameX.o
XhelpscrX.o: helpscr.c $(HEADERS)
X cc -c helpscr.c $(CFLAGS) -DXWANDER
X @mv helpscr.o helpscrX.o
XhelpscrC.o: helpscr.c $(HEADERS)
X cc -c helpscr.c $(CFLAGS) -UXWANDER
X @mv helpscr.o helpscrC.o
XiconC.o: icon.c $(HEADERS)
X cc -c icon.c $(CFLAGS) -UXWANDER
X @mv icon.o iconC.o
XiconX.o: icon.c $(HEADERS)
X cc -c icon.c $(CFLAGS) -DXWANDER
X @mv icon.o iconX.o
XjumpC.o: jump.c $(HEADERS)
X cc -c jump.c $(CFLAGS) -UXWANDER
X @mv jump.o jumpC.o
XjumpX.o: jump.c $(HEADERS)
X cc -c jump.c $(CFLAGS) -DXWANDER
X @mv jump.o jumpX.o
XmC.o: m.c $(HEADERS)
X cc -c m.c $(CFLAGS) -UXWANDER
X @mv m.o mC.o
XmD.o: m.c $(HEADERS)
X cc -c m.c $(CFLAGS) -DGAMEDEV
X @mv m.o mD.o
XmXD.o: m.c $(HEADERS)
X cc -c m.c $(CFLAGS) -DGAMEDEV -DXWANDER
X @mv m.o mXD.o
XmX.o: m.c $(HEADERS)
X cc -c m.c $(CFLAGS) -DXWANDER
X @mv m.o mX.o
XscoresC.o: scores.c $(HEADERS)
X cc -c scores.c $(CFLAGS) -UXWANDER
X @mv scores.o scoresC.o
XscoresX.o: scores.c $(HEADERS)
X cc -c scores.c $(CFLAGS) -DXWANDER
X @mv scores.o scoresX.o
X
END_OF_FILE
if test 4271 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'display.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'display.c'\"
else
echo shar: Extracting \"'display.c'\" \(3917 characters\)
sed "s/^X//" >'display.c' <<'END_OF_FILE'
X#include "wand_head.h"
X
X#ifdef XWANDER
Xextern GC linegc;
Xextern int do_repaint;
X#endif
X
Xvoid map(row_ptr)
Xchar (*row_ptr)[ROWLEN+1];
X{
Xint x,y;
Xchar ch;
X#ifdef XWANDER
X drawmap(row_ptr,1);
X#else
Xmove(0,0);
Xaddch('+');
Xfor(x = 0;x < ROWLEN; x++)
X addch('-');
Xaddch('+');
Xfor(y = 0;y < NOOFROWS; y++)
X {
X move(y+1,0);
X addch('|');
X for(x = 0; x<= ROWLEN; x++)
X {
X ch = (*row_ptr)[x];
X if((ch == 'M')||(ch == 'S'))
X ch = ' ';
X addch(ch);
X }
X addch('|');
X row_ptr++;
X }
Xmove(y+1,0);
Xaddch('+');
Xfor(x = 0;x < ROWLEN; x++)
X addch('-');
Xaddch('+');
Xmove(18,0);
Xaddstr("Press any key to return to the game.");
Xrefresh();
X#endif
X#ifdef XWANDER
Xmessage(0,"Press any key to return to the game.");
Xdo_repaint = 1;
X#endif
X(void) getchar();
X#ifndef XWANDER
Xmove(18,0);
Xaddstr(" ");
Xrefresh();
Xfor(y=0;y<=(NOOFROWS+1);y++)
X {
X move(y,0);
X for(x=0;x<=(ROWLEN+2);x++)
X addch(' ');
X }
X
X#else
X erase_message(0);
X /* clear out the small map */
X XClearArea(dpy, win, 5, 5, ICON_WIDE * 11, ICON_HIGH * 7, 0);
X#endif
X}
X
X#ifdef XWANDER
Xdrawmap(row_ptr, er)
Xchar (*row_ptr)[ROWLEN+1];
X{
Xint x,y;
Xchar ch;
X
X if (er) {
X /* erase the magnified map */
X XClearArea(dpy, win, 5, 5, ICON_WIDE * 11, ICON_HIGH * 7, 0);
X }
X for (x= -1; x <= ROWLEN+1; x++)
X paint_small_square(x ,-1, '=');
X
X for(y = 0;y < NOOFROWS; y++)
X {
X paint_small_square((-1), y,'=');
X for(x = 0; x<= ROWLEN; x++)
X {
X ch = (*row_ptr)[x];
X if((ch == 'M')||(ch == 'S'))
X ch = ' ';
X paint_small_square(x,y,ch);
X }
X paint_small_square(x,y,'=');
X row_ptr++;
X }
X for (x= -1; x <= ROWLEN+1; x++)
X paint_small_square(x, y, '=');
X do_repaint = 1;
X XDrawLine(dpy,win,linegc,2,2,2,ICON_HIGH*7+6);
X XDrawLine(dpy,win,linegc,2,ICON_HIGH*7+6,ICON_WIDE*11+6,ICON_HIGH*7+6);
X XDrawLine(dpy,win,linegc,ICON_WIDE*11+6,ICON_HIGH*7+6,ICON_WIDE*11+6,2);
X XDrawLine(dpy,win,linegc,ICON_WIDE*11+6,2,2,2);
X}
X#endif
X
Xvoid display(cx,cy,row_ptr,score)
Xchar (*row_ptr)[ROWLEN+1];
Xint cx,cy,score;
X{
X int x,y = 0,
X x_coord,y_coord;
X char ch;
X while(y<(cy-3))
X {
X y++;
X row_ptr++;
X };
X#ifndef XWANDER
X move(0,0);
X addstr("+---------------------------------+");
X move(15,0);
X addstr("+---------------------------------+");
X#else
X XDrawLine(dpy,win,linegc,2,2,2,ICON_HIGH*7+6);
X XDrawLine(dpy,win,linegc,2,ICON_HIGH*7+6,ICON_WIDE*11+6,ICON_HIGH*7+6);
X XDrawLine(dpy,win,linegc,ICON_WIDE*11+6,ICON_HIGH*7+6,ICON_WIDE*11+6,2);
X XDrawLine(dpy,win,linegc,ICON_WIDE*11+6,2,2,2);
X#endif
X for(y=(cy-3);y<=(cy+3);y++)
X {
X#ifndef XWANDER
X y_coord = (y+3-cy)*2;
X if ((y<0) || (y>=NOOFROWS))
X {
X move(y_coord+1,0);
X addstr("|#################################|");
X move(y_coord+2,0);
X addstr("|#################################|");
X#else
X y_coord = (y+3-cy);
X if ((y<0) || (y>=NOOFROWS))
X {
X for (x = cx-5; x <= (cx+5); x++) {
X x_coord = (x+5-cx);
X draw_symbol(x_coord,y_coord,'#');
X }
X#endif
X }
X else
X {
X#ifndef XWANDER
X move(y_coord+1,0);
X addch('|');
X move(y_coord+1,34);
X addch('|');
X move(y_coord+2,0);
X addch('|');
X move(y_coord+2,34);
X addch('|');
X#endif
X for(x=(cx-5);x<=(cx+5);x++)
X {
X#ifndef XWANDER
X x_coord = (x+5-cx)*3;
X#else
X x_coord = (x+5-cx);
X#endif
X if ((x<0) || (x>ROWLEN-1))
X draw_symbol(x_coord,y_coord,'#');
X else
X {
X ch = (*row_ptr)[x];
X draw_symbol(x_coord,y_coord,ch);
X }
X };
X row_ptr++;
X } /* end if */
X } /* end y loop */
X#ifndef XWANDER
X move(16,0);
X refresh();
X#endif
X}
END_OF_FILE
if test 3917 -ne `wc -c <'display.c'`; then
echo shar: \"'display.c'\" unpacked with wrong size!
fi
# end of 'display.c'
fi
if test -f 'gamedev.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'gamedev.c'\"
else
echo shar: Extracting \"'gamedev.c'\" \(14429 characters\)
sed "s/^X//" >'gamedev.c' <<'END_OF_FILE'
X#include "wand_head.h"
X
X#define viable(x,y) ((screen[y][x] == ' ') || (screen[y][x] == ':') ||\
X (screen[y][x] == '@') || (screen[y][x] == '+')) && (y >= 0) &&\
X (x >= 0) && (y < NOOFROWS) && (x < ROWLEN)
X
Xtypedef struct mon_rec
X {
X int x,y,mx,my;
X char under;
X struct mon_rec *next;
X };
X
Xtypedef struct { int d[2] } direction;
X
Xextern void draw_symbol();
X
Xextern void display();
X
Xextern int fall();
X
Xextern void map();
X
X/* Add a spirit to the chain */
X
Xstruct mon_rec *make_monster(x,y)
Xint x,y;
X{
Xstruct mon_rec *malloc(),
X *monster;
Xif((monster = malloc(sizeof(struct mon_rec))) == NULL)
X return NULL;
Xmonster->x = x;
Xmonster->y = y;
Xmonster->mx = 1; /* always start moving RIGHT. (fix later) */
Xmonster->my = 0;
Xmonster->under = ' ';
Xmonster->next = NULL;
Xreturn monster;
X}
X
X/* 'follow lefthand wall' algorithm for sprites */
X
Xdirection new_direction(screen,x,y,bx,by)
Xint x,y,bx,by;
Xchar screen[NOOFROWS][ROWLEN+1];
X{
Xdirection out;
Xif(viable((x+by),(y-bx)))
X {
X out.d[0] = by;
X out.d[1] = -bx;
X return out;
X }
Xif(viable((x+bx),(y+by)))
X {
X out.d[0] = bx;
X out.d[1] = by;
X return out;
X }
Xif(viable((x-by),(y+bx)))
X {
X out.d[0] = -by;
X out.d[1] = bx;
X return out;
X }
Xif(viable((x-bx),(y-by)))
X {
X out.d[0] = -bx;
X out.d[1] = -by;
X return out;
X }
Xout.d[0] = -bx;
Xout.d[1] = -by;
Xreturn out;
X}
X
X/* Actual game function - Calls fall() to move
X boulders and arrows recursively */
X
Xchar *playscreen(screen,score,bell,maxmoves,keys)
Xint maxmoves,
X *bell,
X *score;
Xchar screen[NOOFROWS][ROWLEN+1],
X keys[6];
X{
Xint x,y,nx,ny,deadyet =0,
X sx = -1,sy = -1,tx = -1,ty = -1,lx = 0,ly = 0,mx = -1,my = -1,
X bx, by, nbx, nby,
X newnum, num = 1,
X diamonds = 0, nf = 0,hd ,vd ,xdirection,ydirection;
Xchar (*frow)[ROWLEN+1] = screen,
X ch,
X buffer[25],
X howdead[25];
Xdirection new_disp;
Xstruct mon_rec *monster,*mon_ptr, *current;
X
Xmon_ptr = NULL;
X
Xfor(x=0;x<=ROWLEN;x++)
X for(y=0;y<NOOFROWS;y++)
X {
X if((screen[y][x] == '*')||(screen[y][x] == '+'))
X diamonds++;
X if(screen[y][x] == 'A') /* note teleport arrival point & */
X { /* replace with space */
X tx = x;
X ty = y;
X screen[y][x] = ' ';
X }
X if(screen[y][x] == '@')
X {
X sx = x;
X sy = y;
X }
X if(screen[y][x] == 'M') /* Put megamonster in */
X {
X mx = x;
X my = y;
X }
X if(screen[y][x] == 'S') /* link small monster to pointer chain */
X {
X if((monster = make_monster(x,y)) == NULL)
X {
X strcpy(howdead,"running out of memory");
X return howdead;
X }
X if(mon_ptr == NULL)
X current = mon_ptr = monster;
X else
X current = current->next = monster;
X }
X if(screen[y][x] == '-')
X screen[y][x] = ' ';
X };
Xx=sx;
Xy=sy;
Xif((x == -1)&&(y == -1)) /* no start position in file ? */
X {
X strcpy(howdead,"no start position!");
X return(howdead);
X }
Xmove(0,48);
X(void) addstr("Score\t Diamonds");
Xmove(1,48);
X(void) addstr("\tFound\tTotal");
Xmove(3,48);
X(void) sprintf(buffer,"%d\t %d\t %d ",*score,nf,diamonds);
X(void) addstr(buffer);
Xmove(6,48);
X(void) sprintf(buffer,"Current screen %d",num);
X(void) addstr(buffer);
Xif(maxmoves != 0)
X(void) sprintf(buffer,"Moves remaining = %d ",maxmoves);
Xelse
X{
X (void) strcpy(buffer," Unlimited moves ");
X maxmoves = -1;
X};
Xmove(15,48);
X(void) addstr(buffer);
Xif(mx != -1) /* tell player if monster exists */
X draw_symbol(48,10,'M');
Xelse
X draw_symbol(48,10,' ');
X
Xdisplay(sx,sy,frow,*score);
X
X/* ACTUAL GAME FUNCTION - Returns method of death in string */
X
Xwhile(deadyet == 0)
X{
Xch = getchar();
X
Xnx=x;
Xny=y;
X
Xif(ch == keys[3])
X nx++;
Xif(ch == keys[2])
X nx--;
Xif((ch == keys[1]) && (y<(NOOFROWS-1)))
X ny++;
Xif(ch == keys[0])
X ny--;
Xif(ch == '1')
X {
X move(10,45);
X *bell = 1;
X (void) addstr("Bell ON ");
X printf("\007");
X move(16,0);
X refresh();
X }
Xif(ch == '0')
X {
X *bell = 0;
X move(10,45);
X (void) addstr("Bell OFF");
X move(16,0);
X refresh();
X }
Xif(ch == '~') /* level jump */
X {
X strcpy(howdead,"~~");
X return howdead;
X }
Xif(ch == '!')
X {
X map(frow);
X display(sx,sy,frow,*score);
X }
Xif(ch == 'q')
X {
X strcpy(howdead,"quitting the game");
X return howdead;
X }
X
Xif(screen[ny][nx] == 'C')
X {
X screen[ny][nx] = ':';
X *score+=4;
X if (*bell)
X printf("\007");
X if(maxmoves != -1)
X maxmoves+=250;
X }
Xswitch(screen[ny][nx])
X {
X case '@': break;
X case '*': *score+=9;
X if (*bell)
X printf("\007");
X nf++;
X case ':': *score+=1;
X move(3,48);
X sprintf(buffer,"%d\t %d",*score,nf);
X (void) addstr(buffer);
X case ' ':
X screen[y][x] = ' ';
X screen[ny][nx] = '@';
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X draw_symbol((nx-sx+5)*3,(ny-sy+3)*2,'@');
X if(deadyet ==0)
X deadyet = fall(&mx,&my,x,y,sx,sy,screen,howdead);
X if((deadyet ==0) && (nx != (x+1)))
X deadyet = fall(&mx,&my,x+1,y,sx,sy,screen,howdead);
X if((deadyet ==0) && (nx != (x-1)))
X deadyet = fall(&mx,&my,x-1,y,sx,sy,screen,howdead);
X if(deadyet ==0)
X deadyet = fall(&mx,&my,x+1,y+1,sx,sy,screen,howdead);
X if(deadyet ==0)
X deadyet = fall(&mx,&my,x-1,y+1,sx,sy,screen,howdead);
X if(deadyet ==0)
X deadyet = fall(&mx,&my,x-1,y-1,sx,sy,screen,howdead);
X if((deadyet ==0) && (ny != (y+1)))
X deadyet = fall(&mx,&my,x,y+1,sx,sy,screen,howdead);
X if((deadyet ==0) && (ny != (y-1)))
X deadyet = fall(&mx,&my,x,y-1,sx,sy,screen,howdead);
X if(deadyet ==0)
X deadyet = fall(&mx,&my,x+1,y-1,sx,sy,screen,howdead);
X move(16,0);
X refresh();
X y = ny;
X x = nx;
X break;
X case 'O':
X if(screen[y][nx*2-x] == 'M')
X {
X screen[y][nx*2-x] = ' ';
X mx = my = -1;
X if(*bell)
X printf("\007");
X *score+=100;
X move(3,48);
X sprintf(buffer,"%d\t %d\t %d ",*score,nf,diamonds);
X (void) addstr(buffer);
X draw_symbol(48,10,' ');
X move(16,0);
X refresh();
X }
X if(screen[y][nx*2-x] == ' ')
X {
X screen[y][nx*2-x] = 'O';
X screen[y][x] = ' ';
X screen[ny][nx] = '@';
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X draw_symbol((nx-sx+5)*3,(ny-sy+3)*2,'@');
X draw_symbol((nx*2-x-sx+5)*3,(y-sy+3)*2,'O');
X if(deadyet==0)
X deadyet = fall(&mx,&my,nx*2-x,y+1,sx,sy,screen,howdead);
X if(deadyet==0)
X deadyet = fall(&mx,&my,x*2-nx,y,sx,sy,screen,howdead);
X if(deadyet==0)
X deadyet = fall(&mx,&my,x,y,sx,sy,screen,howdead);
X if(deadyet==0)
X deadyet = fall(&mx,&my,x,y-1,sx,sy,screen,howdead);
X if(deadyet==0)
X deadyet = fall(&mx,&my,x,y+1,sx,sy,screen,howdead);
X move(16,0);
X refresh();
X y = ny;
X x = nx;
X }
X break;
X case '<':
X case '>':
X if(screen[ny*2-y][x] == 'M')
X {
X screen[ny*2-y][x] = ' ';
X mx = my = -1;
X if(*bell)
X printf("\007");
X *score+=100;
X move(3,48);
X sprintf(buffer,"%d\t %d\t %d ",*score,nf,diamonds);
X (void) addstr(buffer);
X draw_symbol(48,10,' ');
X move(16,0);
X refresh();
X }
X if(screen[ny*2-y][x] == ' ')
X {
X screen[ny*2-y][x] = screen[ny][nx];
X screen[y][x] = ' ';
X screen[ny][nx] = '@';
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X draw_symbol((nx-sx+5)*3,(ny-sy+3)*2,'@');
X draw_symbol((x-sx+5)*3,(ny*2-y-sy+3)*2,screen[ny*2-y][x]);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,x,y,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,x-1,(ny>y)?y:(y-1),sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,x+1,(ny>y)?y:(y-1),sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,x-1,ny*2-y,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,x+1,ny*2-y,sx,sy,screen,howdead);
X move(16,0);
X refresh();
X y = ny;
X x = nx;
X }
X break;
X case '!':
X strcpy(howdead,"an exploding landmine");
X deadyet = 1;
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X draw_symbol((nx-sx+5)*3,(ny-sy+3)*2,'@');
X move(16,0);
X refresh();
X break;
X case 'X':
X if(nf == diamonds)
X {
X *score+=250;
X if(*bell)
X printf("\007");
X strcpy(howdead,"finishing the screen.");
X return howdead;
X }
X break;
X case 'T':
X if(tx > -1)
X {
X screen[ny][nx] = ' ';
X screen[y][x] = ' ';
X lx = x;
X ly = y;
X y = ty;
X x = tx;
X screen[y][x] = '@';
X sx = x;
X sy = y;
X *score += 20;
X display(sx,sy,frow,*score);
X deadyet = fall(&mx,&my,nx,ny,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,lx,ly,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,lx+1,ly-1,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,lx+1,ly+1,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,lx-1,ly+1,sx,sy,screen,howdead);
X if(deadyet == 0)
X deadyet = fall(&mx,&my,lx-1,ly-1,sx,sy,screen,howdead);
X move(16,0);
X refresh();
X }
X else
X {
X screen[ny][nx] = ' ';
X printf("Teleport out of order");
X }
X break;
X case 'M':
X strcpy(howdead,"a hungry monster");
X deadyet = 1;
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X move(16,0);
X refresh();
X break;
X case 'S':
X strcpy(howdead,"walking into a monster");
X deadyet = 1;
X draw_symbol((x-sx+5)*3,(y-sy+3)*2,' ');
X move(16,0);
X refresh();
X break;
X default:
X break;
X }
Xif((y == ny) && (x == nx) && (maxmoves>0))
X {
X (void) sprintf(buffer,"Moves remaining = %d ",--maxmoves);
X move(15,48);
X (void) addstr(buffer);
X }
Xif(maxmoves == 0)
X {
X addstr("You ran out of time! \007\007");
X refresh();
X }
Xif ((x<(sx-3))&& (deadyet ==0)) /* screen scrolling if necessary */
X {
X sx-=6;
X if(sx < 4)
X sx = 4;
X display(sx,sy,frow,*score);
X }
Xif ((y<(sy-2))&& (deadyet == 0))
X {
X sy-=5;
X if(sy < 2)
X sy = 2;
X display(sx,sy,frow,*score);
X }
Xif ((x>(sx+3)) && (deadyet == 0))
X {
X sx+=6;
X if(sx>(ROWLEN -5))
X sx = ROWLEN -5;
X display(sx,sy,frow,*score);
X }
Xif ((y>(sy+2))&& (deadyet ==0))
X {
X sy+=5;
X if(sy > (NOOFROWS-3))
X sy = NOOFROWS -3;
X display(sx,sy,frow,*score);
X }
X
X /* MONSTER SECTION - Put all these in a separate function later */
X
Xif(mx == -2) /* has the monster been killed ? */
X {
X *score+=100;
X mx = my = -1;
X move(3,48);
X sprintf(buffer,"%d\t %d\t",*score,nf);
X (void) addstr(buffer);
X draw_symbol(48,10,' ');
X move(16,0);
X refresh();
X }
Xif(mx != -1) /* no? then move that monster ! */
X {
X screen[my][mx] = ' ';
X if(mx>x)
X xdirection = -1;
X else
X xdirection = 1;
X if((my<(sy+4))&&(my>(sy-4))&&(mx<(sx+6))&&(mx>(sx-6)))
X draw_symbol((mx-sx+5)*3,(my-sy+3)*2,' ');
X if((hd = (mx-x))<0)
X hd = -hd;
X if((vd = (my-y))<0)
X vd = -vd;
X if((hd>vd)&&((screen[my][mx+xdirection] == ' ')||(screen[my][mx+xdirection] == '@')))
X mx+=xdirection;
X else
X {
X if(my>y)
X ydirection = -1;
X else
X ydirection = 1;
X if((screen[my+ydirection][mx] == ' ')||(screen[my+ydirection][mx] == '@'))
X my+=ydirection;
X else
X if((screen[my][mx+xdirection] == ' ')||(screen[my][mx+xdirection] == '@'))
X mx+=xdirection;
X }
X if((my<(sy+4))&&(my>(sy-4))&&(mx<(sx+6))&&(mx>(sx-6)))
X draw_symbol((mx-sx+5)*3,(my-sy+3)*2,'M');
X if(screen[my][mx] == '@') /* ha! gottim! */
X {
X strcpy(howdead,"a hungry monster");
X move(16,0);
X refresh();
X deadyet = 1;
X screen[my][mx] = 'M';
X }
X screen[my][mx] = 'M';
X move(16,0);
X refresh();
X }
X
Xcurrent = monster = mon_ptr;
Xwhile((monster != NULL)&&(!deadyet))/* deal with those little monsters */
X {
X new_disp = new_direction(screen, monster->x, monster->y, monster->mx, monster->my );
X screen[monster->y][monster->x] = monster->under;
X if((monster->y < (sy+4)) && (monster->y > (sy-4)) && (monster->x < (sx+6)) && (monster->x > (sx-6)))
X draw_symbol((monster->x-sx+5)*3,(monster->y-sy+3)*2,monster->under);
X if(monster->under == ' ')
X deadyet = deadyet | fall(&mx,&my,monster->x,monster->y,sx,sy,screen,howdead);
X monster->mx = new_disp.d[0];
X monster->my = new_disp.d[1];
X monster->x += monster->mx;
X monster->y += monster->my;
X monster->under = screen[monster->y][monster->x];
X screen[monster->y][monster->x] = 'S'; /* move into new space */
X if((monster->y < (sy+4)) && (monster->y > (sy-4)) && (monster->x < (sx+6)) && (monster->x > (sx-6)))
X draw_symbol((monster->x-sx+5)*3,(monster->y-sy+3)*2,'S');
X if(monster->under == '@') /* monster hit you? */
X {
X strcpy(howdead,"the little monsters");
X move(16,0);
X refresh();
X deadyet = 1;
X monster->under = ' ';
X }
X if(monster->under == '+') /* monster hit cage? */
X {
X *score +=20;
X if(*bell)
X printf("\007");
X if(monster == mon_ptr) /* remove from chain */
X mon_ptr = mon_ptr->next;
X else current->next = monster-> next;
X screen[monster->y][monster->x] = '*';
X if((monster->y < (sy+4)) && (monster->y > (sy-4)) && (monster->x < (sx+6)) && (monster->x > (sx-6)))
X draw_symbol((monster->x-sx+5)*3,(monster->y-sy+3)*2,'*');
X }
X if(monster->under == 'S')
X monster->under = ' ';
X if(monster != mon_ptr)
X current = current->next;
X monster = monster->next;
X move(16,0);
X refresh();
X }
Xif(deadyet != 0)
X {
X move(16,0);
X addstr("You are dead, killed by ");
X addstr(howdead);
X addstr("\nPress any key to come back to life.");
X refresh();
X ch = getchar();
X move(16,0);
X addstr(" \n");
X addstr(" ");
X move(16,0);
X refresh();
X deadyet = 0;
X }
X}
Xreturn(howdead);
X}
END_OF_FILE
if test 14429 -ne `wc -c <'gamedev.c'`; then
echo shar: \"'gamedev.c'\" unpacked with wrong size!
fi
# end of 'gamedev.c'
fi
if test -f 'helpscr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'helpscr.c'\"
else
echo shar: Extracting \"'helpscr.c'\" \(9311 characters\)
sed "s/^X//" >'helpscr.c' <<'END_OF_FILE'
X#include "wand_head.h"
X#include <ctype.h>
X
X#define HELPFILE "wanderer.help"
X
Xstruct lh_f {
X char *line;
X struct lh_f *next;
X struct lh_f *prev;
X};
X
Xstruct help_f {
X int pgnum; /* the page number */
X struct lh_f *lh; /* long help */
X struct help_f *next;
X struct help_f *prev;
X};
X
X#define new(type) (type *) malloc(sizeof(type));
X#define cll_insert(member, list) (member->next = list, \
X member->prev = list->prev, \
X list->prev->next = member, \
X list->prev = member)
Xchar *make_filename();
X
X#ifdef XWANDER
Xextern struct fontinfo *tablefont;
Xextern tablefonthigh;
Xextern tablefontwide;
Xextern tablefonta;
Xextern GC tablegc;
X#endif
X
Xstruct help_f *helpscr = NULL;
Xstruct help_f *s_helppage = NULL;
Xchar *movekeys;
X
Xdo_help(keys)
Xchar *keys;
X{
X#ifndef XWANDER
X WINDOW *win;
X int rows = 24;
X#else
X int rows = (ICON_HIGH * 7) / tablefonthigh;
X#endif
X struct lh_f *p;
X int y, ch;
X int done;
X char lastline[255];
X
X movekeys = keys;
X if (helpscr == NULL) parse_help();
X if (helpscr == NULL) return;
X s_helppage = helpscr->next;
X if (s_helppage == helpscr) s_helppage = helpscr->next;
X
X#ifndef XWANDER
X win = newwin(rows-1, COLS, 0,0); /* window which gets the data */
X wclear(win);
X clearok(win,1);
X wrefresh(win);
X#else
X XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0);
X erase_message(0);
X erase_message(1);
X#endif
X
X y = 0;
X for ( p = s_helppage->lh->next; ; p=p->next) {
X eswprint(win,y++,p->line);
X if (y == rows-5 || p->next == s_helppage->lh) {
X lastline[0] = 0;
X if (s_helppage != helpscr->next) strcat(lastline,"<-");
X else strcat(lastline," ");
X strcat(lastline," ");
X if (s_helppage != helpscr->prev) strcat(lastline,"->");
X else strcat(lastline," ");
X strcat(lastline," ");
X if (p->next != s_helppage->lh) {
X strcat(lastline,"-MORE-");
X strcat(lastline," <space> for more,");
X } else {
X strcat(lastline," ");
X }
X strcat(lastline," 'n' next page, 'p' previous page, <esc> end HELP.");
X#ifndef XWANDER
X wmove(win, rows-2, 1);
X waddstr(win, lastline);
X touchwin(win);
X wrefresh(win);
X#else
X table_message(rows-2, lastline);
X#endif
X
X done = 0;
X while(!done) {
X#ifndef XWANDER
X ch = getchar();
X#else
X ch = getchar(-1);
X#endif
X switch(ch) {
X case ' ': /* space - continue */
X#ifndef XWANDER
X wclear(win);
X#else
X XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0);
X#endif
X y = 1;
X if (p->next == s_helppage->lh
X && s_helppage->lh->next != helpscr->lh) {
X s_helppage = s_helppage->next;
X if (s_helppage == helpscr) s_helppage = helpscr->next;
X p = s_helppage->lh;
X y = 0;
X }
X done = 1;
X break;
X case 13: /* ctrl-M, <cr>, ctrl-J */
X case 10:
X case 'n':
X case 'N':
X#ifndef XWANDER
X wclear(win);
X#else
X XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0);
X#endif
X y = 0;
X s_helppage = s_helppage->next;
X if (s_helppage == helpscr) s_helppage = helpscr->next;
X p = s_helppage->lh;
X done = 1;
X break;
X case 'p': /* 'P', 'p' or '-' = previous page */
X case 'P':
X case '-':
X#ifndef XWANDER
X wclear(win);
X#else
X XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0);
X#endif
X y = 0;
X s_helppage = s_helppage->prev;
X if (s_helppage == helpscr) s_helppage = helpscr->prev;
X p = s_helppage->lh;
X done = 1;
X break;
X case 27: /* esc - abort */
X#ifndef XWANDER
X delwin(win);
X touchwin(stdscr);
X clearok(stdscr,1);
X refresh();
X#else
X XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0);
X#endif
X return;
X default:
X dobeep();
X }
X }
X }
X }
X}
X
Xparse_help()
X{
X FILE *inp;
X char buf[1024], buf2[1024];
X int lineno, pgnum, n, i;
X struct help_f *th;
X struct lh_f *tl;
X char *p;
X strcpy(buf,make_filename(SCREENPATH,HELPFILE));
X
X if ((inp = fopen(buf,"r")) == NULL) {
X#ifdef XWANDER
X message(0,"Cannot open help file \"%s\"",buf);
X#else
X fprintf(stderr,"Cannot open help file \"%s\"",buf);
X#endif
X helpscr = NULL;
X return;
X }
X
X pgnum = 0;
X lineno = 0;
X
X /* allocate the header node of the adeck list */
X helpscr = new(struct help_f);
X helpscr->next = helpscr;
X helpscr->prev = helpscr;
X
X while (!feof(inp)) {
X if (fgets(buf,1024,inp) == NULL)
X break;
X lineno++;
X p = buf;
X /* blow off white space */
X for (;isspace(*p);p++);
X /* did we use up all of our line ? */
X if (*p == '#' || *p == 0 || *p == '\n')
X continue;
X
X /* look for key word */
X if (*p == '$') {
X if (strncmp(p,"$PAGE",5) == 0) { /* got the $PAGE token */
X /* allocate the page */
X th = new(struct help_f);
X pgnum++;
X th->pgnum = pgnum; /* set page number */
X th->lh = new(struct lh_f); /* allocate new long-help header node */
X th->lh->next = th->lh; /* init new long-help header node */
X th->lh->prev = th->lh;
X cll_insert(th,helpscr); /* insert page */
X while (1) { /* get the rest of the long-help */
X if (fgets(buf,1024,inp) == NULL) {
X#ifdef XWANDER
X message(0, "Illegal help file (no $END). Page: %d, Line: %d.",pgnum,lineno);
X#else
X fprintf(stderr,"Illegal help file (no $END). Page: %d, Line: %d.",pgnum,lineno);
X#endif
X helpscr = NULL;
X fclose(inp);
X return;
X }
X#ifdef XWANDER
X if (strncmp(buf,"$C",2)==0) continue; /* ignore $C */
X if (strncmp(buf,"$X",2)==0) {
X buf[0] = ' ';
X buf[1] = ' ';
X }
X#else
X if (strncmp(buf,"$X",2)==0) continue; /* ignore $X */
X if (strncmp(buf,"$C",2)==0) {
X buf[0] = ' ';
X buf[1] = ' ';
X }
X#endif
X
X lineno++;
X p = buf;
X if (strncmp(buf,"$END",4) == 0) {
X if (th->lh->next == th->lh) {
X#ifdef XWANDER
X message(0, "Illegal help file (null page). Page: %d, Line: %d.",pgnum,lineno);
X#else
X fprintf(stderr,"Illegal help file (null page). Page: %d, Line: %d.",pgnum,lineno);
X#endif
X helpscr = NULL;
X fclose(inp);
X return;
X }
X break; /* done with this page */
X } else {
X tl = new(struct lh_f); /* new line struct */
X buf[strlen(buf)-1] = 0; /* clobber trailing null */
X tl->line = (char *)strcpy(malloc(strlen(buf)+1),buf);
X cll_insert(tl,th->lh); /* insert line */
X }
X }
X } else {
X#ifdef XWANDER
X message(0,"Illegal help file (Unknown token). Page: %d, Line: %d.",pgnum,lineno);
X#else
X fprintf(stderr,"Illegal help file (Unknown token). Page: %d, Line: %d.",pgnum,lineno);
X#endif
X fclose(inp);
X helpscr = NULL;
X return;
X }
X } else {
X#ifdef XWANDER
X message(0,"Illegal help file (Bad line). Page: %d, Line: %d",pgnum,lineno);
X#else
X fprintf(stderr,"Illegal help file (Bad line). Page: %d, Line: %d",pgnum,lineno);
X#endif
X helpscr = NULL;
X fclose(inp);
X return;
X }
X }
X /* for (th = helpscr->next; th != helpscr; th=th->next) {
X int n;
X printf("help page: %d \"%s\"\n",th->pgnum, th->shorthelp);
X n = 0;
X for (tl = th->lh->next; tl != th->lh; tl=tl->next) {
X printf("%2d: %s\n",n++, tl->line);
X }
X printf("---------------------------\n");
X } */
X}
X
X#ifndef XWANDER
Xeswprint(win, y, line)
XWINDOW *win;
X#else
Xeswprint(foo, y, line)
X#endif
Xint y;
Xchar *line;
X{
X char cp[3];
X char *p;
X int x;
X char ch;
X#ifndef XWANDER
X WINDOW *twin = stdscr;
X
X stdscr = win;
X#endif
X
X p = line;
X x = 0;
X for (;*p;) {
X ch = *p;
X if (*p == '%') {
X p++; if (*p == 0) break;
X switch(*p) {
X case '%':
X break;
X case 'L': /* direction keys */
X ch = movekeys[0];
X break;
X case 'D':
X ch = movekeys[1];
X break;
X case 'U':
X ch = movekeys[2];
X break;
X case 'R':
X ch = movekeys[3];
X break;
X case 'N':
X ch = s_helppage->pgnum + '0';
X break;
X case '$': /* treasure */
X case '*':
X case 'C': /* time capsule */
X case '@': /* player */
X case '#': /* rock */
X case '=': /* brick */
X case ':': /* dirt */
X case '!': /* landmine */
X case '+': /* cage */
X case '<': /* larrow */
X case '>': /* rarrow */
X case '\\': /* backslope */
X case '/': /* fwdslope */
X case 'T': /* Teleport */
X case 'O': /* boulder */
X case 'S': /* sprite */
X case 'X': /* Exit */
X case 'M': /* monster */
X xydrawsymbol(x,y,*p);
X ch = 0;
X break;
X default:
X fprintf(stderr,"illegal escape: %c\n",*p);
X ch = *p;
X break;
X }
X }
X if (ch) xyprintchar(x,y,ch);
X x++;
X p++;
X }
X#ifndef XWANDER
X stdscr = twin;
X#endif
X}
X
Xxyprintchar(x,y,ch)
X{
X char buf[3];
X if (ch == ' ') return;
X#ifndef XWANDER
X move(y,x); addch(ch);
X#else
X buf[0] = ch;
X buf[1] = 0;
X XDrawImageString(dpy, win, tablegc,10+tablefontwide*x,
X (tablefonthigh*y)+10+tablefonta, buf, 1);
X#endif
X}
X
Xxydrawsymbol(x,y,ch)
X{
X#ifdef XWANDER
X Pixmap p = (Pixmap) symbol_pixmap(ch);
X GC g = (GC) symbol_gc(ch);
X
X XCopyArea(dpy, p, win, g, 0, 0, ICON_WIDE, ICON_HIGH,
X x * tablefontwide + 10, y * tablefonthigh + 10);
X#else
X draw_symbol(x, y, ch);
X#endif
X}
X
Xstatic char make_filenamebuf[1024];
Xchar *make_filename(path,file) /* make a filepath from 'path' and 'file' */
Xchar *path, *file;
X{
X strcpy(make_filenamebuf,path);
X strcat(make_filenamebuf,"/");
X strcat(make_filenamebuf,file);
X return(make_filenamebuf);
X}
END_OF_FILE
if test 9311 -ne `wc -c <'helpscr.c'`; then
echo shar: \"'helpscr.c'\" unpacked with wrong size!
fi
# end of 'helpscr.c'
fi
if test -f 'jump.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jump.c'\"
else
echo shar: Extracting \"'jump.c'\" \(3555 characters\)
sed "s/^X//" >'jump.c' <<'END_OF_FILE'
X#include "wand_head.h"
X
Xvoid showpass(num)
Xint num;
X{
Xlong position;
Xchar correct[20];
Xchar buffer[100];
XFILE *fp;
Xchar ch;
X#ifndef XWANDER
Xmove(18,0);
X#endif
Xposition = PASSWD;
Xwhile(position > 200000)
X position -= 200000;
Xif((fp = fopen("/usr/dict/words","r")) == NULL)
X return;
Xfseek(fp,position,ftell(fp));
Xwhile(fgetc(fp) != '\n');
Xfscanf(fp,"%s\n",correct);
X /* read a word into correct */
Xfclose(fp);
X#ifndef XWANDER
X(void) sprintf(buffer,"\007The password to jump from level %d ( using ~ ) is : %s \n",num,correct);
Xaddstr(buffer);
Xaddstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE \n");
Xrefresh();
X#ifndef XWANDER
Xgetchar();
X#else
Xgetchar(-1);
X#endif
Xmove(18,0);
Xaddstr(" \n");
Xaddstr(" ");
Xmove(18,0);
Xrefresh();
X#else
X message(0,"The password to jump from level %d ( using ~ ) is : %s\n",
X num, correct);
X message(1,"PRESS ANY KEY TO REMOVE IT AND CONTINUE");
X#ifndef XWANDER
X (void)getchar();
X#else
X (void)getchar(-1);
X#endif
X erase_message(0);
X erase_message(1);
X#endif
X
X}
X
Xint jumpscreen(num)
Xint num;
X{
Xchar word[20],
X buffer[100],
X correct[20];
Xint index=0, input;
Xchar ch;
Xlong position;
XFILE *fp;
X#ifndef XWANDER
Xmove(16,0);
Xsprintf(buffer,"Number of screen to jump to? (next is %d) :",num+1);
Xaddstr("Please enter password of screen to jump to:");
Xrefresh();
X#else
X message(1,"Please enter password of screen to jump to:");
X#endif
X
X#ifndef XWANDER
Xwhile(((word[index++] = getchar()) != '\n')&&(index < 19))
X#else
Xwhile(((word[index++] = getchar(-1)) != '\n')&&(index < 19))
X#endif
X {
X#ifndef XWANDER
X addch(' ');
X refresh();
X#else
X ; /* NULL statement */
X#endif
X }
Xword[--index]='\0';
X#ifndef XWANDER
Xmove(16,0);
Xaddstr("Validating... ");
Xrefresh();
X#else
Xerase_message(0);
Xmessage(0,"Validating...");
X#endif
Xposition = PASSWD;
Xwhile(position > 200000)
X position -= 200000;
Xif((fp = fopen("/usr/dict/words","r")) == NULL)
X return 0;
Xfseek(fp,position,ftell(fp));
Xwhile(fgetc(fp) != '\n');
Xfscanf(fp,"%s\n",correct);
X /* read a word into correct */
X
Xfclose(fp);
X
Xif(strcmp(word,MASTERPASSWORD) == 0)
X {
X#ifndef XWANDER
X move(16,0);
X sprintf(buffer,"Certainly master, but the correct word is %s. \n",correct);
X addstr(buffer);
X addstr("Press letter corresponding to desired level. (Or space to continue)");
X refresh();
X#else
X message(0,"Certainly master, but the correct word is %s.",correct);
X message(1,"Press letter corresponding to desired level. (Or space to continue)");
X#endif
X#ifndef XWANDER
X ch = getchar();
X#else
X ch = getchar(-1);
X#endif
X num++;
X input = ch - 'a' +1;
X if(!(ch<'a') && !(ch>'z'))
X num = input;
X#ifndef XWANDER
X move(16,0);
X addstr(" ");
X move(16,0);
X refresh();
X#else
X erase_message(0);
X erase_message(1);
X#endif
X return num;
X }
X
Xif(strcmp(correct,word) != 0)
X {
X#ifndef XWANDER
X move(16,0);
X addstr("\007INCORRECT! ");
X refresh();
X#else
X erase_message(0);
X message(0,"INCORRECT!");
X dobeep();
X#endif
X return num;
X }
X
X#ifndef XWANDER
Xmove(16,0);
Xaddstr("Password Validated..... Jumping to next screen. ");
Xrefresh();
X#else
Xerase_message(0);
Xmessage(0,"Password Validated..... Jumping to next screen.");
X#endif
X
X/* if they match, return ++num */
X
Xreturn ++num;
X}
END_OF_FILE
if test 3555 -ne `wc -c <'jump.c'`; then
echo shar: \"'jump.c'\" unpacked with wrong size!
fi
# end of 'jump.c'
fi
if test -f 'm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'m.c'\"
else
echo shar: Extracting \"'m.c'\" \(6750 characters\)
sed "s/^X//" >'m.c' <<'END_OF_FILE'
X#include "wand_head.h"
X
X#ifdef GAMEDEV
Xchar *scrname = "screen";
X#endif
X
X
X#ifdef XWANDER
X# include <ctype.h>
X# define PROGNAME "sample program"
X# define ICON_LABEL "sample"
X# include "icons/wanderer_bm"
X# define BITMAPDEPTH 1
Xextern int do_repaint;
Xextern tinymode;
XWindow win; /* window ID */
XDisplay *dpy; /* structure with display and screen info */
XGC globgc;
Xint scr; /* screen number */
Xint endgame;
X#endif
X
Xextern char *playscreen();
X
Xextern int rscreen();
X
X#ifndef GAMEDEV
Xextern int savescore();
X#endif
X
X#ifdef XWANDER
Xusage()
X{
X fprintf(stderr,"usage: xwander -s -d display_name\n");
X fprintf(stderr,"\t-s\tprints high score table\n");
X fprintf(stderr,"\t-d\tspecify display name\n");
X}
X#endif
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
Xchar screen[NOOFROWS][ROWLEN+1];
Xchar (*frow)[ROWLEN+1] = screen;
Xint num = 1,score = 0,bell = 1,maxmoves = 0;
Xchar howdead[25],
X *name,*keys,*dead;
Xchar *malloc();
X#ifdef XWANDER
X int win_width, win_height, win_x, win_y;
X int border_width = 2;
X int display_width, display_height;
X unsigned int icon_width, icon_height;
X char *window_name = PROGNAME;
X char *icon_name = ICON_LABEL;
X Pixmap icon_pixmap;
X XSizeHints size_hints; /* window manager hints */
X XIconSize *size_list;
X int count; /* number of icon sizes set by wm */
X XEvent report;
X char *display_name = NULL;
X char *p;
X
X argc--; argv++; /* skip program name */
X while (argc > 0 && **argv == '-') /* until there are no more args */
X {
X p = *argv;
X if (strcmp("-display", p) == 0) {
X display_name = *++argv;
X printf("display = \"%s\"\n",display_name);
X argc--;
X } else {
X for (p++; *p;p++)
X {
X switch(*p) {
X case 'd': /* set display name */
X display_name = *++argv;
X printf("display = \"%s\"\n",display_name);
X --argc;
X break;
X#ifndef GAMEDEV
X case 's': /* print scores */
X savescore("-",0,0,"-");
X return 0;
X break;
X#endif
X#ifdef GAMEDEV
X case 'n': /* name of screen to test */
X scrname = *++argv;
X break;
X#endif
X default:
X printf("xwanderer: bad option '%c'\n", *p);
X usage();
X break;
X }
X }
X argv++;
X argc--;
X }
X }
X
X /* try to connect to display server */
X if (( dpy = XOpenDisplay(display_name)) == NULL)
X {
X fprintf(stderr,"Cannot Connect to display server!\n");
X exit(-1);
X }
X
X /* get screen and size from display structure macros */
X scr = DefaultScreen(dpy);
X
X display_width = DisplayWidth(dpy,scr);
X display_height = DisplayHeight(dpy,scr);
X
X win_x = 0; win_y = 0;
X win_width = 1100; win_height = ICON_HIGH * 7 + 75;
X
X /* make window */
X win = XCreateSimpleWindow(dpy,RootWindow(dpy,scr), win_x, win_y,
X win_width, win_height, border_width, WhitePixel(dpy,scr),
X BlackPixel(dpy,scr));
X
X /* get available icon sizes from window manager */
X /* if (XGetIconSizes(dpy,RootWindow(dpy,scr),&size_list,&count)==0) */
X /* I don't care if your window manager doesn't support 64x64--mine does. */
X icon_width = wanderer_bm_width; icon_height = wanderer_bm_height;
X /* else
X {
X icon_width = size_list->min_width; icon_height = size_list->min_height;
X } */
X /* create pixmap from bitmap data */
X icon_pixmap = MakePixmap(dpy,RootWindow(dpy,scr),wanderer_bm_bits,
X icon_width, icon_height);
X
X /* initalize the hint prop. for wm */
X size_hints.flags = PPosition | PSize | PMinSize;
X size_hints.x = win_x;
X size_hints.y = win_y;
X size_hints.width = win_width;
X size_hints.height = win_height;
X size_hints.min_width = 350;
X size_hints.min_height = 100;
X
X /* set props. for wm (always before mapping) */
X XSetStandardProperties(dpy,win,window_name,icon_name,icon_pixmap,
X argv,argc,&size_hints);
X
X /*select event types wanted */
X XSelectInput(dpy,win,ExposureMask | KeyPressMask);
X
X /* build the pixmaps for the game */
X build_pixmaps();
X
X /* display the window! */
X XMapWindow(dpy,win);
X
X#else
X# ifndef GAMEDEV
Xif(argc > 1)
X {
X savescore("-",0,0,"-");
X return 0;
X }
X# else
Xif (argc > 1)
X {
X scrname = argv[1];
X }
X# endif
X#endif
X
Xif((name = (char *)getenv("NEWNAME")) == NULL)
X if((name = (char *)getenv("NAME")) == NULL)
X if((name = (char *)getenv("FULLNAME")) == NULL)
X if((name = (char *)getenv("USER")) == NULL)
X name = "noname";
X
Xif((keys = (char *)getenv("NEWKEYS")) == NULL)
X {
X keys = malloc(5);
X strcpy(keys,"kjhl");
X }
X
X#ifndef XWANDER
Xinitscr();
X
X/* MAIN PROGRAM HERE */
X
Xcrmode(); noecho();
X#endif
X
Xfor (;;)
X {
X int ch;
X
X#ifndef GAMEDEV
X if (rscreen(num,frow,&maxmoves))
X {
X strcpy(howdead,"a non-existant screen");
X break; /* really game over- leave the program and all! */
X }
X#else
X if (rscreen(scrname,frow, &maxmoves))
X {
X fprintf(stderr,"dev: Can't find file `%s'\n",scrname);
X#ifndef XWANDER
X echo();
X nocrmode();
X endwin();
X#endif
X exit(0);
X };
X#endif
X#ifdef XWANDER
X do_repaint = 1;
X tinymode = 0;
X#endif
X dead = playscreen(num,screen,&score,&bell,maxmoves,keys);
X#ifdef GAMEDEV
X if ((dead != NULL) && (*dead == '~'))
X dead = NULL;
X#else
X if ((dead != NULL) && (*dead == '~'))
X {
X num = (int)(dead[1]) - 1;
X dead = NULL;
X }
X#endif
X if (dead != NULL)
X {
X strcpy(howdead,dead);
X#ifdef XWANDER
X /* we can't have this window based program going away every time
X * we die. Ask the user if he wants to play again, but first
X * do the end of game clean up type stuff
X */
X erase_message(0);
X erase_message(1);
X message(0,"%s killed by %s with a score of %d on level %d.",
X name,howdead,score,num);
X endgame = 0;
X XClearArea(dpy, win, 5, 5, ICON_WIDE * 11, ICON_HIGH * 7, 0);
X# ifndef GAMEDEV
X if((savescore(howdead,score,num,name) == 0)&&(score != 0))
X printf("\nWARNING: newgame error: score not saved!\n\n");
X# endif
X message(1,"Would you like to play again? (Y/N)");
X while (1) {
X ch = getchar(-1);
X if (islower(ch)) ch = toupper(ch);
X if (ch == 'Y' || ch == 'N')
X break;
X erase_message(1);
X message(1,"You dolt, type `Y' or `N': ");
X dobeep();
X }
X if (ch == 'N') break; else {
X num = 0; score = 0; maxmoves = 0;
X howdead[0] = 0;
X erase_message(0);
X erase_message(1);
X }
X#else
X break;
X#endif
X }
X num++;
X };
X#ifdef XWANDER
X endgame = 1;
X#endif
X
Xprintf("\n\n%s killed by %s with a score of %d on level %d.\n",name,howdead,score,num);
X
X/* END OF MAIN PROGRAM */
X
X/* SAVE ROUTINES FOR SCORES */
X
X#ifndef GAMEDEV
Xif((savescore(howdead,score,num,name) == 0)&&(score != 0))
X printf("\nWARNING: newgame error: score not saved!\n\n");
X#endif
X
X#ifndef XWANDER
Xecho();
Xnocrmode();
Xendwin();
X#endif
Xprintf("WANDERER (C)1988 S. Shipway\n");
Xreturn 0;
X}
END_OF_FILE
if test 6750 -ne `wc -c <'m.c'`; then
echo shar: \"'m.c'\" unpacked with wrong size!
fi
# end of 'm.c'
fi
if test -f 'scores.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scores.c'\"
else
echo shar: Extracting \"'scores.c'\" \(4206 characters\)
sed "s/^X//" >'scores.c' <<'END_OF_FILE'
X#include "wand_head.h"
X
X/* MFC- lockfiles fixed: tries 5 times to get lock, with 1 second between
X * tries, if after 5 seconds, no lock is gained, the lockfile is blown
X * away.
X */
X#define LOCK { lc=5; \
X while((lock = creat(LOCKPATH,0)<0 && lc)) { \
X sleep(1); lc--; } \
X }
X#define UNLOCK (void) unlink(LOCKPATH)
X
X#define ENTRIES 15
X
Xtypedef struct
X {
X char howdead[25];
X char name[20];
X int score;
X int level;
X } score_entry;
X
X#ifdef XWANDER
Xextern endgame;
Xwin_show_scores(table,num)
Xscore_entry *table;
Xint num;
X{
X int tot = num;
X
Xtable_message(0,"No. Score Level Names How they died");
Xtable_message(1,"-----------------------------------------------------------------------------");
Xwhile(num > 0)
X {
X num--;
X table_message((tot-num)+1,"%2d %5d %3d %-20s killed by %-s",(tot - num),table->score,table->level,table->name,table->howdead);
X table++;
X }
X}
X#endif
X
Xvoid show_scores(table,num)
Xscore_entry *table;
Xint num;
X{
Xint tot = num;
X#ifdef XWANDER
X if (!endgame) { win_show_scores(table, num); return; }
X#endif
Xprintf("\nNo. Score Level Names How they died\n");
Xprintf("=============================================================================\n");
Xwhile(num > 0)
X {
X num--;
X printf("%2d %5d %3d %-20s killed by %-s\n",(tot - num),table->score,table->level,table->name,table->howdead);
X table++;
X }
Xprintf("\n\n");
X}
X
Xint readtable(table_ptr)
Xscore_entry *table_ptr;
X{
XFILE *fp;
Xint numread;
Xif((fp = fopen(HISCOREPATH,"r")) == NULL)
X {
X numread = 0;
X }
Xelse
X {
X numread = fread(table_ptr, sizeof(score_entry), ENTRIES, fp);
X fclose(fp);
X }
Xreturn numread;
X}
X
Xint savescore(howdead,score,level,name)
Xchar *howdead, *name;
Xint score,level;
X{
X int lc;
Xscore_entry table[ENTRIES + 2],
X *table_ptr = table, *from_ptr,
X new_entry,temp_entry;
Xint numread,index = 1, numsaved, lock, already = 0, output_value = 1;
XFILE *fp;
Xstrncpy(new_entry.howdead,howdead,25);
Xstrncpy(new_entry.name,name,20);
Xnew_entry.score = score;
Xnew_entry.level = level;
Xlock = (-1);
Xwhile (lock == (-1)) {
X LOCK;
X if (lock==(-1)) { UNLOCK; }
X}
Xnumread = readtable(table_ptr);
Xif (numread > 0)
X if(table[numread-1].score > 99999) /* stop system errors messing it up*/
X {
X numread--;
X printf("\007Erasing spurious entry in table.\n");
X }
Xif(score == 0)
X {
X show_scores(table,numread);
X UNLOCK;
X return 0;
X }
Xif (numread > 0) {
X numread++; /* scan through until correct insertion point */
X while((table_ptr->score > score)&&(index < numread))
X {
X if(strcmp(table_ptr->name,name)==0) {
X already= 1;
X break;
X }
X table_ptr++;
X index++;
X }
X if(table_ptr->score == score)
X while((table_ptr->level>level)&&(index<=numread)&&(table_ptr->score == score))
X {
X if((already == 1)||(strcmp(table_ptr->name,name)==0)) {
X already= 1;
X break;
X }
X table_ptr++;
X index++;
X };
X if(already == 0) { /* provided no previous hiscore */
X temp_entry = *table_ptr; /* insert new entry */
X *table_ptr = new_entry;
X from_ptr = table_ptr;
X if (strcmp(temp_entry.name, name) == 0)
X numread--; /* new entry directly replaces old one */
X } else {
X numread--;
X from_ptr = table_ptr--;
X temp_entry = *from_ptr;
X }
X while(index++ < numread)
X {
X table_ptr++;
X from_ptr++;
X if(strcmp(from_ptr->name,name)==0 && index<numread) {
X from_ptr++;
X numread--;
X }
X new_entry = *from_ptr;
X *table_ptr = temp_entry;
X temp_entry = new_entry;
X }
X} else {
X printf("\007\nCreating new hiscore table.\n\n");
X *table_ptr = new_entry;
X numread++;
X}
Xnumread = ( (numread > ENTRIES) ? ENTRIES : numread );
Xfp = fopen(HISCOREPATH,"w");
Xtable_ptr = table;
Xnumsaved = fwrite(table_ptr, sizeof(score_entry), numread, fp);
Xchmod(HISCOREPATH,0666);
Xif(numsaved < numread)
X {
X printf("ERROR! Only %d items saved from %d !\n",numsaved,numread);
X output_value = 0;
X }
Xfclose(fp);
XUNLOCK;
Xshow_scores(table,numsaved);
Xreturn output_value;
X}
END_OF_FILE
if test 4206 -ne `wc -c <'scores.c'`; then
echo shar: \"'scores.c'\" unpacked with wrong size!
fi
# end of 'scores.c'
fi
if test -f 'wanderer.help' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wanderer.help'\"
else
echo shar: Extracting \"'wanderer.help'\" \(3799 characters\)
sed "s/^X//" >'wanderer.help' <<'END_OF_FILE'
X#
X# this is the help file for 'wanderer'.
X# it consists of pages of help bracketed by
X# '$PAGE' and '$END' directives.
X# There are several printf style escapes
X# they are:
X# %U %D %L %R - the movement command keys
X# %[any icon character] - draw that icon
X# %N - page number
X# This help file should live with the screens.
X# if a line begins with $X, it will only be present in the
X# X windows versions of the program. Likewise, if
X# a line begins with $C, it will only be printed in
X# the curses versions.
X#
X# (C)1988 Mike Cuddy
X#
X$PAGE
X ** W A N D E R E R **
X
XHow to play:
X %*
X Collect all the treasure:
X
X$X
X$X
X %X
X Then go through the exit:
X
X$X
X$X
X
X Keys are: %L Left 1 Loud
X %D Down 0 Quiet <- Very useful!
X %U Up q Quit game
X %R Right ~ Jump level. NB This means you do not
X***-->> ! Look at map receive your bonus!
X$X t tiny mode (xwanderer only)
X
X$END
X$PAGE
X WANDERER HELP, PAGE %N
X Screen Items:
X
X This is You:
X$X
X %@
X
X$X
X$X
X$X
X
X %# %= %C
X Solid rock Time capsule
X (5 points, 250 moves)
X$X
X$X
X
X %:
X Passable earth (dirt, one point)
X
X$X
X$X
X %O
X Boulder (falls down, boulders and arrows fall off it)
X
X$END
X$PAGE
X WANDERER HELP, PAGE %N
X More Screen Items:
X$X
X$X
X$X
X
X
X %< %> Arrows %+ Cage- holds baby monsters
X (run left and right) and changes into treasure
X
X$X
X$X
X
X %* (10 points) %S
X Money (collect it) Baby monster (kills you)
X
X
X$X
X %! When a baby monster hits a cage
X Instant annihilation it is captured and you get 50
X points. Also the cage becomes
X a treasure.
X
X$END
X$PAGE
X WANDERER HELP, PAGE %N
X Other items are:
X
X$X
X$X
X$X
X
X %\ %/ Slopes %M Monster
X (boulders etc slide off) (eats you up whole.
X Yum yum yum. )
X 100 points for killing
X with a rock or arrow
X$C%X
X$C The exit. Collect all the
X$X%X The exit. Collect all the
X treasure first. (250 point bonus)
X
X$X
X$X
X %T
X$X
X Teleport (50 points for using it)
X
X
X$END
X$PAGE
X WANDERER HELP, PAGE %N
X Thanx-n-hints
X$C
X$C
X XV11R2 port/helpscreens by: Mike Cuddy (ihnp4!convex!cuddy)
X Thanx to : Mark (mjs@opal) for curing the bus error
X James Beckett(cstrhey) for designing screens 5 and 6
X Mike Taylor(maujf) for helpful suggestions
X$C
X$C
X YOU CAN DEFINE YOUR OWN KEYS BY USING THE ENVIRONMENT VARIABLE
X 'NEWKEYS'. TO GET a UP z DOWN n LEFT m RIGHT ADD IN YOUR .cshrc
X setenv NEWKEYS aznm
X YOU CAN ALSO CHANGE YOUR NAME USING THE VARIABLE 'NEWNAME' IN THE
X SAME WAY.
X To see the hiscore table only, use '-s'.
X$END
END_OF_FILE
if test 3799 -ne `wc -c <'wanderer.help'`; then
echo shar: \"'wanderer.help'\" unpacked with wrong size!
fi
# end of 'wanderer.help'
fi
echo shar: End of archive 2 \(of 5\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 5 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0