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

Defined functions

add_score defined in line 103; used 3 times
move_robots defined in line 18; used 3 times
sign defined in line 115; used 2 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-05-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3075
Valid CSS Valid XHTML 1.0 Strict