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