+#ifdef SERGEEV\r
+#include <conio.h>\r
+#include <unistd.h>\r
+#include "sstlinux.h"\r
+#endif /* SERGEEV */\r
#include "sst.h"\r
\r
void doshield(int i) {\r
return;\r
}\r
\r
-void torpedo(double course, double r, int inx, int iny, double *hit) {\r
- int l, iquad, ix, iy, jx, jy, shoved=0, ll;\r
+void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {\r
+ int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;\r
+#ifdef SERGEEV\r
+ int crx,cry;\r
+ \r
+#endif /* SERGEEV */\r
double ac=course + 0.25*r;\r
double angle = (15.0-ac)*0.5235988;\r
double bullseye = (15.0 - course)*0.5235988;\r
if (fabs(deltay) > bigger) bigger = fabs(deltay);\r
deltax /= bigger;\r
deltay /= bigger;\r
-\r
+#ifdef SERGEEV\r
+ crx=wherex();\r
+ cry=wherey();\r
+ if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(1);\r
+ else setwnd(4);\r
+#endif /* SERGEEV */\r
/* Loop to move a single torpedo */\r
for (l=1; l <= 15; l++) {\r
x += deltax;\r
y += deltay;\r
iy = y + 0.5;\r
if (iy < 1 || iy > 10) break;\r
+#ifndef SERGEEV\r
if (l==4 || l==9) skip(1);\r
proutn("%d - %d ", (int)x, (int)y);\r
iquad=game.quad[ix][iy];\r
+#else\r
+ iquad=game.quad[ix][iy];\r
+ if (game.damage[DSRSENS]==0 || condit==IHDOCKED){\r
+ drawmaps(2);\r
+ delay((wait!=1)*400);\r
+ wait=1;\r
+ gotoxy(iy*2+3,ix+2);\r
+ if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){\r
+ game.quad[ix][iy]='+';\r
+ drawmaps(2);\r
+ game.quad[ix][iy]=iquad;\r
+ sound(l*10);\r
+ delay(100);\r
+ nosound();\r
+ }\r
+ else {\r
+ game.quad[ix][iy]|=128;\r
+ drawmaps(2);\r
+ game.quad[ix][iy]=iquad;\r
+ _setcursortype(_NOCURSOR);\r
+ sound(500);\r
+ delay(1000);\r
+ nosound();\r
+ lowvideo();\r
+ _setcursortype(_NORMALCURSOR);\r
+ }\r
+ }\r
+ else {\r
+ proutn("%d - %d ", (int)x, (int)y);\r
+ }\r
+#endif /* SERGEEV */\r
if (iquad==IHDOT) continue;\r
/* hit something */\r
+#ifndef SERGEEV\r
skip(1);\r
+#else\r
+ setwnd(4);\r
+ gotoxy(crx,cry);\r
+#endif\r
switch(iquad) {\r
case IHE: /* Hit our ship */\r
case IHF:\r
1000.0*sqrt(square(ix-inx)+square(iy-iny))*\r
fabs(sin(bullseye-angle));\r
*hit = fabs(*hit);\r
+#ifndef SERGEEV\r
newcnd(); /* undock */\r
+#endif /* SERGEEV */\r
/* We may be displaced. */\r
if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */\r
ang = angle + 2.5*(Rand()-0.5);\r
fabs(sin(bullseye-angle));\r
h1 = fabs(h1);\r
if (h1 >= 600) {\r
+#ifndef SERGEEV\r
prout(" destroyed.");\r
+#endif /* SERGEEV */\r
game.quad[ix][iy] = IHDOT;\r
ithere = 0;\r
ithx = ithy = 0;\r
+#ifdef SERGEEV\r
+ deadkl(ix, iy, iquad, ix, iy);\r
+#endif /* SERGEEV */\r
return;\r
}\r
skip(1);\r
}\r
break;\r
}\r
+#ifdef SERGEEV\r
+ if(curwnd!=4) {\r
+ setwnd(4);\r
+ gotoxy(crx,cry);\r
+ }\r
+#endif /* SERGEEV */\r
if (shoved) {\r
game.quad[jx][jy]=iquad;\r
game.quad[ix][iy]=IHDOT;\r
sortkl();\r
return;\r
}\r
+#ifndef SERGEEV\r
skip(1);\r
+#endif /* SERGEEV */\r
prout("Torpedo missed.");\r
return;\r
}\r
\r
static void fry(double hit) {\r
double ncrit, extradm;\r
- int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr;\r
+ int ktr=1, l, ll, j, cdam[NDEVICES+1];\r
\r
/* a critical hit occured */\r
if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;\r
prout(" ");\r
r = (Rand()+Rand())*0.5 -0.5;\r
r += 0.002*game.kpower[l]*r;\r
- torpedo(course, r, jx, jy, &hit);\r
+ torpedo(course, r, jx, jy, &hit, 0);\r
if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */\r
if (game.state.galaxy[quadx][quady] == 1000 ||\r
alldone) return; /* Supernova or finished */\r
if (absorb > shield) absorb = shield;\r
shield -= absorb;\r
hit -= hitsh;\r
+ if (condit==IHDOCKED) dock(0);\r
if (propor > 0.1 && hit < 0.005*energy) continue;\r
}\r
/* It's a hit -- print out hit size */\r
fry(hit);\r
prout("Hit %g energy %g", hit, energy);\r
energy -= hit;\r
+ if (condit==IHDOCKED) dock(0);\r
}\r
if (energy <= 0) {\r
/* Returning home upon your shield, not with it... */\r
/* Added ixx and iyy allow enemy to "move" before dying */\r
\r
int i,j;\r
- \r
+\r
+#ifdef SERGEEV \r
+ skip(1);\r
+#endif /* SERGEEV */\r
crmena(1, type, 2, ixx, iyy);\r
/* Decide what kind of enemy it is and update approriately */\r
if (type == IHR) {\r
break;\r
}\r
}\r
- if (shldup != 0 || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;\r
+ if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;\r
+#ifndef SERGEEV\r
if (n != 1) {\r
skip(1);\r
proutn("Track for torpedo number %d- ", i);\r
skip(1);\r
proutn("Torpedo track- ");\r
}\r
- torpedo(course[i], r, sectx, secty, &dummy);\r
+#endif /* SERGEEV */\r
+ torpedo(course[i], r, sectx, secty, &dummy, i);\r
if (alldone || game.state.galaxy[quadx][quady]==1000) return;\r
}\r
if (game.state.remkl==0) finish(FWON);\r
\r
\r
void phasers(void) {\r
- double hits[21], rpow, extra, powrem, over, temp;\r
- int kz = 0, k=1, i; /* Cheating inhibitor */\r
+ double hits[21], rpow=0, extra, powrem, over, temp;\r
+ int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */\r
int ifast=0, no=0, ipoop=1, msgflag = 1;\r
enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;\r
int key=0;\r
ifast = 1;\r
\r
}\r
- ididit = 1;\r
/* Original code so convoluted, I re-did it all */\r
while (automode==NOTSET) {\r
key=scan();\r
}\r
else {\r
huh();\r
- ididit = 0;\r
return;\r
}\r
}\r
key = scan();\r
}\r
if (key != IHREAL && nenhere != 0) {\r
- prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy);\r
+ prout("Phasers locked on target. Energy available: %.2f",\r
+ ifast?energy-200.0:energy,1,2);\r
}\r
+ irec=0;\r
do {\r
- while (key != IHREAL) {\r
+ chew();\r
+ if (!kz) for (i = 1; i <= nenhere; i++)\r
+ irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*\r
+ (1.01+0.05*Rand()) + 1.0;\r
+ kz=1;\r
+ proutn("(%d) units required. ", irec);\r
chew();\r
- proutn("Units to fire=");\r
+ proutn("Units to fire= ");\r
key = scan();\r
- }\r
- rpow = aaitem;\r
- if (rpow >= (ifast?energy-200:energy)) {\r
- proutn("Energy available= %.2f",\r
- ifast?energy-200:energy);\r
+ if (key!=IHREAL) return;\r
+ rpow = aaitem;\r
+ if (rpow > (ifast?energy-200:energy)) {\r
+ proutn("Energy available= %.2f",\r
+ ifast?energy-200:energy);\r
skip(1);\r
key = IHEOL;\r
}\r
- } while (rpow >= (ifast?energy-200:energy));\r
+ } while (rpow > (ifast?energy-200:energy));\r
if (rpow<=0) {\r
/* chicken out */\r
- ididit = 0;\r
chew();\r
return;\r
}\r
}\r
if (powrem > 0.0) extra += powrem;\r
hittem(hits);\r
+ ididit=1;\r
}\r
if (extra > 0 && alldone == 0) {\r
if (ithere) {\r
}\r
if (key == IHEOL) {\r
chew();\r
- if (ipoop && k > kz) {\r
- int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*\r
+ if (ipoop && k > kz)\r
+ irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*\r
(1.01+0.05*Rand()) + 1.0;\r
- kz = k;\r
- proutn("(%d)", irec);\r
- }\r
+ kz = k;\r
+ proutn("(");\r
+ if (game.damage[DCOMPTR]==0) proutn("%d", irec);\r
+ else proutn("??");\r
+ proutn(") ");\r
proutn("units to fire at ");\r
crmena(0, ienm, 2, ii, jj);\r
proutn("- ");\r
}\r
if (key == IHALPHA) {\r
huh();\r
- ididit = 0;\r
return;\r
}\r
if (key == IHEOL) {\r
rpow += aaitem;\r
/* If total requested is too much, inform and start over */\r
\r
- if (rpow >= (ifast?energy-200:energy)) {\r
+ if (rpow > (ifast?energy-200:energy)) {\r
prout("Available energy exceeded -- try again.");\r
chew();\r
- key = IHEOL;\r
- k = 1;\r
- msgflag = 1;\r
- continue;\r
+ return;\r
}\r
key = scan(); /* scan for next value */\r
k++;\r
}\r
if (rpow == 0.0) {\r
/* zero energy -- abort */\r
- ididit = 0;\r
chew();\r
return;\r
}\r
}\r
hittem(hits);\r
ididit=1;\r
+ case NOTSET:; /* avoid gcc warning */\r
}\r
/* Say shield raised or malfunction, if necessary */\r
if (alldone) return;\r
\r
void hittem(double *hits) {\r
double kp, kpow, wham, hit, dustfac, kpini;\r
+#ifdef SERGEEV\r
+ int cx, cy;\r
+#endif /* SERGEEV */\r
int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;\r
\r
skip(1);\r
ii = game.kx[kk];\r
jj = game.ky[kk];\r
if (hit > 0.005) {\r
+#ifdef SERGEEV\r
+ if (game.damage[DSRSENS]==0){\r
+ crx=wherex();\r
+ cry=wherey();\r
+ setwnd(1);\r
+ drawmaps(2);\r
+ gotoxy(jj*2+3,ii+2);\r
+ highvideo();\r
+ proutn("%c", game.quad[ii][jj]);\r
+ gotoxy(wherex()-1,wherey());\r
+ sound(500);\r
+ delay(1000);\r
+ nosound();\r
+ lowvideo();\r
+ proutn("%c", game.quad[ii][jj]);\r
+ setwnd(4);\r
+ gotoxy(crx,cry);\r
+ _setcursortype(_NORMALCURSOR);\r
+ delay(500);\r
+ }\r
+#endif /* SERGEEV */\r
proutn("%d unit hit on ", (int)hit);\r
}\r
else\r
+#ifdef SERGEEV
+#define _GNU_SOURCE
+#endif /* SERGEEV */
#include <stdio.h>
+#ifdef SERGEEV
+#include <unistd.h>
+#endif /* SERGEEV */
#include <termios.h>
#include <curses.h>
#include <signal.h>
#include <ctype.h>
#include <stdarg.h>
+#ifdef SERGEEV
+#include <conio.h>
+#endif /* SERGEEV */
#ifdef MSDOS
#include <dos.h>
#endif
#include <time.h>
+#ifdef SERGEEV
+#include "sstlinux.h"
+#endif /* SERGEEV */
#include "sst.h"
+#ifndef SERGEEV
static int linecount; /* for paging */
+#endif /* SERGEEV */
static int screenheight = 24, screenwidth = 80;
+#ifndef SERGEEV
static int curses = FALSE;
+#else /* SERGEEV */
+static int curses = TRUE;
+#endif /* SERGEEV */
static void outro(int sig) {
/* wrap up, either normally or due to signal */
if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
(void)signal(SIGQUIT,fastexit);
+#ifndef SERGEEV
if (curses = usecurses) {
+#else /* SERGEEV */
+ if ((curses = usecurses)) {
+#endif /* SERGEEV */
(void)initscr();
#ifdef KEY_MIN
keypad(stdscr, TRUE);
}
void pause_game(int i) {
+#ifndef SERGEEV
char buf[BUFSIZ], *prompt;
+#else /* SERGEEV */
+ char *prompt;
+ drawmaps(0);
+ setwnd(5);
+#endif /* SERGEEV */
if (i==1) {
if (skill > 2)
prompt = "[ANOUNCEMENT ARRIVING...]";
prompt = "[PRESS ENTER TO CONTINUE]";
}
+#ifndef SERGEEV
if (curses) {
waddch(stdscr, '\n');
waddstr(stdscr, prompt);
}
linecount = 0;
}
+#else /* SERGEEV */
+ proutn(prompt);
+ getche();
+ clrscr();
+ setwnd(4);
+ clrscr();
+#endif /* SERGEEV */
}
void skip(int i) {
+#ifndef SERGEEV
while (i-- > 0) {
if (curses) {
int y, x;
else
putchar('\n');
}
+#else /* SERGEEV */
+ while (i-- > 0) proutn("\n\r");
+}
+
+static void vproutn(char *fmt, va_list ap) {
+ char *strbuf, *p, *s;
+ vasprintf(&strbuf, fmt, ap);
+ p=s=strbuf;
+ if ((curwnd==4)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
+ if (strchr(strbuf,'\n')){
+ p=strchr(strbuf,'\n');
+ p[0]=0;
+ cprintf("%s",strbuf);
+ p++;
+ pause_game(0);
+ }
+#endif /* SERGEEV */
}
+#ifdef SERGEEV
+ if ((curwnd==4)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
+ cprintf("\r");
+// setwnd(curwnd);
+ if (strchr(s,'\n') || strchr(s,'\r')) clreol();
+ cprintf("%s",p);
+ free(strbuf);
+#endif /* SERGEEV */
}
void proutn(char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
+#ifndef SERGEEV
if (curses) {
vw_printw(stdscr, fmt, ap);
wrefresh(stdscr);
} else
vprintf(fmt, ap);
+#else /* SERGEEV */
+ vproutn(fmt, ap);
+#endif /* SERGEEV */
va_end(ap);
}
void prout(char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
+#ifndef SERGEEV
if (curses) {
vw_printw(stdscr, fmt, ap);
wrefresh(stdscr);
} else
vprintf(fmt, ap);
+#else /* SERGEEV */
+ vproutn(fmt, ap);
+#endif /* SERGEEV */
va_end(ap);
skip(1);
}
void proutc(char *line) {
line[strlen(line)-1] = '\0';
+#ifndef SERGEEV
if (curses)
waddstr(stdscr, line);
else
fputs(line, stdout);
+#else /* SERGEEV */
+ cputs(line);
+#endif /* SERGEEV */
skip(1);
}
+#ifdef SERGEEV
+static void prchr(char *s){
+ char str[2];
+ strncpy(str,s,1);
+ str[1]=0;
+ proutn(str);
+}
+
+static void vprouts(char *fmt, va_list ap) {
+ char *s;
+ vasprintf(&s, fmt, ap);
+ while (*s) {
+ prchr(s++);
+ delay(30);
+ }
+ free(s);
+}
+
+#endif /* SERGEEV */
void prouts(char *fmt, ...) {
+#ifndef SERGEEV
clock_t endTime;
char *s, buf[BUFSIZ];
/* print slowly! */
fflush(stdout);
}
}
+#else /* SERGEEV */
+ va_list ap;
+ va_start(ap, fmt);
+ vprouts(fmt, ap);
+ va_end(ap);
+#endif /* SERGEEV */
}
+#ifndef SERGEEV
void getline(char *line, int max) {
+#else /* SERGEEV */
+void cgetline(char *line, int max) {
+#endif /* SERGEEV */
if (curses) {
+#ifndef SERGEEV
wgetnstr(stdscr, line, max);
wrefresh(stdscr);
+#else /* SERGEEV */
+ line[0]=max-1;
+ cgets(line);
+ memmove(line,&line[2],max-3);
+#endif /* SERGEEV */
} else {
fgets(line, max, stdin);
line[strlen(line)-1] = '\0';