From: Holger Schemel Date: Sun, 13 Aug 2023 11:57:49 +0000 (+0200) Subject: added support for CE change pages triggering global animations X-Git-Tag: 4.3.7.0~32 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=a761d121263d681381a61087f110a9320626a8d0;p=rocksndiamonds.git added support for CE change pages triggering global animations This commit extends the previous commit to not only be able to trigger global animations using "ce_change:custom_X" (by any CE change page), but also by specifying change page using "ce_change:custom_X.page_Y". --- diff --git a/src/anim.c b/src/anim.c index bbc38dc4..d780658c 100644 --- a/src/anim.c +++ b/src/anim.c @@ -1191,6 +1191,7 @@ static void PlayGlobalAnimSoundIfLoop(struct GlobalAnimPartControlInfo *part) static boolean checkGlobalAnimEvent(int anim_event, int mask) { int mask_anim_only = mask & ~ANIM_EVENT_PART_MASK; + int mask_ce_only = mask & ~ANIM_EVENT_PAGE_MASK; if (mask & ANIM_EVENT_ANY) return (anim_event & ANIM_EVENT_ANY); @@ -1199,7 +1200,8 @@ static boolean checkGlobalAnimEvent(int anim_event, int mask) else if (mask & ANIM_EVENT_UNCLICK_ANY) return (anim_event & ANIM_EVENT_UNCLICK_ANY); else if (mask & ANIM_EVENT_CE_CHANGE) - return (anim_event == mask); + return (anim_event == mask || + anim_event == mask_ce_only); else return (anim_event == mask || anim_event == mask_anim_only); @@ -1358,12 +1360,13 @@ static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part, } } -static void InitGlobalAnim_Triggered_ByCustomElement(int nr) +static void InitGlobalAnim_Triggered_ByCustomElement(int nr, int page) { struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[GAME_MODE_PLAYING]; int event_value = ANIM_EVENT_CE_CHANGE; - int mask = event_value | (nr << ANIM_EVENT_CE_BIT); + int event_bits = (nr << ANIM_EVENT_CE_BIT) | (page << ANIM_EVENT_PAGE_BIT); + int mask = event_value | event_bits; int anim2_nr; for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++) @@ -2140,10 +2143,11 @@ int getGlobalAnimSyncFrame(void) return anim_sync_frame; } -void HandleGlobalAnimEventByElementChange(int element) +void HandleGlobalAnimEventByElementChange(int element, int page) { if (!IS_CUSTOM_ELEMENT(element)) return; - InitGlobalAnim_Triggered_ByCustomElement(element - EL_CUSTOM_START); + // custom element stored as 0 to 255, change page stored as 1 to 32 + InitGlobalAnim_Triggered_ByCustomElement(element - EL_CUSTOM_START, page + 1); } diff --git a/src/anim.h b/src/anim.h index bf9561fd..5224be13 100644 --- a/src/anim.h +++ b/src/anim.h @@ -22,7 +22,7 @@ void DrawGlobalAnimations(int, int); void RestartGlobalAnimsByStatus(int); boolean HandleGlobalAnimClicks(int, int, int, boolean); -void HandleGlobalAnimEventByElementChange(int); +void HandleGlobalAnimEventByElementChange(int, int); int getGlobalAnimSyncFrame(void); diff --git a/src/files.c b/src/files.c index 42208ce6..13141d7f 100644 --- a/src/files.c +++ b/src/files.c @@ -11549,9 +11549,10 @@ static boolean string_has_parameter(char *s, char *s_contained) static int get_anim_parameter_value_ce(char *s) { char *s_ptr = s; - char *pattern = "ce_change:custom_"; - int pattern_len = strlen(pattern); - char *matching_char = strstr(s_ptr, pattern); + char *pattern_1 = "ce_change:custom_"; + char *pattern_2 = ".page_"; + int pattern_1_len = strlen(pattern_1); + char *matching_char = strstr(s_ptr, pattern_1); int result = ANIM_EVENT_NONE; if (matching_char == NULL) @@ -11559,9 +11560,9 @@ static int get_anim_parameter_value_ce(char *s) result = ANIM_EVENT_CE_CHANGE; - s_ptr = matching_char + pattern_len; + s_ptr = matching_char + pattern_1_len; - // check for custom element number ("custom_X" or "custom_XX" or "custom_XXX") + // check for custom element number ("custom_X", "custom_XX" or "custom_XXX") if (*s_ptr >= '0' && *s_ptr <= '9') { int gic_ce_nr = (*s_ptr++ - '0'); @@ -11577,7 +11578,7 @@ static int get_anim_parameter_value_ce(char *s) if (gic_ce_nr < 1 || gic_ce_nr > NUM_CUSTOM_ELEMENTS) return ANIM_EVENT_NONE; - // store internal CE number (0 to 255, not "custom_1" to "custom_256") + // custom element stored as 0 to 255 gic_ce_nr--; result |= gic_ce_nr << ANIM_EVENT_CE_BIT; @@ -11589,6 +11590,33 @@ static int get_anim_parameter_value_ce(char *s) return ANIM_EVENT_NONE; } + // check for change page number ("page_X" or "page_XX") (optional) + if (strPrefix(s_ptr, pattern_2)) + { + s_ptr += strlen(pattern_2); + + if (*s_ptr >= '0' && *s_ptr <= '9') + { + int gic_page_nr = (*s_ptr++ - '0'); + + if (*s_ptr >= '0' && *s_ptr <= '9') + gic_page_nr = 10 * gic_page_nr + (*s_ptr++ - '0'); + + if (gic_page_nr < 1 || gic_page_nr > MAX_CHANGE_PAGES) + return ANIM_EVENT_NONE; + + // change page stored as 1 to 32 (0 means "all change pages") + + result |= gic_page_nr << ANIM_EVENT_PAGE_BIT; + } + else + { + // invalid animation part number specified + + return ANIM_EVENT_NONE; + } + } + // discard result if next character is neither delimiter nor whitespace if (!(*s_ptr == ',' || *s_ptr == '\0' || *s_ptr == ' ' || *s_ptr == '\t')) diff --git a/src/game.c b/src/game.c index 0d183034..299fd72b 100644 --- a/src/game.c +++ b/src/game.c @@ -10716,7 +10716,7 @@ 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); + HandleGlobalAnimEventByElementChange(element, page); if (change->explode) { diff --git a/src/libgame/system.h b/src/libgame/system.h index 1c6cb88d..e429d233 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -395,13 +395,16 @@ // event mask: bits 0-15 // CE number: bits 16-23 // anim number: bits 16-23 +// page number: bits 24-31 // part number: bits 24-31 #define ANIM_EVENT_CE_BIT 16 #define ANIM_EVENT_ANIM_BIT 16 +#define ANIM_EVENT_PAGE_BIT 24 #define ANIM_EVENT_PART_BIT 24 #define ANIM_EVENT_CE_MASK (0xff << ANIM_EVENT_CE_BIT) #define ANIM_EVENT_ANIM_MASK (0xff << ANIM_EVENT_ANIM_BIT) +#define ANIM_EVENT_PAGE_MASK (0xff << ANIM_EVENT_PAGE_BIT) #define ANIM_EVENT_PART_MASK (0xff << ANIM_EVENT_PART_BIT) #define ANIM_EVENT_DEFAULT ANIM_EVENT_NONE