1 /* $NetBSD: move.c,v 1.15 2009/07/20 06:39:06 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: move.c,v 1.15 2009/07/20 06:39:06 dholland Exp $");
41 #include <sys/types.h>
42 #include <sys/ttydefaults.h> /* for CTRL */
50 static bool do_move(int, int);
51 static bool eaten(const COORD
*);
52 static bool must_telep(void);
56 * Get and execute a move from the player
71 if (Next_move
>= Move_list
)
72 lastmove
= *Next_move
;
74 lastmove
= -1; /* flag for "first time in" */
76 lastmove
= 0; /* Shut up gcc */
79 if (Teleport
&& must_telep())
86 else if (Num_robots
> 1 && Stand_still
)
88 else if (Num_robots
> 1 && Pattern_roll
) {
89 if (*++Next_move
== '\0') {
92 Next_move
= Move_list
;
112 while (isdigit(c
= getchar()))
113 Count
= Count
* 10 + (c
- '0');
118 leaveok(stdscr
, TRUE
);
160 case 'Y': case 'U': case 'H': case 'J':
161 case 'K': case 'L': case 'B': case 'N':
168 leaveok(stdscr
, TRUE
);
172 if (query("Really quit?"))
179 leaveok(stdscr
, TRUE
);
185 mvaddch(My_pos
.y
, My_pos
.x
, ' ');
191 mvaddch(My_pos
.y
, My_pos
.x
, PLAYER
);
192 leaveok(stdscr
, FALSE
);
211 leaveok(stdscr
, FALSE
);
216 * Must I teleport; i.e., is there anywhere I can move without
226 if (Stand_still
&& Num_robots
> 1 && eaten(&My_pos
))
230 for (y
= -1; y
<= 1; y
++) {
231 newpos
.y
= My_pos
.y
+ y
;
232 if (newpos
.y
<= 0 || newpos
.y
>= Y_FIELDSIZE
)
234 for (x
= -1; x
<= 1; x
++) {
235 newpos
.x
= My_pos
.x
+ x
;
236 if (newpos
.x
<= 0 || newpos
.x
>= X_FIELDSIZE
)
238 if (Field
[newpos
.y
][newpos
.x
] > 0)
252 do_move(int dy
, int dx
)
256 newpos
.y
= My_pos
.y
+ dy
;
257 newpos
.x
= My_pos
.x
+ dx
;
258 if (newpos
.y
<= 0 || newpos
.y
>= Y_FIELDSIZE
||
259 newpos
.x
<= 0 || newpos
.x
>= X_FIELDSIZE
||
260 Field
[newpos
.y
][newpos
.x
] > 0 || eaten(&newpos
)) {
263 leaveok(stdscr
, FALSE
);
264 move(My_pos
.y
, My_pos
.x
);
273 else if (dy
== 0 && dx
== 0)
275 mvaddch(My_pos
.y
, My_pos
.x
, ' ');
277 mvaddch(My_pos
.y
, My_pos
.x
, PLAYER
);
285 * Player would get eaten at this place
288 eaten(const COORD
*pos
)
292 for (y
= pos
->y
- 1; y
<= pos
->y
+ 1; y
++) {
293 if (y
<= 0 || y
>= Y_FIELDSIZE
)
295 for (x
= pos
->x
- 1; x
<= pos
->x
+ 1; x
++) {
296 if (x
<= 0 || x
>= X_FIELDSIZE
)
298 if (Field
[y
][x
] == 1)
307 * Reset the count variables
314 leaveok(stdscr
, FALSE
);
320 * See if we are jumping, i.e., we should not refresh.
325 return (Jump
&& (Count
|| Running
|| Waiting
));