home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!news.tek.com!master!saab!billr
- From: billr@saab.CNA.TEK.COM (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v15i035: robot_hunt - original hunt with a robot, Part04/04
- Message-ID: <4191@master.CNA.TEK.COM>
- Date: 14 Jan 93 03:14:35 GMT
- Sender: news@master.CNA.TEK.COM
- Lines: 598
- Approved: billr@saab.CNA.TEK.COM
- Xref: uunet comp.sources.games:1534
-
- Submitted-by: whatis@ucsd.edu (Steve Boswell)
- Posting-number: Volume 15, Issue 35
- Archive-name: robot_hunt/Part04
- Environment: Curses, Sockets
-
-
- #! /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 4 (of 4)."
- # Contents: Makefile connect.c makemaze.c pathname.c terminal.c
- # Wrapped by billr@saab on Wed Jan 13 19:04:32 1993
- 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'\" \(3332 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X#
- X# Copyright (c) 1985 Regents of the University of California.
- X# All rights reserved.
- X#
- X# Redistribution and use in source and binary forms are permitted
- X# provided that the above copyright notice and this paragraph are
- X# duplicated in all such forms and that any documentation,
- X# advertising materials, and other materials related to such
- X# distribution and use acknowledge that the software was developed
- X# by the University of California, Berkeley. The name of the
- X# University may not be used to endorse or promote products derived
- X# from this software without specific prior written permission.
- X# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X#
- X# @(#)Makefile 5.7 (Berkeley) 9/23/88
- X#
- X# Hunt
- X# Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- X# San Francisco, California
- X#
- X
- XHDR= hunt.h
- XDSRC= answer.c driver.c draw.c execute.c expl.c makemaze.c shots.c \
- X terminal.c extern.c pathname.c
- XDOBJ= answer.o driver.o draw.o execute.o expl.o makemaze.o shots.o \
- X terminal.o extern.o
- XPSRC= hunt.c connect.c playit.c pathname.c robot.c
- XPOBJ= hunt.o connect.o playit.o robot.o
- XMAN= hunt.0
- X
- X# Flags are:
- X# DEBUG Don't trust everything in the code
- X# INTERNET Use the Internet domain IPC instead of UNIX domain
- X# BROADCAST Use internet broadcasting code when looking for driver
- X# OLDIPC Use 4.1a internet system calls (must also define
- X# INTERNET but not BROADCAST)
- X# RANDOM Include doors which disperse shots randomly
- X# REFLECT Include diagonal walls that reflect shots
- X# MONITOR Include code for watching the game from the sidelines
- X# OOZE Include slime shots
- X# FLY Make people fly when walls regenerate under them
- X# START_FLYING Players enter flying (FLY must also be defined)
- X# VOLCANO Include occasional large slime explosions
- X# ROBOT Allow "-r" to turn on a hunt robot.
- X# DAEMON Run as a daemon. ROBOT must be on, too.
- X#
- X# NOTE: if you change the domain (INTERNET vs UNIX) then "make newdomain"
- X#
- XDEFS= -DBROADCAST -DRANDOM -DREFLECT -DMONITOR -DINTERNET \
- X -DOOZE -DFLY -DROBOT -DDAEMON
- XCFLAGS= -g ${DEFS}
- X
- Xall: hunt hunt.driver
- X
- Xhunt: ${POBJ} pathname.o
- X ${CC} -o $@ ${POBJ} pathname.o -lcurses -ltermlib
- X
- Xhunt.driver: ${DOBJ} pathname.o
- X ${CC} -o $@ ${DOBJ} pathname.o
- X
- Xdebug: hunt.dbg hunt.driver.dbg
- X
- Xhunt.dbg: ${POBJ} pathname.dbg.o
- X ${CC} -o $@ ${POBJ} pathname.dbg.o -lcurses -ltermlib
- X
- Xhunt.driver.dbg: ${DOBJ} pathname.dbg.o
- X ${CC} -o $@ ${DOBJ} pathname.dbg.o
- X
- Xpathname.dbg.o: pathname.c
- X @echo ${CC} ${CFLAGS} -DDEBUG -c pathname.c -o pathname.dbg.o
- X @rm -f x.c
- X @ln pathname.c x.c
- X @${CC} ${CFLAGS} -DDEBUG -c x.c
- X @mv x.o pathname.dbg.o
- X @rm -f x.c
- X
- Xinstall: ${MAN}
- X install -s -o games -g bin -m 700 hunt.driver ${DESTDIR}/usr/games/lib/hunt.driver
- X install -s -o games -g bin -m 700 hunt ${DESTDIR}/usr/games/hide
- X install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat6
- X (cd ${DESTDIR}/usr/games; rm -f hunt; ln -s dm hunt; chown games.bin hunt)
- X
- Xlint: ${DSRC} ${PSRC}
- X lint -chapbx ${DEFS} ${DSRC}
- X lint -chapbx ${DEFS} ${PSRC} -lcurses
- X
- Xtags: ${DSRC} ${PSRC}
- X ctags ${DSRC} ${PSRC}
- X
- Xclean:
- X rm -f hunt hunt.driver *.o tags core tmp debug_file
- X
- Xcleandir: clean
- X rm -f ${MAN} tags .depend
- X
- Xdepend:
- X mkdep ${DSRC} ${PSRC}
- END_OF_FILE
- if test 3332 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'connect.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'connect.c'\"
- else
- echo shar: Extracting \"'connect.c'\" \(1493 characters\)
- sed "s/^X//" >'connect.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1985 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Berkeley. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- X#ifndef lint
- Xstatic char sccsid[] = "@(#)connect.c 5.2 (Berkeley) 6/27/88";
- X#endif /* not lint */
- X
- X/*
- X * Hunt
- X * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- X * San Francisco, California
- X */
- X
- X# include "hunt.h"
- X# include <signal.h>
- X
- Xdo_connect(name)
- Xchar *name;
- X{
- X static long uid;
- X extern char *ttyname();
- X
- X uid = htonl(getuid());
- X (void) write(Socket, (char *) &uid, sizeof uid);
- X (void) write(Socket, name, NAMELEN);
- X (void) strcpy(Buf, (isatty (fileno (stderr)))
- X ? ttyname(fileno(stderr)) : "");
- X (void) write(Socket, Buf, NAMELEN);
- X# ifdef MONITOR
- X (void) write(Socket, (char *) &Am_monitor, sizeof Am_monitor);
- X# endif MONITOR
- X}
- END_OF_FILE
- if test 1493 -ne `wc -c <'connect.c'`; then
- echo shar: \"'connect.c'\" unpacked with wrong size!
- fi
- # end of 'connect.c'
- fi
- if test -f 'makemaze.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makemaze.c'\"
- else
- echo shar: Extracting \"'makemaze.c'\" \(3700 characters\)
- sed "s/^X//" >'makemaze.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1985 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Berkeley. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- X#ifndef lint
- Xstatic char sccsid[] = "@(#)makemaze.c 5.2 (Berkeley) 6/27/88";
- X#endif /* not lint */
- X
- X/*
- X * Hunt
- X * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- X * San Francisco, California
- X */
- X
- X# include "hunt.h"
- X
- X# define ISCLEAR(y,x) (Maze[y][x] == SPACE)
- X# define ODD(n) ((n) & 01)
- X
- Xmakemaze()
- X{
- X register char *sp;
- X register int y, x;
- X
- X /*
- X * fill maze with walls
- X */
- X sp = &Maze[0][0];
- X while (sp < &Maze[HEIGHT - 1][WIDTH])
- X *sp++ = DOOR;
- X
- X y = rand_num(DBOUND - UBOUND) + UBOUND;
- X x = rand_num(RBOUND - LBOUND) + LBOUND;
- X dig(y, x); /* Dig out the maze */
- X remap();
- X}
- X
- X# define NPERM 24
- X# define NDIR 4
- X
- Xint dirs[NPERM][NDIR] = {
- X {0,1,2,3}, {3,0,1,2}, {0,2,3,1}, {0,3,2,1},
- X {1,0,2,3}, {2,3,0,1}, {0,2,1,3}, {2,3,1,0},
- X {1,0,3,2}, {1,2,0,3}, {3,1,2,0}, {2,0,3,1},
- X {1,3,0,2}, {0,3,1,2}, {1,3,2,0}, {2,0,1,3},
- X {0,1,3,2}, {3,1,0,2}, {2,1,0,3}, {1,2,3,0},
- X {2,1,3,0}, {3,0,2,1}, {3,2,0,1}, {3,2,1,0}
- X };
- X
- Xint incr[NDIR][2] = {
- X {0, 1}, {1, 0}, {0, -1}, {-1, 0}
- X };
- X
- Xdig(y, x)
- Xint y, x;
- X{
- X register int *dp;
- X register int *ip;
- X register int ny, nx;
- X register int *endp;
- X
- X Maze[y][x] = SPACE; /* Clear this spot */
- X dp = dirs[rand_num(NPERM)];
- X endp = &dp[NDIR];
- X while (dp < endp) {
- X ip = &incr[*dp++][0];
- X ny = y + *ip++;
- X nx = x + *ip;
- X if (candig(ny, nx))
- X dig(ny, nx);
- X }
- X}
- X
- X/*
- X * candig:
- X * Is it legal to clear this spot?
- X */
- Xcandig(y, x)
- Xregister int y, x;
- X{
- X register int i;
- X
- X if (ODD(x) && ODD(y))
- X return FALSE; /* can't touch ODD spots */
- X
- X if (y < UBOUND || y >= DBOUND)
- X return FALSE; /* Beyond vertical bounds, NO */
- X if (x < LBOUND || x >= RBOUND)
- X return FALSE; /* Beyond horizontal bounds, NO */
- X
- X if (ISCLEAR(y, x))
- X return FALSE; /* Already clear, NO */
- X
- X i = ISCLEAR(y, x + 1);
- X i += ISCLEAR(y, x - 1);
- X if (i > 1)
- X return FALSE; /* Introduces cycle, NO */
- X i += ISCLEAR(y + 1, x);
- X if (i > 1)
- X return FALSE; /* Introduces cycle, NO */
- X i += ISCLEAR(y - 1, x);
- X if (i > 1)
- X return FALSE; /* Introduces cycle, NO */
- X
- X return TRUE; /* OK */
- X}
- X
- Xremap()
- X{
- X register int y, x;
- X register char *sp;
- X register int stat;
- X
- X for (y = 0; y < HEIGHT; y++)
- X for (x = 0; x < WIDTH; x++) {
- X sp = &Maze[y][x];
- X if (*sp == SPACE)
- X continue;
- X stat = 0;
- X if (y - 1 >= 0 && Maze[y - 1][x] != SPACE)
- X stat |= NORTH;
- X if (y + 1 < HEIGHT && Maze[y + 1][x] != SPACE)
- X stat |= SOUTH;
- X if (x + 1 < WIDTH && Maze[y][x + 1] != SPACE)
- X stat |= EAST;
- X if (x - 1 >= 0 && Maze[y][x - 1] != SPACE)
- X stat |= WEST;
- X switch (stat) {
- X case WEST | EAST:
- X *sp = WALL1;
- X break;
- X case NORTH | SOUTH:
- X *sp = WALL2;
- X break;
- X case 0:
- X# ifdef RANDOM
- X *sp = DOOR;
- X# endif RANDOM
- X# ifdef REFLECT
- X *sp = rand_num(2) ? WALL4 : WALL5;
- X# endif REFLECT
- X break;
- X default:
- X *sp = WALL3;
- X break;
- X }
- X }
- X bcopy((char *) Maze, (char *) Orig_maze, sizeof Maze);
- X}
- END_OF_FILE
- if test 3700 -ne `wc -c <'makemaze.c'`; then
- echo shar: \"'makemaze.c'\" unpacked with wrong size!
- fi
- # end of 'makemaze.c'
- fi
- if test -f 'pathname.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'pathname.c'\"
- else
- echo shar: Extracting \"'pathname.c'\" \(1992 characters\)
- sed "s/^X//" >'pathname.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1985 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Berkeley. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- X#ifndef lint
- Xstatic char sccsid[] = "@(#)pathname.c 5.2 (Berkeley) 6/27/88";
- X#endif /* not lint */
- X
- X/*
- X * Hunt
- X * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- X * San Francisco, California
- X */
- X
- X/*
- X * There is no particular significance to the numbers assigned
- X * to Test_port and Sock_port. They're just random numbers greater
- X * than then range reserved for privileged sockets.
- X */
- X
- X# ifdef DEBUG
- X
- Xchar *Driver = "/va/conrad/games/src/hunt/hunt.driver.dbg";
- X# ifdef INTERNET
- Xint Test_port = ('h' << 8) | 't';
- Xint Sock_port = ('h' << 8) | 's';
- X# else INTERNET
- Xchar *Sock_name = "/tmp/hunt";
- X# endif INTERNET
- X
- X# else DEBUG
- X
- Xchar *Driver = "/a/beowulf/home/beowulf/class/cse264c/cse264ce/Hunt/hunt.driver";
- X# ifdef INTERNET
- Xint Test_port = ('h' << 8) | 't';
- Xint Sock_port = ('h' << 8) | 's';
- X# else INTERNET
- Xchar *Sock_name = "/tmp/hunt";
- X# endif INTERNET
- X
- X# endif DEBUG
- X
- X# ifndef pdp11
- X# define RN random()
- X# else pdp11
- X# define RN ((Seed = Seed * 11109 + 13849) & 0x7fff)
- X# endif pdp11
- X
- Xint Seed = 0;
- X
- X/*
- X * rand_num:
- X * Return a random number in a given range.
- X */
- Xrand_num(range)
- Xint range;
- X{
- X return (range == 0 ? 0 : RN % range);
- X}
- END_OF_FILE
- if test 1992 -ne `wc -c <'pathname.c'`; then
- echo shar: \"'pathname.c'\" unpacked with wrong size!
- fi
- # end of 'pathname.c'
- fi
- if test -f 'terminal.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'terminal.c'\"
- else
- echo shar: Extracting \"'terminal.c'\" \(2652 characters\)
- sed "s/^X//" >'terminal.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1985 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Berkeley. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- X#ifndef lint
- Xstatic char sccsid[] = "@(#)terminal.c 5.2 (Berkeley) 6/27/88";
- X#endif /* not lint */
- X
- X/*
- X * Hunt
- X * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- X * San Francisco, California
- X */
- X
- X# include "hunt.h"
- X# define TERM_WIDTH 80 /* Assume terminals are 80-char wide */
- X
- X/*
- X * cgoto:
- X * Move the cursor to the given position on the given player's
- X * terminal.
- X */
- Xcgoto(pp, y, x)
- Xregister PLAYER *pp;
- Xregister int y, x;
- X{
- X if (x == pp->p_curx && y == pp->p_cury)
- X return;
- X sendcom(pp, MOVE, y, x);
- X pp->p_cury = y;
- X pp->p_curx = x;
- X}
- X
- X/*
- X * outch:
- X * Put out a single character.
- X */
- Xoutch(pp, ch)
- Xregister PLAYER *pp;
- Xchar ch;
- X{
- X if (++pp->p_curx >= TERM_WIDTH) {
- X pp->p_curx = 0;
- X pp->p_cury++;
- X }
- X (void) putc(ch, pp->p_output);
- X}
- X
- X/*
- X * outstr:
- X * Put out a string of the given length.
- X */
- Xoutstr(pp, str, len)
- Xregister PLAYER *pp;
- Xregister char *str;
- Xregister int len;
- X{
- X pp->p_curx += len;
- X pp->p_cury += (pp->p_curx / TERM_WIDTH);
- X pp->p_curx %= TERM_WIDTH;
- X while (len--)
- X (void) putc(*str++, pp->p_output);
- X}
- X
- X/*
- X * clrscr:
- X * Clear the screen, and reset the current position on the screen.
- X */
- Xclrscr(pp)
- Xregister PLAYER *pp;
- X{
- X sendcom(pp, CLEAR);
- X pp->p_cury = 0;
- X pp->p_curx = 0;
- X}
- X
- X/*
- X * ce:
- X * Clear to the end of the line
- X */
- Xce(pp)
- XPLAYER *pp;
- X{
- X sendcom(pp, CLRTOEOL);
- X}
- X
- X/*
- X * ref;
- X * Refresh the screen
- X */
- Xref(pp)
- Xregister PLAYER *pp;
- X{
- X sendcom(pp, REFRESH);
- X}
- X
- X/*
- X * sendcom:
- X * Send a command to the given user
- X */
- X/* VARARGS2 */
- Xsendcom(pp, command, arg1, arg2)
- Xregister PLAYER *pp;
- Xregister int command;
- Xint arg1, arg2;
- X{
- X (void) putc(command, pp->p_output);
- X switch (command & 0377) {
- X case MOVE:
- X (void) putc(arg1, pp->p_output);
- X (void) putc(arg2, pp->p_output);
- X break;
- X case ADDCH:
- X case READY:
- X (void) putc(arg1, pp->p_output);
- X break;
- X }
- X}
- END_OF_FILE
- if test 2652 -ne `wc -c <'terminal.c'`; then
- echo shar: \"'terminal.c'\" unpacked with wrong size!
- fi
- # end of 'terminal.c'
- fi
- echo shar: End of archive 4 \(of 4\).
- cp /dev/null ark4isdone
- MISSING=""
- for I in 1 2 3 4 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 4 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
-