static void klingons_move(void);
static void klingons_shoot(void);
static void repair_damage(void);
-static void find_empty_place(void);
-static void insert_in_quadrant(void);
+static void find_set_empty_place(uint8_t t);
static const char *get_device_name(int n);
-static void string_compare(void);
static void quadrant_name(void);
static int function_d(int i);
-static void mid_str(char *a, char *b, int x, int y);
static int cint(double d);
static void compute_vector(void);
static void sub1(void);
static int r1, r2; /* Temporary Location Corrdinates */
static int s; /* Current shield value */
static uint8_t s3; /* Stars in quadrant */
-static int s8; /* Quadrant locating index */
static uint16_t t0; /* Starting Stardate */
static uint16_t t9; /* End of time */
static unsigned int z[9][9]; /* Cumulative Record of Galaxy */
-static int z3; /* string_compare return value */
static int z1, z2; /* Temporary Sector Coordinates */
static int z4, z5; /* Temporary quadrant coordinates */
static double w1; /* Warp Factor */
static double x, y, x1, x2; /* Navigational coordinates */
-static char sA[4]; /* An Object in a Sector */
static char *sC; /* Condition */
-static char sQ[194]; /* Visual Display of Quadrant */
+
+static uint8_t quad[8][8];
+#define Q_SPACE 0
+#define Q_STAR 1
+#define Q_BASE 2
+#define Q_KLINGON 3
+#define Q_SHIP 4
static char quadname[12]; /* Quadrant name */
+/* We probably need double digit for co-ordinate maths, single for time */
#define TO_FIXED(x) ((x) * 10)
#define FROM_FIXED(x) ((x) / 10)
k[i][3] = 0;
}
- for (i = 0; i <= 192; i++)
- sQ[i] = ' ';
-
- sQ[193] = '\0';
-
- /* Position Enterprise, then Klingons, Starbases, and stars */
-
- strcpy(sA, "<*>");
- /* @@@ z1 = cint(s1); */
- z1 = (int) s1;
- /* @@@ z2 = cint(s2); */
- z2 = (int) s2;
- insert_in_quadrant();
+ memset(quad, Q_SPACE, 64);
+ /* FIXME: do we need 0.5 shifts ? */
+ quad[(int)s1 - 1][(int)s2 - 1] = Q_SHIP;
+
if (k3 > 0) {
for (i = 1; i <= k3; i++) {
- find_empty_place();
-
- strcpy(sA, "+K+");
- z1 = r1;
- z2 = r2;
- insert_in_quadrant();
-
+ find_set_empty_place(Q_KLINGON);
k[i][1] = r1;
k[i][2] = r2;
k[i][3] = 100 + get_rand(200);
}
if (b3 > 0) {
- find_empty_place();
-
- strcpy(sA, ">!<");
- z1 = r1;
- z2 = r2;
- insert_in_quadrant();
+ find_set_empty_place(Q_BASE);
b4 = r1;
b5 = r2;
}
- for (i = 1; i <= s3; i++) {
- find_empty_place();
-
- strcpy(sA, " * ");
- z1 = r1;
- z2 = r2;
- insert_in_quadrant();
- }
+ for (i = 1; i <= s3; i++)
+ find_set_empty_place(Q_STAR);
}
+static const char *inc_1 = "reports:\n Incorrect course data, sir!\n";
+
static void course_control(void)
{
register int i;
c1 = 1.0;
if (c1 < 0 || c1 > 9.0) {
- puts("Lt. Sulu roports:\n Incorrect course data, sir!\n");
+ printf("Lt. Sulu%s", inc_1);
return;
}
repair_damage();
- strcpy(sA, " ");
/* @@@ z1 = cint(s1); */
z1 = (int) s1;
/* @@@ z2 = cint(s2); */
z2 = (int) s2;
- insert_in_quadrant();
+ quad[z1-1][z2-1] = Q_SPACE;
/* @@@ c2 = cint(c1); */
/* @@@ c3 = c2 + 1; */
return;
}
- string_compare();
-
- if (z3 != 1) { /* Sector not empty */
+ if (quad[z1-1][z2-1] != Q_SPACE) { /* Sector not empty */
s1 = s1 - x1;
s2 = s2 - x2;
printf("Warp Engines shut down at sector "
{
int t8;
- strcpy(sA, "<*>");
/* @@@ z1 = cint(s1); */
z1 = (int) s1;
/* @@@ z2 = cint(s2); */
z2 = (int) s2;
- insert_in_quadrant();
+ quad[z1-1][z2-1] = Q_SHIP;
maneuver_energy();
static const char *srs_1 = "------------------------";
+static const char *tilestr[] = {
+ " ",
+ " * ",
+ ">!<",
+ "+K+",
+ "<*>"
+};
+
static void short_range_scan(void)
{
register int i, j;
/* @@@ for (j = s2 - 1; j <= s2 + 1; j++) */
for (j = (int) (s2 - 1); j <= (int) (s2 + 1); j++)
if (i >= 1 && i <= 8 && j >= 1 && j <= 8) {
- strcpy(sA, ">!<");
- z1 = i;
- z2 = j;
- string_compare();
- if (z3 == 1) {
+ /* This is dumb - we store the base co-ords! */
+ if (quad[i-1][j-1] == Q_BASE) {
d0 = 1;
sC = "DOCKED";
e = e0;
puts(srs_1);
for (i = 0; i < 8; i++) {
- for (j = 0; j < 24; j++)
- putchar(sQ[i * 24 + j]);
+ for (j = 0; j < 8; j++) {
+ if (quad[i][j] > 4)
+ printf("FUCK");
+ fputs(tilestr[quad[i][j]], stdout);
+ }
if (i == 0)
printf(" Stardate %d\n", FROM_FIXED(t));
int h1, h;
string sTemp;
- if (d[4] < 0.0) {
- puts("Phasers Inoperative\n");
+ if (inoperable(4))
return;
- }
if (k3 <= 0) {
puts("Science Officer Spock reports:\n"
k9--;
z1 = k[i][1];
z2 = k[i][2];
- strcpy(sA, " ");
- insert_in_quadrant();
+ quad[z1-1][z2-1] = Q_SPACE;
k[i][3] = 0;
g[q1][q2] = g[q1][q2] - 100;
z[q1][q2] = g[q1][q2];
/* @@@ if (c1 < 0 || c1 > 9.0) */
if (c1 < 1.0 || c1 > 9.0) {
- puts("Ensign Chekov roports:\n"
- " Incorrect course data, sir!\n");
+ printf("Ensign Chekov%s", inc_1);
return;
}
while (x3 >= 1 && x3 <= 8 && y3 >= 1 && y3 <= 8) {
printf(" %d, %d\n", x3, y3);
- strcpy(sA, " ");
z1 = x3;
z2 = y3;
- string_compare();
-
- if (z3 == 0) {
+ if (quad[z1-1][z2-1] != Q_SPACE) {
torpedo_hit();
klingons_shoot();
return;
x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */
y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */
- z3 = 0;
-
- strcpy(sA, " * ");
- string_compare();
-
- if (z3 == 1) {
+ switch(quad[x3-1][y3-1]) {
+ case Q_STAR:
printf("Star at %d, %d absorbed torpedo energy.\n\n", x3, y3);
return;
- }
-
- strcpy(sA, "+K+");
- string_compare();
-
- if (z3 == 1) {
+ case Q_KLINGON:
puts("*** Klingon Destroyed ***\n");
k3--;
k9--;
for (i = 0; i <= 3; i++)
if (x3 == k[i][1] && y3 == k[i][2])
k[i][3] = 0;
- }
-
- strcpy(sA, ">!<");
- string_compare();
-
- if (z3 == 1) {
+ break;
+ case Q_BASE:
puts("*** Starbase Destroyed ***");
b3--;
b9--;
"court martial!\n");
d0 = 0; /* Undock */
+ break;
}
-
z1 = x3;
z2 = y3;
- strcpy(sA, " ");
- insert_in_quadrant();
+ quad[z1-1][z2-1] = Q_SPACE;
g[q1][q2] = (k3 * 100) + (b3 * 10) + s3;
z[q1][q2] = g[q1][q2];
double d3 = 0.0;
register int i;
- /* FIXME: should be blocked if Klingons present */
if (d[6] < 0.0)
puts("Damage Control report not available.");
static void status_report(void)
{
const char *plural = str_s + 1;
+ uint16_t left = TO_FIXED(t0 + t9) - t;
puts(" Status Report:\n");
if (k9 > 1)
plural = str_s;
+ /* Assumes fixed point is single digit fixed */
printf("Klingon%s Left: %d\n"
- "Mission must be completed in %4.1f stardates\n",
+ "Mission must be completed in %d.%d stardates\n",
plural, k9,
+ FROM_FIXED(left), left%10);
+#if 0
/* @@@ .1 * cint((t0 + t9 - t) * 10)); */
/* Force long to avoid overflows: FIXME clean this all up
into fixed point forms */
.1 * (int) ((t0 + t9 - FROM_FIXED(t)) * 10L));
+#endif
if (b9 < 1) {
puts("Your stupidity has left you on your own in the galaxy\n"
for (i = 1; i <= 3; i++) {
if (k[i][3] > 0) {
- strcpy(sA, " ");
z1 = k[i][1];
z2 = k[i][2];
- insert_in_quadrant();
+ quad[z1-1][z2-1] = Q_SPACE;
- find_empty_place();
+ find_set_empty_place(Q_KLINGON);
k[i][1] = z1;
k[i][2] = z2;
- strcpy(sA, "+K+");
- insert_in_quadrant();
}
}
/* Misc Functions and Subroutines */
-static void find_empty_place(void)
+static void find_set_empty_place(uint8_t t)
{
- /* @@@ while (z3 == 0) this is a nasty one. */
do {
r1 = rand8();
r2 = rand8();
-
- strcpy(sA, " ");
-
- z1 = r1;
- z2 = r2;
-
- string_compare();
- } while (z3 == 0);
-
- z3 = 0;
-}
-
-static void insert_in_quadrant(void)
-{
- int i, j = 0;
-
- /* @@@ s8 = ((z2 - 1) * 3) + ((z1 - 1) * 24) + 1; */
- s8 = ((int) (z2 - 0.5) * 3) + ((int) (z1 - 0.5) * 24) + 1;
-
- for (i = s8 - 1; i <= s8 + 1; i++)
- sQ[i] = sA[j++];
-
- return;
+ } while (quad[r1-1][r2-1] != Q_SPACE );
+ quad[r1-1][r2-1] = t;
+ z1 = r1;
+ z2 = r2;
}
static const char *device_name[] = {
return device_name[n];
}
-static void string_compare(void)
-{
- int i;
- char sB[4];
-
- z1 = (int) (z1 + 0.5);
- z2 = (int) (z2 + 0.5);
-
- s8 = ((z2 - 1) * 3) + ((z1 - 1) * 24) + 1;
-
- mid_str(sB, sQ, s8, 3);
-
- i = strncmp(sB, sA, 3);
-
- if (i == 0)
- z3 = 1;
- else
- z3 = 0;
-
- return;
-}
-
static const char *quad_name[] = { "",
"Antares", "Rigel", "Procyon", "Vega", "Canopus", "Altair",
"Sagittarius", "Pollux", "Sirius", "Deneb", "Capella",
}
-static void mid_str(char *a, char *b, int x, int y)
-{
- --x;
- y += x;
-
- /* @@@ while (x < y && x <= strlen(b)) */
- while (x < y && x <= (int) strlen(b))
- *a++ = *(b + x++);
-
- *a = '\0';
-}
-
/* Round off floating point numbers instead of truncating */
static int cint(double d)