mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 04:23:20 +01:00
refactor and implement locate mechanic for ride window
This commit is contained in:
10
src/peep.c
10
src/peep.c
@@ -26,6 +26,7 @@
|
||||
#include "rct2.h"
|
||||
#include "ride.h"
|
||||
#include "sprite.h"
|
||||
#include "staff.h"
|
||||
#include "window.h"
|
||||
|
||||
static void peep_update(rct_peep *peep);
|
||||
@@ -586,4 +587,13 @@ void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, ui
|
||||
*/
|
||||
int peep_can_be_picked_up(rct_peep* peep){
|
||||
return RCT2_ADDRESS(0x982004, uint8)[peep->state] & 1;
|
||||
}
|
||||
|
||||
int peep_is_mechanic(rct_peep *peep)
|
||||
{
|
||||
return (
|
||||
peep->sprite_identifier == SPRITE_IDENTIFIER_PEEP &&
|
||||
peep->type == PEEP_TYPE_STAFF &&
|
||||
peep->staff_type == STAFF_TYPE_MECHANIC
|
||||
);
|
||||
}
|
||||
@@ -445,5 +445,6 @@ void peep_applause();
|
||||
rct_peep *peep_generate(int x, int y, int z);
|
||||
void get_arguments_from_action(rct_peep* peep, uint32 *argument_1, uint32* argument_2);
|
||||
void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2);
|
||||
int peep_is_mechanic(rct_peep *peep);
|
||||
|
||||
#endif
|
||||
|
||||
20
src/ride.c
20
src/ride.c
@@ -23,6 +23,7 @@
|
||||
#include "game.h"
|
||||
#include "map.h"
|
||||
#include "news_item.h"
|
||||
#include "staff.h"
|
||||
#include "sprite.h"
|
||||
#include "ride.h"
|
||||
#include "sprite.h"
|
||||
@@ -520,3 +521,22 @@ void ride_get_status(int rideIndex, int *formatSecondary, int *argument)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rct_peep *ride_get_assigned_mechanic(rct_ride *ride)
|
||||
{
|
||||
rct_peep *peep;
|
||||
|
||||
if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) {
|
||||
if (
|
||||
ride->mechanic_status == RIDE_MECHANIC_STATUS_HEADING ||
|
||||
ride->mechanic_status == 3 ||
|
||||
ride->mechanic_status == 4
|
||||
) {
|
||||
peep = &(g_sprite_list[ride->mechanic].peep);
|
||||
if (peep_is_mechanic(peep))
|
||||
return peep;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
#define _RIDE_H_
|
||||
|
||||
#include "map.h"
|
||||
#include "peep.h"
|
||||
#include "rct2.h"
|
||||
#include "string_ids.h"
|
||||
|
||||
@@ -457,5 +458,6 @@ rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *ou
|
||||
void ride_construct_new(int list_item);
|
||||
int ride_try_construct(rct_map_element *trackMapElement);
|
||||
void ride_get_status(int rideIndex, int *formatSecondary, int *argument);
|
||||
rct_peep *ride_get_assigned_mechanic(rct_ride *ride);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1434,7 +1434,16 @@ static void window_ride_main_paint()
|
||||
*/
|
||||
static void window_ride_locate_mechanic(rct_window *w)
|
||||
{
|
||||
RCT2_CALLPROC_X(0x006B1AE4, 0, 0, 0, 0, (int)w, 0, 0);
|
||||
rct_peep *peep;
|
||||
rct_ride *ride = GET_RIDE(w->number);
|
||||
|
||||
peep = ride_get_assigned_mechanic(ride);
|
||||
if (peep != NULL) {
|
||||
window_staff_peep_open(peep);
|
||||
} else {
|
||||
// Presumebly looks for the closest mechanic
|
||||
RCT2_CALLPROC_X(0x006B1B3E, 0, w->number * 0x260, 0, 0, (int)w, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1443,7 +1452,17 @@ static void window_ride_locate_mechanic(rct_window *w)
|
||||
*/
|
||||
static void window_ride_maintenance_draw_bar(rct_window *w, rct_drawpixelinfo *dpi, int x, int y, int value, int unk)
|
||||
{
|
||||
RCT2_CALLPROC_X(0x006B7D08, value, 0, x, y, (int)w, (int)dpi, unk);
|
||||
gfx_fill_rect_inset(dpi, x, y, x + 149, y + 8, w->colours[1], 0x30);
|
||||
if (unk & (1 << 31)) {
|
||||
unk &= ~(1 << 31);
|
||||
if (RCT2_GLOBAL(0x009DEA6E, uint8) == 0 && (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 8))
|
||||
return;
|
||||
}
|
||||
|
||||
value = ((186 * ((value * 2) & 0xFF)) >> 8) & 0xFF;
|
||||
if (value > 2) {
|
||||
gfx_fill_rect_inset(dpi, x + 2, y + 1, x + value + 1, y + 8, unk, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1685,11 +1704,7 @@ static void window_ride_maintenance_paint()
|
||||
gfx_draw_string_left_wrapped(dpi, NULL, x + 4, y, 280, stringId, 0);
|
||||
} else {
|
||||
mechanicSprite = &(g_sprite_list[ride->mechanic].peep);
|
||||
if (
|
||||
mechanicSprite->sprite_identifier == SPRITE_IDENTIFIER_PEEP &&
|
||||
mechanicSprite->type == PEEP_TYPE_STAFF &&
|
||||
mechanicSprite->staff_type == STAFF_TYPE_MECHANIC
|
||||
) {
|
||||
if (peep_is_mechanic(mechanicSprite)) {
|
||||
RCT2_GLOBAL(0x013CE952 + 0, uint16) = mechanicSprite->name_string_idx;
|
||||
RCT2_GLOBAL(0x013CE952 + 2, uint32) = mechanicSprite->id;
|
||||
gfx_draw_string_left_wrapped(dpi, (void*)0x013CE952, x + 4, y, 280, stringId, 0);
|
||||
|
||||
Reference in New Issue
Block a user