From cf91699c89b88f76dcf63c60624635184e8cb7eb Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 19 Jan 2005 03:45:27 +0000 Subject: [PATCH] First round of changes from Stas Sergeev. 1. The Space Thingy can now be shoved. 2. Black holes are not instant death any more, one has a chance of getting timewarped. Various small code cleanups are included. --- ai.c | 42 ++++--- battle.c | 67 +++++++---- conio.c | 326 +++++++++++++++++++++++++++++++++++++++++++++++++++++ conio.h | 103 +++++++++++++++++ events.c | 30 +++-- finish.c | 2 +- io.c | 6 +- moving.c | 50 +++++--- planets.c | 2 +- reports.c | 27 +++-- setup.c | 89 +++++++++------ sst.c | 7 +- sst.h | 18 ++- sstlinux.c | 32 ++++++ sstlinux.h | 13 +++ 15 files changed, 681 insertions(+), 133 deletions(-) create mode 100644 conio.c create mode 100644 conio.h create mode 100644 sstlinux.c create mode 100644 sstlinux.h diff --git a/ai.c b/ai.c index 3deab68..ba970a3 100644 --- a/ai.c +++ b/ai.c @@ -24,12 +24,12 @@ static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) { We know this if either short or long range sensors are working */ if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 || condit == IHDOCKED) { - proutn("***"); - cramen(ienm); + crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]); proutn(" escapes to %s (and regains strength).", cramlc(quadrant, iqx, iqy)); } /* handle local matters related to escape */ + game.quad[game.kx[loccom]][game.ky[loccom]] = IHDOT; game.kx[loccom] = game.kx[nenhere]; game.ky[loccom] = game.ky[nenhere]; game.kavgd[loccom] = game.kavgd[nenhere]; @@ -181,7 +181,6 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (my != 0) my = my*motion < 0 ? -1 : 1; nextx = comx; nexty = comy; - game.quad[comx][comy] = IHDOT; /* main move loop */ for (ll = 1; ll <= nsteps; ll++) { #ifdef DEBUG @@ -242,6 +241,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { else break; /* done early */ } /* Put commander in place within same quadrant */ + game.quad[comx][comy] = IHDOT; game.quad[nextx][nexty] = ienm; if (nextx != comx || nexty != comy) { /* it moved */ @@ -252,6 +252,8 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) { proutn("***"); cramen(ienm); + proutn(" from"); + cramlc(2, comx, comy); if (game.kdist[loccom] < dist1) proutn(" advances to"); else proutn(" retreats to "); prout(cramlc(sector, nextx, nexty)); @@ -297,8 +299,8 @@ void movcom(void) { sortkl(); } -static int checkdest(int iqx, int iqy, int flag, int *ipage) { - int i, j; +static int movescom(int iqx, int iqy, int flag, int *ipage) { + int i; if ((iqx==quadx && iqy==quady) || iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 || @@ -308,13 +310,13 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { for (i = 1; i <= game.state.rembase; i++) if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1; } - + if (justin && !iscate) return 1; /* do the move */ game.state.galaxy[game.state.isx][game.state.isy] -= 100; game.state.isx = iqx; game.state.isy = iqy; game.state.galaxy[game.state.isx][game.state.isy] += 100; - if (iscate) { + if (ishere) { /* SC has scooted, Remove him from current quadrant */ iscate=0; isatb=0; @@ -342,7 +344,7 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { DESTROY(&game.state.plnets[i]); game.state.newstuf[game.state.isx][game.state.isy] -= 1; if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) { - if (*ipage==0) pause(1); + if (*ipage==0) pause_game(1); *ipage = 1; prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports"); proutn(" a planet in "); @@ -458,32 +460,32 @@ void scom(int *ipage) { /* try moving in both x and y directions */ iqx = game.state.isx + ideltax; iqy = game.state.isy + ideltax; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { /* failed -- try some other maneuvers */ if (ideltax==0 || ideltay==0) { /* attempt angle move */ if (ideltax != 0) { iqy = game.state.isy + 1; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqy = game.state.isy - 1; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } else { iqx = game.state.isx + 1; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqx = game.state.isx - 1; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } } else { /* try moving just in x or y */ iqy = game.state.isy; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqy = game.state.isy + ideltay; iqx = game.state.isx; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } } @@ -500,11 +502,12 @@ void scom(int *ipage) { iseenit = 0; isatb=1; game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand(); - if (batx != 0) game.future[FSCDBAS] += game.future[FCDBAS]-game.state.date; + if (game.future[FCDBAS] < 1e30) game.future[FSCDBAS] += + game.future[FCDBAS]-game.state.date; if (game.damage[DRADIO] > 0 && condit != IHDOCKED) return; /* no warning */ iseenit = 1; - if (*ipage == 0) pause(1); + if (*ipage == 0) pause_game(1); *ipage=1; proutn("Lt. Uhura- \"Captain, the starbase in "); proutn(cramlc(quadrant, game.state.isx, game.state.isy)); @@ -529,7 +532,7 @@ void scom(int *ipage) { (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) || game.starch[game.state.isx][game.state.isy] > 0)) return; - if (*ipage==0) pause(1); + if (*ipage==0) pause_game(1); *ipage = 1; prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports"); proutn(" the Super-commander is in "); @@ -582,6 +585,8 @@ void movetho(void) { } } game.quad[ithx][ithy] = IHT; + game.kx[nenhere]=ithx; + game.ky[nenhere]=ithy; /* check to see if all holes plugged */ for (i = 1; i < 11; i++) { @@ -596,5 +601,6 @@ void movetho(void) { crmena(1,IHT, 2, ithx, ithy); prout(" completes web."); ithere = ithx = ithy = 0; + nenhere--; return; } diff --git a/battle.c b/battle.c index 5a29bb8..dd102aa 100644 --- a/battle.c +++ b/battle.c @@ -124,6 +124,7 @@ void doshield(int i) { shield += aaitem; energy -= aaitem; return; + case NONE:; /* avoid gcc warning */ } } @@ -142,6 +143,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) { case IHC: type = 2.0; break; case IHS: type = 2.5; break; case IHT: type = 0.5; break; + case IHQUEST: type = 4.0; break; } proutn(ibumpd ? " rammed by " : " rams "); crmena(0, ienm, 2, ix, iy); @@ -162,7 +164,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) { } shldup = 0; if (game.state.remkl) { - pause(2); + pause_game(2); dreprt(); } else finish(FWON); @@ -209,7 +211,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { *hit = fabs(*hit); newcnd(); /* undock */ /* We may be displaced. */ - if (landed==1) return; /* Cheat if on a planet */ + if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */ ang = angle + 2.5*(Rand()-0.5); temp = fabs(sin(ang)); if (fabs(cos(ang)) > temp) temp = fabs(cos(ang)); @@ -279,12 +281,13 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" damaged but not destroyed."); return; } - prout(" damaged--"); + proutn(" damaged--"); game.kx[ll] = jx; game.ky[ll] = jy; shoved = 1; break; case IHB: /* Hit a base */ + skip(1); prout("***STARBASE DESTROYED.."); if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0; for (ll=1; ll<=game.state.rembase; ll++) { @@ -324,16 +327,25 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" unaffected by photon blast."); return; case IHQUEST: /* Hit a thingy */ + if (Rand()>0.7) { // Used to be certain death skip(1); prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"); skip(1); prouts(" HACK! HACK! HACK! *CHOKE!* "); skip(1); proutn("Mr. Spock-"); - prouts(" \"Facinating!\""); + prouts(" \"Fascinating!\""); skip(1); - game.quad[ix][iy] = IHDOT; - return; + deadkl(ix, iy, iquad, ix, iy); + } else { + /* + * Stas Sergeev added the possibility that + * you can shove the Thingy. + */ + iqengry=1; + shoved=1; + } + return; case IHBLANK: /* Black hole */ skip(1); crmena(1, IHBLANK, 2, ix, iy); @@ -344,8 +356,6 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout("***Torpedo absorbed by Tholian web."); return; case IHT: /* Hit a Tholian */ - skip(1); - crmena(1, IHT, 2, ix, iy); h1 = 700.0 + 100.0*Rand() - 1000.0*sqrt(square(ix-inx)+square(iy-iny))* fabs(sin(bullseye-angle)); @@ -357,6 +367,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { ithx = ithy = 0; return; } + skip(1); + crmena(1, IHT, 2, ix, iy); if (Rand() > 0.05) { prout(" survives photon blast."); return; @@ -364,6 +376,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { prout(" disappears."); game.quad[ix][iy] = IHWEB; ithere = ithx = ithy = 0; + nenhere--; { int dum, my; dropin(IHBLANK, &dum, &my); @@ -395,7 +408,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { static void fry(double hit) { double ncrit, extradm; - int ktr=1, l, ll, j, cdam[6], crptr; + int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr; /* a critical hit occured */ if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return; @@ -403,7 +416,7 @@ static void fry(double hit) { ncrit = 1.0 + hit/(500.0+100.0*Rand()); proutn("***CRITICAL HIT--"); /* Select devices and cause damage */ - for (l = 1; l <= ncrit; l++) { + for (l = 1; l <= ncrit && l <= NDEVICES; l++) { do { j = NDEVICES*Rand()+1.0; /* Cheat to prevent shuttle damage unless on ship */ @@ -447,8 +460,8 @@ void attack(int k) { neutz = 0; return; } - if (((comhere || ishere) && (justin == 0)) || skill == 5) movcom(); - if (nenhere==0) return; + if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom(); + if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return; pfac = 1.0/inshld; if (shldchg == 1) chgfac = 0.25+0.5*Rand(); skip(1); @@ -463,10 +476,12 @@ void attack(int k) { jx = game.kx[l]; jy = game.ky[l]; iquad = game.quad[jx][jy]; + if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue; itflag = (iquad == IHK && r > 0.0005) || k == 0 || (iquad==IHC && r > 0.015) || (iquad==IHR && r > 0.3) || - (iquad==IHS && r > 0.07); + (iquad==IHS && r > 0.07) || + (iquad==IHQUEST && r > 0.05); if (itflag) { /* Enemy uses phasers */ if (condit == IHDOCKED) continue; /* Don't waste the effort! */ @@ -484,7 +499,7 @@ void attack(int k) { crmena(0, iquad, i, jx, jy); } attempt = 1; - prout("--"); + prout(" "); r = (Rand()+Rand())*0.5 -0.5; r += 0.002*game.kpower[l]*r; torpedo(course, r, jx, jy, &hit); @@ -493,9 +508,9 @@ void attack(int k) { alldone) return; /* Supernova or finished */ if (hit == 0) continue; } - if (shldup != 0 || shldchg != 0) { + if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) { /* shields will take hits */ - double absorb, hitsh, propor = pfac*shield; + double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0); if(propor < 0.1) propor = 0.1; hitsh = propor*chgfac*hit+1.0; atackd=1; @@ -584,6 +599,10 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { /* Killed a Tholian */ ithere = 0; } + else if (type == IHQUEST) { + /* Killed a Thingy */ + iqhere=iqengry=thingx=thingy=0; + } else { /* Some type of a Klingon */ game.state.galaxy[quadx][quady] -= 100; @@ -622,10 +641,9 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom); - if (type == IHT) return; - /* Remove enemy ship from arrays describing local conditions */ - + if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC) + game.future[FCDBAS] = 1e30; for (i=1; i<=nenhere; i++) if (game.kx[i]==ix && game.ky[i]==iy) break; nenhere--; @@ -658,7 +676,7 @@ static int targetcheck(double x, double y, double *course) { skip(1); prout("Spock- \"Bridge to sickbay. Dr. McCoy,"); prout(" I recommend an immediate review of"); - prout(" the Captain's psychological profile."); + prout(" the Captain's psychological profile.\""); chew(); return 1; } @@ -704,6 +722,7 @@ void photon(void) { chew(); prout("Maximum of 3 torpedoes per burst."); key = IHEOL; + return; } if (n <= torps) break; chew(); @@ -856,7 +875,7 @@ void phasers(void) { int kz = 0, k=1, i; /* Cheating inhibitor */ int ifast=0, no=0, ipoop=1, msgflag = 1; enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET; - int key; + int key=0; skip(1); /* SR sensors and Computer */ @@ -953,7 +972,7 @@ void phasers(void) { key = scan(); } if (key != IHREAL && nenhere != 0) { - prout("Phasers locked on target. Energy available = %.2f", ifast?energy-200.0:energy); + prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy); } do { while (key != IHREAL) { @@ -1081,7 +1100,6 @@ void phasers(void) { } if (aaitem < 0) { /* abort out */ - ididit = 0; chew(); return; } @@ -1106,7 +1124,7 @@ void phasers(void) { chew(); return; } - if (key == IHALPHA & isit("no")) { + if (key == IHALPHA && isit("no")) { no = 1; } energy -= rpow; @@ -1161,6 +1179,7 @@ void hittem(double *hits) { else proutn("Very small hit on "); ienm = game.quad[ii][jj]; + if (ienm==IHQUEST) iqengry=1; crmena(0,ienm,2,ii,jj); skip(1); if (kpow == 0) { diff --git a/conio.c b/conio.c new file mode 100644 index 0000000..adf42e5 --- /dev/null +++ b/conio.c @@ -0,0 +1,326 @@ +/**************************************************************************** + * This is the implementation file for conio.h - a conio.h for Linux. * + * It uses ncurses and some internal functions of Linux to simulate the * + * I/O-functions. * + * This is copyright (c) 1996,97 by Fractor / Mental eXPlosion (MXP) * + * Use and distribution is only allowed if you follow the terms of the * + * GNU Library Public License Version 2. * + * Since this work is based on ncurses please read its copyright notices as * + * well ! * + * Look into the readme to this file for further information. * + * Thanx to SubZero / MXP for his little tutorial on the curses library ! * + * Many thanks to Mark Hahn and Rich Cochran for solving the inpw and inpd * + * mega-bug !!! * + * Watch out for other MXP releases, too ! * + * Send bugreports to: fractor@germanymail.com * + ****************************************************************************/ + +#define _ISOC99_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include "conio.h" + +static attr_t txtattr,oldattr; +static int fgc,bgc; +char color_warning=1; +int directvideo; +WINDOW *conio_scr; + +/* Some internals... */ +static int colortab(int a) /* convert LINUX Color code to DOS-standard */ +{ + switch(a) { + case 0 : return COLOR_BLACK; + case 1 : return COLOR_BLUE; + case 2 : return COLOR_GREEN; + case 3 : return COLOR_CYAN; + case 4 : return COLOR_RED; + case 5 : return COLOR_MAGENTA; + case 6 : return COLOR_YELLOW; + case 7 : return COLOR_WHITE; + } + return COLOR_BLACK; +} + +static void docolor (int color) /* Set DOS-like text mode colors */ +{ + wattrset(conio_scr,0); /* My curses-version needs this ... */ + if ((color&128)==128) txtattr=A_BLINK; else txtattr=A_NORMAL; + if ((color&15)>7) txtattr|=A_STANDOUT; else txtattr|=A_NORMAL; + txtattr|=COLOR_PAIR((1+(color&7)+(color&112)) >> 1); + if (((color&127)==15) | ((color&127)==7)) txtattr=COLOR_PAIR(0); + if (((color&127)==127) | ((color&127)==119)) txtattr=COLOR_PAIR(8); + wattron(conio_scr,txtattr); + wattron(conio_scr,COLOR_PAIR(1+(color&7)+((color&112)>>1))); +} + +/* Call this before any call to linux conio - except the port functions ! */ +void __attribute__((constructor)) initconio (void) /* This is needed, because ncurses needs to be initialized */ +{ + int x,y; + short pair; + if (atexit(doneconio)){ + fprintf(stderr,"Unable to register doneconio(), exiting...\n"); + exit(1); + } + initscr(); + start_color(); +// attr_get(&oldattr,&pair,NULL); + nonl(); + raw(); + if (!has_colors() & (color_warning>-1)) + fprintf(stderr,"Attention: A color terminal may be required to run this application !\n"); + noecho(); + conio_scr=newwin(0,0,0,0); + keypad(conio_scr,TRUE); + meta(conio_scr,TRUE); + idlok(conio_scr,TRUE); + scrollok(conio_scr,TRUE); + /* Color initialization */ + for (y=0;y<=7;y++) + for (x=0;x<=7;x++) + init_pair((8*y)+x+1, colortab(x), colortab(y)); + wattr_get(conio_scr,&txtattr,&pair,NULL); + bgc=0; + textcolor(7); + textbackground(0); +} + +/* Call this on exiting your program */ +void doneconio (void) +{ + endwin(); +} + +/* Here it starts... */ +void _setcursortype (int cur_t) +{ + curs_set(cur_t); + wrefresh(conio_scr); +} + +char *cgets (char *str) /* ugly function :-( */ +{ + char strng[257]; + unsigned char i=2; + echo(); + strncpy(strng,str,1); + wgetnstr(conio_scr,&strng[2],(int) strng[0]); + while (strng[i]!=0) i++; + i=i-2; + strng[1]=i; + memcpy(str,strng,i+3); + noecho(); + return(&str[2]); +} + +void clreol (void) +{ + wclrtoeol(conio_scr); + wrefresh(conio_scr); +} + +void clrscr (void) +{ + wclear(conio_scr); + wmove(conio_scr,0,0); + wrefresh(conio_scr); +} + +int cprintf (char *format, ... ) +{ + int i; + char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */ + va_list argp; + va_start(argp,format); + vsprintf(buffer,format,argp); + va_end(argp); + i=waddstr(conio_scr,buffer); + wrefresh(conio_scr); + return(i); +} + +void cputs (char *str) +{ + waddstr(conio_scr,str); + wrefresh(conio_scr); +} + +int cscanf (const char *format, ...) +{ + int i; + char buffer[BUFSIZ]; /* See cprintf */ + va_list argp; + echo(); + if (wgetstr(conio_scr,buffer)==ERR) return(-1); + va_start(argp,format); + i=vsscanf(buffer,format,argp); + va_end(argp); + noecho(); + return(i); +} + +void delline (void) +{ + wdeleteln(conio_scr); + wrefresh(conio_scr); +} + +int getche (void) +{ + int i; + echo(); + i=wgetch(conio_scr); + if (i==-1) i=0; + noecho(); + return(i); +} + +void gettextinfo(struct text_info *inforec) +{ + short pair; + unsigned char xp,yp; + unsigned char x1,x2,y1,y2; + attr_t dattr,dnattr,a; /* The "d" stands for DOS */ + getyx(conio_scr,yp,xp); + getbegyx(conio_scr,y1,x1); + getmaxyx(conio_scr,y2,x2); + dattr=(bgc*16)+fgc; + wattr_get(conio_scr,&a,&pair,NULL); + if (a==(a & A_BLINK)) dattr=dattr+128; + dnattr=oldattr; /* Well, this cannot be right, + because we don't know the COLORPAIR values from before initconio() !*/ + inforec->winleft=x1+1; + inforec->wintop=y1+1; + if (x1==0) x2--; + if (y1==0) y2--; + inforec->winright=x1+x2+1; + inforec->winbottom=y1+y2+1; + inforec->curx=xp+1; + inforec->cury=yp+1; + inforec->screenheight=y2+1; + inforec->screenwidth=x2+1; + inforec->currmode=3; /* This is C80 */ + inforec->normattr=dnattr; /* Don't use this ! */ + inforec->attribute=dattr; +} + +void gotoxy (int x, int y) +{ + y--; + x--; + wmove(conio_scr,y,x); + wrefresh(conio_scr); +} + +void highvideo (void) +{ + textcolor(15); /* White */ + textbackground(0); /* Black */ +} + +void insline (void) +{ + winsertln(conio_scr); + wrefresh(conio_scr); +} + +int kbhit (void) +{ + int i; + nodelay(conio_scr,TRUE); + i=wgetch(conio_scr); + nodelay(conio_scr,FALSE); + if (i==-1) i=0; + return(i); +} + +void lowvideo (void) +{ + textbackground(0); /* Black */ + textcolor(8); /* Should be darkgray */ +} + +void normvideo (void) +{ + wattrset(conio_scr,oldattr); +} + +int putch (int c) +{ + if (waddch(conio_scr,c)!=ERR) { + wrefresh(conio_scr); + return(c); + } + return(0); +} + +void textattr (int attr) +{ + docolor(attr); +} + +void textbackground (int color) +{ + bgc=color; + color=(bgc*16)+fgc; + docolor(color); +} + +void textcolor (int color) +{ + fgc=color; + color=(bgc*16)+fgc; + docolor(color); +} + +void textmode (int mode) +{ + /* Ignored */ +} + +int wherex (void) +{ + int y; + int x; + getyx(conio_scr,y,x); + x++; + return(x); +} + +int wherey (void) +{ + int y; + int x; + getyx(conio_scr,y,x); + y++; + return(y); +} + +void window (int left,int top,int right,int bottom) +{ + int nlines,ncols; + delwin(conio_scr); + top--; + left--; + right--; + bottom--; + nlines=bottom-top; + ncols=right-left; + if (top==0) nlines++; + if (left==0) ncols++; + if ((nlines<1) | (ncols<1)) return; + conio_scr=newwin(nlines,ncols,top,left); + keypad(conio_scr,TRUE); + meta(conio_scr,TRUE); + idlok(conio_scr,TRUE); + scrollok(conio_scr,TRUE); + wrefresh(conio_scr); +} + +/* Linux is cool */ diff --git a/conio.h b/conio.h new file mode 100644 index 0000000..1b28c2e --- /dev/null +++ b/conio.h @@ -0,0 +1,103 @@ +/***************************************************************************/ +/** File: conio.h Date: 03/09/1997 Version: 1.02 **/ +/** --------------------------------------------------------------------- **/ +/** CONIO.H an implementation of the conio.h for Linux based on ncurses. **/ +/** This is copyright (c) 1996,97 by Fractor / Mental EXPlosion. **/ +/** If you want to copy it you must do this following the terms of the **/ +/** GNU Library Public License **/ +/** Please read the file "README" before using this library. **/ +/** --------------------------------------------------------------------- **/ +/** To use this thing you must have got the curses library. **/ +/** This thing was tested on Linux Kernel 2.0.29, GCC 2.7.2 and **/ +/** ncurses 1.9.9e which is (c) 1992-1995 by Zeyd M. Ben-Halim and Eric S.**/ +/** Raymond. **/ +/** Please also read the copyright notices for ncurses before using this !**/ +/***************************************************************************/ + +#ifndef __linux__ +#error This conio.h was only tested to work under LINUX ! +#endif + +#ifndef __LINUXCONIO_H +#define __LINUXCONIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define linux_conio_version 1.04 + +extern int directvideo; /* ignored by linux conio.h */ +extern char color_warning; /* Tell the users when terminal can't display colors ? */ +extern WINDOW *conio_scr; + +#define _NOCURSOR 0 +#define _NORMALCURSOR 1 + +struct text_info { + unsigned char winleft; + unsigned char wintop; + unsigned char winright; + unsigned char winbottom; + unsigned char attribute; + unsigned char normattr; + unsigned char currmode; + unsigned char screenheight; + unsigned char screenwidth; + unsigned char curx; + unsigned char cury; +}; + +enum text_modes { LASTMODE=-1, BW40=0, C40, BW80, C80, MONO=7, C4350=64 }; + +enum COLORS { + BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, + DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE +}; + +#define BLINK 128 + +extern void initconio(void); /* Please run this function before any other */ +extern void doneconio(void); /* Please run this function before exiting your program */ + +extern int wherex(void); +extern int wherey(void); +extern int putch(int c); +extern int getche(void); +extern int kbhit(void); +extern void _setcursortype(int); +extern int cprintf(char *format, ...); +extern int cscanf(const char *format, ...); + +extern unsigned inp(unsigned port); +extern unsigned inpw(unsigned port); +extern unsigned outp(unsigned port, unsigned value); +extern unsigned outpw(unsigned port,unsigned value); +extern unsigned inpd(unsigned port); +extern unsigned outpd(unsigned port, unsigned value); + +extern void clreol(void); +extern void clrscr(void); +extern void gotoxy(int x, int y); +extern void delline(void); +extern void gettextinfo(struct text_info *r); +extern void highvideo(void); +extern void insline(void); +extern void lowvideo(void); +extern void normvideo(void); +extern void textattr(int attribute); +extern void textbackground(int color); +extern void textcolor(int color); +extern void textmode(int unused_mode); +extern void window(int left, int top, int right, int bottom); +extern void cputs(char *str); + +extern char *cgets(char *str); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/events.c b/events.c index 940ad7b..194901d 100644 --- a/events.c +++ b/events.c @@ -2,10 +2,8 @@ #include void events(void) { - - int ictbeam=0, ipage=0, istract=0, line, i, j, k, l, ixhold, iyhold; - double fintim = game.state.date + Time, datemin, xtime, repair, yank; - + int ictbeam=0, ipage=0, istract=0, line, i=0, j, k, l, ixhold=0, iyhold=0; + double fintim = game.state.date + Time, datemin, xtime, repair, yank=0; #ifdef DEBUG if (idebug) prout("EVENTS"); @@ -25,7 +23,7 @@ void events(void) { if (alldone) return; datemin = fintim; for (l=1; l<=NEVENTS; l++) - if (game.future[l] <= datemin) { + if (game.future[l] < datemin) { line = l; datemin = game.future[l]; } @@ -64,7 +62,7 @@ void events(void) { for (j=1; j <= 8; j++) if (game.starch[i][j] > 999) game.starch[i][j] = 1; if (iseenit==0) { - attakreport(); + attakreport(0); iseenit = 1; } skip(1); @@ -75,7 +73,7 @@ void events(void) { Time -= xtime; switch (line) { case FSNOVA: /* Supernova */ - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage=1; snova(0,0); game.future[FSNOVA] = game.state.date + expran(0.5*intime); @@ -114,7 +112,7 @@ void events(void) { } /* tractor beaming cases merge here */ yank = sqrt(yank); - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage=1; Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */ ictbeam = 1; @@ -170,6 +168,7 @@ void events(void) { newqad(0); /* Adjust finish time to time of tractor beaming */ fintim = game.state.date+Time; + attack(0); if (game.state.remcom <= 0) game.future[FTBEAM] = 1e30; else game.future[FTBEAM] = game.state.date+Time+expran(1.5*intime/game.state.remcom); break; @@ -212,12 +211,12 @@ void events(void) { if (game.damage[DRADIO] != 0.0 && condit != IHDOCKED) break; /* No warning :-( */ iseenit = 1; - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage = 1; skip(1); proutn("Lt. Uhura- \"Captain, the starbase in "); prout(cramlc(quadrant, batx, baty)); - prout(" reports that it is under atttack and that it can"); + prout(" reports that it is under attack and that it can"); proutn(" hold out only until stardate %d", (int)game.future[FCDBAS]); prout(".\""); @@ -267,7 +266,7 @@ void events(void) { else if (game.state.rembase != 1 && (game.damage[DRADIO] <= 0.0 || condit == IHDOCKED)) { /* Get word via subspace radio */ - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage = 1; skip(1); prout("Lt. Uhura- \"Captain, Starfleet Command reports that"); @@ -314,7 +313,7 @@ void events(void) { game.state.galaxy[probecx][probecy] == 1000) { // Left galaxy or ran into supernova if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) { - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage = 1; skip(1); proutn("Lt. Uhura- \"The deep space probe "); @@ -328,7 +327,7 @@ void events(void) { break; } if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) { - if (ipage==0) pause(1); + if (ipage==0) pause_game(1); ipage = 1; skip(1); proutn("Lt. Uhura- \"The deep space probe is now in "); @@ -373,7 +372,7 @@ void wait(void) { origTime = delay = aaitem; if (delay <= 0.0) return; if (delay >= game.state.remtime || nenhere != 0) { - prout("Are you sure? "); + proutn("Are you sure? "); if (ja() == 0) return; } @@ -394,7 +393,6 @@ void wait(void) { Time = temp; } if (Time < delay) attack(0); - if (nenhere==0) movetho(); if (alldone) return; events(); ididit = 1; @@ -412,7 +410,7 @@ void wait(void) { void nova(int ix, int iy) { static double course[] = {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5}; - int bot, top, top2, burst, hits[11][3], kount, icx, icy, mm, nn, j; + int bot, top, top2, hits[11][3], kount, icx, icy, mm, nn, j; int iquad, iquad1, i, ll, newcx, newcy, ii, jj; if (Rand() < 0.05) { /* Wow! We've supernova'ed */ diff --git a/finish.c b/finish.c index 7144086..8a8427a 100644 --- a/finish.c +++ b/finish.c @@ -307,7 +307,7 @@ void score(void) { double timused = game.state.date - indate; int ithperd, iwon, klship; - pause(0); + pause_game(0); iskill = skill; if ((timused == 0 || game.state.remkl != 0) && timused < 5.0) timused = 5.0; diff --git a/io.c b/io.c index a5ac6d9..81f1c8a 100644 --- a/io.c +++ b/io.c @@ -82,7 +82,7 @@ void clearscreen(void) { #endif } -void pause(int i) { +void pause_game(int i) { char buf[BUFSIZ], *prompt; if (i==1) { if (skill > 2) @@ -121,13 +121,13 @@ void skip(int i) { int y, x; getyx(stdscr, y, x); if (y == screenheight-1) - pause(0); + pause_game(0); else waddch(stdscr, '\n'); } else { linecount++; if (linecount >= screenheight) - pause(0); + pause_game(0); else putchar('\n'); } diff --git a/moving.c b/moving.c index 07eb148..ec7bc91 100644 --- a/moving.c +++ b/moving.c @@ -1,11 +1,12 @@ +#include #include "sst.h" static void getcd(int, int); void imove(void) { double angle, deltax, deltay, bigger, x, y, - finald, finalx, finaly, stopegy; - int trbeam = 0, n, l, ix, iy, kink, kinks, iquad; + finald, finalx, finaly, stopegy, probf; + int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad; if (inorbit) { prout("Helmsman Sulu- \"Leaving standard orbit.\""); @@ -98,11 +99,11 @@ void imove(void) { quady = (iy+9)/10; sectx = ix - 10*(quadx-1); secty = iy - 10*(quady-1); - prout(""); - prout("Entering %s.", + proutn("\n\rEntering %s.", cramlc(quadrant, quadx, quady)); game.quad[sectx][secty] = ship; newqad(0); + if (skill>1) attack(0); return; } iquad = game.quad[ix][iy]; @@ -117,6 +118,7 @@ void imove(void) { case IHC: case IHS: case IHR: + case IHQUEST: sectx = ix; secty = iy; ram(0, iquad, sectx, secty); @@ -131,7 +133,23 @@ void imove(void) { crmshp(); proutn(" pulled into black hole at "); prout(cramlc(sector, ix, iy)); - finish(FHOLE); + /* + * Getting pulled into a black + * hole was certain death in + * Almy's original. Stas + * Sergeev added a possibility + * that you'll get timewarped + * instead. + */ + n=0; + for (l=1;l<=NDEVICES+1;l++) + if (game.damage[l]>0) n++; + probf=pow(1.4,(energy+shield)/5000.0-1.0)* + pow(1.3,1.0/(n+1)-1.0); + if (Rand()>probf) + timwrp(); + else + finish(FHOLE); return; default: /* something else */ @@ -186,9 +204,9 @@ label100: return; } -void dock(void) { +void dock(int l) { chew(); - if (condit == IHDOCKED) { + if (condit == IHDOCKED && l) { prout("Already docked."); return; } @@ -211,7 +229,7 @@ void dock(void) { (game.future[FCDBAS] < 1e30 || isatb == 1) && iseenit == 0) { /* get attack report from base */ prout("Lt. Uhura- \"Captain, an important message from the starbase:\""); - attakreport(); + attakreport(0); iseenit = 1; } } @@ -226,7 +244,7 @@ static void getcd(int isprobe, int akey) { are always displayed y - x, where +y is downward! */ - int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key; + int irowq=quadx, icolq=quady, irows, icols, itemp=0, iprompt=0, key=0; double xi, xj, xk, xl; double deltax, deltay; int automatic = -1; @@ -443,7 +461,7 @@ void impuls(void) { if (Time >= game.state.remtime) { prout("First Officer Spock- \"Captain, our speed under impulse"); prout("power is only 0.95 sectors per stardate. Are you sure"); - prout("we dare spend the time?\""); + proutn("we dare spend the time?\" "); if (ja() == 0) return; } /* Activate impulse engines and pay the cost */ @@ -519,8 +537,8 @@ void warp(int i) { proutn(" a trip would require approximately %2.0f", 100.0*Time/game.state.remtime); prout(" percent of our"); - prout(" remaining time. Are you sure this is wise?\""); - if (ja() == 0) { ididit = 0; return;} + proutn(" remaining time. Are you sure this is wise?\" "); + if (ja() == 0) { ididit = 0; Time=0; return;} } } /* Entry WARPX */ @@ -600,7 +618,7 @@ void setwrp(void) { while ((key=scan()) == IHEOL) { chew(); - proutn("Warp factor-"); + proutn("Warp factor- "); } chew(); if (key != IHREAL) { @@ -628,7 +646,7 @@ void setwrp(void) { warpfac = aaitem; wfacsq=warpfac*warpfac; if (warpfac <= oldfac || warpfac <= 6.0) { - proutn("Helmsman Sulu- \"Warp factor %do, Captain.\"", + proutn("Helmsman Sulu- \"Warp factor %d, Captain.\"", (int)warpfac); return; } @@ -840,7 +858,7 @@ void probe(void) { key = scan(); } else if (key == IHEOL) { - proutn("Arm NOVAMAX warhead?"); + proutn("Arm NOVAMAX warhead? "); isarmed = ja(); } getcd(TRUE, key); @@ -945,7 +963,7 @@ void help(void) { sectx=ix; secty=iy; game.quad[ix][iy]=ship; - dock(); + dock(0); skip(1); prout("Lt. Uhura- \"Captain, we made it!\""); return; diff --git a/planets.c b/planets.c index a45879f..ecc3d60 100644 --- a/planets.c +++ b/planets.c @@ -412,7 +412,7 @@ void deathray(void) { } prout("Spock- \"Captain, the 'Experimental Death Ray'"); prout(" is highly unpredictible. Considering the alternatives,"); - prout(" are you sure this is wise?\" "); + proutn(" are you sure this is wise?\" "); if (ja()==0) return; prout("Spock- \"Acknowledged.\""); skip(1); diff --git a/reports.c b/reports.c index e398e77..794b181 100644 --- a/reports.c +++ b/reports.c @@ -3,9 +3,10 @@ #include #include -void attakreport(void) { +void attakreport(int l) { + if (!l) { if (game.future[FCDBAS] < 1e30) { - prout("Starbase in %s is currently under attack.", + prout("Starbase in %s is currently under Commander attack.", cramlc(quadrant, batx, baty)); prout("It can hold out until Stardate %d.", (int)game.future[FCDBAS]); @@ -16,6 +17,12 @@ void attakreport(void) { prout("It can hold out until Stardate %d.", (int)game.future[FSCDBAS]); } + } else { + if (game.future[FCDBAS] < 1e30) + proutn("Base in %i - %i attacked by C. Alive until %.1f", batx, baty, game.future[FCDBAS]); + if (isatb == 1) + proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.isx, game.state.isy, game.future[FSCDBAS]); + } } @@ -63,7 +70,7 @@ void report(int f) { if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) { /* Don't report this if not seen and either the radio is dead or not at base! */ - attakreport(); + attakreport(0); iseenit = 1; } if (casual) prout("%d casualt%s suffered so far.", @@ -89,7 +96,7 @@ void report(int f) { } if (icrystl) { if (cryprob <= .05) - prout("Dilithium crystals aboard ship...not yet used."); + prout("Dilithium crystals aboard ship... not yet used."); else { int i=0; double ai = 0.05; @@ -319,7 +326,7 @@ void srscan(int l) { proutn(" Klingons Left %d", game.state.remkl); break; case 10: - proutn(" Time Left %.2f", game.state.remtime); + attakreport(1); break; } @@ -363,11 +370,11 @@ void eta(void) { } ix2 = aaitem + 0.5; } - else { // same quadrant - ix2 = ix1; - iy2 = iy1; - ix1 = quady; // ya got me why x and y are reversed! - iy1 = quadx; + else { + if (quady>ix1) ix2 = 1; + else ix2=10; + if (quadx>iy1) iy2 = 1; + else iy2=10; } if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 || diff --git a/setup.c b/setup.c index 6497744..1d7dd01 100644 --- a/setup.c +++ b/setup.c @@ -45,10 +45,9 @@ void freeze(int boss) { } -void thaw(void) { - char *x, *y; +int thaw(void) { FILE *fp; - int key; + int key; game.passwd[0] = '\0'; if ((key = scan()) == IHEOL) { @@ -57,7 +56,7 @@ void thaw(void) { } if (key != IHALPHA) { huh(); - return; + return 1; } chew(); if (strchr(citem, '.') == NULL) { @@ -67,18 +66,19 @@ void thaw(void) { proutn("Can't find game file "); proutn(citem); skip(1); - return; + return 1; } fread(&game, sizeof(game), 1, fp); if (strcmp(game.magic, SSTMAGIC)) { prout("Game file format is bad, should begin with " SSTMAGIC); skip(1); - return; + fclose(fp); + return 1; } fclose(fp); - /* I hope that's enough! */ + return 0; } void abandn(void) { @@ -182,13 +182,13 @@ void abandn(void) { void setup(int needprompt) { int i,j, krem, klumper; int ix, iy; - alldone = gamewon = 0; #ifdef DEBUG idebug = 0; #endif // Decide how many of everything if (choose(needprompt)) return; // frozen game // Prepare the Enterprise + alldone = gamewon = 0; ship = IHE; energy = inenrg = 5000.0; shield = inshld = 2500.0; @@ -207,6 +207,7 @@ void setup(int needprompt) { game.state.date = indate = 100.0*(int)(31.0*Rand()+20.0); game.state.killk = game.state.killc = nkinks = nhelp = resting = casual = game.state.nromkl = 0; isatb = iscate = imine = icrystl = icraft = game.state.nsckill = game.state.nplankl = 0; + game.state.starkl = game.state.basekl = 0; iscraft = 1; landed = -1; alive = 1; @@ -328,7 +329,7 @@ void setup(int needprompt) { game.state.galaxy[ix][iy] += 100; } // Place thing (in tournament game, thingx == -1, don't want one!) - if (Rand() < 0.1 && thingx != -1) { + if (thingx != -1) { iran8(&thingx, &thingy); } else { @@ -336,7 +337,7 @@ void setup(int needprompt) { } // idate = date; - skip(3); + skip(2); game.state.snap = 0; if (skill == 1) { @@ -374,7 +375,7 @@ void setup(int needprompt) { prout("Good Luck!"); if (game.state.nscrem) prout(" YOU'LL NEED IT."); newqad(0); - if (nenhere) shldup=1.0; + if (nenhere-iqhere-ithere) shldup=1.0; if (neutz) attack(0); // bad luck to start in a Romulan Neutral Zone } @@ -515,6 +516,8 @@ void newqad(int shutup) { landed = -1; ientesc = 0; ithere = 0; + iqhere=0; + iqengry=0; iseenit = 0; if (iscate) { // Attempt to escape Super-commander, so tbeam back! @@ -536,27 +539,6 @@ void newqad(int shutup) { // Position Starship game.quad[sectx][secty] = ship; - // Decide if quadrant needs a Tholian - if ((skill < 3 && Rand() <= 0.02) || /* Lighten up if skill is low */ - (skill == 3 && Rand() <= 0.05) || - (skill > 3 && Rand() <= 0.08) -#ifdef DEBUG - || strcmp(game.passwd, "tholianx")==0 -#endif - ) { - do { - ithx = Rand() > 0.5 ? 10 : 1; - ithy = Rand() > 0.5 ? 10 : 1; - } while (game.quad[ithx][ithy] != IHDOT); - game.quad[ithx][ithy] = IHT; - ithere = 1; - /* Reserve unocupied corners */ - if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; - if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X'; - if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X'; - if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X'; - } - if (quadnum >= 100) { // Position ordinary Klingons quadnum -= 100*klhere; @@ -581,7 +563,7 @@ void newqad(int shutup) { if (quadx == game.state.isx && quady == game.state.isy) { game.quad[game.kx[1]][game.ky[1]] = IHS; game.kpower[1] = 1175.0 + 400.0*Rand() + 125.0*skill; - iscate = 1; + iscate = game.state.remkl>1; ishere = 1; } } @@ -615,7 +597,7 @@ void newqad(int shutup) { for (i = 1; i <= quadnum; i++) dropin(IHSTAR, &ix, &iy); // Check for RNZ - if (irhere > 0 && klhere == 0 && basex == 0) { + if (irhere > 0 && klhere == 0) { neutz = 1; if (game.damage[DRADIO] <= 0.0) { skip(1); @@ -631,7 +613,14 @@ void newqad(int shutup) { // Put in THING if needed if (thingx == quadx && thingy == quady) { dropin(IHQUEST, &ix, &iy); - thingx = thingy = 0; // Transient + iran8(&thingx, &thingy); + nenhere++; + iqhere=1; + game.kx[nenhere] = ix; + game.ky[nenhere] = iy; + game.kdist[nenhere] = game.kavgd[nenhere] = + sqrt(square(sectx-ix) + square(secty-iy)); + game.kpower[nenhere] = Rand()*6000.0 +500.0 +250.0*skill; if (game.damage[DSRSENS] == 0.0) { skip(1); prout("MR. SPOCK- \"Captain, this is most unusual."); @@ -640,6 +629,34 @@ void newqad(int shutup) { } } + // Decide if quadrant needs a Tholian + if ((skill < 3 && Rand() <= 0.02) || /* Lighten up if skill is low */ + (skill == 3 && Rand() <= 0.05) || + (skill > 3 && Rand() <= 0.08) +#ifdef DEBUG + || strcmp(passwd, "tholianx")==0 +#endif + ) { + do { + ithx = Rand() > 0.5 ? 10 : 1; + ithy = Rand() > 0.5 ? 10 : 1; + } while (game.quad[ithx][ithy] != IHDOT); + game.quad[ithx][ithy] = IHT; + ithere = 1; + nenhere++; + game.kx[nenhere] = ithx; + game.ky[nenhere] = ithy; + game.kdist[nenhere] = game.kavgd[nenhere] = + sqrt(square(sectx-ithx) + square(secty-ithy)); + game.kpower[nenhere] = Rand()*400.0 +100.0 +25.0*skill; + /* Reserve unocupied corners */ + if (game.quad[1][1]==IHDOT) game.quad[1][1] = 'X'; + if (game.quad[1][10]==IHDOT) game.quad[1][10] = 'X'; + if (game.quad[10][1]==IHDOT) game.quad[10][1] = 'X'; + if (game.quad[10][10]==IHDOT) game.quad[10][10] = 'X'; + } + sortkl(); + // Put in a few black holes for (i = 1; i <= 3; i++) if (Rand() > 0.5) dropin(IHBLANK, &ix, &iy); @@ -659,7 +676,7 @@ void sortkl(void) { // The author liked bubble sort. So we will use it. :-( - if (nenhere < 2) return; + if (nenhere-iqhere-ithere < 2) return; do { sw = FALSE; diff --git a/sst.c b/sst.c index ee80b3f..888b7ec 100644 --- a/sst.c +++ b/sst.c @@ -217,7 +217,8 @@ static void makemoves(void) { } break; case 6: // dock - dock(); + dock(1); + if (ididit) attack(0); break; case 7: // damages dreprt(); @@ -411,6 +412,7 @@ void cramen(int i) { case IHBLANK: s = "Black hole"; break; case IHT: s = "Tholian"; break; case IHWEB: s = "Tholian web"; break; + case IHQUEST: s = "Stranger"; break; default: s = "Unknown??"; break; } proutn(s); @@ -502,6 +504,7 @@ int scan(void) { } if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') { // treat as a number + i = 0; if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) { linep = line; // Invalid numbers are ignored *linep = 0; @@ -534,8 +537,6 @@ int ja(void) { } } -double square(double i) { return i*i; } - void huh(void) { chew(); skip(1); diff --git a/sst.h b/sst.h index 375e7aa..63ea4cf 100644 --- a/sst.h +++ b/sst.h @@ -131,6 +131,8 @@ EXTERN struct { batx, baty, ithere, + iqhere, + iqengry, ithx, ithy, iseenit, @@ -205,6 +207,8 @@ EXTERN struct { #define ishere game.ishere // Super-commander in quandrant #define neutz game.neutz // Romulan Neutral Zone #define irhere game.irhere // Romulans in quadrant +#define iqhere game.iqhere // Thing in quadrant +#define iqengry game.iqengry // Thing attacking #define icraft game.icraft // Kirk in Galileo #define ientesc game.ientesc // Attempted escape from supercommander #define iscraft game.iscraft // =1 if craft on ship, -1 if removed from game @@ -339,6 +343,10 @@ char *device[NDEVICES+1] = { #define IHYELLOW 'Y' #define IHRED 'R' #define IHDOCKED 'D' +#define IHDEAD 'Z' +#define IHMATER0 '-' +#define IHMATER1 'o' +#define IHMATER2 '0' /* Function prototypes */ @@ -354,7 +362,7 @@ void phasers(void); void photon(void); void warp(int); void doshield(int); -void dock(void); +void dock(int); void dreprt(void); void chart(int); void impuls(void); @@ -369,7 +377,7 @@ void finish(FINTYPE); void dstrct(void); void kaboom(void); void freeze(int); -void thaw(void); +int thaw(void); void plaque(void); int scan(void); #define IHEOL (0) @@ -390,7 +398,7 @@ double expran(double); double Rand(void); void iran8(int *, int *); void iran10(int *, int *); -double square(double); +#define square(i) ((i)*(i)) void dropin(int, int*, int*); void newcnd(void); void sortkl(void); @@ -402,7 +410,7 @@ void timwrp(void); void movcom(void); void torpedo(double, double, int, int, double *); void huh(void); -void pause(int); +void pause_game(int); void nova(int, int); void snova(int, int); void scom(int *); @@ -419,7 +427,7 @@ void usecrystals(void); void shuttle(void); void deathray(void); void debugme(void); -void attakreport(void); +void attakreport(int); void movetho(void); void probe(void); void clearscreen(void); diff --git a/sstlinux.c b/sstlinux.c new file mode 100644 index 0000000..b376b39 --- /dev/null +++ b/sstlinux.c @@ -0,0 +1,32 @@ +#include +#include + +#include +#include +#include +#include + +#include "sstlinux.h" + +static int fd = 0; + +int c_printf (char *format, ... ) +{ + char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */ + va_list argp; + va_start(argp,format); + vsprintf(buffer,format,argp); + va_end(argp); + return waddstr(conio_scr,buffer); +} + +void sound(unsigned int freq) +{ + if(fd==0) fd=open("/dev/console", O_RDONLY); + if(fd>0) ioctl(fd, KDMKTONE, 1193180/freq + (0xFFFF<<16)); +} + +void nosound(void) +{ + if(fd>0) ioctl(fd, KDMKTONE, 0); +} diff --git a/sstlinux.h b/sstlinux.h new file mode 100644 index 0000000..779f8eb --- /dev/null +++ b/sstlinux.h @@ -0,0 +1,13 @@ +#ifndef __SSTLINUX_H +#define __SSTLINUX_H + +int c_printf (char *format, ... ); +void sound(unsigned int); +void nosound(void); + +extern WINDOW *conio_scr; + +#define delay(x) usleep(x*1000) +#define randomize() srand((unsigned)time(NULL)) + +#endif -- 2.31.1