added Android project files
[rocksndiamonds.git] / src / game.c
index 2dcc07a496969b3782f16f9908c60e1d5106cc65..57771d75b866c7f4995fefb43eea95ad94830fd5 100644 (file)
@@ -1016,14 +1016,16 @@ static struct GamePanelControlInfo game_panel_controls[] =
 #define GAME_CTRL_ID_PANEL_STOP                8
 #define GAME_CTRL_ID_PANEL_PAUSE       9
 #define GAME_CTRL_ID_PANEL_PLAY                10
-#define SOUND_CTRL_ID_MUSIC            11
-#define SOUND_CTRL_ID_LOOPS            12
-#define SOUND_CTRL_ID_SIMPLE           13
-#define SOUND_CTRL_ID_PANEL_MUSIC      14
-#define SOUND_CTRL_ID_PANEL_LOOPS      15
-#define SOUND_CTRL_ID_PANEL_SIMPLE     16
+#define GAME_CTRL_ID_TOUCH_STOP                11
+#define GAME_CTRL_ID_TOUCH_PAUSE       12
+#define SOUND_CTRL_ID_MUSIC            13
+#define SOUND_CTRL_ID_LOOPS            14
+#define SOUND_CTRL_ID_SIMPLE           15
+#define SOUND_CTRL_ID_PANEL_MUSIC      16
+#define SOUND_CTRL_ID_PANEL_LOOPS      17
+#define SOUND_CTRL_ID_PANEL_SIMPLE     18
 
-#define NUM_GAME_BUTTONS               17
+#define NUM_GAME_BUTTONS               19
 
 
 // forward declaration for internal use
@@ -3354,7 +3356,7 @@ void InitGame(void)
   SetGameStatus(GAME_MODE_PLAYING);
 
   if (level_editor_test_game)
-    FadeSkipNextFadeIn();
+    FadeSkipNextFadeOut();
   else
     FadeSetEnterScreen();
 
@@ -3365,8 +3367,10 @@ void InitGame(void)
 
   ExpireSoundLoops(TRUE);
 
-  if (!level_editor_test_game)
-    FadeOut(fade_mask);
+  FadeOut(fade_mask);
+
+  if (level_editor_test_game)
+    FadeSkipNextFadeIn();
 
   // needed if different viewport properties defined for playing
   ChangeViewportPropertiesIfNeeded();
@@ -12180,12 +12184,17 @@ void GameActions_RND(void)
   DrawAllPlayers();
   PlayAllPlayersSound();
 
-  if (local_player->show_envelope != 0 && (!local_player->active ||
-                                          local_player->MovPos == 0))
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
-    ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
+    struct PlayerInfo *player = &stored_player[i];
 
-    local_player->show_envelope = 0;
+    if (player->show_envelope != 0 && (!player->active ||
+                                      player->MovPos == 0))
+    {
+      ShowEnvelope(player->show_envelope - EL_ENVELOPE_1);
+
+      player->show_envelope = 0;
+    }
   }
 
   // use random number generator in every frame to make it less predictable
@@ -12527,10 +12536,11 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
     }
     else
     {
-      int offset = game.scroll_delay_value;
+      int offset_raw = game.scroll_delay_value;
 
       if (jx != old_jx)                // player has moved horizontally
       {
+       int offset = MIN(offset_raw, (SCR_FIELDX - 2) / 2);
        int offset_x = offset * (player->MovDir == MV_LEFT ? +1 : -1);
        int new_scroll_x = jx - MIDPOSX + offset_x;
 
@@ -12551,6 +12561,7 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
       }
       else                     // player has moved vertically
       {
+       int offset = MIN(offset_raw, (SCR_FIELDY - 2) / 2);
        int offset_y = offset * (player->MovDir == MV_UP ? +1 : -1);
        int new_scroll_y = jy - MIDPOSY + offset_y;
 
@@ -15467,93 +15478,104 @@ static struct
   int gadget_id;
   boolean *setup_value;
   boolean allowed_on_tape;
+  boolean is_touch_button;
   char *infotext;
 } gamebutton_info[NUM_GAME_BUTTONS] =
 {
   {
     IMG_GFX_GAME_BUTTON_STOP,                  &game.button.stop,
     GAME_CTRL_ID_STOP,                         NULL,
-    TRUE,                                      "stop game"
+    TRUE, FALSE,                               "stop game"
   },
   {
     IMG_GFX_GAME_BUTTON_PAUSE,                 &game.button.pause,
     GAME_CTRL_ID_PAUSE,                                NULL,
-    TRUE,                                      "pause game"
+    TRUE, FALSE,                               "pause game"
   },
   {
     IMG_GFX_GAME_BUTTON_PLAY,                  &game.button.play,
     GAME_CTRL_ID_PLAY,                         NULL,
-    TRUE,                                      "play game"
+    TRUE, FALSE,                               "play game"
   },
   {
     IMG_GFX_GAME_BUTTON_UNDO,                  &game.button.undo,
     GAME_CTRL_ID_UNDO,                         NULL,
-    TRUE,                                      "undo step"
+    TRUE, FALSE,                               "undo step"
   },
   {
     IMG_GFX_GAME_BUTTON_REDO,                  &game.button.redo,
     GAME_CTRL_ID_REDO,                         NULL,
-    TRUE,                                      "redo step"
+    TRUE, FALSE,                               "redo step"
   },
   {
     IMG_GFX_GAME_BUTTON_SAVE,                  &game.button.save,
     GAME_CTRL_ID_SAVE,                         NULL,
-    TRUE,                                      "save game"
+    TRUE, FALSE,                               "save game"
   },
   {
     IMG_GFX_GAME_BUTTON_PAUSE2,                        &game.button.pause2,
     GAME_CTRL_ID_PAUSE2,                       NULL,
-    TRUE,                                      "pause game"
+    TRUE, FALSE,                               "pause game"
   },
   {
     IMG_GFX_GAME_BUTTON_LOAD,                  &game.button.load,
     GAME_CTRL_ID_LOAD,                         NULL,
-    TRUE,                                      "load game"
+    TRUE, FALSE,                               "load game"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_STOP,            &game.button.panel_stop,
     GAME_CTRL_ID_PANEL_STOP,                   NULL,
-    FALSE,                                     "stop game"
+    FALSE, FALSE,                              "stop game"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_PAUSE,           &game.button.panel_pause,
     GAME_CTRL_ID_PANEL_PAUSE,                  NULL,
-    FALSE,                                     "pause game"
+    FALSE, FALSE,                              "pause game"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_PLAY,            &game.button.panel_play,
     GAME_CTRL_ID_PANEL_PLAY,                   NULL,
-    FALSE,                                     "play game"
+    FALSE, FALSE,                              "play game"
+  },
+  {
+    IMG_GFX_GAME_BUTTON_TOUCH_STOP,            &game.button.touch_stop,
+    GAME_CTRL_ID_TOUCH_STOP,                   NULL,
+    FALSE, TRUE,                               "stop game"
+  },
+  {
+    IMG_GFX_GAME_BUTTON_TOUCH_PAUSE,           &game.button.touch_pause,
+    GAME_CTRL_ID_TOUCH_PAUSE,                  NULL,
+    FALSE, TRUE,                               "pause game"
   },
   {
     IMG_GFX_GAME_BUTTON_SOUND_MUSIC,           &game.button.sound_music,
     SOUND_CTRL_ID_MUSIC,                       &setup.sound_music,
-    TRUE,                                      "background music on/off"
+    TRUE, FALSE,                               "background music on/off"
   },
   {
     IMG_GFX_GAME_BUTTON_SOUND_LOOPS,           &game.button.sound_loops,
     SOUND_CTRL_ID_LOOPS,                       &setup.sound_loops,
-    TRUE,                                      "sound loops on/off"
+    TRUE, FALSE,                               "sound loops on/off"
   },
   {
     IMG_GFX_GAME_BUTTON_SOUND_SIMPLE,          &game.button.sound_simple,
     SOUND_CTRL_ID_SIMPLE,                      &setup.sound_simple,
-    TRUE,                                      "normal sounds on/off"
+    TRUE, FALSE,                               "normal sounds on/off"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_SOUND_MUSIC,     &game.button.panel_sound_music,
     SOUND_CTRL_ID_PANEL_MUSIC,                 &setup.sound_music,
-    FALSE,                                     "background music on/off"
+    FALSE, FALSE,                              "background music on/off"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_SOUND_LOOPS,     &game.button.panel_sound_loops,
     SOUND_CTRL_ID_PANEL_LOOPS,                 &setup.sound_loops,
-    FALSE,                                     "sound loops on/off"
+    FALSE, FALSE,                              "sound loops on/off"
   },
   {
     IMG_GFX_GAME_BUTTON_PANEL_SOUND_SIMPLE,    &game.button.panel_sound_simple,
     SOUND_CTRL_ID_PANEL_SIMPLE,                        &setup.sound_simple,
-    FALSE,                                     "normal sounds on/off"
+    FALSE, FALSE,                              "normal sounds on/off"
   }
 };
 
@@ -15570,10 +15592,11 @@ void CreateGameButtons(void)
     int button_type;
     boolean checked;
     unsigned int event_mask;
+    boolean is_touch_button = gamebutton_info[i].is_touch_button;
     boolean allowed_on_tape = gamebutton_info[i].allowed_on_tape;
     boolean on_tape = (tape.show_game_buttons && allowed_on_tape);
-    int base_x = (on_tape ? VX : DX);
-    int base_y = (on_tape ? VY : DY);
+    int base_x = (is_touch_button ? 0 : on_tape ? VX : DX);
+    int base_y = (is_touch_button ? 0 : on_tape ? VY : DY);
     int gd_x   = gfx->src_x;
     int gd_y   = gfx->src_y;
     int gd_xp  = gfx->src_x + gfx->pressed_xoffset;
@@ -15582,6 +15605,8 @@ void CreateGameButtons(void)
     int gd_ya  = gfx->src_y + gfx->active_yoffset;
     int gd_xap = gfx->src_x + gfx->active_xoffset + gfx->pressed_xoffset;
     int gd_yap = gfx->src_y + gfx->active_yoffset + gfx->pressed_yoffset;
+    int x = (is_touch_button ? pos->x : GDI_ACTIVE_POS(pos->x));
+    int y = (is_touch_button ? pos->y : GDI_ACTIVE_POS(pos->y));
     int id = i;
 
     if (gfx->bitmap == NULL)
@@ -15593,6 +15618,7 @@ void CreateGameButtons(void)
 
     if (id == GAME_CTRL_ID_STOP ||
        id == GAME_CTRL_ID_PANEL_STOP ||
+       id == GAME_CTRL_ID_TOUCH_STOP ||
        id == GAME_CTRL_ID_PLAY ||
        id == GAME_CTRL_ID_PANEL_PLAY ||
        id == GAME_CTRL_ID_SAVE ||
@@ -15620,8 +15646,8 @@ void CreateGameButtons(void)
     gi = CreateGadget(GDI_CUSTOM_ID, id,
                      GDI_IMAGE_ID, graphic,
                      GDI_INFO_TEXT, gamebutton_info[i].infotext,
-                     GDI_X, base_x + GDI_ACTIVE_POS(pos->x),
-                     GDI_Y, base_y + GDI_ACTIVE_POS(pos->y),
+                     GDI_X, base_x + x,
+                     GDI_Y, base_y + y,
                      GDI_WIDTH, gfx->width,
                      GDI_HEIGHT, gfx->height,
                      GDI_TYPE, button_type,
@@ -15632,6 +15658,7 @@ void CreateGameButtons(void)
                      GDI_ALT_DESIGN_UNPRESSED, gfx->bitmap, gd_xa, gd_ya,
                      GDI_ALT_DESIGN_PRESSED, gfx->bitmap, gd_xap, gd_yap,
                      GDI_DIRECT_DRAW, FALSE,
+                     GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
                      GDI_EVENT_MASK, event_mask,
                      GDI_CALLBACK_ACTION, HandleGameButtons,
                      GDI_END);
@@ -15702,8 +15729,6 @@ void MapUndoRedoButtons(void)
 
   MapGadget(game_gadget[GAME_CTRL_ID_UNDO]);
   MapGadget(game_gadget[GAME_CTRL_ID_REDO]);
-
-  ModifyGadget(game_gadget[GAME_CTRL_ID_PAUSE2], GDI_CHECKED, TRUE, GDI_END);
 }
 
 void UnmapUndoRedoButtons(void)
@@ -15713,8 +15738,22 @@ void UnmapUndoRedoButtons(void)
 
   MapGameButtonsAtSamePosition(GAME_CTRL_ID_UNDO);
   MapGameButtonsAtSamePosition(GAME_CTRL_ID_REDO);
+}
+
+void ModifyPauseButtons(void)
+{
+  static int ids[] =
+  {
+    GAME_CTRL_ID_PAUSE,
+    GAME_CTRL_ID_PAUSE2,
+    GAME_CTRL_ID_PANEL_PAUSE,
+    GAME_CTRL_ID_TOUCH_PAUSE,
+    -1
+  };
+  int i;
 
-  ModifyGadget(game_gadget[GAME_CTRL_ID_PAUSE2], GDI_CHECKED, FALSE, GDI_END);
+  for (i = 0; ids[i] > -1; i++)
+    ModifyGadget(game_gadget[ids[i]], GDI_CHECKED, tape.pausing, GDI_END);
 }
 
 static void MapGameButtonsExt(boolean on_tape)
@@ -15748,9 +15787,6 @@ static void RedrawGameButtonsExt(boolean on_tape)
   for (i = 0; i < NUM_GAME_BUTTONS; i++)
     if (!on_tape || gamebutton_info[i].allowed_on_tape)
       RedrawGadget(game_gadget[i]);
-
-  // RedrawGadget() may have set REDRAW_ALL if buttons are defined off-area
-  redraw_mask &= ~REDRAW_ALL;
 }
 
 static void SetGadgetState(struct GadgetInfo *gi, boolean state)
@@ -15857,6 +15893,7 @@ static void HandleGameButtonsExt(int id, int button)
   {
     case GAME_CTRL_ID_STOP:
     case GAME_CTRL_ID_PANEL_STOP:
+    case GAME_CTRL_ID_TOUCH_STOP:
       if (game_status == GAME_MODE_MAIN)
        break;
 
@@ -15870,6 +15907,7 @@ static void HandleGameButtonsExt(int id, int button)
     case GAME_CTRL_ID_PAUSE:
     case GAME_CTRL_ID_PAUSE2:
     case GAME_CTRL_ID_PANEL_PAUSE:
+    case GAME_CTRL_ID_TOUCH_PAUSE:
       if (network.enabled && game_status == GAME_MODE_PLAYING)
       {
        if (tape.pausing)