Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include <ctype.h>
  2.  
  3. #ifdef MSDOS
  4. #include <dos.h>
  5. #endif
  6.  
  7. #ifdef WINDOWS
  8. #include <windows.h>
  9. #endif
  10.  
  11. #include <time.h>
  12.  
  13. #ifdef KOS32
  14. #include <conio.h>
  15. #include <kos32sys0.h>
  16. #endif
  17.  
  18. #define INCLUDED        // Define externs here
  19. #include "sst.h"
  20.        
  21. /*int getch(void);
  22. */
  23.  
  24. static char line[128], *linep = line;
  25. static int linecount;   /* for paging */
  26.  
  27. static void clearscreen(void);
  28.  
  29. /* Compared to original version, I've changed the "help" command to
  30.    "call" and the "terminate" command to "quit" to better match
  31.    user expectations. The DECUS version apparently made those changes
  32.    as well as changing "freeze" to "save". However I like "freeze".
  33.  
  34.    When I got a later version of Super Star Trek that I was converting
  35.    from, I added the emexit command.
  36.  
  37.    That later version also mentions srscan and lrscan working when
  38.    docked (using the starbase's scanners), so I made some changes here
  39.    to do this (and indicating that fact to the player), and then realized
  40.    the base would have a subspace radio as well -- doing a Chart when docked
  41.    updates the star chart, and all radio reports will be heard. The Dock
  42.    command will also give a report if a base is under attack.
  43.  
  44.    Movecom no longer reports movement if sensors are damaged so you wouldn't
  45.    otherwise know it.
  46.  
  47.    Also added:
  48.  
  49.    1. Better base positioning at startup
  50.  
  51.    2. deathray improvement (but keeping original failure alternatives)
  52.  
  53.    3. Tholian Web
  54.  
  55.    4. Enemies can ram the Enterprise. Regular Klingons and Romulans can
  56.       move in Expert and Emeritus games. This code could use improvement.
  57.  
  58.    5. The deep space probe looks interesting! DECUS version
  59.  
  60.    6. Cloaking (with contributions from Erik Olofsen) and Capturing (BSD version).
  61.  
  62.    */
  63.  
  64. // I don't like the way this is done, relying on an index. But I don't
  65. // want to invest the time to make this nice and table driven.
  66.  
  67. static char *commands[] = {
  68.         "srscan",
  69.         "lrscan",
  70.         "phasers",
  71.         "photons",
  72.         "move",
  73.         "shields",
  74.         "dock",
  75.         "damages",
  76.         "chart",
  77.         "impulse",
  78.         "rest",
  79.         "warp",
  80.         "status",
  81.         "sensors",
  82.         "orbit",
  83.         "transport",
  84.         "mine",
  85.         "crystals",
  86.         "shuttle",
  87.         "planets",
  88.         "request",
  89.         "report",
  90.         "computer",
  91.         "commands",
  92.     "emexit",
  93.     "probe",
  94.     "cloak",
  95.     "capture",
  96.     "score",
  97.         "abandon",
  98.         "destruct",
  99.         "freeze",
  100.         "deathray",
  101.         "debug",
  102.         "call",
  103.         "quit",
  104.     "help"
  105.  
  106. };
  107.  
  108. #define NUMCOMMANDS (sizeof(commands)/sizeof(char *))
  109.  
  110. static void listCommands(int x) {
  111.         prout("   SRSCAN    MOVE      PHASERS   CALL\n"
  112.                   "   STATUS    IMPULSE   PHOTONS   ABANDON\n"
  113.                   "   LRSCAN    WARP      SHIELDS   DESTRUCT\n"
  114.                   "   CHART     REST      DOCK      QUIT\n"
  115.                   "   DAMAGES   REPORT    SENSORS   ORBIT\n"
  116.                   "   TRANSPORT MINE      CRYSTALS  SHUTTLE\n"
  117.                   "   PLANETS   REQUEST   DEATHRAY  FREEZE\n"
  118.           "   COMPUTER  EMEXIT    PROBE     COMMANDS");
  119.     proutn("   ");
  120. #ifdef SCORE
  121.     proutn("SCORE     ");
  122. #endif
  123. #ifdef CLOAKING
  124.     proutn("CLOAK     ");
  125. #endif
  126. #ifdef CAPTURE
  127.     proutn("CAPTURE   ");
  128. #endif
  129.     if (x) proutn("HELP     ");
  130.     prout("");
  131. }
  132.  
  133. static void helpme(void) {
  134.         int i, j;
  135.         char cmdbuf[32];
  136.         char linebuf[132];
  137.         FILE *fp;
  138.         /* Give help on commands */
  139.         int key;
  140.         key = scan();
  141.         while (TRUE) {
  142.                 if (key == IHEOL) {
  143.                         /* proutn("Help on what command?"); */
  144.                         proutn("‘¯à ¢ªã ¯® ª ª®© ª®¬ ­¤¥?");
  145.                         key = scan();
  146.                 }
  147.                 if (key == IHEOL) return;
  148.                 for (i = 0; i < NUMCOMMANDS; i++) {
  149.                         if (strcmp(commands[i], citem)==0) break;
  150.                 }
  151.                 if (i != NUMCOMMANDS) break;
  152.                 skip(1);
  153.                 /* prout("Valid commands:"); */
  154.                 prout("¥à¥ç¥­ì ª®¬ ­¤:");
  155.                 listCommands(FALSE);
  156.                 key = IHEOL;
  157.                 chew();
  158.                 skip(1);
  159.         }
  160.         if (i == 23) {
  161.                 strcpy(cmdbuf, " ABBREV");
  162.         }
  163.         else {
  164.                 strcpy(cmdbuf, "  Mnemonic:  ");
  165.                 j = 0;
  166.                 while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++;
  167.         }
  168.         fp = fopen("sst.doc", "r");
  169.         if (fp == NULL) {
  170. /*              prout("Spock-  \"Captain, that information is missing from the");
  171.                 prout("   computer. You need to find SST.DOC and put it in the");
  172.                 prout("   current directory.\"");
  173.  */             prout("‘¯®ª-  \"Š ¯¨â ­, ¢áï á¯à ¢®ç­ ï ¨­ä®à¬ æ¨ï ¯à®¯ «  á ­ è¥£® ª®¬¯ìîâ¥à .");
  174.                 prout("    ©¤¨â¥ ä ©« SST.DOC ¨ ¯®«®¦¨â¥ ¢ ⥪ãéãî ¯ ¯ªã.\"");
  175.                 return;
  176.         }
  177.         i = strlen(cmdbuf);
  178.         do {
  179.                 if (fgets(linebuf, 132, fp) == NULL) {
  180.                         /* prout("Spock- \"Captain, there is no information on that command.\""); */
  181.                         prout("‘¯®ª- \"Š ¯¨â ­, ¯® í⮩ ª®¬ ­¤¥ á¯à ¢®ç­ ï ¨­ä®à¬ æ¨ï ­¥ ­ ©¤¥­ .\"");
  182.                         fclose(fp);
  183.                         return;
  184.                 }
  185.         } while (strncmp(linebuf, cmdbuf, i) != 0);
  186.  
  187.         skip(1);
  188.         /* prout("Spock- \"Captain, I've found the following information:\""); */
  189.         prout("‘¯®ª- \"Š ¯¨â ­, ï ­ è¥« á«¥¤ãîéãî ¨­ä®à¬ æ¨î:\"");
  190.         skip(1);
  191.  
  192.         do {
  193.                 if (linebuf[0]!=12) { // ignore page break lines
  194.                         linebuf[strlen(linebuf)-1] = '\0'; // No \n at end
  195.                         prout(linebuf);
  196.                 }
  197.                 fgets(linebuf,132,fp);
  198.         } while (strstr(linebuf, "******")==NULL);
  199.         fclose(fp);
  200. }
  201.  
  202. static void makemoves(void) {
  203.         int i, hitme;
  204.         char ch;
  205.         while (TRUE) { /* command loop */
  206.                 hitme = FALSE;
  207.                 justin = 0;
  208.                 Time = 0.0;
  209.                 i = -1;
  210.                 while (TRUE)  { /* get a command */
  211.                         chew();
  212.                         skip(1);
  213.                         proutn("COMMAND> ");
  214.                         if (scan() == IHEOL) continue;
  215.                         for (i=0; i < 29; i++) // Abbreviations allowed for the first 29 commands, only.
  216.                                 if (isit(commands[i]))
  217.                                         break;
  218.                         if (i < 29) break;
  219.                         for (; i < NUMCOMMANDS; i++)
  220.                                 if (strcmp(commands[i], citem) == 0) break;
  221.                         if (i < NUMCOMMANDS
  222. #ifndef CLOAKING
  223.                             && i != 26 // ignore the CLOAK command
  224. #endif
  225. #ifndef CAPTURE
  226.                             && i != 27 // ignore the CAPTURE command
  227. #endif
  228. #ifndef SCORE
  229.                             && i != 28 // ignore the SCORE command
  230. #endif
  231. #ifndef DEBUG
  232.                             && i != 33 // ignore the DEBUG command
  233. #endif
  234.                            ) break;
  235.  
  236.                         if (skill <= SFAIR)  {
  237.                                 /* prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:"); */
  238.                                 prout("ŠŽŒ€„€ … €‘Ž‡€€. „…‰‘’‚“ž™ˆ… ŠŽŒ€„›:");
  239.                                 listCommands(TRUE);
  240.                         }
  241.                         else prout("ŠŽŒ€„€ … €‘Ž‡€€.");/*UNRECOGNIZED COMMAND*/
  242.                 }
  243.                 switch (i) { /* command switch */
  244.                         case 0:                 // srscan
  245.                                 srscan(1);
  246.                                 break;
  247.                         case 1:                 // lrscan
  248.                                 lrscan();
  249.                                 break;
  250.                         case 2:                 // phasers
  251.                                 phasers();
  252.                 if (ididit) {
  253. #ifdef CLOAKING
  254.                     if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
  255.                         /* prout("The Romulan ship discovers you are breaking the Treaty of Algeron!"); */
  256.                         prout("Š®à ¡«ì ஬㫠­æ¥¢ § ¬¥â¨« ¢ è¥ ­ àã襭¨¥ €«£¥à®­áª®£® ᮣ« è¥­¨ï!");
  257.                         ncviol++;
  258.                         isviolreported = TRUE;
  259.                     }
  260. #endif
  261.                     hitme = TRUE;
  262.                 }
  263.                                 break;
  264.                         case 3:                 // photons
  265.                                 photon();
  266.                 if (ididit) {
  267. #ifdef CLOAKING
  268.                     if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
  269.                         /* prout("The Romulan ship discovers you are breaking the Treaty of Algeron!"); */
  270.                         prout("Š®à ¡«ì ஬㫠­æ¥¢ § ¬¥â¨« ¢ è¥ ­ àã襭¨¥ €«£¥à®­áª®£® ᮣ« è¥­¨ï!");
  271.                         ncviol++;
  272.                         isviolreported = TRUE;
  273.                     }
  274. #endif
  275.                     hitme = TRUE;
  276.                 }
  277.                                 break;
  278.                         case 4:                 // move
  279.                                 warp(1);
  280.                                 break;
  281.                         case 5:                 // shields
  282.                                 sheild(1);
  283.                                 if (ididit) {
  284.                                         attack(2);
  285.                                         shldchg = 0;
  286.                                 }
  287.                                 break;
  288.                         case 6:                 // dock
  289.                                 dock();
  290.                                 break;
  291.                         case 7:                 // damages
  292.                                 dreprt();
  293.                                 break;
  294.                         case 8:                 // chart
  295.                                 chart(0);
  296.                                 break;
  297.                         case 9:                 // impulse
  298.                                 impuls();
  299.                                 break;
  300.                         case 10:                // rest
  301.                                 waiting();
  302.                                 if (ididit) hitme = TRUE;
  303.                                 break;
  304.                         case 11:                // warp
  305.                                 setwrp();
  306.                                 break;
  307.                         case 12:                // status
  308.                                 srscan(3);
  309.                                 break;
  310.                         case 13:                        // sensors
  311.                                 sensor();
  312.                                 break;
  313.                         case 14:                        // orbit
  314.                                 orbit();
  315.                                 if (ididit) hitme = TRUE;
  316.                                 break;
  317.                         case 15:                        // transport "beam"
  318.                                 beam();
  319.                                 break;
  320.                         case 16:                        // mine
  321.                                 mine();
  322.                                 if (ididit) hitme = TRUE;
  323.                                 break;
  324.                         case 17:                        // crystals
  325.                                 usecrystals();
  326.                                 break;
  327.                         case 18:                        // shuttle
  328.                                 shuttle();
  329.                                 if (ididit) hitme = TRUE;
  330.                                 break;
  331.                         case 19:                        // Planet list
  332.                                 preport();
  333.                                 break;
  334.                         case 20:                        // Status information
  335.                                 srscan(2);
  336.                                 break;
  337.                         case 21:                        // Game Report
  338.                                 report(0);
  339.                                 break;
  340.                         case 22:                        // use COMPUTER!
  341.                                 eta();
  342.                                 break;
  343.                         case 23:
  344.                                 listCommands(TRUE);
  345.                                 break;
  346.                         case 24:                // Emergency exit
  347.                                 clearscreen();  // Hide screen
  348.                                 freeze(TRUE);   // forced save
  349. #ifdef KOS32
  350.                                 con_exit(1);
  351. #endif                         
  352.                                 exit(1);                // And quick exit
  353.                                 break;
  354.                         case 25:
  355.                                 probe();                // Launch probe
  356.                                 break;
  357. #ifdef CLOAKING
  358.                         case 26:
  359.                                 cloak();        // turn on/off cloaking
  360.                                 if (iscloaking) {
  361.                                         attack(2); // We will be seen while we cloak
  362.                                         iscloaking = FALSE;
  363.                                         iscloaked = TRUE;
  364.                                 }
  365.                                 break;
  366. #endif
  367. #ifdef CAPTURE
  368.                         case 27:
  369.                                 capture();      // Attempt to get Klingon ship to surrender
  370.                                 if (ididit) hitme = TRUE;
  371.                                 break;
  372. #endif
  373. #ifdef SCORE
  374.                         case 28:
  375.                                 score(1);    // get the score
  376.                                 break;
  377. #endif
  378.                         case 29:                        // Abandon Ship
  379.                                 abandn();
  380.                                 break;
  381.                         case 30:                        // Self Destruct
  382.                                 dstrct();
  383.                                 break;
  384.                         case 31:                        // Save Game
  385.                                 freeze(FALSE);
  386.                                 if (skill > SGOOD)
  387.                                         /* prout("WARNING--Frozen games produce no plaques!"); */
  388.                                         prout("‚ˆŒ€ˆ…--‘®åà ­¥­­ë¥ ¨£àë ­¥ ¤ îâ ­ £à ¤!");
  389.                                 break;
  390.                         case 32:                        // Try a desparation measure
  391.                                 deathray();
  392.                                 if (ididit) hitme = TRUE;
  393.                                 break;
  394. #ifdef DEBUG
  395.                         case 33:                        // What do we want for debug???
  396.                                 debugme();
  397.                                 break;
  398. #endif
  399.                         case 34:                // Call for help
  400.                                 help();
  401.                                 break;
  402.                         case 35:
  403.                                 alldone = 1;    // quit the game
  404. #ifdef DEBUG
  405.                                 if (idebug) score(0);
  406. #endif
  407.                                 break;
  408.                         case 36:
  409.                                 helpme();       // get help
  410.                                 break;
  411.                 }
  412.                 for (;;) {
  413.                         if (alldone) break;             // Game has ended
  414. #ifdef DEBUG
  415.                         if (idebug) prout("2500");
  416. #endif
  417.                         if (Time != 0.0) {
  418.                                 events();
  419.                                 if (alldone) break;             // Events did us in
  420.                         }
  421.                         if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
  422.                                 atover(0);
  423.                                 continue;
  424.                         }
  425.                         if (nenhere == 0) movetho();
  426.                         if (hitme && justin==0) {
  427.                                 attack(2);
  428.                                 if (alldone) break;
  429.                                 if (d.galaxy[quadx][quady] == 1000) {   // went NOVA!
  430.                                         atover(0);
  431.                                         hitme = TRUE;
  432.                                         continue;
  433.                                 }
  434.                         }
  435.                         break;
  436.                 }
  437.                 if (alldone) break;
  438.         }
  439. }
  440.  
  441.  
  442. int main(int argc, char **argv) {
  443.         int i;
  444.         int hitme;
  445.         char ch;
  446.        
  447. #ifdef KOS32
  448.         if (con_init_console_dll()) return 1; // init fail
  449.         con_set_title("-SUPER- STAR TREK");
  450.         con_set_flags(CON_COLOR_GREEN);
  451. #endif 
  452. #ifdef WINDOWS
  453.         HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);  // Get handle to standard output
  454.         SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
  455. #endif
  456.  
  457.        
  458.         prelim();
  459.  
  460.         if (argc > 1) { // look for -f option
  461.                 if (strcmp(argv[1], "-f")== 0) {
  462.                         coordfixed = 1;
  463.                         argc--;
  464.                         argv++;
  465.                 }
  466.         }
  467.                                        
  468.        
  469.         if (argc > 1) {
  470.                 fromcommandline = 1;
  471.                 line[0] = '\0';
  472.                 while (--argc > 0) {
  473.                         strcat(line, *(++argv));
  474.                         strcat(line, " ");
  475.                 }
  476.         }
  477.         else fromcommandline = 0;
  478.  
  479.  
  480.         while (TRUE) { /* Play a game */
  481.                 setup();
  482.                 if (alldone) {
  483.                         score(0);
  484.                         alldone = 0;
  485.                 }
  486.                 else makemoves();
  487.                 skip(2);
  488.                 stars();
  489.                 skip(1);
  490.  
  491.                 if (tourn && alldone) {
  492.                         /* printf("Do you want your score recorded?"); */
  493.                         printf("‚ë å®â¨â¥ § ¯¨á âì ᢮¨ ¤®á⨦¥­¨ï?");
  494.                         if (ja()) {
  495.                                 chew2();
  496.                                 freeze(FALSE);
  497.                         }
  498.                 }
  499.                 /* printf("Do you want to play again?"); */
  500.                 printf("†¥« ¥â¥ áë£à âì § ­®¢®?");
  501.                 if (!ja()) break;
  502.         }
  503.         skip(1);
  504.         /* prout("May the Great Bird of the Galaxy roost upon your home planet."); */
  505.         prout("ãáâì ‚¥«¨ª ï ƒ « ªâ¨ç¥áª ï â¨æ  ᮢì¥â £­¥§¤® ­  ‚ è¥© த­®© ¯« ­¥â¥.");
  506.         return 0;
  507. }
  508.  
  509.  
  510. void cramen(int i) {
  511.         /* return an enemy */
  512.         char *s;
  513.        
  514.         switch (i) {
  515.                 case IHR: s = "®¬ã« ­¥æ"; break;/*Romulan*/
  516.                 case IHK: s = "Š«¨­£®­"; break;/*Klingon*/
  517.                 case IHC: s = "Š®¬¬ ­¤¥à"; break;/*Commander*/
  518.                 case IHS: s = "‘ã¯¥àŠ®¬¬ ­¤¥à"; break;/*Super-commander*/
  519.                 case IHSTAR: s = "‡¢¥§¤ "; break;/*Star*/
  520.                 case IHP: s = "« ­¥â "; break;/*Planet*/
  521.                 case IHB: s = "‘â ­æ¨ï"; break;/*Starbase*/
  522.                 case IHBLANK: s = "—¥à­ ï ¤ëà "; break;/*Black hole*/
  523.                 case IHT: s = "’®«¨ ­"; break;/*Tholean*/
  524.                 case IHWEB: s = "’®«¨ ­áª ï á¥âì"; break;/*Tholean web*/
  525.                 default: s = "‹Ž??"; break;/*Unknown*/
  526.         }
  527.         proutn(s);
  528. }
  529.  
  530. void cramlc(int key, int x, int y) {
  531.         if (key == 1) proutn(" Š¢ ¤à ­â");/*Quadrant*/
  532.         else if (key == 2) proutn(" ‘¥ªâ®à");/*Sector*/
  533.         proutn(" ");
  534.         crami(x, 1);
  535.         proutn(" - ");
  536.         crami(y, 1);
  537. }
  538.  
  539. void crmena(int i, int enemy, int key, int x, int y) {
  540.         if (i == 1) proutn("***");
  541.         cramen(enemy);
  542.         proutn(" at");
  543.         cramlc(key, x, y);
  544. }
  545.  
  546. void crmshp(void) {
  547.         char *s;
  548.         switch (ship) {
  549.                 case IHE: s = "­â¥à¯à ©§"; break;/*Enterprise*/
  550.                 case IHF: s = "Š®à®«¥¢  ”¥©"; break;/*Faerie Queene*/
  551.                 default:  s = "Š®à ¡«ì???"; break;/*Ship*/
  552.         }
  553.         proutn(s);
  554. }
  555.  
  556. void stars(void) {
  557.         prouts("******************************************************");
  558.         skip(1);
  559. }
  560.  
  561. double expran(double avrage) {
  562.         return -avrage*log(1e-7 + Rand());
  563. }
  564.  
  565. double Rand(void) {
  566.         return rand()/(1.0 + (double)RAND_MAX);
  567. }
  568.  
  569. void iran8(int *i, int *j) {
  570.         *i = Rand()*8.0 + 1.0;
  571.         *j = Rand()*8.0 + 1.0;
  572. }
  573.  
  574. void iran10(int *i, int *j) {
  575.         *i = Rand()*10.0 + 1.0;
  576.         *j = Rand()*10.0 + 1.0;
  577. }
  578.  
  579. void chew(void) {
  580.         linecount = 0;
  581.         linep = line;
  582.         *linep = 0;
  583. }
  584.  
  585. void chew2(void) {
  586.         /* return IHEOL next time */
  587.         linecount = 0;
  588.         linep = line+1;
  589.         *linep = 0;
  590. }
  591.  
  592. int scan(void) {
  593.         int i;
  594.         char *cp;
  595.  
  596.         linecount = 0;
  597.  
  598.         // Init result
  599.         aaitem = 0.0;
  600.         *citem = 0;
  601.  
  602.         // Read a line if nothing here
  603.         if (*linep == 0) {
  604.                 if (linep != line) {
  605.                         chew();
  606.                         return IHEOL;
  607.                 }
  608. #ifdef KOS32
  609.                 cp = gets(line);
  610.                 if (!cp) exit(1);
  611. #else
  612.                 // We should really be using fgets
  613.                 fgets(line,sizeof(line),stdin);
  614. #endif
  615.                 if (line[strlen(line)-1] == '\n')
  616.                         line[strlen(line)-1] = '\0';
  617.                 linep = line;
  618.         }
  619.         // Skip leading white space
  620.         while (*linep == ' ') linep++;
  621.         // Nothing left
  622.         if (*linep == 0) {
  623.                 chew();
  624.                 return IHEOL;
  625.         }
  626.         if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') {
  627.                 // treat as a number
  628.             if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) {
  629.                 linep = line; // Invalid numbers are ignored
  630.                 *linep = 0;
  631.                 return IHEOL;
  632.             }
  633.             else {
  634.                 // skip to end
  635.                 linep += i;
  636.                 return IHREAL;
  637.             }
  638.         }
  639.         // Treat as alpha
  640.         cp = citem;
  641.         while (*linep && *linep!=' ') {
  642.                 if ((cp - citem) < 9) *cp++ = tolower(*linep);
  643.                 linep++;
  644.         }
  645.         *cp = 0;
  646.         return IHALPHA;
  647. }
  648.  
  649. int ja(void) {
  650.         chew();
  651.         while (TRUE) {
  652.                 scan();
  653.                 chew();
  654.                 if (*citem == 'y') return TRUE;
  655.                 if (*citem == 'n') return FALSE;
  656.                 /* proutn("Please answer with \"Y\" or \"N\":"); */
  657.                 proutn("®¦ «ã©áâ  ®â¢¥âì⥠\"y\" or \"n\":");
  658.         }
  659. }
  660.  
  661. void cramf(double x, int w, int d) {
  662.         char buf[64];
  663.         sprintf(buf, "%*.*f", w, d, x);
  664.         proutn(buf);
  665. }
  666.  
  667. void crami(int i, int w) {
  668.         char buf[16];
  669.         sprintf(buf, "%*d", w, i);
  670.         proutn(buf);
  671. }
  672.  
  673. double square(double i) { return i*i; }
  674.                                                                        
  675. static void clearscreen(void) {
  676.         /* Somehow we need to clear the screen */
  677.         proutn("\033[2J\033[0;0H");     /* Hope for an ANSI display */
  678. }
  679.  
  680. /* We will pull these out in case we want to do something special later */
  681.  
  682. void pause(int i) {
  683. #ifdef CLOAKING
  684.         if (iscloaked) return;
  685. #endif
  686.         putchar('\n');
  687.         if (i==1) {
  688.                 if (skill > SFAIR)
  689.                         prout("[Ž‹“—…Ž ŽšŸ‚‹…ˆ…...]");/*ANNOUNCEMENT ARRIVING*/
  690.                 else
  691.                         /* prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- HIT ENTER TO CONTINUE]"); */
  692.                         prout("[Ž‹“—…Ž ‚€†Ž… ŽšŸ‚‹…ˆ… -- €†Œˆ’… ENTER „‹Ÿ Ž„Ž‹†…ˆŸ]");
  693.                 getchar();
  694.         }
  695.         else {
  696.                 if (skill > SFAIR)
  697.                         proutn("[Ž„Ž‹†ˆ’œ?]");/*CONTINUE*/
  698.                 else
  699.                         proutn("[€†Œˆ’… ENTER „‹Ÿ Ž„Ž‹†…ˆŸ]");/*HIT ENTER TO CONTINUE*/
  700.                 getchar();
  701.                 proutn("\r                           \r");
  702.         }
  703.         if (i != 0) {
  704.                 clearscreen();
  705.         }
  706.     linecount = 0;
  707. }
  708.  
  709.  
  710. void skip(int i) {
  711.         while (i-- > 0) {
  712.                 linecount++;
  713.                 if (linecount >= 23)
  714.                         pause(0);
  715.                 else
  716.                         putchar('\n');
  717.         }
  718. }
  719.  
  720.  
  721. void proutn(char *s) {
  722. #ifndef KOS32
  723.         fputs(s, stdout);
  724. #else
  725.         con_write_asciiz(s);
  726. #endif
  727. }
  728.  
  729. void prout(char *s) {
  730.         proutn(s);
  731.         skip(1);
  732. }
  733.  
  734. void prouts(char *s) {
  735. #ifdef KOS32
  736. #define clock_t long int
  737. #define clock() get_tick_count()
  738. #define CLOCKS_PER_SEC 100
  739. #endif
  740.  
  741.         clock_t endTime;
  742.         /* print slowly! */
  743.         while (*s) {
  744.                 endTime = clock() + CLOCKS_PER_SEC*0.05;
  745.                 while (clock() < endTime) ;
  746.                 putchar(*s++);
  747. #ifndef KOS32
  748.                 fflush(stdout);
  749. #endif
  750.         }
  751. }
  752.  
  753. void huh(void) {
  754.         chew();
  755.         skip(1);
  756.         /* prout("Beg your pardon, Captain?"); */
  757.         prout("à®áâ¨â¥, ­¥ ¯®­ï«, Š ¯¨â ­?");
  758. }
  759.  
  760. int isit(char *s) {
  761.         /* New function -- compares s to scaned citem and returns true if it
  762.            matches to the length of s */
  763.  
  764.         return strncmp(s, citem, max(1, strlen(citem))) == 0;
  765.  
  766. }
  767.  
  768. #ifdef DEBUG
  769. void debugme(void) {
  770.         proutn("Reset levels? ");
  771.         if (ja() != 0) {
  772.                 if (energy < inenrg) energy = inenrg;
  773.                 shield = inshld;
  774.                 torps = intorps;
  775.                 lsupres = inlsr;
  776.         }
  777.         proutn("Reset damage? ");
  778.         if (ja() != 0) {
  779.                 int i;
  780.                 for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;
  781.                 stdamtim = 1e30;
  782.         }
  783.         proutn("Toggle idebug? ");
  784.         if (ja() != 0) {
  785.                 idebug = !idebug;
  786.                 if (idebug) prout("Debug output ON");
  787.                 else prout("Debug output OFF");
  788.         }
  789.         proutn("Cause selective damage? ");
  790.         if (ja() != 0) {
  791.                 int i, key;
  792.                 for (i=1; i <= ndevice; i++) {
  793.                         proutn("Kill ");
  794.                         proutn(device[i]);
  795.                         proutn("? ");
  796.                         chew();
  797.                         key = scan();
  798.                         if (key == IHALPHA &&  isit("y")) {
  799.                                 damage[i] = 10.0;
  800.                                 if (i == DRADIO) stdamtim = d.date;
  801.                         }
  802.                 }
  803.         }
  804.         proutn("Examine/change events? ");
  805.         if (ja() != 0) {
  806.                 int i;
  807.                 for (i = 1; i < NEVENTS; i++) {
  808.                         int key;
  809.                         if (future[i] == 1e30) continue;
  810.                         switch (i) {
  811.                                 case FSNOVA:  proutn("Supernova       "); break;
  812.                                 case FTBEAM:  proutn("T Beam          "); break;
  813.                                 case FSNAP:   proutn("Snapshot        "); break;
  814.                                 case FBATTAK: proutn("Base Attack     "); break;
  815.                                 case FCDBAS:  proutn("Base Destroy    "); break;
  816.                                 case FSCMOVE: proutn("SC Move         "); break;
  817.                                 case FSCDBAS: proutn("SC Base Destroy "); break;
  818.                         }
  819.                         cramf(future[i]-d.date, 8, 2);
  820.                         chew();
  821.                         proutn("  ?");
  822.                         key = scan();
  823.                         if (key == IHREAL) {
  824.                                 future[i] = d.date + aaitem;
  825.                         }
  826.                 }
  827.                 chew();
  828.         }
  829.         proutn("Make universe visible? ");
  830.         if (ja() != 0) {
  831.                 int i, j;
  832.                 for (i = 1; i < 9; i++)
  833.                 {
  834.                         for (j = 1; j < 9; j++)
  835.                         {
  836.                                 starch[i][j] = 1;
  837.                         }
  838.                 }
  839.         }
  840. }
  841.                        
  842.  
  843. #endif
  844.