diff --git a/src/ride/ride.c b/src/ride/ride.c index dd9409030a..004fd956ad 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -45,6 +45,7 @@ #include "../world/map.h" #include "../world/map_animation.h" #include "../world/sprite.h" +#include "../world/scenery.h" #include "cable_lift.h" #include "ride.h" #include "ride_data.h" @@ -7663,13 +7664,8 @@ money32 place_ride_entrance_or_exit(sint16 x, sint16 y, sint16 z, uint8 directio } sint16 clear_z = z / 8 + (is_exit ? 5 : 7); - RCT2_GLOBAL(0x009E32C4, sint16) = x; - RCT2_GLOBAL(0x009E32C6, sint16) = y; - - // Horrible hack until map_can_construct_with_clear_at is implemented. - RCT2_GLOBAL(0x009E32C8, uint8*) = (&flags) - 4; - - if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z / 8, clear_z, (void*)0x0066637E, 0xF)) { + + if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z / 8, clear_z, &map_place_non_scenery_clear_func, 0xF, flags, RCT2_ADDRESS(0x009E32B8, money32))) { return MONEY32_UNDEFINED; } @@ -7766,13 +7762,8 @@ money32 place_ride_entrance_or_exit(sint16 x, sint16 y, sint16 z, uint8 directio } sint8 clear_z = (z / 8) + (is_exit ? 5 : 7); - RCT2_GLOBAL(0x009E32C4, sint16) = x; - RCT2_GLOBAL(0x009E32C6, sint16) = y; - // Horrible hack until map_can_construct_with_clear_at is implemented. - RCT2_GLOBAL(0x009E32C8, uint8*) = (&flags) - 4; - - if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z / 8, clear_z, (void*)0x0066637E, 0xF)) { + if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z / 8, clear_z, &map_place_non_scenery_clear_func, 0xF, flags, RCT2_ADDRESS(0x009E32B8, money32))) { return MONEY32_UNDEFINED; } diff --git a/src/ride/track.c b/src/ride/track.c index 8b9f4aa638..c2d09ed5a5 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -3401,7 +3401,6 @@ money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, sint16 RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, sint16) = x + 8; RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, sint16) = y + 8; RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, sint16) = z; - RCT2_GLOBAL(0x00F4413E, uint32) = 0; if (!sub_68B044()) { return MONEY32_UNDEFINED; } @@ -3444,6 +3443,7 @@ money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, sint16 } } + money32 cost = 0; // Clearance checks if (!gCheatsDisableClearanceChecks) { int fx = floor2(x, 32); @@ -3451,14 +3451,7 @@ money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, sint16 int fz0 = z >> 3; int fz1 = fz0 + 4; - uint8 stack_F4412F[13]; - stack_F4412F[0x0C] = flags; - - RCT2_GLOBAL(0x00F4412B, uint16) = fx; - RCT2_GLOBAL(0x00F4412D, uint16) = fy; - RCT2_GLOBAL(0x00F4412F, uint8*) = stack_F4412F; - RCT2_GLOBAL(0x00F4413E, money32) = 0; - if (!map_can_construct_with_clear_at(fx, fy, fz0, fz1, (void*)0x006CDE57, 15)) { + if (!map_can_construct_with_clear_at(fx, fy, fz0, fz1, &map_place_non_scenery_clear_func, 15, flags, &cost)) { return MONEY32_UNDEFINED; } @@ -3482,6 +3475,8 @@ money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, sint16 price = (price >> 17) * 10; } + cost += price; + if (flags & GAME_COMMAND_FLAG_APPLY) { if (RCT2_GLOBAL(0x009A8C28, uint8) == 1 && !(flags & GAME_COMMAND_FLAG_GHOST)) { rct_xyz16 coord; @@ -3515,7 +3510,7 @@ money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, sint16 } } - return price; + return cost; } /** @@ -4288,23 +4283,10 @@ static money32 track_place(int rideIndex, int type, int originX, int originY, in _currentTrackEndX = x; _currentTrackEndY = y; - // Until 0x006C5A5F is implemented use this hacky struct. - struct{ - money32 cost; //0 - uint8 pad[0x10];//4 - uint8 flags;//14 - } clearance_struct; - clearance_struct.cost = cost; - clearance_struct.flags = flags; - - RCT2_GLOBAL(0x00F44060, void*) = &clearance_struct; - if (!gCheatsDisableClearanceChecks || flags & GAME_COMMAND_FLAG_GHOST){ - if (!map_can_construct_with_clear_at(x, y, baseZ, clearanceZ, (void*)0x006C5A5F, bl)) + if (!map_can_construct_with_clear_at(x, y, baseZ, clearanceZ, &map_place_non_scenery_clear_func, bl, flags, &cost)) return MONEY32_UNDEFINED; } - // Again when 0x006C5A5F implemented remove this. - cost = clearance_struct.cost; //6c53dc // push baseZ and clearanceZ diff --git a/src/world/footpath.c b/src/world/footpath.c index 0d5301738f..ef3ce37feb 100644 --- a/src/world/footpath.c +++ b/src/world/footpath.c @@ -158,14 +158,7 @@ static money32 footpath_element_insert(int type, int x, int y, int z, int slope, zHigh += 2; } - RCT2_GLOBAL(0x00F3EF84, uint16) = x; - RCT2_GLOBAL(0x00F3EF86, uint16) = y; - - // Ugh, hack until 0x006A6733 is written - // 0x006A6733 expects the flags to be at (*0xF3EF7C) + 8 - RCT2_GLOBAL(0x00F3EF7C, uint32) = (uint32)(&flags - 2); - - if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z, zHigh, (void*)0x006A6733, bl)) + if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z, zHigh, &map_place_non_scenery_clear_func, bl, flags, RCT2_ADDRESS(0x00F3EFD9, money32))) return MONEY32_UNDEFINED; RCT2_GLOBAL(0x00F3EFA4, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_ELEMENT_LOCATION_COMPARED_TO_GROUND_AND_WATER, uint8); @@ -493,14 +486,7 @@ static money32 footpath_place_from_track(int type, int x, int y, int z, int slop zHigh += 2; } - RCT2_GLOBAL(0x00F3EF84, uint16) = x; - RCT2_GLOBAL(0x00F3EF86, uint16) = y; - - // Ugh, hack until 0x006A6733 is written - // 0x006A6733 expects the flags to be at (*0xF3EF7C) + 8 - RCT2_GLOBAL(0x00F3EF7C, uint32) = (uint32)(&flags - 2); - - if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z, zHigh, (void*)0x006A6733, bl)) + if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(x, y, z, zHigh, &map_place_non_scenery_clear_func, bl, flags, RCT2_ADDRESS(0x00F3EFD9, money32))) return MONEY32_UNDEFINED; RCT2_GLOBAL(0x00F3EFA4, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_ELEMENT_LOCATION_COMPARED_TO_GROUND_AND_WATER, uint8); diff --git a/src/world/map.c b/src/world/map.c index 3f10eebcfb..49873a0e84 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -1582,6 +1582,20 @@ const uint8 map_element_lower_styles[5][32] = { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x0D, 0x0E, 0x00 }, }; +/** + * + * rct2: 0x00663CB9 + */ +int map_set_land_height_clear_func(rct_map_element** map_element, int x, int y, uint8 flags, money32* price) { + if (map_element_get_type(*map_element) == MAP_ELEMENT_TYPE_SURFACE) + return 0; + + if (map_element_get_type(*map_element) == MAP_ELEMENT_TYPE_SCENERY) + return 0; + + return 1; +} + static money32 map_set_land_height(int flags, int x, int y, int height, int style, int selectionType) { if (RCT2_GLOBAL(RCT2_ADDRESS_GAME_PAUSED, uint8) != 0 && !gCheatsBuildInPauseMode) { @@ -1722,7 +1736,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl } } - if(map_can_construct_with_clear_at(x, y, height, zCorner, RCT2_ADDRESS(0x663CB9, void), 0xF) == false) + if(map_can_construct_with_clear_at(x, y, height, zCorner, &map_set_land_height_clear_func, 0xF, 0, NULL) == false) return MONEY32_UNDEFINED; mapElement = map_get_first_element_at(x / 32, y / 32); @@ -2772,6 +2786,73 @@ void game_command_place_banner(int* eax, int* ebx, int* ecx, int* edx, int* esi, *ebx = MONEY32_UNDEFINED; } +/** + * + * rct2: 0x006E0D6E, 0x006B8D88 + */ +int map_place_scenery_clear_func(rct_map_element** map_element, int x, int y, uint8 flags, money32* price) { + if (map_element_get_type(*map_element) != MAP_ELEMENT_TYPE_SCENERY) + return 1; + + if (!(flags & GAME_COMMAND_FLAG_7)) + return 1; + + rct_scenery_entry* scenery = g_smallSceneryEntries[(*map_element)->properties.scenery.type]; + + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_TREE_REMOVAL) { + if (scenery->small_scenery.height > 64) + return 1; + } + + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) + *price += scenery->small_scenery.removal_price * 10; + + if (flags & GAME_COMMAND_FLAG_GHOST) + return 0; + + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + return 0; + + map_invalidate_tile(x, y, (*map_element)->base_height * 8, (*map_element)->clearance_height * 8); + + map_element_remove(*map_element); + + (*map_element)--; + return 0; +} + +/** + * + * rct2: 0x006C5A4F, 0x006CDE57, 0x006A6733, 0x0066637E + */ +int map_place_non_scenery_clear_func(rct_map_element** map_element, int x, int y, uint8 flags, money32* price) { + if (map_element_get_type(*map_element) != MAP_ELEMENT_TYPE_SCENERY) + return 1; + + rct_scenery_entry* scenery = g_smallSceneryEntries[(*map_element)->properties.scenery.type]; + + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_TREE_REMOVAL) { + if (scenery->small_scenery.height > 64) + return 1; + } + + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) + *price += scenery->small_scenery.removal_price * 10; + + if (flags & GAME_COMMAND_FLAG_GHOST) + return 0; + + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + return 0; + + map_invalidate_tile(x, y, (*map_element)->base_height * 8, (*map_element)->clearance_height * 8); + + map_element_remove(*map_element); + + (*map_element)--; + return 0; +} + /** * * rct2: 0x006E08F4 @@ -2785,8 +2866,10 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi uint8 rotation = *edi; int z = *ebp; uint8 scenery_type = *ebx >> 8; + uint8 flags = *ebx & 0xFF; uint8 quadrant = *edx; uint8 color1 = *edx >> 8; + RCT2_GLOBAL(0x00F64F26, money32) = 0; int F64F1D = 0; int F64EC8 = z; int base_height = map_element_height(x, y); @@ -2834,7 +2917,7 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi *ebx = MONEY32_UNDEFINED; return; } - if(*ebx & GAME_COMMAND_FLAG_APPLY && !(*ebx & 0x40)){ + if(flags & GAME_COMMAND_FLAG_APPLY && !(flags & 0x40)){ footpath_remove_litter(x, y, F64EC8); if(!gCheatsDisableClearanceChecks && (scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_ALLOW_WALLS)) { map_remove_walls_at(x, y, F64EC8, F64EC8 + scenery_entry->small_scenery.height); @@ -2905,21 +2988,19 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi if(z == 0){ bl |= 0xF0; } - RCT2_GLOBAL(0x00F64F22, uint16) = x; - RCT2_GLOBAL(0x00F64F24, uint16) = y; - RCT2_GLOBAL(0x00F64F1E, uint32) = (uint32)(ebx - 1); //0x006E0D6E uses [F64F1E+4] to read ebx value - if(gCheatsDisableClearanceChecks || map_can_construct_with_clear_at(x, y, zLow, zHigh, (void*)0x006E0D6E, bl)){ + + if(gCheatsDisableClearanceChecks || map_can_construct_with_clear_at(x, y, zLow, zHigh, &map_place_scenery_clear_func, bl, flags, RCT2_ADDRESS(0x00F64F26, money32))){ RCT2_GLOBAL(0x00F64F14, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_ELEMENT_LOCATION_COMPARED_TO_GROUND_AND_WATER, uint8) & 0x3; - if(*ebx & GAME_COMMAND_FLAG_APPLY){ - if (RCT2_GLOBAL(0x009A8C28, uint8) == 1 && !(*ebx & GAME_COMMAND_FLAG_GHOST)) { + if(flags & GAME_COMMAND_FLAG_APPLY){ + if (RCT2_GLOBAL(0x009A8C28, uint8) == 1 && !(flags & GAME_COMMAND_FLAG_GHOST)) { rct_xyz16 coord; coord.x = x + 16; coord.y = y + 16; coord.z = map_element_height(coord.x, coord.y); network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); } - int flags = (bl & 0xf); - rct_map_element* new_map_element = map_element_insert(x / 32, y / 32, zLow, flags); + int collisionQuadrants = (bl & 0xf); + rct_map_element* new_map_element = map_element_insert(x / 32, y / 32, zLow, collisionQuadrants); RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_MAP_ELEMENT, rct_map_element*) = new_map_element; uint8 type = quadrant << 6; type |= MAP_ELEMENT_TYPE_SCENERY; @@ -2933,7 +3014,7 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi if(z != 0){ new_map_element->properties.scenery.colour_1 |= 0x20; } - if(*ebx & 0x40){ + if(flags & 0x40){ new_map_element->flags |= 0x10; } map_invalidate_tile_full(x, y); @@ -2941,7 +3022,7 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi map_animation_create(2, x, y, new_map_element->base_height); } } - *ebx = (scenery_entry->small_scenery.price * 10); + *ebx = (scenery_entry->small_scenery.price * 10) + RCT2_GLOBAL(0x00F64F26, money32); if(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY){ *ebx = 0; } @@ -3555,7 +3636,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in RCT2_GLOBAL(0x00F43892, sint16) = curTile.x; RCT2_GLOBAL(0x00F43894, sint16) = curTile.y; RCT2_GLOBAL(0x00F43896, uint32) = (uint32)(ebx - 3); // this is how ebx flags var is passed to 0x006B8D88 - if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(curTile.x, curTile.y, zLow, zHigh, (void*)0x006B8D88, bl)) { + if (!gCheatsDisableClearanceChecks && !map_can_construct_with_clear_at(curTile.x, curTile.y, zLow, zHigh, &map_place_scenery_clear_func, bl, flags, RCT2_ADDRESS(0x00F4389A, money32))) { *ebx = MONEY32_UNDEFINED; return; } @@ -3961,9 +4042,8 @@ static void map_obstruction_set_error_text(rct_map_element *mapElement) * ebp = clearFunc * bl = bl */ -int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *clearFunc, uint8 bl) +int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, CLEAR_FUNC *clearFunc, uint8 bl, uint8 flags, money32 *price) { - RCT2_GLOBAL(0x00F1AD40, void*) = clearFunc; RCT2_GLOBAL(RCT2_ADDRESS_ELEMENT_LOCATION_COMPARED_TO_GROUND_AND_WATER, uint8) = 1; if (x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) || x < 32 || y < 32) { RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id) = STR_OFF_EDGE_OF_MAP; @@ -4035,9 +4115,9 @@ int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *cle continue; } loc_68BABC: - if (RCT2_GLOBAL(0x00F1AD40, void*) != (void*)0xFFFFFFFF) { + if (clearFunc != NULL) { int zero = 0; - if (!(RCT2_CALLFUNC_X((int)RCT2_GLOBAL(0x00F1AD40, void*), &zero, &zero, &zero, &zero, (int*)&map_element, &zero, &zero) & 0x100)) { + if (!clearFunc(&map_element, x, y, flags, price)) { continue; } } @@ -4046,9 +4126,9 @@ int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *cle } return false; loc_68BAE6: - if (RCT2_GLOBAL(0x00F1AD40, void*) != (void*)0xFFFFFFFF) { + if (clearFunc != NULL) { int zero = 0; - if (!(RCT2_CALLFUNC_X((int)RCT2_GLOBAL(0x00F1AD40, void*), &zero, &zero, &zero, &zero, (int*)&map_element, &zero, &zero) & 0x100)) { + if (!clearFunc(&map_element, x, y, flags, price)) { goto loc_68B9B7; } } @@ -4068,7 +4148,7 @@ int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *cle */ int map_can_construct_at(int x, int y, int zLow, int zHigh, uint8 bl) { - return map_can_construct_with_clear_at(x, y, zLow, zHigh, (void*)0xFFFFFFFF, bl); + return map_can_construct_with_clear_at(x, y, zLow, zHigh, NULL, bl, 0, NULL); } /** diff --git a/src/world/map.h b/src/world/map.h index c1ce1865e5..1a169ced67 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -311,7 +311,10 @@ void map_invalidate_selection_rect(); void map_reorganise_elements(); int sub_68B044(); rct_map_element *map_element_insert(int x, int y, int z, int flags); -int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *clearFunc, uint8 bl); + +typedef int (CLEAR_FUNC)(rct_map_element** map_element, int x, int y, uint8 flags, money32* price); +int map_place_non_scenery_clear_func(rct_map_element** map_element, int x, int y, uint8 flags, money32* price); +int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, CLEAR_FUNC *clearFunc, uint8 bl, uint8 flags, money32 *price); int map_can_construct_at(int x, int y, int zLow, int zHigh, uint8 bl); void rotate_map_coordinates(sint16 *x, sint16 *y, int rotation); rct_xy16 coordinate_3d_to_2d(const rct_xyz16* coordinate_3d, int rotation);