Annotation of 43BSDReno/games/trek/torped.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[] = "@(#)torped.c   5.4 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: # include      <stdio.h>
                     25: # include      "trek.h"
                     26: 
                     27: /*
                     28: **  PHOTON TORPEDO CONTROL
                     29: **
                     30: **     Either one or three photon torpedoes are fired.  If three
                     31: **     are fired, it is called a "burst" and you also specify
                     32: **     a spread angle.
                     33: **
                     34: **     Torpedoes are never 100% accurate.  There is always a random
                     35: **     cludge factor in their course which is increased if you have
                     36: **     your shields up.  Hence, you will find that they are more
                     37: **     accurate at close range.  However, they have the advantage that
                     38: **     at long range they don't lose any of their power as phasers
                     39: **     do, i.e., a hit is a hit is a hit, by any other name.
                     40: **
                     41: **     When the course spreads too much, you get a misfire, and the
                     42: **     course is randomized even more.  You also have the chance that
                     43: **     the misfire damages your torpedo tubes.
                     44: */
                     45: 
                     46: 
                     47: torped()
                     48: {
                     49:        register int            ix, iy;
                     50:        double                  x, y, dx, dy;
                     51:        double                  angle;
                     52:        int                     course, course2;
                     53:        register int            k;
                     54:        double                  bigger;
                     55:        double                  sectsize;
                     56:        int                     burst;
                     57:        int                     n;
                     58: 
                     59:        if (Ship.cloaked)
                     60:        {
                     61:                return (printf("Federation regulations do not permit attack while cloaked.\n"));
                     62:        }
                     63:        if (check_out(TORPED))
                     64:                return;
                     65:        if (Ship.torped <= 0)
                     66:        {
                     67:                return (printf("All photon torpedos expended\n"));
                     68:        }
                     69: 
                     70:        /* get the course */
                     71:        course = getintpar("Torpedo course");
                     72:        if (course < 0 || course > 360)
                     73:                return;
                     74:        burst = -1;
                     75: 
                     76:        /* need at least three torpedoes for a burst */
                     77:        if (Ship.torped < 3)
                     78:        {
                     79:                printf("No-burst mode selected\n");
                     80:                burst = 0;
                     81:        }
                     82:        else
                     83:        {
                     84:                /* see if the user wants one */
                     85:                if (!testnl())
                     86:                {
                     87:                        k = ungetc(cgetc(0), stdin);
                     88:                        if (k >= '0' && k <= '9')
                     89:                                burst = 1;
                     90:                }
                     91:        }
                     92:        if (burst < 0)
                     93:        {
                     94:                burst = getynpar("Do you want a burst");
                     95:        }
                     96:        if (burst)
                     97:        {
                     98:                burst = getintpar("burst angle");
                     99:                if (burst <= 0)
                    100:                        return;
                    101:                if (burst > 15)
                    102:                        return (printf("Maximum burst angle is 15 degrees\n"));
                    103:        }
                    104:        sectsize = NSECTS;
                    105:        n = -1;
                    106:        if (burst)
                    107:        {
                    108:                n = 1;
                    109:                course -= burst;
                    110:        }
                    111:        for (; n && n <= 3; n++)
                    112:        {
                    113:                /* select a nice random course */
                    114:                course2 = course + randcourse(n);
                    115:                angle = course2 * 0.0174532925;                 /* convert to radians */
                    116:                dx = -cos(angle);
                    117:                dy =  sin(angle);
                    118:                bigger = fabs(dx);
                    119:                x = fabs(dy);
                    120:                if (x > bigger)
                    121:                        bigger = x;
                    122:                dx /= bigger;
                    123:                dy /= bigger;
                    124:                x = Ship.sectx + 0.5;
                    125:                y = Ship.secty + 0.5;
                    126:                if (Ship.cond != DOCKED)
                    127:                        Ship.torped -= 1;
                    128:                printf("Torpedo track");
                    129:                if (n > 0)
                    130:                        printf(", torpedo number %d", n);
                    131:                printf(":\n%6.1f\t%4.1f\n", x, y);
                    132:                while (1)
                    133:                {
                    134:                        ix = x += dx;
                    135:                        iy = y += dy;
                    136:                        if (x < 0.0 || x >= sectsize || y < 0.0 || y >= sectsize)
                    137:                        {
                    138:                                printf("Torpedo missed\n");
                    139:                                break;
                    140:                        }
                    141:                        printf("%6.1f\t%4.1f\n", x, y);
                    142:                        switch (Sect[ix][iy])
                    143:                        {
                    144:                          case EMPTY:
                    145:                                continue;
                    146:        
                    147:                          case HOLE:
                    148:                                printf("Torpedo disappears into a black hole\n");
                    149:                                break;
                    150: 
                    151:                          case KLINGON:
                    152:                                for (k = 0; k < Etc.nkling; k++)
                    153:                                {
                    154:                                        if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy)
                    155:                                                continue;
                    156:                                        Etc.klingon[k].power -= 500 + ranf(501);
                    157:                                        if (Etc.klingon[k].power > 0)
                    158:                                        {
                    159:                                                printf("*** Hit on Klingon at %d,%d: extensive damages\n",
                    160:                                                        ix, iy);
                    161:                                                break;
                    162:                                        }
                    163:                                        killk(ix, iy);
                    164:                                        break;
                    165:                                }
                    166:                                break;
                    167:        
                    168:                          case STAR:
                    169:                                nova(ix, iy);
                    170:                                break;
                    171:        
                    172:                          case INHABIT:
                    173:                                kills(ix, iy, -1);
                    174:                                break;
                    175:        
                    176:                          case BASE:
                    177:                                killb(Ship.quadx, Ship.quady);
                    178:                                Game.killb += 1;
                    179:                                break;
                    180:                          default:
                    181:                                printf("Unknown object %c at %d,%d destroyed\n",
                    182:                                        Sect[ix][iy], ix, iy);
                    183:                                Sect[ix][iy] = EMPTY;
                    184:                                break;
                    185:                        }
                    186:                        break;
                    187:                }
                    188:                if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0)
                    189:                        break;
                    190:                course += burst;
                    191:        }
                    192:        Move.free = 0;
                    193: }
                    194: 
                    195: 
                    196: /*
                    197: **  RANDOMIZE COURSE
                    198: **
                    199: **     This routine randomizes the course for torpedo number 'n'.
                    200: **     Other things handled by this routine are misfires, damages
                    201: **     to the tubes, etc.
                    202: */
                    203: 
                    204: randcourse(n)
                    205: int    n;
                    206: {
                    207:        double                  r;
                    208:        register int            d;
                    209: 
                    210:        d = ((franf() + franf()) - 1.0) * 20;
                    211:        if (abs(d) > 12)
                    212:        {
                    213:                printf("Photon tubes misfire");
                    214:                if (n < 0)
                    215:                        printf("\n");
                    216:                else
                    217:                        printf(" on torpedo %d\n", n);
                    218:                if (ranf(2))
                    219:                {
                    220:                        damage(TORPED, 0.2 * abs(d) * (franf() + 1.0));
                    221:                }
                    222:                d *= 1.0 + 2.0 * franf();
                    223:        }
                    224:        if (Ship.shldup || Ship.cond == DOCKED)
                    225:        {
                    226:                r = Ship.shield;
                    227:                r = 1.0 + r / Param.shield;
                    228:                if (Ship.cond == DOCKED)
                    229:                        r = 2.0;
                    230:                d *= r;
                    231:        }
                    232:        return (d);
                    233: }

unix.superglobalmegacorp.com

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