1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

implement banner_get_closest_ride_index

This commit is contained in:
IntelOrca
2015-07-11 20:24:27 +01:00
parent 9dca351e8d
commit 9e9eb6a833
4 changed files with 96 additions and 16 deletions

View File

@@ -337,10 +337,11 @@ static void window_sign_textinput(rct_window *w, int widgetIndex, char *text)
}
}
else{
int eax = x, ebx = 0, ecx = y, edx = 16, ebp = 0, edi = 0, esi = 0;
RCT2_CALLFUNC_X(0x6B7D86, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp);
if ((eax & 0xFF) == 0xFF)return;
banner->colour = eax & 0xFF;
int rideIndex = banner_get_closest_ride_index(x, y, 16);
if (rideIndex == -1)
return;
banner->colour = rideIndex;
banner->flags |= BANNER_FLAG_2;
rct_string_id prev_string_id = banner->string_idx;

View File

@@ -21,6 +21,7 @@
#include "../addresses.h"
#include "../game.h"
#include "../localisation/localisation.h"
#include "../ride/ride.h"
#include "banner.h"
#include "map.h"
@@ -82,3 +83,83 @@ rct_map_element *banner_get_map_element(int bannerIndex)
} while (!map_element_is_last_for_tile(mapElement++));
return NULL;
}
/**
*
* rct2: 0x006B7EAB
*/
static int banner_get_ride_index_at(int x, int y, int z)
{
rct_map_element *mapElement;
rct_ride *ride;
int rideIndex, resultRideIndex;
resultRideIndex = -1;
mapElement = map_get_first_element_at(x >> 5, y >> 5);
do {
if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK)
continue;
rideIndex = mapElement->properties.track.ride_index;
ride = GET_RIDE(rideIndex);
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP))
continue;
if ((mapElement->clearance_height * 8) + 32 <= z)
continue;
resultRideIndex = rideIndex;
} while (!map_element_is_last_for_tile(mapElement++));
return resultRideIndex;
}
/**
*
* rct2: 0x006B7D86
*/
int banner_get_closest_ride_index(int x, int y, int z)
{
int i, rideIndex;
rct_ride *ride;
static const rct_xy16 NeighbourCheckOrder[] = {
{ 32, 0 },
{ -32, 0 },
{ 0, 32 },
{ 0, -32 },
{ -32, +32 },
{ +32, -32 },
{ +32, +32 },
{ -32, +32 },
{ 0, 0 }
};
for (i = 0; i < countof(NeighbourCheckOrder); i++) {
rideIndex = banner_get_ride_index_at(x + NeighbourCheckOrder[i].x, y + NeighbourCheckOrder[i].y, z);
if (rideIndex != -1) {
return rideIndex;
}
}
rideIndex = -1;
int resultDistance = INT_MAX;
FOR_ALL_RIDES(i, ride) {
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP))
continue;
uint16 xy = ride->overall_view;
if (xy == 0xFFFF)
continue;
int rideX = (xy & 0xFF) * 32;
int rideY = (xy >> 8) * 32;
int distance = abs(x - rideX) + abs(y - rideY);
if (distance < resultDistance) {
resultDistance = distance;
rideIndex = i;
}
}
return rideIndex;
}

View File

@@ -48,5 +48,6 @@ extern rct_banner *gBanners;
void banner_init();
int create_new_banner(uint8 flags);
rct_map_element *banner_get_map_element(int bannerIndex);
int banner_get_closest_ride_index(int x, int y, int z);
#endif

View File

@@ -2411,12 +2411,9 @@ void game_command_place_fence(int* eax, int* ebx, int* ecx, int* edx, int* esi,
banner->x = position.x / 32;
banner->y = position.y / 32;
*eax = position.x;
*ecx = position.y;
*edx = position.z;
RCT2_CALLFUNC_X(0x6B7D86, eax, ebx, ecx, edx, esi, edi, ebp);
if ((*eax & 0xFF) != 0xFF){
banner->colour = *eax & 0xFF;
int rideIndex = banner_get_closest_ride_index(position.x, position.y, position.z);
if (rideIndex != -1) {
banner->colour = rideIndex & 0xFF;
banner->flags |= BANNER_FLAG_2;
}
}
@@ -2516,20 +2513,20 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in
rct_scenery_entry* scenery_entry = RCT2_ADDRESS(RCT2_ADDRESS_LARGE_SCENERY_ENTRIES, rct_scenery_entry*)[entry_index];
if(scenery_entry->large_scenery.var_11 != 0xFF){
banner_id = create_new_banner(flags);
if(banner_id == MAX_BANNERS){
if (banner_id == MAX_BANNERS) {
*ebx = MONEY32_UNDEFINED;
return;
}
if(flags & GAME_COMMAND_FLAG_APPLY){
if (flags & GAME_COMMAND_FLAG_APPLY) {
rct_banner* banner = &gBanners[banner_id];
banner->flags |= BANNER_FLAG_1;
banner->type = 0;
banner->x = x / 32;
banner->y = y / 32;
int eax2 = x, ebx2 = *ebx, ecx2 = y, edx2 = z, esi2 = *esi, edi2 = *edi, ebp2 = *ebp;
RCT2_CALLFUNC_X(0x006B7D86, &eax2, &ebx2, &ecx2, &edx2, &esi2, &edi2, &ebp2);
if((uint8)eax2 != 0xFF){
banner->colour = eax2;
int rideIndex = banner_get_closest_ride_index(x, y, z);
if (rideIndex != -1) {
banner->colour = rideIndex;
banner->flags |= BANNER_FLAG_2;
}
}