From 77e3814f0c0e3dea4d0032e25666f77e6f83bfff Mon Sep 17 00:00:00 2001 From: cgd Date: Sun, 21 Mar 1993 09:45:37 +0000 Subject: initial import of 386bsd-0.1 sources --- robots/Makefile | 16 +++ robots/extern.c | 75 +++++++++++++ robots/flush_in.c | 51 +++++++++ robots/init_field.c | 117 ++++++++++++++++++++ robots/main.c | 196 ++++++++++++++++++++++++++++++++++ robots/make_level.c | 89 ++++++++++++++++ robots/move.c | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++++ robots/move_robs.c | 152 ++++++++++++++++++++++++++ robots/pathnames.h | 36 +++++++ robots/play_level.c | 115 ++++++++++++++++++++ robots/query.c | 60 +++++++++++ robots/rnd_pos.c | 68 ++++++++++++ robots/robots.6 | 141 +++++++++++++++++++++++++ robots/robots.h | 110 +++++++++++++++++++ robots/score.c | 184 ++++++++++++++++++++++++++++++++ 15 files changed, 1709 insertions(+) create mode 100644 robots/Makefile create mode 100644 robots/extern.c create mode 100644 robots/flush_in.c create mode 100644 robots/init_field.c create mode 100644 robots/main.c create mode 100644 robots/make_level.c create mode 100644 robots/move.c create mode 100644 robots/move_robs.c create mode 100644 robots/pathnames.h create mode 100644 robots/play_level.c create mode 100644 robots/query.c create mode 100644 robots/rnd_pos.c create mode 100644 robots/robots.6 create mode 100644 robots/robots.h create mode 100644 robots/score.c (limited to 'robots') diff --git a/robots/Makefile b/robots/Makefile new file mode 100644 index 00000000..264b77b3 --- /dev/null +++ b/robots/Makefile @@ -0,0 +1,16 @@ +# @(#)Makefile 5.10 (Berkeley) 5/11/90 + +PROG= robots +CFLAGS+=-DMAX_PER_UID=5 +SRCS= extern.c init_field.c main.c make_level.c move.c move_robs.c \ + play_level.c query.c rnd_pos.c score.c flush_in.c +MAN6= robots.0 +DPADD= ${LIBCURSES} ${LIBTERM} ${LIBCOMPAT} +LDADD= -lcurses -ltermlib -lcompat +HIDEGAME=hidegame + +beforeinstall: + install -c -o ${BINOWN} -g ${BINGRP} -m 600 /dev/null \ + ${DESTDIR}/var/games/robots_roll + +.include diff --git a/robots/extern.c b/robots/extern.c new file mode 100644 index 00000000..86d2f757 --- /dev/null +++ b/robots/extern.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)extern.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +bool Dead; /* Player is now dead */ +bool Full_clear = TRUE; /* Lots of junk for init_field to clear */ +bool Jump = FALSE; /* Jump while running, counting, or waiting */ +bool Newscore; /* There was a new score added */ +#ifdef FANCY +bool Pattern_roll = FALSE; /* Auto play for YHBJNLUK pattern */ +#endif +bool Real_time = FALSE; /* Play in real time? */ +bool Running = FALSE; /* Currently in the middle of a run */ +#ifdef FANCY +bool Stand_still = FALSE; /* Auto play for standing still pattern */ +#endif +bool Teleport = FALSE; /* Teleport automatically when player must */ +bool Waiting; /* Player is waiting for end */ +bool Was_bonus = FALSE; /* Was a bonus last level */ + +char Cnt_move; /* Command which has preceded the count */ +char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itslef */ +char *Next_move; /* Next move to be used in the pattern */ +char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ +char Run_ch; /* Character for the direction we are running */ + +int Count = 0; /* Command count */ +int Level; /* Current level */ +int Num_robots; /* Number of robots left */ +int Num_scores; /* Number of scores posted */ +int Score; /* Current score */ +int Start_level = 1; /* Level on which to start */ +int Wait_bonus; /* bonus for waiting */ + +COORD Max; /* Max area robots take up */ +COORD Min; /* Min area robots take up */ +COORD My_pos; /* Player's current position */ +COORD Robots[MAXROBOTS]; /* Robots' current positions */ + +jmp_buf End_move; /* Jump to on Real_time */ diff --git a/robots/flush_in.c b/robots/flush_in.c new file mode 100644 index 00000000..13db1e7b --- /dev/null +++ b/robots/flush_in.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)flush_in.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include + +/* + * flush_in: + * Flush all pending input. + */ +flush_in() +{ +# ifdef TIOCFLUSH + ioctl(fileno(stdin), TIOCFLUSH, NULL); +# else TIOCFLUSH + crmode(); +# endif TIOCFLUSH +} diff --git a/robots/init_field.c b/robots/init_field.c new file mode 100644 index 00000000..7fa5c0da --- /dev/null +++ b/robots/init_field.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)init_field.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +/* + * init_field: + * Lay down the initial pattern whih is constant across all levels, + * and initialize all the global variables. + */ +init_field() +{ + register int i; + register WINDOW *wp; + register int j; + static bool first = TRUE; + static char *desc[] = { + "Directions:", + "", + "y k u", + " \\|/", + "h- -l", + " /|\\", + "b j n", + "", + "Commands:", + "", + "w: wait for end", + "t: teleport", + "q: quit", + "^L: redraw screen", + "", + "Legend:", + "", + "+: robot", + "*: junk heap", + "@: you", + "", + "Score: 0", + NULL + }; + + Dead = FALSE; + Waiting = FALSE; + flushok(stdscr, TRUE); + Score = 0; + + erase(); + move(0, 0); + addch('+'); + for (i = 1; i < Y_FIELDSIZE; i++) { + move(i, 0); + addch('|'); + } + move(Y_FIELDSIZE, 0); + addch('+'); + for (i = 1; i < X_FIELDSIZE; i++) + addch('-'); + addch('+'); + if (first) + refresh(); + move(0, 1); + for (i = 1; i < X_FIELDSIZE; i++) + addch('-'); + addch('+'); + for (i = 1; i < Y_FIELDSIZE; i++) { + move(i, X_FIELDSIZE); + addch('|'); + } + if (first) + refresh(); + for (i = 0; desc[i] != NULL; i++) { + move(i, X_FIELDSIZE + 2); + addstr(desc[i]); + } + if (first) + refresh(); + first = FALSE; +#ifdef FANCY + if (Pattern_roll) + Next_move = &Move_list[-1]; +#endif +} diff --git a/robots/main.c b/robots/main.c new file mode 100644 index 00000000..d30928b7 --- /dev/null +++ b/robots/main.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +char copyright[] = +"@(#) Copyright (c) 1980 Regents of the University of California.\n\ + All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 2/28/91"; +#endif /* not lint */ + +# include "robots.h" +# include +# include + +main(ac, av) +int ac; +char **av; +{ + register char *sp; + register bool bad_arg; + register bool show_only; + extern char *Scorefile; + extern int Max_per_uid; + void quit(); + + show_only = FALSE; + if (ac > 1) { + bad_arg = FALSE; + for (++av; ac > 1 && *av[0]; av++, ac--) + if (av[0][0] != '-') + if (isdigit(av[0][0])) + Max_per_uid = atoi(av[0]); + else { + setuid(getuid()); + setgid(getgid()); + Scorefile = av[0]; +# ifdef FANCY + sp = rindex(Scorefile, '/'); + if (sp == NULL) + sp = Scorefile; + if (strcmp(sp, "pattern_roll") == 0) + Pattern_roll = TRUE; + else if (strcmp(sp, "stand_still") == 0) + Stand_still = TRUE; + if (Pattern_roll || Stand_still) + Teleport = TRUE; +# endif + } + else + for (sp = &av[0][1]; *sp; sp++) + switch (*sp) { + case 's': + show_only = TRUE; + break; + case 'r': + Real_time = TRUE; + break; + case 'a': + Start_level = 4; + break; + case 'j': + Jump = TRUE; + break; + case 't': + Teleport = TRUE; + break; + default: + fprintf(stderr, "robots: uknown option: %c\n", *sp); + bad_arg = TRUE; + break; + } + if (bad_arg) { + exit(1); + /* NOTREACHED */ + } + } + + if (show_only) { + show_score(); + exit(0); + /* NOTREACHED */ + } + + initscr(); + signal(SIGINT, quit); + crmode(); + noecho(); + nonl(); + if (LINES != Y_SIZE || COLS != X_SIZE) { + if (LINES < Y_SIZE || COLS < X_SIZE) { + endwin(); + printf("Need at least a %dx%d screen\n", + Y_SIZE, X_SIZE); + exit(1); + } + delwin(stdscr); + stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); + } + + srand(getpid()); + if (Real_time) + signal(SIGALRM, move_robots); + do { + init_field(); + for (Level = Start_level; !Dead; Level++) { + make_level(); + play_level(); + } + move(My_pos.y, My_pos.x); + printw("AARRrrgghhhh...."); + refresh(); + score(); + } while (another()); + quit(); +} + +/* + * quit: + * Leave the program elegantly. + */ +void +quit() +{ + extern int _putchar(); + + mvcur(0, COLS - 1, LINES - 1, 0); + if (CE) { + tputs(CE, 1, _putchar); + endwin(); + } + else { + endwin(); + putchar('\n'); + } + exit(0); + /* NOTREACHED */ +} + +/* + * another: + * See if another game is desired + */ +another() +{ + register int y; + +#ifdef FANCY + if ((Stand_still || Pattern_roll) && !Newscore) + return TRUE; +#endif + + if (query("Another game?")) { + if (Full_clear) { + for (y = 1; y <= Num_scores; y++) { + move(y, 1); + clrtoeol(); + } + refresh(); + } + return TRUE; + } + return FALSE; +} diff --git a/robots/make_level.c b/robots/make_level.c new file mode 100644 index 00000000..422a7fc2 --- /dev/null +++ b/robots/make_level.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)make_level.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +/* + * make_level: + * Make the current level + */ +make_level() +{ + register int i; + register COORD *cp; + register WINDOW *wp; + register int x, *endp; + + reset_count(); + for (i = 1; i < Y_FIELDSIZE; i++) + for (x = 1; x < X_FIELDSIZE; x++) + if (Field[i][x] != 0) + mvaddch(i, x, ' '); + if (My_pos.y > 0) + mvaddch(My_pos.y, My_pos.x, ' '); + + Waiting = FALSE; + Wait_bonus = 0; + leaveok(stdscr, FALSE); + for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) + cp->y = -1; + My_pos.y = -1; + + bzero(Field, sizeof Field); + Min.y = Y_FIELDSIZE; + Min.x = X_FIELDSIZE; + Max.y = 0; + Max.x = 0; + if ((i = Level * 10) > MAXROBOTS) + i = MAXROBOTS; + Num_robots = i; + while (i-- > 0) { + cp = rnd_pos(); + Robots[i] = *cp; + Field[cp->y][cp->x]++; + if (cp->y < Min.y) + Min.y = cp->y; + if (cp->x < Min.x) + Min.x = cp->x; + if (cp->y > Max.y) + Max.y = cp->y; + if (cp->x > Max.x) + Max.x = cp->x; + } + My_pos = *rnd_pos(); + refresh(); +} diff --git a/robots/move.c b/robots/move.c new file mode 100644 index 00000000..79364440 --- /dev/null +++ b/robots/move.c @@ -0,0 +1,299 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)move.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" +# include + +# define ESC '\033' + +/* + * get_move: + * Get and execute a move from the player + */ +get_move() +{ + register int c; + register int y, x, lastmove; + static COORD newpos; + + if (Waiting) + return; + +#ifdef FANCY + if (Pattern_roll) { + if (Next_move >= Move_list) + lastmove = *Next_move; + else + lastmove = -1; /* flag for "first time in" */ + } +#endif + for (;;) { + if (Teleport && must_telep()) + goto teleport; + if (Running) + c = Run_ch; + else if (Count != 0) + c = Cnt_move; +#ifdef FANCY + else if (Num_robots > 1 && Stand_still) + c = '>'; + else if (Num_robots > 1 && Pattern_roll) { + if (*++Next_move == '\0') { + if (lastmove < 0) + goto over; + Next_move = Move_list; + } + c = *Next_move; + mvaddch(0, 0, c); + if (c == lastmove) + goto over; + } +#endif + else { +over: + c = getchar(); + if (isdigit(c)) { + Count = (c - '0'); + while (isdigit(c = getchar())) + Count = Count * 10 + (c - '0'); + if (c == ESC) + goto over; + Cnt_move = c; + if (Count) + leaveok(stdscr, TRUE); + } + } + + switch (c) { + case ' ': + case '.': + if (do_move(0, 0)) + goto ret; + break; + case 'y': + if (do_move(-1, -1)) + goto ret; + break; + case 'k': + if (do_move(-1, 0)) + goto ret; + break; + case 'u': + if (do_move(-1, 1)) + goto ret; + break; + case 'h': + if (do_move(0, -1)) + goto ret; + break; + case 'l': + if (do_move(0, 1)) + goto ret; + break; + case 'b': + if (do_move(1, -1)) + goto ret; + break; + case 'j': + if (do_move(1, 0)) + goto ret; + break; + case 'n': + if (do_move(1, 1)) + goto ret; + break; + case 'Y': case 'U': case 'H': case 'J': + case 'K': case 'L': case 'B': case 'N': + case '>': + Running = TRUE; + if (c == '>') + Run_ch = ' '; + else + Run_ch = tolower(c); + leaveok(stdscr, TRUE); + break; + case 'q': + case 'Q': + if (query("Really quit?")) + quit(); + refresh(); + break; + case 'w': + case 'W': + Waiting = TRUE; + leaveok(stdscr, TRUE); + flushok(stdscr, FALSE); + goto ret; + case 't': + case 'T': +teleport: + Running = FALSE; + mvaddch(My_pos.y, My_pos.x, ' '); + My_pos = *rnd_pos(); + mvaddch(My_pos.y, My_pos.x, PLAYER); + leaveok(stdscr, FALSE); + refresh(); + flush_in(); + goto ret; + case CTRL(L): + wrefresh(curscr); + break; + case EOF: + break; + default: + putchar(CTRL(G)); + reset_count(); + fflush(stdout); + break; + } + } +ret: + if (Count > 0) + if (--Count == 0) + leaveok(stdscr, FALSE); +} + +/* + * must_telep: + * Must I teleport; i.e., is there anywhere I can move without + * being eaten? + */ +must_telep() +{ + register int x, y; + static COORD newpos; + +#ifdef FANCY + if (Stand_still && Num_robots > 1 && eaten(&My_pos)) + return TRUE; +#endif + + for (y = -1; y <= 1; y++) { + newpos.y = My_pos.y + y; + if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE) + continue; + for (x = -1; x <= 1; x++) { + newpos.x = My_pos.x + x; + if (newpos.x <= 0 || newpos.x >= X_FIELDSIZE) + continue; + if (Field[newpos.y][newpos.x] > 0) + continue; + if (!eaten(&newpos)) + return FALSE; + } + } + return TRUE; +} + +/* + * do_move: + * Execute a move + */ +do_move(dy, dx) +int dy, dx; +{ + static COORD newpos; + + newpos.y = My_pos.y + dy; + newpos.x = My_pos.x + dx; + if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE || + newpos.x <= 0 || newpos.x >= X_FIELDSIZE || + Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) { + if (Running) { + Running = FALSE; + leaveok(stdscr, FALSE); + move(My_pos.y, My_pos.x); + refresh(); + } + else { + putchar(CTRL(G)); + reset_count(); + } + return FALSE; + } + else if (dy == 0 && dx == 0) + return TRUE; + mvaddch(My_pos.y, My_pos.x, ' '); + My_pos = newpos; + mvaddch(My_pos.y, My_pos.x, PLAYER); + if (!jumping()) + refresh(); + return TRUE; +} + +/* + * eaten: + * Player would get eaten at this place + */ +eaten(pos) +register COORD *pos; +{ + register int x, y; + + for (y = pos->y - 1; y <= pos->y + 1; y++) { + if (y <= 0 || y >= Y_FIELDSIZE) + continue; + for (x = pos->x - 1; x <= pos->x + 1; x++) { + if (x <= 0 || x >= X_FIELDSIZE) + continue; + if (Field[y][x] == 1) + return TRUE; + } + } + return FALSE; +} + +/* + * reset_count: + * Reset the count variables + */ +reset_count() +{ + Count = 0; + Running = FALSE; + leaveok(stdscr, FALSE); + refresh(); +} + +/* + * jumping: + * See if we are jumping, i.e., we should not refresh. + */ +jumping() +{ + return (Jump && (Count || Running || Waiting)); +} diff --git a/robots/move_robs.c b/robots/move_robs.c new file mode 100644 index 00000000..4eaa5b52 --- /dev/null +++ b/robots/move_robs.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)move_robs.c 5.5 (Berkeley) 2/28/91"; +#endif /* not lint */ + +# include "robots.h" +# include + +/* + * move_robots: + * Move the robots around + */ +void +move_robots(was_sig) +bool was_sig; +{ + register COORD *rp; + register int y, x; + register int mindist, d; + static COORD newpos; + + if (Real_time) + signal(SIGALRM, move_robots); +# ifdef DEBUG + move(Min.y, Min.x); + addch(inch()); + move(Max.y, Max.x); + addch(inch()); +# endif DEBUG + for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) { + if (rp->y < 0) + continue; + mvaddch(rp->y, rp->x, ' '); + Field[rp->y][rp->x]--; + rp->y += sign(My_pos.y - rp->y); + rp->x += sign(My_pos.x - rp->x); + if (rp->y <= 0) + rp->y = 0; + else if (rp->y >= Y_FIELDSIZE) + rp->y = Y_FIELDSIZE - 1; + if (rp->x <= 0) + rp->x = 0; + else if (rp->x >= X_FIELDSIZE) + rp->x = X_FIELDSIZE - 1; + Field[rp->y][rp->x]++; + } + + Min.y = Y_FIELDSIZE; + Min.x = X_FIELDSIZE; + Max.y = 0; + Max.x = 0; + for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) + if (rp->y < 0) + continue; + else if (rp->y == My_pos.y && rp->x == My_pos.x) + Dead = TRUE; + else if (Field[rp->y][rp->x] > 1) { + mvaddch(rp->y, rp->x, HEAP); + rp->y = -1; + Num_robots--; + if (Waiting) + Wait_bonus++; + add_score(ROB_SCORE); + } + else { + mvaddch(rp->y, rp->x, ROBOT); + if (rp->y < Min.y) + Min.y = rp->y; + if (rp->x < Min.x) + Min.x = rp->x; + if (rp->y > Max.y) + Max.y = rp->y; + if (rp->x > Max.x) + Max.x = rp->x; + } + + if (was_sig) { + refresh(); + if (Dead || Num_robots <= 0) + longjmp(End_move, 0); + } + +# ifdef DEBUG + standout(); + move(Min.y, Min.x); + addch(inch()); + move(Max.y, Max.x); + addch(inch()); + standend(); +# endif DEBUG + if (Real_time) + alarm(3); +} + +/* + * add_score: + * Add a score to the overall point total + */ +add_score(add) +int add; +{ + Score += add; + move(Y_SCORE, X_SCORE); + printw("%d", Score); +} + +/* + * sign: + * Return the sign of the number + */ +sign(n) +int n; +{ + if (n < 0) + return -1; + else if (n > 0) + return 1; + else + return 0; +} diff --git a/robots/pathnames.h b/robots/pathnames.h new file mode 100644 index 00000000..ec0784bd --- /dev/null +++ b/robots/pathnames.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)pathnames.h 5.1 (Berkeley) 5/2/90 + */ + +#define _PATH_SCORE "/var/games/robots_roll" diff --git a/robots/play_level.c b/robots/play_level.c new file mode 100644 index 00000000..887560ad --- /dev/null +++ b/robots/play_level.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)play_level.c 5.5 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +/* + * play_level: + * Let the player play the current level + */ +play_level() +{ + register COORD *cp; + register int y, x, bonus; + + move(My_pos.y, My_pos.x); + addch(PLAYER); + refresh(); + for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) { + if (cp->y < 0) + continue; + move(cp->y, cp->x); + addch(ROBOT); + } + refresh(); +# ifdef DEBUG + standout(); + move(Min.y, Min.x); + addch(inch()); + move(Max.y, Max.x); + addch(inch()); + standend(); +# endif DEBUG + setjmp(End_move); + flush_in(); + while (!Dead && Num_robots > 0) { + move(My_pos.y, My_pos.x); + if (!jumping()) + refresh(); + get_move(); + if (Real_time) + alarm(0); + if (Field[My_pos.y][My_pos.x] != 0) + Dead = TRUE; + if (!Dead) + move_robots(FALSE); + if (Was_bonus) { + move(Y_PROMPT, X_PROMPT); + clrtoeol(); + move(Y_PROMPT + 1, X_PROMPT); + clrtoeol(); + Was_bonus = FALSE; + } + } + + /* + * if the player didn't die, add on the possible bonuses + */ + + if (!Dead) { + Was_bonus = FALSE; + + if (Level == Start_level && Start_level > 1) { + move(Y_PROMPT, X_PROMPT); + printw("Advance bonus: %d", S_BONUS); + refresh(); + add_score(S_BONUS); + Was_bonus = TRUE; + } + + if (Wait_bonus != 0) { + if (!Was_bonus) + move(Y_PROMPT, X_PROMPT); + else + move(Y_PROMPT + 1, X_PROMPT); + printw("Wait bonus: %d", Wait_bonus); + refresh(); + add_score(Wait_bonus); + Was_bonus = TRUE; + } + } +} diff --git a/robots/query.c b/robots/query.c new file mode 100644 index 00000000..fecf608c --- /dev/null +++ b/robots/query.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)query.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +/* + * query: + * Ask a question and get a yes or no answer. Default is "no". + */ +query(prompt) +char *prompt; +{ + register int c, retval; + register int y, x; + + getyx(stdscr, y, x); + move(Y_PROMPT, X_PROMPT); + addstr(prompt); + clrtoeol(); + refresh(); + retval = ((c = getchar()) == 'y' || c == 'Y'); + move(Y_PROMPT, X_PROMPT); + clrtoeol(); + move(y, x); + return retval; +} diff --git a/robots/rnd_pos.c b/robots/rnd_pos.c new file mode 100644 index 00000000..0e49ff50 --- /dev/null +++ b/robots/rnd_pos.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)rnd_pos.c 5.4 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" + +# define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) + +/* + * rnd_pos: + * Pick a random, unoccupied position + */ +COORD * +rnd_pos() +{ + static COORD pos; + static int call = 0; + register int i = 0; + + do { + pos.y = rnd(Y_FIELDSIZE - 1) + 1; + pos.x = rnd(X_FIELDSIZE - 1) + 1; + refresh(); + } while (Field[pos.y][pos.x] != 0); + call++; + return &pos; +} + +rnd(range) +int range; +{ + unsigned int rand(); + + return rand() % range; +} diff --git a/robots/robots.6 b/robots/robots.6 new file mode 100644 index 00000000..0f76c952 --- /dev/null +++ b/robots/robots.6 @@ -0,0 +1,141 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)robots.6 6.2 (Berkeley) 4/8/91 +.\" +.TH ROBOTS 6 "April 8, 1991" +.UC 6 +.SH NAME +robots \- fight off villainous robots +.SH SYNOPSIS +.B robots +[ +.B \-sjta +] [ +.B scorefile +] +.SH DESCRIPTION +.I Robots +pits you against evil robots, who are trying to kill you (which is why +they are evil). +Fortunately for you, even though they are evil, they are not very bright +and have a habit of bumping into each other, thus destroying themselves. +In order to survive, you must get them to kill each other off, since you +have no offensive weaponry. +.PP +Since you are stuck without offensive weaponry, you are endowed with one +piece of defensive weaponry: a teleportation device. +When two robots run into each other or a junk pile, they die. +If a robot runs into you, you die. +When a robot dies, you get 10 points, and when all the robots die, +you start on the next field. +This keeps up until they finally get you. +.PP +Robots are represented on the screen by a +.RB ` + ', +the junk heaps from their collisions by a +.RB ` \(** ', +and you +(the good guy) +by a +.RB ` @ '. +.PP +The commands are: +.sp +.nf +.ta +.ta \w'\fBHJKLBNYU\fP\ \ 'u +\fBh\fP move one square left +\fBl\fP move one square right +\fBk\fP move one square up +\fBj\fP move one square down +\fBy\fP move one square up and left +\fBu\fP move one square up and right +\fBb\fP move one square down and left +\fBn\fP move one square down and right +\fB\&.\fP (also space) do nothing for one turn +\fBHJKLBNYU\fP run as far as possible in the given direction +\fB>\fP do nothing for as long as possible +\fBt\fP teleport to a random location +\fBw\fP wait until you die or they all do +\fBq\fP quit +\fB^L\fP redraw the screen +.sp +.fi +All commands can be preceded by a count. +.PP +If you use the +.RB ` w ' +command and survive to the next level, you will get a bonus of 10% +for each robot which died after you decided to wait. +If you die, however, you get nothing. +For all other commands, the program will save you from typos +by stopping short of being eaten. +However, with +.RB ` w ' +you take the risk of dying by miscalculation. +.PP +Only five scores are allowed per user on the score file. +If you make it into the score file, you will be shown the list at the end +of the game. +If an alternate score file is specified, that will be used instead of the +standard file for scores. +.PP +The options are +.TP +.B \-s +Don't play, just show the score file. +.TP +.B \-j +Jump, +.IR i.e. , +when you run, don't show any intermediate positions; only show things at +the end. +This is useful on slow terminals. +.TP +.B \-t +Teleport automatically when you have no other option. +This is a little disconcerting until you get used to it, and then it is +very nice. +.TP +.B \-a +Advance into the higher levels directly, skipping the lower, easier levels. +.SH AUTHOR +Ken Arnold +.SH FILES +.ta +.ta \w'/usr/games/lib/robots_roll\ \ \ \ 'u +/usr/games/lib/robots_roll the score file +.SH BUGS +Bugs? +You +.IR crazy , +man?!? diff --git a/robots/robots.h b/robots/robots.h new file mode 100644 index 00000000..cafea703 --- /dev/null +++ b/robots/robots.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)robots.h 5.6 (Berkeley) 2/28/91 + */ + +# include +# include + +/* + * miscellaneous constants + */ + +# define Y_FIELDSIZE 23 +# define X_FIELDSIZE 60 +# define Y_SIZE 24 +# define X_SIZE 80 +# define MAXLEVELS 4 +# define MAXROBOTS (MAXLEVELS * 10) +# define ROB_SCORE 10 +# define S_BONUS (60 * ROB_SCORE) +# define Y_SCORE 21 +# define X_SCORE (X_FIELDSIZE + 9) +# define Y_PROMPT (Y_FIELDSIZE - 1) +# define X_PROMPT (X_FIELDSIZE + 2) +# define MAXSCORES (Y_SIZE - 2) +# define MAXNAME 16 +# define MS_NAME "Ten" + +/* + * characters on screen + */ + +# define ROBOT '+' +# define HEAP '*' +# define PLAYER '@' + +/* + * pseudo functions + */ + +# undef CTRL +# define CTRL(X) ('X' - 'A' + 1) + +/* + * type definitions + */ + +typedef struct { + int y, x; +} COORD; + +/* + * global variables + */ + +extern bool Dead, Full_clear, Jump, Newscore, Real_time, Running, + Teleport, Waiting, Was_bonus; + +#ifdef FANCY +extern bool Pattern_roll, Stand_still; +#endif + +extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], *Next_move, + *Move_list, Run_ch; + +extern int Count, Level, Num_robots, Num_scores, Score, + Start_level, Wait_bonus; + +extern COORD Max, Min, My_pos, Robots[]; + +extern jmp_buf End_move; + +/* + * functions types + */ + +int cmp_sc(); +void move_robots(); + +COORD *rnd_pos(); diff --git a/robots/score.c b/robots/score.c new file mode 100644 index 00000000..fc0fb757 --- /dev/null +++ b/robots/score.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)score.c 5.6 (Berkeley) 6/1/90"; +#endif /* not lint */ + +# include "robots.h" +# include +# include +# include "pathnames.h" + +typedef struct { + int s_uid; + int s_score; + char s_name[MAXNAME]; +} SCORE; + +typedef struct passwd PASSWD; + +char *Scorefile = _PATH_SCORE; + +int Max_per_uid = MAX_PER_UID; + +static SCORE Top[MAXSCORES]; + +/* + * score: + * Post the player's score, if reasonable, and then print out the + * top list. + */ +score() +{ + register int inf; + register SCORE *scp; + register int uid; + register bool done_show = FALSE; + static int numscores, max_uid; + + Newscore = FALSE; + if ((inf = open(Scorefile, 2)) < 0) { + perror(Scorefile); + return; + } + + if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid) + read(inf, Top, sizeof Top); + else { + for (scp = Top; scp < &Top[MAXSCORES]; scp++) + scp->s_score = -1; + max_uid = Max_per_uid; + } + + uid = getuid(); + if (Top[MAXSCORES-1].s_score <= Score) { + numscores = 0; + for (scp = Top; scp < &Top[MAXSCORES]; scp++) + if (scp->s_score < 0 || + (scp->s_uid == uid && ++numscores == max_uid)) { + if (scp->s_score > Score) + break; + scp->s_score = Score; + scp->s_uid = uid; + set_name(scp); + Newscore = TRUE; + break; + } + if (scp == &Top[MAXSCORES]) { + Top[MAXSCORES-1].s_score = Score; + Top[MAXSCORES-1].s_uid = uid; + set_name(&Top[MAXSCORES-1]); + Newscore = TRUE; + } + if (Newscore) + qsort(Top, MAXSCORES, sizeof Top[0], cmp_sc); + } + + if (!Newscore) { + Full_clear = FALSE; + close(inf); + return; + } + else + Full_clear = TRUE; + + for (scp = Top; scp < &Top[MAXSCORES]; scp++) { + if (scp->s_score < 0) + break; + move((scp - Top) + 1, 15); + if (!done_show && scp->s_uid == uid && scp->s_score == Score) + standout(); + printw(" %d\t%d\t%-8.8s ", (scp - Top) + 1, scp->s_score, scp->s_name); + if (!done_show && scp->s_uid == uid && scp->s_score == Score) { + standend(); + done_show = TRUE; + } + } + Num_scores = scp - Top; + refresh(); + + if (Newscore) { + lseek(inf, 0L, 0); + write(inf, &max_uid, sizeof max_uid); + write(inf, Top, sizeof Top); + } + close(inf); +} + +set_name(scp) +register SCORE *scp; +{ + register PASSWD *pp; + + if ((pp = getpwuid(scp->s_uid)) == NULL) + pp->pw_name = "???"; + strncpy(scp->s_name, pp->pw_name, MAXNAME); +} + +/* + * cmp_sc: + * Compare two scores. + */ +cmp_sc(s1, s2) +register SCORE *s1, *s2; +{ + return s2->s_score - s1->s_score; +} + +/* + * show_score: + * Show the score list for the '-s' option. + */ +show_score() +{ + register SCORE *scp; + register int inf; + static int max_score; + + if ((inf = open(Scorefile, 0)) < 0) { + perror(Scorefile); + return; + } + + for (scp = Top; scp < &Top[MAXSCORES]; scp++) + scp->s_score = -1; + + read(inf, &max_score, sizeof max_score); + read(inf, Top, sizeof Top); + close(inf); + inf = 1; + for (scp = Top; scp < &Top[MAXSCORES]; scp++) + if (scp->s_score >= 0) + printf("%d\t%d\t%.*s\n", inf++, scp->s_score, sizeof scp->s_name, scp->s_name); +} -- cgit v1.2.3-56-ge451