2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)move.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/robots/move.c,v 1.6 1999/11/30 03:49:18 billf Exp $
33 #include <sys/ttydefaults.h>
39 static bool must_telep(void);
40 static bool do_move(int, int);
41 static bool eaten(COORD
*);
45 * Get and execute a move from the player
59 if (Next_move
>= Move_list
)
60 lastmove
= *Next_move
;
62 lastmove
= -1; /* flag for "first time in" */
64 lastmove
= 0; /* Shut up gcc */
67 if (Teleport
&& must_telep())
74 else if (Num_robots
> 1 && Stand_still
)
76 else if (Num_robots
> 1 && Pattern_roll
) {
77 if (*++Next_move
== '\0') {
80 Next_move
= Move_list
;
93 while (isdigit(c
= getchar()))
94 Count
= Count
* 10 + (c
- '0');
99 leaveok(stdscr
, true);
141 case 'Y': case 'U': case 'H': case 'J':
142 case 'K': case 'L': case 'B': case 'N':
149 leaveok(stdscr
, true);
153 if (query("Really quit?"))
160 leaveok(stdscr
, true);
166 mvaddch(My_pos
.y
, My_pos
.x
, ' ');
168 mvaddch(My_pos
.y
, My_pos
.x
, PLAYER
);
169 leaveok(stdscr
, false);
188 leaveok(stdscr
, false);
193 * Must I teleport; i.e., is there anywhere I can move without
203 if (Stand_still
&& Num_robots
> 1 && eaten(&My_pos
))
207 for (y
= -1; y
<= 1; y
++) {
208 newpos
.y
= My_pos
.y
+ y
;
209 if (newpos
.y
<= 0 || newpos
.y
>= Y_FIELDSIZE
)
211 for (x
= -1; x
<= 1; x
++) {
212 newpos
.x
= My_pos
.x
+ x
;
213 if (newpos
.x
<= 0 || newpos
.x
>= X_FIELDSIZE
)
215 if (Field
[newpos
.y
][newpos
.x
] > 0)
229 do_move(int dy
, int dx
)
233 newpos
.y
= My_pos
.y
+ dy
;
234 newpos
.x
= My_pos
.x
+ dx
;
235 if (newpos
.y
<= 0 || newpos
.y
>= Y_FIELDSIZE
||
236 newpos
.x
<= 0 || newpos
.x
>= X_FIELDSIZE
||
237 Field
[newpos
.y
][newpos
.x
] > 0 || eaten(&newpos
)) {
240 leaveok(stdscr
, false);
241 move(My_pos
.y
, My_pos
.x
);
250 else if (dy
== 0 && dx
== 0)
252 mvaddch(My_pos
.y
, My_pos
.x
, ' ');
254 mvaddch(My_pos
.y
, My_pos
.x
, PLAYER
);
262 * Player would get eaten at this place
269 for (y
= pos
->y
- 1; y
<= pos
->y
+ 1; y
++) {
270 if (y
<= 0 || y
>= Y_FIELDSIZE
)
272 for (x
= pos
->x
- 1; x
<= pos
->x
+ 1; x
++) {
273 if (x
<= 0 || x
>= X_FIELDSIZE
)
275 if (Field
[y
][x
] == 1)
284 * Reset the count variables
291 leaveok(stdscr
, false);
297 * See if we are jumping, i.e., we should not refresh.
302 return (Jump
&& (Count
|| Running
|| Waiting
));