ANSIfy. Use __dead. Object diffs checked.diff -r1.8 -r1.9 src/games/robots/auto.c
(dholland)
--- 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); | |||
63 | static int yinc(int); | 63 | static int yinc(int); | |
64 | static const char *find_moves(void); | 64 | static const char *find_moves(void); | |
65 | static COORD *closest_robot(int *); | 65 | static COORD *closest_robot(int *); | |
66 | static COORD *closest_heap(int *); | 66 | static COORD *closest_heap(int *); | |
67 | static char move_towards(int, int); | 67 | static char move_towards(int, int); | |
68 | static char move_away(COORD *); | 68 | static char move_away(COORD *); | |
69 | static char move_between(COORD *, COORD *); | 69 | static char move_between(COORD *, COORD *); | |
70 | static int between(COORD *, COORD *); | 70 | static 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 | */ | |
75 | static int | 75 | static int | |
76 | distance(x1, y1, x2, y2) | 76 | distance(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 | */ | |
85 | static int | 84 | static int | |
86 | xinc(dir) | 85 | xinc(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 | */ | |
108 | static int | 106 | static int | |
109 | yinc(dir) | 107 | yinc(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 | */ | |
131 | static const char * | 128 | static const char * | |
132 | find_moves() | 129 | find_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 | */ | |
171 | static COORD * | 168 | static COORD * | |
172 | closest_robot(dist) | 169 | closest_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 | */ | |
195 | static COORD * | 191 | static COORD * | |
196 | closest_heap(dist) | 192 | closest_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 | */ | |
220 | static char | 215 | static char | |
221 | move_towards(dx, dy) | 216 | move_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 | */ | |
250 | static char | 244 | static char | |
251 | move_away(rob) | 245 | move_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 | */ | |
265 | static char | 258 | static char | |
266 | move_between(rob, hp) | 259 | move_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 | */ | |
322 | int | 313 | int | |
323 | between(rob, hp) | 314 | between(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 | */ | |
350 | char | 339 | char | |
351 | automove() | 340 | automove(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 | } |
--- 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 | |
35 | static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | |||
43 | static int telx = 0; | 43 | static int telx = 0; | |
44 | static int tely = 0; | 44 | static 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 | */ | |
51 | void | 51 | void | |
52 | init_field() | 52 | init_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 | |||
125 | void | 125 | void | |
126 | telmsg(on) | 126 | telmsg(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 | } |
--- 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 | |
35 | static char sccsid[] = "@(#)flush_in.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
47 | void | 47 | void | |
48 | flush_in() | 48 | flush_in(void) | |
49 | { | 49 | { | |
50 | tcflush(fileno(stdin), TCIFLUSH); | 50 | tcflush(fileno(stdin), TCIFLUSH); | |
51 | } | 51 | } |
--- 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 | |
35 | static char sccsid[] = "@(#)play_level.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
47 | void | 47 | void | |
48 | play_level() | 48 | play_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(); |
--- 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 | |
35 | static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
47 | int | 47 | int | |
48 | query(prompt) | 48 | query(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); |
--- 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 | |
40 | static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; | 40 | static 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 | |||
48 | int main(int, char **); | |||
49 | ||||
50 | extern const char *Scorefile; | 48 | extern const char *Scorefile; | |
51 | extern int Max_per_uid; | 49 | extern int Max_per_uid; | |
52 | 50 | |||
53 | int | 51 | int | |
54 | main(ac, av) | 52 | main(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 | */ | |
199 | void | 195 | void | |
200 | quit(dummy) | 196 | quit(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 | */ | |
212 | bool | 207 | bool | |
213 | another() | 208 | another(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(); |
--- 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 | |
35 | static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
47 | void | 47 | void | |
48 | make_level() | 48 | make_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 |
--- 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 | |
35 | static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
47 | void | 47 | void | |
48 | move_robots(was_sig) | 48 | move_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 | */ | |
131 | void | 130 | void | |
132 | add_score(add) | 131 | add_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 | */ | |
144 | int | 142 | int | |
145 | sign(n) | 143 | sign(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 | } |
--- 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 | |
35 | static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
49 | void | 49 | void | |
50 | get_move() | 50 | get_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 | } | |
199 | ret: | 199 | ret: | |
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 | */ | |
210 | bool | 210 | bool | |
211 | must_telep() | 211 | must_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 | */ | |
242 | bool | 242 | bool | |
243 | do_move(dy, dx) | 243 | do_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 | */ | |
279 | bool | 278 | bool | |
280 | eaten(pos) | 279 | eaten(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 | */ | |
302 | void | 300 | void | |
303 | reset_count() | 301 | reset_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 | */ | |
315 | bool | 313 | bool | |
316 | jumping() | 314 | jumping(void) | |
317 | { | 315 | { | |
318 | return (Jump && (Count || Running || Waiting)); | 316 | return (Jump && (Count || Running || Waiting)); | |
319 | } | 317 | } |
--- 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 | |
35 | static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | */ | |
49 | COORD * | 49 | COORD * | |
50 | rnd_pos() | 50 | rnd_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 | |||
64 | int | 64 | int | |
65 | rnd(range) | 65 | rnd(int range) | |
66 | int range; | |||
67 | { | 66 | { | |
68 | 67 | |||
69 | return rand() % range; | 68 | return rand() % range; | |
70 | } | 69 | } |
--- 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; | |||
107 | extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], Run_ch; | 107 | extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], Run_ch; | |
108 | extern const char *Next_move, *Move_list; | 108 | extern const char *Next_move, *Move_list; | |
109 | 109 | |||
110 | extern int Count, Level, Num_robots, Num_scrap, Num_scores, | 110 | extern 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 | |||
113 | extern u_int32_t Score; | 113 | extern u_int32_t Score; | |
114 | 114 | |||
115 | extern COORD Max, Min, My_pos, Robots[], Scrap[]; | 115 | extern COORD Max, Min, My_pos, Robots[], Scrap[]; | |
116 | 116 | |||
117 | extern jmp_buf End_move; | 117 | extern jmp_buf End_move; | |
118 | 118 | |||
119 | /* | 119 | /* | |
120 | * functions types | 120 | * functions | |
121 | */ | 121 | */ | |
122 | 122 | |||
123 | void add_score(int); | 123 | void add_score(int); | |
124 | bool another(void); | 124 | bool another(void); | |
125 | char automove(void); | 125 | char automove(void); | |
126 | int cmp_sc(const void *, const void *); | 126 | int cmp_sc(const void *, const void *); | |
127 | bool do_move(int, int); | 127 | bool do_move(int, int); | |
128 | bool eaten(const COORD *); | 128 | bool eaten(const COORD *); | |
129 | void flush_in(void); | 129 | void flush_in(void); | |
130 | void get_move(void); | 130 | void get_move(void); | |
131 | void init_field(void); | 131 | void init_field(void); | |
132 | bool jumping(void); | 132 | bool jumping(void); | |
133 | void make_level(void); | 133 | void make_level(void); | |
134 | void move_robots(int); | 134 | void move_robots(int); | |
135 | bool must_telep(void); | 135 | bool must_telep(void); | |
136 | void play_level(void); | 136 | void play_level(void); | |
137 | int query(const char *); | 137 | int query(const char *); | |
138 | void quit(int) __attribute__((__noreturn__)); | 138 | void quit(int) __dead; | |
139 | void reset_count(void); | 139 | void reset_count(void); | |
140 | int rnd(int); | 140 | int rnd(int); | |
141 | COORD *rnd_pos(void); | 141 | COORD *rnd_pos(void); | |
142 | void score(int); | 142 | void score(int); | |
143 | void set_name(SCORE *); | 143 | void set_name(SCORE *); | |
144 | void show_score(void); | 144 | void show_score(void); | |
145 | int sign(int); | 145 | int sign(int); | |
146 | void telmsg(int); | 146 | void telmsg(int); |
--- 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 | |
35 | static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; | 35 | static 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 | |||
44 | const char *Scorefile = _PATH_SCORE; | 44 | const char *Scorefile = _PATH_SCORE; | |
45 | 45 | |||
46 | int Max_per_uid = MAX_PER_UID; | 46 | int Max_per_uid = MAX_PER_UID; | |
47 | 47 | |||
48 | static SCORE Top[MAXSCORES]; | 48 | static SCORE Top[MAXSCORES]; | |
49 | 49 | |||
50 | static u_int32_t numscores, max_uid; | 50 | static u_int32_t numscores, max_uid; | |
51 | 51 | |||
52 | static void read_score(int); | 52 | static void read_score(int); | |
53 | static void write_score(int); | 53 | static 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 | */ | |
59 | static void | 59 | static void | |
60 | read_score(inf) | 60 | read_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 | */ | |
87 | static void | 86 | static void | |
88 | write_score(inf) | 87 | write_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 | */ | |
114 | void | 112 | void | |
115 | score(score_wfd) | 113 | score(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 | |||
191 | void | 188 | void | |
192 | set_name(scp) | 189 | set_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 | */ | |
207 | int | 203 | int | |
208 | cmp_sc(s1, s2) | 204 | cmp_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 | */ | |
218 | void | 213 | void | |
219 | show_score() | 214 | show_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", |