Esempio n. 1
0
File: reports.c Progetto: aichao/sst
void attakreport(void) {
	if (future[FCDBAS] < 1e30) {
		proutn("Starbase in ");
		cramlc(1, batx, baty);
		prout(" is currently under attack.");
		proutn("It can hold out until Stardate ");
		cramf(future[FCDBAS], 0,1);
		prout(".");
	}
	if (isatb == 1) {
		proutn("Starbase in ");
		cramlc(1, d.isx, d.isy);
		prout(" is under Super-commander attack.");
		proutn("It can hold out until Stardate ");
		cramf(future[FSCDBAS], 0, 1);
		prout(".");
	}
}
Esempio n. 2
0
File: events.c Progetto: aichao/sst
void waiting(void) {
	int key;
	double temp, delay, origTime;

	ididit = 0;
	for (;;) {
		key = scan();
		if (key  != IHEOL) break;
		proutn("How long? ");
	}
	chew();
	if (key != IHREAL) {
		huh();
		return;
	}
	origTime = delay = aaitem;
	if (delay <= 0.0) return;
	if (delay >= d.remtime || nenhere != 0) {
		prout("Are you sure? ");
		if (ja() == 0) return;
	}

	/* Alternate resting periods (events) with attacks */

	resting = 1;
	do {
		if (delay <= 0) resting = 0;
		if (resting == 0) {
			cramf(d.remtime, 0, 2);
			prout(" stardates left.");
			return;
		}
		temp = Time = delay;

		if (nenhere) {
			double rtime = 1.0 + Rand();
			if (rtime < temp) temp = rtime;
			Time = temp;
		}
		if (Time < delay) attack(0);
		if (nenhere==0) movetho();
		if (alldone) return;
		events();
		ididit = 1;
		if (alldone) return;
		delay -= temp;
		/* Repair Deathray if long rest at starbase */
		if (origTime-delay >= 9.99 && condit == IHDOCKED)
			damage[DDRAY] = 0.0;
	} while (d.galaxy[quadx][quady] != 1000); // leave if quadrant supernovas

	resting = 0;
	Time = 0;
}
Esempio n. 3
0
File: reports.c Progetto: aichao/sst
void dreprt(void) {
	int jdam = FALSE, i;
	chew();

	for (i = 1; i <= ndevice; i++) {
		if (damage[i] > 0.0) {
			if (!jdam) {
				skip(1);
				prout("DEVICE            -REPAIR TIMES-");
				prout("                IN FLIGHT   DOCKED");
				jdam = TRUE;
			}
			printf("  %16s ", device[i]);
			cramf(damage[i]+0.05, 8, 2);
			proutn("  ");
			cramf(docfac*damage[i]+0.005, 8, 2);
			skip(1);
		}
	}
	if (!jdam) prout("All devices functional.");
}
Esempio n. 4
0
File: reports.c Progetto: aichao/sst
void chart(int nn) {
	int i,j;

	chew();
	skip(1);
	if (stdamtim != 1e30 && stdamtim != d.date && condit == IHDOCKED) {
		prout("Spock-  \"I revised the Star Chart from the");
		prout("  starbase's records.\"");
		skip(1);
	}
	if (nn == 0) prout("STAR CHART FOR THE KNOWN GALAXY");
	if (stdamtim != 1e30) {
		if (condit == IHDOCKED) {
			/* We are docked, so restore chart from base information */
			stdamtim = d.date;
			for (i=1; i <= 8 ; i++)
				for (j=1; j <= 8; j++)
					if (starch[i][j] == 1) starch[i][j] = d.galaxy[i][j]+1000;
		}
		else {
			proutn("(Last surveillance update ");
			cramf(d.date-stdamtim, 0, 1);
			prout(" stardates ago.)");
		}
	}
	if (nn ==0) skip(1);

	prout("      1    2    3    4    5    6    7    8");
	prout("    ----------------------------------------");
	if (nn==0) prout("  -");
	for (i = 1; i <= 8; i++) {
		printf("%d -", i);
		for (j = 1; j <= 8; j++) {
			if (starch[i][j] < 0)
				printf("  .1.");
			else if (starch[i][j] == 0)
				printf("  ...");
			else if (starch[i][j] > 999)
				printf("%5d", starch[i][j]-1000);
			else
				printf("%5d", d.galaxy[i][j]);
		}
		prout("  -");
	}
	if (nn == 0) {
		skip(1);
		crmshp();
		proutn(" is currently in");
		cramlc(1, quadx, quady);
		skip(1);
	}
}
Esempio n. 5
0
File: ai.c Progetto: aichao/sst
static void movebaddy(int comx, int comy, int loccom, int ienm) {
	int motion, mdist, nsteps, mx, my, nextx, nexty, lookx, looky, ll;
	int irun = 0;
	int krawlx, krawly;
	int success;
	int attempts;
	/* This should probably be just comhere + ishere */
	int nbaddys = skill > 3 ?
				  (int)((comhere*2 + ishere*2+klhere*1.23+irhere*1.5)/2.0):
				  (comhere + ishere);
	double dist1, forces;

	dist1 = kdist[loccom];
	mdist = dist1 + 0.5; /* Nearest integer distance */

	/* If SC, check with spy to see if should hi-tail it */
	if (ienm==IHS &&
		(kpower[loccom] <= 500.0 || (condit==IHDOCKED && damage[DPHOTON]==0))) {
		irun = 1;
		motion = -10;
	}
	else {
		/* decide whether to advance, retreat, or hold position */
/* Algorithm:
   * Enterprise has "force" based on condition of phaser and photon torpedoes.
     If both are operating full strength, force is 1000. If both are damaged,
	 force is -1000. Having shields down subtracts an additional 1000.

   * Enemy has forces equal to the energy of the attacker plus
     100*(K+R) + 500*(C+S) - 400 for novice through good levels OR
	 346*K + 400*R + 500*(C+S) - 400 for expert and emeritus.

	 Attacker Initial energy levels (nominal):
	          Klingon   Romulan   Commander   Super-Commander
	 Novice    400        700        1200        
	 Fair      425        750        1250
	 Good      450        800        1300        1750
	 Expert    475        850        1350        1875
	 Emeritus  500        900        1400        2000
     VARIANCE   75        200         200         200

	 Enemy vessels only move prior to their attack. In Novice - Good games
	 only commanders move. In Expert games, all enemy vessels move if there
	 is a commander present. In Emeritus games all enemy vessels move.

  *  If Enterprise is not docked, an agressive action is taken if enemy
     forces are 1000 greater than Enterprise.

	 Agressive action on average cuts the distance between the ship and
	 the enemy to 1/4 the original.

  *  At lower energy advantage, movement units are proportional to the
     advantage with a 650 advantage being to hold ground, 800 to move forward
	 1, 950 for two, 150 for back 4, etc. Variance of 100.

	 If docked, is reduced by roughly 1.75*skill, generally forcing a
	 retreat, especially at high skill levels.

  *  Motion is limited to skill level, except for SC hi-tailing it out.
  */

		forces = kpower[loccom]+100.0*nenhere+400*(nbaddys-1);
		if (shldup==0) forces += 1000; /* Good for enemy if shield is down! */
		if (damage[DPHASER] == 0.0 || damage[DPHOTON] == 0.0) {
			if (damage[DPHASER] != 0) /* phasers damaged */
				forces += 300.0;
			else
				forces -= 0.2*(energy - 2500.0);
			if (damage[DPHOTON] != 0) /* photon torpedoes damaged */
				forces += 300.0;
			else
				forces -= 50.0*torps;
		}
		else {
			/* phasers and photon tubes both out! */
			forces += 1000.0;
		}
		motion = 0;
		if (forces <= 1000.0 && condit != IHDOCKED) /* Typical situation */
			motion = ((forces+200.0*Rand())/150.0) - 5.0;
		else {
			if (forces > 1000.0) /* Very strong -- move in for kill */
				motion = (1.0-square(Rand()))*dist1 + 1.0;
			if (condit==IHDOCKED) /* protected by base -- back off ! */
				motion -= skill*(2.0-square(Rand()));
		}
#ifdef DEBUG
		if (idebug) {
			proutn("MOTION = ");
			cramf(motion, 1, 2);
            proutn("  FORCES = ");
			cramf(forces, 1, 2);
			skip(1);
		}
#endif
		/* don't move if no motion */
		if (motion==0) return;
		/* Limit motion according to skill */
		if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
	}
	/* calcuate preferred number of steps */
	nsteps = motion < 0 ? -motion : motion;
	if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
	if (nsteps > 10) nsteps = 10; /* This shouldn't be necessary */
	if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
#ifdef DEBUG
	if (idebug) {
		proutn("NSTEPS = ");
		crami(nsteps, 1);
		skip(1);
	}
#endif
	/* Compute preferred values of delta X and Y */
	mx = sectx - comx;
	my = secty - comy;
	if (2.0 * abs(mx) < abs(my)) mx = 0;
	if (2.0 * abs(my) < abs(sectx-comx)) my = 0;
	if (mx != 0) mx = mx*motion < 0 ? -1 : 1;
	if (my != 0) my = my*motion < 0 ? -1 : 1;
	nextx = comx;
	nexty = comy;
	quad[comx][comy] = IHDOT;
	/* main move loop */
	for (ll = 1; ll <= nsteps; ll++) {
#ifdef DEBUG
		if (idebug) {
			crami(ll,2);
			skip(1);
		}
#endif
		/* Check if preferred position available */
		lookx = nextx + mx;
		looky = nexty + my;
		krawlx = mx < 0 ? 1 : -1;
		krawly = my < 0 ? 1 : -1;
		success = 0;
		attempts = 0; /* Settle mysterious hang problem */
		while (attempts++ < 20 && !success) {
			if (lookx < 1 || lookx > 10) {
				if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
					return;
				if (krawlx == mx || my == 0) break;
				lookx = nextx + krawlx;
				krawlx = -krawlx;
			}
			else if (looky < 1 || looky > 10) {
				if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
					return;
				if (krawly == my || mx == 0) break;
				looky = nexty + krawly;
				krawly = -krawly;
			}
			else if (quad[lookx][looky] != IHDOT) {
				/* See if we should ram ship */
				if (quad[lookx][looky] == ship &&
					(ienm == IHC || ienm == IHS)) {
					ram(1, ienm, comx, comy);
					return;
				}
				if (krawlx != mx && my != 0) {
					lookx = nextx + krawlx;
					krawlx = -krawlx;
				}
				else if (krawly != my && mx != 0) {
					looky = nexty + krawly;
					krawly = -krawly;
				}
				else break; /* we have failed */
			}
			else success = 1;
		}
		if (success) {
			nextx = lookx;
			nexty = looky;
#ifdef DEBUG
			if (idebug) {
				cramlc(0, nextx, nexty);
				skip(1);
			}
#endif
		}
		else break; /* done early */
	}
	/* Put commander in place within same quadrant */
	quad[nextx][nexty] = ienm;
	if (nextx != comx || nexty != comy) {
		/* it moved */
		kx[loccom] = nextx;
		ky[loccom] = nexty;
		kdist[loccom] = kavgd[loccom] =
					sqrt(square(sectx-nextx)+square(secty-nexty));
		if (damage[DSRSENS] == 0 || condit == IHDOCKED) {
			proutn("***");
			cramen(ienm);
			if (kdist[loccom] < dist1) proutn(" advances to");
			else proutn(" retreats to");
			cramlc(2, nextx, nexty);
			skip(1);
		}
	}
}
Esempio n. 6
0
File: ai.c Progetto: aichao/sst
void scom(int *ipage) {
	int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb;
	int iqx, iqy;
	int basetbl[6];
	double bdist[6];
	int flag;
#ifdef DEBUG
	if (idebug) prout("SCOM");
#endif

	/* Decide on being active or passive */
	flag = ((d.killc+d.killk)/(d.date+0.01-indate) < 0.1*skill*(skill+1.0) ||
			(d.date-indate) < 3.0);
	if (iscate==0 && flag) {
		/* compute move away from Enterprise */
		ideltax = d.isx-quadx;
		ideltay = d.isy-quady;
		if (sqrt(ideltax*(double)ideltax+ideltay*(double)ideltay) > 2.0) {
			/* circulate in space */
			ideltax = d.isy-quady;
			ideltay = quadx-d.isx;
		}
	}
	else {
		/* compute distances to starbases */
		if (d.rembase <= 0) {
			/* nothing left to do */
			future[FSCMOVE] = 1e30;
			return;
		}
		sx = d.isx;
		sy = d.isy;
		for (i = 1; i <= d.rembase; i++) {
			basetbl[i] = i;
			ibqx = d.baseqx[i];
			ibqy = d.baseqy[i];
			bdist[i] = sqrt(square(ibqx-sx) + square(ibqy-sy));
		}
		if (d.rembase > 1) {
			/* sort into nearest first order */
			int iswitch;
			do {
				iswitch = 0;
				for (i=1; i < d.rembase-1; i++) {
					if (bdist[i] > bdist[i+1]) {
						int ti = basetbl[i];
						double t = bdist[i];
						bdist[i] = bdist[i+1];
						bdist[i+1] = t;
						basetbl[i] = basetbl[i+1];
						basetbl[i+1] =ti;
						iswitch = 1;
					}
				}
			} while (iswitch);
		}
		/* look for nearest base without a commander, no Enterprise, and
		   without too many Klingons, and not already under attack. */
		ifindit = iwhichb = 0;

		for (i2 = 1; i2 <= d.rembase; i2++) {
			i = basetbl[i2];	/* bug in original had it not finding nearest*/
			ibqx = d.baseqx[i];
			ibqy = d.baseqy[i];
			if ((ibqx == quadx && ibqy == quady) ||
				(ibqx == batx && ibqy == baty) ||
				d.galaxy[ibqx][ibqy] > 899) continue;
			/* if there is a commander, an no other base is appropriate,
			   we will take the one with the commander */
			for (j = 1; j <= d.remcom; j++) {
				if (ibqx==d.cx[j] && ibqy==d.cy[j] && ifindit!= 2) {
						ifindit = 2;
						iwhichb = i;
						break;
				}
			}
			if (j > d.remcom) { /* no commander -- use this one */
				ifindit = 1;
				iwhichb = i;
				break;
			}
		}
		if (ifindit==0) return; /* Nothing suitable -- wait until next time*/
		ibqx = d.baseqx[iwhichb];
		ibqy = d.baseqy[iwhichb];
		/* decide how to move toward base */
		ideltax = ibqx - d.isx;
		ideltay = ibqy - d.isy;
	}
	/* Maximum movement is 1 quadrant in either or both axis */
	if (ideltax > 1) ideltax = 1;
	if (ideltax < -1) ideltax = -1;
	if (ideltay > 1) ideltay = 1;
	if (ideltay < -1) ideltay = -1;

	/* try moving in both x and y directions */
	iqx = d.isx + ideltax;
	iqy = d.isy + ideltax;
	if (checkdest(iqx, iqy, flag, ipage)) {
		/* failed -- try some other maneuvers */
		if (ideltax==0 || ideltay==0) {
			/* attempt angle move */
			if (ideltax != 0) {
				iqy = d.isy + 1;
				if (checkdest(iqx, iqy, flag, ipage)) {
					iqy = d.isy - 1;
					checkdest(iqx, iqy, flag, ipage);
				}
			}
			else {
				iqx = d.isx + 1;
				if (checkdest(iqx, iqy, flag, ipage)) {
					iqx = d.isx - 1;
					checkdest(iqx, iqy, flag, ipage);
				}
			}
		}
		else {
			/* try moving just in x or y */
			iqy = d.isy;
			if (checkdest(iqx, iqy, flag, ipage)) {
				iqy = d.isy + ideltay;
				iqx = d.isx;
				checkdest(iqx, iqy, flag, ipage);
			}
		}
	}
	/* check for a base */
	if (d.rembase == 0) {
		future[FSCMOVE] = 1e30;
	}
	else for (i=1; i<=d.rembase; i++) {
		ibqx = d.baseqx[i];
		ibqy = d.baseqy[i];
		if (ibqx==d.isx && ibqy == d.isy && d.isx != batx && d.isy != baty) {
			/* attack the base */
			if (flag) return; /* no, don't attack base! */
			iseenit = 0;
			isatb=1;
			future[FSCDBAS] = d.date + 1.0 +2.0*Rand();
			if (batx != 0) future[FSCDBAS] += future[FCDBAS]-d.date;
			if (damage[DRADIO] > 0 && condit != IHDOCKED)
				return; /* no warning */
			iseenit = 1;
			if (*ipage == 0)  pause(1);
			*ipage=1;
			proutn("Lt. Uhura-  \"Captain, the starbase in");
			cramlc(1, d.isx, d.isy);
			skip(1);
			prout("   reports that it is under attack from the Klingon Super-commander.");
			proutn("   It can survive until stardate ");
			cramf(future[FSCDBAS], 0, 1);
			prout(" .\"");
			if (resting==0) return;
			prout("Mr. Spock-  \"Captain, shall we cancel the rest period?\"");
			if (ja()==0) return;
			resting = 0;
			Time = 0.0; /* actually finished */
			return;
		}
	}
	/* Check for intelligence report */
	if (
#ifdef DEBUG
		idebug==0 &&
#endif
		(Rand() > 0.2 ||
		 (damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
		 starch[d.isx][d.isy] > 0))
		return;
	if (*ipage==0) pause(1);
	*ipage = 1;
	prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");
	proutn("   the Super-commander is in");
	cramlc(1, d.isx, d.isy);
	prout(".\"");
	return;
}
Esempio n. 7
0
void debugme(void) {
	proutn("Reset levels? ");
	if (ja() != 0) {
		if (energy < inenrg) energy = inenrg;
		shield = inshld;
		torps = intorps;
		lsupres = inlsr;
	}
	proutn("Reset damage? ");
	if (ja() != 0) {
		int i;
		for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0;
		stdamtim = 1e30;
	}
	proutn("Toggle idebug? ");
	if (ja() != 0) {
		idebug = !idebug;
		if (idebug) prout("Debug output ON");
		else prout("Debug output OFF");
	}
	proutn("Cause selective damage? ");
	if (ja() != 0) {
		int i, key;
		for (i=1; i <= ndevice; i++) {
			proutn("Kill ");
			proutn(device[i]);
			proutn("? ");
			chew();
			key = scan();
			if (key == IHALPHA &&  isit("y")) {
				damage[i] = 10.0;
				if (i == DRADIO) stdamtim = d.date;
			}
		}
	}
	proutn("Examine/change events? ");
	if (ja() != 0) {
		int i;
		for (i = 1; i < NEVENTS; i++) {
			int key;
			if (future[i] == 1e30) continue;
			switch (i) {
				case FSNOVA:  proutn("Supernova       "); break;
				case FTBEAM:  proutn("T Beam          "); break;
				case FSNAP:   proutn("Snapshot        "); break;
				case FBATTAK: proutn("Base Attack     "); break;
				case FCDBAS:  proutn("Base Destroy    "); break;
				case FSCMOVE: proutn("SC Move         "); break;
				case FSCDBAS: proutn("SC Base Destroy "); break;
			}
			cramf(future[i]-d.date, 8, 2);
			chew();
			proutn("  ?");
			key = scan();
			if (key == IHREAL) {
				future[i] = d.date + aaitem;
			}
		}
		chew();
	}
	proutn("Make universe visible? ");
	if (ja() != 0) {
		int i, j;
		for (i = 1; i < 9; i++) 
		{
			for (j = 1; j < 9; j++)
			{
				starch[i][j] = 1;
			}
		}
	}
}
Esempio n. 8
0
File: events.c Progetto: aichao/sst
void snova(int insx, int insy) {
	int comdead, nqx, nqy, nsx, nsy, num, kldead, iscdead;
	int nrmdead, npdead;
	int insipient=0;

	nsx = insy;
	nsy = insy;

	if (insy== 0) {
		if (insx == 1) {
			/* NOVAMAX being used */
			nqx = probecx;
			nqy = probecy;
		}
		else {
			int stars = 0;
			/* Scheduled supernova -- select star */
			/* logic changed here so that we won't favor quadrants in top
			left of universe */
			for (nqx = 1; nqx<=8; nqx++) {
				for (nqy = 1; nqy<=8; nqy++) {
					stars += d.galaxy[nqx][nqy] % 10;
				}
			}
			if (stars == 0) return; /* nothing to supernova exists */
			num = Rand()*stars + 1;
			for (nqx = 1; nqx<=8; nqx++) {
				for (nqy = 1; nqy<=8; nqy++) {
					num -= d.galaxy[nqx][nqy] % 10;
					if (num <= 0) break;
				}
				if (num <=0) break;
			}
#ifdef DEBUG
			if (idebug) {
				proutn("Super nova here?");
				if (ja()==1) {
					nqx = quadx;
					nqy = quady;
				}
			}
#endif
		}

		if (nqx != quady || nqy != quady || justin != 0) {
			/* it isn't here, or we just entered (treat as inroute) */
			if (damage[DRADIO] == 0.0 || condit == IHDOCKED) {
				skip(1);
				proutn("Message from Starfleet Command       Stardate ");
				cramf(d.date, 0, 1);
				skip(1);
				proutn("     Supernova in");
				cramlc(1, nqx, nqy);
				prout("; caution advised.");
			}
		}
		else {
			/* we are in the quadrant! */
			insipient = 1;
			num = Rand()* (d.galaxy[nqx][nqy]%10) + 1;
			for (nsx=1; nsx < 10; nsx++) {
				for (nsy=1; nsy < 10; nsy++) {
					if (quad[nsx][nsy]==IHSTAR) {
						num--;
						if (num==0) break;
					}
				}
				if (num==0) break;
			}
		}
	}
	else {
		insipient = 1;
	}

	if (insipient) {
		skip(1);
		prouts("***RED ALERT!  RED ALERT!");
		skip(1);
		proutn("***Incipient supernova detected at");
		cramlc(2, nsx, nsy);
		skip(1);
		nqx = quadx;
		nqy = quady;
		if (square(nsx-sectx) + square(nsy-secty) <= 2.1) {
			proutn("Emergency override attempts t");
			prouts("***************");
			skip(1);
			stars();
			alldone=1;
		}
	}
	/* destroy any Klingons in supernovaed quadrant */
	num=d.galaxy[nqx][nqy];
	kldead = num/100;
	comdead = iscdead = 0;
	if (nqx==d.isx && nqy == d.isy) {
		/* did in the Supercommander! */
		d.nscrem = d.isx = d.isy = isatb = iscate = 0;
		iscdead = 1;
		future[FSCMOVE] = future[FSCDBAS] = 1e30;
	}
	d.remkl -= kldead;
	if (d.remcom) {
		int maxloop = d.remcom, l;
		for (l = 1; l <= maxloop; l++) {
			if (d.cx[l] == nqx && d.cy[l] == nqy) {
				d.cx[l] = d.cx[d.remcom];
				d.cy[l] = d.cy[d.remcom];
				d.cx[d.remcom] = d.cy[d.remcom] = 0;
				d.remcom--;
				kldead--;
				comdead++;
				if (d.remcom==0) future[FTBEAM] = 1e30;
				break;
			}
		}
	}
	/* destroy Romulans and planets in supernovaed quadrant */
	num = d.newstuf[nqx][nqy];
	d.newstuf[nqx][nqy] = 0;
	nrmdead = num/10;
	d.nromrem -= nrmdead;
	npdead = num - nrmdead*10;
	if (npdead) {
		int l;
		for (l = 1; l <= inplan; l++)
			if (d.plnets[l].x == nqx && d.plnets[l].y == nqy) {
				d.plnets[l] = nulplanet;
			}
	}
	/* Destroy any base in supernovaed quadrant */
	if (d.rembase) {
		int maxloop = d.rembase, l;
		for (l = 1; l <= maxloop; l++)
			if (d.baseqx[l]==nqx && d.baseqy[l]==nqy) {
				d.baseqx[l] = d.baseqx[d.rembase];
				d.baseqy[l] = d.baseqy[d.rembase];
				d.baseqx[d.rembase] = d.baseqy[d.rembase] = 0;
				d.rembase--;
				break;
			}
	}
	/* If starship caused supernova, tally up destruction */
	if (insx) {
		num = d.galaxy[nqx][nqy] % 100;
		d.starkl += num % 10;
		d.basekl += num/10;
		d.killk += kldead;
		d.killc += comdead;
		d.nromkl += nrmdead;
		d.nplankl += npdead;
		d.nsckill += iscdead;
	}
	/* mark supernova in galaxy and in star chart */
	if ((quadx == nqx && quady == nqy) ||
		damage[DRADIO] == 0 ||
		condit == IHDOCKED)
		starch[nqx][nqy] = 1;
	d.galaxy[nqx][nqy] = 1000;
	/* If supernova destroys last klingons give special message */
	if (d.remkl==0 && (nqx != quadx || nqy != quady)) {
		skip(2);
		if (insx == 0) prout("Lucky you!");
		proutn("A supernova in");
		cramlc(1, nqx, nqy);
		prout(" has just destroyed the last Klingons.");
		finish(FWON);
		return;
	}
	/* if some Klingons remain, continue or die in supernova */
	if (alldone) finish(FSNOVAED);
	return;
}
Esempio n. 9
0
File: events.c Progetto: aichao/sst
void events(void) {

	int ictbeam=0, ipage=0, istract=0, line, i, j, k, l, ixhold, iyhold;
	double fintim = d.date + Time, datemin, xtime, repair, yank;
	

#ifdef DEBUG
	if (idebug) prout("EVENTS");
#endif

	if (stdamtim == 1e30 && damage[DRADIO] != 0.0) {
		/* chart will no longer be updated because radio is dead */
		stdamtim = d.date;
		for (i=1; i <= 8 ; i++)
			for (j=1; j <= 8; j++)
				if (starch[i][j] == 1) starch[i][j] = d.galaxy[i][j]+1000;
	}

	for (;;) {
		/* Select earliest extraneous event, line==0 if no events */
		line = FSPY;
		if (alldone) return;
		datemin = fintim;
		for (l=1; l<=NEVENTS; l++)
			if (future[l] <= datemin) {
				line = l;
				datemin = future[l];
			}
		xtime = datemin-d.date;
		d.date = datemin;
		/* Decrement Federation resources and recompute remaining time */
		d.remres -= (d.remkl+4*d.remcom)*xtime;
		d.remtime = d.remres/(d.remkl+4*d.remcom);
		if (d.remtime <=0) {
			finish(FDEPLETE);
			return;
		}
		/* Is life support adequate? */
		if (damage[DLIFSUP] && condit != IHDOCKED) {
			if (lsupres < xtime && damage[DLIFSUP] > lsupres) {
				finish(FLIFESUP);
				return;
			}
			lsupres -= xtime;
			if (damage[DLIFSUP] <= xtime) lsupres = inlsr;
		}
		/* Fix devices */
		repair = xtime;
		if (condit == IHDOCKED) repair /= docfac;
		/* Don't fix Deathray here */
		for (l=1; l<=ndevice; l++)
			if (damage[l] > 0.0 && l != DDRAY)
				damage[l] -= (damage[l]-repair > 0.0 ? repair : damage[l]);
		/* If radio repaired, update star chart and attack reports */
		if (stdamtim != 1e30 && damage[DRADIO] == 0.0) {
			stdamtim = 1e30;
			prout("Lt. Uhura- \"Captain, the sub-space radio is working and");
			prout("   surveillance reports are coming in.");
			skip(1);
			for (i=1; i <= 8 ; i++)
				for (j=1; j <= 8; j++)
					if (starch[i][j] > 999) starch[i][j] = 1;
			if (iseenit==0) {
				attakreport();
				iseenit = 1;
			}
			skip(1);
			prout("   The star chart is now up to date.\"");
			skip(1);
		}
		/* Cause extraneous event LINE to occur */
		Time -= xtime;
		switch (line) {
			case FSNOVA: /* Supernova */
				if (ipage==0) pause(1);
				ipage=1;
				snova(0,0);
				future[FSNOVA] = d.date + expran(0.5*intime);
				if (d.galaxy[quadx][quady] == 1000) return;
				break;
			case FSPY: /* Check with spy to see if S.C. should tractor beam */
				if (d.nscrem == 0 ||
					ictbeam+istract > 0 ||
					condit==IHDOCKED || isatb==1 || iscate==1) return;
				if (ientesc ||
					(energy < 2000 && torps < 4 && shield < 1250) ||
					(damage[DPHASER]>0 && (damage[DPHOTON]>0 || torps < 4)) ||
					(damage[DSHIELD] > 0 &&
					 (energy < 2500 || damage[DPHASER] > 0) &&
					 (torps < 5 || damage[DPHOTON] > 0))) {
					/* Tractor-beam her! */
					istract=1;
					yank = square(d.isx-quadx) + square(d.isy-quady);
					/*********TBEAM CODE***********/
				}
				else return;
			case FTBEAM: /* Tractor beam */
				if (line==FTBEAM) {
					if (d.remcom == 0) {
						future[FTBEAM] = 1e30;
						break;
					}
					i = Rand()*d.remcom+1.0;
					yank = square(d.cx[i]-quadx) + square(d.cy[i]-quady);
					if (istract || condit == IHDOCKED || yank == 0) {
						/* Drats! Have to reschedule */
						future[FTBEAM] = d.date + Time +
										 expran(1.5*intime/d.remcom);
						break;
					}
				}
				/* tractor beaming cases merge here */
				yank = sqrt(yank);
				if (ipage==0) pause(1);
				ipage=1;
				Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */
				ictbeam = 1;
				skip(1);
				proutn("***");
				crmshp();
				prout(" caught in long range tractor beam--");
				/* If Kirk & Co. screwing around on planet, handle */
				atover(1); /* atover(1) is Grab */
				if (alldone) return;
				if (icraft == 1) { /* Caught in Galileo? */
					finish(FSTRACTOR);
					return;
				}
				/* Check to see if shuttle is aboard */
				if (iscraft==0) {
					skip(1);
					if (Rand() >0.5) {
						prout("Galileo, left on the planet surface, is captured");
						prout("by aliens and made into a flying McDonald's.");
						damage[DSHUTTL] = -10;
						iscraft = -1;
					}
					else {
						prout("Galileo, left on the planet surface, is well hidden.");
					}
				}
				if (line==0) {
					quadx = d.isx;
					quady = d.isy;
				}
				else {
					quadx = d.cx[i];
					quady = d.cy[i];
				}
				iran10(&sectx, &secty);
				crmshp();
				proutn(" is pulled to");
				cramlc(1, quadx, quady);
				proutn(", ");
				cramlc(2, sectx, secty);
				skip(1);
				if (resting) {
					prout("(Remainder of rest/repair period cancelled.)");
					resting = 0;
				}
				if (shldup==0) {
					if (damage[DSHIELD]==0 && shield > 0) {
						sheild(2); /* Shldsup */
						shldchg=0;
					}
					else prout("(Shields not currently useable.)");
				}
				newqad(0);
				/* Adjust finish time to time of tractor beaming */
				fintim = d.date+Time;
				if (d.remcom <= 0) future[FTBEAM] = 1e30;
				else future[FTBEAM] = d.date+Time+expran(1.5*intime/d.remcom);
				break;
			case FSNAP: /* Snapshot of the universe (for time warp) */
				snapsht = d;
				d.snap = 1;
				future[FSNAP] = d.date + expran(0.5 * intime);
				break;
			case FBATTAK: /* Commander attacks starbase */
				if (d.remcom==0 || d.rembase==0) {
					/* no can do */
					future[FBATTAK] = future[FCDBAS] = 1e30;
					break;
				}
				i = 0;
				for (j=1; j<=d.rembase; j++) {
					for (k=1; k<=d.remcom; k++)
						if (d.baseqx[j]==d.cx[k] && d.baseqy[j]==d.cy[k] &&
							(d.baseqx[j]!=quadx || d.baseqy[j]!=quady) &&
							(d.baseqx[j]!=d.isx || d.baseqy[j]!=d.isy)) {
							i = 1;
							break;
						}
					if (i == 1) break;
				}
				if (j>d.rembase) {
					/* no match found -- try later */
					future[FBATTAK] = d.date + expran(0.3*intime);
					future[FCDBAS] = 1e30;
					break;
				}
				/* commander + starbase combination found -- launch attack */
				batx = d.baseqx[j];
				baty = d.baseqy[j];
				future[FCDBAS] = d.date+1.0+3.0*Rand();
				if (isatb) /* extra time if SC already attacking */
					future[FCDBAS] += future[FSCDBAS]-d.date;
				future[FBATTAK] = future[FCDBAS] +expran(0.3*intime);
				iseenit = 0;
				if (damage[DRADIO] != 0.0 &&
					condit != IHDOCKED) break; /* No warning :-( */
				iseenit = 1;
				if (ipage==0) pause(1);
				ipage = 1;
				skip(1);
				proutn("Lt. Uhura-  \"Captain, the starbase in");
				cramlc(1, batx, baty);
				skip(1);
				prout("   reports that it is under atttack and that it can");
				proutn("   hold out only until stardate ");
				cramf(future[FCDBAS],1,1);
				prout(".\"");
				if (resting) {
					skip(1);
					proutn("Mr. Spock-  \"Captain, shall we cancel the rest period?\"");
					if (ja()) {
						resting = 0;
						Time = 0.0;
						return;
					}
				}
				break;
			case FSCDBAS: /* Supercommander destroys base */
				future[FSCDBAS] = 1e30;
				isatb = 2;
				if (d.galaxy[d.isx][d.isy]%100 < 10) break; /* WAS RETURN! */
				ixhold = batx;
				iyhold = baty;
				batx = d.isx;
				baty = d.isy;
			case FCDBAS: /* Commander succeeds in destroying base */
				if (line==FCDBAS) {
					future[FCDBAS] = 1e30;
					/* find the lucky pair */
					for (i = 1; i <= d.remcom; i++)
						if (d.cx[i]==batx && d.cy[i]==baty) break;
					if (i > d.remcom || d.rembase == 0 ||
						d.galaxy[batx][baty] % 100 < 10) {
						/* No action to take after all */
						batx = baty = 0;
						break;
					}
				}
				/* Code merges here for any commander destroying base */
				/* Not perfect, but will have to do */
				if (starch[batx][baty] == -1) starch[batx][baty] = 0;
				/* Handle case where base is in same quadrant as starship */
				if (batx==quadx && baty==quady) {
					if (starch[batx][baty] > 999) starch[batx][baty] -= 10;
					quad[basex][basey]= IHDOT;
					basex=basey=0;
					newcnd();
					skip(1);
					prout("Spock-  \"Captain, I believe the starbase has been destroyed.\"");
				}
				else if (d.rembase != 1 &&
						 (damage[DRADIO] <= 0.0 || condit == IHDOCKED)) {
					/* Get word via subspace radio */
					if (ipage==0) pause(1);
					ipage = 1;
					skip(1);
					prout("Lt. Uhura-  \"Captain, Starfleet Command reports that");
					proutn("   the starbase in");
					cramlc(1, batx, baty);
					prout(" has been destroyed by");
					if (isatb==2) prout("the Klingon Super-Commander");
					else prout("a Klingon Commander");
				}
				/* Remove Starbase from galaxy */
				d.galaxy[batx][baty] -= 10;
				for (i=1; i <= d.rembase; i++)
					if (d.baseqx[i]==batx && d.baseqy[i]==baty) {
						d.baseqx[i]=d.baseqx[d.rembase];
						d.baseqy[i]=d.baseqy[d.rembase];
					}
				d.rembase--;
				if (isatb == 2) {
					/* reinstate a commander's base attack */
					batx = ixhold;
					baty = iyhold;
					isatb = 0;
				}
				else {
					batx = baty = 0;
				}
				break;
			case FSCMOVE: /* Supercommander moves */
				future[FSCMOVE] = d.date+0.2777;
				if (ientesc+istract==0 &&
					isatb!=1 &&
					(iscate!=1 || justin==1)) scom(&ipage);
				break;
			case FDSPROB: /* Move deep space probe */
				future[FDSPROB] = d.date + 0.01;
				probex += probeinx;
				probey += probeiny;
				i = (int)(probex/10 +0.05);
				j = (int)(probey/10 + 0.05);
				if (probecx != i || probecy != j) {
					probecx = i;
					probecy = j;
					if (i < 1 || i > 8 || j < 1 || j > 8 ||
						d.galaxy[probecx][probecy] == 1000) {
						// Left galaxy or ran into supernova
						if (damage[DRADIO]==0.0 || condit == IHDOCKED) {
							if (ipage==0) pause(1);
							ipage = 1;
							skip(1);
							proutn("Lt. Uhura-  \"The deep space probe ");
							if (i < 1 ||i > 8 || j < 1 || j > 8)
								proutn("has left the galaxy");
							else
								proutn("is no longer transmitting");
							prout(".\"");
						}
						future[FDSPROB] = 1e30;
						break;
					}
					if (damage[DRADIO]==0.0   || condit == IHDOCKED) {
						if (ipage==0) pause(1);
						ipage = 1;
						skip(1);
						proutn("Lt. Uhura-  \"The deep space probe is now in ");
						cramlc(1, probecx, probecy);
						prout(".\"");
					}
				}
				/* Update star chart if Radio is working or have access to
				   radio. */
				if (damage[DRADIO] == 0.0 || condit == IHDOCKED)
					starch[probecx][probecy] = damage[DRADIO] > 0.0 ?
										   d.galaxy[probecx][probecy]+1000 : 1;
				proben--; // One less to travel
				if (proben == 0 && isarmed &&
					d.galaxy[probecx][probecy] % 10 > 0) {
					/* lets blow the sucker! */
					snova(1,0);
					future[FDSPROB] = 1e30;
					if (d.galaxy[quadx][quady] == 1000) return;
				}
				break;
		}
	}
}
Esempio n. 10
0
File: reports.c Progetto: aichao/sst
void eta(void) {
	int key, ix1, ix2, iy1, iy2, prompt=FALSE;
	int wfl;
	double ttime, twarp, tpower;
	if (damage[DCOMPTR] != 0.0) {
		prout("COMPUTER DAMAGED, USE A POCKET CALCULATOR.");
		skip(1);
		return;
	}
	if (scan() != IHREAL) {
		prompt = TRUE;
		chew();
		proutn("Destination quadrant and/or sector? ");
		if (scan()!=IHREAL) {
			huh();
			return;
		}
	}
	iy1 = aaitem +0.5;
	if (scan() != IHREAL) {
		huh();
		return;
	}
	ix1 = aaitem + 0.5;
	if (scan() == IHREAL) {
		iy2 = aaitem + 0.5;
		if (scan() != IHREAL) {
			huh();
			return;
		}
		ix2 = aaitem + 0.5;
	}
	else {	// same quadrant
		ix2 = ix1;
		iy2 = iy1;
		ix1 = quady;	// ya got me why x and y are reversed!
		iy1 = quadx;
	}

	if (ix1 > 8 || ix1 < 1 || iy1 > 8 || iy1 < 1 ||
		ix2 > 10 || ix2 < 1 || iy2 > 10 || iy2 < 1) {
		huh();
		return;
	}
	dist = sqrt(square(iy1-quadx+0.1*(iy2-sectx))+
				square(ix1-quady+0.1*(ix2-secty)));
	wfl = FALSE;

	if (prompt) prout("Answer \"no\" if you don't know the value:");
	while (TRUE) {
		chew();
		proutn("Time or arrival date? ");
		if (scan()==IHREAL) {
			ttime = aaitem;
			if (ttime > d.date) ttime -= d.date; // Actually a star date
			if (ttime <= 1e-10 ||
				(twarp=(floor(sqrt((10.0*dist)/ttime)*10.0)+1.0)/10.0) > 10) {
				prout("We'll never make it, sir.");
				chew();
				return;
			}
			if (twarp < 1.0) twarp = 1.0;
			break;
		}
		chew();
		proutn("Warp factor? ");
		if (scan()== IHREAL) {
			wfl = TRUE;
			twarp = aaitem;
			if (twarp<1.0 || twarp > 10.0) {
				huh();
				return;
			}
			break;
		}
		prout("Captain, certainly you can give me one of these.");
	}
	while (TRUE) {
		chew();
		ttime = (10.0*dist)/square(twarp);
		tpower = dist*twarp*twarp*twarp*(shldup+1);
		if (tpower >= energy) {
			prout("Insufficient energy, sir.");
			if (shldup==0 || tpower > energy*2.0) {
				if (!wfl) return;
				proutn("New warp factor to try? ");
				if (scan() == IHREAL) {
					wfl = TRUE;
					twarp = aaitem;
					if (twarp<1.0 || twarp > 10.0) {
						huh();
						return;
					}
					continue;
				}
				else {
					chew();
					skip(1);
					return;
				}
			}
			prout("But if you lower your shields,");
			proutn("remaining");
			tpower /= 2;
		}
		else
			proutn("Remaining");
		proutn(" energy will be ");
		cramf(energy-tpower, 1, 1);
		prout(".");
		if (wfl) {
			proutn("And we will arrive at stardate ");
			cramf(d.date+ttime, 1, 1);
			prout(".");
		}
		else if (twarp==1.0)
			prout("Any warp speed is adequate.");
		else {
			proutn("Minimum warp needed is ");
			cramf(twarp, 1, 2);
			skip(1);
			proutn("and we will arrive at stardate ");
			cramf(d.date+ttime, 1, 2);
			prout(".");
		}
		if (d.remtime < ttime)
			prout("Unfortunately, the Federation will be destroyed by then.");
		if (twarp > 6.0)
			prout("You'll be taking risks at that speed, Captain");
		if ((isatb==1 && d.isy == ix1 && d.isx == iy1 &&
			 future[FSCDBAS]< ttime+d.date)||
			(future[FCDBAS]<ttime+d.date && baty==ix1 && batx == iy1))
			prout("The starbase there will be destroyed by then.");
		proutn("New warp factor to try? ");
		if (scan() == IHREAL) {
			wfl = TRUE;
			twarp = aaitem;
			if (twarp<1.0 || twarp > 10.0) {
				huh();
				return;
			}
		}
		else {
			chew();
			skip(1);
			return;
		}
	}
			
}