Annotation of 42BSD/games/trek/help.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)help.c     4.2     (Berkeley)      5/9/83";
        !             3: #endif not lint
        !             4: 
        !             5: # include      "trek.h"
        !             6: 
        !             7: /*
        !             8: **  call starbase for help
        !             9: **
        !            10: **     First, the closest starbase is selected.  If there is a
        !            11: **     a starbase in your own quadrant, you are in good shape.
        !            12: **     This distance takes quadrant distances into account only.
        !            13: **
        !            14: **     A magic number is computed based on the distance which acts
        !            15: **     as the probability that you will be rematerialized.  You
        !            16: **     get three tries.
        !            17: **
        !            18: **     When it is determined that you should be able to be remater-
        !            19: **     ialized (i.e., when the probability thing mentioned above
        !            20: **     comes up positive), you are put into that quadrant (anywhere).
        !            21: **     Then, we try to see if there is a spot adjacent to the star-
        !            22: **     base.  If not, you can't be rematerialized!!!  Otherwise,
        !            23: **     it drops you there.  It only tries five times to find a spot
        !            24: **     to drop you.  After that, it's your problem.
        !            25: */
        !            26: 
        !            27: char   *Cntvect[3] =
        !            28: {"first", "second", "third"};
        !            29: 
        !            30: help()
        !            31: {
        !            32:        register int            i;
        !            33:        double                  dist, x;
        !            34:        register int            dx, dy;
        !            35:        int                     j, l;
        !            36: 
        !            37:        /* check to see if calling for help is reasonable ... */
        !            38:        if (Ship.cond == DOCKED)
        !            39:                return (printf("Uhura: But Captain, we're already docked\n"));
        !            40: 
        !            41:        /* or possible */
        !            42:        if (damaged(SSRADIO))
        !            43:                return (out(SSRADIO));
        !            44:        if (Now.bases <= 0)
        !            45:                return (printf("Uhura: I'm not getting any response from starbase\n"));
        !            46: 
        !            47:        /* tut tut, there goes the score */
        !            48:        Game.helps += 1;
        !            49: 
        !            50:        /* find the closest base */
        !            51:        dist = 1e50;
        !            52:        if (Quad[Ship.quadx][Ship.quady].bases <= 0)
        !            53:        {
        !            54:                /* there isn't one in this quadrant */
        !            55:                for (i = 0; i < Now.bases; i++)
        !            56:                {
        !            57:                        /* compute distance */
        !            58:                        dx = Now.base[i].x - Ship.quadx;
        !            59:                        dy = Now.base[i].y - Ship.quady;
        !            60:                        x = dx * dx + dy * dy;
        !            61:                        x = sqrt(x);
        !            62: 
        !            63:                        /* see if better than what we already have */
        !            64:                        if (x < dist)
        !            65:                        {
        !            66:                                dist = x;
        !            67:                                l = i;
        !            68:                        }
        !            69:                }
        !            70: 
        !            71:                /* go to that quadrant */
        !            72:                Ship.quadx = Now.base[l].x;
        !            73:                Ship.quady = Now.base[l].y;
        !            74:                initquad(1);
        !            75:        }
        !            76:        else
        !            77:        {
        !            78:                dist = 0.0;
        !            79:        }
        !            80: 
        !            81:        /* dematerialize the Enterprise */
        !            82:        Sect[Ship.sectx][Ship.secty] = EMPTY;
        !            83:        printf("Starbase in %d,%d responds\n", Ship.quadx, Ship.quady);
        !            84: 
        !            85:        /* this next thing acts as a probability that it will work */
        !            86:        x = pow(1.0 - pow(0.94, dist), 0.3333333);
        !            87: 
        !            88:        /* attempt to rematerialize */
        !            89:        for (i = 0; i < 3; i++)
        !            90:        {
        !            91:                sleep(2);
        !            92:                printf("%s attempt to rematerialize ", Cntvect[i]);
        !            93:                if (franf() > x)
        !            94:                {
        !            95:                        /* ok, that's good.  let's see if we can set her down */
        !            96:                        for (j = 0; j < 5; j++)
        !            97:                        {
        !            98:                                dx = Etc.starbase.x + ranf(3) - 1;
        !            99:                                if (dx < 0 || dx >= NSECTS)
        !           100:                                        continue;
        !           101:                                dy = Etc.starbase.y + ranf(3) - 1;
        !           102:                                if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY)
        !           103:                                        continue;
        !           104:                                break;
        !           105:                        }
        !           106:                        if (j < 5)
        !           107:                        {
        !           108:                                /* found an empty spot */
        !           109:                                printf("succeeds\n");
        !           110:                                Ship.sectx = dx;
        !           111:                                Ship.secty = dy;
        !           112:                                Sect[dx][dy] = Ship.ship;
        !           113:                                dock();
        !           114:                                compkldist(0);
        !           115:                                return;
        !           116:                        }
        !           117:                        /* the starbase must have been surrounded */
        !           118:                }
        !           119:                printf("fails\n");
        !           120:        }
        !           121: 
        !           122:        /* one, two, three strikes, you're out */
        !           123:        lose(L_NOHELP);
        !           124: }

unix.superglobalmegacorp.com

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