diff --git a/src/management/news_item.c b/src/management/news_item.c index 95441e242f..37c2996afd 100644 --- a/src/management/news_item.c +++ b/src/management/news_item.c @@ -295,7 +295,7 @@ void news_item_open_subject(int type, int subject) case NEWS_ITEM_PEEP_ON_RIDE: case NEWS_ITEM_PEEP: peep = GET_PEEP(subject); - RCT2_CALLPROC_X(0x006989E9, 0, 0, 0, (int)peep, 0, 0, 0); + window_guest_open(peep); break; case NEWS_ITEM_MONEY: window_finances_open(); diff --git a/src/ride/station.c b/src/ride/station.c index ae5f4ac149..398c98892e 100644 --- a/src/ride/station.c +++ b/src/ride/station.c @@ -185,8 +185,8 @@ static void ride_update_station_race(rct_ride *ride, int stationIndex) vehicle = &(g_sprite_list[ride->vehicles[i]].vehicle); if (vehicle->status != VEHICLE_STATUS_WAITING_TO_DEPART && vehicle->num_laps >= numLaps) { // Found a winner - if (vehicle->var_B3 != 0) { - peep = &(g_sprite_list[vehicle->peep].peep); + if (vehicle->num_peeps != 0) { + peep = &(g_sprite_list[vehicle->peep[0]].peep); ride->race_winner = peep->sprite_index; ride->var_14D |= 12; } @@ -240,8 +240,8 @@ static void ride_race_init_vehicle_speeds(rct_ride *ride) vehicle->speed = (scenario_rand() & 16) - 8 + RCT2_GLOBAL(unk + 0x76, uint8); - if (vehicle->var_B3) { - rct_peep *peep = &g_sprite_list[vehicle->peep].peep; + if (vehicle->num_peeps != 0) { + rct_peep *peep = &g_sprite_list[vehicle->peep[0]].peep; switch (peep_get_easteregg_name_id(peep)) { case EASTEREGG_PEEP_NAME_MICHAEL_SCHUMACHER: diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0f905e4598..19b32d97e5 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -601,7 +601,7 @@ void vehicle_set_map_toolbar(rct_vehicle *vehicle) ride = GET_RIDE(vehicle->ride); while (vehicle->var_01 != 0) - vehicle = &(g_sprite_list[vehicle->var_40].vehicle); + vehicle = &(g_sprite_list[vehicle->prev_vehicle_on_train].vehicle); for (vehicleIndex = 0; vehicleIndex < 32; vehicleIndex++) if (ride->vehicles[vehicleIndex] == vehicle->sprite_index) @@ -618,4 +618,19 @@ void vehicle_set_map_toolbar(rct_vehicle *vehicle) ride_get_status(vehicle->ride, &arg0, &arg1); RCT2_GLOBAL(RCT2_ADDRESS_MAP_TOOLTIP_ARGS + 14, uint16) = (uint16)arg0; RCT2_GLOBAL(RCT2_ADDRESS_MAP_TOOLTIP_ARGS + 16, uint32) = (uint16)arg1; +} + +rct_vehicle *vehicle_get_head(rct_vehicle *vehicle) +{ + rct_vehicle *prevVehicle; + + for (;;) { + prevVehicle = &(g_sprite_list[vehicle->prev_vehicle_on_train].vehicle); + if (prevVehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) + break; + + vehicle = prevVehicle; + } + + return vehicle; } \ No newline at end of file diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 969197661c..292e3f399d 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -52,7 +52,7 @@ typedef struct { sint16 var_36; uint8 pad_38[0x06]; uint16 next_vehicle_on_train; // 0x3E - uint16 var_40; + uint16 prev_vehicle_on_train; // 0x40 uint16 pad_42; uint16 var_44; uint16 var_46; @@ -62,11 +62,9 @@ typedef struct { uint8 pad_4C[0x4]; uint8 status; // 0x50 uint8 var_51; - uint16 peep; // 0x52 - uint8 pad_54[0x2C]; - uint16 var_80; - uint8 pad_82[0x31]; - uint8 var_B3; + uint16 peep[32]; // 0x52 + uint8 pad_92[0x21]; + uint8 num_peeps; // 0xB3 uint8 pad_B4[0x07]; uint8 sound1_id; // 0xBB uint8 sound1_volume; // 0xBC @@ -127,6 +125,8 @@ void vehicle_sounds_update(); void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); +rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); + /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) diff --git a/src/windows/ride.c b/src/windows/ride.c index aca7d4d98e..4134380b6c 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -925,17 +925,6 @@ static uint32* window_ride_page_events[] = { const int window_ride_tab_animation_divisor[] = { 0, 0, 2, 2, 4, 2, 8, 8, 2, 0 }; const int window_ride_tab_animation_frames[] = { 0, 0, 4, 16, 8, 16, 8, 8, 8, 0 }; -// WINDOW_PARK_PAGE_MAIN, -// WINDOW_PARK_PAGE_VEHICLE, -// WINDOW_PARK_PAGE_OPERATING, -// WINDOW_PARK_PAGE_MAINTENANCE, -// WINDOW_PARK_PAGE_COLOUR, -// WINDOW_PARK_PAGE_MUSIC, -// WINDOW_PARK_PAGE_MEASUREMENTS, -// WINDOW_PARK_PAGE_GRAPHS, -// WINDOW_PARK_PAGE_INCOME, -// WINDOW_PARK_PAGE_CUSTOMER - static void window_ride_draw_tab_image(rct_drawpixelinfo *dpi, rct_window *w, int page, int spriteIndex) { int widgetIndex = WIDX_TAB_1 + page; @@ -1184,8 +1173,52 @@ rct_window *window_ride_main_open(int rideIndex) */ rct_window *window_ride_open_station(int rideIndex, int stationIndex) { - RCT2_CALLPROC_X(0x006ACCCE, rideIndex, stationIndex, 0, 0, 0, 0, 0); - return window_find_by_number(WC_RIDE, rideIndex); + int i; + rct_ride *ride; + rct_window *w; + + ride = GET_RIDE(rideIndex); + + if (RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8), uint32) & 0x2000) + return window_ride_main_open(rideIndex); + + w = window_bring_to_front_by_number(WC_RIDE, rideIndex); + if (w == NULL) { + w = window_ride_open(rideIndex); + w->ride.var_482 = -1; + } + + if ( + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint8) & INPUT_FLAG_TOOL_ACTIVE && + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) == w->classification && + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) == w->number + ) { + tool_cancel(); + } + + w->page = WINDOW_PARK_PAGE_MAIN; + w->width = 316; + w->height = 180; + window_invalidate(w); + + w->widgets = window_ride_page_widgets[w->page]; + w->enabled_widgets = window_ride_page_enabled_widgets[w->page]; + w->var_020 = RCT2_ADDRESS(0x0098DD68, uint32)[w->page]; + w->event_handlers = window_ride_page_events[w->page]; + w->pressed_widgets = 0; + RCT2_CALLPROC_X(0x006AEB9F, 0, 0, 0, 0, (int)w, 0, 0); + window_init_scroll_widgets(w); + + // View + for (i = stationIndex; i >= 0; i--) { + if (ride->station_starts[i] == 0xFFFF) + stationIndex--; + } + + w->ride.view = 1 + ride->num_vehicles + stationIndex; + window_ride_init_viewport(w); + + return w; } rct_window *window_ride_open_track(rct_map_element *mapElement) @@ -1209,8 +1242,87 @@ rct_window *window_ride_open_track(rct_map_element *mapElement) */ rct_window *window_ride_open_vehicle(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x6ACAC2, 0, 0, 0, (int)vehicle, 0, 0, 0); - return window_find_by_number(WC_RIDE, vehicle->ride); + int i, rideIndex, view, numPeepsLeft, openedPeepWindow; + uint16 headVehicleSpriteIndex, peepSpriteIndex; + rct_ride *ride; + rct_vehicle *headVehicle; + rct_window *w, *w2; + + headVehicle = vehicle_get_head(vehicle); + headVehicleSpriteIndex = headVehicle->sprite_index; + rideIndex = headVehicle->ride; + ride = GET_RIDE(rideIndex); + + // Get view index + view = 1; + for (i = 0; i < 32; i++) { + if (ride->vehicles[i] == headVehicleSpriteIndex) + break; + + view++; + } + + + w = window_find_by_number(WC_RIDE, rideIndex); + if (w != NULL) { + window_invalidate(w); + + if ( + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint8) & INPUT_FLAG_TOOL_ACTIVE && + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) == w->classification && + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) == w->number + ) { + tool_cancel(); + } + + openedPeepWindow = 0; + if (w->ride.view == view) { + numPeepsLeft = vehicle->num_peeps; + for (i = 0; i < 32 && numPeepsLeft > 0; i++) { + peepSpriteIndex = vehicle->peep[i]; + if (peepSpriteIndex == SPRITE_INDEX_NULL) + continue; + + numPeepsLeft--; + w2 = window_find_by_number(WC_PEEP, peepSpriteIndex); + if (w2 == NULL) { + rct_peep *peep = &(g_sprite_list[peepSpriteIndex].peep); + window_guest_open(peep); + openedPeepWindow = 1; + + break; + } + } + } + + w = openedPeepWindow ? + window_find_by_number(WC_RIDE, rideIndex) : + window_bring_to_front_by_number(WC_RIDE, rideIndex); + } + + if (w == NULL) { + w = window_ride_open(rideIndex); + w->ride.var_482 = -1; + } + + w->page = WINDOW_PARK_PAGE_MAIN; + w->width = 316; + w->height = 180; + window_invalidate(w); + + w->widgets = window_ride_page_widgets[w->page]; + w->enabled_widgets = window_ride_page_enabled_widgets[w->page]; + w->var_020 = RCT2_ADDRESS(0x0098DD68, uint32)[w->page]; + w->event_handlers = window_ride_page_events[w->page]; + w->pressed_widgets = 0; + RCT2_CALLPROC_X(0x006AEB9F, 0, 0, 0, 0, (int)w, 0, 0); + window_init_scroll_widgets(w); + + w->ride.view = view; + window_ride_init_viewport(w); + window_invalidate(w); + + return w; } /**