From fb1c8c4e420595b7be62dd98f167ba9cc54e869e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 3 Jun 2015 18:02:41 +0100 Subject: [PATCH] Check against invalid tiles correctly --- src/audio/audio.c | 2 +- src/interface/viewport.c | 2 +- src/interface/viewport_interaction.c | 2 +- src/peep/peep.c | 4 ++-- src/rct1.c | 2 +- src/ride/vehicle.c | 4 ++-- src/windows/cheats.c | 4 ++-- src/windows/footpath.c | 4 ++-- src/windows/guest.c | 6 +++--- src/windows/staff.c | 4 ++-- src/world/sprite.c | 6 +++--- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/audio/audio.c b/src/audio/audio.c index 57429f7cdf..d50c1b4ab1 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -1482,7 +1482,7 @@ int sound_play_panned(int sound_id, int ebx, sint16 x, sint16 y, sint16 z) } other_sound->id = sound_id; int pan; - if (ebx == 0x8000) { + if (ebx == (sint16)0x8000) { pan = 0; } else { int x2 = ebx << 16; diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 1ce75b6591..29d450731e 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -1652,7 +1652,7 @@ void sub_688972(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **v void screen_pos_to_map_pos(sint16 *x, sint16 *y, int *direction) { sub_688972(*x, *y, x, y, NULL); - if (*x == 0x8000) + if (*x == (sint16)0x8000) return; int my_direction; diff --git a/src/interface/viewport_interaction.c b/src/interface/viewport_interaction.c index 6d2ac7152f..fb704f3192 100644 --- a/src/interface/viewport_interaction.c +++ b/src/interface/viewport_interaction.c @@ -548,7 +548,7 @@ static rct_peep *viewport_interaction_get_closest_peep(int x, int y, int maxDist closestPeep = NULL; closestDistance = 0xFFFF; FOR_ALL_PEEPS(spriteIndex, peep) { - if (peep->sprite_left == 0x8000) + if (peep->sprite_left == (sint16)0x8000) continue; distance = diff --git a/src/peep/peep.c b/src/peep/peep.c index bd566339ba..1b219178a7 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -667,7 +667,7 @@ void peep_update_falling(rct_peep* peep){ if (peep->item_standard_flags & PEEP_ITEM_BALLOON){ peep->item_standard_flags &= ~PEEP_ITEM_BALLOON; - if (peep->sprite_type == 19 && peep->x != 0x8000){ + if (peep->sprite_type == 19 && peep->x != (sint16)0x8000){ create_balloon(peep->x, peep->y, height, peep->balloon_colour, 0); peep->var_45 |= (1 << 3); peep_update_sprite_type(peep); @@ -4619,7 +4619,7 @@ void peep_applause() // Release balloon if (peep->item_standard_flags & PEEP_ITEM_BALLOON) { peep->item_standard_flags &= ~PEEP_ITEM_BALLOON; - if (peep->x != 0x8000) { + if (peep->x != (sint16)0x8000) { create_balloon(peep->x, peep->y, peep->z + 9, peep->balloon_colour, 0); peep->var_45 |= 8; peep_update_sprite_type(peep); diff --git a/src/rct1.c b/src/rct1.c index 6cb651210a..854ecaf06f 100644 --- a/src/rct1.c +++ b/src/rct1.c @@ -500,7 +500,7 @@ static void sub_666DFD() x = RCT2_GLOBAL(0x013573EA, uint16); y = RCT2_GLOBAL(0x013573EC, uint16); - if (x == 0x8000) + if (x == (sint16)0x8000) return; x /= 32; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 10d3243de9..3536ea1985 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -37,7 +37,7 @@ void vehicle_update_sound_params(rct_vehicle* vehicle) { if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) || RCT2_GLOBAL(0x0141F570, uint8) == 6)) { if (vehicle->sound1_id != (uint8)-1 || vehicle->sound2_id != (uint8)-1) { - if (vehicle->sprite_left != 0x8000) { + if (vehicle->sprite_left != (sint16)0x8000) { RCT2_GLOBAL(0x009AF5A0, sint16) = vehicle->sprite_left; RCT2_GLOBAL(0x009AF5A2, sint16) = vehicle->sprite_top; RCT2_GLOBAL(0x009AF5A4, sint16) = vehicle->sprite_right; @@ -116,7 +116,7 @@ void vehicle_update_sound_params(rct_vehicle* vehicle) i->frequency = (uint16)v19; i->id = vehicle->sprite_index; i->volume = 0; - if (vehicle->x != 0x8000) { + if (vehicle->x != (sint16)0x8000) { int tile_idx = (((vehicle->y & 0xFFE0) * 256) + (vehicle->x & 0xFFE0)) / 32; rct_map_element* map_element; for (map_element = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[tile_idx]; map_element->type & MAP_ELEMENT_TYPE_MASK; map_element++); diff --git a/src/windows/cheats.c b/src/windows/cheats.c index 3b99076f01..748426ca6f 100644 --- a/src/windows/cheats.c +++ b/src/windows/cheats.c @@ -836,7 +836,7 @@ static void window_cheats_misc_tool_update() int map_x, map_y; footpath_get_coordinates_from_pos(x, y + 16, &map_x, &map_y, NULL, NULL); - if (map_x != 0x8000){ + if (map_x != (sint16)0x8000){ RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) |= 1; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16) = 4; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16) = map_x; @@ -862,7 +862,7 @@ static void window_cheats_misc_tool_down() int dest_x, dest_y; footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, NULL); - if (dest_x == 0x8000)return; + if (dest_x == (sint16)0x8000)return; // Set the coordinate of destination to be exactly // in the middle of a tile. diff --git a/src/windows/footpath.c b/src/windows/footpath.c index 614ca87e81..3e55aca1a8 100644 --- a/src/windows/footpath.c +++ b/src/windows/footpath.c @@ -719,7 +719,7 @@ static void window_footpath_set_selection_start_bridge_at_point(int screenX, int RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~(1 << 0) & ~(1 << 2); footpath_bridge_get_info_from_pos(screenX, screenY, &x, &y, &direction, &mapElement); - if (x == 0x8000) + if (x == (sint16)0x8000) return; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) |= (1 << 0) | (1 << 2); @@ -801,7 +801,7 @@ static void window_footpath_start_bridge_at_point(int screenX, int screenY) rct_map_element *mapElement; footpath_bridge_get_info_from_pos(screenX, screenY, &x, &y, &direction, &mapElement); - if (x == 0x8000) + if (x == (sint16)0x8000) return; if (map_element_get_type(mapElement) == MAP_ELEMENT_TYPE_SURFACE) { diff --git a/src/windows/guest.c b/src/windows/guest.c index 90843629b3..837851106e 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -1149,7 +1149,7 @@ void window_guest_overview_tool_update(){ int map_x, map_y; footpath_get_coordinates_from_pos(x, y + 16, &map_x, &map_y, NULL, NULL); - if (map_x != 0x8000){ + if (map_x != (sint16)0x8000){ RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) |= 1; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16) = 4; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16) = map_x; @@ -1199,7 +1199,7 @@ void window_guest_overview_tool_down(){ rct_map_element *mapElement; footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, &mapElement); - if (dest_x == 0x8000)return; + if (dest_x == (sint16)0x8000)return; // Set the coordinate of destination to be exactly // in the middle of a tile. @@ -1263,7 +1263,7 @@ void window_guest_overview_tool_abort(){ sprite_move( w->var_48C, peep->y, peep->z + 8, (rct_sprite*)peep); invalidate_sprite((rct_sprite*)peep); - if (peep->x != 0x8000){ + if (peep->x != (sint16)0x8000){ peep_decrement_num_riders(peep); peep->state = 0; peep_window_state_update(peep); diff --git a/src/windows/staff.c b/src/windows/staff.c index e2183ef642..d30c27dfd6 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -1123,7 +1123,7 @@ void window_staff_overview_tool_down(){ rct_map_element *mapElement; footpath_get_coordinates_from_pos(x, y + 16, &dest_x, &dest_y, NULL, &mapElement); - if (dest_x == 0x8000)return; + if (dest_x == (sint16)0x8000)return; // Set the coordinate of destination to be exactly // in the middle of a tile. @@ -1172,7 +1172,7 @@ void window_staff_overview_tool_down(){ int dest_x, dest_y; footpath_get_coordinates_from_pos(x, y, &dest_x, &dest_y, NULL, NULL); - if (dest_x == 0x8000)return; + if (dest_x == (sint16)0x8000)return; game_do_command(dest_x, 1, dest_y, w->number, GAME_COMMAND_SET_STAFF_PATROL, 0, 0); } diff --git a/src/world/sprite.c b/src/world/sprite.c index 4be96b9837..1ad644cae1 100644 --- a/src/world/sprite.c +++ b/src/world/sprite.c @@ -808,14 +808,14 @@ void sprite_misc_update_all() */ void sprite_move(int x, int y, int z, rct_sprite* sprite){ int new_position = x; - if ((uint16)x == 0x8000)new_position = 0x10000; + if (x == (sint16)0x8000)new_position = 0x10000; else{ new_position &= 0x1FE0; new_position = (y >> 5) | (new_position << 3); } int current_position = sprite->unknown.x; - if ((uint16)sprite->unknown.x == 0x8000)current_position = 0x10000; + if (sprite->unknown.x == (sint16)0x8000)current_position = 0x10000; else{ current_position &= 0x1FE0; current_position = (sprite->unknown.y >> 5) | (current_position << 3); @@ -835,7 +835,7 @@ void sprite_move(int x, int y, int z, rct_sprite* sprite){ sprite->unknown.next_in_quadrant = temp_sprite_idx; } - if (x == 0x8000){ + if (x == (sint16)0x8000){ sprite->unknown.sprite_left = 0x8000; sprite->unknown.x = x; sprite->unknown.y = y;