예제 #1
0
static int
randcourse(int n)
{
	double			r;
	int		d;

	d = ((franf() + franf()) - 1.0) * 20;
	if (abs(d) > 12) {
		printf("Photon tubes misfire");
		if (n < 0)
			printf("\n");
		else
			printf(" on torpedo %d\n", n);
		if (ranf(2)) {
			damage(TORPED, 0.2 * abs(d) * (franf() + 1.0));
		}
		d *= 1.0 + 2.0 * franf();
	}
	if (Ship.shldup || Ship.cond == DOCKED) {
		r = Ship.shield;
		r = 1.0 + r / Param.shield;
		if (Ship.cond == DOCKED)
			r = 2.0;
		d *= r;
	}
	return (d);
}
예제 #2
0
void
ram(int ix, int iy)
{
    int		i;
    char		c;

    printf("\07RED ALERT\07: collision imminent\n");
    c = Sect[ix][iy];
    switch (c) {

    case KLINGON:
        printf("%s rams Klingon at %d,%d\n", Ship.shipname, ix, iy);
        killk(ix, iy);
        break;

    case STAR:
    case INHABIT:
        printf("Yeoman Rand: Captain, isn't it getting hot in here?\n");
        sleep(2);
        printf("Spock: Hull temperature approaching 550 Degrees Kelvin.\n");
        lose(L_STAR);

    case BASE:
        printf("You ran into the starbase at %d,%d\n", ix, iy);
        killb(Ship.quadx, Ship.quady);
        /* don't penalize the captain if it wasn't his fault */
        if (!damaged(SINS))
            Game.killb += 1;
        break;
    }
    sleep(2);
    printf("%s heavily damaged\n", Ship.shipname);

    /* select the number of deaths to occur */
    i = 10 + ranf(20 * Game.skill);
    Game.deaths += i;
    Ship.crew -= i;
    printf("McCoy: Take it easy Jim; we had %d casualties.\n", i);

    /* damage devices with an 80% probability */
    for (i = 0; i < NDEV; i++) {
        if (ranf(100) < 20)
            continue;
        damage(i, (2.5 * (franf() + franf()) + 1.0) * Param.damfac[i]);
    }

    /* no chance that your shields remained up in all that */
    Ship.shldup = 0;
}
예제 #3
0
void
dumpme(int flag)
{
	int		f;
	double		x;
	struct event	*e;
	int		i;

	f = flag;
	Ship.quadx = ranf(NQUADS);
	Ship.quady = ranf(NQUADS);
	Ship.sectx = ranf(NSECTS);
	Ship.secty = ranf(NSECTS);
	x = 1.5 * franf();
	Move.time += x;
	if (f) {
		printf("%s falls into a black hole.\n", Ship.shipname);
	} else {
		printf("Computer applies full reverse power to avoid hitting "
		       "the\n");
		printf("   negative energy barrier.  A space warp was "
		       "entered.\n");
	}
	/* bump repair dates forward */
	for (i = 0; i < MAXEVENTS; i++) {
		e = &Event[i];
		if (e->evcode != E_FIXDV)
			continue;
		reschedule(e, (e->date - Now.date) + x);
	}
	events(1);
	printf("You are now in quadrant %d,%d.  It is stardate %.2f\n",
		Ship.quadx, Ship.quady, Now.date);
	Move.time = 0;
}
예제 #4
0
파일: schedule.c 프로젝트: a565109863/src
struct event *
xsched(int ev1, int factor, int x, int y, int z)
{
	int	ev;

	ev = ev1;
	return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
}
예제 #5
0
파일: schedule.c 프로젝트: a565109863/src
void
xresched(struct event *e1, int ev1, int factor)
{
	int		ev;
	struct event	*e;

	ev = ev1;
	e = e1;
	reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
}
예제 #6
0
autover()
{
	double			dist;
	register int		course;

	printf("\07RED ALERT:  The %s is in a supernova quadrant\n", Ship.shipname);
	printf("***  Emergency override attempts to hurl %s to safety\n", Ship.shipname);
	/* let's get our ass out of here */
	Ship.warp = 6.0 + 2.0 * franf();
	Ship.warp2 = Ship.warp * Ship.warp;
	Ship.warp3 = Ship.warp2 * Ship.warp;
	dist = 0.75 * Ship.energy / (Ship.warp3 * (Ship.shldup + 1));
	if (dist > 1.4142)
		dist = 1.4142;
	course = ranf(360);
	Etc.nkling = -1;
	Ship.cond = RED;
	warp(-1, course, dist);
	attack(0);
}
예제 #7
0
파일: attack.c 프로젝트: a565109863/src
/* argument is set if attack while resting */
void
attack(int resting)
{
	int	hit, i, l;
	int	maxhit, tothit, shldabsb;
	double	chgfac, propor, extradm;
	double	dustfac, tothe;
	int	cas;
	int	hitflag;

	if (Move.free)
		return;
	if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
		return;
	if (Ship.cloaked && Ship.cloakgood)
		return;
	/* move before attack */
	klmove(0);
	if (Ship.cond == DOCKED)
	{
		if (!resting)
			printf("Starbase shields protect the %s\n", Ship.shipname);
		return;
	}
	/* setup shield effectiveness */
	chgfac = 1.0;
	if (Move.shldchg)
		chgfac = 0.25 + 0.50 * franf();
	maxhit = tothit = 0;
	hitflag = 0;

	/* let each Klingon do his damndest */
	for (i = 0; i < Etc.nkling; i++)
	{
		/* if he's low on power he won't attack */
		if (Etc.klingon[i].power < 20)
			continue;
		if (!hitflag)
		{
			printf("\nStardate %.2f: Klingon attack:\n",
				Now.date);
			hitflag++;
		}
		/* complete the hit */
		dustfac = 0.90 + 0.01 * franf();
		tothe = Etc.klingon[i].avgdist;
		hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
		/* deplete his energy */
		dustfac = Etc.klingon[i].power;
		Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
		/* see how much of hit shields will absorb */
		shldabsb = 0;
		if (Ship.shldup || Move.shldchg)
		{
			propor = Ship.shield;
			propor /= Param.shield;
			shldabsb = propor * chgfac * hit;
			if (shldabsb > Ship.shield)
				shldabsb = Ship.shield;
			Ship.shield -= shldabsb;
		}
		/* actually do the hit */
		printf("\aHIT: %d units", hit);
		if (!damaged(SRSCAN))
			printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
		cas = (shldabsb * 100) / hit;
		hit -= shldabsb;
		if (shldabsb > 0)
			printf(", shields absorb %d%%, effective hit %d\n",
				cas, hit);
		else
			printf("\n");
		tothit += hit;
		if (hit > maxhit)
			maxhit = hit;
		Ship.energy -= hit;
		/* see if damages occurred */
		if (hit >= (15 - Game.skill) * (25 - ranf(12)))
		{
			printf("\aCRITICAL HIT!!!\a\n");
			/* select a device from probability vector */
			cas = ranf(1000);
			for (l = 0; cas >= 0; l++)
				cas -= Param.damprob[l];
			l -= 1;
			/* compute amount of damage */
			extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5;
			/* damage the device */
			damage(l, extradm);
			if (damaged(SHIELD))
			{
				if (Ship.shldup)
					printf("Sulu: Shields knocked down, captain.\n");
				Ship.shldup = 0;
				Move.shldchg = 0;
			}
		}
		if (Ship.energy <= 0)
			lose(L_DSTRYD);
	}

	/* see what our casualities are like */
	if (maxhit >= 200 || tothit >= 500)
	{
		cas = tothit * 0.015 * franf();
		if (cas >= 2)
		{
			printf("McCoy: we suffered %d casualties in that attack.\n",
				cas);
			Game.deaths += cas;
			Ship.crew -= cas;
		}
	}

	/* allow Klingons to move after attacking */
	klmove(1);
}
예제 #8
0
void
warp(int fl, int c, double d)
{
	int		course;
	double		power;
	double		dist;
	double		p_time;
	double		speed;
	double		frac;
	int		percent;
	int		i;
	char		*s;

	if (Ship.cond == DOCKED) {
		printf("%s is docked\n", Ship.shipname);
		return;
	}
	if (damaged(WARP)) {
		out(WARP);
		return;
	}
	course = c;
	dist = d;

	/* check to see that we are not using an absurd amount of power */
	power = (dist + 0.05) * Ship.warp3;
	percent = 100 * power / Ship.energy + 0.5;
	if (percent >= 85) {
		printf("Scotty: That would consume %d%% of our remaining energy.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
	}

	/* compute the speed we will move at, and the time it will take */
	speed = Ship.warp2 / Param.warptime;
	p_time = dist / speed;

	/* check to see that that value is not ridiculous */
	percent = 100 * p_time / Now.time + 0.5;
	if (percent >= 85) {
		printf("Spock: That would take %d%% of our remaining time.\n",
			percent);
		if (!getynpar("Are you sure that is wise"))
			return;
	}

	/* compute how far we will go if we get damages */
	if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0)) {
		frac = franf();
		dist *= frac;
		p_time *= frac;
		damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
	}

	/* do the move */
	Move.time = move(fl, course, p_time, speed);

	/* see how far we actually went, and decrement energy appropriately */
	dist = Move.time * speed;
	Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);

	/* test for bizarre events */
	if (Ship.warp <= 9.0)
		return;
	printf("\n\n  ___ Speed exceeding warp nine ___\n\n");
	sleep(2);
	printf("Ship's safety systems malfunction\n");
	sleep(2);
	printf("Crew experiencing extreme sensory distortion\n");
	sleep(4);
	if (ranf(100) >= 100 * dist) {
		printf("Equilibrium restored -- all systems normal\n");
		return;
	}

	/* select a bizzare thing to happen to us */
	percent = ranf(100);
	if (percent < 70) {
		/* time warp */
		if (percent < 35 || !Game.snap) {
			/* positive time warp */
			p_time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
			Now.date += p_time;
			printf("Positive time portal entered -- it is now Stardate %.2f\n",
				Now.date);
			for (i = 0; i < MAXEVENTS; i++) {
				percent = Event[i].evcode;
				if (percent == E_FIXDV || percent == E_LRTB)
					Event[i].date += p_time;
			}
			return;
		}

		/* s/he got lucky: a negative time portal */
		p_time = Now.date;
		s = Etc.snapshot;
		bmove(s, Quad, sizeof Quad);
		bmove(s += sizeof Quad, Event, sizeof Event);
		bmove(s += sizeof Event, &Now, sizeof Now);
		printf("Negative time portal entered -- it is now Stardate %.2f\n",
			Now.date);
		for (i = 0; i < MAXEVENTS; i++)
			if (Event[i].evcode == E_FIXDV)
				reschedule(&Event[i], Event[i].date - p_time);
		return;
	}

	/* test for just a lot of damage */
	if (percent < 80)
		lose(L_TOOFAST);
	printf("Equilibrium restored -- extreme damage occurred to ship systems\n");
	for (i = 0; i < NDEV; i++)
		damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
	Ship.shldup = 0;
}
예제 #9
0
void
setup()
{
	const struct cvntab	*r;
	int			i, j;
	double			f;
	int			d;
	int			klump;
	int			ix, iy;
	struct quad		*q;
	struct event		*e;

	while (1)
	{
		r = getcodpar("What length game", Lentab);
		Game.length = (long) r->value;
		if (Game.length == 0)
		{
			if (restartgame())
				continue;
			return;
		}
		break;
	}
	r = getcodpar("What skill game", Skitab);
	Game.skill = (long) r->value;
	Game.tourn = 0;
	getstrpar("Enter a password", Game.passwd, 14, 0);
	if (strcmp(Game.passwd, "tournament") == 0)
	{
		getstrpar("Enter tournament code", Game.passwd, 14, 0);
		Game.tourn = 1;
		d = 0;
		for (i = 0; Game.passwd[i]; i++)
			d += Game.passwd[i] << i;
		srand(d);
	}
	Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
	if (Game.skill == 6)
		Param.bases = Now.bases = 1;
	Param.time = Now.time = 6.0 * Game.length + 2.0;
	i = Game.skill;
	j = Game.length;
	Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
	if (Param.klings < i * j * 5)
		Param.klings = Now.klings = i * j * 5;
	if (Param.klings <= i)		/* numerical overflow problems */
		Param.klings = Now.klings = 127;
	Param.energy = Ship.energy = 5000;
	Param.torped = Ship.torped = 10;
	Ship.ship = ENTERPRISE;
	Ship.shipname = "Enterprise";
	Param.shield = Ship.shield = 1500;
	Param.resource = Now.resource = Param.klings * Param.time;
	Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
	Param.crew = Ship.crew = 387;
	Param.brigfree = Ship.brigfree = 400;
	Ship.shldup = 1;
	Ship.cond = GREEN;
	Ship.warp = 5.0;
	Ship.warp2 = 25.0;
	Ship.warp3 = 125.0;
	Ship.sinsbad = 0;
	Ship.cloaked = 0;
	Param.date = Now.date = (ranf(20) + 20) * 100;
	f = Game.skill;
	f = log(f + 0.5);
	for (i = 0; i < NDEV; i++)
		if (Device[i].name[0] == '*')
			Param.damfac[i] = 0;
		else
			Param.damfac[i] = f;
	/* these probabilities must sum to 1000 */
	Param.damprob[WARP] = 70;	/* warp drive		 7.0% */
	Param.damprob[SRSCAN] = 110;	/* short range scanners	11.0% */
	Param.damprob[LRSCAN] = 110;	/* long range scanners	11.0% */
	Param.damprob[PHASER] = 125;	/* phasers		12.5% */
	Param.damprob[TORPED] = 125;	/* photon torpedoes	12.5% */
	Param.damprob[IMPULSE] = 75;	/* impulse engines	 7.5% */
	Param.damprob[SHIELD] = 150;	/* shield control	15.0% */
	Param.damprob[COMPUTER] = 20;	/* computer		 2.0% */
	Param.damprob[SSRADIO] = 35;	/* subspace radio	 3.5% */
	Param.damprob[LIFESUP] = 30;	/* life support		 3.0% */
	Param.damprob[SINS] = 20;	/* navigation system	 2.0% */
	Param.damprob[CLOAK] = 50;	/* cloaking device	 5.0% */
	Param.damprob[XPORTER] = 80;	/* transporter		 8.0% */
	/* check to see that I didn't blow it */
	for (i = j = 0; i < NDEV; i++)
		j += Param.damprob[i];
	if (j != 1000)
		errx(1, "Device probabilities sum to %d", j);
	Param.dockfac = 0.5;
	Param.regenfac = (5 - Game.skill) * 0.05;
	if (Param.regenfac < 0.0)
		Param.regenfac = 0.0;
	Param.warptime = 10;
	Param.stopengy = 50;
	Param.shupengy = 40;
	i = Game.skill;
	Param.klingpwr = 100 + 150 * i;
	if (i >= 6)
		Param.klingpwr += 150;
	Param.phasfac = 0.8;
	Param.hitfac = 0.5;
	Param.klingcrew = 200;
	Param.srndrprob = 0.0035;
	Param.moveprob[KM_OB] = 45;
	Param.movefac[KM_OB] = .09;
	Param.moveprob[KM_OA] = 40;
	Param.movefac[KM_OA] = -0.05;
	Param.moveprob[KM_EB] = 40;
	Param.movefac[KM_EB] = 0.075;
	Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
	Param.movefac[KM_EA] = -0.06 * Game.skill;
	Param.moveprob[KM_LB] = 0;
	Param.movefac[KM_LB] = 0.0;
	Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
	Param.movefac[KM_LA] = 0.25;
	Param.eventdly[E_SNOVA] = 0.5;
	Param.eventdly[E_LRTB] = 25.0;
	Param.eventdly[E_KATSB] = 1.0;
	Param.eventdly[E_KDESB] = 3.0;
	Param.eventdly[E_ISSUE] = 1.0;
	Param.eventdly[E_SNAP] = 0.5;
	Param.eventdly[E_ENSLV] = 0.5;
	Param.eventdly[E_REPRO] = 2.0;
	Param.navigcrud[0] = 1.50;
	Param.navigcrud[1] = 0.75;
	Param.cloakenergy = 1000;
	Param.energylow = 1000;
	for (i = 0; i < MAXEVENTS; i++)
	{
		e = &Event[i];
		e->date = 1e50;
		e->evcode = 0;
	}
	xsched(E_SNOVA, 1, 0, 0, 0);
	xsched(E_LRTB, Param.klings, 0, 0, 0);
	xsched(E_KATSB, 1, 0, 0, 0);
	xsched(E_ISSUE, 1, 0, 0, 0);
	xsched(E_SNAP, 1, 0, 0, 0);
	Ship.sectx = ranf(NSECTS);
	Ship.secty = ranf(NSECTS);
	Game.killk = Game.kills = Game.killb = 0;
	Game.deaths = Game.negenbar = 0;
	Game.captives = 0;
	Game.killinhab = 0;
	Game.helps = 0;
	Game.killed = 0;
	Game.snap = 0;
	Move.endgame = 0;

	/* setup stars */
	for (i = 0; i < NQUADS; i++)
		for (j = 0; j < NQUADS; j++)
		{
			q = &Quad[i][j];
			q->klings = q->bases = 0;
			q->scanned = -1;
			q->stars = ranf(9) + 1;
			q->holes = ranf(3) - q->stars / 5;
			if (q->holes < 0)
				q->holes = 0;
			q->qsystemname = 0;
		}

	/* select inhabited starsystems */
	for (d = 1; d < NINHAB; d++)
	{
		do
		{
			i = ranf(NQUADS);
			j = ranf(NQUADS);
			q = &Quad[i][j];
		} while (q->qsystemname);
		q->qsystemname = d;
	}

	/* position starbases */
	for (i = 0; i < Param.bases; i++)
	{
		while (1)
		{
			ix = ranf(NQUADS);
			iy = ranf(NQUADS);
			q = &Quad[ix][iy];
			if (q->bases > 0)
				continue;
			break;
		}
		q->bases = 1;
		Now.base[i].x = ix;
		Now.base[i].y = iy;
		q->scanned = 1001;
		/* start the Enterprise near starbase */
		if (i == 0)
		{
			Ship.quadx = ix;
			Ship.quady = iy;
		}
	}

	/* position klingons */
	for (i = Param.klings; i > 0; )
	{
		klump = ranf(4) + 1;
		if (klump > i)
			klump = i;
		while (1)
		{
			ix = ranf(NQUADS);
			iy = ranf(NQUADS);
			q = &Quad[ix][iy];
			if (q->klings + klump > MAXKLQUAD)
				continue;
			q->klings += klump;
			i -= klump;
			break;
		}
	}

	/* initialize this quadrant */
	printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
	if (Param.bases > 1)
		printf("s");
	printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
	for (i = 1; i < Param.bases; i++)
		printf(", %d,%d", Now.base[i].x, Now.base[i].y);
	printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);
	Move.free = 0;
	initquad(0);
	srscan(1);
	attack(0);
}
예제 #10
0
phaser()
{
	register int		i;
	int			j;
	register struct kling	*k;
	double			dx, dy;
	double			anglefactor, distfactor;
	register struct banks	*b;
	int			manual, flag, extra;
	int			hit;
	double			tot;
	int			n;
	int			hitreqd[NBANKS];
	struct banks		bank[NBANKS];
	struct cvntab		*ptr;

	if (Ship.cond == DOCKED)
		return(printf("Phasers cannot fire through starbase shields\n"));
	if (damaged(PHASER))
		return (out(PHASER));
	if (Ship.shldup)
		return (printf("Sulu: Captain, we cannot fire through shields.\n"));
	if (Ship.cloaked)
	{
		printf("Sulu: Captain, surely you must realize that we cannot fire\n");
		printf("  phasers with the cloaking device up.\n");
		return;
	}

	/* decide if we want manual or automatic mode */
	manual = 0;
	if (testnl())
	{
		if (damaged(COMPUTER))
		{
			printf(Device[COMPUTER].name);
			manual++;
		}
		else
			if (damaged(SRSCAN))
			{
				printf(Device[SRSCAN].name);
				manual++;
			}
		if (manual)
			printf(" damaged, manual mode selected\n");
	}

	if (!manual)
	{
		ptr = getcodpar("Manual or automatic", Matab);
		manual = (int) ptr->value;
	}
	if (!manual && damaged(COMPUTER))
	{
		printf("Computer damaged, manual selected\n");
		skiptonl(0);
		manual++;
	}

	/* initialize the bank[] array */
	flag = 1;
	for (i = 0; i < NBANKS; i++)
		bank[i].units = 0;
	if (manual)
	{
		/* collect manual mode statistics */
		while (flag)
		{
			printf("%d units available\n", Ship.energy);
			extra = 0;
			flag = 0;
			for (i = 0; i < NBANKS; i++)
			{
				b = &bank[i];
				printf("\nBank %d:\n", i);
				hit = getintpar("units");
				if (hit < 0)
					return;
				if (hit == 0)
					break;
				extra += hit;
				if (extra > Ship.energy)
				{
					printf("available energy exceeded.  ");
					skiptonl(0);
					flag++;
					break;
				}
				b->units = hit;
				hit = getintpar("course");
				if (hit < 0 || hit > 360)
					return;
				b->angle = hit * 0.0174532925;
				b->spread = getfltpar("spread");
				if (b->spread < 0 || b->spread > 1)
					return;
			}
			Ship.energy -= extra;
		}
		extra = 0;
	}
	else
	{
		/* automatic distribution of power */
		if (Etc.nkling <= 0)
			return (printf("Sulu: But there are no Klingons in this quadrant\n"));
		printf("Phasers locked on target.  ");
		while (flag)
		{
			printf("%d units available\n", Ship.energy);
			hit = getintpar("Units to fire");
			if (hit <= 0)
				return;
			if (hit > Ship.energy)
			{
				printf("available energy exceeded.  ");
				skiptonl(0);
				continue;
			}
			flag = 0;
			Ship.energy -= hit;
			extra = hit;
			n = Etc.nkling;
			if (n > NBANKS)
				n = NBANKS;
			tot = n * (n + 1) / 2;
			for (i = 0; i < n; i++)
			{
				k = &Etc.klingon[i];
				b = &bank[i];
				distfactor = k->dist;
				anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON);
				anglefactor *= GAMMA;
				distfactor = k->power;
				distfactor /= anglefactor;
				hitreqd[i] = distfactor + 0.5;
				dx = Ship.sectx - k->x;
				dy = k->y - Ship.secty;
				b->angle = atan2(dy, dx);
				b->spread = 0.0;
				b->units = ((n - i) / tot) * extra;
#				ifdef xTRACE
				if (Trace)
				{
					printf("b%d hr%d u%d df%.2f af%.2f\n",
						i, hitreqd[i], b->units,
						distfactor, anglefactor);
				}
#				endif
				extra -= b->units;
				hit = b->units - hitreqd[i];
				if (hit > 0)
				{
					extra += hit;
					b->units -= hit;
				}
			}

			/* give out any extra energy we might have around */
			if (extra > 0)
			{
				for (i = 0; i < n; i++)
				{
					b = &bank[i];
					hit = hitreqd[i] - b->units;
					if (hit <= 0)
						continue;
					if (hit >= extra)
					{
						b->units += extra;
						extra = 0;
						break;
					}
					b->units = hitreqd[i];
					extra -= hit;
				}
				if (extra > 0)
					printf("%d units overkill\n", extra);
			}
		}
	}

#	ifdef xTRACE
	if (Trace)
	{
		for (i = 0; i < NBANKS; i++)
		{
			b = &bank[i];
			printf("b%d u%d", i, b->units);
			if (b->units > 0)
				printf(" a%.2f s%.2f\n", b->angle, b->spread);
			else
				printf("\n");
		}
	}
#	endif

	/* actually fire the shots */
	Move.free = 0;
	for (i = 0; i < NBANKS; i++)
	{
		b = &bank[i];
		if (b->units <= 0)
		{
			continue;
		}
		printf("\nPhaser bank %d fires:\n", i);
		n = Etc.nkling;
		k = Etc.klingon;
		for (j = 0; j < n; j++)
		{
			if (b->units <= 0)
				break;
			/*
			** The formula for hit is as follows:
			**
			**  zap = OMEGA * [(sigma + ALPHA) * (rho + BETA)]
			**	/ (dist ** 2 + EPSILON)]
			**	* [cos(delta * sigma) + GAMMA]
			**	* hit
			**
			** where sigma is the spread factor,
			** rho is a random number (0 -> 1),
			** GAMMA is a crud factor for angle (essentially
			**	cruds up the spread factor),
			** delta is the difference in radians between the
			**	angle you are shooting at and the actual
			**	angle of the klingon,
			** ALPHA scales down the significance of sigma,
			** BETA scales down the significance of rho,
			** OMEGA is the magic number which makes everything
			**	up to "* hit" between zero and one,
			** dist is the distance to the klingon
			** hit is the number of units in the bank, and
			** zap is the amount of the actual hit.
			**
			** Everything up through dist squared should maximize
			** at 1.0, so that the distance factor is never
			** greater than one.  Conveniently, cos() is
			** never greater than one, but the same restric-
			** tion applies.
			*/
			distfactor = BETA + franf();
			distfactor *= ALPHA + b->spread;
			distfactor *= OMEGA;
			anglefactor = k->dist;
			distfactor /= anglefactor * anglefactor + EPSILON;
			distfactor *= b->units;
			dx = Ship.sectx - k->x;
			dy = k->y - Ship.secty;
			anglefactor = atan2(dy, dx) - b->angle;
			anglefactor = cos((anglefactor * b->spread) + GAMMA);
			if (anglefactor < 0.0)
			{
				k++;
				continue;
			}
			hit = anglefactor * distfactor + 0.5;
			k->power -= hit;
			printf("%d unit hit on Klingon", hit);
			if (!damaged(SRSCAN))
				printf(" at %d,%d", k->x, k->y);
			printf("\n");
			b->units -= hit;
			if (k->power <= 0)
			{
				killk(k->x, k->y);
				continue;
			}
			k++;
		}
	}

	/* compute overkill */
	for (i = 0; i < NBANKS; i++)
		extra += bank[i].units;
	if (extra > 0)
		printf("\n%d units expended on empty space\n", extra);
}
예제 #11
0
// Simplified reschedule routine
//
// Parameters are the event index, the initial date, and the
// division factor.  Look at the code to see what really happens.
//
void xresched (struct event* e, int ev, int factor)
{
    reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
}
예제 #12
0
// Abreviated schedule routine
//
// Parameters are the event index and a factor for the time figure.
struct event* xsched (int ev, int factor, int x, int y, int z)
{
    return schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z);
}
예제 #13
0
double
move(int ramflag, int course, double p_time, double speed)
{
	double			angle;
	double			x, y, dx, dy;
	int		ix, iy;
	double			bigger;
	int			n;
	int		i;
	double			dist;
	double			sectsize;
	double			xn;
	double			evtime;

	ix = iy = 0;
#ifdef xTRACE
	if (Trace)
		printf("move: ramflag %d course %d time %.2f speed %.2f\n",
			ramflag, course, p_time, speed);
#endif
	sectsize = NSECTS;
	/* initialize delta factors for move */
	angle = course * 0.0174532925;
	if (damaged(SINS))
		angle += Param.navigcrud[1] * (franf() - 0.5);
	else
		if (Ship.sinsbad)
			angle += Param.navigcrud[0] * (franf() - 0.5);
	dx = -cos(angle);
	dy = sin(angle);
	bigger = fabs(dx);
	dist = fabs(dy);
	if (dist > bigger)
		bigger = dist;
	dx /= bigger;
	dy /= bigger;

	/* check for long range tractor beams */
	/****  TEMPORARY CODE == DEBUGGING  ****/
	evtime = Now.eventptr[E_LRTB]->date - Now.date;
#ifdef xTRACE
	if (Trace)
		printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
			(void *)Now.eventptr[E_LRTB],
			Now.eventptr[E_LRTB]->evcode,
			Now.eventptr[E_LRTB]->date, evtime);
#endif
	if (p_time > evtime && Etc.nkling < 3) {
		/* then we got a LRTB */
		evtime += 0.005;
		p_time = evtime;
	} else
		evtime = -1.0e50;
	dist = p_time * speed;

	/* move within quadrant */
	Sect[Ship.sectx][Ship.secty] = EMPTY;
	x = Ship.sectx + 0.5;
	y = Ship.secty + 0.5;
	xn = NSECTS * dist * bigger;
	n = xn + 0.5;
#ifdef xTRACE
	if (Trace)
		printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
#endif
	Move.free = 0;

	for (i = 0; i < n; i++) {
		ix = (x += dx);
		iy = (y += dy);
#ifdef xTRACE
		if (Trace)
			printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
#endif
		if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) {
			/* enter new quadrant */
			dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
			dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
			if (dx < 0.0)
				ix = -1;
			else
				ix = dx + 0.5;
			if (dy < 0.0)
				iy = -1;
			else
				iy = dy + 0.5;
#ifdef xTRACE
			if (Trace)
				printf("New quad: ix = %d, iy = %d\n", ix, iy);
#endif
			Ship.sectx = x;
			Ship.secty = y;
			compkldist(0);
			Move.newquad = 2;
			attack(0);
			checkcond();
			Ship.quadx = ix / NSECTS;
			Ship.quady = iy / NSECTS;
			Ship.sectx = ix % NSECTS;
			Ship.secty = iy % NSECTS;
			if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
			    Ship.quady >= NQUADS) {
				if (!damaged(COMPUTER)) {
					dumpme(0);
				} else
					lose(L_NEGENB);
			}
			initquad(0);
			n = 0;
			break;
		}
		if (Sect[ix][iy] != EMPTY) {
			/* we just hit something */
			if (!damaged(COMPUTER) && ramflag <= 0) {
				ix = x - dx;
				iy = y - dy;
				printf("Computer reports navigation error; %s stopped at %d,%d\n",
					Ship.shipname, ix, iy);
				Ship.energy -= Param.stopengy * speed;
				break;
			}
			/* test for a black hole */
			if (Sect[ix][iy] == HOLE) {
				/* get dumped elsewhere in the galaxy */
				dumpme(1);
				initquad(0);
				n = 0;
				break;
			}
			ram(ix, iy);
			break;
		}
	}
	if (n > 0) {
		dx = Ship.sectx - ix;
		dy = Ship.secty - iy;
		dist = sqrt(dx * dx + dy * dy) / NSECTS;
		p_time = dist / speed;
		if (evtime > p_time)
			p_time = evtime;		/* spring the LRTB trap */
		Ship.sectx = ix;
		Ship.secty = iy;
	}
	Sect[Ship.sectx][Ship.secty] = Ship.ship;
	compkldist(0);
	return (p_time);
}