fixed compiler warnings (after adding "-Wstrict-prototypes")
[rocksndiamonds.git] / src / game_sp / MainForm.c
index f169bac384a68bedd9412c18e51329cfba56e198..85f7a12988e2efc6a13d945c175b845b2b68279d 100644 (file)
@@ -6,98 +6,58 @@
 
 
 static void DrawFrame(int Delta);
-static void ReStretch(float NewStretch);
-static void picViewPort_Resize();
+static void ReStretch(void);
 
 void DrawField(int X, int Y);
 void DrawFieldAnimated(int X, int Y);
 void DrawFieldNoAnimated(int X, int Y);
 
-boolean Loaded;
-
-void DrawFrameIfNeeded()
+void DrawFrameIfNeeded(void)
 {
   DrawFrame(0);
 
   /* !!! CHECK THIS !!! */
-#if 1
   if (! menBorder)
     DrawFrame(1);
-#endif
 }
 
-void DisplayLevel()
+void DisplayLevel(void)
 {
   int X, Y;
 
-  if (! Loaded)
-    return;
-
   if (! LevelLoaded)
     return;
 
   ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
-  ClearRectangle(screenBitmap, 0, 0,
-                MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY);
+  ClearRectangle(bitmap_db_field_sp, 0, 0, FXSIZE, FYSIZE);
 
-#if 1
   SetDisplayRegion();
-#endif
 
-  DrawFrame(0);
-
-  /* !!! CHECK THIS !!! */
-#if 1
-  if (! menBorder)
-    DrawFrame(1);
-#endif
+  DrawFrameIfNeeded();
 
   if (bPlaying)
   {
-#if 0
-    printf("::: MainForm.c: DisplayLevel(): [%ld, %ld, %ld, %ld] [%d, %d]...\n",
-          DisplayMinX, DisplayMinY, DisplayMaxX, DisplayMaxY,
-          FieldWidth, FieldHeight);
-#endif
-
     for (Y = DisplayMinY; Y <= DisplayMaxY; Y++)
-    {
       for (X = DisplayMinX; X <= DisplayMaxX; X++)
-      {
         DrawFieldNoAnimated(X, Y);
-      }
-    }
 
     for (Y = DisplayMinY; Y <= DisplayMaxY; Y++)
-    {
       for (X = DisplayMinX; X <= DisplayMaxX; X++)
-      {
         DrawFieldAnimated(X, Y);
-      }
-    }
-
   }
   else
   {
     for (Y = DisplayMinY; Y <= DisplayMaxY; Y++)
-    {
       for (X = DisplayMinX; X <= DisplayMaxX; X++)
-      {
         DrawField(X, Y);
-      }
-    }
   }
 }
 
-void Form_Load()
+void Form_Load(void)
 {
-  Loaded = False;
-
   InitGlobals();
 
-  Loaded = True;
-
-  ReStretch(Stretch);
+  ReStretch();
 }
 
 static void DrawFrame(int Delta)
@@ -108,24 +68,32 @@ static void DrawFrame(int Delta)
   tY = -1 + Delta;
   RX = FieldWidth - Delta;
   BY = FieldHeight - Delta;
-  DrawImage(LX, tY, imgFrameCorner);
-  DrawImage(LX, BY, imgFrameCorner);
-  DrawImage(RX, tY, imgFrameCorner);
-  DrawImage(RX, BY, imgFrameCorner);
+
+  DrawImage(LX, tY, (Delta > 0 ? imgFrameCorner : aniSpace));
+  DrawImage(LX, BY, (Delta > 0 ? imgFrameCorner : aniSpace));
+  DrawImage(RX, tY, (Delta > 0 ? imgFrameCorner : aniSpace));
+  DrawImage(RX, BY, (Delta > 0 ? imgFrameCorner : aniSpace));
+
   for (i = LX + 1; i <= RX - 1; i++)
   {
-    DrawImage(i, tY, imgFrameHorizontal);
-    DrawImage(i, BY, imgFrameHorizontal);
+    DrawImage(i, tY, (Delta > 0 ? imgFrameHorizontal : aniSpace));
+    DrawImage(i, BY, (Delta > 0 ? imgFrameHorizontal : aniSpace));
   }
 
   for (i = tY + 1; i <= BY - 1; i++)
   {
-    DrawImage(LX, i, imgFrameVertical);
-    DrawImage(RX, i, imgFrameVertical);
+    DrawImage(LX, i, (Delta > 0 ? imgFrameVertical : aniSpace));
+    DrawImage(RX, i, (Delta > 0 ? imgFrameVertical : aniSpace));
+  }
+
+  if (Delta > 0)
+  {
+    // ...
+    // ClearRectangle(bitmap_db_field_sp, 
   }
 }
 
-static void RestoreFrame()
+static void RestoreFrame(void)
 {
   int i, LX, tY, RX, BY;
 
@@ -147,16 +115,14 @@ static void RestoreFrame()
   }
 }
 
-void SetDisplayRegion()
+void SetDisplayRegion(void)
 {
   if (! menBorder)
   {
     DisplayMinX = 1;
-    DisplayMaxX = FieldWidth - 2;
-    DisplayWidth = FieldWidth;
     DisplayMinY = 1;
+    DisplayMaxX = FieldWidth - 2;
     DisplayMaxY = FieldHeight - 2;
-    DisplayHeight = FieldHeight;
 
     if (LevelLoaded)
       DrawFrame(1);
@@ -164,57 +130,36 @@ void SetDisplayRegion()
   else
   {
     DisplayMinX = 0;
-    DisplayMaxX = FieldWidth - 1;
-    DisplayWidth = FieldWidth + 2;
     DisplayMinY = 0;
+    DisplayMaxX = FieldWidth - 1;
     DisplayMaxY = FieldHeight - 1;
-    DisplayHeight = FieldHeight + 2;
 
     if (LevelLoaded)
       RestoreFrame();
   }
 }
 
-void menPlay_Click()
+void menPlay_Click(void)
 {
   bPlaying = True;
 
   subFetchAndInitLevelB();
 
-  ReStretch(Stretch);
+  ReStretch();
 
   subMainGameLoop_Init();
-
-#if 1
-  return;
-#endif
-
-  bPlaying = False;
-
-  subFetchAndInitLevel();
 }
 
-static void ReStretch(float NewStretch)
+static void ReStretch(void)
 {
-  long BW2, LW, LH;
-
-  if (! Loaded)
+  if (LevelLoaded)
   {
-    Stretch = NewStretch;
-
-    return;
-  }
+    SetDisplayRegion();
 
-  Stretch = NewStretch;
+    SetScrollEdges();
 
-  BW2 = StretchWidth / 2;
-  LW = (FieldWidth + 2) * BaseWidth; // StretchWidth
-  LH = (FieldHeight + 2) * BaseWidth; // StretchWidth
+    ScrollTo(ScrollX, ScrollY);
 
-  if (Loaded && LevelLoaded)
-  {
-    SetDisplayRegion();
-    picViewPort_Resize();
     DisplayLevel();
   }
 
@@ -223,50 +168,57 @@ static void ReStretch(float NewStretch)
   ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
 }
 
-void SetScrollEdges()
+void SetScrollEdges(void)
 {
-  ScrollMinX = (int)(DisplayMinX - 0.5) * Stretch * BaseWidth;
-  ScrollMinY = (int)(DisplayMinY - 0.5) * Stretch * BaseWidth;
-  ScrollMaxX = (int)(DisplayMaxX + 1.5) * Stretch * BaseWidth - SXSIZE;
-  ScrollMaxY = (int)(DisplayMaxY + 1.5) * Stretch * BaseWidth - SYSIZE;
+  int border1_offset = (menBorder ? 1 : 2);
+  int border2_offset = (menBorder ? 0 : TILESIZE / 2);
+
+  /* scroll correction for border frame (1 tile) or border element (2 tiles) */
+  ScrollMinX = 0;
+  ScrollMinY = 0;
+  ScrollMaxX = (DisplayMaxX + border1_offset - SCR_FIELDX) * TILEX;
+  ScrollMaxY = (DisplayMaxY + border1_offset - SCR_FIELDY) * TILEY;
+
+  /* scroll correction for border element (half tile on left and right side) */
+  ScrollMinX += border2_offset;
+  ScrollMinY += border2_offset;
+  ScrollMaxX -= border2_offset;
+  ScrollMaxY -= border2_offset;
+
+  /* scroll correction for even number of visible tiles (half tile shifted) */
+  ScrollMinX -= game_sp.scroll_xoffset;
+  ScrollMaxX -= game_sp.scroll_xoffset;
+  ScrollMinY -= game_sp.scroll_yoffset;
+  ScrollMaxY -= game_sp.scroll_yoffset;
 }
 
 void DrawField(int X, int Y)
 {
-  int Tmp, tsi;
+  int tsi = GetSI(X, Y);
+  int Tmp = LowByte(PlayField16[tsi]);
 
-  tsi = GetSI(X, Y);
-  Tmp = LowByte(PlayField16[tsi]);
-  if (Tmp > 40)
-    Tmp = 0;
-
-  if (Tmp == fiRAM || Tmp == fiHardWare)
-    Tmp = DisPlayField[tsi];
+  if (Tmp < fiFirst || Tmp > fiLast)
+    Tmp = fiSpace;
 
-  if (Tmp == fiBug || Tmp == 40)
+  if (Tmp == fiRAM ||
+      Tmp == fiHardWare ||
+      Tmp == fiBug ||
+      Tmp == fiWallSpace)
     Tmp = DisPlayField[tsi];
 
-#if 1
-  if (Tmp >= 0 && Tmp <= 40)
-  {
-    subCopyImageToScreen(tsi, fiGraphic[Tmp]);
+  subCopyImageToScreen(tsi, fiGraphic[Tmp]);
 
-#if 1
-    if (Tmp != fiSpace && Tmp != fiSnikSnak && Tmp != fiElectron)
-      GfxGraphic[X][Y] = fiGraphic[Tmp];
-#endif
-  }
-#else
-  DDSpriteBuffer_BltEx(StretchWidth * X, StretchWidth * Y, Tmp);
-#endif
+  if (Tmp != fiSpace &&
+      Tmp != fiSnikSnak &&
+      Tmp != fiElectron)
+    GfxGraphic[X][Y] = fiGraphic[Tmp];
 }
 
 void DrawFieldAnimated(int X, int Y)
 {
-  int Tmp, tsi;
+  int tsi = GetSI(X, Y);
+  int Tmp = LowByte(PlayField16[tsi]);
 
-  tsi = GetSI(X, Y);
-  Tmp = LowByte(PlayField16[tsi]);
   switch (Tmp)
   {
     case fiSnikSnak:
@@ -278,23 +230,15 @@ void DrawFieldAnimated(int X, int Y)
       break;
 
     default:
-      //      If 40 < Tmp Then Tmp = 0
-      //      If Tmp = fiRAM Or Tmp = fiHardWare Then Tmp = DisPlayField(tsi)
-      //      If Tmp = fiBug Or Tmp = 40 Then Tmp = DisPlayField(tsi)
-      //      If EditFlag Then
-      //        If fiOrangeDisk < Tmp And Tmp < fiSnikSnak Then Tmp = DisPlayField(tsi)
-      //      End If
-      //      DDSpriteBuffer_BltEx StretchWidth * X, StretchWidth * Y, Tmp
       break;
   }
 }
 
 void DrawFieldNoAnimated(int X, int Y)
 {
-  int Tmp, tsi;
+  int tsi = GetSI(X, Y);
+  int Tmp = LowByte(PlayField16[tsi]);
 
-  tsi = GetSI(X, Y);
-  Tmp = LowByte(PlayField16[tsi]);
   switch (Tmp)
   {
     case fiSnikSnak:
@@ -306,29 +250,7 @@ void DrawFieldNoAnimated(int X, int Y)
       break;
 
     default:
-      if (Tmp > 40)
-        Tmp = 0;
-
-      if (Tmp == fiRAM || Tmp == fiHardWare)
-        Tmp = DisPlayField[tsi];
-
-      if (Tmp == fiBug || Tmp == 40)
-        Tmp = DisPlayField[tsi];
-
-#if 1
-      if (Tmp >= 0 && Tmp <= 40)
-      {
-       subCopyImageToScreen(tsi, fiGraphic[Tmp]);
-
-#if 1
-       if (Tmp != fiSpace && Tmp != fiSnikSnak && Tmp != fiElectron)
-         GfxGraphic[X][Y] = fiGraphic[Tmp];
-#endif
-      }
-#else
-      DDSpriteBuffer_BltEx(StretchWidth * X, StretchWidth * Y, Tmp);
-#endif
-
+      DrawField(X, Y);
       break;
   }
 }
@@ -337,10 +259,3 @@ void DrawImage(int X, int Y, int graphic)
 {
   DDSpriteBuffer_BltImg(StretchWidth * X, StretchWidth * Y, graphic, 0);
 }
-
-static void picViewPort_Resize()
-{
-  SetScrollEdges();
-
-  ScrollTo(ScrollX, ScrollY);
-}