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