From 509afe74cd69ad7db20983d07ecd8d2f97254d2c Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 12 Apr 2017 20:34:12 +0100 Subject: [PATCH 1/3] Refactor easter egg peep functions. Fix #5357 --- src/openrct2/peep/peep.c | 162 +++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 91 deletions(-) diff --git a/src/openrct2/peep/peep.c b/src/openrct2/peep/peep.c index 9ba3f39138..5fb9ec383e 100644 --- a/src/openrct2/peep/peep.c +++ b/src/openrct2/peep/peep.c @@ -11122,105 +11122,85 @@ static bool peep_has_valid_xy(rct_peep *peep) return false; } -static void peep_give_passing_peeps_purple_clothes(rct_peep *peep) +static void peep_apply_easter_egg_to_nearby_guests(rct_peep *peep, void(*easter_egg_function)(rct_peep* peep, rct_peep* otherPeep)) { - if (peep_has_valid_xy(peep)) { - rct_peep *otherPeep; - uint16 spriteIndex = sprite_get_first_in_quadrant(peep->x, peep->y); - for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { - otherPeep = GET_PEEP(spriteIndex); - if (otherPeep->type == PEEP_TYPE_GUEST) { - sint32 zDiff = abs(otherPeep->z - peep->z); - if (zDiff <= 32) { - otherPeep->tshirt_colour = COLOUR_BRIGHT_PURPLE; - otherPeep->trousers_colour = COLOUR_BRIGHT_PURPLE; - invalidate_sprite_2((rct_sprite*)peep); - } - } - } + if (!peep_has_valid_xy(peep)) + return; + + uint16 spriteIndex = sprite_get_first_in_quadrant(peep->x, peep->y); + if (spriteIndex == SPRITE_INDEX_NULL) + return; + + rct_peep * otherPeep = GET_PEEP(spriteIndex); + for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { + if (otherPeep->sprite_identifier != SPRITE_IDENTIFIER_PEEP) + continue; + + if (otherPeep->type != PEEP_TYPE_GUEST) + continue; + + sint32 zDiff = abs(otherPeep->z - peep->z); + if (zDiff > 32) + continue; + + easter_egg_function(peep, otherPeep); } } -static void peep_give_passing_peeps_pizza(rct_peep *peep) +static void peep_give_passing_peeps_purple_clothes(rct_peep *peep, rct_peep *otherPeep) { - if (peep_has_valid_xy(peep)) { - rct_peep *otherPeep; - uint16 spriteIndex = sprite_get_first_in_quadrant(peep->x, peep->y); - for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { - otherPeep = GET_PEEP(spriteIndex); - if (otherPeep->type == PEEP_TYPE_GUEST) { - sint32 zDiff = abs(otherPeep->z - peep->z); - if (zDiff <= 32) { - if (!(otherPeep->item_standard_flags & PEEP_ITEM_PIZZA)) { - otherPeep->item_standard_flags |= PEEP_ITEM_PIZZA; + otherPeep->tshirt_colour = COLOUR_BRIGHT_PURPLE; + otherPeep->trousers_colour = COLOUR_BRIGHT_PURPLE; + invalidate_sprite_2((rct_sprite*)otherPeep); +} - sint32 peepDirection = (peep->sprite_direction >> 3) ^ 2; - sint32 otherPeepOppositeDirection = otherPeep->sprite_direction >> 3; - if (peepDirection == otherPeepOppositeDirection) { - if (otherPeep->action == PEEP_ACTION_NONE_1 || otherPeep->action == PEEP_ACTION_NONE_2) { - invalidate_sprite_2((rct_sprite*)peep); - otherPeep->action = PEEP_ACTION_WAVE_2; - otherPeep->action_frame = 0; - otherPeep->action_sprite_image_offset = 0; - sub_693B58(otherPeep); - invalidate_sprite_2((rct_sprite*)otherPeep); - } - } - invalidate_sprite_2((rct_sprite*)otherPeep); - } - } - } +static void peep_give_passing_peeps_pizza(rct_peep *peep, rct_peep *otherPeep) +{ + if ((otherPeep->item_standard_flags & PEEP_ITEM_PIZZA)) + return; + + otherPeep->item_standard_flags |= PEEP_ITEM_PIZZA; + + sint32 peepDirection = (peep->sprite_direction >> 3) ^ 2; + sint32 otherPeepOppositeDirection = otherPeep->sprite_direction >> 3; + if (peepDirection == otherPeepOppositeDirection) { + if (otherPeep->action == PEEP_ACTION_NONE_1 || otherPeep->action == PEEP_ACTION_NONE_2) { + invalidate_sprite_2((rct_sprite*)peep); + otherPeep->action = PEEP_ACTION_WAVE_2; + otherPeep->action_frame = 0; + otherPeep->action_sprite_image_offset = 0; + sub_693B58(otherPeep); + invalidate_sprite_2((rct_sprite*)otherPeep); } } + invalidate_sprite_2((rct_sprite*)otherPeep); +} + +static void peep_make_passing_peeps_sick(rct_peep *peep, rct_peep *otherPeep) +{ + if (peep == otherPeep) + return; + if (otherPeep->state == PEEP_STATE_QUEUING) + return; + + if (otherPeep->action == PEEP_ACTION_NONE_1 || otherPeep->action == PEEP_ACTION_NONE_2) { + otherPeep->action = PEEP_ACTION_THROW_UP; + otherPeep->action_frame = 0; + otherPeep->action_sprite_image_offset = 0; + sub_693B58(otherPeep); + invalidate_sprite_2((rct_sprite*)otherPeep); + } } -static void peep_make_passing_peeps_sick(rct_peep *peep) +static void peep_give_passing_peeps_ice_cream(rct_peep *peep, rct_peep *otherPeep) { - if (peep_has_valid_xy(peep)) { - rct_peep *otherPeep; - uint16 spriteIndex = sprite_get_first_in_quadrant(peep->x, peep->y); - for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { - otherPeep = GET_PEEP(spriteIndex); - if (otherPeep->type == PEEP_TYPE_GUEST) { - sint32 zDiff = abs(otherPeep->z - peep->z); - if (zDiff <= 32) { - if (peep != otherPeep) { - if (otherPeep->state != PEEP_STATE_QUEUING) { - if (otherPeep->action == PEEP_ACTION_NONE_1 || otherPeep->action == PEEP_ACTION_NONE_2) { - otherPeep->action = PEEP_ACTION_THROW_UP; - otherPeep->action_frame = 0; - otherPeep->action_sprite_image_offset = 0; - sub_693B58(otherPeep); - invalidate_sprite_2((rct_sprite*)otherPeep); - } - } - } - } - } - } - } -} + if (peep == otherPeep) + return; + if (otherPeep->item_standard_flags & PEEP_ITEM_ICE_CREAM) + return; -static void peep_give_passing_peeps_ice_cream(rct_peep *peep) -{ - if (peep_has_valid_xy(peep)) { - rct_peep *otherPeep; - uint16 spriteIndex = sprite_get_first_in_quadrant(peep->x, peep->y); - for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { - otherPeep = GET_PEEP(spriteIndex); - if (otherPeep->type == PEEP_TYPE_GUEST) { - sint32 zDiff = abs(otherPeep->z - peep->z); - if (zDiff <= 32) { - if (peep != otherPeep) { - if (!(otherPeep->item_standard_flags & PEEP_ITEM_ICE_CREAM)) { - otherPeep->item_standard_flags |= PEEP_ITEM_ICE_CREAM; - peep_update_sprite_type(otherPeep); - } - } - } - } - } - } + otherPeep->item_standard_flags |= PEEP_ITEM_ICE_CREAM; + peep_update_sprite_type(otherPeep); } /** @@ -11230,15 +11210,15 @@ static void peep_give_passing_peeps_ice_cream(rct_peep *peep) static void peep_easter_egg_peep_interactions(rct_peep *peep) { if (peep->peep_flags & PEEP_FLAGS_PURPLE) { - peep_give_passing_peeps_purple_clothes(peep); + peep_apply_easter_egg_to_nearby_guests(peep, &peep_give_passing_peeps_purple_clothes); } if (peep->peep_flags & PEEP_FLAGS_PIZZA) { - peep_give_passing_peeps_pizza(peep); + peep_apply_easter_egg_to_nearby_guests(peep, &peep_give_passing_peeps_pizza); } if (peep->peep_flags & PEEP_FLAGS_CONTAGIOUS) { - peep_make_passing_peeps_sick(peep); + peep_apply_easter_egg_to_nearby_guests(peep, &peep_make_passing_peeps_sick); } if (peep->peep_flags & PEEP_FLAGS_JOY) { @@ -11254,7 +11234,7 @@ static void peep_easter_egg_peep_interactions(rct_peep *peep) } if (peep->peep_flags & PEEP_FLAGS_ICE_CREAM) { - peep_give_passing_peeps_ice_cream(peep); + peep_apply_easter_egg_to_nearby_guests(peep, &peep_give_passing_peeps_ice_cream); } } From 1b98c0b1cb71e35bf17a94ad9cb692f2784aed25 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 12 Apr 2017 20:34:57 +0100 Subject: [PATCH 2/3] Increment network --- src/openrct2/network/network.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 482d511a85..e0a1a3cf5c 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -56,7 +56,7 @@ extern "C" { // This define specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "16" +#define NETWORK_STREAM_VERSION "17" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #ifdef __cplusplus From 9257645cb7b5ac439b89f859990c851533e5a16b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 12 Apr 2017 20:44:44 +0100 Subject: [PATCH 3/3] Correctly loop. Add typedef for easter egg functions --- src/openrct2/peep/peep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openrct2/peep/peep.c b/src/openrct2/peep/peep.c index 5fb9ec383e..2b3844c545 100644 --- a/src/openrct2/peep/peep.c +++ b/src/openrct2/peep/peep.c @@ -11122,7 +11122,9 @@ static bool peep_has_valid_xy(rct_peep *peep) return false; } -static void peep_apply_easter_egg_to_nearby_guests(rct_peep *peep, void(*easter_egg_function)(rct_peep* peep, rct_peep* otherPeep)) +typedef void(*easter_egg_function)(rct_peep* peep, rct_peep* otherPeep); + +static void peep_apply_easter_egg_to_nearby_guests(rct_peep *peep, easter_egg_function easter_egg) { if (!peep_has_valid_xy(peep)) return; @@ -11133,6 +11135,8 @@ static void peep_apply_easter_egg_to_nearby_guests(rct_peep *peep, void(*easter_ rct_peep * otherPeep = GET_PEEP(spriteIndex); for (; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = otherPeep->next_in_quadrant) { + otherPeep = GET_PEEP(spriteIndex); + if (otherPeep->sprite_identifier != SPRITE_IDENTIFIER_PEEP) continue; @@ -11143,7 +11147,7 @@ static void peep_apply_easter_egg_to_nearby_guests(rct_peep *peep, void(*easter_ if (zDiff > 32) continue; - easter_egg_function(peep, otherPeep); + easter_egg(peep, otherPeep); } }