Mon Jul 20 05:44:02 2009 UTC ()
ANSIfy. Use __dead. Object diffs checked.


(dholland)
diff -r1.8 -r1.9 src/games/robots/auto.c
diff -r1.8 -r1.9 src/games/robots/init_field.c
diff -r1.6 -r1.7 src/games/robots/flush_in.c
diff -r1.6 -r1.7 src/games/robots/play_level.c
diff -r1.6 -r1.7 src/games/robots/query.c
diff -r1.24 -r1.25 src/games/robots/main.c
diff -r1.7 -r1.8 src/games/robots/make_level.c
diff -r1.7 -r1.8 src/games/robots/move_robs.c
diff -r1.12 -r1.13 src/games/robots/move.c
diff -r1.5 -r1.6 src/games/robots/rnd_pos.c
diff -r1.18 -r1.19 src/games/robots/robots.h
diff -r1.18 -r1.19 src/games/robots/score.c

cvs diff -r1.8 -r1.9 src/games/robots/auto.c (expand / switch to unified diff)

--- src/games/robots/auto.c 2008/04/28 20:22:54 1.8
+++ src/games/robots/auto.c 2009/07/20 05:44:02 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: auto.c,v 1.8 2008/04/28 20:22:54 martin Exp $ */ 1/* $NetBSD: auto.c,v 1.9 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -63,83 +63,80 @@ static int xinc(int); @@ -63,83 +63,80 @@ static int xinc(int);
63static int yinc(int); 63static int yinc(int);
64static const char *find_moves(void); 64static const char *find_moves(void);
65static COORD *closest_robot(int *); 65static COORD *closest_robot(int *);
66static COORD *closest_heap(int *); 66static COORD *closest_heap(int *);
67static char move_towards(int, int); 67static char move_towards(int, int);
68static char move_away(COORD *); 68static char move_away(COORD *);
69static char move_between(COORD *, COORD *); 69static char move_between(COORD *, COORD *);
70static int between(COORD *, COORD *); 70static int between(COORD *, COORD *);
71 71
72/* distance(): 72/* distance():
73 * return "move" number distance of the two coordinates 73 * return "move" number distance of the two coordinates
74 */ 74 */
75static int  75static int
76distance(x1, y1, x2, y2) 76distance(int x1, int y1, int x2, int y2)
77 int x1, y1, x2, y2; 
78{ 77{
79 return MAX(ABS(ABS(x1) - ABS(x2)), ABS(ABS(y1) - ABS(y2))); 78 return MAX(ABS(ABS(x1) - ABS(x2)), ABS(ABS(y1) - ABS(y2)));
80} /* end distance */ 79}
81 80
82/* xinc(): 81/* xinc():
83 * Return x coordinate moves 82 * Return x coordinate moves
84 */ 83 */
85static int 84static int
86xinc(dir) 85xinc(int dir)
87 int dir; 
88{ 86{
89 switch(dir) { 87 switch(dir) {
90 case 'b': 88 case 'b':
91 case 'h': 89 case 'h':
92 case 'y': 90 case 'y':
93 return -1; 91 return -1;
94 case 'l': 92 case 'l':
95 case 'n': 93 case 'n':
96 case 'u': 94 case 'u':
97 return 1; 95 return 1;
98 case 'j': 96 case 'j':
99 case 'k': 97 case 'k':
100 default: 98 default:
101 return 0; 99 return 0;
102 } 100 }
103} 101}
104 102
105/* yinc(): 103/* yinc():
106 * Return y coordinate moves 104 * Return y coordinate moves
107 */ 105 */
108static int 106static int
109yinc(dir) 107yinc(int dir)
110 int dir; 
111{ 108{
112 switch(dir) { 109 switch(dir) {
113 case 'k': 110 case 'k':
114 case 'u': 111 case 'u':
115 case 'y': 112 case 'y':
116 return -1; 113 return -1;
117 case 'b': 114 case 'b':
118 case 'j': 115 case 'j':
119 case 'n': 116 case 'n':
120 return 1; 117 return 1;
121 case 'h': 118 case 'h':
122 case 'l': 119 case 'l':
123 default: 120 default:
124 return 0; 121 return 0;
125 } 122 }
126} 123}
127 124
128/* find_moves(): 125/* find_moves():
129 * Find possible moves 126 * Find possible moves
130 */ 127 */
131static const char * 128static const char *
132find_moves() 129find_moves(void)
133{ 130{
134 int x, y; 131 int x, y;
135 COORD test; 132 COORD test;
136 const char *m; 133 const char *m;
137 char *a; 134 char *a;
138 static const char moves[] = ".hjklyubn"; 135 static const char moves[] = ".hjklyubn";
139 static char ans[sizeof moves]; 136 static char ans[sizeof moves];
140 a = ans; 137 a = ans;
141 138
142 for(m = moves; *m; m++) { 139 for(m = moves; *m; m++) {
143 test.x = My_pos.x + xinc(*m); 140 test.x = My_pos.x + xinc(*m);
144 test.y = My_pos.y + yinc(*m); 141 test.y = My_pos.y + yinc(*m);
145 move(test.y, test.x); 142 move(test.y, test.x);
@@ -159,123 +156,117 @@ find_moves() @@ -159,123 +156,117 @@ find_moves()
159 } 156 }
160 *a = 0; 157 *a = 0;
161 if(ans[0]) 158 if(ans[0])
162 return ans; 159 return ans;
163 else 160 else
164 return "t"; 161 return "t";
165} 162}
166 163
167/* closest_robot(): 164/* closest_robot():
168 * return the robot closest to us 165 * return the robot closest to us
169 * and put in dist its distance 166 * and put in dist its distance
170 */ 167 */
171static COORD * 168static COORD *
172closest_robot(dist) 169closest_robot(int *dist)
173 int *dist; 
174{ 170{
175 COORD *rob, *end, *minrob = NULL; 171 COORD *rob, *end, *minrob = NULL;
176 int tdist, mindist; 172 int tdist, mindist;
177 173
178 mindist = 1000000; 174 mindist = 1000000;
179 end = &Robots[MAXROBOTS]; 175 end = &Robots[MAXROBOTS];
180 for (rob = Robots; rob < end; rob++) { 176 for (rob = Robots; rob < end; rob++) {
181 tdist = distance(My_pos.x, My_pos.y, rob->x, rob->y); 177 tdist = distance(My_pos.x, My_pos.y, rob->x, rob->y);
182 if (tdist < mindist) { 178 if (tdist < mindist) {
183 minrob = rob; 179 minrob = rob;
184 mindist = tdist; 180 mindist = tdist;
185 } 181 }
186 } 182 }
187 *dist = mindist; 183 *dist = mindist;
188 return minrob; 184 return minrob;
189} /* end closest_robot */ 185}
190  186
191/* closest_heap(): 187/* closest_heap():
192 * return the heap closest to us 188 * return the heap closest to us
193 * and put in dist its distance 189 * and put in dist its distance
194 */ 190 */
195static COORD * 191static COORD *
196closest_heap(dist) 192closest_heap(int *dist)
197 int *dist; 
198{ 193{
199 COORD *hp, *end, *minhp = NULL; 194 COORD *hp, *end, *minhp = NULL;
200 int mindist, tdist; 195 int mindist, tdist;
201 196
202 mindist = 1000000; 197 mindist = 1000000;
203 end = &Scrap[MAXROBOTS]; 198 end = &Scrap[MAXROBOTS];
204 for (hp = Scrap; hp < end; hp++) { 199 for (hp = Scrap; hp < end; hp++) {
205 if (hp->x == 0 && hp->y == 0) 200 if (hp->x == 0 && hp->y == 0)
206 break; 201 break;
207 tdist = distance(My_pos.x, My_pos.y, hp->x, hp->y); 202 tdist = distance(My_pos.x, My_pos.y, hp->x, hp->y);
208 if (tdist < mindist) { 203 if (tdist < mindist) {
209 minhp = hp; 204 minhp = hp;
210 mindist = tdist; 205 mindist = tdist;
211 } 206 }
212 } 207 }
213 *dist = mindist; 208 *dist = mindist;
214 return minhp; 209 return minhp;
215} /* end closest_heap */ 210}
216 211
217/* move_towards(): 212/* move_towards():
218 * move as close to the given direction as possible 213 * move as close to the given direction as possible
219 */ 214 */
220static char  215static char
221move_towards(dx, dy) 216move_towards(int dx, int dy)
222 int dx, dy; 
223{ 217{
224 char ok_moves[10], best_move; 218 char ok_moves[10], best_move;
225 char *ptr; 219 char *ptr;
226 int move_judge, cur_judge, mvx, mvy; 220 int move_judge, cur_judge, mvx, mvy;
227 221
228 (void)strcpy(ok_moves, find_moves()); 222 (void)strcpy(ok_moves, find_moves());
229 best_move = ok_moves[0];  223 best_move = ok_moves[0];
230 if (best_move != 't') { 224 if (best_move != 't') {
231 mvx = xinc(best_move); 225 mvx = xinc(best_move);
232 mvy = yinc(best_move); 226 mvy = yinc(best_move);
233 move_judge = ABS(mvx - dx) + ABS(mvy - dy); 227 move_judge = ABS(mvx - dx) + ABS(mvy - dy);
234 for (ptr = &ok_moves[1]; *ptr != '\0'; ptr++) { 228 for (ptr = &ok_moves[1]; *ptr != '\0'; ptr++) {
235 mvx = xinc(*ptr); 229 mvx = xinc(*ptr);
236 mvy = yinc(*ptr); 230 mvy = yinc(*ptr);
237 cur_judge = ABS(mvx - dx) + ABS(mvy - dy); 231 cur_judge = ABS(mvx - dx) + ABS(mvy - dy);
238 if (cur_judge < move_judge) { 232 if (cur_judge < move_judge) {
239 move_judge = cur_judge; 233 move_judge = cur_judge;
240 best_move = *ptr; 234 best_move = *ptr;
241 } 235 }
242 } 236 }
243 } 237 }
244 return best_move; 238 return best_move;
245} /* end move_towards */ 239}
246 240
247/* move_away(): 241/* move_away():
248 * move away form the robot given 242 * move away form the robot given
249 */ 243 */
250static char 244static char
251move_away(rob) 245move_away(COORD *rob)
252 COORD *rob; 
253{ 246{
254 int dx, dy; 247 int dx, dy;
255 248
256 dx = sign(My_pos.x - rob->x); 249 dx = sign(My_pos.x - rob->x);
257 dy = sign(My_pos.y - rob->y); 250 dy = sign(My_pos.y - rob->y);
258 return move_towards(dx, dy); 251 return move_towards(dx, dy);
259} /* end move_away */ 252}
260 253
261 254
262/* move_between(): 255/* move_between():
263 * move the closest heap between us and the closest robot 256 * move the closest heap between us and the closest robot
264 */ 257 */
265static char 258static char
266move_between(rob, hp) 259move_between(COORD *rob, COORD *hp)
267 COORD *rob; 
268 COORD *hp; 
269{ 260{
270 int dx, dy; 261 int dx, dy;
271 float slope, cons; 262 float slope, cons;
272 263
273 /* equation of the line between us and the closest robot */ 264 /* equation of the line between us and the closest robot */
274 if (My_pos.x == rob->x) { 265 if (My_pos.x == rob->x) {
275 /*  266 /*
276 * me and the robot are aligned in x  267 * me and the robot are aligned in x
277 * change my x so I get closer to the heap 268 * change my x so I get closer to the heap
278 * and my y far from the robot 269 * and my y far from the robot
279 */ 270 */
280 dx = - sign(My_pos.x - hp->x); 271 dx = - sign(My_pos.x - hp->x);
281 dy = sign(My_pos.y - rob->y); 272 dy = sign(My_pos.y - rob->y);
@@ -304,61 +295,59 @@ move_between(rob, hp) @@ -304,61 +295,59 @@ move_between(rob, hp)
304 dx = sign(My_pos.x - rob->x); 295 dx = sign(My_pos.x - rob->x);
305 dy = sign(((slope * ((float) hp->x)) + cons) - 296 dy = sign(((slope * ((float) hp->x)) + cons) -
306 ((float) hp->y)); 297 ((float) hp->y));
307 } 298 }
308 else { 299 else {
309 dx = sign(((slope * ((float) hp->x)) + cons) - 300 dx = sign(((slope * ((float) hp->x)) + cons) -
310 ((float) hp->y)); 301 ((float) hp->y));
311 dy = sign(My_pos.y - rob->y); 302 dy = sign(My_pos.y - rob->y);
312 } 303 }
313 } 304 }
314 CONSDEBUG(("me (%d,%d) robot(%d,%d) heap(%d,%d) delta(%d,%d)", 305 CONSDEBUG(("me (%d,%d) robot(%d,%d) heap(%d,%d) delta(%d,%d)",
315 My_pos.x, My_pos.y, rob->x, rob->y, hp->x, hp->y, dx, dy)); 306 My_pos.x, My_pos.y, rob->x, rob->y, hp->x, hp->y, dx, dy));
316 return move_towards(dx, dy); 307 return move_towards(dx, dy);
317} /* end move_between */ 308}
318  309
319/* between(): 310/* between():
320 * Return true if the heap is between us and the robot 311 * Return true if the heap is between us and the robot
321 */ 312 */
322int 313int
323between(rob, hp) 314between(COORD *rob, COORD *hp)
324 COORD *rob; 
325 COORD *hp; 
326{ 315{
327 /* I = @ */ 316 /* I = @ */
328 if (hp->x > rob->x && My_pos.x < rob->x) 317 if (hp->x > rob->x && My_pos.x < rob->x)
329 return 0; 318 return 0;
330 /* @ = I */ 319 /* @ = I */
331 if (hp->x < rob->x && My_pos.x > rob->x) 320 if (hp->x < rob->x && My_pos.x > rob->x)
332 return 0; 321 return 0;
333 /* @ */ 322 /* @ */
334 /* = */ 323 /* = */
335 /* I */ 324 /* I */
336 if (hp->y < rob->y && My_pos.y > rob->y) 325 if (hp->y < rob->y && My_pos.y > rob->y)
337 return 0; 326 return 0;
338 /* I */ 327 /* I */
339 /* = */ 328 /* = */
340 /* @ */ 329 /* @ */
341 if (hp->y > rob->y && My_pos.y < rob->y) 330 if (hp->y > rob->y && My_pos.y < rob->y)
342 return 0; 331 return 0;
343 return 1; 332 return 1;
344} /* end between */ 333}
345 334
346/* automove(): 335/* automove():
347 * find and do the best move if flag 336 * find and do the best move if flag
348 * else get the first move; 337 * else get the first move;
349 */ 338 */
350char 339char
351automove()  340automove(void)
352{ 341{
353#if 0 342#if 0
354 return find_moves()[0]; 343 return find_moves()[0];
355#else 344#else
356 COORD *robot_close; 345 COORD *robot_close;
357 COORD *heap_close; 346 COORD *heap_close;
358 int robot_dist, robot_heap, heap_dist; 347 int robot_dist, robot_heap, heap_dist;
359 348
360 robot_close = closest_robot(&robot_dist); 349 robot_close = closest_robot(&robot_dist);
361 if (robot_dist > 1) 350 if (robot_dist > 1)
362 return('.'); 351 return('.');
363 if (!Num_scrap)  352 if (!Num_scrap)
364 /* no scrap heaps just run away */ 353 /* no scrap heaps just run away */
@@ -366,14 +355,14 @@ automove()  @@ -366,14 +355,14 @@ automove()
366 355
367 heap_close = closest_heap(&heap_dist); 356 heap_close = closest_heap(&heap_dist);
368 robot_heap = distance(robot_close->x, robot_close->y,  357 robot_heap = distance(robot_close->x, robot_close->y,
369 heap_close->x, heap_close->y);  358 heap_close->x, heap_close->y);
370 if (robot_heap <= heap_dist && !between(robot_close, heap_close)) { 359 if (robot_heap <= heap_dist && !between(robot_close, heap_close)) {
371 /*  360 /*
372 * robot is closest to us from the heap. Run away! 361 * robot is closest to us from the heap. Run away!
373 */ 362 */
374 return move_away(robot_close); 363 return move_away(robot_close);
375 } 364 }
376  365
377 return move_between(robot_close, heap_close); 366 return move_between(robot_close, heap_close);
378#endif 367#endif
379} /* end automove */ 368}

cvs diff -r1.8 -r1.9 src/games/robots/init_field.c (expand / switch to unified diff)

--- src/games/robots/init_field.c 2003/08/07 09:37:36 1.8
+++ src/games/robots/init_field.c 2009/07/20 05:44:02 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $ */ 1/* $NetBSD: init_field.c,v 1.9 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,42 +24,42 @@ @@ -24,42 +24,42 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: init_field.c,v 1.8 2003/08/07 09:37:36 agc Exp $"); 37__RCSID("$NetBSD: init_field.c,v 1.9 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43static int telx = 0; 43static int telx = 0;
44static int tely = 0; 44static int tely = 0;
45 45
46/* 46/*
47 * init_field: 47 * init_field:
48 * Lay down the initial pattern whih is constant across all levels, 48 * Lay down the initial pattern whih is constant across all levels,
49 * and initialize all the global variables. 49 * and initialize all the global variables.
50 */ 50 */
51void 51void
52init_field() 52init_field(void)
53{ 53{
54 int i; 54 int i;
55 static bool first = TRUE; 55 static bool first = TRUE;
56 static const char *const desc[] = { 56 static const char *const desc[] = {
57 "Directions:", 57 "Directions:",
58 "", 58 "",
59 "y k u", 59 "y k u",
60 " \\|/", 60 " \\|/",
61 "h- -l", 61 "h- -l",
62 " /|\\", 62 " /|\\",
63 "b j n", 63 "b j n",
64 "", 64 "",
65 "Commands:", 65 "Commands:",
@@ -113,19 +113,18 @@ init_field() @@ -113,19 +113,18 @@ init_field()
113 } 113 }
114 telx = X_FIELDSIZE + 2; 114 telx = X_FIELDSIZE + 2;
115 tely = i; 115 tely = i;
116 if (first) 116 if (first)
117 refresh(); 117 refresh();
118 first = FALSE; 118 first = FALSE;
119#ifdef FANCY 119#ifdef FANCY
120 if (Pattern_roll) 120 if (Pattern_roll)
121 Next_move = &Move_list[-1]; 121 Next_move = &Move_list[-1];
122#endif 122#endif
123} 123}
124 124
125void 125void
126telmsg(on) 126telmsg(int on)
127 int on; 
128{ 127{
129 move(tely, telx); 128 move(tely, telx);
130 addstr(on ? "Teleport!" : " "); 129 addstr(on ? "Teleport!" : " ");
131} 130}

cvs diff -r1.6 -r1.7 src/games/robots/flush_in.c (expand / switch to unified diff)

--- src/games/robots/flush_in.c 2003/08/07 09:37:36 1.6
+++ src/games/robots/flush_in.c 2009/07/20 05:44:02 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: flush_in.c,v 1.6 2003/08/07 09:37:36 agc Exp $ */ 1/* $NetBSD: flush_in.c,v 1.7 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,28 +24,28 @@ @@ -24,28 +24,28 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)flush_in.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)flush_in.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: flush_in.c,v 1.6 2003/08/07 09:37:36 agc Exp $"); 37__RCSID("$NetBSD: flush_in.c,v 1.7 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43/* 43/*
44 * flush_in: 44 * flush_in:
45 * Flush all pending input. 45 * Flush all pending input.
46 */ 46 */
47void 47void
48flush_in() 48flush_in(void)
49{ 49{
50 tcflush(fileno(stdin), TCIFLUSH); 50 tcflush(fileno(stdin), TCIFLUSH);
51} 51}

cvs diff -r1.6 -r1.7 src/games/robots/play_level.c (expand / switch to unified diff)

--- src/games/robots/play_level.c 2003/08/07 09:37:37 1.6
+++ src/games/robots/play_level.c 2009/07/20 05:44:02 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: play_level.c,v 1.6 2003/08/07 09:37:37 agc Exp $ */ 1/* $NetBSD: play_level.c,v 1.7 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,38 +24,38 @@ @@ -24,38 +24,38 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)play_level.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)play_level.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: play_level.c,v 1.6 2003/08/07 09:37:37 agc Exp $"); 37__RCSID("$NetBSD: play_level.c,v 1.7 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43/* 43/*
44 * play_level: 44 * play_level:
45 * Let the player play the current level 45 * Let the player play the current level
46 */ 46 */
47void 47void
48play_level() 48play_level(void)
49{ 49{
50 COORD *cp; 50 COORD *cp;
51 51
52 move(My_pos.y, My_pos.x); 52 move(My_pos.y, My_pos.x);
53 addch(PLAYER); 53 addch(PLAYER);
54 refresh(); 54 refresh();
55 for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) { 55 for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) {
56 if (cp->y < 0) 56 if (cp->y < 0)
57 continue; 57 continue;
58 move(cp->y, cp->x); 58 move(cp->y, cp->x);
59 addch(ROBOT); 59 addch(ROBOT);
60 } 60 }
61 refresh(); 61 refresh();

cvs diff -r1.6 -r1.7 src/games/robots/query.c (expand / switch to unified diff)

--- src/games/robots/query.c 2003/08/07 09:37:37 1.6
+++ src/games/robots/query.c 2009/07/20 05:44:02 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: query.c,v 1.6 2003/08/07 09:37:37 agc Exp $ */ 1/* $NetBSD: query.c,v 1.7 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,39 +24,38 @@ @@ -24,39 +24,38 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: query.c,v 1.6 2003/08/07 09:37:37 agc Exp $"); 37__RCSID("$NetBSD: query.c,v 1.7 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43/* 43/*
44 * query: 44 * query:
45 * Ask a question and get a yes or no answer. Default is "no". 45 * Ask a question and get a yes or no answer. Default is "no".
46 */ 46 */
47int 47int
48query(prompt) 48query(const char *prompt)
49 const char *prompt; 
50{ 49{
51 int c, retval; 50 int c, retval;
52 int y, x; 51 int y, x;
53 52
54 getyx(stdscr, y, x); 53 getyx(stdscr, y, x);
55 move(Y_PROMPT, X_PROMPT); 54 move(Y_PROMPT, X_PROMPT);
56 addstr(prompt); 55 addstr(prompt);
57 clrtoeol(); 56 clrtoeol();
58 refresh(); 57 refresh();
59 retval = ((c = getchar()) == 'y' || c == 'Y'); 58 retval = ((c = getchar()) == 'y' || c == 'Y');
60 move(Y_PROMPT, X_PROMPT); 59 move(Y_PROMPT, X_PROMPT);
61 clrtoeol(); 60 clrtoeol();
62 move(y, x); 61 move(y, x);

cvs diff -r1.24 -r1.25 src/games/robots/main.c (expand / switch to unified diff)

--- src/games/robots/main.c 2008/08/08 16:10:47 1.24
+++ src/games/robots/main.c 2009/07/20 05:44:02 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.24 2008/08/08 16:10:47 drochner Exp $ */ 1/* $NetBSD: main.c,v 1.25 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -29,41 +29,37 @@ @@ -29,41 +29,37 @@
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1980, 1993\ 34__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
35 The Regents of the University of California. All rights reserved."); 35 The Regents of the University of California. All rights reserved.");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#ifndef lint 38#ifndef lint
39#if 0 39#if 0
40static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; 40static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
41#else 41#else
42__RCSID("$NetBSD: main.c,v 1.24 2008/08/08 16:10:47 drochner Exp $"); 42__RCSID("$NetBSD: main.c,v 1.25 2009/07/20 05:44:02 dholland Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46# include "robots.h" 46# include "robots.h"
47 47
48int main(int, char **); 
49 
50extern const char *Scorefile; 48extern const char *Scorefile;
51extern int Max_per_uid; 49extern int Max_per_uid;
52 50
53int 51int
54main(ac, av) 52main(int ac, char **av)
55 int ac; 
56 char **av; 
57{ 53{
58 const char *sp; 54 const char *sp;
59 bool bad_arg; 55 bool bad_arg;
60 bool show_only; 56 bool show_only;
61 int score_wfd; /* high score writable file descriptor */ 57 int score_wfd; /* high score writable file descriptor */
62 int score_err = 0; /* hold errno from score file open */ 58 int score_err = 0; /* hold errno from score file open */
63 59
64 score_wfd = open(Scorefile, O_RDWR); 60 score_wfd = open(Scorefile, O_RDWR);
65 if (score_wfd < 0) 61 if (score_wfd < 0)
66 score_err = errno; 62 score_err = errno;
67 else if (score_wfd < 3) 63 else if (score_wfd < 3)
68 exit(1); 64 exit(1);
69 65
@@ -187,40 +183,39 @@ main(ac, av) @@ -187,40 +183,39 @@ main(ac, av)
187 } 183 }
188 Num_games = 1; 184 Num_games = 1;
189 } while (!Auto_bot && another()); 185 } while (!Auto_bot && another());
190 quit(0); 186 quit(0);
191 /* NOTREACHED */ 187 /* NOTREACHED */
192 return(0); 188 return(0);
193} 189}
194 190
195/* 191/*
196 * quit: 192 * quit:
197 * Leave the program elegantly. 193 * Leave the program elegantly.
198 */ 194 */
199void 195void
200quit(dummy) 196quit(int dummy __unused)
201 int dummy __unused; 
202{ 197{
203 endwin(); 198 endwin();
204 exit(0); 199 exit(0);
205 /* NOTREACHED */ 200 /* NOTREACHED */
206} 201}
207 202
208/* 203/*
209 * another: 204 * another:
210 * See if another game is desired 205 * See if another game is desired
211 */ 206 */
212bool 207bool
213another() 208another(void)
214{ 209{
215 int y; 210 int y;
216 211
217#ifdef FANCY 212#ifdef FANCY
218 if ((Stand_still || Pattern_roll) && !Newscore) 213 if ((Stand_still || Pattern_roll) && !Newscore)
219 return TRUE; 214 return TRUE;
220#endif 215#endif
221 216
222 if (query("Another game?")) { 217 if (query("Another game?")) {
223 if (Full_clear) { 218 if (Full_clear) {
224 for (y = 1; y <= Num_scores; y++) { 219 for (y = 1; y <= Num_scores; y++) {
225 move(y, 1); 220 move(y, 1);
226 clrtoeol(); 221 clrtoeol();

cvs diff -r1.7 -r1.8 src/games/robots/make_level.c (expand / switch to unified diff)

--- src/games/robots/make_level.c 2003/08/07 09:37:36 1.7
+++ src/games/robots/make_level.c 2009/07/20 05:44:02 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make_level.c,v 1.7 2003/08/07 09:37:36 agc Exp $ */ 1/* $NetBSD: make_level.c,v 1.8 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,38 +24,38 @@ @@ -24,38 +24,38 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: make_level.c,v 1.7 2003/08/07 09:37:36 agc Exp $"); 37__RCSID("$NetBSD: make_level.c,v 1.8 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43/* 43/*
44 * make_level: 44 * make_level:
45 * Make the current level 45 * Make the current level
46 */ 46 */
47void 47void
48make_level() 48make_level(void)
49{ 49{
50 int i; 50 int i;
51 COORD *cp; 51 COORD *cp;
52 int x; 52 int x;
53 53
54 reset_count(); 54 reset_count();
55 for (i = 1; i < Y_FIELDSIZE; i++) 55 for (i = 1; i < Y_FIELDSIZE; i++)
56 for (x = 1; x < X_FIELDSIZE; x++) 56 for (x = 1; x < X_FIELDSIZE; x++)
57 if (Field[i][x] != 0) 57 if (Field[i][x] != 0)
58 mvaddch(i, x, ' '); 58 mvaddch(i, x, ' ');
59 if (My_pos.y > 0) 59 if (My_pos.y > 0)
60 mvaddch(My_pos.y, My_pos.x, ' '); 60 mvaddch(My_pos.y, My_pos.x, ' ');
61 61

cvs diff -r1.7 -r1.8 src/games/robots/move_robs.c (expand / switch to unified diff)

--- src/games/robots/move_robs.c 2003/08/07 09:37:37 1.7
+++ src/games/robots/move_robs.c 2009/07/20 05:44:02 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: move_robs.c,v 1.7 2003/08/07 09:37:37 agc Exp $ */ 1/* $NetBSD: move_robs.c,v 1.8 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,39 +24,38 @@ @@ -24,39 +24,38 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: move_robs.c,v 1.7 2003/08/07 09:37:37 agc Exp $"); 37__RCSID("$NetBSD: move_robs.c,v 1.8 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43/* 43/*
44 * move_robots: 44 * move_robots:
45 * Move the robots around 45 * Move the robots around
46 */ 46 */
47void 47void
48move_robots(was_sig) 48move_robots(int was_sig)
49 int was_sig; 
50{ 49{
51 COORD *rp; 50 COORD *rp;
52 51
53 if (Real_time) 52 if (Real_time)
54 signal(SIGALRM, move_robots); 53 signal(SIGALRM, move_robots);
55# ifdef DEBUG 54# ifdef DEBUG
56 move(Min.y, Min.x); 55 move(Min.y, Min.x);
57 addch(inch()); 56 addch(inch());
58 move(Max.y, Max.x); 57 move(Max.y, Max.x);
59 addch(inch()); 58 addch(inch());
60# endif /* DEBUG */ 59# endif /* DEBUG */
61 for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) { 60 for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) {
62 if (rp->y < 0) 61 if (rp->y < 0)
@@ -119,36 +118,34 @@ move_robots(was_sig) @@ -119,36 +118,34 @@ move_robots(was_sig)
119 move(Max.y, Max.x); 118 move(Max.y, Max.x);
120 addch(inch()); 119 addch(inch());
121 standend(); 120 standend();
122# endif /* DEBUG */ 121# endif /* DEBUG */
123 if (Real_time) 122 if (Real_time)
124 alarm(3); 123 alarm(3);
125} 124}
126 125
127/* 126/*
128 * add_score: 127 * add_score:
129 * Add a score to the overall point total 128 * Add a score to the overall point total
130 */ 129 */
131void 130void
132add_score(add) 131add_score(int add)
133 int add; 
134{ 132{
135 Score += add; 133 Score += add;
136 move(Y_SCORE, X_SCORE); 134 move(Y_SCORE, X_SCORE);
137 printw("%d", Score); 135 printw("%d", Score);
138} 136}
139 137
140/* 138/*
141 * sign: 139 * sign:
142 * Return the sign of the number 140 * Return the sign of the number
143 */ 141 */
144int 142int
145sign(n) 143sign(int n)
146 int n; 
147{ 144{
148 if (n < 0) 145 if (n < 0)
149 return -1; 146 return -1;
150 else if (n > 0) 147 else if (n > 0)
151 return 1; 148 return 1;
152 else 149 else
153 return 0; 150 return 0;
154} 151}

cvs diff -r1.12 -r1.13 src/games/robots/move.c (expand / switch to unified diff)

--- src/games/robots/move.c 2004/08/27 09:07:08 1.12
+++ src/games/robots/move.c 2009/07/20 05:44:02 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: move.c,v 1.12 2004/08/27 09:07:08 christos Exp $ */ 1/* $NetBSD: move.c,v 1.13 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,40 +24,40 @@ @@ -24,40 +24,40 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: move.c,v 1.12 2004/08/27 09:07:08 christos Exp $"); 37__RCSID("$NetBSD: move.c,v 1.13 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include "robots.h" 41#include "robots.h"
42 42
43# define ESC '\033' 43# define ESC '\033'
44 44
45/* 45/*
46 * get_move: 46 * get_move:
47 * Get and execute a move from the player 47 * Get and execute a move from the player
48 */ 48 */
49void 49void
50get_move() 50get_move(void)
51{ 51{
52 int c; 52 int c;
53#ifdef FANCY 53#ifdef FANCY
54 int lastmove; 54 int lastmove;
55#endif /*FANCY*/ 55#endif /*FANCY*/
56 56
57 if (Waiting) 57 if (Waiting)
58 return; 58 return;
59 59
60#ifdef FANCY 60#ifdef FANCY
61 if (Pattern_roll) { 61 if (Pattern_roll) {
62 if (Next_move >= Move_list) 62 if (Next_move >= Move_list)
63 lastmove = *Next_move; 63 lastmove = *Next_move;
@@ -198,27 +198,27 @@ teleport: @@ -198,27 +198,27 @@ teleport:
198 } 198 }
199ret: 199ret:
200 if (Count > 0) 200 if (Count > 0)
201 if (--Count == 0) 201 if (--Count == 0)
202 leaveok(stdscr, FALSE); 202 leaveok(stdscr, FALSE);
203} 203}
204 204
205/* 205/*
206 * must_telep: 206 * must_telep:
207 * Must I teleport; i.e., is there anywhere I can move without 207 * Must I teleport; i.e., is there anywhere I can move without
208 * being eaten? 208 * being eaten?
209 */ 209 */
210bool 210bool
211must_telep() 211must_telep(void)
212{ 212{
213 int x, y; 213 int x, y;
214 static COORD newpos; 214 static COORD newpos;
215 215
216#ifdef FANCY 216#ifdef FANCY
217 if (Stand_still && Num_robots > 1 && eaten(&My_pos)) 217 if (Stand_still && Num_robots > 1 && eaten(&My_pos))
218 return TRUE; 218 return TRUE;
219#endif 219#endif
220 220
221 for (y = -1; y <= 1; y++) { 221 for (y = -1; y <= 1; y++) {
222 newpos.y = My_pos.y + y; 222 newpos.y = My_pos.y + y;
223 if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE) 223 if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE)
224 continue; 224 continue;
@@ -230,28 +230,27 @@ must_telep() @@ -230,28 +230,27 @@ must_telep()
230 continue; 230 continue;
231 if (!eaten(&newpos)) 231 if (!eaten(&newpos))
232 return FALSE; 232 return FALSE;
233 } 233 }
234 } 234 }
235 return TRUE; 235 return TRUE;
236} 236}
237 237
238/* 238/*
239 * do_move: 239 * do_move:
240 * Execute a move 240 * Execute a move
241 */ 241 */
242bool 242bool
243do_move(dy, dx) 243do_move(int dy, int dx)
244 int dy, dx; 
245{ 244{
246 static COORD newpos; 245 static COORD newpos;
247 246
248 newpos.y = My_pos.y + dy; 247 newpos.y = My_pos.y + dy;
249 newpos.x = My_pos.x + dx; 248 newpos.x = My_pos.x + dx;
250 if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE || 249 if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE ||
251 newpos.x <= 0 || newpos.x >= X_FIELDSIZE || 250 newpos.x <= 0 || newpos.x >= X_FIELDSIZE ||
252 Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) { 251 Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) {
253 if (Running) { 252 if (Running) {
254 Running = FALSE; 253 Running = FALSE;
255 leaveok(stdscr, FALSE); 254 leaveok(stdscr, FALSE);
256 move(My_pos.y, My_pos.x); 255 move(My_pos.y, My_pos.x);
257 refresh(); 256 refresh();
@@ -267,53 +266,52 @@ do_move(dy, dx) @@ -267,53 +266,52 @@ do_move(dy, dx)
267 mvaddch(My_pos.y, My_pos.x, ' '); 266 mvaddch(My_pos.y, My_pos.x, ' ');
268 My_pos = newpos; 267 My_pos = newpos;
269 mvaddch(My_pos.y, My_pos.x, PLAYER); 268 mvaddch(My_pos.y, My_pos.x, PLAYER);
270 if (!jumping()) 269 if (!jumping())
271 refresh(); 270 refresh();
272 return TRUE; 271 return TRUE;
273} 272}
274 273
275/* 274/*
276 * eaten: 275 * eaten:
277 * Player would get eaten at this place 276 * Player would get eaten at this place
278 */ 277 */
279bool 278bool
280eaten(pos) 279eaten(const COORD *pos)
281 const COORD *pos; 
282{ 280{
283 int x, y; 281 int x, y;
284 282
285 for (y = pos->y - 1; y <= pos->y + 1; y++) { 283 for (y = pos->y - 1; y <= pos->y + 1; y++) {
286 if (y <= 0 || y >= Y_FIELDSIZE) 284 if (y <= 0 || y >= Y_FIELDSIZE)
287 continue; 285 continue;
288 for (x = pos->x - 1; x <= pos->x + 1; x++) { 286 for (x = pos->x - 1; x <= pos->x + 1; x++) {
289 if (x <= 0 || x >= X_FIELDSIZE) 287 if (x <= 0 || x >= X_FIELDSIZE)
290 continue; 288 continue;
291 if (Field[y][x] == 1) 289 if (Field[y][x] == 1)
292 return TRUE; 290 return TRUE;
293 } 291 }
294 } 292 }
295 return FALSE; 293 return FALSE;
296} 294}
297 295
298/* 296/*
299 * reset_count: 297 * reset_count:
300 * Reset the count variables 298 * Reset the count variables
301 */ 299 */
302void 300void
303reset_count() 301reset_count(void)
304{ 302{
305 Count = 0; 303 Count = 0;
306 Running = FALSE; 304 Running = FALSE;
307 leaveok(stdscr, FALSE); 305 leaveok(stdscr, FALSE);
308 refresh(); 306 refresh();
309} 307}
310 308
311/* 309/*
312 * jumping: 310 * jumping:
313 * See if we are jumping, i.e., we should not refresh. 311 * See if we are jumping, i.e., we should not refresh.
314 */ 312 */
315bool 313bool
316jumping() 314jumping(void)
317{ 315{
318 return (Jump && (Count || Running || Waiting)); 316 return (Jump && (Count || Running || Waiting));
319} 317}

cvs diff -r1.5 -r1.6 src/games/robots/rnd_pos.c (expand / switch to unified diff)

--- src/games/robots/rnd_pos.c 2003/08/07 09:37:37 1.5
+++ src/games/robots/rnd_pos.c 2009/07/20 05:44:02 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rnd_pos.c,v 1.5 2003/08/07 09:37:37 agc Exp $ */ 1/* $NetBSD: rnd_pos.c,v 1.6 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,47 +24,46 @@ @@ -24,47 +24,46 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: rnd_pos.c,v 1.5 2003/08/07 09:37:37 agc Exp $"); 37__RCSID("$NetBSD: rnd_pos.c,v 1.6 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42 42
43# define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) 43# define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x)
44 44
45/* 45/*
46 * rnd_pos: 46 * rnd_pos:
47 * Pick a random, unoccupied position 47 * Pick a random, unoccupied position
48 */ 48 */
49COORD * 49COORD *
50rnd_pos() 50rnd_pos(void)
51{ 51{
52 static COORD pos; 52 static COORD pos;
53 static int call = 0; 53 static int call = 0;
54 54
55 do { 55 do {
56 pos.y = rnd(Y_FIELDSIZE - 1) + 1; 56 pos.y = rnd(Y_FIELDSIZE - 1) + 1;
57 pos.x = rnd(X_FIELDSIZE - 1) + 1; 57 pos.x = rnd(X_FIELDSIZE - 1) + 1;
58 refresh(); 58 refresh();
59 } while (Field[pos.y][pos.x] != 0); 59 } while (Field[pos.y][pos.x] != 0);
60 call++; 60 call++;
61 return &pos; 61 return &pos;
62} 62}
63 63
64int 64int
65rnd(range) 65rnd(int range)
66 int range; 
67{ 66{
68 67
69 return rand() % range; 68 return rand() % range;
70} 69}

cvs diff -r1.18 -r1.19 src/games/robots/robots.h (expand / switch to unified diff)

--- src/games/robots/robots.h 2004/01/27 20:30:30 1.18
+++ src/games/robots/robots.h 2009/07/20 05:44:02 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: robots.h,v 1.18 2004/01/27 20:30:30 jsm Exp $ */ 1/* $NetBSD: robots.h,v 1.19 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -107,40 +107,40 @@ extern bool Pattern_roll, Stand_still; @@ -107,40 +107,40 @@ extern bool Pattern_roll, Stand_still;
107extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], Run_ch; 107extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], Run_ch;
108extern const char *Next_move, *Move_list; 108extern const char *Next_move, *Move_list;
109 109
110extern int Count, Level, Num_robots, Num_scrap, Num_scores, 110extern int Count, Level, Num_robots, Num_scrap, Num_scores,
111 Start_level, Wait_bonus, Num_games; 111 Start_level, Wait_bonus, Num_games;
112 112
113extern u_int32_t Score; 113extern u_int32_t Score;
114 114
115extern COORD Max, Min, My_pos, Robots[], Scrap[]; 115extern COORD Max, Min, My_pos, Robots[], Scrap[];
116 116
117extern jmp_buf End_move; 117extern jmp_buf End_move;
118 118
119/* 119/*
120 * functions types 120 * functions
121 */ 121 */
122 122
123void add_score(int); 123void add_score(int);
124bool another(void); 124bool another(void);
125char automove(void); 125char automove(void);
126int cmp_sc(const void *, const void *); 126int cmp_sc(const void *, const void *);
127bool do_move(int, int); 127bool do_move(int, int);
128bool eaten(const COORD *); 128bool eaten(const COORD *);
129void flush_in(void); 129void flush_in(void);
130void get_move(void); 130void get_move(void);
131void init_field(void); 131void init_field(void);
132bool jumping(void); 132bool jumping(void);
133void make_level(void); 133void make_level(void);
134void move_robots(int); 134void move_robots(int);
135bool must_telep(void); 135bool must_telep(void);
136void play_level(void); 136void play_level(void);
137int query(const char *); 137int query(const char *);
138void quit(int) __attribute__((__noreturn__)); 138void quit(int) __dead;
139void reset_count(void); 139void reset_count(void);
140int rnd(int); 140int rnd(int);
141COORD *rnd_pos(void); 141COORD *rnd_pos(void);
142void score(int); 142void score(int);
143void set_name(SCORE *); 143void set_name(SCORE *);
144void show_score(void); 144void show_score(void);
145int sign(int); 145int sign(int);
146void telmsg(int); 146void telmsg(int);

cvs diff -r1.18 -r1.19 src/games/robots/score.c (expand / switch to unified diff)

--- src/games/robots/score.c 2006/03/17 23:11:47 1.18
+++ src/games/robots/score.c 2009/07/20 05:44:02 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: score.c,v 1.18 2006/03/17 23:11:47 abs Exp $ */ 1/* $NetBSD: score.c,v 1.19 2009/07/20 05:44:02 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,106 +24,103 @@ @@ -24,106 +24,103 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: score.c,v 1.18 2006/03/17 23:11:47 abs Exp $"); 37__RCSID("$NetBSD: score.c,v 1.19 2009/07/20 05:44:02 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "robots.h" 41# include "robots.h"
42# include "pathnames.h" 42# include "pathnames.h"
43 43
44const char *Scorefile = _PATH_SCORE; 44const char *Scorefile = _PATH_SCORE;
45 45
46int Max_per_uid = MAX_PER_UID; 46int Max_per_uid = MAX_PER_UID;
47 47
48static SCORE Top[MAXSCORES]; 48static SCORE Top[MAXSCORES];
49 49
50static u_int32_t numscores, max_uid; 50static u_int32_t numscores, max_uid;
51 51
52static void read_score(int); 52static void read_score(int);
53static void write_score(int); 53static void write_score(int);
54 54
55/* 55/*
56 * read_score: 56 * read_score:
57 * Read the score file in MI format 57 * Read the score file in MI format
58 */ 58 */
59static void 59static void
60read_score(inf) 60read_score(int inf)
61 int inf; 
62{ 61{
63 SCORE *scp; 62 SCORE *scp;
64 63
65 if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid) { 64 if (read(inf, &max_uid, sizeof max_uid) == sizeof max_uid) {
66 max_uid = ntohl(max_uid); 65 max_uid = ntohl(max_uid);
67 66
68 read(inf, Top, sizeof Top); 67 read(inf, Top, sizeof Top);
69 for (scp = Top; scp < &Top[MAXSCORES]; scp++) { 68 for (scp = Top; scp < &Top[MAXSCORES]; scp++) {
70 scp->s_uid = ntohl(scp->s_uid); 69 scp->s_uid = ntohl(scp->s_uid);
71 scp->s_score = ntohl(scp->s_score); 70 scp->s_score = ntohl(scp->s_score);
72 scp->s_auto = ntohl(scp->s_auto); 71 scp->s_auto = ntohl(scp->s_auto);
73 scp->s_level = ntohl(scp->s_level); 72 scp->s_level = ntohl(scp->s_level);
74 } 73 }
75 } 74 }
76 else { 75 else {
77 for (scp = Top; scp < &Top[MAXSCORES]; scp++) 76 for (scp = Top; scp < &Top[MAXSCORES]; scp++)
78 scp->s_score = 0; 77 scp->s_score = 0;
79 max_uid = Max_per_uid; 78 max_uid = Max_per_uid;
80 } 79 }
81} 80}
82 81
83/* 82/*
84 * write_score: 83 * write_score:
85 * Write the score file in MI format 84 * Write the score file in MI format
86 */ 85 */
87static void 86static void
88write_score(inf) 87write_score(int inf)
89 int inf; 
90{ 88{
91 SCORE *scp; 89 SCORE *scp;
92 90
93 lseek(inf, 0L, SEEK_SET); 91 lseek(inf, 0L, SEEK_SET);
94 92
95 max_uid = htonl(max_uid); 93 max_uid = htonl(max_uid);
96 write(inf, &max_uid, sizeof max_uid); 94 write(inf, &max_uid, sizeof max_uid);
97 95
98 for (scp = Top; scp < &Top[MAXSCORES]; scp++) { 96 for (scp = Top; scp < &Top[MAXSCORES]; scp++) {
99 scp->s_uid = htonl(scp->s_uid); 97 scp->s_uid = htonl(scp->s_uid);
100 scp->s_score = htonl(scp->s_score); 98 scp->s_score = htonl(scp->s_score);
101 scp->s_auto = htonl(scp->s_auto); 99 scp->s_auto = htonl(scp->s_auto);
102 scp->s_level = htonl(scp->s_level); 100 scp->s_level = htonl(scp->s_level);
103 } 101 }
104 102
105 write(inf, Top, sizeof Top); 103 write(inf, Top, sizeof Top);
106} 104}
107 105
108 106
109/* 107/*
110 * score: 108 * score:
111 * Post the player's score, if reasonable, and then print out the 109 * Post the player's score, if reasonable, and then print out the
112 * top list. 110 * top list.
113 */ 111 */
114void 112void
115score(score_wfd) 113score(int score_wfd)
116 int score_wfd; 
117{ 114{
118 int inf = score_wfd; 115 int inf = score_wfd;
119 SCORE *scp; 116 SCORE *scp;
120 u_int32_t uid; 117 u_int32_t uid;
121 bool done_show = FALSE; 118 bool done_show = FALSE;
122 119
123 Newscore = FALSE; 120 Newscore = FALSE;
124 if (inf < 0) 121 if (inf < 0)
125 return; 122 return;
126 123
127 read_score(inf); 124 read_score(inf);
128 125
129 uid = getuid(); 126 uid = getuid();
@@ -179,54 +176,52 @@ score(score_wfd) @@ -179,54 +176,52 @@ score(score_wfd)
179 done_show = TRUE; 176 done_show = TRUE;
180 } 177 }
181 } 178 }
182 Num_scores = scp - Top; 179 Num_scores = scp - Top;
183 refresh(); 180 refresh();
184 181
185 if (Newscore) { 182 if (Newscore) {
186 write_score(inf); 183 write_score(inf);
187 } 184 }
188 lseek(inf, 0, SEEK_SET); 185 lseek(inf, 0, SEEK_SET);
189} 186}
190 187
191void 188void
192set_name(scp) 189set_name(SCORE *scp)
193 SCORE *scp; 
194{ 190{
195 PASSWD *pp; 191 PASSWD *pp;
196 192
197 if ((pp = getpwuid(scp->s_uid)) == NULL) 193 if ((pp = getpwuid(scp->s_uid)) == NULL)
198 strncpy(scp->s_name, "???", MAXNAME); 194 strncpy(scp->s_name, "???", MAXNAME);
199 else 195 else
200 strncpy(scp->s_name, pp->pw_name, MAXNAME); 196 strncpy(scp->s_name, pp->pw_name, MAXNAME);
201} 197}
202 198
203/* 199/*
204 * cmp_sc: 200 * cmp_sc:
205 * Compare two scores. 201 * Compare two scores.
206 */ 202 */
207int 203int
208cmp_sc(s1, s2) 204cmp_sc(const void *s1, const void *s2)
209 const void *s1, *s2; 
210{ 205{
211 return ((const SCORE *)s2)->s_score - ((const SCORE *)s1)->s_score; 206 return ((const SCORE *)s2)->s_score - ((const SCORE *)s1)->s_score;
212} 207}
213 208
214/* 209/*
215 * show_score: 210 * show_score:
216 * Show the score list for the '-s' option. 211 * Show the score list for the '-s' option.
217 */ 212 */
218void 213void
219show_score() 214show_score(void)
220{ 215{
221 SCORE *scp; 216 SCORE *scp;
222 int inf; 217 int inf;
223 218
224 if ((inf = open(Scorefile, O_RDONLY)) < 0) { 219 if ((inf = open(Scorefile, O_RDONLY)) < 0) {
225 warn("opening `%s'", Scorefile); 220 warn("opening `%s'", Scorefile);
226 return; 221 return;
227 } 222 }
228 223
229 read_score(inf); 224 read_score(inf);
230 close(inf); 225 close(inf);
231 inf = 1; 226 inf = 1;
232 printf("%5.5s %5.5s %-9.9s %-8.8s %5.5s\n", "Rank", "Score", "User", 227 printf("%5.5s %5.5s %-9.9s %-8.8s %5.5s\n", "Rank", "Score", "User",