-/* $NetBSD: phaser.c,v 1.4 1995/04/24 12:26:02 cgd Exp $ */
+/* $NetBSD: phaser.c,v 1.15 2009/08/12 08:54:54 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)phaser.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: phaser.c,v 1.4 1995/04/24 12:26:02 cgd Exp $";
+__RCSID("$NetBSD: phaser.c,v 1.15 2009/08/12 08:54:54 dholland Exp $");
#endif
#endif /* not lint */
-# include "trek.h"
-# include "getpar.h"
+#include <stdio.h>
+#include <math.h>
+#include "trek.h"
+#include "getpar.h"
/* factors for phaser hits; see description below */
-# define ALPHA 3.0 /* spread */
-# define BETA 3.0 /* franf() */
-# define GAMMA 0.30 /* cos(angle) */
-# define EPSILON 150.0 /* dist ** 2 */
-# define OMEGA 10.596 /* overall scaling factor */
+#define ALPHA 3.0 /* spread */
+#define BETA 3.0 /* franf() */
+#define GAMMA 0.30 /* cos(angle) */
+#define EPSILON 150.0 /* dist ** 2 */
+#define OMEGA 10.596 /* overall scaling factor */
/* OMEGA ~= 100 * (ALPHA + 1) * (BETA + 1) / (EPSILON + 1) */
** Uses trace flag 30
*/
-struct cvntab Matab[] =
-{
- "m", "anual", (int (*)())1, 0,
- "a", "utomatic", 0, 0,
- 0
+static struct cvntab Matab[] = {
+ { "m", "anual", (cmdfun) 1, 0 },
+ { "a", "utomatic", (cmdfun) 0, 0 },
+ { NULL, NULL, NULL, 0 }
};
-struct banks
-{
+struct banks {
int units;
double angle;
double spread;
-phaser()
+/*ARGSUSED*/
+void
+phaser(int v __unused)
{
- 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;
+ int i;
+ int j;
+ struct kling *k;
+ double dx, dy;
+ double anglefactor, distfactor;
+ struct banks *b;
+ int manual, flag, extra = 0;
+ int hit;
+ double tot;
+ int n;
+ int hitreqd[NBANKS];
+ struct banks bank[NBANKS];
+ const 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");
+ if (Ship.cond == DOCKED) {
+ printf("Phasers cannot fire through starbase shields\n");
+ return;
+ }
+ if (damaged(PHASER)) {
+ out(PHASER);
+ return;
+ }
+ if (Ship.shldup) {
+ printf("Sulu: Captain, we cannot fire through shields.\n");
+ return;
+ }
+ 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);
+ if (testnl()) {
+ if (damaged(COMPUTER)) {
+ printf("%s", Device[COMPUTER].name);
+ manual++;
+ } else if (damaged(SRSCAN)) {
+ printf("%s", Device[SRSCAN].name);
manual++;
}
- else
- if (damaged(SRSCAN))
- {
- printf(Device[SRSCAN].name);
- manual++;
- }
if (manual)
printf(" damaged, manual mode selected\n");
}
- if (!manual)
- {
+ if (!manual) {
ptr = getcodpar("Manual or automatic", Matab);
manual = (long) ptr->value;
}
- if (!manual && damaged(COMPUTER))
- {
+ if (!manual && damaged(COMPUTER)) {
printf("Computer damaged, manual selected\n");
skiptonl(0);
manual++;
flag = 1;
for (i = 0; i < NBANKS; i++)
bank[i].units = 0;
- if (manual)
- {
+ if (manual) {
/* collect manual mode statistics */
- while (flag)
- {
+ while (flag) {
printf("%d units available\n", Ship.energy);
extra = 0;
flag = 0;
- for (i = 0; i < NBANKS; i++)
- {
+ for (i = 0; i < NBANKS; i++) {
b = &bank[i];
printf("\nBank %d:\n", i);
hit = getintpar("units");
if (hit == 0)
break;
extra += hit;
- if (extra > Ship.energy)
- {
+ if (extra > Ship.energy) {
printf("available energy exceeded. ");
skiptonl(0);
flag++;
Ship.energy -= extra;
}
extra = 0;
- }
- else
- {
+ } else {
/* automatic distribution of power */
- if (Etc.nkling <= 0)
- return (printf("Sulu: But there are no Klingons in this quadrant\n"));
+ if (Etc.nkling <= 0) {
+ printf("Sulu: But there are no Klingons in this "
+ "quadrant\n");
+ return;
+ }
printf("Phasers locked on target. ");
- while (flag)
- {
+ while (flag) {
printf("%d units available\n", Ship.energy);
hit = getintpar("Units to fire");
if (hit <= 0)
return;
- if (hit > Ship.energy)
- {
+ if (hit > Ship.energy) {
printf("available energy exceeded. ");
skiptonl(0);
continue;
if (n > NBANKS)
n = NBANKS;
tot = n * (n + 1) / 2;
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
k = &Etc.klingon[i];
b = &bank[i];
distfactor = k->dist;
- anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON);
+ anglefactor = ALPHA * BETA * OMEGA /
+ (distfactor * distfactor + EPSILON);
anglefactor *= GAMMA;
distfactor = k->power;
distfactor /= anglefactor;
b->angle = atan2(dy, dx);
b->spread = 0.0;
b->units = ((n - i) / tot) * extra;
-# ifdef xTRACE
- if (Trace)
- {
+#ifdef xTRACE
+ if (Trace) {
printf("b%d hr%d u%d df%.2f af%.2f\n",
i, hitreqd[i], b->units,
distfactor, anglefactor);
}
-# endif
+#endif
extra -= b->units;
hit = b->units - hitreqd[i];
- if (hit > 0)
- {
+ 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++)
- {
+ if (extra > 0) {
+ for (i = 0; i < n; i++) {
b = &bank[i];
hit = hitreqd[i] - b->units;
if (hit <= 0)
continue;
- if (hit >= extra)
- {
+ if (hit >= extra) {
b->units += extra;
extra = 0;
break;
}
}
-# ifdef xTRACE
- if (Trace)
- {
- for (i = 0; i < NBANKS; i++)
- {
+#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("\n");
}
}
-# endif
+#endif
/* actually fire the shots */
Move.free = 0;
- for (i = 0; i < NBANKS; i++)
- {
+ for (i = 0; i < NBANKS; i++) {
b = &bank[i];
- if (b->units <= 0)
- {
+ if (b->units <= 0) {
continue;
}
printf("\nPhaser bank %d fires:\n", i);
n = Etc.nkling;
k = Etc.klingon;
- for (j = 0; j < n; j++)
- {
+ for (j = 0; j < n; j++) {
if (b->units <= 0)
break;
/*
dy = k->y - Ship.secty;
anglefactor = atan2(dy, dx) - b->angle;
anglefactor = cos((anglefactor * b->spread) + GAMMA);
- if (anglefactor < 0.0)
- {
+ if (anglefactor < 0.0) {
k++;
continue;
}
printf(" at %d,%d", k->x, k->y);
printf("\n");
b->units -= hit;
- if (k->power <= 0)
- {
+ if (k->power <= 0) {
killk(k->x, k->y);
continue;
}