Initial revision

git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
joey
1999-09-08 23:56:51 +00:00
commit 03272d67da
623 changed files with 243457 additions and 0 deletions

14
robots/Makefile.bsd Normal file
View File

@@ -0,0 +1,14 @@
# $NetBSD: Makefile,v 1.14 1998/02/18 22:37:32 jtc Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= robots
CPPFLAGS+=-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
MAN= robots.6
DPADD= ${LIBCURSES}
LDADD= -lcurses
HIDEGAME=hidegame
SETGIDGAME=yes
.include <bsd.prog.mk>

12
robots/Makefrag Normal file
View File

@@ -0,0 +1,12 @@
# Makefile - makefile for robots
robots_DEFS := -DFANCY -DMAX_PER_UID=5
robots_DIRS := $(GAMESDIR) $(MAN6DIR)
robots_all: robots/robots robots/robots.6
robots_install: robots_all
$(INSTALL_SCORE_GAME) robots/robots $(INSTALL_PREFIX)$(GAMESDIR)/robots
$(HIDE_GAME) robots
$(INSTALL_SCORE_FILE) $(ROBOTS_SCOREFILE)
$(INSTALL_MANUAL) robots/robots.6

82
robots/extern.c Normal file
View File

@@ -0,0 +1,82 @@
/* $NetBSD: extern.c,v 1.4 1997/10/12 14:09:56 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: extern.c,v 1.4 1997/10/12 14:09:56 lukem Exp $");
#endif
#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 */

55
robots/flush_in.c Normal file
View File

@@ -0,0 +1,55 @@
/* $NetBSD: flush_in.c,v 1.5 1997/10/12 14:09:56 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)flush_in.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: flush_in.c,v 1.5 1997/10/12 14:09:56 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
/*
* flush_in:
* Flush all pending input.
*/
void
flush_in()
{
tcflush(fileno(stdin), TCIFLUSH);
}

122
robots/init_field.c Normal file
View File

@@ -0,0 +1,122 @@
/* $NetBSD: init_field.c,v 1.5 1997/10/12 14:09:57 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: init_field.c,v 1.5 1997/10/12 14:09:57 lukem Exp $");
#endif
#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.
*/
void
init_field()
{
int i;
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;
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
}

214
robots/main.c Normal file
View File

@@ -0,0 +1,214 @@
/* $NetBSD: main.c,v 1.7 1997/10/12 14:16:26 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: main.c,v 1.7 1997/10/12 14:16:26 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
int main __P((int, char **));
int
main(ac, av)
int ac;
char **av;
{
char *sp;
bool bad_arg;
bool show_only;
extern char *Scorefile;
extern int Max_per_uid;
int score_wfd; /* high score writable file descriptor */
int score_err = 0; /* hold errno from score file open */
score_wfd = open(Scorefile, O_RDWR);
if (score_wfd < 0)
score_err = errno;
/* Revoke setgid privileges */
setregid(getgid(), getgid());
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 {
Scorefile = av[0];
if (score_wfd >= 0)
close(score_wfd);
score_wfd = open(Scorefile, O_RDWR);
if (score_wfd < 0)
score_err = errno;
# ifdef FANCY
sp = strrchr(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 */
}
if (score_wfd < 0) {
warn("%s", Scorefile);
warnx("High scores will not be recorded!");
sleep(2);
}
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(score_wfd);
} while (another());
quit(0);
/* NOTREACHED */
return(0);
}
/*
* quit:
* Leave the program elegantly.
*/
void
quit(dummy)
int dummy __attribute__((unused));
{
endwin();
exit(0);
/* NOTREACHED */
}
/*
* another:
* See if another game is desired
*/
bool
another()
{
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;
}

96
robots/make_level.c Normal file
View File

@@ -0,0 +1,96 @@
/* $NetBSD: make_level.c,v 1.5 1997/10/12 14:16:27 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: make_level.c,v 1.5 1997/10/12 14:16:27 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
/*
* make_level:
* Make the current level
*/
void
make_level()
{
int i;
COORD *cp;
int x;
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;
memset(Field, 0, 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();
}

312
robots/move.c Normal file
View File

@@ -0,0 +1,312 @@
/* $NetBSD: move.c,v 1.7 1998/07/24 23:28:02 hubertf Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: move.c,v 1.7 1998/07/24 23:28:02 hubertf Exp $");
#endif
#endif /* not lint */
#include "robots.h"
# define ESC '\033'
/*
* get_move:
* Get and execute a move from the player
*/
void
get_move()
{
int c;
#ifdef FANCY
int lastmove;
#endif /*FANCY*/
if (Waiting)
return;
#ifdef FANCY
if (Pattern_roll) {
if (Next_move >= Move_list)
lastmove = *Next_move;
else
lastmove = -1; /* flag for "first time in" */
} else
lastmove = 0; /* Shut up gcc */
#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(0);
refresh();
break;
case 'w':
case 'W':
Waiting = TRUE;
leaveok(stdscr, TRUE);
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?
*/
bool
must_telep()
{
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
*/
bool
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
*/
bool
eaten(pos)
COORD *pos;
{
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
*/
void
reset_count()
{
Count = 0;
Running = FALSE;
leaveok(stdscr, FALSE);
refresh();
}
/*
* jumping:
* See if we are jumping, i.e., we should not refresh.
*/
bool
jumping()
{
return (Jump && (Count || Running || Waiting));
}

157
robots/move_robs.c Normal file
View File

@@ -0,0 +1,157 @@
/* $NetBSD: move_robs.c,v 1.4 1997/10/12 14:10:00 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: move_robs.c,v 1.4 1997/10/12 14:10:00 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
/*
* move_robots:
* Move the robots around
*/
void
move_robots(was_sig)
int was_sig;
{
COORD *rp;
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
*/
void
add_score(add)
int add;
{
Score += add;
move(Y_SCORE, X_SCORE);
printw("%d", Score);
}
/*
* sign:
* Return the sign of the number
*/
int
sign(n)
int n;
{
if (n < 0)
return -1;
else if (n > 0)
return 1;
else
return 0;
}

38
robots/pathnames.h.in Normal file
View File

@@ -0,0 +1,38 @@
/* $NetBSD: pathnames.h,v 1.3 1995/04/22 10:09:01 cgd Exp $ */
/*-
* Copyright (c) 1990, 1993
* 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 8.1 (Berkeley) 5/31/93
*/
#define _PATH_SCORE "@robots_scorefile@"

122
robots/play_level.c Normal file
View File

@@ -0,0 +1,122 @@
/* $NetBSD: play_level.c,v 1.4 1997/10/12 14:10:01 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)play_level.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: play_level.c,v 1.4 1997/10/12 14:10:01 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
/*
* play_level:
* Let the player play the current level
*/
void
play_level()
{
COORD *cp;
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;
}
}
}

68
robots/query.c Normal file
View File

@@ -0,0 +1,68 @@
/* $NetBSD: query.c,v 1.4 1997/10/12 14:10:01 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: query.c,v 1.4 1997/10/12 14:10:01 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
/*
* query:
* Ask a question and get a yes or no answer. Default is "no".
*/
int
query(prompt)
char *prompt;
{
int c, retval;
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;
}

74
robots/rnd_pos.c Normal file
View File

@@ -0,0 +1,74 @@
/* $NetBSD: rnd_pos.c,v 1.4 1997/10/12 14:10:02 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: rnd_pos.c,v 1.4 1997/10/12 14:10:02 lukem Exp $");
#endif
#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;
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;
}
int
rnd(range)
int range;
{
return rand() % range;
}

153
robots/robots.6.in Normal file
View File

@@ -0,0 +1,153 @@
.\" $NetBSD: robots.6,v 1.6 1997/10/12 14:10:03 lukem Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" 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 8.1 (Berkeley) 5/31/93
.\"
.Dd May 31, 1993
.Dt ROBOTS 6
.Os
.Sh NAME
.Nm robots
.Nd fight off villainous robots
.Sh SYNOPSIS
.Nm
.Op Fl sjta
.Op Ar scorefile
.Sh DESCRIPTION
.Nm
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
.Sq \+ ,
the junk heaps from their collisions by a
.Sq \(** ,
and you
(the good guy)
by a
.Sq \@ .
.Pp
The commands are:
.Bl -tag -width indent -compact
.It Ic h
move one square left
.It Ic l
move one square right
.It Ic k
move one square up
.It Ic j
move one square down
.It Ic y
move one square up and left
.It Ic u
move one square up and right
.It Ic b
move one square down and left
.It Ic n
move one square down and right
.It Ic \&.
(also space) do nothing for one turn
.It Ic HJKLBNYU
run as far as possible in the given direction
.It Ic \>
do nothing for as long as possible
.It Ic t
teleport to a random location
.It Ic w
wait until you die or they all do
.It Ic q
quit
.It Ic ^L
redraw the screen
.El
.Pp
All commands can be preceded by a count.
.Pp
If you use the
.Sq Ic 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
.Sq Ic 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 alternative score file is specified, that will be used instead of the
standard file for scores.
.Pp
The options are
.Bl -tag -width indent
.It Fl s
Don't play, just show the score file.
.It Fl j
Jump,
.Em i.e. ,
when you run, don't show any intermediate positions; only show things at
the end.
This is useful on slow terminals.
.It Fl 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.
.It Fl a
Advance into the higher levels directly, skipping the lower, easier levels.
.El
.Sh AUTHOR
Ken Arnold
.Sh FILES
.Bl -tag -width @robots_scorefile@ -compact
.It Pa @robots_scorefile@
the score file
.El
.Sh BUGS
Bugs?
You
.Em crazy ,
man?!?

143
robots/robots.h Normal file
View File

@@ -0,0 +1,143 @@
/* $NetBSD: robots.h,v 1.8 1998/09/13 15:27:29 hubertf Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.h 8.1 (Berkeley) 5/31/93
*/
# include <sys/ttydefaults.h>
# include <ctype.h>
# include <curses.h>
# include <err.h>
# include <errno.h>
# include <fcntl.h>
# include <pwd.h>
# include <setjmp.h>
# include <signal.h>
# include <stdlib.h>
# include <string.h>
# include <termios.h>
# include <unistd.h>
/*
* 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
# undef S_BONUS
# 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 '@'
/*
* type definitions
*/
typedef struct {
int y, x;
} COORD;
typedef struct {
int s_uid;
int s_score;
char s_name[MAXNAME];
} SCORE;
typedef struct passwd PASSWD;
/*
* 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
*/
void add_score __P((int));
bool another __P((void));
int cmp_sc __P((const void *, const void *));
bool do_move __P((int, int));
bool eaten __P((COORD *));
void flush_in __P((void));
void get_move __P((void));
void init_field __P((void));
bool jumping __P((void));
void make_level __P((void));
void move_robots __P((int));
bool must_telep __P((void));
void play_level __P((void));
int query __P((char *));
void quit __P((int)) __attribute__((__noreturn__));
void reset_count __P((void));
int rnd __P((int));
COORD *rnd_pos __P((void));
void score __P((int));
void set_name __P((SCORE *));
void show_score __P((void));
int sign __P((int));

185
robots/score.c Normal file
View File

@@ -0,0 +1,185 @@
/* $NetBSD: score.c,v 1.5 1997/10/12 14:16:28 lukem Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: score.c,v 1.5 1997/10/12 14:16:28 lukem Exp $");
#endif
#endif /* not lint */
# include "robots.h"
# include "pathnames.h"
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.
*/
void
score(score_wfd)
int score_wfd;
{
int inf = score_wfd;
SCORE *scp;
int uid;
bool done_show = FALSE;
static int numscores, max_uid;
Newscore = FALSE;
if (inf < 0)
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;
lseek(inf, 0, SEEK_SET);
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, SEEK_SET);
write(inf, &max_uid, sizeof max_uid);
write(inf, Top, sizeof Top);
}
lseek(inf, 0, SEEK_SET);
}
void
set_name(scp)
SCORE *scp;
{
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.
*/
int
cmp_sc(s1, s2)
const void *s1, *s2;
{
return ((const SCORE *)s2)->s_score - ((const SCORE *)s1)->s_score;
}
/*
* show_score:
* Show the score list for the '-s' option.
*/
void
show_score()
{
SCORE *scp;
int inf;
static int max_score;
if ((inf = open(Scorefile, O_RDONLY)) < 0) {
warn("opening `%s'", 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,
(int)(sizeof(scp->s_name)), scp->s_name);
}