Annotation of 43BSD/games/trek/warp.c, revision 1.1.1.1

1.1       root        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[] = "@(#)warp.c     5.1 (Berkeley) 1/29/86";
                      9: #endif not lint
                     10: 
                     11: # include      "trek.h"
                     12: 
                     13: /*
                     14: **  MOVE UNDER WARP POWER
                     15: **
                     16: **     This is both the "move" and the "ram" commands, differing
                     17: **     only in the flag 'fl'.  It is also used for automatic
                     18: **     emergency override mode, when 'fl' is < 0 and 'c' and 'd'
                     19: **     are the course and distance to be moved.  If 'fl' >= 0,
                     20: **     the course and distance are asked of the captain.
                     21: **
                     22: **     The guts of this routine are in the routine move(), which
                     23: **     is shared with impulse().  Also, the working part of this
                     24: **     routine is very small; the rest is to handle the slight chance
                     25: **     that you may be moving at some riduculous speed.  In that
                     26: **     case, there is code to handle time warps, etc.
                     27: */
                     28: 
                     29: warp(fl, c, d)
                     30: int    fl, c;
                     31: double d;
                     32: {
                     33:        int                     course;
                     34:        double                  power;
                     35:        double                  dist;
                     36:        double                  time;
                     37:        double                  speed;
                     38:        double                  frac;
                     39:        register int            percent;
                     40:        register int            i;
                     41:        extern double           move();
                     42: 
                     43:        if (Ship.cond == DOCKED)
                     44:                return (printf("%s is docked\n", Ship.shipname));
                     45:        if (damaged(WARP))
                     46:        {
                     47:                return (out(WARP));
                     48:        }
                     49:        if (fl < 0)
                     50:        {
                     51:                course = c;
                     52:                dist = d;
                     53:        }
                     54:        else
                     55:                if (getcodi(&course, &dist))
                     56:                        return;
                     57: 
                     58:        /* check to see that we are not using an absurd amount of power */
                     59:        power = (dist + 0.05) * Ship.warp3;
                     60:        percent = 100 * power / Ship.energy + 0.5;
                     61:        if (percent >= 85)
                     62:        {
                     63:                printf("Scotty: That would consume %d%% of our remaining energy.\n",
                     64:                        percent);
                     65:                if (!getynpar("Are you sure that is wise"))
                     66:                        return;
                     67:        }
                     68: 
                     69:        /* compute the speed we will move at, and the time it will take */
                     70:        speed = Ship.warp2 / Param.warptime;
                     71:        time = dist / speed;
                     72: 
                     73:        /* check to see that that value is not ridiculous */
                     74:        percent = 100 * time / Now.time + 0.5;
                     75:        if (percent >= 85)
                     76:        {
                     77:                printf("Spock: That would take %d%% of our remaining time.\n",
                     78:                        percent);
                     79:                if (!getynpar("Are you sure that is wise"))
                     80:                        return;
                     81:        }
                     82: 
                     83:        /* compute how far we will go if we get damages */
                     84:        if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0))
                     85:        {
                     86:                frac = franf();
                     87:                dist *= frac;
                     88:                time *= frac;
                     89:                damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
                     90:        }
                     91: 
                     92:        /* do the move */
                     93:        Move.time = move(fl, course, time, speed);
                     94: 
                     95:        /* see how far we actually went, and decrement energy appropriately */
                     96:        dist = Move.time * speed;
                     97:        Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);
                     98: 
                     99:        /* test for bizarre events */
                    100:        if (Ship.warp <= 9.0)
                    101:                return;
                    102:        printf("\n\n  ___ Speed exceeding warp nine ___\n\n");
                    103:        sleep(2);
                    104:        printf("Ship's safety systems malfunction\n");
                    105:        sleep(2);
                    106:        printf("Crew experiencing extreme sensory distortion\n");
                    107:        sleep(4);
                    108:        if (ranf(100) >= 100 * dist)
                    109:        {
                    110:                return (printf("Equilibrium restored -- all systems normal\n"));
                    111:        }
                    112: 
                    113:        /* select a bizzare thing to happen to us */
                    114:        percent = ranf(100);
                    115:        if (percent < 70)
                    116:        {
                    117:                /* time warp */
                    118:                if (percent < 35 || !Game.snap)
                    119:                {
                    120:                        /* positive time warp */
                    121:                        time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
                    122:                        Now.date += time;
                    123:                        printf("Positive time portal entered -- it is now Stardate %.2f\n",
                    124:                                Now.date);
                    125:                        for (i = 0; i < MAXEVENTS; i++)
                    126:                        {
                    127:                                percent = Event[i].evcode;
                    128:                                if (percent == E_FIXDV || percent == E_LRTB)
                    129:                                        Event[i].date += time;
                    130:                        }
                    131:                        return;
                    132:                }
                    133: 
                    134:                /* s/he got lucky: a negative time portal */
                    135:                time = Now.date;
                    136:                i = (int) Etc.snapshot;
                    137:                bmove(i, Quad, sizeof Quad);
                    138:                bmove(i += sizeof Quad, Event, sizeof Event);
                    139:                bmove(i += sizeof Event, &Now, sizeof Now);
                    140:                printf("Negative time portal entered -- it is now Stardate %.2f\n",
                    141:                        Now.date);
                    142:                for (i = 0; i < MAXEVENTS; i++)
                    143:                        if (Event[i].evcode == E_FIXDV)
                    144:                                reschedule(&Event[i], Event[i].date - time);
                    145:                return;
                    146:        }
                    147: 
                    148:        /* test for just a lot of damage */
                    149:        if (percent < 80)
                    150:                lose(L_TOOFAST);
                    151:        printf("Equilibrium restored -- extreme damage occured to ship systems\n");
                    152:        for (i = 0; i < NDEV; i++)
                    153:                damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
                    154:        Ship.shldup = 0;
                    155: }

unix.superglobalmegacorp.com

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