|
|
1.1 ! root 1: # include "trek.h" ! 2: ! 3: /** ! 4: ** photon torpedo control ! 5: ** ! 6: **/ ! 7: ! 8: ! 9: torped() ! 10: { ! 11: register int ix, iy; ! 12: double x, y, dx, dy; ! 13: double angle; ! 14: int course, course2, delta; ! 15: int burst, spread; ! 16: int n; ! 17: ! 18: if (Status.cloaked) ! 19: { ! 20: printf("Federation regulations do not permit attack while cloaked.\n"); ! 21: return; ! 22: } ! 23: if (Damage[TORPED]) ! 24: { ! 25: printf("Photon tubes inoperable.\n"); ! 26: return; ! 27: } ! 28: if (Status.torped <= 0) ! 29: { ! 30: printf("All photon torpedos expended.\n"); ! 31: return; ! 32: } ! 33: if(getintpar("Torpedo course", &course)==0) return; ! 34: fixco(&course); ! 35: if(lineended() && Status.torped<3) { ! 36: burst=0; ! 37: printf("No burst mode selected.\n"); ! 38: } else { ! 39: if(!digit(peekchar())) { ! 40: if((burst=getynpar("Do you want a burst"))<0) return; ! 41: } else ! 42: burst=1; ! 43: if (burst) { ! 44: if(getintpar("Burst angle", &spread)==0) return; ! 45: if (spread < 0 || spread > 15) { ! 46: printf("Angle out of range.\n"); ! 47: return; ! 48: } ! 49: if(Status.torped<3) { ! 50: printf("Not enough left for a burst.\n"); ! 51: burst=spread=0; ! 52: } ! 53: else { ! 54: burst = 2; ! 55: course =- spread; ! 56: } ! 57: } ! 58: } ! 59: for (n=0; n<=burst; n++) { ! 60: delta = randcourse(); ! 61: course2 = course + delta; ! 62: angle = course2 * 0.0174532925; /* convert to radians */ ! 63: dx = -cos(angle); ! 64: dy = sin(angle); ! 65: x = fabs(dx); y = fabs(dy); ! 66: x = (x>y ? x : y); ! 67: dx =/ x; dy =/ x; ! 68: x = Sectx; ! 69: y = Secty; ! 70: if (Status.cond != DOCKED) ! 71: Status.torped =- 1; ! 72: if(burst) ! 73: printf("Torpedo %d: ", n); ! 74: printf("[%d] ", course2); ! 75: printf("track"); ! 76: while (1) ! 77: { ! 78: ix = (x =+ dx)+0.5; ! 79: iy = (y =+ dy)+0.5; ! 80: if (x <= -0.5 || ix >= NSECTS || y <= -0.5 || iy >= NSECTS) { ! 81: printf(" MISSED\n"); ! 82: break; ! 83: } ! 84: printf(" %d,%d", ix, iy); ! 85: switch (Sect[ix][iy]) ! 86: { ! 87: case EMPTY: ! 88: continue; ! 89: ! 90: case KLINGON: ! 91: printf("\n"); ! 92: hitkling(ix, iy, 500); ! 93: break; ! 94: ! 95: case STAR: ! 96: printf("\n"); ! 97: nova(ix, iy); ! 98: break; ! 99: ! 100: case INHABIT: ! 101: printf("\n"); ! 102: kills(ix, iy, -1); ! 103: break; ! 104: ! 105: case BASE: ! 106: printf("\n"); ! 107: killb(Quadx, Quady); Game.killb++; ! 108: break; ! 109: case BLACKHOLE: ! 110: printf(" ...\n"); ! 111: break; ! 112: } ! 113: break; ! 114: } ! 115: if (Damage[TORPED]) { ! 116: printf("Damages sustained"); ! 117: if (burst) ! 118: printf("; remainder of burst aborted"); ! 119: printf("\n"); ! 120: break; ! 121: } ! 122: course =+ spread; ! 123: } ! 124: Move.free = 0; ! 125: } ! 126: ! 127: ! 128: randcourse() ! 129: { ! 130: double r; ! 131: register int d; ! 132: ! 133: d = ((franf() + franf()) - 1.0) * 20; ! 134: if (abs(d) > 12) ! 135: { ! 136: printf("Photon tubes misfire.\n"); ! 137: if (!ranf(3)) ! 138: { ! 139: damage(TORPED, 0.2 * abs(d)); ! 140: } ! 141: d =* 1.0 + 2.0 * franf(); ! 142: } ! 143: if (Status.shldup || Status.cond == DOCKED) ! 144: { ! 145: r = Status.shield; ! 146: r = 1.0 + r / Initial.shield; ! 147: if (Status.cond == DOCKED) ! 148: r = 2.0; ! 149: d =* r; ! 150: } ! 151: return (d); ! 152: } ! 153: ! 154: hitkling(ix, iy, hit) ! 155: int ix, iy, hit; ! 156: { ! 157: register int k; ! 158: ! 159: for (k = 0; k < Nkling; k++) ! 160: { ! 161: if (Kling[k].x != ix || Kling[k].y != iy) ! 162: continue; ! 163: Kling[k].power =- hit + ranf(hit+1); ! 164: if (Kling[k].power > 0) ! 165: { ! 166: printf("*** Klingon hit at %d,%d: extensive damages.\n", ! 167: ix, iy); ! 168: } else ! 169: killk(ix, iy); ! 170: break; ! 171: } ! 172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.