+/* $NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * 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
* 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
+ * 3. 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.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char sccsid[] = "@(#)move.c 5.4 (Berkeley) 6/1/90";
+#if 0
+static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $");
+#endif
#endif /* not lint */
-# include "robots.h"
-# include <ctype.h>
+#include <sys/types.h>
+#include <sys/ttydefaults.h> /* for CTRL */
+#include <ctype.h>
+#include <curses.h>
+#include <unistd.h>
+#include "robots.h"
+
+#define ESC '\033'
-# define ESC '\033'
+static bool do_move(int, int);
+static bool eaten(const COORD *);
+static bool must_telep(void);
/*
* get_move:
* Get and execute a move from the player
*/
-get_move()
+void
+get_move(void)
{
- register int c;
- register int y, x, lastmove;
- static COORD newpos;
+ int c;
+#ifdef FANCY
+ int lastmove;
+#endif /*FANCY*/
if (Waiting)
return;
-#ifdef FANCY
+#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())
c = Run_ch;
else if (Count != 0)
c = Cnt_move;
-#ifdef FANCY
+#ifdef FANCY
else if (Num_robots > 1 && Stand_still)
c = '>';
else if (Num_robots > 1 && Pattern_roll) {
#endif
else {
over:
- c = getchar();
+ if (Auto_bot) {
+ c = automove();
+ if (!Jump) {
+ usleep(10000);
+ refresh();
+ }
+ } else
+ c = getchar();
if (isdigit(c)) {
Count = (c - '0');
while (isdigit(c = getchar()))
case 'Y': case 'U': case 'H': case 'J':
case 'K': case 'L': case 'B': case 'N':
case '>':
- Running = TRUE;
+ Running = true;
if (c == '>')
Run_ch = ' ';
else
case 'q':
case 'Q':
if (query("Really quit?"))
- quit();
+ quit(0);
refresh();
break;
case 'w':
case 'W':
- Waiting = TRUE;
+ Waiting = true;
leaveok(stdscr, TRUE);
- flushok(stdscr, FALSE);
goto ret;
case 't':
case 'T':
teleport:
- Running = FALSE;
+ Running = false;
mvaddch(My_pos.y, My_pos.x, ' ');
My_pos = *rnd_pos();
+ telmsg(1);
+ refresh();
+ sleep(1);
+ telmsg(0);
mvaddch(My_pos.y, My_pos.x, PLAYER);
leaveok(stdscr, FALSE);
refresh();
flush_in();
goto ret;
- case CTRL(L):
- wrefresh(curscr);
+ case CTRL('L'):
+ refresh();
break;
case EOF:
break;
default:
- putchar(CTRL(G));
+ putchar(CTRL('G'));
reset_count();
fflush(stdout);
break;
* Must I teleport; i.e., is there anywhere I can move without
* being eaten?
*/
-must_telep()
+static bool
+must_telep(void)
{
- register int x, y;
- static COORD newpos;
+ int x, y;
+ static COORD newpos;
-#ifdef FANCY
+#ifdef FANCY
if (Stand_still && Num_robots > 1 && eaten(&My_pos))
- return TRUE;
+ return true;
#endif
for (y = -1; y <= 1; y++) {
if (Field[newpos.y][newpos.x] > 0)
continue;
if (!eaten(&newpos))
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
/*
* do_move:
* Execute a move
*/
-do_move(dy, dx)
-int dy, dx;
+static bool
+do_move(int dy, int dx)
{
- static COORD newpos;
+ static COORD newpos;
newpos.y = My_pos.y + dy;
newpos.x = My_pos.x + dx;
newpos.x <= 0 || newpos.x >= X_FIELDSIZE ||
Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) {
if (Running) {
- Running = FALSE;
+ Running = false;
leaveok(stdscr, FALSE);
move(My_pos.y, My_pos.x);
refresh();
}
else {
- putchar(CTRL(G));
+ putchar(CTRL('G'));
reset_count();
}
- return FALSE;
+ return false;
}
else if (dy == 0 && dx == 0)
- return TRUE;
+ 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;
+ return true;
}
/*
* eaten:
* Player would get eaten at this place
*/
-eaten(pos)
-register COORD *pos;
+static bool
+eaten(const COORD *pos)
{
- register int x, y;
+ int x, y;
for (y = pos->y - 1; y <= pos->y + 1; y++) {
if (y <= 0 || y >= Y_FIELDSIZE)
if (x <= 0 || x >= X_FIELDSIZE)
continue;
if (Field[y][x] == 1)
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/*
* reset_count:
* Reset the count variables
*/
-reset_count()
+void
+reset_count(void)
{
Count = 0;
- Running = FALSE;
+ Running = false;
leaveok(stdscr, FALSE);
refresh();
}
* jumping:
* See if we are jumping, i.e., we should not refresh.
*/
-jumping()
+bool
+jumping(void)
{
return (Jump && (Count || Running || Waiting));
}