X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.c;h=23e10016f42312fd7c8994f33b0ecffe3b5f9f58;hp=07b7da5cef805bca47a59a279237eee70611f9c1;hb=8b0a1880ee115e281afe83e1cd0c90e3306dfed8;hpb=a8f5216ff30142b93e4ff3e9bc12535ed0792563 diff --git a/sst.c b/sst.c index 07b7da5..23e1001 100644 --- a/sst.c +++ b/sst.c @@ -2,7 +2,6 @@ #include #include #include -#include "conio.h" #include "sstlinux.h" #include "sst.h" @@ -10,8 +9,6 @@ #define SSTDOC "sst.doc" #endif -static char line[128], *linep = line; - /* Here are Tom Almy's changes: @@ -90,59 +87,73 @@ Here are Stas Sergeev's changes: Eric Raymond's changes: + Mainly, I translated this C code out of FORTRAN into C -- created #defines + for a lot of magic numbers. + 1. "sos" and "call" becomes "mayday", "freeze" and "save" are both good. + 2. Status report now indicates when dilithium crystals are on board. + + 3. Can now report starbases left in scrscan. + */ +/* the input queue */ +static char line[128], *linep = line; +static int usecurses = TRUE; + static struct { char *name; int value; } commands[] = { -#define SRSCAN 1 +#define SRSCAN 0 {"SRSCAN", SRSCAN}, - {"STATUS", SRSCAN}, -#define LRSCAN 2 +#define STATUS 1 + {"STATUS", STATUS}, +#define REQUEST 2 + {"REQUEST", REQUEST}, +#define LRSCAN 3 {"LRSCAN", LRSCAN}, -#define PHASERS 3 +#define PHASERS 4 {"PHASERS", PHASERS}, -#define TORPEDO 4 +#define TORPEDO 5 {"TORPEDO", TORPEDO}, {"PHOTONS", TORPEDO}, -#define MOVE 5 +#define MOVE 6 {"MOVE", MOVE}, -#define SHIELDS 6 +#define SHIELDS 7 {"SHIELDS", SHIELDS}, -#define DOCK 7 +#define DOCK 8 {"DOCK", DOCK}, -#define DAMAGES 8 +#define DAMAGES 9 {"DAMAGES", DAMAGES}, -#define CHART 9 +#define CHART 10 {"CHART", CHART}, -#define IMPULSE 10 +#define IMPULSE 11 {"IMPULSE", IMPULSE}, -#define REST 11 +#define REST 12 {"REST", REST}, -#define WARP 12 +#define WARP 13 {"WARP", WARP}, -#define SCORE 13 +#define SCORE 14 {"SCORE", SCORE}, -#define SENSORS 14 +#define SENSORS 15 {"SENSORS", SENSORS}, -#define ORBIT 15 +#define ORBIT 16 {"ORBIT", ORBIT}, -#define TRANSPORT 16 +#define TRANSPORT 17 {"TRANSPORT", TRANSPORT}, -#define MINE 17 +#define MINE 18 {"MINE", MINE}, -#define CRYSTALS 18 +#define CRYSTALS 19 {"CRYSTALS", CRYSTALS}, -#define SHUTTLE 19 +#define SHUTTLE 20 {"SHUTTLE", SHUTTLE}, -#define PLANETS 20 +#define PLANETS 21 {"PLANETS", PLANETS}, -#define REPORT 21 +#define REPORT 22 {"REPORT", REPORT}, #define COMPUTER 23 {"COMPUTER", COMPUTER}, @@ -157,9 +168,9 @@ commands[] = { {"FREEZE", SAVE}, #define ABANDON 28 {"ABANDON", ABANDON}, -#define DESTRUCT 29 +#define DESTRUCT 29 {"DESTRUCT", DESTRUCT}, -#define DEATHRAY 30 +#define DEATHRAY 30 {"DEATHRAY", DEATHRAY}, #define DEBUGCMD 31 {"DEBUG", DEBUGCMD}, @@ -175,13 +186,16 @@ commands[] = { #define NUMCOMMANDS sizeof(commands)/sizeof(commands[0]) -static void listCommands(int x) { - int i; - prout("LEGAL COMMANDS ARE:"); - for (i = 0; i < NUMCOMMANDS; i++) { - proutn("%-12s ", commands[i].name); - if (i % 5 == 4) +#define MIN_CURSES_COMMAND PHASERS /* might change someday */ + +static void listCommands(int usecurses) { + int i, k = 0; + proutn("LEGAL COMMANDS ARE:"); + for (i = usecurses ? MIN_CURSES_COMMAND : 0; i < NUMCOMMANDS; i++) { + if (k % 5 == 0) skip(1); + proutn("%-12s ", commands[i].name); + k++; } skip(1); } @@ -196,11 +210,11 @@ static void helpme(void) { key = scan(); while (TRUE) { if (key == IHEOL) { - setwnd(BOTTOM_WINDOW); + setwnd(prompt_window); proutn("Help on what command? "); key = scan(); } - setwnd(LOWER_WINDOW); + setwnd(message_window); if (key == IHEOL) return; for (i = 0; i < NUMCOMMANDS; i++) { if (strcasecmp(commands[i].name, citem)==0) { @@ -211,7 +225,7 @@ static void helpme(void) { if (i != NUMCOMMANDS) break; skip(1); prout("Valid commands:"); - listCommands(FALSE); + listCommands(usecurses); key = IHEOL; chew(); skip(1); @@ -256,15 +270,19 @@ static void helpme(void) { while (fgets(linebuf, sizeof(linebuf),fp)) { if (strstr(linebuf, "******")) break; - proutc(linebuf); + proutn(linebuf); } fclose(fp); } +void enqueue(char *s) { + strcpy(line, s); +} + static void makemoves(void) { int i, hitme; clrscr(); - setwnd(LOWER_WINDOW); + setwnd(message_window); while (TRUE) { /* command loop */ drawmaps(1); while (TRUE) { /* get a command */ @@ -273,7 +291,7 @@ static void makemoves(void) { Time = 0.0; i = -1; chew(); - setwnd(BOTTOM_WINDOW); + setwnd(prompt_window); clrscr(); proutn("COMMAND> "); if (scan() == IHEOL) { @@ -282,7 +300,7 @@ static void makemoves(void) { } ididit=0; clrscr(); - setwnd(LOWER_WINDOW); + setwnd(message_window); clrscr(); for (i=0; i < ABANDON; i++) if (isit(commands[i].name)) { @@ -296,14 +314,19 @@ static void makemoves(void) { break; } if (i < NUMCOMMANDS) break; - - listCommands(TRUE); + listCommands(usecurses); } commandhook(commands[i].name, TRUE); switch (i) { /* command switch */ case SRSCAN: // srscan - srscan(1); + srscan(SCAN_FULL); break; + case STATUS: // status + srscan(SCAN_STATUS); + break; + case REQUEST: // status request + srscan(SCAN_REQUEST); + break; case LRSCAN: // lrscan lrscan(); break; @@ -380,7 +403,7 @@ static void makemoves(void) { eta(); break; case COMMANDS: - listCommands(TRUE); + listCommands(usecurses); break; case EMEXIT: // Emergency exit clrscr(); // Hide screen @@ -400,7 +423,7 @@ static void makemoves(void) { case SAVE: // Save Game freeze(FALSE); clrscr(); - if (skill > 3) + if (skill > SKILL_GOOD) prout("WARNING--Saved games produce no plaques!"); break; case DEATHRAY: // Try a desparation measure @@ -436,14 +459,14 @@ static void makemoves(void) { events(); if (alldone) break; // Events did us in } - if (game.state.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! + if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) { // Galaxy went Nova! atover(0); continue; } if (hitme && justin==0) { attack(2); if (alldone) break; - if (game.state.galaxy[quadx][quady] == 1000) { // went NOVA! + if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) { // went NOVA! atover(0); hitme = TRUE; continue; @@ -457,7 +480,7 @@ static void makemoves(void) { int main(int argc, char **argv) { - int i, option, usecurses = TRUE; + int i, option; while ((option = getopt(argc, argv, "t")) != -1) { switch (option) { @@ -479,6 +502,8 @@ int main(int argc, char **argv) { strcat(line, " "); } while (TRUE) { /* Play a game */ + setwnd(fullscreen_window); + clrscr(); prelim(); setup(line[0] == '\0'); if (alldone) { @@ -499,11 +524,8 @@ int main(int argc, char **argv) { } proutn("Do you want to play again? "); if (!ja()) break; - setwnd(FULLSCREEN_WINDOW); - clrscr(); } skip(1); - ioend(); prout("May the Great Bird of the Galaxy roost upon your home planet."); return 0; } @@ -569,14 +591,9 @@ double Rand(void) { return rand()/(1.0 + (double)RAND_MAX); } -void iran8(int *i, int *j) { - *i = Rand()*8.0 + 1.0; - *j = Rand()*8.0 + 1.0; -} - -void iran10(int *i, int *j) { - *i = Rand()*10.0 + 1.0; - *j = Rand()*10.0 + 1.0; +void iran(int size, int *i, int *j) { + *i = Rand()*(size*1.0) + 1.0; + *j = Rand()*(size*1.0) + 1.0; } void chew(void) { @@ -606,9 +623,9 @@ int scan(void) { } cgetline(line, sizeof(line)); fflush(stdin); - if (curwnd==BOTTOM_WINDOW){ + if (curwnd==prompt_window){ clrscr(); - setwnd(LOWER_WINDOW); + setwnd(message_window); clrscr(); } linep = line;