Restored REQUEST.
[super-star-trek.git] / reports.c
1 #include "sst.h"
2 #include <math.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "conio.h"
6 #include "sstlinux.h"
7
8 void attakreport(int l) {
9      if (!l) {
10         if (game.future[FCDBAS] < 1e30) {
11                 prout("Starbase in %s is currently under Commander attack.",
12                       cramlc(quadrant, batx, baty));
13                 prout("It can hold out until Stardate %d.", 
14                       (int)game.future[FCDBAS]);
15         }
16         if (isatb == 1) {
17                 prout("Starbase in %s is under Super-commander attack.",
18                       cramlc(quadrant, game.state.isx, game.state.isy));
19                 prout("It can hold out until Stardate %d.", 
20                       (int)game.future[FSCDBAS]);
21         }
22      } else {
23         if (game.future[FCDBAS] < 1e30)
24            proutn("Base in %i - %i attacked by C. Alive until %.1f", batx, baty, game.future[FCDBAS]);
25         if (isatb == 1)
26            proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.isx, game.state.isy, game.future[FSCDBAS]);
27      }
28      clreol();
29 }
30         
31
32 void report(void) {
33         char *s1,*s2,*s3;
34
35         chew();
36         s1 = (thawed?"thawed ":"");
37         switch (length) {
38                 case 1: s2="short"; break;
39                 case 2: s2="medium"; break;
40                 case 4: s2="long"; break;
41                 default: s2="unknown length"; break;
42         }
43         switch (skill) {
44                 case 1: s3="novice"; break;
45                 case 2: s3="fair"; break;
46                 case 3: s3="good"; break;
47                 case 4: s3="expert"; break;
48                 case 5: s3="emeritus"; break;
49                 default: s3="skilled"; break;
50         }
51         prout("");
52         prout("You %s playing a %s%s %s game.",
53                    alldone? "were": "are now", s1, s2, s3);
54         if (skill>3 && thawed && !alldone) prout("No plaque is allowed.");
55         if (tourn) prout("This is tournament game %d.", tourn);
56         prout("Your secret password is \"%s\"",game.passwd);
57         proutn("%d of %d Klingons have been killed",
58                    game.state.killk+game.state.killc+game.state.nsckill, inkling);
59         if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s");
60         else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders.");
61         else prout(".");
62         if (skill > 2) prout("The Super Commander has %sbeen destroyed.",
63                                                   game.state.nscrem?"not ":"");
64         if (game.state.rembase != inbase) {
65                 proutn("There ");
66                 if (inbase-game.state.rembase==1) proutn("has been 1 base");
67                 else {
68                     proutn("have been %d bases", inbase-game.state.rembase);
69                 }
70                 prout(" destroyed, %d remaining.", game.state.rembase);
71         }
72         else prout("There are %d bases.", inbase);
73         if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) {
74                 /* Don't report this if not seen and
75                         either the radio is dead or not at base! */
76                 attakreport(0);
77                 iseenit = 1;
78         }
79         if (casual) prout("%d casualt%s suffered so far.",
80                                            casual, casual==1? "y" : "ies");
81         if (nhelp) prout("There were %d call%s for help.",
82                                           nhelp, nhelp==1 ? "" : "s");
83         if (ship == IHE) {
84                 proutn("You have ");
85                 if (nprobes) proutn("%d", nprobes);
86                 else proutn("no");
87                 proutn(" deep space probe");
88                 if (nprobes!=1) proutn("s");
89                 prout(".");
90         }
91         if ((game.damage[DRADIO] == 0.0 || condit == IHDOCKED)&&
92                 game.future[FDSPROB] != 1e30) {
93                 if (isarmed) 
94                         proutn("An armed deep space probe is in");
95                 else
96                         proutn("A deep space probe is in");
97                 proutn(cramlc(quadrant, probecx, probecy));
98                 prout(".");
99         }
100         if (icrystl) {
101                 if (cryprob <= .05)
102                         prout("Dilithium crystals aboard ship... not yet used.");
103                 else {
104                         int i=0;
105                         double ai = 0.05;
106                         while (cryprob > ai) {
107                                 ai *= 2.0;
108                                 i++;
109                         }
110                         prout("Dilithium crystals have been used %d time%s.",
111                                    i, i==1? "" : "s");
112                 }
113         }
114         skip(1);
115 }
116         
117 void lrscan(void) {
118         int x, y;
119         chew();
120         if (game.damage[DLRSENS] != 0.0) {
121                 /* Now allow base's sensors if docked */
122                 if (condit != IHDOCKED) {
123                         prout("LONG-RANGE SENSORS DAMAGED.");
124                         return;
125                 }
126                 proutn("Starbase's long-range scan");
127         }
128         else {
129                 prout("Long-range scan");
130         }
131         for (x = quadx-1; x <= quadx+1; x++) {
132                 proutn(" ");
133                 for (y = quady-1; y <= quady+1; y++) {
134                         if (x == 0 || x > 8 || y == 0 || y > 8)
135                                 proutn("  -1");
136                         else {
137                                 if (game.state.galaxy[x][y]<1000) proutn(" %3d", game.state.galaxy[x][y]);
138                                 else proutn("***");
139                                 game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 : 1;
140                         }
141                 }
142                 prout(" ");
143         }
144 }
145
146 void dreprt(void) {
147         int jdam = FALSE, i;
148         chew();
149
150         for (i = 1; i <= NDEVICES; i++) {
151                 if (game.damage[i] > 0.0) {
152                         if (!jdam) {
153                                 prout("DEVICE            -REPAIR TIMES-");
154                                 prout("                IN FLIGHT   DOCKED");
155                                 jdam = TRUE;
156                         }
157                         prout("  %16s %8.2f  %8.2f", 
158                                 device[i],
159                                 game.damage[i]+0.05,
160                                 docfac*game.damage[i]+0.005);
161                 }
162         }
163         if (!jdam) prout("All devices functional.");
164 }
165
166 void chart(int nn) {
167         int i,j;
168         char *cp;
169         chew();
170         if (stdamtim != 1e30 && stdamtim != game.state.date && condit == IHDOCKED) {
171                 c_printf("Spock-  \"I revised the Star Chart from the starbase's records.\"\n\r");
172         }
173         if (nn == 0) c_printf("       STAR CHART FOR THE KNOWN GALAXY\n\r");
174         if (stdamtim != 1e30) {
175                 if (condit == IHDOCKED) {
176                         /* We are docked, so restore chart from base information */
177                         stdamtim = game.state.date;
178                         for (i=1; i <= 8 ; i++)
179                                 for (j=1; j <= 8; j++)
180                                         if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+1000;
181                 }
182                 else {
183                     proutn("(Last surveillance update %d stardates ago.",
184                            (int)(game.state.date-stdamtim));
185                 }
186         }
187
188         prout("      1    2    3    4    5    6    7    8");
189         for (i = 1; i <= 8; i++) {
190                 c_printf("%d |", i);
191                 for (j = 1; j <= 8; j++) {
192                     char buf[4];
193                         c_printf("  ");
194                         if (game.starch[i][j] < 0)
195                                 strcpy(buf, ".1.");
196                         else if (game.starch[i][j] == 0)
197                                 strcpy(buf, "...");
198                         else if (game.starch[i][j] > 999)
199                                 if ((i==quadx)&&(j==quady)){
200                                    gotoxy(wherex()-1,wherey());
201                                    if (game.starch[i][i]<2000)
202                                        sprintf(buf, "%03d", game.starch[i][j]-1000);
203                                    else 
204                                        strcpy(buf, "***");
205                                 }
206                                 else
207                                     if (game.starch[i][j]<2000) 
208                                         sprintf(buf, "%03d", game.starch[i][j]-1000);
209                                     else 
210                                         strcpy(buf, "***");
211                         else if ((i==quadx)&&(j==quady)){
212                                 gotoxy(wherex()-1,wherey());
213                                 sprintf(buf, "%03d", game.state.galaxy[i][j]);
214                         }
215                         else if (game.state.galaxy[i][j]>=1000)
216                                 strcpy(buf, "***");
217                         else
218                                 sprintf(buf, "%03d", game.state.galaxy[i][j]);
219                         for (cp = buf; cp < buf + sizeof(buf); cp++)
220                             if (*cp == '0')
221                                 *cp = '.';
222                         c_printf(buf);
223                 }
224                 c_printf("  |");
225                 if (i<8) c_printf("\n\r");
226         }
227         prout("");      /* flush output */
228 }
229                 
230                 
231 int srscan(int l) {
232         static char requests[][3] =
233                 {"","da","co","po","ls","wa","en","to","sh","kl","ti"};
234         char *cp = NULL;
235         int leftside=TRUE, rightside=TRUE, i, j, jj, k=0, nn=FALSE, t, dam=0;
236         int goodScan=TRUE;
237         switch (l) {
238                 case SCAN_FULL: // SRSCAN
239                         if (game.damage[DSRSENS] != 0) {
240                                 /* Allow base's sensors if docked */
241                                 if (condit != IHDOCKED) {
242                                         prout("   S.R. SENSORS DAMAGED!");
243                                         goodScan=FALSE;
244                                 }
245                                 else
246                                         prout("  [Using Base's sensors]");
247                         }
248                         else c_printf("     Short-range scan\n\r");
249                         if (goodScan) game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ? game.state.galaxy[quadx][quady]+1000:1;
250                         scan();
251                         if (isit("chart")) nn = TRUE;
252                         if (isit("no")) rightside = FALSE;
253                         chew();
254                         c_printf("    1 2 3 4 5 6 7 8 9 10\n\r");
255                         break;
256                 case SCAN_REQUEST:
257                         while (scan() == IHEOL)
258                                 proutn("Information desired? ");
259                         chew();
260                         for (k = 1; k <= 10; k++)
261                                 if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)
262                                         break;
263                         if (k > 10) {
264                                 prout("UNRECOGNIZED REQUEST. Legal requests are:\n"
265                                          "  date, condition, position, lsupport, warpfactor,\n"
266                                          "  energy, torpedoes, shields, klingons, time.");
267                                 return FALSE;
268                         }
269                         // no "break"
270                 case SCAN_STATUS: // STATUS
271                         chew();
272                         leftside = FALSE;
273                         skip(1);
274                 case SCAN_NO_LEFTSIDE: // REQUEST
275                         leftside=FALSE;
276                         break;
277         }
278         if (condit != IHDOCKED) newcnd();
279         for (i = 1; i <= 10; i++) {
280                 jj = (k!=0 ? k : i);
281                 if (leftside) {
282                         proutn("%2d  ", i);
283                         for (j = 1; j <= 10; j++) {
284                                 if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)){
285                                    if ((game.quad[i][j]==IHMATER0)||(game.quad[i][j]==IHMATER1)||(game.quad[i][j]==IHMATER2)||(game.quad[i][j]==IHE)||(game.quad[i][j]==IHF)){
286                                         switch (condit) {
287                                                 case IHRED: textcolor(RED); break;
288                                                 case IHGREEN: textcolor(GREEN); break;
289                                                 case IHYELLOW: textcolor(YELLOW); break;
290                                                 case IHDOCKED: textcolor(LIGHTGRAY); break;
291                                                 case IHDEAD: textcolor(WHITE);
292                                         }
293                                         if (game.quad[i][j]!=ship) highvideo();
294                                    }
295                                    if (game.quad[i][j] & 128) highvideo();
296                                    c_printf("%c ",game.quad[i][j] & 127);
297                                    textcolor(LIGHTGRAY);
298                                 }
299                                 else
300                                         proutn("- ");
301                         }
302                 }
303                 if (rightside) {
304                         switch (jj) {
305                                 case 1:
306                                         proutn("Stardate      %.1f, Time Left %.2f", game.state.date, game.state.remtime);
307                                         break;
308                                 case 2:
309                                         if (condit != IHDOCKED) newcnd();
310                                         switch (condit) {
311                                                 case IHRED: cp = "RED"; break;
312                                                 case IHGREEN: cp = "GREEN"; break;
313                                                 case IHYELLOW: cp = "YELLOW"; break;
314                                                 case IHDOCKED: cp = "DOCKED"; break;
315                                                 case IHDEAD: cp="DEAD"; break;
316                                         }
317                                         for (t=0;t<=NDEVICES;t++)
318                                             if (game.damage[t]>0) dam++;
319                                         proutn("Condition     %s, %i DAMAGES", cp, dam);
320                                         break;
321                                 case 3:
322                                         proutn("Position      %d - %d , %d - %d",
323                                             quadx, quady, sectx, secty);
324                                         break;
325                                 case 4:
326                                         proutn("Life Support  ");
327                                         if (game.damage[DLIFSUP] != 0.0) {
328                                                 if (condit == IHDOCKED)
329                                                         proutn("DAMAGED, Base provides");
330                                                 else
331                                                         proutn("DAMAGED, reserves=%4.2f", lsupres);
332                                         }
333                                         else
334                                                 proutn("ACTIVE");
335                                         break;
336                                 case 5:
337                                         proutn("Warp Factor   %.1f", warpfac);
338                                         break;
339                                 case 6:
340                                         proutn("Energy        %.2f", energy);
341                                         break;
342                                 case 7:
343                                         proutn("Torpedoes     %d", torps);
344                                         break;
345                                 case 8:
346                                         proutn("Shields       ");
347                                         if (game.damage[DSHIELD] != 0)
348                                                 proutn("DAMAGED,");
349                                         else if (shldup)
350                                                 proutn("UP,");
351                                         else
352                                                 proutn("DOWN,");
353                                         proutn(" %d%% %.1f units",
354                                                    (int)((100.0*shield)/inshld + 0.5), shield);
355                                         break;
356                                 case 9:
357                                         proutn("Klingons Left %d", game.state.remkl);
358                                         break;
359                                 case 10:
360                                         attakreport(1);
361                                         break;
362                         }
363                 }
364                 if (i<10) c_printf("\n\r");
365                 if (k!=0) return(goodScan);
366         }
367         prout("");
368         if (nn) chart(1);
369         return(goodScan);
370 }
371                         
372                         
373 void eta(void) {
374         int ix1, ix2, iy1, iy2, prompt=FALSE;
375         int wfl;
376         double ttime, twarp, tpower;
377         if (game.damage[DCOMPTR] != 0.0) {
378                 prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR.");
379                 skip(1);
380                 return;
381         }
382         if (scan() != IHREAL) {
383                 prompt = TRUE;
384                 chew();
385                 proutn("Destination quadrant and/or sector? ");
386                 if (scan()!=IHREAL) {
387                         huh();
388                         return;
389                 }
390         }
391         iy1 = aaitem +0.5;
392         if (scan() != IHREAL) {
393                 huh();
394                 return;
395         }
396         ix1 = aaitem + 0.5;
397         if (scan() == IHREAL) {
398                 iy2 = aaitem + 0.5;
399                 if (scan() != IHREAL) {
400                         huh();
401                         return;
402                 }
403                 ix2 = aaitem + 0.5;
404         }
405         else {
406                 if (quady>ix1) ix2 = 1;
407                 else ix2=10;
408                 if (quadx>iy1) iy2 = 1;
409                 else iy2=10;
410         }
411
412         if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||
413                 ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) {
414                 huh();
415                 return;
416         }
417         dist = sqrt(square(iy1-quadx+0.1*(iy2-sectx))+
418                                 square(ix1-quady+0.1*(ix2-secty)));
419         wfl = FALSE;
420
421         if (prompt) prout("Answer \"no\" if you don't know the value:");
422         while (TRUE) {
423                 chew();
424                 proutn("Time or arrival date? ");
425                 if (scan()==IHREAL) {
426                         ttime = aaitem;
427                         if (ttime > game.state.date) ttime -= game.state.date; // Actually a star date
428                         if (ttime <= 1e-10 ||
429                                 (twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) {
430                                 prout("We'll never make it, sir.");
431                                 chew();
432                                 return;
433                         }
434                         if (twarp < 1.0) twarp = 1.0;
435                         break;
436                 }
437                 chew();
438                 proutn("Warp factor? ");
439                 if (scan()== IHREAL) {
440                         wfl = TRUE;
441                         twarp = aaitem;
442                         if (twarp<1.0 || twarp > 10.0) {
443                                 huh();
444                                 return;
445                         }
446                         break;
447                 }
448                 prout("Captain, certainly you can give me one of these.");
449         }
450         while (TRUE) {
451                 chew();
452                 ttime = (10.0*dist)/square(twarp);
453                 tpower = dist*twarp*twarp*twarp*(shldup+1);
454                 if (tpower >= energy) {
455                         prout("Insufficient energy, sir.");
456                         if (shldup==0 || tpower > energy*2.0) {
457                                 if (!wfl) return;
458                                 proutn("New warp factor to try? ");
459                                 if (scan() == IHREAL) {
460                                         wfl = TRUE;
461                                         twarp = aaitem;
462                                         if (twarp<1.0 || twarp > 10.0) {
463                                                 huh();
464                                                 return;
465                                         }
466                                         continue;
467                                 }
468                                 else {
469                                         chew();
470                                         skip(1);
471                                         return;
472                                 }
473                         }
474                         prout("But if you lower your shields,");
475                         proutn("remaining");
476                         tpower /= 2;
477                 }
478                 else
479                         proutn("Remaining");
480                 prout(" energy will be %.2f.", energy-tpower);
481                 if (wfl) {
482                         prout("And we will arrive at stardate %.2f.",
483                                 game.state.date+ttime);
484                 }
485                 else if (twarp==1.0)
486                         prout("Any warp speed is adequate.");
487                 else {
488                         prout("Minimum warp needed is %.2f,", twarp);
489                         prout("and we will arrive at stardate %.2f.",
490                                 game.state.date+ttime);
491                 }
492                 if (game.state.remtime < ttime)
493                         prout("Unfortunately, the Federation will be destroyed by then.");
494                 if (twarp > 6.0)
495                         prout("You'll be taking risks at that speed, Captain");
496                 if ((isatb==1 && game.state.isy == ix1 && game.state.isx == iy1 &&
497                          game.future[FSCDBAS]< ttime+game.state.date)||
498                         (game.future[FCDBAS]<ttime+game.state.date && baty==ix1 && batx == iy1))
499                         prout("The starbase there will be destroyed by then.");
500                 proutn("New warp factor to try? ");
501                 if (scan() == IHREAL) {
502                         wfl = TRUE;
503                         twarp = aaitem;
504                         if (twarp<1.0 || twarp > 10.0) {
505                                 huh();
506                                 return;
507                         }
508                 }
509                 else {
510                         chew();
511                         skip(1);
512                         return;
513                 }
514         }
515                         
516 }