1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 05/31/93"; 10 #endif /* not lint */ 11 12 # include "robots.h" 13 # include <signal.h> 14 15 /* 16 * move_robots: 17 * Move the robots around 18 */ 19 void 20 move_robots(was_sig) 21 bool was_sig; 22 { 23 register COORD *rp; 24 register int y, x; 25 register int mindist, d; 26 static COORD newpos; 27 28 if (Real_time) 29 signal(SIGALRM, move_robots); 30 # ifdef DEBUG 31 move(Min.y, Min.x); 32 addch(inch()); 33 move(Max.y, Max.x); 34 addch(inch()); 35 # endif DEBUG 36 for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) { 37 if (rp->y < 0) 38 continue; 39 mvaddch(rp->y, rp->x, ' '); 40 Field[rp->y][rp->x]--; 41 rp->y += sign(My_pos.y - rp->y); 42 rp->x += sign(My_pos.x - rp->x); 43 if (rp->y <= 0) 44 rp->y = 0; 45 else if (rp->y >= Y_FIELDSIZE) 46 rp->y = Y_FIELDSIZE - 1; 47 if (rp->x <= 0) 48 rp->x = 0; 49 else if (rp->x >= X_FIELDSIZE) 50 rp->x = X_FIELDSIZE - 1; 51 Field[rp->y][rp->x]++; 52 } 53 54 Min.y = Y_FIELDSIZE; 55 Min.x = X_FIELDSIZE; 56 Max.y = 0; 57 Max.x = 0; 58 for (rp = Robots; rp < &Robots[MAXROBOTS]; rp++) 59 if (rp->y < 0) 60 continue; 61 else if (rp->y == My_pos.y && rp->x == My_pos.x) 62 Dead = TRUE; 63 else if (Field[rp->y][rp->x] > 1) { 64 mvaddch(rp->y, rp->x, HEAP); 65 rp->y = -1; 66 Num_robots--; 67 if (Waiting) 68 Wait_bonus++; 69 add_score(ROB_SCORE); 70 } 71 else { 72 mvaddch(rp->y, rp->x, ROBOT); 73 if (rp->y < Min.y) 74 Min.y = rp->y; 75 if (rp->x < Min.x) 76 Min.x = rp->x; 77 if (rp->y > Max.y) 78 Max.y = rp->y; 79 if (rp->x > Max.x) 80 Max.x = rp->x; 81 } 82 83 if (was_sig) { 84 refresh(); 85 if (Dead || Num_robots <= 0) 86 longjmp(End_move, 0); 87 } 88 89 # ifdef DEBUG 90 standout(); 91 move(Min.y, Min.x); 92 addch(inch()); 93 move(Max.y, Max.x); 94 addch(inch()); 95 standend(); 96 # endif DEBUG 97 if (Real_time) 98 alarm(3); 99 } 100 101 /* 102 * add_score: 103 * Add a score to the overall point total 104 */ 105 add_score(add) 106 int add; 107 { 108 Score += add; 109 move(Y_SCORE, X_SCORE); 110 printw("%d", Score); 111 } 112 113 /* 114 * sign: 115 * Return the sign of the number 116 */ 117 sign(n) 118 int n; 119 { 120 if (n < 0) 121 return -1; 122 else if (n > 0) 123 return 1; 124 else 125 return 0; 126 } 127