From b7bbbdd604afc1fac8b7c54563520b7d191ca216 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 19 Jan 2005 23:17:44 +0000 Subject: [PATCH] First round of Sergeev merges. --- battle.c | 168 +++++++++++++++++++++++++++++++++++++++++++----------- events.c | 2 +- io.c | 110 +++++++++++++++++++++++++++++++++++ makefile | 6 +- moving.c | 2 +- reports.c | 6 +- setup.c | 1 - sst.c | 5 +- sst.h | 2 +- 9 files changed, 256 insertions(+), 46 deletions(-) diff --git a/battle.c b/battle.c index dd102aa..97cea70 100644 --- a/battle.c +++ b/battle.c @@ -1,3 +1,8 @@ +#ifdef SERGEEV +#include +#include +#include "sstlinux.h" +#endif /* SERGEEV */ #include "sst.h" void doshield(int i) { @@ -171,8 +176,12 @@ void ram(int ibumpd, int ienm, int ix, int iy) { return; } -void torpedo(double course, double r, int inx, int iny, double *hit) { - int l, iquad, ix, iy, jx, jy, shoved=0, ll; +void torpedo(double course, double r, int inx, int iny, double *hit, int wait) { + int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll; +#ifdef SERGEEV + int crx,cry; + +#endif /* SERGEEV */ double ac=course + 0.25*r; double angle = (15.0-ac)*0.5235988; double bullseye = (15.0 - course)*0.5235988; @@ -183,7 +192,12 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { if (fabs(deltay) > bigger) bigger = fabs(deltay); deltax /= bigger; deltay /= bigger; - +#ifdef SERGEEV + crx=wherex(); + cry=wherey(); + if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(1); + else setwnd(4); +#endif /* SERGEEV */ /* Loop to move a single torpedo */ for (l=1; l <= 15; l++) { x += deltax; @@ -192,12 +206,49 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { y += deltay; iy = y + 0.5; if (iy < 1 || iy > 10) break; +#ifndef SERGEEV if (l==4 || l==9) skip(1); proutn("%d - %d ", (int)x, (int)y); iquad=game.quad[ix][iy]; +#else + iquad=game.quad[ix][iy]; + if (game.damage[DSRSENS]==0 || condit==IHDOCKED){ + drawmaps(2); + delay((wait!=1)*400); + wait=1; + gotoxy(iy*2+3,ix+2); + if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){ + game.quad[ix][iy]='+'; + drawmaps(2); + game.quad[ix][iy]=iquad; + sound(l*10); + delay(100); + nosound(); + } + else { + game.quad[ix][iy]|=128; + drawmaps(2); + game.quad[ix][iy]=iquad; + _setcursortype(_NOCURSOR); + sound(500); + delay(1000); + nosound(); + lowvideo(); + _setcursortype(_NORMALCURSOR); + } + } + else { + proutn("%d - %d ", (int)x, (int)y); + } +#endif /* SERGEEV */ if (iquad==IHDOT) continue; /* hit something */ +#ifndef SERGEEV skip(1); +#else + setwnd(4); + gotoxy(crx,cry); +#endif switch(iquad) { case IHE: /* Hit our ship */ case IHF: @@ -209,7 +260,9 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { 1000.0*sqrt(square(ix-inx)+square(iy-iny))* fabs(sin(bullseye-angle)); *hit = fabs(*hit); +#ifndef SERGEEV newcnd(); /* undock */ +#endif /* SERGEEV */ /* We may be displaced. */ if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */ ang = angle + 2.5*(Rand()-0.5); @@ -361,10 +414,15 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { fabs(sin(bullseye-angle)); h1 = fabs(h1); if (h1 >= 600) { +#ifndef SERGEEV prout(" destroyed."); +#endif /* SERGEEV */ game.quad[ix][iy] = IHDOT; ithere = 0; ithx = ithy = 0; +#ifdef SERGEEV + deadkl(ix, iy, iquad, ix, iy); +#endif /* SERGEEV */ return; } skip(1); @@ -392,6 +450,12 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { } break; } +#ifdef SERGEEV + if(curwnd!=4) { + setwnd(4); + gotoxy(crx,cry); + } +#endif /* SERGEEV */ if (shoved) { game.quad[jx][jy]=iquad; game.quad[ix][iy]=IHDOT; @@ -401,14 +465,16 @@ void torpedo(double course, double r, int inx, int iny, double *hit) { sortkl(); return; } +#ifndef SERGEEV skip(1); +#endif /* SERGEEV */ prout("Torpedo missed."); return; } static void fry(double hit) { double ncrit, extradm; - int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr; + int ktr=1, l, ll, j, cdam[NDEVICES+1]; /* a critical hit occured */ if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return; @@ -502,7 +568,7 @@ void attack(int k) { prout(" "); r = (Rand()+Rand())*0.5 -0.5; r += 0.002*game.kpower[l]*r; - torpedo(course, r, jx, jy, &hit); + torpedo(course, r, jx, jy, &hit, 0); if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */ if (game.state.galaxy[quadx][quady] == 1000 || alldone) return; /* Supernova or finished */ @@ -518,6 +584,7 @@ void attack(int k) { if (absorb > shield) absorb = shield; shield -= absorb; hit -= hitsh; + if (condit==IHDOCKED) dock(0); if (propor > 0.1 && hit < 0.005*energy) continue; } /* It's a hit -- print out hit size */ @@ -541,6 +608,7 @@ void attack(int k) { fry(hit); prout("Hit %g energy %g", hit, energy); energy -= hit; + if (condit==IHDOCKED) dock(0); } if (energy <= 0) { /* Returning home upon your shield, not with it... */ @@ -585,7 +653,10 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) { /* Added ixx and iyy allow enemy to "move" before dying */ int i,j; - + +#ifdef SERGEEV + skip(1); +#endif /* SERGEEV */ crmena(1, type, 2, ixx, iyy); /* Decide what kind of enemy it is and update approriately */ if (type == IHR) { @@ -801,7 +872,8 @@ void photon(void) { break; } } - if (shldup != 0 || condit == IHDOCKED) r *= 1.0 + 0.0001*shield; + if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield; +#ifndef SERGEEV if (n != 1) { skip(1); proutn("Track for torpedo number %d- ", i); @@ -810,7 +882,8 @@ void photon(void) { skip(1); proutn("Torpedo track- "); } - torpedo(course[i], r, sectx, secty, &dummy); +#endif /* SERGEEV */ + torpedo(course[i], r, sectx, secty, &dummy, i); if (alldone || game.state.galaxy[quadx][quady]==1000) return; } if (game.state.remkl==0) finish(FWON); @@ -871,8 +944,8 @@ static int checkshctrl(double rpow) { void phasers(void) { - double hits[21], rpow, extra, powrem, over, temp; - int kz = 0, k=1, i; /* Cheating inhibitor */ + double hits[21], rpow=0, extra, powrem, over, temp; + int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */ int ifast=0, no=0, ipoop=1, msgflag = 1; enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET; int key=0; @@ -905,7 +978,6 @@ void phasers(void) { ifast = 1; } - ididit = 1; /* Original code so convoluted, I re-did it all */ while (automode==NOTSET) { key=scan(); @@ -938,7 +1010,6 @@ void phasers(void) { } else { huh(); - ididit = 0; return; } } @@ -972,25 +1043,31 @@ 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,1,2); } + irec=0; do { - while (key != IHREAL) { + chew(); + if (!kz) for (i = 1; i <= nenhere; i++) + irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))* + (1.01+0.05*Rand()) + 1.0; + kz=1; + proutn("(%d) units required. ", irec); chew(); - proutn("Units to fire="); + proutn("Units to fire= "); key = scan(); - } - rpow = aaitem; - if (rpow >= (ifast?energy-200:energy)) { - proutn("Energy available= %.2f", - ifast?energy-200:energy); + if (key!=IHREAL) return; + rpow = aaitem; + if (rpow > (ifast?energy-200:energy)) { + proutn("Energy available= %.2f", + ifast?energy-200:energy); skip(1); key = IHEOL; } - } while (rpow >= (ifast?energy-200:energy)); + } while (rpow > (ifast?energy-200:energy)); if (rpow<=0) { /* chicken out */ - ididit = 0; chew(); return; } @@ -1020,6 +1097,7 @@ void phasers(void) { } if (powrem > 0.0) extra += powrem; hittem(hits); + ididit=1; } if (extra > 0 && alldone == 0) { if (ithere) { @@ -1071,12 +1149,14 @@ void phasers(void) { } if (key == IHEOL) { chew(); - if (ipoop && k > kz) { - int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))* + if (ipoop && k > kz) + irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))* (1.01+0.05*Rand()) + 1.0; - kz = k; - proutn("(%d)", irec); - } + kz = k; + proutn("("); + if (game.damage[DCOMPTR]==0) proutn("%d", irec); + else proutn("??"); + proutn(") "); proutn("units to fire at "); crmena(0, ienm, 2, ii, jj); proutn("- "); @@ -1089,7 +1169,6 @@ void phasers(void) { } if (key == IHALPHA) { huh(); - ididit = 0; return; } if (key == IHEOL) { @@ -1107,20 +1186,16 @@ void phasers(void) { rpow += aaitem; /* If total requested is too much, inform and start over */ - if (rpow >= (ifast?energy-200:energy)) { + if (rpow > (ifast?energy-200:energy)) { prout("Available energy exceeded -- try again."); chew(); - key = IHEOL; - k = 1; - msgflag = 1; - continue; + return; } key = scan(); /* scan for next value */ k++; } if (rpow == 0.0) { /* zero energy -- abort */ - ididit = 0; chew(); return; } @@ -1135,6 +1210,7 @@ void phasers(void) { } hittem(hits); ididit=1; + case NOTSET:; /* avoid gcc warning */ } /* Say shield raised or malfunction, if necessary */ if (alldone) return; @@ -1158,6 +1234,9 @@ void phasers(void) { void hittem(double *hits) { double kp, kpow, wham, hit, dustfac, kpini; +#ifdef SERGEEV + int cx, cy; +#endif /* SERGEEV */ int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm; skip(1); @@ -1174,6 +1253,27 @@ void hittem(double *hits) { ii = game.kx[kk]; jj = game.ky[kk]; if (hit > 0.005) { +#ifdef SERGEEV + if (game.damage[DSRSENS]==0){ + crx=wherex(); + cry=wherey(); + setwnd(1); + drawmaps(2); + gotoxy(jj*2+3,ii+2); + highvideo(); + proutn("%c", game.quad[ii][jj]); + gotoxy(wherex()-1,wherey()); + sound(500); + delay(1000); + nosound(); + lowvideo(); + proutn("%c", game.quad[ii][jj]); + setwnd(4); + gotoxy(crx,cry); + _setcursortype(_NORMALCURSOR); + delay(500); + } +#endif /* SERGEEV */ proutn("%d unit hit on ", (int)hit); } else diff --git a/events.c b/events.c index 194901d..10c030a 100644 --- a/events.c +++ b/events.c @@ -585,7 +585,7 @@ void nova(int ix, int iy) { void snova(int insx, int insy) { - int comdead, nqx, nqy, nsx, nsy, num, kldead, iscdead; + int comdead, nqx=0, nqy=0, nsx, nsy, num, kldead, iscdead; int nrmdead, npdead; int insipient=0; diff --git a/io.c b/io.c index 81f1c8a..8b766e9 100644 --- a/io.c +++ b/io.c @@ -1,19 +1,37 @@ +#ifdef SERGEEV +#define _GNU_SOURCE +#endif /* SERGEEV */ #include +#ifdef SERGEEV +#include +#endif /* SERGEEV */ #include #include #include #include #include +#ifdef SERGEEV +#include +#endif /* SERGEEV */ #ifdef MSDOS #include #endif #include +#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 */ @@ -41,7 +59,11 @@ void iostart(int usecurses) { 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); @@ -83,7 +105,13 @@ void clearscreen(void) { } 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...]"; @@ -97,6 +125,7 @@ void pause_game(int i) { prompt = "[PRESS ENTER TO CONTINUE]"; } +#ifndef SERGEEV if (curses) { waddch(stdscr, '\n'); waddstr(stdscr, prompt); @@ -112,10 +141,18 @@ void pause_game(int i) { } 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; @@ -131,42 +168,99 @@ void skip(int i) { 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! */ @@ -187,12 +281,28 @@ void prouts(char *fmt, ...) { 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'; diff --git a/makefile b/makefile index c9c42b1..1d41c14 100644 --- a/makefile +++ b/makefile @@ -2,12 +2,16 @@ VERS=$(shell sed