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