rnd-20100315-2-src
[rocksndiamonds.git] / src / game_sp / Globals.c
index 67491f730a84fb7ba0801094b6088131c5462628..cca754aa1ac06fba69bac790434da1c0caabef0b 100644 (file)
@@ -52,6 +52,7 @@ int LevelNumber;
 char *CurPath, *OrigPath, *TmpPath;
 boolean LevelLoaded;
 long SignatureDelay;
+boolean bSignatureAvailable;
 
 boolean bCapturePane;
 
@@ -66,7 +67,12 @@ byte *DisPlayField;
 
 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
 
-int TimerVar, RandomSeed;
+int TimerVar;
+#if 1
+short RandomSeed;
+#else
+int RandomSeed;
+#endif
 currency DeltaT; // Interval between two frames (in ms)
 long DeltaTPlay, DeltaTDemo;
 boolean BlockingSpeed;
@@ -167,29 +173,134 @@ int *aniEatInfotronLeft, *aniEatInfotronRight;
 #endif
 
 #if 1
-int aniBug[] = { 74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25 };
-int aniZonkRollRight[] = { 198, 197, 196, 195, 194, 193, 192, 1, -1 };
-int aniZonkRollLeft[] = { 192, 193, 194, 195, 196, 197, 198, 1, -1 };
-int aniInfotronRollRight[] = { 206, 205, 204, 203, 202, 201, 200, 4 };
-int aniInfotronRollLeft[] = { 200, 201, 202, 203, 204, 205, 206, 4 };
-int aniSnikSnak[] = { 121, 122, 123, 124, 125, 126, 127, 120, 121 };
-int aniElectron[] = { 144, 145, 146, 147, 148, 149, 150, 151, 144 };
-int aniExplosion[] = { 3, 103, 104, 105, 106, 107, 108, 109, 0 };
-int aniTouchBase[] = { 80, 81, 82, 83, 84, 85, 86, 0, -1 };
-int aniTouchInfotron[] = { 87, 88, 89, 91, 92, 93, 0, -1 }; // Only seven frames!!!!
-int aniTouchRedDisk[] = { 96, 97, 98, 99, 100, 101, 102, 0, -1 };
-int aniMurphyExit[] = { 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 0, 0, 0, 0, -1 };
-int aniMurphyEatLeft[] = { 176, 177, 178, 179, 180, 181, 182, 183, -1 };
-int aniMurphyEatRight[] = { 184, 185, 186, 187, 188, 189, 190, 191, -1 };
-int aniMurphyEatUpLeft[] = { 183, 182, 181, 180, 179, 178, 177, 176, -1 };
-int aniMurphyEatUpRight[] = { 191, 190, 189, 188, 187, 186, 185, 184, -1 };
-  // aniMurphyEatRightRedDisk = { 184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
-int aniEatInfotronLeft[] = { 209, 211, 213, 215, 217, 219, 221, 223, -1 };
-int aniEatInfotronRight[] = { 224, 226, 228, 230, 232, 234, 236, 238, -1 };
-int aniSplitUpDown[] = { 3, 3, 3, 3, 3, 3, 3, 3, -1 };
-int aniYellowDisk[] = { 18, 18, 18, 18, 18, 18, 18, 18, -1 };
-int aniOrangeDisk[] = { 8, 8, 8, 8, 8, 8, 8, 8, -1 };
-int aniRedDisk[] = { 20, -1 };
+int aniFramesBug[] = { 74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25 };
+int aniFramesZonkRollRight[] = { 198, 197, 196, 195, 194, 193, 192, 1, -1 };
+int aniFramesZonkRollLeft[] = { 192, 193, 194, 195, 196, 197, 198, 1, -1 };
+int aniFramesInfotronRollRight[] = { 206, 205, 204, 203, 202, 201, 200, 4 };
+int aniFramesInfotronRollLeft[] = { 200, 201, 202, 203, 204, 205, 206, 4 };
+int aniFramesSnikSnak[] = { 121, 122, 123, 124, 125, 126, 127, 120, 121 };
+int aniFramesElectron[] = { 144, 145, 146, 147, 148, 149, 150, 151, 144 };
+int aniFramesExplosion[] = { 3, 103, 104, 105, 106, 107, 108, 109, 0 };
+int aniFramesTouchBase[] = { 80, 81, 82, 83, 84, 85, 86, 0, -1 };
+int aniFramesTouchInfotron[] = { 87, 88, 89, 91, 92, 93, 0, -1 }; // Only seven frames!!!!
+int aniFramesTouchRedDisk[] = { 96, 97, 98, 99, 100, 101, 102, 0, -1 };
+int aniFramesMurphyExit[] = { 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 0, 0, 0, 0, -1 };
+int aniFramesMurphyEatLeft[] = { 176, 177, 178, 179, 180, 181, 182, 183, -1 };
+int aniFramesMurphyEatRight[] = { 184, 185, 186, 187, 188, 189, 190, 191, -1 };
+int aniFramesMurphyEatUpLeft[] = { 183, 182, 181, 180, 179, 178, 177, 176, -1 };
+int aniFramesMurphyEatUpRight[] = { 191, 190, 189, 188, 187, 186, 185, 184, -1 };
+  // aniFramesMurphyEatRightRedDisk = { 184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
+int aniFramesEatInfotronLeft[] = { 209, 211, 213, 215, 217, 219, 221, 223, -1 };
+int aniFramesEatInfotronRight[] = { 224, 226, 228, 230, 232, 234, 236, 238, -1 };
+int aniFramesSplitUpDown[] = { 3, 3, 3, 3, 3, 3, 3, 3, -1 };
+int aniFramesYellowDisk[] = { 18, 18, 18, 18, 18, 18, 18, 18, -1 };
+int aniFramesOrangeDisk[] = { 8, 8, 8, 8, 8, 8, 8, 8, -1 };
+int aniFramesRedDisk[] = { 20, -1 };
+#endif
+
+#if 1
+
+int fiGraphic[] =
+{
+  aniSpace,
+  aniZonk,
+  aniBase,
+  aniMurphy,
+  aniInfotron,
+  aniRAM,
+  aniHardWare,
+  aniExit,
+  aniOrangeDisk,
+  aniPortRight,
+  aniPortDown,
+  aniPortLeft,
+  aniPortUp,
+  aniSpPortRight,
+  aniSpPortDown,
+  aniSpPortLeft,
+  aniSpPortUp,
+  aniSnikSnak,
+  aniYellowDisk,
+  aniTerminal,
+  aniRedDisk,
+  aniPortUpAndDown,
+  aniPortLeftAndRight,
+  aniPortAllDirections,
+  aniElectron,
+  aniBug,
+  aniRAMLeft,
+  aniRAMRight,
+  aniHW0,
+  aniHW1,
+  aniHW2,
+  aniHW3,
+  aniHW4,
+  aniHW5,
+  aniHW6,
+  aniHW7,
+  aniHW8,
+  aniHW9,
+  aniRAMTop,
+  aniRAMBottom,
+  aniWallSpace
+};
+
+int aniSnikSnakTurningLeft[] =
+{
+  aniSnikSnakTurnUpToLeft,
+  aniSnikSnakTurnLeftToDown,
+  aniSnikSnakTurnDownToRight,
+  aniSnikSnakTurnRightToUp
+};
+
+int aniSnikSnakTurningRight[] =
+{
+  aniSnikSnakTurnUpToRight,
+  aniSnikSnakTurnRightToDown,
+  aniSnikSnakTurnDownToLeft,
+  aniSnikSnakTurnLeftToUp
+};
+
+
+int getSequenceLength(int sequence)
+{
+  switch (sequence)
+  {
+    case aniBug:
+      return 14;
+
+    case aniElectron:
+    case aniExplosion:
+      return 9;
+
+    case aniTouchInfotron:
+      return 7;
+
+    case aniMurphyExit:
+      return 40;
+
+    case aniRedDisk:
+      return 1;
+
+    default:
+      return 8;
+  }
+}
+
+boolean isSnappingSequence(int sequence)
+{
+  switch (sequence)
+  {
+    case aniTouchBase:
+    case aniTouchInfotron:
+    case aniTouchRedDisk:
+      return TRUE;
+
+    default:
+      return FALSE;
+  }
+}
+
 #endif
 
 void InitGlobals()
@@ -237,7 +348,6 @@ void InitGlobals()
   bSignatureAvailable = False;
   FirstDemoByte = 0x81;
   MySignature = "";
-  InitErrorReporting();
 }
 
 void InitPseudoCompileFlags()
@@ -324,8 +434,12 @@ int GetStretchY(int si)
   return GetStretchY;
 }
 
-void ReadLevel()
+void OLD_ReadLevel()
 {
+#if 1
+  static char CurPathTEST[1024];
+#endif
+
   // int FNum;
   FILE *FNum;
   long i;
@@ -333,13 +447,30 @@ void ReadLevel()
 
 #if 1
   // CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat";
+
+#if 0
   CurPath = "/home/aeglos/projects/rocksndiamonds/supaplex_demo_JENS0001.sp";
   LevelNumber = 1;
+#else
+
+#if 0
+  // sprintf(CurPathTEST, "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/test_solutions/%03d.sp", level_nr);
+
+  sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/Set77/77S%03d.SP", level_nr);
+#else
+  sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/solve00/JENS%04d.SP", level_nr);
+#endif
+
+  CurPath = CurPathTEST;
+  LevelNumber = level_nr;
+#endif
+
 #endif
 
   DemoAvailable = False;
 
-  if (STRING_IS_LIKE(CurPath, "*.mpx"))
+  if (STRING_IS_LIKE(CurPath, "*.mpx") ||
+      STRING_IS_LIKE(CurPath, "*.MPX"))
   {
     printf("::: reading MPX file ...\n");
 
@@ -347,7 +478,8 @@ void ReadLevel()
     return;
   }
 
-  if (STRING_IS_LIKE(CurPath, "*.sp"))
+  if (STRING_IS_LIKE(CurPath, "*.sp") ||
+      STRING_IS_LIKE(CurPath, "*.SP"))
   {
     printf("::: reading SP file ...\n");
 
@@ -462,6 +594,12 @@ static void ReadDemo()
   int i;
   // byte T;
 
+  int RecordNumber = LevelNumber;
+
+#if 1
+  RecordNumber = 1;    // always "1" for "*.sp" style one level/demo files
+#endif
+
   FieldWidth = 60;
   FieldHeight = 24;
   HeaderSize = 96;
@@ -480,14 +618,14 @@ static void ReadDemo()
 
   FNum = fopen(CurPath, "rb");
 
-  i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1;
+  i = (RecordNumber - 1) * ((long)(FieldMax) + 1) + 1;
 #if 1
   FILE_GET(FNum, i, PlayField8, FileMax + 1);
 #else
   FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8));
 #endif
 
-  i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
+  i = (RecordNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize;
   FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure
 
   fclose(FNum);
@@ -522,8 +660,61 @@ static void ReadDemo()
   GravityFlag = LInfo.InitialGravity;
   FreezeZonks = LInfo.InitialFreezeZonks;
 
+#if 0
+  printf("::: Globals.c: ReadDemo(): %d / %d\n", GravityFlag, FreezeZonks);
+#endif
+
+
+
+#if 0
+  /* !!! TESTING BIG / LITTLE ENDIAN STUFF !!! */
+  LInfo.DemoRandomSeed =
+    LowByte(LInfo.DemoRandomSeed) << 8 |
+    HighByte(LInfo.DemoRandomSeed);
+  for (i = 0; i < 10; i++)
+    LInfo.SpecialPort[i].PortLocation =
+      LowByte(LInfo.SpecialPort[i].PortLocation) << 8 |
+      HighByte(LInfo.SpecialPort[i].PortLocation);
+
+  printf("::: swapping file bytes for DemoRandomSeed etc.\n");
+#else
+  printf("::: keeping file bytes in (maybe wrong) 'native' order.\n");
+#endif
+
+#if 1
+  printf("::: LInfo.DemoRandomSeed == %d\n", LInfo.DemoRandomSeed);
+#endif
+
+#if 0
+  printf("::: LInfo.SpecialPortCount == %d\n", LInfo.SpecialPortCount);
+  for (i = 0; i < LInfo.SpecialPortCount; i++)
+  {
+    int port_x = (LInfo.SpecialPort[i].PortLocation / 2) % FieldWidth;
+    int port_y = (LInfo.SpecialPort[i].PortLocation / 2) / FieldWidth;
+
+    printf("::: %d: port_location == %d => (%d, %d)\n",
+          i, LInfo.SpecialPort[i].PortLocation, port_x, port_y);
+  }
+#endif
+
   RandomSeed = LInfo.DemoRandomSeed;
 
+#if 0
+  printf("::: SpeedByte == %d\n", LInfo.SpeedByte);
+  printf("::: CheckSumByte == %d\n", LInfo.CheckSumByte);
+  printf("::: RandomSeed == %d\n", RandomSeed);
+
+#if 0
+  {
+    int i;
+
+    for (i = 0; i < 10; i++)
+      printf("::: TEST random number: %d\n", subGetRandomNumber());
+  }
+#endif
+
+#endif
+
   LevelLoaded = True;
 
   return;
@@ -533,3 +724,62 @@ ReadDemoEH:
   Close();
 #endif
 }
+
+void ReadLevel()
+{
+#if 0
+  OLD_ReadLevel();
+
+  // return;
+#endif
+
+  copyInternalEngineVars_SP();
+
+#if 1
+  SetDisplayRegion();
+  SetScrollEdges();
+#endif
+
+  LevelNumber = level_nr;
+
+#if 0
+  if (!DemoFlag || !DemoAvailable)
+    subRandomize();
+#endif
+
+  LevelLoaded = True;
+}
+
+void Trace(char *Source, char *Message)
+{
+  printf("::: Trace: Source == '%s', Message == '%s'\n", Source, Message);
+}
+
+void ReportError(char *Source, char *Message)
+{
+  printf("::: ReportError: Source == '%s', Message == '%s'\n", Source, Message);
+}
+
+int Min(int A, int B)
+{
+  int Min;
+
+  if (A < B)
+    Min = A;
+  else
+    Min = B;
+
+  return Min;
+}
+
+int Max(int A, int B)
+{
+  int Max;
+
+  if (A < B)
+    Max = B;
+  else
+    Max = A;
+
+  return Max;
+}