From b374899bc8b3d6e2978a08c5fb1d6425bae2f7f8 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Jul 2015 16:13:04 +0100 Subject: [PATCH] Fix finance issues. Small refactor. Fixes #1524 --- src/addresses.h | 1 + src/peep/peep.c | 4 +- src/peep/staff.c | 4 +- src/ride/ride.c | 12 +-- src/ride/track.c | 10 +-- src/world/park.c | 190 +---------------------------------------------- 6 files changed, 17 insertions(+), 204 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 14958a4dc0..119b397e07 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -495,6 +495,7 @@ #define RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER 0x0141ED68 +// This value is always 4 times the actual type #define RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE 0x0141F56C #define RCT2_ADDRESS_WATER_RAISE_COST 0x0141F738 diff --git a/src/peep/peep.c b/src/peep/peep.c index 53f153475a..1c55217281 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1386,7 +1386,7 @@ static void peep_update_ride_sub_state_2_enter_ride(rct_peep* peep, rct_ride* ri else{ ride->total_profit += ride->price; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 20; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS * 4; peep_spend_money(peep, &peep->paid_on_rides, ride->price); } } @@ -5351,7 +5351,7 @@ static void peep_spend_money(rct_peep *peep, money16 *peep_expend_type, money32 window_invalidate_by_number(WC_PEEP, peep->sprite_index); RCT2_GLOBAL(0x00141F568, uint8) = RCT2_GLOBAL(0x0013CA740, uint8); - finance_payment(-amount, RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint32)); + finance_payment(-amount, RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) / 4); sound_play_panned(SOUND_PURCHASE, 0x8001, peep->x, peep->y, peep->z); } diff --git a/src/peep/staff.c b/src/peep/staff.c index 73d6c9708a..f35a93239b 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -263,7 +263,7 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, */ void game_command_set_staff_order(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) { - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 40; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_WAGES * 4; uint8 order_id = *ebx >> 8; uint16 sprite_id = *edx; if(*ebx & GAME_COMMAND_FLAG_APPLY){ @@ -335,7 +335,7 @@ void game_command_set_staff_patrol(int *eax, int *ebx, int *ecx, int *edx, int * */ void game_command_fire_staff_member(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) { - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 40; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_WAGES * 4; if(*ebx & GAME_COMMAND_FLAG_APPLY){ window_close_by_class(WC_FIRE_PROMPT); uint16 sprite_id = *edx; diff --git a/src/ride/ride.c b/src/ride/ride.c index f5021b106a..459be68b40 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -3461,7 +3461,7 @@ void ride_music_update_final() /* rct2: 0x006B5559 */ void game_command_set_ride_setting(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) { - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 4; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS * 4; uint8 ride_id = *edx & 0xFF; rct_ride* ride = GET_RIDE(ride_id); @@ -4321,7 +4321,7 @@ void game_command_set_ride_status(int *eax, int *ebx, int *ecx, int *edx, int *e rideIndex = *edx & 0xFF; targetStatus = (*edx >> 8) & 0xFF; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 4; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS * 4; ride = GET_RIDE(rideIndex); RCT2_GLOBAL(0x00F43484, uint32) = RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8), uint32); @@ -4665,11 +4665,11 @@ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi RCT2_GLOBAL(0x009DEA5E, uint16) = x; RCT2_GLOBAL(0x009DEA60, uint16) = y; RCT2_GLOBAL(0x009DEA62, uint16) = z; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; return; }else{ *ebx = 0; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; return; } } @@ -4758,7 +4758,7 @@ void game_command_set_ride_price(int *eax, int *ebx, int *ecx, int *edx, int *es //edx ride_number //ebp ride_type - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 0x14; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS * 4; if (flags & 0x1) { if (!secondary_price) { shop_item = 0x1F; @@ -5490,7 +5490,7 @@ void game_command_set_ride_vehicles(int *eax, int *ebx, int *ecx, int *edx, int ride = GET_RIDE(rideIndex); - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_PARK_ENTRANCE_TICKETS; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS * 4; if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) { RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id) = STR_HAS_BROKEN_DOWN_AND_REQUIRES_FIXING; diff --git a/src/ride/track.c b/src/ride/track.c index 3dd344b74b..770f5d0b47 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -3210,7 +3210,7 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int game_do_command_p(GAME_COMMAND_CREATE_RIDE, &_eax, &_ebx, &_ecx, &_edx, &_esi, &_edi, &_ebp); if (_ebx == MONEY32_UNDEFINED){ *ebx = MONEY32_UNDEFINED; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; RCT2_GLOBAL(0x00F44121, money32) = MONEY32_UNDEFINED; return; } @@ -3244,7 +3244,7 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, rideIndex, GAME_COMMAND_DEMOLISH_RIDE, 0, 0); *ebx = cost; RCT2_GLOBAL(0x00141E9AC, rct_string_id) = error_reason; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; RCT2_GLOBAL(0x00F44121, money32) = cost; return; } @@ -3311,7 +3311,7 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int ride_set_name(rideIndex, RCT2_ADDRESS(0x009E3504,const char)); - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; *ebx = RCT2_GLOBAL(0x00F44121, money32); *edi = rideIndex; } @@ -3453,7 +3453,7 @@ static money32 track_place(int rideIndex, int type, int originX, int originY, in rct_ride_type *rideEntry = GET_RIDE_ENTRY(ride->subtype); rct_map_element *mapElement; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; RCT2_GLOBAL(0x009DEA5E, uint16) = originX + 16; RCT2_GLOBAL(0x009DEA60, uint16) = originY + 16; RCT2_GLOBAL(0x009DEA62, uint16) = originZ; @@ -4215,7 +4215,7 @@ void game_command_set_brakes_speed(int *eax, int *ebx, int *ecx, int *edx, int * trackType = (*edx & 0xFF); brakesSpeed = ((*ebx >> 8) & 0xFF); - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION * 4; RCT2_GLOBAL(0x009DEA5E, uint8) = x + 16; RCT2_GLOBAL(0x009DEA60, uint8) = y + 16; RCT2_GLOBAL(0x009DEA62, uint8) = z; diff --git a/src/world/park.c b/src/world/park.c index 2a83928258..cdb174e8a6 100644 --- a/src/world/park.c +++ b/src/world/park.c @@ -891,7 +891,7 @@ void game_command_remove_park_entrance(int *eax, int *ebx, int *ecx, int *edx, i y = *ecx & 0xFFFF; z = *edx * 16; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint32) = RCT_EXPENDITURE_TYPE_LAND_PURCHASE * 4; + RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_LAND_PURCHASE * 4; RCT2_GLOBAL(0x009DEA5E, uint16) = x; RCT2_GLOBAL(0x009DEA60, uint16) = y; RCT2_GLOBAL(0x009DEA62, uint16) = z; @@ -1219,194 +1219,6 @@ void game_command_buy_land_rights(int *eax, int *ebx, int *ecx, int *edx, int *e (*edx & 0xFF00) >> 8, *ebx & 0xFF ); - // Original decompiled function for Duncan to look at: - - /*RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_LAND_PURCHASE * 4; - int x = *eax; - int y = *ecx; - int y2 = *ecx; - int z = map_element_height(x + 16, y + 16); - - RCT2_GLOBAL(0x009DEA5E, uint16) = x + 16; - RCT2_GLOBAL(0x009DEA60, uint16) = y + 16; - RCT2_GLOBAL(0x009DEA62, uint16) = z; - - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; - if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) != 0 || RCT2_GLOBAL(RCT2_ADDRESS_GAME_PAUSED, uint8) == 0) { - - int tile_idx = (((y & 0xFFE0) * 256) + (x & 0xFFE0)) / 32; - while ((TILE_MAP_ELEMENT_POINTER(tile_idx)->type & 0x3C) != 0) { - y += 8; - tile_idx = (((y & 0xFFE0) * 256) + (x & 0xFFE0)) / 32; - } - uint8 ownership = TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership; - uint8 flags = (*edx & 0xFF00) >> 8; - switch (flags) { - case 0: - if ((ownership & OWNERSHIP_OWNED) != 0) { // If the land is already owned - *ebx = 0; - return; - } - else if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) != 0 || (ownership & OWNERSHIP_AVAILABLE) == 0) { - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 1726; // Land not for sale! - *ebx = 0x80000000; - return; - } - else { - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_OWNED; - update_park_fences(x, y2); - update_park_fences(x - 32, y2); - update_park_fences(x + 32, y2); - update_park_fences(x, y2 + 32); - update_park_fences(x, y2 - 32); - } - *ebx = RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, uint16); - return; - } - break; - case 1: - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership &= 0xCF; - update_park_fences(x, y2); - update_park_fences(x - 32, y2); - update_park_fences(x + 32, y2); - update_park_fences(x, y2 + 32); - update_park_fences(x, y2 - 32); - } - *ebx = 0; - break; - case 2: - if ((ownership & (OWNERSHIP_OWNED | OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)) != 0) { // If the land or construction rights are already owned - *ebx = 0; - return; - } - else if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) != 0 || (ownership & OWNERSHIP_CONSTRUCTION_RIGHTS_AVAILABLE) == 0) { - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 1727; // Construction rights not for sale! - *ebx = 0x80000000; - return; - } - else { - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED; - uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; - baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y2, baseHeight, baseHeight + 16); - } - *ebx = RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, uint16); - return; - } - break; - case 3: - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership &= 0xEF; - uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; - baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y2, baseHeight, baseHeight + 16); - } - *ebx = 0; - break; - break; - case 4: - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_AVAILABLE; - uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; - baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y2, baseHeight, baseHeight + 16); - } - *ebx = 0; - break; - case 5: - if ((*ebx & 1) != 0) { - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_CONSTRUCTION_RIGHTS_AVAILABLE; - uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; - baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y2, baseHeight, baseHeight + 16); - } - *ebx = 0; - break; - default: - if (x <= 32) { - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 3215; - *ebx = 0x80000000; - return; - } - else if (y <= 32) { - *ebp = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16); - *ebp -= 32; - if (x >= *ebp || y >= *ebp) { - RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, uint16) = 3215; - *ebx = 0x80000000; - return; - } - else { - int tile_idx2 = (((y & 0xFFE0) * 256) + (x & 0xFFE0)) / 32; - ownership = TILE_MAP_ELEMENT_POINTER(tile_idx2)->properties.surface.ownership; - do { - y += 8; - tile_idx2 = (((y & 0xFFE0) * 256) + (x & 0xFFE0)) / 32; - if ((TILE_MAP_ELEMENT_POINTER(tile_idx2)->type & 0x3C) == 0x10) { - *ebx = 0; - return; - } - - } while ((TILE_MAP_ELEMENT_POINTER(((((y - 8) & 0xFFE0) * 256) + (x & 0xFFE0)) / 32)->flags & 0x80) == 0); - - uint8 bh = (*ebx & 0xFF00) >> 4; - if (bh == (TILE_MAP_ELEMENT_POINTER(tile_idx2)->properties.surface.ownership & 0xF0)) { - *ebx = 0; - return; - } - else { - if ((*ebx & 1) == 0) { - *ebx = RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, uint16); - return; - } - if ((bh & 0xF0) == 0) { - uint16 bp = RCT2_GLOBAL(RCT2_ADDRESS_PEEP_SPAWNS, uint16); - if (x != (bp & 0xFFE0)) { - bp = RCT2_GLOBAL(RCT2_ADDRESS_PEEP_SPAWNS + 2, uint16); - if (y2 != (bp & 0xFFE0)) { - RCT2_GLOBAL(RCT2_ADDRESS_PEEP_SPAWNS, uint16) = 0xFFFF; - } - } - bp = RCT2_GLOBAL(0x13573F8, uint16); - if (x != (bp & 0xFFE0)) { - bp = RCT2_GLOBAL(0x13573F8 + 2, uint16); - if (y2 != (bp & 0xFFE0)) { - RCT2_GLOBAL(0x13573F8, uint16) = 0xFFFF; - } - } - } - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership &= 0x0F; - TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= bh; - update_park_fences(x, y2); - update_park_fences(x - 32, y2); - update_park_fences(x + 32, y2); - update_park_fences(x, y2 + 32); - update_park_fences(x, y2 - 32); - RCT2_GLOBAL(0x9E2E28, uint8) |= 1; - - *ebx = 0; - return; - } - } - } - break; - } - } - else { - // Should this ever be called? esi is never set properly - if ((*ebx & 1) != 0) { - //TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_OWNED; - update_park_fences(x, y); - update_park_fences(x - 32, y2); - update_park_fences(x + 32, y2); - update_park_fences(x, y2 + 32); - update_park_fences(x, y2 - 32); - } - *ebx = RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, uint16); - }*/ }