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