Pull SERGEEV dependencies out of reports.c.
[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         char *cp = NULL;
233         int leftside=TRUE, rightside=TRUE, i, j, jj, k=0, nn=FALSE, t, dam=0;
234         int goodScan=TRUE;
235         switch (l) {
236                 case 1: // SRSCAN
237                         if (game.damage[DSRSENS] != 0) {
238                                 /* Allow base's sensors if docked */
239                                 if (condit != IHDOCKED) {
240                                         prout("   S.R. SENSORS DAMAGED!");
241                                         goodScan=FALSE;
242                                 }
243                                 else
244                                         prout("  [Using Base's sensors]");
245                         }
246                         else c_printf("     Short-range scan\n\r");
247                         if (goodScan) game.starch[quadx][quady] = game.damage[DRADIO]>0.0 ? game.state.galaxy[quadx][quady]+1000:1;
248                         scan();
249                         if (isit("chart")) nn = TRUE;
250                         rightside = FALSE;
251                         chew();
252                         c_printf("    1 2 3 4 5 6 7 8 9 10\n\r");
253                         break;
254                 case 2: // REQUEST
255                         leftside=FALSE;
256                         break;
257                 case 3: // STATUS
258                         chew();
259                         leftside = FALSE;
260                         skip(1);
261         }
262         if (condit != IHDOCKED) newcnd();
263         for (i = 1; i <= 10; i++) {
264                 jj = (k!=0 ? k : i);
265                 if (leftside) {
266                         proutn("%2d  ", i);
267                         for (j = 1; j <= 10; j++) {
268                                 if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1)){
269                                    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)){
270                                         switch (condit) {
271                                                 case IHRED: textcolor(RED); break;
272                                                 case IHGREEN: textcolor(GREEN); break;
273                                                 case IHYELLOW: textcolor(YELLOW); break;
274                                                 case IHDOCKED: textcolor(LIGHTGRAY); break;
275                                                 case IHDEAD: textcolor(WHITE);
276                                         }
277                                         if (game.quad[i][j]!=ship) highvideo();
278                                    }
279                                    if (game.quad[i][j] & 128) highvideo();
280                                    c_printf("%c ",game.quad[i][j] & 127);
281                                    textcolor(LIGHTGRAY);
282                                 }
283                                 else
284                                         proutn("- ");
285                         }
286                 }
287                 if (rightside) {
288                         switch (jj) {
289                                 case 1:
290                                         proutn("Stardate      %.1f, Time Left %.2f", game.state.date, game.state.remtime);
291                                         break;
292                                 case 2:
293                                         if (condit != IHDOCKED) newcnd();
294                                         switch (condit) {
295                                                 case IHRED: cp = "RED"; break;
296                                                 case IHGREEN: cp = "GREEN"; break;
297                                                 case IHYELLOW: cp = "YELLOW"; break;
298                                                 case IHDOCKED: cp = "DOCKED"; break;
299                                                 case IHDEAD: cp="DEAD"; break;
300                                         }
301                                         for (t=0;t<=NDEVICES;t++)
302                                             if (game.damage[t]>0) dam++;
303                                         proutn("Condition     %s, %i DAMAGES", cp, dam);
304                                         break;
305                                 case 3:
306                                         proutn("Position      %d - %d , %d - %d",
307                                             quadx, quady, sectx, secty);
308                                         break;
309                                 case 4:
310                                         proutn("Life Support  ");
311                                         if (game.damage[DLIFSUP] != 0.0) {
312                                                 if (condit == IHDOCKED)
313                                                         proutn("DAMAGED, Base provides");
314                                                 else
315                                                         proutn("DAMAGED, reserves=%4.2f", lsupres);
316                                         }
317                                         else
318                                                 proutn("ACTIVE");
319                                         break;
320                                 case 5:
321                                         proutn("Warp Factor   %.1f", warpfac);
322                                         break;
323                                 case 6:
324                                         proutn("Energy        %.2f", energy);
325                                         break;
326                                 case 7:
327                                         proutn("Torpedoes     %d", torps);
328                                         break;
329                                 case 8:
330                                         proutn("Shields       ");
331                                         if (game.damage[DSHIELD] != 0)
332                                                 proutn("DAMAGED,");
333                                         else if (shldup)
334                                                 proutn("UP,");
335                                         else
336                                                 proutn("DOWN,");
337                                         proutn(" %d%% %.1f units",
338                                                    (int)((100.0*shield)/inshld + 0.5), shield);
339                                         break;
340                                 case 9:
341                                         proutn("Klingons Left %d", game.state.remkl);
342                                         break;
343                                 case 10:
344                                         attakreport(1);
345                                         break;
346                         }
347                 }
348                 if (i<10) c_printf("\n\r");
349                 if (k!=0) return(goodScan);
350         }
351         if (nn) chart(1);
352         prout("");
353         return(goodScan);
354 }
355                         
356                         
357 void eta(void) {
358         int ix1, ix2, iy1, iy2, prompt=FALSE;
359         int wfl;
360         double ttime, twarp, tpower;
361         if (game.damage[DCOMPTR] != 0.0) {
362                 prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR.");
363                 skip(1);
364                 return;
365         }
366         if (scan() != IHREAL) {
367                 prompt = TRUE;
368                 chew();
369                 proutn("Destination quadrant and/or sector? ");
370                 if (scan()!=IHREAL) {
371                         huh();
372                         return;
373                 }
374         }
375         iy1 = aaitem +0.5;
376         if (scan() != IHREAL) {
377                 huh();
378                 return;
379         }
380         ix1 = aaitem + 0.5;
381         if (scan() == IHREAL) {
382                 iy2 = aaitem + 0.5;
383                 if (scan() != IHREAL) {
384                         huh();
385                         return;
386                 }
387                 ix2 = aaitem + 0.5;
388         }
389         else {
390                 if (quady>ix1) ix2 = 1;
391                 else ix2=10;
392                 if (quadx>iy1) iy2 = 1;
393                 else iy2=10;
394         }
395
396         if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||
397                 ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) {
398                 huh();
399                 return;
400         }
401         dist = sqrt(square(iy1-quadx+0.1*(iy2-sectx))+
402                                 square(ix1-quady+0.1*(ix2-secty)));
403         wfl = FALSE;
404
405         if (prompt) prout("Answer \"no\" if you don't know the value:");
406         while (TRUE) {
407                 chew();
408                 proutn("Time or arrival date? ");
409                 if (scan()==IHREAL) {
410                         ttime = aaitem;
411                         if (ttime > game.state.date) ttime -= game.state.date; // Actually a star date
412                         if (ttime <= 1e-10 ||
413                                 (twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) {
414                                 prout("We'll never make it, sir.");
415                                 chew();
416                                 return;
417                         }
418                         if (twarp < 1.0) twarp = 1.0;
419                         break;
420                 }
421                 chew();
422                 proutn("Warp factor? ");
423                 if (scan()== IHREAL) {
424                         wfl = TRUE;
425                         twarp = aaitem;
426                         if (twarp<1.0 || twarp > 10.0) {
427                                 huh();
428                                 return;
429                         }
430                         break;
431                 }
432                 prout("Captain, certainly you can give me one of these.");
433         }
434         while (TRUE) {
435                 chew();
436                 ttime = (10.0*dist)/square(twarp);
437                 tpower = dist*twarp*twarp*twarp*(shldup+1);
438                 if (tpower >= energy) {
439                         prout("Insufficient energy, sir.");
440                         if (shldup==0 || tpower > energy*2.0) {
441                                 if (!wfl) return;
442                                 proutn("New warp factor to try? ");
443                                 if (scan() == IHREAL) {
444                                         wfl = TRUE;
445                                         twarp = aaitem;
446                                         if (twarp<1.0 || twarp > 10.0) {
447                                                 huh();
448                                                 return;
449                                         }
450                                         continue;
451                                 }
452                                 else {
453                                         chew();
454                                         skip(1);
455                                         return;
456                                 }
457                         }
458                         prout("But if you lower your shields,");
459                         proutn("remaining");
460                         tpower /= 2;
461                 }
462                 else
463                         proutn("Remaining");
464                 prout(" energy will be %.2f.", energy-tpower);
465                 if (wfl) {
466                         prout("And we will arrive at stardate %.2f.",
467                                 game.state.date+ttime);
468                 }
469                 else if (twarp==1.0)
470                         prout("Any warp speed is adequate.");
471                 else {
472                         prout("Minimum warp needed is %.2f,", twarp);
473                         prout("and we will arrive at stardate %.2f.",
474                                 game.state.date+ttime);
475                 }
476                 if (game.state.remtime < ttime)
477                         prout("Unfortunately, the Federation will be destroyed by then.");
478                 if (twarp > 6.0)
479                         prout("You'll be taking risks at that speed, Captain");
480                 if ((isatb==1 && game.state.isy == ix1 && game.state.isx == iy1 &&
481                          game.future[FSCDBAS]< ttime+game.state.date)||
482                         (game.future[FCDBAS]<ttime+game.state.date && baty==ix1 && batx == iy1))
483                         prout("The starbase there will be destroyed by then.");
484                 proutn("New warp factor to try? ");
485                 if (scan() == IHREAL) {
486                         wfl = TRUE;
487                         twarp = aaitem;
488                         if (twarp<1.0 || twarp > 10.0) {
489                                 huh();
490                                 return;
491                         }
492                 }
493                 else {
494                         chew();
495                         skip(1);
496                         return;
497                 }
498         }
499                         
500 }