int ja(void) { chew(); while (TRUE) { scan(); chew(); if (*citem == 'y') return TRUE; if (*citem == 'n') return FALSE; proutn("Please answer with \"Y\" or \"N\":"); } }
int scan(void) { int i; char *cp; linecount = 0; // Init result aaitem = 0.0; *citem = 0; // Read a line if nothing here if (*linep == 0) { if (linep != line) { chew(); return IHEOL; } // gets(line); // We should really be using fgets fgets(line,sizeof(line),stdin); if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; linep = line; } // Skip leading white space while (*linep == ' ') linep++; // Nothing left if (*linep == 0) { chew(); return IHEOL; } if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') { // treat as a number if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) { linep = line; // Invalid numbers are ignored *linep = 0; return IHEOL; } else { // skip to end linep += i; return IHREAL; } } // Treat as alpha cp = citem; while (*linep && *linep!=' ') { if ((cp - citem) < 9) *cp++ = tolower(*linep); linep++; } *cp = 0; return IHALPHA; }
void lrscan(void) { int x, y; chew(); if (damage[DLRSENS] != 0.0) { /* Now allow base's sensors if docked */ if (condit != IHDOCKED) { prout("LONG-RANGE SENSORS DAMAGED."); return; } skip(1); proutn("Starbase's long-range scan for"); } else { skip(1); proutn("Long-range scan for"); } cramlc(1, quadx, quady); skip(1); for (x = quadx-1; x <= quadx+1; x++) { for (y = quady-1; y <= quady+1; y++) { if (x == 0 || x > 8 || y == 0 || y > 8) printf(" -1"); else { printf("%5d", d.galaxy[x][y]); starch[x][y] = damage[DRADIO] > 0 ? d.galaxy[x][y]+1000 :1; } } putchar('\n'); } }
void waiting(void) { int key; double temp, delay, origTime; ididit = 0; for (;;) { key = scan(); if (key != IHEOL) break; proutn("How long? "); } chew(); if (key != IHREAL) { huh(); return; } origTime = delay = aaitem; if (delay <= 0.0) return; if (delay >= d.remtime || nenhere != 0) { prout("Are you sure? "); if (ja() == 0) return; } /* Alternate resting periods (events) with attacks */ resting = 1; do { if (delay <= 0) resting = 0; if (resting == 0) { cramf(d.remtime, 0, 2); prout(" stardates left."); return; } temp = Time = delay; if (nenhere) { double rtime = 1.0 + Rand(); if (rtime < temp) temp = rtime; Time = temp; } if (Time < delay) attack(0); if (nenhere==0) movetho(); if (alldone) return; events(); ididit = 1; if (alldone) return; delay -= temp; /* Repair Deathray if long rest at starbase */ if (origTime-delay >= 9.99 && condit == IHDOCKED) damage[DDRAY] = 0.0; } while (d.galaxy[quadx][quady] != 1000); // leave if quadrant supernovas resting = 0; Time = 0; }
void chart(int nn) { int i,j; chew(); skip(1); if (stdamtim != 1e30 && stdamtim != d.date && condit == IHDOCKED) { prout("Spock- \"I revised the Star Chart from the"); prout(" starbase's records.\""); skip(1); } if (nn == 0) prout("STAR CHART FOR THE KNOWN GALAXY"); if (stdamtim != 1e30) { if (condit == IHDOCKED) { /* We are docked, so restore chart from base information */ stdamtim = d.date; for (i=1; i <= 8 ; i++) for (j=1; j <= 8; j++) if (starch[i][j] == 1) starch[i][j] = d.galaxy[i][j]+1000; } else { proutn("(Last surveillance update "); cramf(d.date-stdamtim, 0, 1); prout(" stardates ago.)"); } } if (nn ==0) skip(1); prout(" 1 2 3 4 5 6 7 8"); prout(" ----------------------------------------"); if (nn==0) prout(" -"); for (i = 1; i <= 8; i++) { printf("%d -", i); for (j = 1; j <= 8; j++) { if (starch[i][j] < 0) printf(" .1."); else if (starch[i][j] == 0) printf(" ..."); else if (starch[i][j] > 999) printf("%5d", starch[i][j]-1000); else printf("%5d", d.galaxy[i][j]); } prout(" -"); } if (nn == 0) { skip(1); crmshp(); proutn(" is currently in"); cramlc(1, quadx, quady); skip(1); } }
/** parse is like scan except it does not retrieve a new * line of input when the current line reaches EOL. * Instead, it just returns IHEOL. * * Precondition: line contains input(s) to be parsed and linep * points to the current position within the input in line to * parse the next input separated by space. * Postconditions: linep points to position within line after * the parsed input. If EOL is encountered during parsing, line * is reset to '\0' and linep is reset to point to the start of * line. If the parsed input is a character string, the input * (limited to 9 chars) is copied to the global variable citem. If * the parsed input is numeric, the input is copied to the global * variable aaitem. The global variable linecount is set to zero. * The function returns IHEOL if EOL is encountered during parsing, * IHREAL if the parsed input is numeric, and IHALPHA if the * parsed input is a character string. * Exception: If the next input is detected to be numeric, but an * error occured in parsing the input, line is reset to '\0', linep * is reset to point to the start of line, and IHEOL is returned. * * Usage: parse is used by Command execution functions to parse * the input command with parameters separated by spaces. The * parsing logic should parallel the current logic in handling * interactive input except that no further prompting for * parameters is necessary since all parameters are assumed to * be contained in the global variable line for this Command. * In addition, no error handling is necessary since the global * variable line is assumed to contain the complete command, and * all error handling is assumed to have occurred in assembling * this Command interactively in the get<Command>Params() * function for the command. */ int parse(void) { int i; char *cp; linecount = 0; // Init result aaitem = 0.0; *citem = 0; // Skip leading white space while (*linep == ' ') linep++; // Nothing left if (*linep == 0) { // This occurs if newly gotten line has nothing but spaces or // when last read line has only spaces left. In either case, // call chew to reset line and linep and return EOL flag. chew(); return IHEOL; } // This point is reach iff there is a string or number in the // currently read line to be parsed. if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') { // treat as a number if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) { // if sscanf does not convert a double, reset line and linep // (i.e., equivalent to calling chew()) and return EOL. linep = line; // Invalid numbers are ignored *linep = 0; return IHEOL; } else { // i returns the number of characters converted to a double! // skip to end of converted characters in line and return REAL flag linep += i; return IHREAL; } } // Treat as alpha cp = citem; while (*linep && *linep!=' ') { // copy characters (convert to lower case) from line to citem // length of string is limited to 9 characters if ((cp - citem) < 9) *cp++ = tolower(*linep); linep++; } // terminate with '\0' and return STRING flag *cp = 0; return IHALPHA; }
void dreprt(void) { int jdam = FALSE, i; chew(); for (i = 1; i <= ndevice; i++) { if (damage[i] > 0.0) { if (!jdam) { skip(1); prout("DEVICE -REPAIR TIMES-"); prout(" IN FLIGHT DOCKED"); jdam = TRUE; } printf(" %16s ", device[i]); cramf(damage[i]+0.05, 8, 2); proutn(" "); cramf(docfac*damage[i]+0.005, 8, 2); skip(1); } } if (!jdam) prout("All devices functional."); }
void debugme(void) { proutn("Reset levels? "); if (ja() != 0) { if (energy < inenrg) energy = inenrg; shield = inshld; torps = intorps; lsupres = inlsr; } proutn("Reset damage? "); if (ja() != 0) { int i; for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0; stdamtim = 1e30; } proutn("Toggle idebug? "); if (ja() != 0) { idebug = !idebug; if (idebug) prout("Debug output ON"); else prout("Debug output OFF"); } proutn("Cause selective damage? "); if (ja() != 0) { int i, key; for (i=1; i <= ndevice; i++) { proutn("Kill "); proutn(device[i]); proutn("? "); chew(); key = scan(); if (key == IHALPHA && isit("y")) { damage[i] = 10.0; if (i == DRADIO) stdamtim = d.date; } } } proutn("Examine/change events? "); if (ja() != 0) { int i; for (i = 1; i < NEVENTS; i++) { int key; if (future[i] == 1e30) continue; switch (i) { case FSNOVA: proutn("Supernova "); break; case FTBEAM: proutn("T Beam "); break; case FSNAP: proutn("Snapshot "); break; case FBATTAK: proutn("Base Attack "); break; case FCDBAS: proutn("Base Destroy "); break; case FSCMOVE: proutn("SC Move "); break; case FSCDBAS: proutn("SC Base Destroy "); break; } cramf(future[i]-d.date, 8, 2); chew(); proutn(" ?"); key = scan(); if (key == IHREAL) { future[i] = d.date + aaitem; } } chew(); } proutn("Make universe visible? "); if (ja() != 0) { int i, j; for (i = 1; i < 9; i++) { for (j = 1; j < 9; j++) { starch[i][j] = 1; } } } }
void huh(void) { chew(); skip(1); prout("Beg your pardon, Captain?"); }
static void makemoves(void) { int i, hitme; char ch; while (TRUE) { /* command loop */ hitme = FALSE; justin = 0; Time = 0.0; i = -1; while (TRUE) { /* get a command */ chew(); skip(1); proutn("COMMAND> "); if (scan() == IHEOL) continue; for (i=0; i < 29; i++) // Abbreviations allowed for the first 29 commands, only. if (isit(commands[i])) break; if (i < 29) break; for (; i < NUMCOMMANDS; i++) if (strcmp(commands[i], citem) == 0) break; if (i < NUMCOMMANDS #ifndef CLOAKING && i != 26 // ignore the CLOAK command #endif #ifndef CAPTURE && i != 27 // ignore the CAPTURE command #endif #ifndef SCORE && i != 28 // ignore the SCORE command #endif #ifndef DEBUG && i != 33 // ignore the DEBUG command #endif ) break; if (skill <= SFAIR) { prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:"); listCommands(TRUE); } else prout("UNRECOGNIZED COMMAND."); } switch (i) { /* command switch */ case 0: // srscan srscan(1); break; case 1: // lrscan lrscan(); break; case 2: // phasers phasers(); if (ididit) { #ifdef CLOAKING if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) { prout("The Romulan ship discovers you are breaking the Treaty of Algeron!"); ncviol++; isviolreported = TRUE; } #endif hitme = TRUE; } break; case 3: // photons photon(); if (ididit) { #ifdef CLOAKING if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) { prout("The Romulan ship discovers you are breaking the Treaty of Algeron!"); ncviol++; isviolreported = TRUE; } #endif hitme = TRUE; } break; case 4: // move warp(1); break; case 5: // shields sheild(1); if (ididit) { attack(2); shldchg = 0; } break; case 6: // dock dock(); break; case 7: // damages dreprt(); break; case 8: // chart chart(0); break; case 9: // impulse impuls(); break; case 10: // rest waiting(); if (ididit) hitme = TRUE; break; case 11: // warp setwrp(); break; case 12: // status srscan(3); break; case 13: // sensors sensor(); break; case 14: // orbit orbit(); if (ididit) hitme = TRUE; break; case 15: // transport "beam" beam(); break; case 16: // mine mine(); if (ididit) hitme = TRUE; break; case 17: // crystals usecrystals(); break; case 18: // shuttle shuttle(); if (ididit) hitme = TRUE; break; case 19: // Planet list preport(); break; case 20: // Status information srscan(2); break; case 21: // Game Report report(0); break; case 22: // use COMPUTER! eta(); break; case 23: listCommands(TRUE); break; case 24: // Emergency exit clearscreen(); // Hide screen freeze(TRUE); // forced save exit(1); // And quick exit break; case 25: probe(); // Launch probe break; #ifdef CLOAKING case 26: cloak(); // turn on/off cloaking if (iscloaking) { attack(2); // We will be seen while we cloak iscloaking = FALSE; iscloaked = TRUE; } break; #endif #ifdef CAPTURE case 27: capture(); // Attempt to get Klingon ship to surrender if (ididit) hitme = TRUE; break; #endif #ifdef SCORE case 28: score(1); // get the score break; #endif case 29: // Abandon Ship abandn(); break; case 30: // Self Destruct dstrct(); break; case 31: // Save Game freeze(FALSE); if (skill > SGOOD) prout("WARNING--Frozen games produce no plaques!"); break; case 32: // Try a desparation measure deathray(); if (ididit) hitme = TRUE; break; #ifdef DEBUG case 33: // What do we want for debug??? debugme(); break; #endif case 34: // Call for help help(); break; case 35: alldone = 1; // quit the game #ifdef DEBUG if (idebug) score(0); #endif break; case 36: helpme(); // get help break; } for (;;) { if (alldone) break; // Game has ended #ifdef DEBUG if (idebug) prout("2500"); #endif if (Time != 0.0) { events(); if (alldone) break; // Events did us in } if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! atover(0); continue; } if (nenhere == 0) movetho(); if (hitme && justin==0) { attack(2); if (alldone) break; if (d.galaxy[quadx][quady] == 1000) { // went NOVA! atover(0); hitme = TRUE; continue; } } break; } if (alldone) break; } }
static void helpme(void) { int i, j; char cmdbuf[32]; char linebuf[132]; FILE *fp; /* Give help on commands */ int key; key = scan(); while (TRUE) { if (key == IHEOL) { proutn("Help on what command?"); key = scan(); } if (key == IHEOL) return; for (i = 0; i < NUMCOMMANDS; i++) { if (strcmp(commands[i], citem)==0) break; } if (i != NUMCOMMANDS) break; skip(1); prout("Valid commands:"); listCommands(FALSE); key = IHEOL; chew(); skip(1); } if (i == 23) { strcpy(cmdbuf, " ABBREV"); } else { strcpy(cmdbuf, " Mnemonic: "); j = 0; while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++; } fp = fopen("sst.doc", "r"); if (fp == NULL) { prout("Spock- \"Captain, that information is missing from the"); prout(" computer. You need to find SST.DOC and put it in the"); prout(" current directory.\""); return; } i = strlen(cmdbuf); do { if (fgets(linebuf, 132, fp) == NULL) { prout("Spock- \"Captain, there is no information on that command.\""); fclose(fp); return; } } while (strncmp(linebuf, cmdbuf, i) != 0); skip(1); prout("Spock- \"Captain, I've found the following information:\""); skip(1); do { if (linebuf[0]!=12) { // ignore page break lines linebuf[strlen(linebuf)-1] = '\0'; // No \n at end prout(linebuf); } fgets(linebuf,132,fp); } while (strstr(linebuf, "******")==NULL); fclose(fp); }
int main(int argc, char ** argv) { FILE * fh = stdin; char buf[1024], * p; int i, k, l, b, n, jmax; int (* input)(FILE * fh); struct bf_op * x; /* main loop variables - keep 'em in registers */ register struct bf_op * z; register int j, v_off; register int * v; if ( (argc > 1 && argv[1][0] == '-') || (argc > 2 && argv[2][0] == '-') || (argc > 3) ) usage(); /* open and read the program file */ if (argc > 1 && ! (fh = fopen(argv[1], "r"))) die("cannot open program file (%s)\n", argv[1]); n = 0; p = 0; while (! feof(fh)) { b = fread(buf, 1, sizeof buf, fh); p = xalloc(p, (n += b) + 1); memcpy(p + n - b, buf, b); } fclose(fh); /* open data file */ if (argc > 2) { if (! (fh = fopen(argv[2], "r"))) die("cannot open input data file (%s)\n", argv[2]); input = getc_ext; } else { fh = stdin; input = getc; } /* strip the comments */ for (i=j=0; i<n; i++) if (strchr("[]<>+-,.", p[i])) p[j++] = p[i]; n = j++; p[n] = 0; /* 'end of program' */ /* skip leading < > */ for (i=0; i<n; i++) if (! strchr("<>", p[i])) break; n -= i; memmove(p, p+i, n); /* preprocess */ x = xalloc(NULL, (n+1) * sizeof(*x)); for (i=0; i<n; i++) { switch (p[i]) { case '[': for (j=i+1,l=1; j<n; j++) if (p[j] == '[') l++; /* recurse */ else if (p[j] == ']') if (! --l) break; if (l) die("no matching ]\n"); x[i].op = 'c'; x[i].p_ofx = chew(p, j+1, &x[i].v_ofx) - i; x[i].p_off = chew(p, i+1, &x[i].v_off) - i; /* [-] and [+] */ if (j == i+2 && (p[i+1] == '-' || p[i+1] == '+')) { x[i].op = 'z'; x[i].p_off = x[i].p_ofx; x[i].v_off = x[i].v_ofx; } i += x[i].p_off - 1; break; case ']': for (j=i-1,l=1; 0<=j; j--) if (p[j] == ']') l++; else if (p[j] == '[') if (! --l) break; if (j < 0) die("no matching [\n"); x[i].op = 'c'; x[i].p_off = chew(p, j+1, &x[i].v_off) - i; x[i].p_ofx = chew(p, i+1, &x[i].v_ofx) - i; i += x[i].p_ofx - 1; break; case '+': case '-': case '.': case ',': x[i].op = p[i]; for (j=i; j<n && p[j]==x[i].op; j++); x[i].op_arg = j-i; x[i].p_off = chew(p, j, &x[i].v_off) - i; i += x[i].p_off - 1; break; case '<': case '>': /* chew() folds these into all other ops */ default: assert(0); break; } } /* exit */ x[i].op = 'x'; /* allocate cell array - start with the moderate size */ jmax = 256; v = xalloc(NULL, jmax * sizeof(int)); /* get busy */ j = jmax / 2; z = x; v_off = 0; for (;;) { if (v_off) { j += v_off; if (j < 0 || jmax <= j) { int _j = j, _m = jmax; v = grow(v, &_j, &_m); j = _j; jmax = _m; } } v_off = z->v_off; switch (z->op) { case '+': v[j] += z->op_arg; break; case '-': v[j] -= z->op_arg; break; case 'c': if (! v[j]) { v_off = z->v_ofx; z += z->p_ofx; continue; } break; case '.': for (k=0; k<z->op_arg; k++) /* printf("%02x", v[j]); */ putchar(v[j]); break; case ',': for (k=0; k<z->op_arg; k++) v[j] = input(fh); break; case 'z': v[j] = 0; break; case 'x': goto _break; default: assert(0); } z += z->p_off; } _break: return 0; }
static void makemoves(void) { int i, hitme; char ch; while (TRUE) { /* command loop */ hitme = FALSE; justin = 0; Time = 0.0; i = -1; while (TRUE) { /* get a command */ chew(); skip(1); proutn("COMMAND> "); // Use of scan() here (after chew) will get a new line of input // and will return IHEOL iff new line of input contains nothing // or a numeric input is detected but conversion fails. if (scan() == IHEOL) continue; for (i=0; i < 26; i++) if (isit(commands[i])) break; if (i < 26) break; for (; i < NUMCOMMANDS; i++) if (strcmp(commands[i], citem) == 0) break; if (i < NUMCOMMANDS) break; // we get here iff the first parsed input from the line does not // match one of the commands. In this case, the rest of the line // is discarded, the below message is printed, and we go back to // get a new command. if (skill <= 2) { prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:"); listCommands(TRUE); } else prout("UNRECOGNIZED COMMAND."); } // end get command loop // we get here iff the first parsed input from the line matches one // of the commands (i.e., command i). We use i to dispatch the // handling of the command. The line may still contain additional // inputs (i.e., parameters of the command) that is to be parsed by // the dispatched command handler. If the line does not contain // all the necessary parameters, the dispatched command handler is // responsible to get additional input(s) interactively using scan(). // The dispatched command handler is also responsible to handle any // input errors. switch (i) { /* command switch */ case 0: // srscan srscan(1); break; case 1: // lrscan lrscan(); break; case 2: // phasers phasers(); if (ididit) hitme = TRUE; break; case 3: // photons photon(); if (ididit) hitme = TRUE; break; case 4: // move warp(1); break; case 5: // shields sheild(1); if (ididit) { attack(2); shldchg = 0; } break; case 6: // dock dock(); break; case 7: // damages dreprt(); break; case 8: // chart chart(0); break; case 9: // impulse impuls(); break; case 10: // rest waiting(); if (ididit) hitme = TRUE; break; case 11: // warp setwrp(); break; case 12: // status srscan(3); break; case 13: // sensors sensor(); break; case 14: // orbit orbit(); if (ididit) hitme = TRUE; break; case 15: // transport "beam" beam(); break; case 16: // mine mine(); if (ididit) hitme = TRUE; break; case 17: // crystals usecrystals(); break; case 18: // shuttle shuttle(); if (ididit) hitme = TRUE; break; case 19: // Planet list preport(); break; case 20: // Status information srscan(2); break; case 21: // Game Report report(0); break; case 22: // use COMPUTER! eta(); break; case 23: listCommands(TRUE); break; case 24: // Emergency exit clearscreen(); // Hide screen freeze(TRUE); // forced save exit(1); // And quick exit break; case 25: probe(); // Launch probe break; case 26: // Abandon Ship abandn(); break; case 27: // Self Destruct dstrct(); break; case 28: // Save Game freeze(FALSE); if (skill > 3) prout("WARNING--Frozen games produce no plaques!"); break; case 29: // Try a desparation measure deathray(); if (ididit) hitme = TRUE; break; case 30: // What do we want for debug??? #ifdef DEBUG debugme(); #endif break; case 31: // Call for help help(); break; case 32: alldone = 1; // quit the game #ifdef DEBUG if (idebug) score(); #endif break; case 33: helpme(); // get help break; } // end command switch for (;;) { if (alldone) break; // Game has ended #ifdef DEBUG if (idebug) prout("2500"); #endif if (Time != 0.0) { events(); if (alldone) break; // Events did us in } if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! atover(0); continue; } if (nenhere == 0) movetho(); if (hitme && justin==0) { attack(2); if (alldone) break; if (d.galaxy[quadx][quady] == 1000) { // went NOVA! atover(0); hitme = TRUE; continue; } } break; } // end event loop if (alldone) break; } // end command loop }
void eta(void) { int key, ix1, ix2, iy1, iy2, prompt=FALSE; int wfl; double ttime, twarp, tpower; if (damage[DCOMPTR] != 0.0) { prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR."); skip(1); return; } if (scan() != IHREAL) { prompt = TRUE; chew(); proutn("Destination quadrant and/or sector? "); if (scan()!=IHREAL) { huh(); return; } } iy1 = aaitem +0.5; if (scan() != IHREAL) { huh(); return; } ix1 = aaitem + 0.5; if (scan() == IHREAL) { iy2 = aaitem + 0.5; if (scan() != IHREAL) { huh(); return; } ix2 = aaitem + 0.5; } else { // same quadrant ix2 = ix1; iy2 = iy1; ix1 = quady; // ya got me why x and y are reversed! iy1 = quadx; } if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 || ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) { huh(); return; } dist = sqrt(square(iy1-quadx+0.1*(iy2-sectx))+ square(ix1-quady+0.1*(ix2-secty))); wfl = FALSE; if (prompt) prout("Answer \"no\" if you don't know the value:"); while (TRUE) { chew(); proutn("Time or arrival date? "); if (scan()==IHREAL) { ttime = aaitem; if (ttime > d.date) ttime -= d.date; // Actually a star date if (ttime <= 1e-10 || (twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) { prout("We'll never make it, sir."); chew(); return; } if (twarp < 1.0) twarp = 1.0; break; } chew(); proutn("Warp factor? "); if (scan()== IHREAL) { wfl = TRUE; twarp = aaitem; if (twarp<1.0 || twarp > 10.0) { huh(); return; } break; } prout("Captain, certainly you can give me one of these."); } while (TRUE) { chew(); ttime = (10.0*dist)/square(twarp); tpower = dist*twarp*twarp*twarp*(shldup+1); if (tpower >= energy) { prout("Insufficient energy, sir."); if (shldup==0 || tpower > energy*2.0) { if (!wfl) return; proutn("New warp factor to try? "); if (scan() == IHREAL) { wfl = TRUE; twarp = aaitem; if (twarp<1.0 || twarp > 10.0) { huh(); return; } continue; } else { chew(); skip(1); return; } } prout("But if you lower your shields,"); proutn("remaining"); tpower /= 2; } else proutn("Remaining"); proutn(" energy will be "); cramf(energy-tpower, 1, 1); prout("."); if (wfl) { proutn("And we will arrive at stardate "); cramf(d.date+ttime, 1, 1); prout("."); } else if (twarp==1.0) prout("Any warp speed is adequate."); else { proutn("Minimum warp needed is "); cramf(twarp, 1, 2); skip(1); proutn("and we will arrive at stardate "); cramf(d.date+ttime, 1, 2); prout("."); } if (d.remtime < ttime) prout("Unfortunately, the Federation will be destroyed by then."); if (twarp > 6.0) prout("You'll be taking risks at that speed, Captain"); if ((isatb==1 && d.isy == ix1 && d.isx == iy1 && future[FSCDBAS]< ttime+d.date)|| (future[FCDBAS]<ttime+d.date && baty==ix1 && batx == iy1)) prout("The starbase there will be destroyed by then."); proutn("New warp factor to try? "); if (scan() == IHREAL) { wfl = TRUE; twarp = aaitem; if (twarp<1.0 || twarp > 10.0) { huh(); return; } } else { chew(); skip(1); return; } } }
void report(int f) { char *s1,*s2,*s3; chew(); s1 = (thawed?"thawed ":""); switch (length) { case 1: s2="short"; break; case 2: s2="medium"; break; case 4: s2="long"; break; default: s2="unknown length"; break; } switch (skill) { case 1: s3="novice"; break; case 2: s3="fair"; break; case 3: s3="good"; break; case 4: s3="expert"; break; case 5: s3="emeritus"; break; default: s3="skilled"; break; } printf("\nYou %s playing a %s%s %s game.\n", alldone? "were": "are now", s1, s2, s3); if (skill>3 && thawed && !alldone) prout("No plaque is allowed."); if (tourn) printf("This is tournament game %d.\n", tourn); if (f) printf("Your secret password is \"%s\"\n",passwd); printf("%d of %d Klingons have been killed", d.killk+d.killc+d.nsckill, inkling); if (d.killc) printf(", including %d Commander%s.\n", d.killc, d.killc==1?"":"s"); else if (d.killk+d.nsckill > 0) prout(", but no Commanders."); else prout("."); if (skill > 2) printf("The Super Commander has %sbeen destroyed.\n", d.nscrem?"not ":""); if (d.rembase != inbase) { proutn("There "); if (inbase-d.rembase==1) proutn("has been 1 base"); else { proutn("have been "); crami(inbase-d.rembase, 1); proutn(" bases"); } proutn(" destroyed, "); crami(d.rembase, 1); prout(" remaining."); } else printf("There are %d bases.\n", inbase); if (damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) { /* Don't report this if not seen and either the radio is dead or not at base! */ attakreport(); iseenit = 1; } if (casual) printf("%d casualt%s suffered so far.\n", casual, casual==1? "y" : "ies"); if (nhelp) printf("There were %d call%s for help.\n", nhelp, nhelp==1 ? "" : "s"); if (ship == IHE) { proutn("You have "); if (nprobes) crami(nprobes,1); else proutn("no"); proutn(" deep space probe"); if (nprobes!=1) proutn("s"); prout("."); } if ((damage[DRADIO] == 0.0 || condit == IHDOCKED)&& future[FDSPROB] != 1e30) { if (isarmed) proutn("An armed deep space probe is in"); else proutn("A deep space probe is in"); cramlc(1, probecx, probecy); prout("."); } if (icrystl) { if (cryprob <= .05) prout("Dilithium crystals aboard ship...not yet used."); else { int i=0; double ai = 0.05; while (cryprob > ai) { ai *= 2.0; i++; } printf("Dilithium crystals have been used %d time%s.\n", i, i==1? "" : "s"); } } skip(1); }
void srscan(int l) { static char requests[][3] = {"","da","co","po","ls","wa","en","to","sh","kl","ti"}; char *cp; int leftside=TRUE, rightside=TRUE, i, j, jj, k=0, nn=FALSE; int goodScan=TRUE; switch (l) { case 1: // SRSCAN if (damage[DSRSENS] != 0) { /* Allow base's sensors if docked */ if (condit != IHDOCKED) { prout("SHORT-RANGE SENSORS DAMAGED"); goodScan=FALSE; } else prout("[Using starbase's sensors]"); } if (goodScan) starch[quadx][quady] = damage[DRADIO]>0.0 ? d.galaxy[quadx][quady]+1000:1; scan(); if (isit("chart")) nn = TRUE; if (isit("no")) rightside = FALSE; chew(); prout("\n 1 2 3 4 5 6 7 8 9 10"); break; case 2: // REQUEST while (scan() == IHEOL) printf("Information desired? "); chew(); for (k = 1; k <= 10; k++) if (strncmp(citem,requests[k],min(2,strlen(citem)))==0) break; if (k > 10) { prout("UNRECOGNIZED REQUEST. Legal requests are:\n" " date, condition, position, lsupport, warpfactor,\n" " energy, torpedoes, shields, klingons, time."); return; } // no "break" case 3: // STATUS chew(); leftside = FALSE; skip(1); } for (i = 1; i <= 10; i++) { int jj = (k!=0 ? k : i); if (leftside) { printf("%2d ", i); for (j = 1; j <= 10; j++) { if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)) printf("%c ",quad[i][j]); else printf("- "); } } if (rightside) { switch (jj) { case 1: printf(" Stardate %.1f", d.date); break; case 2: if (condit != IHDOCKED) newcnd(); switch (condit) { case IHRED: cp = "RED"; break; case IHGREEN: cp = "GREEN"; break; case IHYELLOW: cp = "YELLOW"; break; case IHDOCKED: cp = "DOCKED"; break; } printf(" Condition %s", cp); break; case 3: printf(" Position "); cramlc(0, quadx, quady); putchar(','); cramlc(0, sectx, secty); break; case 4: printf(" Life Support "); if (damage[DLIFSUP] != 0.0) { if (condit == IHDOCKED) printf("DAMAGED, supported by starbase"); else printf("DAMAGED, reserves=%4.2f", lsupres); } else printf("ACTIVE"); break; case 5: printf(" Warp Factor %.1f", warpfac); break; case 6: printf(" Energy %.2f", energy); break; case 7: printf(" Torpedoes %d", torps); break; case 8: printf(" Shields "); if (damage[DSHIELD] != 0) printf("DAMAGED,"); else if (shldup) printf("UP,"); else printf("DOWN,"); printf(" %d%% %.1f units", (int)((100.0*shield)/inshld + 0.5), shield); break; case 9: printf(" Klingons Left %d", d.remkl); break; case 10: printf(" Time Left %.2f", d.remtime); break; } } skip(1); if (k!=0) return; } if (nn) chart(1); }