added using trigger element position for CE triggered global animations
authorHolger Schemel <info@artsoft.org>
Fri, 10 Nov 2023 19:44:27 +0000 (20:44 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 10 Nov 2023 19:48:51 +0000 (20:48 +0100)
When using global animations that are triggered by custom elements,
using ".position: ce_trigger" instead of ".position: ce" will use
the position of the CE trigger element instead of the CE itself.

src/anim.c
src/anim.h
src/files.c
src/game.c
src/libgame/system.h
src/main.h

index ee2e1ede3fa881b979cabb5aa548acd5a617ba64..39ed377292fcc3288dbbb3a8cadca526ea6fb7b2 100644 (file)
@@ -1434,7 +1434,9 @@ static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
 }
 
 static void InitGlobalAnim_Triggered_ByCustomElement(int nr, int page,
-                                                    int x, int y)
+                                                    int x, int y,
+                                                    int trigger_x,
+                                                    int trigger_y)
 {
   struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[GAME_MODE_PLAYING];
 
@@ -1459,11 +1461,12 @@ static void InitGlobalAnim_Triggered_ByCustomElement(int nr, int page,
       {
        struct GraphicInfo *c = &part2->control_info;
 
-       if (c->position == POS_CE)
+       if (c->position == POS_CE ||
+           c->position == POS_CE_TRIGGER)
        {
          // store CE tile and offset position to handle scrolling
-         part2->tile_x = x;
-         part2->tile_y = y;
+         part2->tile_x = (c->position == POS_CE_TRIGGER ? trigger_x : x);
+         part2->tile_y = (c->position == POS_CE_TRIGGER ? trigger_y : y);
          part2->tile_xoffset = c->x;
          part2->tile_yoffset = c->y;
 
@@ -1796,7 +1799,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
   }
 #endif
 
-  if (c->position == POS_CE)
+  if (c->position == POS_CE ||
+      c->position == POS_CE_TRIGGER)
   {
     SetGlobalAnimPartTileXY(part);
   }
@@ -2260,12 +2264,13 @@ int getGlobalAnimSyncFrame(void)
   return anim_sync_frame;
 }
 
-void HandleGlobalAnimEventByElementChange(int element, int page, int x, int y)
+void HandleGlobalAnimEventByElementChange(int element, int page, int x, int y,
+                                         int trigger_x, int trigger_y)
 {
   if (!IS_CUSTOM_ELEMENT(element))
     return;
 
   // custom element stored as 0 to 255, change page stored as 1 to 32
   InitGlobalAnim_Triggered_ByCustomElement(element - EL_CUSTOM_START, page + 1,
-                                          x, y);
+                                          x, y, trigger_x, trigger_y);
 }
index 992f50106dbe0bb028903b7ef3233c11abaaedf1..274cade99dc0c8a41c839a52518ef5033379f118 100644 (file)
@@ -23,7 +23,7 @@ void RestartGlobalAnimsByStatus(int);
 void SetAnimStatusBeforeFading(int);
 
 boolean HandleGlobalAnimClicks(int, int, int, boolean);
-void HandleGlobalAnimEventByElementChange(int, int, int, int);
+void HandleGlobalAnimEventByElementChange(int, int, int, int, int, int);
 
 int getGlobalAnimSyncFrame(void);
 
index 17a5fa8daf6cae02be69f8d4fab135a3f1e28b79..1514d4e6d864ddc0dc0761257561b8f1f77baa45 100644 (file)
@@ -11826,6 +11826,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              strEqual(value, "bottom") ? POS_BOTTOM :
              strEqual(value, "any")    ? POS_ANY :
              strEqual(value, "ce")     ? POS_CE :
+             strEqual(value, "ce_trigger") ? POS_CE_TRIGGER :
              strEqual(value, "last")   ? POS_LAST : POS_UNDEFINED);
   }
   else if (strEqual(suffix, ".align"))
index 94b74f786cdc2c7d211af21d484a3cec17a22eb0..51633eb17bac0a776424354fca73b6a7c642f46b 100644 (file)
@@ -3279,6 +3279,8 @@ static void InitGameEngine(void)
       change->actual_trigger_side = CH_SIDE_NONE;
       change->actual_trigger_ce_value = 0;
       change->actual_trigger_ce_score = 0;
+      change->actual_trigger_x = -1;
+      change->actual_trigger_y = -1;
     }
   }
 
@@ -10759,6 +10761,8 @@ static boolean ChangeElement(int x, int y, int element, int page)
     change->actual_trigger_side = CH_SIDE_NONE;
     change->actual_trigger_ce_value = 0;
     change->actual_trigger_ce_score = 0;
+    change->actual_trigger_x = -1;
+    change->actual_trigger_y = -1;
   }
 
   // do not change elements more than a specified maximum number of changes
@@ -10768,7 +10772,9 @@ static boolean ChangeElement(int x, int y, int element, int page)
   ChangeCount[x][y]++;         // count number of changes in the same frame
 
   if (ei->has_anim_event)
-    HandleGlobalAnimEventByElementChange(element, page, x, y);
+    HandleGlobalAnimEventByElementChange(element, page, x, y,
+                                        change->actual_trigger_x,
+                                        change->actual_trigger_y);
 
   if (change->explode)
   {
@@ -11098,6 +11104,8 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
        change->actual_trigger_side = trigger_side;
        change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
        change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
+       change->actual_trigger_x = trigger_x;
+       change->actual_trigger_y = trigger_y;
 
        if ((change->can_change && !change_done) || change->has_action)
        {
@@ -11212,6 +11220,8 @@ static boolean CheckElementChangeExt(int x, int y,
       change->actual_trigger_side = trigger_side;
       change->actual_trigger_ce_value = CustomValue[x][y];
       change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
+      change->actual_trigger_x = x;
+      change->actual_trigger_y = y;
 
       // special case: trigger element not at (x,y) position for some events
       if (check_trigger_element)
@@ -11235,6 +11245,8 @@ static boolean CheckElementChangeExt(int x, int y,
 
        change->actual_trigger_ce_value = CustomValue[xx][yy];
        change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element);
+       change->actual_trigger_x = xx;
+       change->actual_trigger_y = yy;
       }
 
       if (change->can_change && !change_done)
index f321f217c0d16e71d044d25d017bb08df390d50d..b2f95e358d73182a3ff53224b821cdc3f2163d2f 100644 (file)
 #define POS_BOTTOM             6
 #define POS_ANY                        7
 #define POS_CE                 8
-#define POS_LAST               9
+#define POS_CE_TRIGGER         9
+#define POS_LAST               10
 
 // values for text alignment
 #define ALIGN_LEFT             (1 << 0)
index af5bed9742b741ae437cd416feebec4151ae7905..2b2d2b2c255e32a5ad6a708b4300c3b42731a220 100644 (file)
@@ -3477,6 +3477,8 @@ struct ElementChangeInfo
   void (*post_change_function)(int x, int y);
 
   short actual_trigger_element;        // element that actually triggered change
+  int actual_trigger_x;                // element x position that triggered change
+  int actual_trigger_y;                // element y position that triggered change
   int actual_trigger_side;     // element side that triggered the change
   int actual_trigger_player;   // player which actually triggered change
   int actual_trigger_player_bits; // player bits of triggering players