Annotation of 43BSDReno/games/trek/attack.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[] = "@(#)attack.c   5.4 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: # include      "trek.h"
                     25: 
                     26: /*
                     27: **  Klingon Attack Routine
                     28: **
                     29: **     This routine performs the Klingon attack provided that
                     30: **     (1) Something happened this move (i.e., not free), and
                     31: **     (2) You are not cloaked.  Note that if you issue the
                     32: **     cloak command, you are not considered cloaked until you
                     33: **     expend some time.
                     34: **
                     35: **     Klingons are permitted to move both before and after the
                     36: **     attack.  They will tend to move toward you before the
                     37: **     attack and away from you after the attack.
                     38: **
                     39: **     Under certain conditions you can get a critical hit.  This
                     40: **     sort of hit damages devices.  The probability that a given
                     41: **     device is damaged depends on the device.  Well protected
                     42: **     devices (such as the computer, which is in the core of the
                     43: **     ship and has considerable redundancy) almost never get
                     44: **     damaged, whereas devices which are exposed (such as the
                     45: **     warp engines) or which are particularly delicate (such as
                     46: **     the transporter) have a much higher probability of being
                     47: **     damaged.
                     48: **
                     49: **     The actual amount of damage (i.e., how long it takes to fix
                     50: **     it) depends on the amount of the hit and the "damfac[]"
                     51: **     entry for the particular device.
                     52: **
                     53: **     Casualties can also occur.
                     54: */
                     55: 
                     56: attack(resting)
                     57: int    resting;        /* set if attack while resting */
                     58: {
                     59:        register int            hit, i, l;
                     60:        int                     maxhit, tothit, shldabsb;
                     61:        double                  chgfac, propor, extradm;
                     62:        double                  dustfac, tothe;
                     63:        int                     cas;
                     64:        int                     hitflag;
                     65: 
                     66:        if (Move.free)
                     67:                return;
                     68:        if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
                     69:                return;
                     70:        if (Ship.cloaked && Ship.cloakgood)
                     71:                return;
                     72:        /* move before attack */
                     73:        klmove(0);
                     74:        if (Ship.cond == DOCKED)
                     75:        {
                     76:                if (!resting)
                     77:                        printf("Starbase shields protect the %s\n", Ship.shipname);
                     78:                return;
                     79:        }
                     80:        /* setup shield effectiveness */
                     81:        chgfac = 1.0;
                     82:        if (Move.shldchg)
                     83:                chgfac = 0.25 + 0.50 * franf();
                     84:        maxhit = tothit = 0;
                     85:        hitflag = 0;
                     86: 
                     87:        /* let each Klingon do his damndest */
                     88:        for (i = 0; i < Etc.nkling; i++)
                     89:        {
                     90:                /* if he's low on power he won't attack */
                     91:                if (Etc.klingon[i].power < 20)
                     92:                        continue;
                     93:                if (!hitflag)
                     94:                {
                     95:                        printf("\nStardate %.2f: Klingon attack:\n",
                     96:                                Now.date);
                     97:                        hitflag++;
                     98:                }
                     99:                /* complete the hit */
                    100:                dustfac = 0.90 + 0.01 * franf();
                    101:                tothe = Etc.klingon[i].avgdist;
                    102:                hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
                    103:                /* deplete his energy */
                    104:                dustfac = Etc.klingon[i].power;
                    105:                Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
                    106:                /* see how much of hit shields will absorb */
                    107:                shldabsb = 0;
                    108:                if (Ship.shldup || Move.shldchg)
                    109:                {
                    110:                        propor = Ship.shield;
                    111:                        propor /= Param.shield;
                    112:                        shldabsb = propor * chgfac * hit;
                    113:                        if (shldabsb > Ship.shield)
                    114:                                shldabsb = Ship.shield;
                    115:                        Ship.shield -= shldabsb;
                    116:                }
                    117:                /* actually do the hit */
                    118:                printf("HIT: %d units", hit);
                    119:                if (!damaged(SRSCAN))
                    120:                        printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
                    121:                cas = (shldabsb * 100) / hit;
                    122:                hit -= shldabsb;
                    123:                if (shldabsb > 0)
                    124:                        printf(", shields absorb %d%%, effective hit %d\n",
                    125:                                cas, hit);
                    126:                else
                    127:                        printf("\n");
                    128:                tothit += hit;
                    129:                if (hit > maxhit)
                    130:                        maxhit = hit;
                    131:                Ship.energy -= hit;
                    132:                /* see if damages occurred */
                    133:                if (hit >= (15 - Game.skill) * (25 - ranf(12)))
                    134:                {
                    135:                        printf("CRITICAL HIT!!!\n");
                    136:                        /* select a device from probability vector */
                    137:                        cas = ranf(1000);
                    138:                        for (l = 0; cas >= 0; l++)
                    139:                                cas -= Param.damprob[l];
                    140:                        l -= 1;
                    141:                        /* compute amount of damage */
                    142:                        extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5;
                    143:                        /* damage the device */
                    144:                        damage(l, extradm);
                    145:                        if (damaged(SHIELD))
                    146:                        {
                    147:                                if (Ship.shldup)
                    148:                                        printf("Sulu: Shields knocked down, captain.\n");
                    149:                                Ship.shldup = 0;
                    150:                                Move.shldchg = 0;
                    151:                        }
                    152:                }
                    153:                if (Ship.energy <= 0)
                    154:                        lose(L_DSTRYD);
                    155:        }
                    156: 
                    157:        /* see what our casualities are like */
                    158:        if (maxhit >= 200 || tothit >= 500)
                    159:        {
                    160:                cas = tothit * 0.015 * franf();
                    161:                if (cas >= 2)
                    162:                {
                    163:                        printf("McCoy: we suffered %d casualties in that attack.\n",
                    164:                                cas);
                    165:                        Game.deaths += cas;
                    166:                        Ship.crew -= cas;
                    167:                }
                    168:        }
                    169: 
                    170:        /* allow Klingons to move after attacking */
                    171:        klmove(1);
                    172: 
                    173:        return;
                    174: }

unix.superglobalmegacorp.com

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