+float sin_table[TWOREV];
+float cos_table[TWOREV];
+float tan_table[TWOREV];
+
+/*
+ * this table represents both the firing order and included angle of engine.
+ * To simplify things, we always number from 0 starting at the flywheel and
+ * moving down the crankshaft toward the back of the engine. This doesn't
+ * always match manufacturer's schemes. For example, the Porsche 911 engine
+ * is a flat six with the following configuration (Porsche's numbering):
+ *
+ * 3 2 1
+ * |= firing order is 1-6-2-4-3-5 in this diagram
+ * 6 5 4
+ *
+ * We renumber these using our scheme but preserve the effective firing order:
+ *
+ * 0 2 4
+ * |= firing order is 4-1-2-5-0-3 in this diagram
+ * 1 3 5
+ *
+ * To avoid going completely insane, we also reorder these so the newly
+ * renumbered cylinder 0 is always first: 0-3-4-1-2-5
+ *
+ * For a flat 6, the included angle is 180 degrees (0 would be a inline
+ * engine). Because these are all four-stroke engines, each piston goes
+ * through 720 degrees of rotation for each time the spark plug sparks,
+ * so in this case, we would use the following angles:
+ *
+ * cylinder firing order angle
+ * -------- ------------ -----
+ * 0 0 0
+ * 1 3 360
+ * 2 4 240
+ * 3 1 600
+ * 4 2 480
+ * 5 5 120
+ *
+ */
+
+typedef struct
+{
+ int cylinders;
+ int includedAngle;
+ int pistonAngle[12]; /* twelve cylinders should suffice... */
+ int speed; /* step size in degrees for engine speed */
+ const char *engineName; /* currently unused */
+} engine_type;
+
+engine_type engines[] = {
+ { 3, 0, { 0, 240, 480, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "Honda Insight" },
+ { 4, 0, { 0, 180, 540, 360, 0, 0,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "BMW M3" },
+ { 4, 180, { 0, 360, 180, 540, 0, 0,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "VW Beetle" },
+ { 5, 0, { 0, 576, 144, 432, 288, 0,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "Audi Quattro" },
+ { 6, 0, { 0, 240, 480, 120, 600, 360,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "BMW M5" },
+ { 6, 90, { 0, 360, 480, 120, 240, 600,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "Subaru XT" },
+ { 6, 180, { 0, 360, 240, 600, 480, 120,
+ 0, 0, 0, 0, 0, 0 }, 12,
+ "Porsche 911" },
+ { 8, 90, { 0, 450, 90, 180, 270, 360,
+ 540, 630, 0, 0, 0, 0 }, 15,
+ "Corvette Z06" },
+ {10, 90, { 0, 72, 432, 504, 288, 360,
+ 144, 216, 576, 648, 0, 0 }, 12,
+ "Dodge Viper" },
+ {12, 60, { 0, 300, 240, 540, 480, 60,
+ 120, 420, 600, 180, 360, 660 }, 12,
+ "Jaguar XKE" },
+};
+
+/* this define is just a little shorter way of referring to members of the
+ * table above
+ */
+#define ENG engines[engineType]
+
+/* given a number of cylinders and an included angle, finds matching engine */
+int find_engine(const char *name)
+{
+ unsigned int i;
+
+ if (!name || !*name || !strcasecmp (name, "(none)"))
+ return (random() % countof(engines));
+
+ for (i = 0; i < countof(engines); i++) {
+ if (!strcasecmp(name, engines[i].engineName))
+ return i;
+ }
+
+ fprintf (stderr, "%s: unknown engine type \"%s\"\n", progname, name);
+ fprintf (stderr, "%s: available models are:\n", progname);
+ for (i = 0; i < countof(engines); i++) {
+ fprintf (stderr, "\t %-13s (%d cylinders",
+ engines[i].engineName, engines[i].cylinders);
+ if (engines[i].includedAngle == 0)
+ fprintf (stderr, ")\n");
+ else if (engines[i].includedAngle == 180)
+ fprintf (stderr, ", flat)\n");
+ else
+ fprintf (stderr, ", V)\n");
+ }
+ exit(1);
+}