From 4d26e4c4a179c2ffdaaed6a9c5e2ab0ae2266a9a Mon Sep 17 00:00:00 2001 From: Jonathan Haas Date: Tue, 29 Dec 2015 21:08:14 +0100 Subject: [PATCH] Refactor peep code Name various fields and constants related to peeps. This includes: - Flags for flashing peeps in map window - Animation frames for picked up peeps - Function checking if peep should start to fall - Special sprite handling for slide boards and lawn mowers - Created array for peep sprite entries, renamed some variables and constants --- src/addresses.h | 3 +- src/drawing/drawing.c | 6 +- src/interface/viewport.c | 2 +- src/interface/window.h | 10 ++- src/peep/peep.c | 116 ++++++++++++++++-------------- src/peep/peep.h | 18 +++-- src/peep/staff.c | 13 ++-- src/windows/game_bottom_toolbar.c | 2 +- src/windows/guest.c | 30 ++++---- src/windows/guest_list.c | 16 ++--- src/windows/map.c | 2 +- src/windows/news.c | 2 +- src/windows/park.c | 2 +- src/windows/ride.c | 2 +- src/windows/staff.c | 29 ++++---- src/windows/staff_list.c | 4 +- src/world/sprite.c | 2 + src/world/sprite.h | 21 ++++++ 18 files changed, 168 insertions(+), 112 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 49ada59c0f..7ab377d187 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -63,6 +63,7 @@ // are implemented in C. Sometimes memory locations are still used even if // they aren't directly referenced, for example when a game is saved and // loaded, large chunks of data is read and written to. +#define RCT2_ADDRESS_SPRITE_ENTRIES 0x00982708 #define RCT2_ADDRESS_EASTEREGG_NAMES 0x00988C20 @@ -191,7 +192,7 @@ #define RCT2_ADDRESS_TICKS_SINCE_DRAG_START 0x009DE540 -#define RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE 0x009DE550 +#define RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE 0x009DE550 #define RCT2_ADDRESS_PICKEDUP_PEEP_X 0x009DE554 #define RCT2_ADDRESS_PICKEDUP_PEEP_Y 0x009DE556 diff --git a/src/drawing/drawing.c b/src/drawing/drawing.c index cb0743544a..d2f8226595 100644 --- a/src/drawing/drawing.c +++ b/src/drawing/drawing.c @@ -485,7 +485,7 @@ void redraw_rain() void gfx_invalidate_pickedup_peep() { if (RCT2_GLOBAL(0x009ABDF2, uint32) != 0) { - int sprite = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32); + int sprite = RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32); if (sprite != -1) { sprite = sprite & 0x7FFFF; @@ -506,10 +506,10 @@ void gfx_draw_pickedup_peep() return; // Draw picked-up peep - if (RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, uint32) != 0xFFFFFFFF) { + if (RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, uint32) != 0xFFFFFFFF) { gfx_draw_sprite( (rct_drawpixelinfo*)RCT2_ADDRESS_SCREEN_DPI, - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, uint32), + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, uint32), RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_X, sint16), RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, sint16), 0 ); diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 91e9e21707..1de8b79160 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -104,7 +104,7 @@ void viewport_init_all() RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) = 0; RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = INPUT_STATE_RESET; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass) = -1; - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_NOT_SHOWN_TICKS, sint16) = -1; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, sint16) = 0; RCT2_GLOBAL(0x009DEA50, sint16) = -1; diff --git a/src/interface/window.h b/src/interface/window.h index 714f741a92..14caac8e53 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -262,10 +262,16 @@ typedef struct rct_window { error_variables error; }; sint16 page; // 0x48A - sint16 var_48C; + union { + sint16 picked_peep_old_x; // 0x48C staff/guest window: peep x gets set to 0x8000 on pickup, this is the old value + sint16 var_48C; + }; uint16 frame_no; // 0x48E updated every tic for motion in windows sprites uint16 list_information_type; // 0x490 0 for none, Used as current position of marquee in window_peep - sint16 var_492; + union { + sint16 picked_peep_frame; // 0x492 Animation frame of picked peep in staff window and guest window + sint16 var_492; + }; union { // 0x494 uint32 highlighted_item; uint16 ride_colour; diff --git a/src/peep/peep.c b/src/peep/peep.c index ba9180f355..b6d3759489 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -802,10 +802,17 @@ static void sub_68F41A(rct_peep *peep, int index) } } -/* some sort of check to see if peep is connected to the ground?? */ -int sub_68F3AE(rct_peep* peep){ +/* + * rct2: 0x68F3AE + * Set peep state to falling if path below has gone missing, return 1 if current path is valid, 0 if peep starts falling + */ +int checkForPath(rct_peep *peep){ peep->var_C4++; - if ((peep->var_C4 & 0xF) != (peep->sprite_index & 0xF))return 1; + if ((peep->var_C4 & 0xF) != (peep->sprite_index & 0xF)){ + // This condition makes the check happen less often so the peeps hover for a short, + // random time when a path below them has been deleted + return 1; + } rct_map_element* map_element = map_get_first_element_at(peep->next_x / 32, peep->next_y / 32); @@ -818,10 +825,14 @@ int sub_68F3AE(rct_peep* peep){ do { if (map_element_get_type(map_element) == map_type){ - if (z == map_element->base_height)return 1; + if (z == map_element->base_height) { + // Found a suitable path + return 1; + } } } while (!map_element_is_last_for_tile(map_element++)); + // Found no suitable path peep_decrement_num_riders(peep); peep->state = PEEP_STATE_FALLING; peep_window_state_update(peep); @@ -829,31 +840,31 @@ int sub_68F3AE(rct_peep* peep){ } void sub_693B58(rct_peep* peep){ - int ebx; - if (peep->action >= 0xFE){ - ebx = RCT2_ADDRESS(0x981D8C, uint8)[peep->var_6D]; + uint8 action_sprite_type; + if (peep->action >= PEEP_ACTION_NONE_1){ // PEEP_ACTION_NONE_1 or PEEP_ACTION_NONE_2 + action_sprite_type = RCT2_ADDRESS(0x981D8C, uint8)[peep->special_sprite]; } else{ - ebx = RCT2_ADDRESS(0x981D8F, uint8)[peep->action]; + action_sprite_type = RCT2_ADDRESS(0x981D8F, uint8)[peep->action]; } - if (ebx == peep->action_sprite_type)return; + if (action_sprite_type == peep->action_sprite_type)return; invalidate_sprite_2((rct_sprite*)peep); - peep->action_sprite_type = ebx; + peep->action_sprite_type = action_sprite_type; - uint8* edx = RCT2_ADDRESS(0x98270C, uint8*)[peep->sprite_type * 2]; - peep->sprite_width = edx[ebx * 4]; - peep->sprite_height_negative = edx[ebx * 4 + 1]; - peep->sprite_height_positive = edx[ebx * 4 + 2]; + rct_sprite_bounds* spriteBounds = g_sprite_entries[peep->sprite_type].sprite_bounds; + peep->sprite_width = spriteBounds[action_sprite_type].sprite_width; + peep->sprite_height_negative = spriteBounds[action_sprite_type].sprite_height_negative; + peep->sprite_height_positive = spriteBounds[action_sprite_type].sprite_height_positive; // This is pointless as nothing will have changed. invalidate_sprite_2((rct_sprite*)peep); } /* 0x00693BE5 */ void sub_693BE5(rct_peep* peep, uint8 al){ - if (al == peep->var_6D)return; + if (al == peep->special_sprite)return; - peep->var_6D = al; + peep->special_sprite = al; // If NONE_1 or NONE_2 if (peep->action >= PEEP_ACTION_NONE_1){ @@ -997,8 +1008,8 @@ int peep_update_action(sint16* x, sint16* y, sint16* xy_distance, rct_peep* peep *x = peep->x + RCT2_ADDRESS(0x981D7C, uint16)[direction / 4]; *y = peep->y + RCT2_ADDRESS(0x981D7E, uint16)[direction / 4]; peep->no_action_frame_no++; - uint32* edi = RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2]; - uint8* _edi = (uint8*)(edi[peep->action_sprite_type * 2 + 1]); + rct_sprite_image * edi = g_sprite_entries[peep->sprite_type].sprite_image; + uint8* _edi = (edi[peep->action_sprite_type]).unkn_04; if (peep->no_action_frame_no >= *_edi){ peep->no_action_frame_no = 0; } @@ -1006,8 +1017,8 @@ int peep_update_action(sint16* x, sint16* y, sint16* xy_distance, rct_peep* peep return 1; } - uint32* edi = RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2]; - uint8* _edi = (uint8*)(edi[peep->action_sprite_type * 2 + 1]); + rct_sprite_image * edi = g_sprite_entries[peep->sprite_type].sprite_image; + uint8* _edi = (edi[peep->action_sprite_type]).unkn_04; peep->action_frame++; int ebx = _edi[peep->action_frame + 1]; @@ -1089,12 +1100,12 @@ void set_sprite_type(rct_peep* peep, uint8 type){ if (peep->state == PEEP_STATE_SITTING){ peep->action = PEEP_ACTION_NONE_1; - peep->var_6F = 7; + peep->next_action_sprite_type = 7; sub_693BAB(peep); } if (peep->state == PEEP_STATE_WATCHING){ peep->action = PEEP_ACTION_NONE_1; - peep->var_6F = 2; + peep->next_action_sprite_type = 2; sub_693BAB(peep); } } @@ -1457,7 +1468,7 @@ void peep_try_get_up_from_sitting(rct_peep* peep){ */ void peep_update_sitting(rct_peep* peep){ if (peep->sub_state == 0){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; //691541 sub_693C9E(peep); @@ -1474,7 +1485,7 @@ void peep_update_sitting(rct_peep* peep){ peep->sprite_direction = ((peep->var_37 + 2) & 3) * 8; invalidate_sprite_2((rct_sprite*)peep); peep->action = 254; - peep->var_6F = 7; + peep->next_action_sprite_type = 7; sub_693BAB(peep); peep->sub_state++; @@ -3414,7 +3425,7 @@ static void peep_update_fixing(int steps, rct_peep* peep){ * rct2: 0x69185D */ static void peep_update_queuing(rct_peep* peep){ - if (!sub_68F3AE(peep)){ + if (!checkForPath(peep)){ remove_peep_from_queue(peep); return; } @@ -3465,7 +3476,7 @@ static void peep_update_queuing(rct_peep* peep){ } } else{ - if (!(peep->time_in_queue & 0x3F) && peep->action == 0xFE && peep->var_6F == 2){ + if (!(peep->time_in_queue & 0x3F) && peep->action == 0xFE && peep->next_action_sprite_type == 2){ switch (peep->sprite_type){ case 0xF: case 0x10: @@ -3518,7 +3529,7 @@ static void peep_update_queuing(rct_peep* peep){ */ static void peep_update_mowing(rct_peep* peep){ peep->var_E2 = 0; - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; invalidate_sprite_2((rct_sprite*)peep); while (1){ @@ -3566,7 +3577,7 @@ static void peep_update_mowing(rct_peep* peep){ static void peep_update_watering(rct_peep* peep){ peep->var_E2 = 0; if (peep->sub_state == 0){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); if (!(RCT2_GLOBAL(0xF1EE18, uint16) & 1))return; @@ -3622,7 +3633,7 @@ static void peep_update_emptying_bin(rct_peep* peep){ peep->var_E2 = 0; if (peep->sub_state == 0){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); if (!(RCT2_GLOBAL(0xF1EE18, uint16) & 1))return; @@ -3691,7 +3702,7 @@ static void peep_update_emptying_bin(rct_peep* peep){ */ static void peep_update_sweeping(rct_peep* peep){ peep->var_E2 = 0; - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; invalidate_sprite_2((rct_sprite*)peep); @@ -3726,7 +3737,7 @@ static void peep_update_sweeping(rct_peep* peep){ * rct2: 0x6902A2 */ static void peep_update_1(rct_peep* peep){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; peep_decrement_num_riders(peep); @@ -3795,7 +3806,7 @@ static void peep_update_leaving_park(rct_peep* peep){ */ static void peep_update_watching(rct_peep* peep){ if (peep->sub_state == 0){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); if (!(RCT2_GLOBAL(0xF1EE18, uint16) & 1))return; @@ -3807,7 +3818,7 @@ static void peep_update_watching(rct_peep* peep){ invalidate_sprite_2((rct_sprite*)peep); peep->action = 0xFE; - peep->var_6F = 2; + peep->next_action_sprite_type = 2; sub_693BAB(peep); @@ -4132,7 +4143,7 @@ static void peep_update_walking_break_scenery(rct_peep* peep){ */ static void peep_update_buying(rct_peep* peep) { - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; rct_ride* ride = GET_RIDE(peep->current_ride); if (ride->type == RIDE_TYPE_NULL || ride->status != RIDE_STATUS_OPEN){ @@ -4225,7 +4236,7 @@ static void peep_update_buying(rct_peep* peep) */ static void peep_update_using_bin(rct_peep* peep){ if (peep->sub_state == 0){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); if (!(RCT2_GLOBAL(0xF1EE18, uint16) & 1))return; @@ -4400,7 +4411,7 @@ static void peep_update_heading_to_inspect(rct_peep* peep){ return; } - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); @@ -4513,7 +4524,7 @@ static void peep_update_answering(rct_peep* peep){ return; } - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); @@ -4768,7 +4779,7 @@ static int peep_update_patrolling_find_sweeping(rct_peep* peep){ */ static void peep_update_patrolling(rct_peep* peep){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; sub_693C9E(peep); if (!(RCT2_GLOBAL(0xF1EE18, uint16) & 1))return; @@ -4808,7 +4819,7 @@ static void peep_update_patrolling(rct_peep* peep){ * rct2: 0x0069030A */ static void peep_update_walking(rct_peep* peep){ - if (!sub_68F3AE(peep))return; + if (!checkForPath(peep))return; if (peep->flags & PEEP_FLAGS_WAVING){ if (peep->action >= PEEP_ACTION_NONE_1){ @@ -5484,7 +5495,7 @@ rct_peep *peep_generate(int x, int y, int z) peep->outside_of_park = 1; peep->state = PEEP_STATE_FALLING; peep->action = PEEP_ACTION_NONE_2; - peep->var_6D = 0; + peep->special_sprite = 0; peep->action_sprite_image_offset = 0; peep->no_action_frame_no = 0; peep->action_sprite_type = 0; @@ -5492,10 +5503,10 @@ rct_peep *peep_generate(int x, int y, int z) peep->favourite_ride = 0xFF; peep->favourite_ride_rating = 0; - uint8* edx = RCT2_ADDRESS(0x98270C, uint8*)[peep->sprite_type * 2]; - peep->sprite_width = edx[peep->action_sprite_type * 4]; - peep->sprite_height_negative = edx[peep->action_sprite_type * 4 + 1]; - peep->sprite_height_positive = edx[peep->action_sprite_type * 4 + 2]; + rct_sprite_bounds* spriteBounds = g_sprite_entries[peep->sprite_type].sprite_bounds; + peep->sprite_width = spriteBounds[peep->action_sprite_type].sprite_width; + peep->sprite_height_negative = spriteBounds[peep->action_sprite_type].sprite_height_negative; + peep->sprite_height_positive = spriteBounds[peep->action_sprite_type].sprite_height_positive; peep->sprite_direction = 0; @@ -6160,14 +6171,15 @@ void peep_set_map_tooltip(rct_peep *peep) void sub_693BAB(rct_peep* peep) { - uint8 bl = peep->var_6F; - if (bl != peep->action_sprite_type) { + // TBD: Add nextActionSpriteType as function parameter and make peep->next_action_sprite_type obsolete? + uint8 nextActionSpriteType = peep->next_action_sprite_type; + if (nextActionSpriteType != peep->action_sprite_type) { invalidate_sprite_2((rct_sprite*)peep); - peep->action_sprite_type = bl; - uint8* edx = RCT2_ADDRESS(0x98270C, uint8*)[peep->sprite_type * 2]; - peep->sprite_width = edx[bl * 4]; - peep->sprite_height_negative = edx[bl * 4 + 1]; - peep->sprite_height_positive = edx[bl * 4 + 2]; + peep->action_sprite_type = nextActionSpriteType; + rct_sprite_bounds* spriteBounds = g_sprite_entries[peep->sprite_type].sprite_bounds; + peep->sprite_width = spriteBounds[nextActionSpriteType].sprite_width; + peep->sprite_height_negative = spriteBounds[nextActionSpriteType].sprite_height_negative; + peep->sprite_height_positive = spriteBounds[nextActionSpriteType].sprite_height_positive; invalidate_sprite_2((rct_sprite*)peep); } } @@ -6235,7 +6247,7 @@ static int peep_update_queue_position(rct_peep* peep){ return 1; peep->action = PEEP_ACTION_NONE_1; - peep->var_6F = 2; + peep->next_action_sprite_type = 2; if (RCT2_GLOBAL(0x00F1AEF1, uint8) != 0xFE) invalidate_sprite_2((rct_sprite*)peep); return 1; diff --git a/src/peep/peep.h b/src/peep/peep.h index c758f335b7..3bea736123 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -372,6 +372,12 @@ enum { PEEP_RIDE_DECISION_THINKING = 1 << 2 }; +// Flags used by peep->list_flags +enum { + PEEP_LIST_FLAGS_VISIBLE = 1 << 8, // Peep is eligible to show in summarized guest list window (is inside park?) + PEEP_LIST_FLAGS_FLASHING = 1 << 9, // Peep belongs to highlighted group (flashes red on map) +}; + typedef struct { uint8 type; //0 uint8 item; //1 @@ -389,7 +395,7 @@ typedef struct { // Height from center of sprite to bottom uint8 sprite_height_negative; // 0x09 uint16 sprite_index; // 0x0A - uint16 var_0C; + uint16 list_flags; // 0x0C Used for highlighting peeps on map with staff list or guest list open sint16 x; // 0x0E sint16 y; // 0x10 sint16 z; // 0x12 @@ -408,7 +414,7 @@ typedef struct { uint16 next_y; // 0x26 uint8 next_z; // 0x28 uint8 next_var_29; // 0x29 - uint8 outside_of_park; + uint8 outside_of_park; // 0x2A uint8 state; // 0x2B uint8 sub_state; // 0x2C uint8 sprite_type; // 0x2D @@ -458,9 +464,11 @@ typedef struct { uint8 standing_flags; //0x6C }; }; - uint8 var_6D; // 0x6D + // Normally 0, 1 for carrying sliding board on spiral slide ride, 2 for carrying lawn mower + uint8 special_sprite; // 0x6D uint8 action_sprite_type; // 0x6E - uint8 var_6F; + // Seems to be used like a local variable, as it's always set before calling sub_693BAB, which reads this again + uint8 next_action_sprite_type; // 0x6F uint8 action_sprite_image_offset; // 0x70 uint8 action; // 0x71 uint8 action_frame; // 0x72 @@ -488,7 +496,7 @@ typedef struct { uint8 previous_ride; // 0xAD uint16 previous_ride_time_out; // 0xAE rct_peep_thought thoughts[PEEP_MAX_THOUGHTS]; // 0xB0 - uint8 var_C4; // 0xC4 + uint8 var_C4; // 0xC4 has something to do with peep falling, see peep.checkForPath union { uint8 staff_id; // 0xC5 uint8 guest_heading_to_ride_id; // 0xC5 diff --git a/src/peep/staff.c b/src/peep/staff.c index 60348ac860..7ded0b1528 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -109,7 +109,8 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, int newStaffId = i; - int _eax, _ebx, _ecx = _cx, _edx; + int _eax, _ebx, _ecx = _cx; + rct_sprite_bounds *spriteBounds; _ebx = _bl; rct_peep* newPeep = &(create_sprite(_bl)->peep); @@ -129,7 +130,7 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, newPeep->sprite_identifier = 1; newPeep->window_invalidate_flags = 0; newPeep->action = PEEP_ACTION_NONE_2; - newPeep->var_6D = 0; + newPeep->special_sprite = 0; newPeep->action_sprite_image_offset = 0; newPeep->no_action_frame_no = 0; newPeep->action_sprite_type = 0; @@ -181,10 +182,10 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, newPeep->name_string_idx = staff_type + 0x300; newPeep->sprite_type = _eax; - _edx = RCT2_ADDRESS(0x0098270C, uint32)[_eax * 2]; - newPeep->sprite_width = *((uint8*)_edx); - newPeep->sprite_height_negative = *((uint8*)(_edx + 1)); - newPeep->sprite_height_positive = *((uint8*)(_edx + 2)); + spriteBounds = g_sprite_entries[_eax].sprite_bounds; + newPeep->sprite_width = spriteBounds->sprite_width; + newPeep->sprite_height_negative = spriteBounds->sprite_height_negative; + newPeep->sprite_height_positive = spriteBounds->sprite_height_positive; if ((gConfigGeneral.auto_staff_placement != 0) != ((SDL_GetModState() & KMOD_SHIFT) != 0)) { newPeep->state = PEEP_STATE_FALLING; diff --git a/src/windows/game_bottom_toolbar.c b/src/windows/game_bottom_toolbar.c index 9dbc2aebf4..5f97e96b05 100644 --- a/src/windows/game_bottom_toolbar.c +++ b/src/windows/game_bottom_toolbar.c @@ -551,7 +551,7 @@ static void window_game_bottom_toolbar_draw_news_item(rct_drawpixelinfo *dpi, rc } } - uint32 image_id_base = *RCT2_ADDRESS(0x00982708, uint32*)[peep->sprite_type * 2]; + uint32 image_id_base = g_sprite_entries[peep->sprite_type].sprite_image->base_image; image_id_base += w->frame_no & 0xFFFFFFFC; image_id_base++; diff --git a/src/windows/guest.c b/src/windows/guest.c index 58f808db5c..b1b4421c24 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -503,7 +503,7 @@ void window_guest_open(rct_peep* peep){ window->viewport_focus_coordinates.y = 0; window->frame_no = 0; window->list_information_type = 0; - window->var_492 = 0; + window->picked_peep_frame = 0; window->highlighted_item = 0; window_guest_disable_widgets(window); window->min_width = 192; @@ -625,7 +625,7 @@ void window_guest_overview_mouse_up(rct_window *w, int widgetIndex) return; } - w->var_48C = peep->x; + w->picked_peep_old_x = peep->x; remove_peep_from_ride(peep); invalidate_sprite_2((rct_sprite*)peep); @@ -830,7 +830,7 @@ void window_guest_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_ENTERTAINER) y++; - int ebx = *(RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2]) + 1; + int ebx = g_sprite_entries[peep->sprite_type].sprite_image->base_image + 1; int eax = 0; @@ -1182,7 +1182,7 @@ void window_guest_overview_tool_update(rct_window* w, int widgetIndex, int x, in map_invalidate_selection_rect(); } - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; int interactionType; get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_NONE, NULL, NULL, &interactionType, NULL, NULL); @@ -1193,19 +1193,21 @@ void window_guest_overview_tool_update(rct_window* w, int widgetIndex, int x, in y += 16; RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_X, uint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, uint16) = y; - w->var_492++; - if (w->var_492 >= 48)w->var_492 = 0; + w->picked_peep_frame++; + if (w->picked_peep_frame >= 48) { + w->picked_peep_frame = 0; + } rct_peep* peep; peep = GET_PEEP(w->number); - int ebx = (RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2])[22]; - ebx += w->var_492 >> 2; + uint32 imageId = g_sprite_entries[peep->sprite_type].sprite_image[11].base_image; + imageId += w->picked_peep_frame >> 2; int ebp = peep->tshirt_colour << 19; int ecx = peep->trousers_colour << 24; - ebx |= ebp | ecx | 0xA0000000; - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, uint32) = ebx; + imageId |= ebp | ecx | 0xA0000000; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, uint32) = imageId; } /** @@ -1254,7 +1256,7 @@ void window_guest_overview_tool_down(rct_window* w, int widgetIndex, int x, int peep->state = 0; peep_window_state_update(peep); peep->action = 0xFF; - peep->var_6D = 0; + peep->special_sprite = 0; peep->action_sprite_image_offset = 0; peep->action_sprite_type = 0xFF; peep->var_C4 = 0; @@ -1279,7 +1281,7 @@ void window_guest_overview_tool_abort(rct_window *w, int widgetIndex) if (peep->state != PEEP_STATE_PICKED) return; - sprite_move( w->var_48C, peep->y, peep->z + 8, (rct_sprite*)peep); + sprite_move(w->picked_peep_old_x, peep->y, peep->z + 8, (rct_sprite*)peep); invalidate_sprite_2((rct_sprite*)peep); if (peep->x != (sint16)0x8000){ @@ -1287,13 +1289,13 @@ void window_guest_overview_tool_abort(rct_window *w, int widgetIndex) peep->state = 0; peep_window_state_update(peep); peep->action = 0xFF; - peep->var_6D = 0; + peep->special_sprite = 0; peep->action_sprite_image_offset = 0; peep->action_sprite_type = 0; peep->var_C4 = 0; } - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; } /** diff --git a/src/windows/guest_list.c b/src/windows/guest_list.c index b1079bda40..f4989979c0 100644 --- a/src/windows/guest_list.c +++ b/src/windows/guest_list.c @@ -590,7 +590,7 @@ static void window_guest_list_paint(rct_window *w, rct_drawpixelinfo *dpi) window_draw_widgets(w, dpi); // Tab 1 image i = (_window_guest_list_selected_tab == 0 ? w->list_information_type & 0x0FFFFFFFC : 0); - i += RCT2_ADDRESS(RCT2_GLOBAL(0x00982708, int), int)[0] + 1; + i += g_sprite_entries[0].sprite_image->base_image + 1; i |= 0xA1600000; gfx_draw_sprite( dpi, @@ -655,14 +655,14 @@ static void window_guest_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, // For each guest FOR_ALL_GUESTS(spriteIndex, peep) { - peep->var_0C &= ~0x200; + peep->list_flags &= ~(PEEP_LIST_FLAGS_FLASHING); if (peep->outside_of_park != 0) continue; if (_window_guest_list_selected_filter != -1) { if (window_guest_list_is_peep_in_filter(peep)) continue; RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_MAP_FLASHING_FLAGS, uint16) |= (1 << 0); - peep->var_0C |= 0x200; + peep->list_flags |= PEEP_LIST_FLAGS_FLASHING; } if (_window_guest_list_tracking_only && !(peep->flags & PEEP_FLAGS_TRACKING)) continue; @@ -841,11 +841,11 @@ static void window_guest_list_find_groups() // Set all guests to unassigned FOR_ALL_GUESTS(spriteIndex, peep) if (peep->outside_of_park == 0) - peep->var_0C |= (1 << 8); + peep->list_flags |= PEEP_LIST_FLAGS_VISIBLE; // For each guest / group FOR_ALL_GUESTS(spriteIndex, peep) { - if (peep->outside_of_park != 0 || !(peep->var_0C & (1 << 8))) + if (peep->outside_of_park != 0 || !(peep->list_flags & PEEP_LIST_FLAGS_VISIBLE)) continue; // New group, cap at 240 though @@ -856,7 +856,7 @@ static void window_guest_list_find_groups() int ax = peep->sprite_index; _window_guest_list_num_groups++; _window_guest_list_groups_num_guests[groupIndex] = 1; - peep->var_0C &= ~(1 << 8); + peep->list_flags &= ~(PEEP_LIST_FLAGS_VISIBLE); get_arguments_from_peep( peep, &_window_guest_list_groups_argument_1[groupIndex], &_window_guest_list_groups_argument_2[groupIndex]); RCT2_GLOBAL(0x00F1EDF6, uint32) = _window_guest_list_groups_argument_1[groupIndex]; @@ -868,7 +868,7 @@ static void window_guest_list_find_groups() // Find more peeps that belong to same group FOR_ALL_GUESTS(spriteIndex2, peep2) { - if (peep2->outside_of_park != 0 || !(peep2->var_0C & (1 << 8))) + if (peep2->outside_of_park != 0 || !(peep2->list_flags & PEEP_LIST_FLAGS_VISIBLE)) continue; uint32 argument1, argument2; @@ -879,7 +879,7 @@ static void window_guest_list_find_groups() // Assign guest _window_guest_list_groups_num_guests[groupIndex]++; - peep2->var_0C &= ~(1 << 8); + peep2->list_flags &= ~(PEEP_LIST_FLAGS_VISIBLE); // Add face sprite, cap at 56 though if (_window_guest_list_groups_num_guests[groupIndex] >= 56) diff --git a/src/windows/map.c b/src/windows/map.c index 12503e84f1..76921d99ee 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -1028,7 +1028,7 @@ static void window_map_paint_peep_overlay(rct_drawpixelinfo *dpi) color = 0x14; - if ((peep->var_0C & 0x200) != 0) { + if ((peep->list_flags & PEEP_LIST_FLAGS_FLASHING) != 0) { if (peep->type == PEEP_TYPE_STAFF) { if ((RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_MAP_FLASHING_FLAGS, uint16) & (1 << 3)) != 0) { color = 0x8A; diff --git a/src/windows/news.c b/src/windows/news.c index 5885811365..77a0760e01 100644 --- a/src/windows/news.c +++ b/src/windows/news.c @@ -344,7 +344,7 @@ static void window_news_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int s } } - uint32 image_id = *RCT2_ADDRESS(0x00982708, uint32*)[sprite_type * 2]; + uint32 image_id = g_sprite_entries[sprite_type].sprite_image->base_image; image_id += 0xA0000001; image_id |= (peep->tshirt_colour << 19) | (peep->trousers_colour << 24); diff --git a/src/windows/park.c b/src/windows/park.c index 15f419ede7..d8306d4d74 100644 --- a/src/windows/park.c +++ b/src/windows/park.c @@ -1982,7 +1982,7 @@ static void window_park_draw_tab_images(rct_drawpixelinfo *dpi, rct_window *w) sprite_idx += (w->frame_no / 8) % 8; gfx_draw_sprite(dpi, sprite_idx, w->x + w->widgets[WIDX_TAB_3].left, w->y + w->widgets[WIDX_TAB_3].top, 0); - sprite_idx = *RCT2_GLOBAL(0x00982708, sint32*) + 1; + sprite_idx = g_sprite_entries[0].sprite_image->base_image + 1; if (w->page == WINDOW_PARK_PAGE_GUESTS) sprite_idx += w->var_492 & 0xFFFFFFFC; diff --git a/src/windows/ride.c b/src/windows/ride.c index 5c3f5c1480..13d0eb5666 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -1086,7 +1086,7 @@ static void window_ride_draw_tab_customer(rct_drawpixelinfo *dpi, rct_window *w) if (w->page == WINDOW_RIDE_PAGE_CUSTOMER) spriteIndex = w->var_492 & ~3; - spriteIndex += RCT2_GLOBAL(RCT2_GLOBAL(0x00982708, uint32), uint32); + spriteIndex += g_sprite_entries[0].sprite_image->base_image; spriteIndex += 1; spriteIndex |= 0xA9E00000; diff --git a/src/windows/staff.c b/src/windows/staff.c index 0d3833830f..3da193a083 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -449,7 +449,7 @@ void window_staff_overview_mouseup(rct_window *w, int widgetIndex) return; } - w->var_48C = peep->x; + w->picked_peep_old_x = peep->x; remove_peep_from_ride(peep); invalidate_sprite_2((rct_sprite*)peep); @@ -987,7 +987,7 @@ void window_staff_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi) if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_ENTERTAINER) y++; - int ebx = *(RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2]) + 1; + int ebx = g_sprite_entries[peep->sprite_type].sprite_image->base_image + 1; int eax = 0; @@ -1096,7 +1096,7 @@ void window_staff_overview_tool_update(rct_window* w, int widgetIndex, int x, in if (widgetIndex != WIDX_PICKUP) return; - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; int interactionType; get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_NONE, NULL, NULL, &interactionType, NULL, NULL); @@ -1107,16 +1107,19 @@ void window_staff_overview_tool_update(rct_window* w, int widgetIndex, int x, in y += 16; RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_X, uint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, uint16) = y; - w->var_492++; - if (w->var_492 >= 48)w->var_492 = 0; + w->picked_peep_frame++; + if (w->picked_peep_frame >= 48) { + w->picked_peep_frame = 0; + } rct_peep* peep; peep = GET_PEEP(w->number); - int sprite_idx = (RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2])[22]; - sprite_idx += w->var_492 >> 2; - sprite_idx |= (peep->tshirt_colour << 19) | (peep->trousers_colour << 24) | 0xA0000000; - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, uint32) = sprite_idx; + uint32 imageId = g_sprite_entries[peep->sprite_type].sprite_image[11].base_image; + imageId += w->picked_peep_frame >> 2; + + imageId |= (peep->tshirt_colour << 19) | (peep->trousers_colour << 24) | 0xA0000000; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, uint32) = imageId; } /** @@ -1163,7 +1166,7 @@ void window_staff_overview_tool_down(rct_window* w, int widgetIndex, int x, int peep->state = PEEP_STATE_FALLING; peep_window_state_update(peep); peep->action = 0xFF; - peep->var_6D = 0; + peep->special_sprite = 0; peep->action_sprite_image_offset = 0; peep->action_sprite_type = 0; peep->var_C4 = 0; @@ -1191,7 +1194,7 @@ void window_staff_overview_tool_abort(rct_window *w, int widgetIndex) rct_peep* peep = GET_PEEP(w->number); if (peep->state != PEEP_STATE_PICKED) return; - sprite_move(w->var_48C, peep->y, peep->z + 8, (rct_sprite*)peep); + sprite_move(w->picked_peep_old_x, peep->y, peep->z + 8, (rct_sprite*)peep); invalidate_sprite_2((rct_sprite*)peep); if (peep->x != (sint16)0x8000){ @@ -1199,13 +1202,13 @@ void window_staff_overview_tool_abort(rct_window *w, int widgetIndex) peep->state = PEEP_STATE_FALLING; peep_window_state_update(peep); peep->action = 0xFF; - peep->var_6D = 0; + peep->special_sprite = 0; peep->action_sprite_image_offset = 0; peep->action_sprite_type = 0; peep->var_C4 = 0; } - RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; } else if (widgetIndex == WIDX_PATROL){ hide_gridlines(); diff --git a/src/windows/staff_list.c b/src/windows/staff_list.c index 76595b00da..afd7271fd7 100644 --- a/src/windows/staff_list.c +++ b/src/windows/staff_list.c @@ -310,10 +310,10 @@ void window_staff_list_update(rct_window *w) RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_MAP_FLASHING_FLAGS, uint16) |= (1 << 2); FOR_ALL_PEEPS(spriteIndex, peep) { if (peep->type == PEEP_TYPE_STAFF) { - peep->var_0C &= ~0x200; + peep->list_flags &= ~(PEEP_LIST_FLAGS_FLASHING); if (peep->staff_type == RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_STAFF_LIST_SELECTED_TAB, uint8)) { - peep->var_0C |= 0x200; + peep->list_flags |= PEEP_LIST_FLAGS_FLASHING; } } } diff --git a/src/world/sprite.c b/src/world/sprite.c index 40ec76621a..96a9b1eebb 100644 --- a/src/world/sprite.c +++ b/src/world/sprite.c @@ -29,6 +29,8 @@ rct_sprite* g_sprite_list = RCT2_ADDRESS(RCT2_ADDRESS_SPRITE_LIST, rct_sprite); +rct_sprite_entry* g_sprite_entries = RCT2_ADDRESS(RCT2_ADDRESS_SPRITE_ENTRIES, rct_sprite_entry); + static uint16 sprite_get_first_in_quadrant(int x, int y) { int offset = ((x & 0x1FE0) << 3) | (y >> 5); diff --git a/src/world/sprite.h b/src/world/sprite.h index 89fdb512d2..9ce80c93b7 100644 --- a/src/world/sprite.h +++ b/src/world/sprite.h @@ -300,6 +300,23 @@ typedef union { rct_crash_splash crash_splash; } rct_sprite; +typedef struct { + uint8 sprite_width; // 0x00 + uint8 sprite_height_negative; // 0x01 + uint8 sprite_height_positive; // 0x02 + uint8 unused; // 0x03 +} rct_sprite_bounds; + +typedef struct { + uint32 base_image; // 0x00 + uint8* unkn_04; // 0x04 +} rct_sprite_image; + +typedef struct { + rct_sprite_image *sprite_image; // 0x00 + rct_sprite_bounds *sprite_bounds; // 0x04 +} rct_sprite_entry; + enum { SPRITE_MISC_0, SPRITE_MISC_MONEY_EFFECT, @@ -316,6 +333,10 @@ enum { // rct2: 0x010E63BC extern rct_sprite* g_sprite_list; +// rct2: 0x00982708 +extern rct_sprite_entry* g_sprite_entries; + + rct_sprite *create_sprite(uint8 bl); void reset_sprite_list(); void reset_0x69EBE4();