-/* $NetBSD: move.c,v 1.7 1998/07/24 23:28:02 hubertf Exp $ */
+/* $NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*
#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 $");
+__RCSID("$NetBSD: move.c,v 1.16 2009/08/12 08:30:55 dholland Exp $");
#endif
#endif /* not lint */
+#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
*/
void
-get_move()
+get_move(void)
{
- int c;
+ int c;
#ifdef FANCY
- int lastmove;
+ int lastmove;
#endif /*FANCY*/
if (Waiting)
return;
-#ifdef FANCY
+#ifdef FANCY
if (Pattern_roll) {
if (Next_move >= Move_list)
lastmove = *Next_move;
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
break;
case 'w':
case 'W':
- Waiting = TRUE;
+ Waiting = true;
leaveok(stdscr, TRUE);
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);
+ refresh();
break;
case EOF:
break;
* Must I teleport; i.e., is there anywhere I can move without
* being eaten?
*/
-bool
-must_telep()
+static bool
+must_telep(void)
{
- 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
*/
-bool
-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();
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
*/
-bool
-eaten(pos)
- COORD *pos;
+static bool
+eaten(const COORD *pos)
{
- 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 the count variables
*/
void
-reset_count()
+reset_count(void)
{
Count = 0;
- Running = FALSE;
+ Running = false;
leaveok(stdscr, FALSE);
refresh();
}
* See if we are jumping, i.e., we should not refresh.
*/
bool
-jumping()
+jumping(void)
{
return (Jump && (Count || Running || Waiting));
}