#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
static int s; /* Current shield value */
static int s3; /* Stars in quadrant */
static int s8; /* Quadrant locating index */
-static int t0; /* Starting Stardate */
-static int t9; /* End of time */
+static uint16_t t0; /* Starting Stardate */
+static uint16_t t9; /* End of time */
static int z[9][9]; /* Cumulative Record of Galaxy */
static int z3; /* string_compare return value */
static int z1, z2; /* Temporary Sector Coordinates */
static double d[9]; /* Damage Array */
static double d4; /* Used for computing damage repair time */
static double s1, s2; /* Current Sector Position of Enterprise */
-static double t; /* Current Stardate */
+static uint16_t t; /* Current Stardate */
static double w1; /* Warp Factor */
static double x, y, x1, x2; /* Navigational coordinates */
static char quadname[12]; /* Quadrant name */
+#define TO_FIXED(x) ((x) * 10)
+#define FROM_FIXED(x) ((x) / 10)
/*
* Returns an integer from 1 to iSpread
/* Seed the randomizer with the timer */
srand((unsigned) time(NULL));
- t = (get_rand(20) + 20) * 100;
+ /* Max of 4000, which works nicely with our 0.1 fixed point giving
+ us a 16bit unsigned range of time */
+ t = TO_FIXED((get_rand(20) + 20) * 100);
}
static void new_game(void)
phaser_control();
else if (!strncmp(sTemp, "tor", 3))
photon_torpedoes();
- else if (!strncmp(sTemp, "she", 3))
+ else if (!strncmp(sTemp, "shi", 3))
shield_control();
else if (!strncmp(sTemp, "dam", 3))
damage_control();
puts(" lrs - Long Range Sensors");
puts(" pha - Phasers");
puts(" tor - Photon Torpedoes");
- puts(" she - Shield Control");
+ puts(" shi - Shield Control");
puts(" dam - Damage Control");
puts(" com - Library Computer");
puts(" xxx - Resign Command\n");
/* InItialize time */
/* @@@ t0 = t; */
- t0 = (int) t;
+ t0 = FROM_FIXED(t);
t9 = 25 + get_rand(10);
/* Initialize Enterprise */
printf("Your orders are as follows:\n"
" Destroy the %d Klingon warships which have invaded\n"
" the galaxy before they can attack Federation Headquarters\n"
- " on stardate %d. This gives you %d days. There %s\n"
+ " on stardate %u. This gives you %d days. There %s\n"
" %d starbase%s in the galaxy for resupplying your ship.\n\n"
"Hit any key to accept command. ",
k9, t0 + t9, t9, sX0, b9, sX);
static void complete_maneuver(void)
{
- double t8;
+ int t8;
strcpy(sA, "<*>");
/* @@@ z1 = cint(s1); */
maneuver_energy();
- t8 = 1.0;
+ t8 = TO_FIXED(1);
if (w1 < 1.0)
- t8 = w1;
+ t8 = TO_FIXED(w1);
t = t + t8;
- if (t > t0 + t9)
+ if (FROM_FIXED(t) > t0 + t9)
end_of_time();
short_range_scan();
end_of_time();
*/
- if (t > t0 + t9)
+ if (FROM_FIXED(t) > t0 + t9)
end_of_time();
/* @@@ what does this do?? It's in the original.
putchar(sQ[i * 24 + j]);
if (i == 0)
- printf(" Stardate %d\n", (int) t);
+ printf(" Stardate %d\n", FROM_FIXED(t));
if (i == 1)
printf(" Condition %s\n", sC);
if (i == 2)
b3--;
b9--;
- if (b9 <= 0 && k9 <= t - t0 - t9) {
+ if (b9 <= 0 && k9 <= FROM_FIXED(t) - t0 - t9) {
/* showfile ? FIXME */
puts("That does it, Captain!!"
"You are hereby relieved of command\n"
register int i;
/* FIXME: should be blocked if Klingons present */
- if (d[6] < 0.0) {
+ if (d[6] < 0.0)
puts("Damage Control report not available.");
- if (d0 == 0)
- return;
-
+ /* Offer repair if docked */
+ if (d0) {
d3 = 0.0;
for (i = 1; i <= 8; i++)
if (d[i] < 0.0)
if (d[i] < 0.0)
d[i] = 0.0;
- t = t + d3 + 0.1;
+ t = t + TO_FIXED(d3 + 0.1);
}
}
+ if (d[6] < 0.0)
+ return;
+
puts("Device State of Repair");
for (r1 = 1; r1 <= 8; r1++)
"Mission must be completed in %4.1f stardates\n",
plural, k9,
/* @@@ .1 * cint((t0 + t9 - t) * 10)); */
- .1 * (int) ((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));
if (b9 < 1) {
puts("Your stupidity has left you on your own in the galaxy\n"
static void end_of_time(void)
{
- printf("It is stardate %d.\n\n", (int) t);
+ printf("It is stardate %d.\n\n", FROM_FIXED(t));
resign_commision();
}
puts("Congratulations, Captain! The last Klingon Battle Cruiser\n"
"menacing the Federation has been destoyed.\n");
- if (t - t0 > 0)
- printf("Your efficiency rating is %4.2f\n", 1000 * pow(k7 / (t - t0), 2));
+ if (FROM_FIXED(t) - t0 > 0)
+ printf("Your efficiency rating is %4.2f\n", 1000 * pow(k7 / (FROM_FIXED(t) - t0), 2));
end_of_game();
}
d6 = w1;
if (w1 >= 1.0)
- d6 = w1 / 10;
+ d6 = 1.0;
for (i = 1; i <= 8; i++) {
if (d[i] < 0.0) {
if (d[i] > -0.1 && d[i] < 0)
d[i] = -0.1;
else if (d[i] >= 0.0) {
- if (d1 != 1)
+ if (d1 != 1) {
d1 = 1;
-
- puts(dcr_1);
+ puts(dcr_1);
+ }
printf(" %s repair completed\n\n",
get_device_name(i));
+ d[i] = 0.0;
}
}
}
puts(dcr_1);
printf(" %s state of repair improved\n\n",
get_device_name(r1));
+#if 0 // Basic allows it to go +ve ??
+ if (d[r1] > 0.0)
+ d[r1] = 0.0;
+#endif
}
}
}