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