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

unix.superglobalmegacorp.com

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