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