From 3617c2cb934bddb486bf1332e87ea5c4692266e5 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Tue, 18 Oct 2016 13:33:43 -0600 Subject: [PATCH] Code review --- src/game.c | 2 +- src/game.h | 3 ++- src/peep/peep.c | 25 +++++++++++++++---------- src/peep/peep.h | 4 ++-- src/peep/staff.c | 4 +++- src/windows/guest.c | 9 ++++++++- src/windows/staff.c | 9 ++++++++- src/world/balloon.c | 2 +- 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/game.c b/src/game.c index 810d782ed0..5a56eefcfd 100644 --- a/src/game.c +++ b/src/game.c @@ -1099,7 +1099,7 @@ void game_load_or_quit_no_save_prompt() } } -GAME_COMMAND_POINTER* new_game_command_table[70] = { +GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { game_command_set_ride_appearance, game_command_set_land_height, game_pause_toggle, diff --git a/src/game.h b/src/game.h index ab189b5359..c02a67835c 100644 --- a/src/game.h +++ b/src/game.h @@ -93,6 +93,7 @@ enum GAME_COMMAND { GAME_COMMAND_PICKUP_GUEST, GAME_COMMAND_PICKUP_STAFF, GAME_COMMAND_BALLOON_PRESS, + GAME_COMMAND_COUNT }; enum { @@ -132,7 +133,7 @@ extern rct_string_id gGameCommandErrorText; extern uint8 gErrorType; extern rct_string_id gErrorStringId; -extern GAME_COMMAND_POINTER* new_game_command_table[70]; +extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT]; #ifndef NO_RCT2 #define gCurrentTicks RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) diff --git a/src/peep/peep.c b/src/peep/peep.c index 8973f90c2c..9b3e502381 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1880,20 +1880,23 @@ void peep_pickup_abort(rct_peep* peep, int old_x) gPickupPeepImage = UINT32_MAX; } -bool peep_pickup_place(rct_peep* peep, int x, int y, bool apply) +bool peep_pickup_place(rct_peep* peep, int x, int y, int z, bool apply) { if (!peep) return false; - int dest_x, dest_y; - rct_map_element *mapElement; - footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, &mapElement); + rct_map_element *mapElement = map_get_path_element_at(x / 32, y / 32, z); - if (dest_x == (sint16)SPRITE_LOCATION_NULL) { - gGameCommandErrorTitle = STR_ERR_CANT_PLACE_PERSON_HERE; - return false; + if (!mapElement) { + mapElement = map_get_surface_element_at(x / 32, y / 32); } + if (!mapElement) + return false; + + int dest_x = x & 0xFFE0; + int dest_y = y & 0xFFE0; + // Set the coordinate of destination to be exactly // in the middle of a tile. dest_x += 16; @@ -1943,7 +1946,7 @@ bool peep_pickup_place(rct_peep* peep, int x, int y, bool apply) return true; } -bool peep_pickup_command(int peepnum, int x, int y, int action, bool apply) +bool peep_pickup_command(int peepnum, int x, int y, int z, int action, bool apply) { rct_peep* peep = GET_PEEP(peepnum); switch (action) { @@ -1974,7 +1977,7 @@ bool peep_pickup_command(int peepnum, int x, int y, int action, bool apply) if (network_get_pickup_peep(game_command_playerid) != peep) { return false; } - if (!peep_pickup_place(peep, x, y, apply)) { + if (!peep_pickup_place(peep, x, y, z, apply)) { return false; } break; @@ -1987,7 +1990,9 @@ void game_command_pickup_guest(int* eax, int* ebx, int* ecx, int* edx, int* esi, int peepnum = *eax; int x = *edi; int y = *ebp; - if (peep_pickup_command(peepnum, x, y, *ecx, *ebx & GAME_COMMAND_FLAG_APPLY)) { + int z = *edx; + int action = *ecx; + if (peep_pickup_command(peepnum, x, y, z, action, *ebx & GAME_COMMAND_FLAG_APPLY)) { *ebx = 0; } else diff --git a/src/peep/peep.h b/src/peep/peep.h index 027b6287bc..c1bd61d592 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -654,8 +654,8 @@ bool peep_has_item(rct_peep *peep, int peepItem); int peep_has_food(rct_peep* peep); void peep_pickup(rct_peep* peep); void peep_pickup_abort(rct_peep* peep, int old_x); -bool peep_pickup_place(rct_peep* peep, int x, int y, bool apply); -bool peep_pickup_command(int peepnum, int x, int y, int action, bool apply); +bool peep_pickup_place(rct_peep* peep, int x, int y, int z, bool apply); +bool peep_pickup_command(int peepnum, int x, int y, int z, int action, bool apply); void game_command_pickup_guest(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp); void peep_sprite_remove(rct_peep* peep); void peep_remove(rct_peep* peep); diff --git a/src/peep/staff.c b/src/peep/staff.c index 40568c1dea..6e8cbaaa2b 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -1371,7 +1371,9 @@ void game_command_pickup_staff(int* eax, int* ebx, int* ecx, int* edx, int* esi, int peepnum = *eax; int x = *edi; int y = *ebp; - if (peep_pickup_command(peepnum, x, y, *ecx, *ebx & GAME_COMMAND_FLAG_APPLY)) { + int z = *edx; + int action = *ecx; + if (peep_pickup_command(peepnum, x, y, z, action, *ebx & GAME_COMMAND_FLAG_APPLY)) { *ebx = 0; } else diff --git a/src/windows/guest.c b/src/windows/guest.c index ad7f07611f..17467cf82b 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -1213,8 +1213,15 @@ void window_guest_overview_tool_down(rct_window* w, int widgetIndex, int x, int if (widgetIndex != WIDX_PICKUP) return; + int dest_x, dest_y; + rct_map_element* mapElement; + footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, &mapElement); + + if (x == (sint16)0x8000) + return; + game_command_callback = game_command_callback_pickup_guest; - game_do_command(w->number, GAME_COMMAND_FLAG_APPLY, 2, 0, GAME_COMMAND_PICKUP_GUEST, x, y); + game_do_command(w->number, GAME_COMMAND_FLAG_APPLY, 2, mapElement->base_height, GAME_COMMAND_PICKUP_GUEST, dest_x, dest_y); } /** diff --git a/src/windows/staff.c b/src/windows/staff.c index e1d98bf35c..5b54d8ffc2 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -1158,8 +1158,15 @@ void window_staff_overview_tool_update(rct_window* w, int widgetIndex, int x, in void window_staff_overview_tool_down(rct_window* w, int widgetIndex, int x, int y) { if (widgetIndex == WIDX_PICKUP) { + int dest_x, dest_y; + rct_map_element* mapElement; + footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, &mapElement); + + if (x == (sint16)0x8000) + return; + game_command_callback = game_command_callback_pickup_staff; - game_do_command(w->number, GAME_COMMAND_FLAG_APPLY, 2, 0, GAME_COMMAND_PICKUP_STAFF, x, y); + game_do_command(w->number, GAME_COMMAND_FLAG_APPLY, 2, mapElement->base_height, GAME_COMMAND_PICKUP_STAFF, dest_x, dest_y); } else if (widgetIndex == WIDX_PATROL){ int dest_x, dest_y; diff --git a/src/world/balloon.c b/src/world/balloon.c index 604723f1be..0cff7ed7cb 100644 --- a/src/world/balloon.c +++ b/src/world/balloon.c @@ -81,7 +81,7 @@ void balloon_update(rct_balloon *balloon) * * rct2: 0x006E88ED */ -void balloon_press(rct_balloon *balloon) +static void balloon_press(rct_balloon *balloon) { if (balloon->popped == 1) return;