Annotation of researchv10no/games/trek/klmove.c, revision 1.1.1.1

1.1       root        1: # include      "trek.h"
                      2: 
                      3: /**
                      4:  **    move klingons around
                      5:  **/
                      6: 
                      7: klmove(fl)
                      8: int    fl;
                      9: {
                     10:        int                     n, i;
                     11:        register KLINGONS       *k;
                     12:        double                  dx, dy;
                     13:        int                     nextx, nexty;
                     14:        register int            lookx, looky;
                     15:        int                     motion;
                     16:        int                     fudgex, fudgey;
                     17:        int                     qx, qy;
                     18:        double                  bigger;
                     19: 
                     20: #ifdef TRACE
                     21:        if (tTf(20,0))
                     22:                printf("entered klmove fl = %d, Nkling = %d\n", fl, Nkling);
                     23: #endif
                     24:        for (n = 0; n < Nkling; k && n++)
                     25:        {
                     26:                k = &Kling[n];
                     27:                i = 100;
                     28:                if (fl)
                     29:                        if(Param.klingpwr != 0.)
                     30:                                i = 100.0 * k->power / Param.klingpwr;
                     31:                if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl])
                     32:                        continue;
                     33:                /* compute distance to move */
                     34:                motion = ranf(75) - 25;
                     35:                motion =* k->avgdist * Param.movefac[2 * Move.newquad + fl];
                     36:                /* compute direction */
                     37:                dx = Sectx - k->x + ranf(3) - 1;
                     38:                dy = Secty - k->y + ranf(3) - 1;
                     39:                bigger = dx;
                     40:                if (dy > bigger)
                     41:                        bigger = dy;
                     42:                if(bigger == 0.)
                     43:                        bigger = 1.;
                     44:                dx = dx / bigger + 0.5;
                     45:                dy = dy / bigger + 0.5;
                     46:                if (motion < 0)
                     47:                {
                     48:                        motion = -motion;
                     49:                        dx = -dx;
                     50:                        dy = -dy;
                     51:                }
                     52:                fudgex = fudgey = 1;
                     53:                /* try to move the klingon */
                     54:                nextx = k->x;
                     55:                nexty = k->y;
                     56:                for (; motion > 0; motion--)
                     57:                {
                     58:                        lookx = nextx + dx;
                     59:                        looky = nexty + dy;
                     60:                        if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS)
                     61:                        {
                     62:                                /* new quadrant */
                     63:                                qx = Quadx;
                     64:                                qy = Quady;
                     65:                                if (lookx < 0)
                     66:                                        qx =- 1;
                     67:                                else
                     68:                                        if (lookx >= NSECTS)
                     69:                                                qx =+ 1;
                     70:                                if (looky < 0)
                     71:                                        qy =- 1;
                     72:                                else
                     73:                                        if (looky >= NSECTS)
                     74:                                                qy =+ 1;
                     75:                                if(movkling(Quadx,Quady,qx,qy)) {
                     76:                                        printf("Klingon at %d,%d escapes to quadrant %d,%d\n",
                     77:                                                k->x, k->y, qx, qy);
                     78:                                        Nkling =- 1;
                     79:                                        Sect[k->x][k->y] = EMPTY;
                     80:                                        bmove(&Kling[Nkling], k, sizeof *k);
                     81:                                }
                     82:                                k = 0;
                     83:                                break;
                     84:                        }
                     85:                        if (Sect[lookx][looky] != EMPTY)
                     86:                        {
                     87:                                lookx = nextx + fudgex;
                     88:                                if (lookx < 0 || lookx >= NSECTS)
                     89:                                        lookx = nextx + dx;
                     90:                                if (Sect[lookx][looky] != EMPTY)
                     91:                                {
                     92:                                        fudgex = -fudgex;
                     93:                                        looky = nexty + fudgey;
                     94:                                        if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY)
                     95:                                        {
                     96:                                                fudgey = -fudgey;
                     97:                                                break;
                     98:                                        }
                     99:                                }
                    100:                        }
                    101:                        nextx = lookx;
                    102:                        nexty = looky;
                    103:                }
                    104:                if (k && (k->x != nextx || k->y != nexty))
                    105:                {
                    106:                        printf("Klingon at %d,%d moves to %d,%d\n",
                    107:                                k->x, k->y, nextx, nexty);
                    108:                        Sect[k->x][k->y] = EMPTY;
                    109:                        Sect[k->x = nextx][k->y = nexty] = KLINGON;
                    110:                }
                    111:        }
                    112:        compkldist(0);
                    113: }
                    114: 
                    115: 
                    116: movkling(fqx,fqy,qx,qy)
                    117: int    fqx, fqy;
                    118: int    qx, qy;
                    119: {
                    120:        register int    qs;
                    121: 
                    122:        if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS ||
                    123:                        Quad[qx][qy].stars < 0 || Quad[qx][qy].qkling > 8)
                    124:                return(0);
                    125:        qs = Quad[qx][qy].scanned;
                    126:        if (qs >= 0 && qs < 1000)
                    127:                Quad[qx][qy].scanned =+ 100;
                    128:        qs = Quad[fqx][fqy].scanned;
                    129:        if (qs >= 0 && qs < 1000)
                    130:                Quad[fqx][fqy].scanned =- 100;
                    131:        Quad[fqx][fqy].qkling =- 1;
                    132:        Quad[qx][qy].qkling =+ 1;
                    133:        return(1);
                    134: }

unix.superglobalmegacorp.com

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