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