+/*
+ * This is an abstraction of the game's input state. All input is
+ * encapsulated here, and all references to the input by the game are made
+ * here. This has the effect of homogenizing input for use in replay
+ * recording and playback.
+ *
+ * x and z:
+ * -32767 = -ANGLE_BOUND
+ * +32767 = +ANGLE_BOUND
+ *
+ * r:
+ * -32767 = -VIEWR_BOUND
+ * +32767 = +VIEWR_BOUND
+ *
+ */
+
+struct input
+{
+ short x;
+ short z;
+ short r;
+ short c;
+};
+
+static struct input input_current;
+
+static void input_init(void)
+{
+ input_current.x = 0;
+ input_current.z = 0;
+ input_current.r = 0;
+ input_current.c = 0;
+}
+
+static void input_set_x(float x)
+{
+ if (x < -ANGLE_BOUND) x = -ANGLE_BOUND;
+ if (x > ANGLE_BOUND) x = ANGLE_BOUND;
+
+ input_current.x = (short) (32767.0f * x / ANGLE_BOUND);
+}
+
+static void input_set_z(float z)
+{
+ if (z < -ANGLE_BOUND) z = -ANGLE_BOUND;
+ if (z > ANGLE_BOUND) z = ANGLE_BOUND;
+
+ input_current.z = (short) (32767.0f * z / ANGLE_BOUND);
+}
+
+static void input_set_r(float r)
+{
+ if (r < -VIEWR_BOUND) r = -VIEWR_BOUND;
+ if (r > VIEWR_BOUND) r = VIEWR_BOUND;
+
+ input_current.r = (short) (32767.0f * r / VIEWR_BOUND);
+}
+
+static void input_set_c(int c)
+{
+ input_current.c = (short) c;
+}
+
+static float input_get_x(void)
+{
+ return ANGLE_BOUND * (float) input_current.x / 32767.0f;
+}
+
+static float input_get_z(void)
+{
+ return ANGLE_BOUND * (float) input_current.z / 32767.0f;
+}
+
+static float input_get_r(void)
+{
+ return VIEWR_BOUND * (float) input_current.r / 32767.0f;
+}
+
+static int input_get_c(void)
+{
+ return (int) input_current.c;
+}
+
+int input_put(FILE *fout)
+{
+ if (game_state)
+ {
+ put_short(fout, &input_current.x);
+ put_short(fout, &input_current.z);
+ put_short(fout, &input_current.r);
+ put_short(fout, &input_current.c);
+
+ return 1;
+ }
+ return 0;
+}
+
+int input_get(FILE *fin)
+{
+ if (game_state)
+ {
+ get_short(fin, &input_current.x);
+ get_short(fin, &input_current.z);
+ get_short(fin, &input_current.r);
+ get_short(fin, &input_current.c);
+
+ return (feof(fin) ? 0 : 1);
+ }
+ return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+