fixed wrong position of global animations in 'door_2' in level editor
[rocksndiamonds.git] / src / anim.c
index 933af1dec0b6d713bbc13567f2cf9b9f1147de0b..824f86b5a159e441fc90c03112b0e45cc36cae0c 100644 (file)
@@ -19,6 +19,9 @@
 #include "screens.h"
 
 
+#define DEBUG_ANIM_EVENTS              0
+
+
 // values for global toon animation definition
 #define NUM_GLOBAL_TOON_ANIMS          1
 #define NUM_GLOBAL_TOON_PARTS          MAX_NUM_TOONS
@@ -851,10 +854,20 @@ static boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part
   }
   else if (part->control_info.class == get_hash_from_key("door_2"))
   {
-    viewport_x = VX;
-    viewport_y = VY;
-    viewport_width  = VXSIZE;
-    viewport_height = VYSIZE;
+    if (part->mode_nr == GAME_MODE_EDITOR)
+    {
+      viewport_x = EX;
+      viewport_y = EY;
+      viewport_width  = EXSIZE;
+      viewport_height = EYSIZE;
+    }
+    else
+    {
+      viewport_x = VX;
+      viewport_y = VY;
+      viewport_width  = VXSIZE;
+      viewport_height = VYSIZE;
+    }
   }
   else         // default: "playfield"
   {
@@ -1069,7 +1082,7 @@ static boolean clickConsumed(struct GlobalAnimPartControlInfo *part)
 static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
                                     boolean *anything_clicked,
                                     boolean *any_event_action,
-                                    int event_value)
+                                    int event_value, char *info_text)
 {
   struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
 
@@ -1099,6 +1112,11 @@ static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
        part2->triggered = TRUE;
        *anything_clicked = clickConsumed(part);        // click was on "part"!
 
+#if DEBUG_ANIM_EVENTS
+       printf("::: => %d.%d TRIGGERED BY %s OF %d.%d\n",
+              part2->old_anim_nr + 1, part2->old_nr + 1, info_text,
+              part->old_anim_nr + 1, part->old_nr + 1);
+#endif
 #if 0
        printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr,
               part2->control_info.anim_event_action);
@@ -1125,6 +1143,21 @@ static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
   }
 }
 
+static void HandleGlobalAnimEvent(struct GlobalAnimPartControlInfo *part,
+                                 int event_value, char *info_text)
+{
+#if DEBUG_ANIM_EVENTS
+  printf("::: %d.%d %s\n", part->old_anim_nr + 1, part->old_nr + 1, info_text);
+#endif
+
+  boolean anything_clicked = FALSE;
+  boolean any_event_action = FALSE;
+
+  // check if this event is defined to trigger other animations
+  InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
+                          event_value, info_text);
+}
+
 static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
                                 int state)
 {
@@ -1241,7 +1274,15 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
 
     if (part->init_delay_counter == 0 &&
        !part->init_event_state)
+    {
       PlayGlobalAnimSoundAndMusic(part);
+
+      HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
+    }
+    else
+    {
+      HandleGlobalAnimEvent(part, ANIM_EVENT_INIT, "START [INIT_DELAY/EVENT]");
+    }
   }
 
   if (part->clicked &&
@@ -1274,6 +1315,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
       part->init_event_state = FALSE;
 
       PlayGlobalAnimSoundAndMusic(part);
+
+      HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
     }
 
     return ANIM_STATE_WAITING;
@@ -1300,6 +1343,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
     {
       StopGlobalAnimSoundAndMusic(part);
 
+      HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM/OFF-SCREEN]");
+
       part->post_delay_counter =
        (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
 
@@ -1321,6 +1366,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
 
       StopGlobalAnimSoundAndMusic(part);
 
+      HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM_DELAY/EVENT]");
+
       part->post_delay_counter =
        (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
 
@@ -1337,7 +1384,11 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
     part->post_delay_counter--;
 
     if (part->post_delay_counter == 0)
+    {
+      HandleGlobalAnimEvent(part, ANIM_EVENT_POST, "END [POST_DELAY]");
+
       return ANIM_STATE_RESTART;
+    }
 
     return ANIM_STATE_WAITING;
   }
@@ -1651,6 +1702,11 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
        // always handle "any" click events (clicking anywhere on screen) ...
        if (isClickablePart(part, ANIM_EVENT_ANY))
        {
+#if DEBUG_ANIM_EVENTS
+         printf("::: => %d.%d TRIGGERED BY ANY\n",
+                part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
          part->clicked = TRUE;
          anything_clicked = clickConsumed(part);
        }
@@ -1675,13 +1731,18 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked)
 
          if (isClickablePart(part, ANIM_EVENT_SELF))
          {
+#if DEBUG_ANIM_EVENTS
+           printf("::: => %d.%d TRIGGERED BY SELF\n",
+                  part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
            part->clicked = TRUE;
            anything_clicked = clickConsumed(part);
          }
 
          // check if this click is defined to trigger other animations
          InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
-                                  ANIM_EVENT_CLICK);
+                                  ANIM_EVENT_CLICK, "CLICK");
        }
       }
     }