mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 13:33:02 +01:00
Use CoordsXY(Z) in more places
This commit is contained in:
@@ -174,10 +174,9 @@ rct_window* window_banner_open(rct_windownumber number)
|
||||
static void window_banner_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
{
|
||||
auto banner = GetBanner(w->number);
|
||||
int32_t x = banner->position.x << 5;
|
||||
int32_t y = banner->position.y << 5;
|
||||
auto bannerPos = banner->position.ToCoordsXY();
|
||||
|
||||
TileElement* tile_element = map_get_first_element_at({ x, y });
|
||||
TileElement* tile_element = map_get_first_element_at(bannerPos);
|
||||
if (tile_element == nullptr)
|
||||
return;
|
||||
|
||||
@@ -196,7 +195,7 @@ static void window_banner_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
case WIDX_BANNER_DEMOLISH:
|
||||
{
|
||||
auto bannerRemoveAction = BannerRemoveAction(
|
||||
{ x, y, tile_element->GetBaseZ(), tile_element->AsBanner()->GetPosition() });
|
||||
{ bannerPos, tile_element->GetBaseZ(), tile_element->AsBanner()->GetPosition() });
|
||||
GameActions::Execute(&bannerRemoveAction);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -127,10 +127,9 @@ rct_window* window_ride_demolish_prompt_open(Ride* ride)
|
||||
w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT);
|
||||
if (w != nullptr)
|
||||
{
|
||||
int x = w->x;
|
||||
int y = w->y;
|
||||
auto windowPos = ScreenCoordsXY{ w->x, w->y };
|
||||
window_close(w);
|
||||
w = window_create(ScreenCoordsXY(x, y), WW, WH, &window_ride_demolish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT);
|
||||
w = window_create(windowPos, WW, WH, &window_ride_demolish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -153,10 +152,9 @@ rct_window* window_ride_refurbish_prompt_open(Ride* ride)
|
||||
w = window_find_by_class(WC_DEMOLISH_RIDE_PROMPT);
|
||||
if (w != nullptr)
|
||||
{
|
||||
int x = w->x;
|
||||
int y = w->y;
|
||||
auto windowPos = ScreenCoordsXY{ w->x, w->y };
|
||||
window_close(w);
|
||||
w = window_create(ScreenCoordsXY(x, y), WW, WH, &window_ride_refurbish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT);
|
||||
w = window_create(windowPos, WW, WH, &window_ride_refurbish_events, WC_DEMOLISH_RIDE_PROMPT, WF_TRANSPARENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1057,26 +1057,24 @@ static void footpath_remove_tile_element(TileElement* tileElement)
|
||||
static TileElement* footpath_get_tile_element_to_remove()
|
||||
{
|
||||
TileElement* tileElement;
|
||||
int32_t x, y, z, zLow;
|
||||
int32_t z, zLow;
|
||||
|
||||
x = gFootpathConstructFromPosition.x / 32;
|
||||
y = gFootpathConstructFromPosition.y / 32;
|
||||
if (x >= 256 || y >= 256)
|
||||
if (!map_is_location_valid(gFootpathConstructFromPosition))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
z = (gFootpathConstructFromPosition.z >> 3) & 0xFF;
|
||||
zLow = z - 2;
|
||||
z = std::min(255 * COORDS_Z_STEP, gFootpathConstructFromPosition.z);
|
||||
zLow = z - (2 * COORDS_Z_STEP);
|
||||
|
||||
tileElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY());
|
||||
tileElement = map_get_first_element_at(gFootpathConstructFromPosition);
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
|
||||
{
|
||||
if (tileElement->base_height == z)
|
||||
if (tileElement->GetBaseZ() == z)
|
||||
{
|
||||
if (tileElement->AsPath()->IsSloped())
|
||||
{
|
||||
@@ -1088,7 +1086,7 @@ static TileElement* footpath_get_tile_element_to_remove()
|
||||
|
||||
return tileElement;
|
||||
}
|
||||
else if (tileElement->base_height == zLow)
|
||||
else if (tileElement->GetBaseZ() == zLow)
|
||||
{
|
||||
if (!tileElement->AsPath()->IsSloped())
|
||||
{
|
||||
|
||||
@@ -192,17 +192,15 @@ static void window_game_bottom_toolbar_mouseup(rct_window* w, rct_widgetindex wi
|
||||
|
||||
{
|
||||
newsItem = news_item_get(0);
|
||||
int32_t x, y, z;
|
||||
int32_t subject = newsItem->Assoc;
|
||||
|
||||
news_item_get_subject_location(newsItem->Type, subject, &x, &y, &z);
|
||||
auto subjectLoc = news_item_get_subject_location(newsItem->Type, newsItem->Assoc);
|
||||
|
||||
if (x == LOCATION_NULL)
|
||||
if (subjectLoc == std::nullopt)
|
||||
break;
|
||||
|
||||
rct_window* mainWindow = window_get_main();
|
||||
if (mainWindow != nullptr)
|
||||
window_scroll_to_location(mainWindow, x, y, z);
|
||||
window_scroll_to_location(mainWindow, subjectLoc->x, subjectLoc->y, subjectLoc->z);
|
||||
}
|
||||
break;
|
||||
case WIDX_RIGHT_OUTSET:
|
||||
@@ -333,11 +331,9 @@ static void window_game_bottom_toolbar_invalidate(rct_window* w)
|
||||
w->disabled_widgets &= ~(1 << WIDX_NEWS_LOCATE);
|
||||
|
||||
// Find out if the news item is no longer valid
|
||||
int32_t y, z;
|
||||
int32_t subject = newsItem->Assoc;
|
||||
news_item_get_subject_location(newsItem->Type, subject, &x, &y, &z);
|
||||
auto subjectLoc = news_item_get_subject_location(newsItem->Type, newsItem->Assoc);
|
||||
|
||||
if (x == LOCATION_NULL)
|
||||
if (subjectLoc == std::nullopt)
|
||||
w->disabled_widgets |= (1 << WIDX_NEWS_LOCATE);
|
||||
|
||||
if (!(news_type_properties[newsItem->Type] & NEWS_TYPE_HAS_SUBJECT))
|
||||
|
||||
@@ -136,7 +136,7 @@ static void window_news_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
*/
|
||||
static void window_news_update(rct_window* w)
|
||||
{
|
||||
int32_t i, j, x, y, z;
|
||||
int32_t i, j;
|
||||
|
||||
if (w->news.var_480 == -1 || --w->news.var_484 != 0)
|
||||
{
|
||||
@@ -165,10 +165,10 @@ static void window_news_update(rct_window* w)
|
||||
}
|
||||
else if (w->news.var_482 > 1)
|
||||
{
|
||||
news_item_get_subject_location(newsItem->Type, newsItem->Assoc, &x, &y, &z);
|
||||
if (x != LOCATION_NULL && (w = window_get_main()) != nullptr)
|
||||
auto subjectLoc = news_item_get_subject_location(newsItem->Type, newsItem->Assoc);
|
||||
if (subjectLoc != std::nullopt && (w = window_get_main()) != nullptr)
|
||||
{
|
||||
window_scroll_to_location(w, x, y, z);
|
||||
window_scroll_to_location(w, subjectLoc->x, subjectLoc->y, subjectLoc->z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -207,73 +207,70 @@ static int32_t news_item_get_new_history_slot()
|
||||
*
|
||||
* rct2: 0x0066BA74
|
||||
*/
|
||||
void news_item_get_subject_location(int32_t type, int32_t subject, int32_t* x, int32_t* y, int32_t* z)
|
||||
std::optional<CoordsXYZ> news_item_get_subject_location(int32_t type, int32_t subject)
|
||||
{
|
||||
Ride* ride;
|
||||
Peep* peep;
|
||||
Vehicle* vehicle;
|
||||
std::optional<CoordsXYZ> subjectLoc{ std::nullopt };
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NEWS_ITEM_RIDE:
|
||||
ride = get_ride(subject);
|
||||
{
|
||||
Ride* ride = get_ride(subject);
|
||||
if (ride == nullptr || ride->overall_view.isNull())
|
||||
{
|
||||
*x = LOCATION_NULL;
|
||||
break;
|
||||
}
|
||||
*x = ride->overall_view.x + 16;
|
||||
*y = ride->overall_view.y + 16;
|
||||
*z = tile_element_height({ *x, *y });
|
||||
auto rideViewCentre = ride->overall_view.ToTileCentre();
|
||||
subjectLoc = CoordsXYZ{ rideViewCentre, tile_element_height(rideViewCentre) };
|
||||
break;
|
||||
}
|
||||
case NEWS_ITEM_PEEP_ON_RIDE:
|
||||
peep = GET_PEEP(subject);
|
||||
*x = peep->x;
|
||||
*y = peep->y;
|
||||
*z = peep->z;
|
||||
if (*x != LOCATION_NULL)
|
||||
{
|
||||
Peep* peep = GET_PEEP(subject);
|
||||
subjectLoc = CoordsXYZ{ peep->x, peep->y, peep->z };
|
||||
if (subjectLoc->x != LOCATION_NULL)
|
||||
break;
|
||||
|
||||
if (peep->state != 3 && peep->state != 7)
|
||||
{
|
||||
*x = LOCATION_NULL;
|
||||
subjectLoc = std::nullopt;
|
||||
break;
|
||||
}
|
||||
|
||||
// Find which ride peep is on
|
||||
ride = get_ride(peep->current_ride);
|
||||
Ride* ride = get_ride(peep->current_ride);
|
||||
if (ride == nullptr || !(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK))
|
||||
{
|
||||
*x = LOCATION_NULL;
|
||||
subjectLoc = std::nullopt;
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the first car of the train peep is on
|
||||
vehicle = &(get_sprite(ride->vehicles[peep->current_train])->vehicle);
|
||||
Vehicle* vehicle = GET_VEHICLE(ride->vehicles[peep->current_train]);
|
||||
// Find the actual car peep is on
|
||||
for (int32_t i = 0; i < peep->current_car; i++)
|
||||
{
|
||||
vehicle = &(get_sprite(vehicle->next_vehicle_on_train)->vehicle);
|
||||
vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train);
|
||||
}
|
||||
*x = vehicle->x;
|
||||
*y = vehicle->y;
|
||||
*z = vehicle->z;
|
||||
subjectLoc = CoordsXYZ{ vehicle->x, vehicle->y, vehicle->z };
|
||||
break;
|
||||
}
|
||||
case NEWS_ITEM_PEEP:
|
||||
peep = GET_PEEP(subject);
|
||||
*x = peep->x;
|
||||
*y = peep->y;
|
||||
*z = peep->z;
|
||||
{
|
||||
Peep* peep = GET_PEEP(subject);
|
||||
subjectLoc = CoordsXYZ{ peep->x, peep->y, peep->z };
|
||||
break;
|
||||
}
|
||||
case NEWS_ITEM_BLANK:
|
||||
*x = subject;
|
||||
*y = subject >> 16;
|
||||
*z = tile_element_height({ *x, *y });
|
||||
{
|
||||
auto subjectXY = CoordsXY{ subject & 0xFFFF, subject >> 16 };
|
||||
subjectLoc = CoordsXYZ{ subjectXY, tile_element_height(subjectXY) };
|
||||
break;
|
||||
}
|
||||
default:
|
||||
*x = LOCATION_NULL;
|
||||
break;
|
||||
}
|
||||
return subjectLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
#include "../world/Location.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -61,7 +64,7 @@ void news_item_init_queue();
|
||||
void news_item_update_current();
|
||||
void news_item_close_current();
|
||||
|
||||
void news_item_get_subject_location(int32_t type, int32_t subject, int32_t* x, int32_t* y, int32_t* z);
|
||||
std::optional<CoordsXYZ> news_item_get_subject_location(int32_t type, int32_t subject);
|
||||
|
||||
NewsItem* news_item_add_to_queue(uint8_t type, rct_string_id string_id, uint32_t assoc);
|
||||
NewsItem* news_item_add_to_queue_raw(uint8_t type, const utf8* text, uint32_t assoc);
|
||||
|
||||
Reference in New Issue
Block a user