|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: static char sccsid[] = "@(#)move_robs.c 5.3 (Berkeley) 6/18/88";
20: #endif /* not lint */
21:
22: # include "robots.h"
23: # include <signal.h>
24:
25: /*
26: * move_robots:
27: * Move the robots around
28: */
29: move_robots(was_sig)
30: bool was_sig;
31: {
32: register COORD *rp;
33: register int y, x;
34: register int mindist, d;
35: static COORD newpos;
36:
37: if (Real_time)
38: signal(SIGALRM, move_robots);
39: # ifdef DEBUG
40: move(Min.y, Min.x);
41: addch(inch());
42: move(Max.y, Max.x);
43: addch(inch());
44: # endif DEBUG
45: for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) {
46: if (rp->y < 0)
47: continue;
48: mvaddch(rp->y, rp->x, ' ');
49: Field[rp->y][rp->x]--;
50: rp->y += sign(My_pos.y - rp->y);
51: rp->x += sign(My_pos.x - rp->x);
52: if (rp->y <= 0)
53: rp->y = 0;
54: else if (rp->y >= Y_FIELDSIZE)
55: rp->y = Y_FIELDSIZE - 1;
56: if (rp->x <= 0)
57: rp->x = 0;
58: else if (rp->x >= X_FIELDSIZE)
59: rp->x = X_FIELDSIZE - 1;
60: Field[rp->y][rp->x]++;
61: }
62:
63: Min.y = Y_FIELDSIZE;
64: Min.x = X_FIELDSIZE;
65: Max.y = 0;
66: Max.x = 0;
67: for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++)
68: if (rp->y < 0)
69: continue;
70: else if (rp->y == My_pos.y && rp->x == My_pos.x)
71: Dead = TRUE;
72: else if (Field[rp->y][rp->x] > 1) {
73: mvaddch(rp->y, rp->x, HEAP);
74: rp->y = -1;
75: Num_robots--;
76: if (Waiting)
77: Wait_bonus++;
78: add_score(ROB_SCORE);
79: }
80: else {
81: mvaddch(rp->y, rp->x, ROBOT);
82: if (rp->y < Min.y)
83: Min.y = rp->y;
84: if (rp->x < Min.x)
85: Min.x = rp->x;
86: if (rp->y > Max.y)
87: Max.y = rp->y;
88: if (rp->x > Max.x)
89: Max.x = rp->x;
90: }
91:
92: if (was_sig) {
93: refresh();
94: if (Dead || Num_robots <= 0)
95: longjmp(End_move);
96: }
97:
98: # ifdef DEBUG
99: standout();
100: move(Min.y, Min.x);
101: addch(inch());
102: move(Max.y, Max.x);
103: addch(inch());
104: standend();
105: # endif DEBUG
106: if (Real_time)
107: alarm(3);
108: }
109:
110: /*
111: * add_score:
112: * Add a score to the overall point total
113: */
114: add_score(add)
115: int add;
116: {
117: Score += add;
118: move(Y_SCORE, X_SCORE);
119: printw("%d", Score);
120: }
121:
122: /*
123: * sign:
124: * Return the sign of the number
125: */
126: sign(n)
127: int n;
128: {
129: if (n < 0)
130: return -1;
131: else if (n > 0)
132: return 1;
133: else
134: return 0;
135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.