Merge branch 'games' of https://github.com/RetroBSD/retrobsd into games

This commit is contained in:
Sergey
2014-05-09 21:01:09 -07:00
16 changed files with 452 additions and 441 deletions

View File

@@ -95,7 +95,7 @@ ALLDIRS = games/ sbin/ bin/ dev/ etc/ tmp/ lib/ libexec/ share/ include/
var/run/ var/log/ var/lock/ games/ games/lib/ include/sys/ \
include/machine/ include/arpa/ include/smallc/ \
include/smallc/sys/ share/misc/ share/smallc/ include/sys/ \
games/lib/
games/lib/ games/lib/atc/
BDEVS = dev/rd0!b0:0 dev/rd0a!b0:1 dev/rd0b!b0:2 dev/rd0c!b0:3 dev/rd0d!b0:4
BDEVS += dev/rd1!b1:0 dev/rd1a!b1:1 dev/rd1b!b1:2 dev/rd1c!b1:3 dev/rd1d!b1:4
BDEVS += dev/rd2!b2:0 dev/rd2a!b2:1 dev/rd2b!b2:2 dev/rd2c!b2:3 dev/rd2d!b2:4

View File

@@ -181,6 +181,8 @@ int waddstr (WINDOW *, char *);
int wgetstr (WINDOW *, char *);
int wdeleteln (WINDOW *);
void mvcur(int ly, int lx, int y, int x);
void overwrite(WINDOW *win1, WINDOW *win2);
void wclrtobot(WINDOW *win);
/*
* Used to be in unctrl.h.

View File

@@ -11,8 +11,8 @@ CFLAGS += -Werror -Wall -Os
# Programs that live in subdirectories, and have makefiles of their own.
#
SUBDIR = adventure backgammon battlestar rogue sail trek
# TODO: atc boggle btlgammon cribbage
SUBDIR = adventure atc backgammon battlestar rogue sail trek
# TODO: boggle btlgammon cribbage
# fortune hangman hunt mille monop phantasia quiz robots
# sail snake warp

2
src/games/atc/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
atc
y.tab.h

View File

@@ -5,26 +5,31 @@
#
# @(#)Makefile 5.1.2 (2.11BSD) 1999/10/25
#
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
#include $(TOPSRC)/cross.mk
DESTDIR =
CFLAGS = -O -DSYSV -DDEST=\"${DESTDIR}/usr/games/lib/atc/\"
CFLAGS = -Os -g -Werror -Wall
CFLAGS += -DBSD -DDEST=\"/games/lib/atc/\"
#CFLAGS += -DSYSV -DDEST=\"games/\"
YFLAGS = -d
LIBS = -ll -lm -lcurses -ltermcap
LEX = lex
LIBS = -lm -lcurses -ltermcap
OBJS = extern.o grammar.o input.o lex.o list.o log.o main.o tunable.o \
graphics.o update.o
all: atc
atc: ${OBJS}
${CC} ${OBJS} ${LIBS} -o $@
atc: $(OBJS)
$(CC) $(LDFLAGS) -o atc.elf $(OBJS) $(LIBS)
$(OBJDUMP) -S atc.elf > atc.dis
$(SIZE) atc.elf
$(ELF2AOUT) atc.elf $@ && rm atc.elf
clean:
rm -f *.o core atc grammar.c y.tab.h y.tab.c lex.yy.c lex.c
rm -f *.o *.0 *.elf atc *.elf *.dis tags *~ grammar.c lex.c y.tab.h
install:
-[ -d ${DESTDIR}/usr/games/lib/atc ] || mkdir ${DESTDIR}/usr/games/lib/atc
chmod 700 ${DESTDIR}/usr/games/lib/atc
chown games.bin ${DESTDIR}/usr/games/lib/atc
(cd games; install -c -o games -g bin -m 600 * ${DESTDIR}/usr/games/lib/atc)
install -s -o games -g bin -m 4700 atc ${DESTDIR}/usr/games/hide/atc
(cd ${DESTDIR}/usr/games; rm -f atc; ln -s dm atc; chown games.bin atc)
install: all
install atc $(DESTDIR)/games/
mkdir -p ${DESTDIR}/games/lib/atc
cp -p games/* ${DESTDIR}/games/lib/atc

View File

@@ -12,7 +12,7 @@
char GAMES[] = "Game_List",
LOG[] = "ATC_scores";
int clock, safe_planes, start_time, test_mode;
int clocktick, safe_planes, start_time, test_mode;
char *file;

View File

@@ -9,7 +9,7 @@
extern char GAMES[], LOG[], *file;
extern int clock, safe_planes, start_time, test_mode;
extern int clocktick, safe_planes, start_time, test_mode;
extern FILE *filein, *fileout;
@@ -22,3 +22,29 @@ extern struct sgttyb tty_start, tty_new;
extern DISPLACEMENT displacement[MAXDIR];
extern PLANE *findplane(), *newplane();
int dir_no(int ch);
void ioclrtoeol(int pos);
void iomove(int pos);
void ioaddstr(int pos, char *str);
void ioclrtobot(void);
int getAChar(void);
void done_screen(void);
void redraw(void);
void ioerror(int pos, int len, char *str);
int number(int l);
void loser(PLANE *p, char *s);
void init_gr(void);
int yyparse(void);
void setup_screen(C_SCREEN *scp);
int addplane(void);
void log_score(int list_em);
void quit(int sig);
void update(int sig);
int getcommand(void);
void planewin(void);
int name(PLANE *p);
void erase_all(void);
void append(LIST *l, PLANE *p);
void delete(LIST *l, PLANE *p);
void draw_all(void);

View File

@@ -27,6 +27,9 @@
int errors = 0;
int line = 1;
int yylex(void);
int yyerror(char *s);
%}
%%
@@ -242,14 +245,14 @@ Lline:
;
%%
check_edge(x, y)
void check_edge(x, y)
{
if (!(x == 0) && !(x == sp->width - 1) &&
!(y == 0) && !(y == sp->height - 1))
yyerror("edge value not on edge.");
}
check_point(x, y)
void check_point(x, y)
{
if (x < 1 || x >= sp->width - 1)
yyerror("X value out of range.");
@@ -257,7 +260,7 @@ check_point(x, y)
yyerror("Y value out of range.");
}
check_linepoint(x, y)
void check_linepoint(x, y)
{
if (x < 0 || x >= sp->width)
yyerror("X value out of range.");
@@ -265,7 +268,7 @@ check_linepoint(x, y)
yyerror("Y value out of range.");
}
check_line(x1, y1, x2, y2)
void check_line(x1, y1, x2, y2)
{
int d1, d2;
@@ -279,7 +282,7 @@ check_line(x1, y1, x2, y2)
yyerror("Bad line endpoints.");
}
yyerror(s)
int yyerror(char *s)
{
fprintf(stderr, "\"%s\": line %d: %s\n", file, line, s);
errors++;
@@ -287,7 +290,7 @@ yyerror(s)
return (errors);
}
check_edir(x, y, dir)
void check_edir(x, y, dir)
{
int bad = 0;
@@ -318,11 +321,11 @@ check_edir(x, y, dir)
yyerror("Bad direction for entrance at exit.");
}
check_adir(x, y, dir)
void check_adir(x, y, dir)
{
}
checkdefs()
int checkdefs()
{
int err = 0;

View File

@@ -22,7 +22,7 @@
WINDOW *radar, *cleanradar, *credit, *input, *planes;
getAChar()
int getAChar()
{
#ifdef BSD
return (getchar());
@@ -35,7 +35,7 @@ getAChar()
#endif
}
erase_all()
void erase_all()
{
PLANE *pp;
@@ -49,7 +49,7 @@ erase_all()
}
}
draw_all()
void draw_all()
{
PLANE *pp;
@@ -68,7 +68,7 @@ draw_all()
fflush(stdout);
}
init_gr()
void init_gr()
{
static char buffer[BUFSIZ];
@@ -80,7 +80,25 @@ init_gr()
planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
}
setup_screen(scp)
void draw_line(w, x, y, lx, ly, s)
WINDOW *w;
char *s;
{
int dx, dy;
dx = SGN(lx - x);
dy = SGN(ly - y);
for (;;) {
wmove(w, y, x * 2);
waddstr(w, s);
if (x == lx && y == ly)
break;
x += dx;
y += dy;
}
}
void setup_screen(scp)
C_SCREEN *scp;
{
register int i, j;
@@ -171,25 +189,7 @@ setup_screen(scp)
fflush(stdout);
}
draw_line(w, x, y, lx, ly, s)
WINDOW *w;
char *s;
{
int dx, dy;
dx = SGN(lx - x);
dy = SGN(ly - y);
for (;;) {
wmove(w, y, x * 2);
waddstr(w, s);
if (x == lx && y == ly)
break;
x += dx;
y += dy;
}
}
ioclrtoeol(pos)
void ioclrtoeol(pos)
{
wmove(input, 0, pos);
wclrtoeol(input);
@@ -197,14 +197,14 @@ ioclrtoeol(pos)
fflush(stdout);
}
iomove(pos)
void iomove(pos)
{
wmove(input, 0, pos);
wrefresh(input);
fflush(stdout);
}
ioaddstr(pos, str)
void ioaddstr(pos, str)
char *str;
{
wmove(input, 0, pos);
@@ -213,14 +213,14 @@ ioaddstr(pos, str)
fflush(stdout);
}
ioclrtobot()
void ioclrtobot()
{
wclrtobot(input);
wrefresh(input);
fflush(stdout);
}
ioerror(pos, len, str)
void ioerror(pos, len, str)
char *str;
{
int i;
@@ -234,7 +234,7 @@ ioerror(pos, len, str)
fflush(stdout);
}
quit()
void quit(int sig)
{
int c, y, x;
#ifdef BSD
@@ -271,10 +271,9 @@ quit()
wmove(input, y, x);
wrefresh(input);
fflush(stdout);
return;
}
planewin()
void planewin()
{
PLANE *pp;
char *command();
@@ -289,7 +288,7 @@ planewin()
#ifdef SYSV
wclrtobot(planes);
#endif
wprintw(planes, "Time: %-4d Safe: %d", clock, safe_planes);
wprintw(planes, "Time: %-4d Safe: %d", clocktick, safe_planes);
wmove(planes, 2, 0);
waddstr(planes, "pl dt comm");
@@ -317,7 +316,7 @@ planewin()
fflush(stdout);
}
loser(p, s)
void loser(p, s)
PLANE *p;
char *s;
{
@@ -351,7 +350,7 @@ loser(p, s)
exit(0);
}
redraw()
void redraw()
{
clear();
refresh();
@@ -370,7 +369,7 @@ redraw()
}
done_screen()
void done_screen()
{
clear();
refresh();

View File

@@ -8,11 +8,20 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef SYSV
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/utsname.h>
#ifdef SYSV
#include <sys/ioctl.h>
#endif
#include <pwd.h>
#include <fcntl.h>
#ifdef BSD
#include <sgtty.h>
@@ -21,25 +30,17 @@
#endif
#ifdef SYSV
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include <termios.h>
#endif
#include <signal.h>
#include <math.h>
#include <curses.h>
#ifdef SYSV
#define index strchr
#define rindex strrchr
#define bcopy(a,b,c) memcpy((b), (a), (c))
#define bzero(a,b) memset((a), '\0', (b))
#define srandom srand
#define random rand
#define sgttyb termio
#ifdef SYSV
#define sgttyb termios
#define sg_erase c_cc[2]
#define sg_kill c_cc[3]
#endif

View File

@@ -6,11 +6,6 @@
*
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#ifndef lint
static char sccsid[] = "@(#)input.c 1.2 (Berkeley) 10/22/87";
#endif not lint
#include "include.h"
#define MAXRULES 6
@@ -153,7 +148,7 @@ int level;
int tval;
int dest_type, dest_no, dir;
pop()
int pop()
{
if (level == 0)
return (-1);
@@ -167,7 +162,7 @@ pop()
return (0);
}
rezero()
void rezero()
{
iomove(0);
@@ -179,7 +174,7 @@ rezero()
strcpy(T_STR, "");
}
push(ruleno, ch)
void push(ruleno, ch)
{
int newstate, newpos;
@@ -200,7 +195,77 @@ push(ruleno, ch)
strcpy(T_STR, "");
}
getcommand()
int gettoken()
{
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
{
if (tval == SHELLTOKEN)
{
#ifdef BSD
struct itimerval itv;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
int aval;
aval = alarm(0);
#endif
if (fork() == 0) /* child */
{
char *shell, *base, *getenv(), *strrchr();
setuid(getuid()); /* turn off setuid bit */
done_screen();
/* run user's favorite shell */
if ((shell = getenv("SHELL")) != NULL)
{
base = strrchr(shell, '/');
if (base == NULL)
base = shell;
else
base++;
execl(shell, base, (char*)0);
}
else
execl("/bin/sh", "sh", (char*)0);
exit(0); /* oops */
}
wait(0);
#ifdef BSD
ioctl(fileno(stdin), TIOCSETP, &tty_new);
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 1;
itv.it_interval.tv_sec = sp->update_secs;
itv.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
ioctl(fileno(stdin), TCSETAW, &tty_new);
alarm(aval);
#endif
}
redraw();
}
if (isdigit(tval))
return (NUMTOKEN);
else if (isalpha(tval))
return (ALPHATOKEN);
else
return (tval);
}
void noise()
{
putchar('\07');
fflush(stdout);
}
int getcommand()
{
int c, i, done;
char *s, *(*func)();
@@ -258,76 +323,6 @@ getcommand()
return (0);
}
noise()
{
putchar('\07');
fflush(stdout);
}
gettoken()
{
while ((tval = getAChar()) == REDRAWTOKEN || tval == SHELLTOKEN)
{
if (tval == SHELLTOKEN)
{
#ifdef BSD
struct itimerval itv;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
int aval;
aval = alarm(0);
#endif
if (fork() == 0) /* child */
{
char *shell, *base, *getenv(), *strrchr();
setuid(getuid()); /* turn off setuid bit */
done_screen();
/* run user's favorite shell */
if ((shell = getenv("SHELL")) != NULL)
{
base = strrchr(shell, '/');
if (base == NULL)
base = shell;
else
base++;
execl(shell, base, 0);
}
else
execl("/bin/sh", "sh", 0);
exit(0); /* oops */
}
wait(0);
#ifdef BSD
ioctl(fileno(stdin), TIOCSETP, &tty_new);
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 1;
itv.it_interval.tv_sec = sp->update_secs;
itv.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itv, NULL);
#endif
#ifdef SYSV
ioctl(fileno(stdin), TCSETAW, &tty_new);
alarm(aval);
#endif
}
redraw();
}
if (isdigit(tval))
return (NUMTOKEN);
else if (isalpha(tval))
return (ALPHATOKEN);
else
return (tval);
}
char *
setplane(c)
{
@@ -604,10 +599,9 @@ ignore(c)
return (NULL);
}
dir_no(ch)
char ch;
int dir_no(ch)
{
int dir;
int dir = 0;
switch (ch) {
case 'w': dir = 0; break;

View File

@@ -8,9 +8,13 @@
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#define YY_NO_INPUT
#define YY_SKIP_YYWRAP
#include "y.tab.h"
#define yywrap() 0
extern int line;
%}
%option nounput
%%
[0-9]+ { yylval.ival = atoi(yytext); return(ConstOp); }
height { return(HeightOp); }

View File

@@ -15,7 +15,7 @@ newplane()
return ((PLANE *) calloc(1, sizeof (PLANE)));
}
append(l, p)
void append(l, p)
LIST *l;
PLANE *p;
{
@@ -53,7 +53,7 @@ append(l, p)
}
}
delete(l, p)
void delete(l, p)
LIST *l;
PLANE *p;
{

View File

@@ -6,14 +6,9 @@
*
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#ifndef lint
static char sccsid[] = "@(#)log.c 1.4 (Berkeley) 12/26/87";
#endif not lint
#include "include.h"
compar(a, b)
int compar(a, b)
SCORE *a, *b;
{
if (b->planes == a->planes)
@@ -51,16 +46,14 @@ timestr(t)
return (s);
}
log_score(list_em)
void log_score(list_em)
{
register int i, fd, num_scores = 0, good, changed = 0, found = 0;
struct passwd *pw;
FILE *fp;
char *cp, logstr[BUFSIZ], *index(), *rindex();
char *cp, logstr[BUFSIZ];
SCORE score[100], thisscore;
#ifdef SYSV
struct utsname name;
#endif
strcpy(logstr, SPECIAL_DIR);
strcat(logstr, LOG);
@@ -69,7 +62,7 @@ log_score(list_em)
fd = open(logstr, O_CREAT|O_RDWR, 0644);
if (fd < 0) {
perror(logstr);
return (-1);
return;
}
/*
* This is done to take advantage of stdio, while still
@@ -78,7 +71,7 @@ log_score(list_em)
fp = fdopen(fd, "r+");
if (fp == NULL) {
perror(logstr);
return (-1);
return;
}
#ifdef BSD
if (flock(fileno(fp), LOCK_EX) < 0)
@@ -88,7 +81,7 @@ log_score(list_em)
#endif
{
perror("flock");
return (-1);
return;
}
for (;;) {
good = fscanf(fp, "%s %s %s %d %d %d",
@@ -106,29 +99,21 @@ log_score(list_em)
fprintf(stderr,
"getpwuid failed for uid %d. Who are you?\n",
getuid());
return (-1);
return;
}
strcpy(thisscore.name, pw->pw_name);
#ifdef BSD
if (gethostname(thisscore.host, sizeof (thisscore.host)) < 0) {
perror("gethostname");
return (-1);
}
#endif
#ifdef SYSV
uname(&name);
strcpy(thisscore.host, name.sysname);
#endif
cp = rindex(file, '/');
cp = strrchr(file, '/');
if (cp == NULL) {
fprintf(stderr, "log: where's the '/' in %s?\n", file);
return (-1);
return;
}
cp++;
strcpy(thisscore.game, cp);
thisscore.time = clock;
thisscore.time = clocktick;
thisscore.planes = safe_planes;
thisscore.real_time = time(0) - start_time;
@@ -200,7 +185,7 @@ log_score(list_em)
"game", "time", "real time", "planes safe");
puts("-------------------------------------------------------------------------------");
for (i = 0; i < num_scores; i++) {
cp = index(score[i].host, '.');
cp = strchr(score[i].host, '.');
if (cp != NULL)
*cp = '\0';
printf("%2d: %-8s %-8s %-18s %4d %9s %4d\n", i + 1,
@@ -209,5 +194,4 @@ log_score(list_em)
score[i].planes);
}
putchar('\n');
return (0);
}

View File

@@ -9,7 +9,114 @@
#include "include.h"
main(ac, av)
int read_file(s)
char *s;
{
extern FILE *yyin;
int retval;
file = s;
yyin = fopen(s, "r");
if (yyin == NULL) {
perror(s);
return (-1);
}
retval = yyparse();
fclose(yyin);
if (retval != 0)
return (-1);
else
return (0);
}
char *
default_game()
{
FILE *fp;
static char file[256];
char line[256], games[256];
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (NULL);
}
if (fgets(line, sizeof(line), fp) == NULL) {
fprintf(stderr, "%s: no default game available\n", games);
return (NULL);
}
fclose(fp);
line[strlen(line) - 1] = '\0';
strcpy(file, SPECIAL_DIR);
strcat(file, line);
return (file);
}
char *
okay_game(s)
char *s;
{
FILE *fp;
static char file[256];
char *ret = NULL, line[256], games[256];
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (NULL);
}
while (fgets(line, sizeof(line), fp) != NULL) {
line[strlen(line) - 1] = '\0';
if (strcmp(s, line) == 0) {
strcpy(file, SPECIAL_DIR);
strcat(file, line);
ret = file;
break;
}
}
fclose(fp);
if (ret == NULL) {
test_mode = 1;
ret = s;
fprintf(stderr, "%s: %s: game not found\n", games, s);
fprintf(stderr, "Your score will not be logged.\n");
sleep(2); /* give the guy time to read it */
}
return (ret);
}
int list_games()
{
FILE *fp;
char line[256], games[256];
int num_games = 0;
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (-1);
}
puts("available games:");
while (fgets(line, sizeof(line), fp) != NULL) {
printf(" %s", line);
num_games++;
}
fclose(fp);
if (num_games == 0) {
fprintf(stderr, "%s: no games available\n", games);
return (-1);
}
return (0);
}
int main(ac, av)
char *av[];
{
int seed;
@@ -20,8 +127,6 @@ main(ac, av)
#ifdef BSD
struct itimerval itv;
#endif
extern int update(), quit(), log_score();
extern char *default_game(), *okay_game();
start_time = seed = time(0);
@@ -29,7 +134,7 @@ main(ac, av)
while (*av) {
#ifndef SAVEDASH
if (**av == '-')
*++*av;
(*av)++;
else
break;
#endif
@@ -60,8 +165,7 @@ main(ac, av)
av++;
break;
default:
fprintf(stderr, "Unknown option '%c'\n", *ptr,
name);
fprintf(stderr, "Unknown option '%c'\n", *ptr);
f_usage++;
break;
}
@@ -155,7 +259,7 @@ main(ac, av)
alarm(0);
#endif
update();
update(0);
#ifdef BSD
itv.it_value.tv_sec = sp->update_secs;
@@ -170,110 +274,3 @@ main(ac, av)
}
}
}
read_file(s)
char *s;
{
extern FILE *yyin;
int retval;
file = s;
yyin = fopen(s, "r");
if (yyin == NULL) {
perror(s);
return (-1);
}
retval = yyparse();
fclose(yyin);
if (retval != 0)
return (-1);
else
return (0);
}
char *
default_game()
{
FILE *fp;
static char file[256];
char line[256], games[256];
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (NULL);
}
if (fgets(line, sizeof(line), fp) == NULL) {
fprintf(stderr, "%s: no default game available\n", games);
return (NULL);
}
fclose(fp);
line[strlen(line) - 1] = '\0';
strcpy(file, SPECIAL_DIR);
strcat(file, line);
return (file);
}
char *
okay_game(s)
char *s;
{
FILE *fp;
static char file[256];
char *ret = NULL, line[256], games[256];
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (NULL);
}
while (fgets(line, sizeof(line), fp) != NULL) {
line[strlen(line) - 1] = '\0';
if (strcmp(s, line) == 0) {
strcpy(file, SPECIAL_DIR);
strcat(file, line);
ret = file;
break;
}
}
fclose(fp);
if (ret == NULL) {
test_mode = 1;
ret = s;
fprintf(stderr, "%s: %s: game not found\n", games, s);
fprintf(stderr, "Your score will not be logged.\n");
sleep(2); /* give the guy time to read it */
}
return (ret);
}
list_games()
{
FILE *fp;
char line[256], games[256];
int num_games = 0;
strcpy(games, SPECIAL_DIR);
strcat(games, GAMES);
if ((fp = fopen(games, "r")) == NULL) {
perror(games);
return (-1);
}
puts("available games:");
while (fgets(line, sizeof(line), fp) != NULL) {
printf(" %s", line);
num_games++;
}
fclose(fp);
if (num_games == 0) {
fprintf(stderr, "%s: no games available\n", games);
return (-1);
}
return (0);
}

View File

@@ -6,24 +6,29 @@
*
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
#if !defined(lint) && defined(DOSCCS)
static char sccsid[] = "@(#)update.c 1.3.1 (2.11BSD) 1999/10/25";
#endif
#include "include.h"
update()
int too_close(p1, p2, dist)
PLANE *p1, *p2;
{
if (ABS(p1->altitude - p2->altitude) <= dist &&
ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
return (1);
else
return (0);
}
void update(int sig)
{
int i, dir_diff, unclean;
PLANE *pp, *p1, *p2, *p;
PLANE *pp, *p1, *p2;
sigset_t set, oset;
sigemptyset(&set);
sigaddset(&set, SIGINT);
(void)sigprocmask(SIG_BLOCK, &set, &oset);
clock++;
clocktick++;
erase_all();
/* put some planes in the air */
@@ -42,7 +47,7 @@ update()
/* do altitude change and basic movement */
for (pp = air.head; pp != NULL; pp = pp->next) {
/* type 0 only move every other turn */
if (pp->plane_type == 0 && clock & 1)
if (pp->plane_type == 0 && clocktick & 1)
continue;
pp->fuel--;
@@ -174,12 +179,27 @@ update()
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
}
int dir_deg(d)
{
switch (d) {
case 0: return (0);
case 1: return (45);
case 2: return (90);
case 3: return (135);
case 4: return (180);
case 5: return (225);
case 6: return (270);
case 7: return (315);
default:
return (-1);
}
}
char *
command(pp)
PLANE *pp;
{
static char buf[50], *bp, *comm_start;
char *index();
buf[0] = '\0';
bp = buf;
@@ -187,7 +207,7 @@ command(pp)
(pp->fuel < LOWFUEL) ? '*' : ' ',
(pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no);
comm_start = bp = index(buf, '\0');
comm_start = bp = strchr(buf, '\0');
if (pp->altitude == 0)
(void)sprintf(bp, "Holding @ A%d", pp->orig_no);
else if (pp->new_dir >= MAXDIR || pp->new_dir < 0)
@@ -195,11 +215,11 @@ command(pp)
else if (pp->new_dir != pp->dir)
(void)sprintf(bp, "%d", dir_deg(pp->new_dir));
bp = index(buf, '\0');
bp = strchr(buf, '\0');
if (pp->delayd)
(void)sprintf(bp, " @ B%d", pp->delayd_no);
bp = index(buf, '\0');
bp = strchr(buf, '\0');
if (*comm_start == '\0' &&
(pp->status == S_UNMARKED || pp->status == S_IGNORED))
strcpy(bp, "---------");
@@ -207,7 +227,7 @@ command(pp)
}
/* char */
name(p)
int name(p)
PLANE *p;
{
if (p->plane_type == 0)
@@ -216,7 +236,7 @@ name(p)
return ('a' + p->plane_no);
}
number(l)
int number(l)
{
if (l < 'a' && l > 'z' && l < 'A' && l > 'Z')
return (-1);
@@ -226,7 +246,7 @@ number(l)
return (l - 'A');
}
next_plane()
int next_plane()
{
static int last_plane = -1;
PLANE *pp;
@@ -254,7 +274,7 @@ next_plane()
return (last_plane);
}
addplane()
int addplane()
{
PLANE p, *pp, *p1;
int i, num_starts, close, rnd, rnd2, pnum;
@@ -337,29 +357,3 @@ findplane(n)
return (pp);
return (NULL);
}
too_close(p1, p2, dist)
PLANE *p1, *p2;
{
if (ABS(p1->altitude - p2->altitude) <= dist &&
ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
return (1);
else
return (0);
}
dir_deg(d)
{
switch (d) {
case 0: return (0);
case 1: return (45);
case 2: return (90);
case 3: return (135);
case 4: return (180);
case 5: return (225);
case 6: return (270);
case 7: return (315);
default:
return (-1);
}
}