From: Stas Sergeev Date: Wed, 25 May 2005 17:42:07 +0000 (+0000) Subject: Fix the logic around remkl. X-Git-Tag: 2.0~305 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=2a83be50e15e057ac9237e5c9bf97bd6d395db39;p=super-star-trek.git Fix the logic around remkl. - There were the confusions about the remkl around the code: sometimes it was used as a total klingons count, sometimes - as a count of only an ordinary klingons. I added the separate counters for those. Also removed the killed counters; added the macros that calculates "killed" values as initial_val-remaining_val. - Reset the klingons, starbases and supernovas on map upon an initialization. This fixes the bug where the unkilled klingons could propagate themselves to the subsequent game round. --- diff --git a/ai.c b/ai.c index 291c2f7..1e70f2a 100644 --- a/ai.c +++ b/ai.c @@ -378,7 +378,7 @@ void scom(int *ipage) #endif /* Decide on being active or passive */ - flag = ((game.state.killc+game.state.killk)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) || + flag = ((NKILLC+NKILLK)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) || (game.state.date-indate) < 3.0); if (iscate==0 && flag) { /* compute move away from Enterprise */ diff --git a/battle.c b/battle.c index bd8070a..903e216 100644 --- a/battle.c +++ b/battle.c @@ -168,7 +168,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) game.damage[l] += Time + extradm; /* Damage for at least time of travel! */ } shldup = 0; - if (game.state.remkl) { + if (KLINGREM) { pause_game(2); dreprt(); } @@ -518,7 +518,7 @@ void attack(int torps_ok) r = (Rand()+Rand())*0.5 -0.5; r += 0.002*game.kpower[l]*r; torpedo(course, r, jx, jy, &hit, 1, 1); - if (game.state.remkl==0) + if (KLINGREM==0) finish(FWON); /* Klingons did themselves in! */ if (game.state.galaxy[quadx][quady].supernova || alldone) return; /* Supernova or finished */ @@ -613,7 +613,6 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) /* chalk up a Romulan */ game.state.galaxy[quadx][quady].romulans--; irhere--; - game.state.nromkl++; game.state.nromrem--; } else if (type == IHT) { @@ -628,7 +627,6 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) /* Some type of a Klingon */ game.state.galaxy[quadx][quady].klingons--; klhere--; - game.state.remkl--; switch (type) { case IHC: comhere = 0; @@ -642,14 +640,13 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) game.future[FTBEAM] = FOREVER; if (game.state.remcom != 0) game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom); - game.state.killc++; break; case IHK: - game.state.killk++; + game.state.remkl--; break; case IHS: - game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0; - game.state.nsckill = 1; + game.state.nscrem--; + ishere = game.state.isx = game.state.isy = isatb = iscate = 0; game.future[FSCMOVE] = game.future[FSCDBAS] = FOREVER; break; } @@ -658,7 +655,7 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) /* For each kind of enemy, finish message to player */ prout(" destroyed."); game.quad[ix][iy] = IHDOT; - if (game.state.remkl==0) return; + if (KLINGREM==0) return; game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom); @@ -830,7 +827,7 @@ void photon(void) if (alldone || game.state.galaxy[quadx][quady].supernova) return; } - if (game.state.remkl==0) finish(FWON); + if (KLINGREM==0) finish(FWON); } @@ -1211,7 +1208,7 @@ void hittem(double *hits) skip(1); if (kpow == 0) { deadkl(ii, jj, ienm, ii, jj); - if (game.state.remkl==0) finish(FWON); + if (KLINGREM==0) finish(FWON); if (alldone) return; kk--; /* don't do the increment */ } diff --git a/events.c b/events.c index be7facd..589a838 100644 --- a/events.c +++ b/events.c @@ -687,7 +687,6 @@ void snova(int insx, int insy) iscdead = 1; game.future[FSCMOVE] = game.future[FSCDBAS] = FOREVER; } - game.state.remkl -= kldead; if (game.state.remcom) { int maxloop = game.state.remcom, l; for (l = 1; l <= maxloop; l++) { @@ -703,6 +702,7 @@ void snova(int insx, int insy) } } } + game.state.remkl -= kldead; /* destroy Romulans and planets in supernovaed quadrant */ nrmdead = game.state.galaxy[nqx][nqy].romulans; game.state.galaxy[nqx][nqy].romulans = 0; @@ -731,11 +731,7 @@ void snova(int insx, int insy) if (insx) { game.state.starkl += game.state.galaxy[nqx][nqy].stars; game.state.basekl += game.state.galaxy[nqx][nqy].starbase; - game.state.killk += kldead; - game.state.killc += comdead; - game.state.nromkl += nrmdead; game.state.nplankl += npdead; - game.state.nsckill += iscdead; } /* mark supernova in galaxy and in star chart */ if ((quadx == nqx && quady == nqy) || @@ -743,7 +739,7 @@ void snova(int insx, int insy) condit == IHDOCKED) game.state.galaxy[nqx][nqy].supernova = TRUE; /* If supernova destroys last klingons give special message */ - if (game.state.remkl==0 && (nqx != quadx || nqy != quady)) { + if (KLINGREM==0 && (nqx != quadx || nqy != quady)) { skip(2); if (insx == 0) prout("Lucky you!"); proutn("A supernova in %s has just destroyed the last Klingons.", diff --git a/finish.c b/finish.c index ae70c4c..c0d3569 100644 --- a/finish.c +++ b/finish.c @@ -93,7 +93,7 @@ void finish(FINTYPE ifin) if (badpt < 100.0) badpt = 0.0; // Close enough! if (game.state.date-indate < 5.0 || // killsPerDate >= RateMax - (game.state.killk+game.state.killc+game.state.nsckill)/(game.state.date-indate) >= + KLINGKILLED/(game.state.date-indate) >= 0.1*skill*(skill+1.0) + 0.1 + 0.008*badpt) { skip(1); prout("In fact, you have done so well that Starfleet Command"); @@ -160,7 +160,7 @@ void finish(FINTYPE ifin) prout("conquered. Your starship is now Klingon property,"); prout("and you are put on trial as a war criminal. On the"); proutn("basis of your record, you are "); - if (game.state.remkl*3.0 > inkling) { + if (KLINGREM*3.0 > INKLINGTOT) { prout("aquitted."); skip(1); prout("LIVE LONG AND PROSPER."); @@ -285,7 +285,7 @@ void finish(FINTYPE ifin) if (ship==IHF) ship= 0; else if (ship == IHE) ship = IHF; alive = 0; - if (game.state.remkl != 0) { + if (KLINGREM != 0) { double goodies = game.state.remres/inresor; double baddies = (game.state.remkl + 2.0*game.state.remcom)/(inkling+2.0*incom); if (goodies/baddies >= 1.0+0.5*Rand()) { @@ -318,8 +318,8 @@ void score(void) int ithperd, iwon, klship; iskill = skill; - if ((timused == 0 || game.state.remkl != 0) && timused < 5.0) timused = 5.0; - perdate = (game.state.killc + game.state.killk + game.state.nsckill)/timused; + if ((timused == 0 || KLINGREM != 0) && timused < 5.0) timused = 5.0; + perdate = KLINGKILLED/timused; ithperd = 500*perdate + 0.5; iwon = 0; if (gamewon) iwon = 100*skill; @@ -327,27 +327,27 @@ void score(void) else if (ship == IHF) klship = 1; else klship = 2; if (gamewon == 0) game.state.nromrem = 0; // None captured if no win - iscore = 10*game.state.killk + 50*game.state.killc + ithperd + iwon + iscore = 10*NKILLK + 50*NKILLC + ithperd + iwon - 100*game.state.basekl - 100*klship - 45*nhelp -5*game.state.starkl - casual - + 20*game.state.nromkl + 200*game.state.nsckill - 10*game.state.nplankl + game.state.nromrem; + + 20*NKILLROM + 200*NKILLSC - 10*game.state.nplankl + game.state.nromrem; if (alive == 0) iscore -= 200; skip(2); prout("Your score --"); - if (game.state.nromkl) + if (NKILLROM) prout("%6d Romulans destroyed %5d", - game.state.nromkl,20*game.state.nromkl); + NKILLROM,20*NKILLROM); if (game.state.nromrem) prout("%6d Romulans captured %5d", game.state.nromrem, game.state.nromrem); - if (game.state.killk) + if (NKILLK) prout("%6d ordinary Klingons destroyed %5d", - game.state.killk, 10*game.state.killk); - if (game.state.killc) + NKILLK, 10*NKILLK); + if (NKILLC) prout("%6d Klingon commanders destroyed %5d", - game.state.killc, 50*game.state.killc); - if (game.state.nsckill) + NKILLC, 50*NKILLC); + if (NKILLSC) prout("%6d Super-Commander destroyed %5d", - game.state.nsckill, 200*game.state.nsckill); + NKILLSC, 200*NKILLSC); if (ithperd) prout("%6.2f Klingons per stardate %5d", perdate, ithperd); diff --git a/moving.c b/moving.c index 2f08d08..7d3f6df 100644 --- a/moving.c +++ b/moving.c @@ -763,7 +763,7 @@ void atover(int igrab) } while /* Repeat if another snova */ (game.state.galaxy[quadx][quady].supernova); - if (game.state.remkl==0) + if (KLINGREM==0) finish(FWON); /* Snova killed remaining enemy. */ } diff --git a/planets.c b/planets.c index 9e847eb..7dd9541 100644 --- a/planets.c +++ b/planets.c @@ -436,7 +436,7 @@ void deathray(void) while (nenhere > 0) deadkl(game.kx[1],game.ky[1],game.quad[game.kx[1]][game.ky[1]],game.kx[1],game.ky[1]); prout("Ensign Chekov- \"Congratulations, Captain!\""); - if (game.state.remkl == 0) finish(FWON); + if (KLINGREM == 0) finish(FWON); prout("Spock- \"Captain, I believe the `Experimental Death Ray'"); if (Rand() <= 0.05) { prout(" is still operational.\""); diff --git a/reports.c b/reports.c index 568d4f0..f0dc134 100644 --- a/reports.c +++ b/reports.c @@ -54,10 +54,9 @@ void report(void) if (skill>SKILL_GOOD && thawed && !alldone) prout("No plaque is allowed."); if (tourn) prout("This is tournament game %d.", tourn); prout("Your secret password is \"%s\"",game.passwd); - proutn("%d of %d Klingons have been killed", - game.state.killk+game.state.killc+game.state.nsckill, inkling); - if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s"); - else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders."); + proutn("%d of %d Klingons have been killed", KLINGKILLED, INKLINGTOT); + if (NKILLC) prout(", including %d Commander%s.", NKILLC, NKILLC==1?"":"s"); + else if (NKILLK + NKILLSC > 0) prout(", but no Commanders."); else prout("."); if (skill > SKILL_FAIR) prout("The Super Commander has %sbeen destroyed.", game.state.nscrem?"not ":""); @@ -311,7 +310,7 @@ static void status(int req) (int)((100.0*shield)/inshld + 0.5), shield); break; case 9: - proutn("Klingons Left %d", game.state.remkl); + proutn("Klingons Left %d", KLINGREM); break; case 10: attakreport(1); diff --git a/setup.c b/setup.c index 40e610b..72c2e84 100644 --- a/setup.c +++ b/setup.c @@ -219,8 +219,8 @@ void setup(int needprompt) // Set up assorted game parameters batx = baty = 0; 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; + nkinks = nhelp = resting = casual = 0; + isatb = iscate = imine = icrystl = icraft = game.state.nplankl = 0; game.state.starkl = game.state.basekl = 0; iscraft = 1; landed = -1; @@ -231,6 +231,9 @@ void setup(int needprompt) game.state.galaxy[i][j].charted = 0; game.state.galaxy[i][j].planets = 0; game.state.galaxy[i][j].romulans = 0; + game.state.galaxy[i][j].klingons = 0; + game.state.galaxy[i][j].starbase = 0; + game.state.galaxy[i][j].supernova = 0; } // Initialize times for extraneous events game.future[FSNOVA] = game.state.date + expran(0.5 * intime); @@ -282,7 +285,7 @@ void setup(int needprompt) game.state.chart[ix][iy].starbase = 1; } // Position ordinary Klingon Battle Cruisers - krem = inkling - incom - game.state.nscrem; + krem = inkling; klumper = 0.25*skill*(9.0-length)+1.0; if (klumper > 9) klumper = 9; // Can't have more than 9 in quadrant do { @@ -364,7 +367,7 @@ void setup(int needprompt) prout("a deadly Klingon invasion force. As captain of the United"); prout("Starship U.S.S. Enterprise, it is your mission to seek out"); prout("and destroy this invasion force of %d battle cruisers.", - inkling); + INKLINGTOT); prout("You have an initial allotment of %d stardates to complete", (int)intime); prout("your mission. As you proceed you may be given more time."); prout(""); @@ -374,7 +377,7 @@ void setup(int needprompt) else { prout("Stardate %d.", (int)game.state.date); prout(""); - prout("%d Klingons.", inkling); + prout("%d Klingons.", INKLINGTOT); prout("An unknown number of Romulans."); if (game.state.nscrem) prout("and one (GULP) Super-Commander."); prout("%d stardates.",(int)intime); @@ -475,15 +478,14 @@ int choose(int needprompt) inbase = game.state.rembase; if (game.options & OPTION_PLANETS) inplan = (PLNETMAX/2) + (PLNETMAX/2+1)*Rand(); - game.state.nromrem = (2.0+Rand())*skill; - game.state.nscrem = (skill > SKILL_FAIR ? 1 : 0); + game.state.nromrem = inrom = (2.0+Rand())*skill; + game.state.nscrem = inscom = (skill > SKILL_FAIR ? 1 : 0); game.state.remtime = 7.0 * length; intime = game.state.remtime; - inkling = 2.0*intime*((skill+1 - 2*Rand())*skill*0.1+.15); + game.state.remkl = inkling = 2.0*intime*((skill+1 - 2*Rand())*skill*0.1+.15); incom = skill + 0.0625*inkling*Rand(); - game.state.remcom= min(10, incom); + game.state.remcom = min(10, incom); incom = game.state.remcom; - game.state.remkl = inkling + incom + game.state.nscrem; game.state.remres = (inkling+4*incom)*intime; inresor = game.state.remres; if (inkling > 50) { diff --git a/sst.h b/sst.h index e186dc0..ae8c4f5 100644 --- a/sst.h +++ b/sst.h @@ -46,19 +46,15 @@ typedef struct { int snap, // snapshot taken remkl, // remaining klingons remcom, // remaining commanders + nscrem, // remaining super commanders rembase, // remaining bases starkl, // destroyed stars basekl, // destroyed bases - killk, // Klingons killed - killc, // commanders killed cx[QUADSIZE+1],cy[QUADSIZE+1], // Commander quadrant coordinates baseqx[BASEMAX+1], // Base quadrant X baseqy[BASEMAX+1], // Base quadrant Y isx, isy, // Coordinate of Super Commander - nscrem, // remaining super commanders - nromkl, // Romulans killed nromrem, // Romulans remaining - nsckill, // super commanders killed nplankl; // destroyed planets planet plnets[PLNETMAX]; // Planet information double date, // stardate @@ -80,6 +76,14 @@ typedef struct { } chart[GALSIZE+1][GALSIZE+1]; // the starchart (subscript 0 not used) } snapshot; // Data that is snapshot +#define NKILLK (inkling - game.state.remkl) +#define NKILLC (incom - game.state.remcom) +#define NKILLSC (inscom - game.state.nscrem) +#define NKILLROM (inrom - game.state.nromrem) +#define KLINGREM (game.state.remkl + game.state.remcom + game.state.nscrem) +#define INKLINGTOT (inkling + incom + inscom) +#define KLINGKILLED (INKLINGTOT - KLINGREM) + #define SKILL_NONE 0 #define SKILL_NOVICE 1 #define SKILL_FAIR 2 @@ -158,6 +162,8 @@ EXTERN struct { int inkling, inbase, incom, + inscom, + inrom, instar, intorps, condit, @@ -246,6 +252,8 @@ EXTERN struct { #define inkling game.inkling // Initial number of klingons #define inbase game.inbase // Initial number of bases #define incom game.incom // Initian number of commanders +#define inscom game.inscom // Initian number of commanders +#define inrom game.inrom // Initian number of commanders #define instar game.instar // Initial stars #define intorps game.intorps // Initial/Max torpedoes #define condit game.condit // Condition (red/yellow/green/docked)