Annotation of 43BSDReno/games/robots/move_robs.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.