Move Viewport functions into Ui (#22454)

* Move viewport functions into ui

* Move footpath function to ui

* Don't include viewport in footpath.h

* Include missing includes
This commit is contained in:
Duncan authored and GitHub committed 2024-08-02 06:01:31 +01:00
1 parent f109ed2bc0
commit a07b56a655
49 files changed
+1079 -965

No files matched your search

@@ -15,6 +15,7 @@
#include <openrct2/Diagnostic.h>
#include <openrct2/Game.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2/drawing/X8DrawingEngine.h>
+1
View File
@@ -8,6 +8,7 @@
*****************************************************************************/
#include "../UiStringIds.h"
#include "../interface/ViewportInteraction.h"
#include <cassert>
#include <cmath>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,21 @@
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include <openrct2/world/Location.hpp>
namespace OpenRCT2::Ui
{
bool ViewportInteractionLeftOver(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionRightOver(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords);
CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords);
} // namespace OpenRCT2::Ui
+178
View File
@@ -0,0 +1,178 @@
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "ViewportQuery.h"
#include "Viewport.h"
#include "Window.h"
#include <algorithm>
#include <openrct2/world/Map.h>
#include <openrct2/world/TileElement.h>
namespace OpenRCT2::Ui
{
/**
* Determines the location of the footpath at which we point with the cursor. If no footpath is underneath the cursor,
* then return the location of the ground tile. Besides the location it also computes the direction of the yellow arrow
* when we are going to build a footpath bridge/tunnel.
* rct2: 0x00689726
* In:
* screenX: eax
* screenY: ebx
* Out:
* x: ax
* y: bx
* direction: ecx
* tileElement: edx
*/
CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement)
{
WindowBase* window = WindowFindFromPoint(screenCoords);
if (window == nullptr || window->viewport == nullptr)
{
CoordsXY position{};
position.SetNull();
return position;
}
auto viewport = window->viewport;
auto info = GetMapCoordinatesFromPosWindow(window, screenCoords, EnumsToFlags(ViewportInteractionItem::Footpath));
if (info.SpriteType != ViewportInteractionItem::Footpath
|| !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL)))
{
info = GetMapCoordinatesFromPosWindow(
window, screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath));
if (info.SpriteType == ViewportInteractionItem::None)
{
auto position = info.Loc;
position.SetNull();
return position;
}
}
auto minPosition = info.Loc;
auto maxPosition = info.Loc + CoordsXY{ 31, 31 };
auto myTileElement = info.Element;
auto position = info.Loc.ToTileCentre();
auto z = 0;
if (info.SpriteType == ViewportInteractionItem::Footpath)
{
z = myTileElement->GetBaseZ();
if (myTileElement->AsPath()->IsSloped())
{
z += 8;
}
}
auto start_vp_pos = viewport->ScreenToViewportCoord(screenCoords);
for (int32_t i = 0; i < 5; i++)
{
if (info.SpriteType != ViewportInteractionItem::Footpath)
{
z = TileElementHeight(position);
}
position = ViewportPosToMapPos(start_vp_pos, z, viewport->rotation);
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
position.y = std::clamp(position.y, minPosition.y, maxPosition.y);
}
// Determine to which edge the cursor is closest
uint32_t myDirection;
int32_t mod_x = position.x & 0x1F, mod_y = position.y & 0x1F;
if (mod_x < mod_y)
{
if (mod_x + mod_y < 32)
{
myDirection = 0;
}
else
{
myDirection = 1;
}
}
else
{
if (mod_x + mod_y < 32)
{
myDirection = 3;
}
else
{
myDirection = 2;
}
}
position = position.ToTileStart();
if (direction != nullptr)
*direction = myDirection;
if (tileElement != nullptr)
*tileElement = myTileElement;
return position;
}
/**
*
* rct2: 0x0068A0C9
* screenX: eax
* screenY: ebx
* x: ax
* y: bx
* direction: cl
* tileElement: edx
*/
CoordsXY FootpathBridgeGetInfoFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement)
{
// First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit.
WindowBase* window = WindowFindFromPoint(screenCoords);
if (window == nullptr || window->viewport == nullptr)
{
CoordsXY ret{};
ret.SetNull();
return ret;
}
auto viewport = window->viewport;
auto info = GetMapCoordinatesFromPosWindow(window, screenCoords, EnumsToFlags(ViewportInteractionItem::Ride));
*tileElement = info.Element;
if (info.SpriteType == ViewportInteractionItem::Ride
&& viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL)
&& (*tileElement)->GetType() == TileElementType::Entrance)
{
uint32_t directions = (*tileElement)->AsEntrance()->GetDirections();
if (directions & 0x0F)
{
int32_t bx = UtilBitScanForward(directions);
bx += (*tileElement)->AsEntrance()->GetDirection();
bx &= 3;
if (direction != nullptr)
*direction = bx;
return info.Loc;
}
}
info = GetMapCoordinatesFromPosWindow(
window, screenCoords,
EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath, ViewportInteractionItem::Ride));
if (info.SpriteType == ViewportInteractionItem::Ride && (*tileElement)->GetType() == TileElementType::Entrance)
{
uint32_t directions = (*tileElement)->AsEntrance()->GetDirections();
if (directions & 0x0F)
{
int32_t bx = (*tileElement)->GetDirectionWithOffset(UtilBitScanForward(directions));
if (direction != nullptr)
*direction = bx;
return info.Loc;
}
}
// We point at something else
return FootpathGetCoordinatesFromPos(screenCoords, direction, tileElement);
}
} // namespace OpenRCT2::Ui
+19
View File
@@ -0,0 +1,19 @@
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include <openrct2/world/Location.hpp>
struct TileElement;
namespace OpenRCT2::Ui
{
CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement);
CoordsXY FootpathBridgeGetInfoFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement);
} // namespace OpenRCT2::Ui
+4 -1
View File
@@ -72,6 +72,8 @@
<ClInclude Include="interface\Objective.h" />
<ClInclude Include="interface\Theme.h" />
<ClInclude Include="interface\Viewport.h" />
<ClInclude Include="interface\ViewportInteraction.h" />
<ClInclude Include="interface\ViewportQuery.h" />
<ClInclude Include="interface\Widget.h" />
<ClInclude Include="interface\Window.h" />
<ClInclude Include="ride\Construction.h" />
@@ -134,6 +136,7 @@
<ClCompile Include="interface\Objective.cpp" />
<ClCompile Include="interface\Theme.cpp" />
<ClCompile Include="interface\ViewportInteraction.cpp" />
<ClCompile Include="interface\ViewportQuery.cpp" />
<ClCompile Include="interface\Widget.cpp" />
<ClCompile Include="interface\Window.cpp" />
<ClCompile Include="ride\Construction.cpp" />
@@ -253,4 +256,4 @@
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>
+131
View File
@@ -9,6 +9,8 @@
#include "Construction.h"
#include "../interface/Viewport.h"
#include <openrct2/GameState.h>
#include <openrct2/actions/RideCreateAction.h>
#include <openrct2/ride/Ride.h>
@@ -104,4 +106,133 @@ namespace OpenRCT2
}
return list;
}
/**
*
* rct2: 0x006CCF70
*/
CoordsXYZD RideGetEntranceOrExitPositionFromScreenPosition(const ScreenCoordsXY& screenCoords)
{
CoordsXYZD entranceExitCoords{};
gRideEntranceExitPlaceDirection = INVALID_DIRECTION;
// determine if the mouse is hovering over a station - that's the station to add the entrance to
auto info = GetMapCoordinatesFromPos(screenCoords, EnumsToFlags(ViewportInteractionItem::Ride));
if (info.SpriteType != ViewportInteractionItem::None)
{
if (info.Element->GetType() == TileElementType::Track)
{
const auto* trackElement = info.Element->AsTrack();
if (trackElement->GetRideIndex() == gRideEntranceExitPlaceRideIndex)
{
const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType());
if (std::get<0>(ted.SequenceProperties) & TRACK_SEQUENCE_FLAG_ORIGIN)
{
if (trackElement->GetTrackType() == TrackElemType::Maze)
{
gRideEntranceExitPlaceStationIndex = StationIndex::FromUnderlying(0);
}
else
{
gRideEntranceExitPlaceStationIndex = trackElement->GetStationIndex();
}
}
}
}
}
auto ride = GetRide(gRideEntranceExitPlaceRideIndex);
if (ride == nullptr)
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
auto stationBaseZ = ride->GetStation(gRideEntranceExitPlaceStationIndex).GetBaseZ();
auto coordsAtHeight = ScreenGetMapXYWithZ(screenCoords, stationBaseZ);
if (!coordsAtHeight.has_value())
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
entranceExitCoords = { coordsAtHeight->ToTileStart(), stationBaseZ, INVALID_DIRECTION };
if (ride->type == RIDE_TYPE_NULL)
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
auto stationStart = ride->GetStation(gRideEntranceExitPlaceStationIndex).Start;
if (stationStart.IsNull())
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
// find the quadrant the mouse is hovering over - that's the direction to start searching for a station TileElement
Direction startDirection = 0;
auto mapX = (coordsAtHeight->x & 0x1F) - 16;
auto mapY = (coordsAtHeight->y & 0x1F) - 16;
if (std::abs(mapX) < std::abs(mapY))
{
startDirection = mapY < 0 ? 3 : 1;
}
else
{
startDirection = mapX < 0 ? 0 : 2;
}
// check all 4 directions, starting with the mouse's quadrant
for (uint8_t directionIncrement = 0; directionIncrement < 4; directionIncrement++)
{
entranceExitCoords.direction = (startDirection + directionIncrement) & 3;
// search for TrackElement one tile over, shifted in the search direction
auto nextLocation = entranceExitCoords;
nextLocation += CoordsDirectionDelta[entranceExitCoords.direction];
if (MapIsLocationValid(nextLocation))
{
// iterate over every element in the tile until we find what we want
auto* tileElement = MapGetFirstElementAt(nextLocation);
if (tileElement == nullptr)
continue;
do
{
if (tileElement->GetType() != TileElementType::Track)
continue;
if (tileElement->GetBaseZ() != stationBaseZ)
continue;
auto* trackElement = tileElement->AsTrack();
if (trackElement->GetRideIndex() != gRideEntranceExitPlaceRideIndex)
continue;
if (trackElement->GetTrackType() == TrackElemType::Maze)
{
// if it's a maze, it can place the entrance and exit immediately
entranceExitCoords.direction = DirectionReverse(entranceExitCoords.direction);
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
return entranceExitCoords;
}
// if it's not a maze, the sequence properties for the TrackElement must be found to determine if an
// entrance can be placed on that side
gRideEntranceExitPlaceStationIndex = trackElement->GetStationIndex();
// get the ride entrance's side relative to the TrackElement
Direction direction = (DirectionReverse(entranceExitCoords.direction) - tileElement->GetDirection()) & 3;
const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType());
if (ted.SequenceProperties[trackElement->GetSequenceIndex()] & (1 << direction))
{
// if that side of the TrackElement supports stations, the ride entrance is valid and faces away from
// the station
entranceExitCoords.direction = DirectionReverse(entranceExitCoords.direction);
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
return entranceExitCoords;
}
} while (!(tileElement++)->IsLastForTile());
}
}
gRideEntranceExitPlaceDirection = INVALID_DIRECTION;
return entranceExitCoords;
}
} // namespace OpenRCT2
+1
View File
@@ -165,4 +165,5 @@ namespace OpenRCT2
RideConstructionState state);
void RideConstructNew(RideSelection listItem);
CoordsXYZD RideGetEntranceOrExitPositionFromScreenPosition(const ScreenCoordsXY& screenCoords);
} // namespace OpenRCT2
@@ -11,6 +11,7 @@
# include "CustomListView.h"
# include "../interface/Viewport.h"
# include "../interface/Widget.h"
# include "../interface/Window.h"
@@ -11,6 +11,8 @@
#ifdef ENABLE_SCRIPTING
# include "../interface/Window.h"
# include <cstdint>
# include <memory>
# include <openrct2/scripting/Duktape.hpp>
+2
View File
@@ -11,6 +11,8 @@
# include "CustomMenu.h"
# include "../interface/Viewport.h"
# include <openrct2-ui/input/ShortcutManager.h>
# include <openrct2/Input.h>
# include <openrct2/world/Map.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Viewport.h"
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportQuery.h"
#include <openrct2-ui/input/ShortcutIds.h>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportQuery.h"
#include <array>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Viewport.h"
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
+3
View File
@@ -7,6 +7,9 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportInteraction.h"
#include "../interface/ViewportQuery.h"
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../ride/Construction.h"
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportQuery.h"
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Viewport.h"
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
@@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportInteraction.h"
#include "../ride/Construction.h"
#include <limits>
+1
View File
@@ -6,6 +6,7 @@
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportInteraction.h"
#include <deque>
#include <openrct2-ui/interface/Dropdown.h>
+1
View File
@@ -8,6 +8,7 @@
*****************************************************************************/
#include "../interface/Theme.h"
#include "../interface/ViewportQuery.h"
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
+2
View File
@@ -7,6 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportQuery.h"
#include <limits>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
@@ -8,6 +8,7 @@
*****************************************************************************/
#include "../UiStringIds.h"
#include "../interface/Viewport.h"
#include <iterator>
#include <openrct2-ui/interface/Dropdown.h>
@@ -6,6 +6,7 @@
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/ViewportInteraction.h"
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
+1
View File
@@ -6,6 +6,7 @@
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Viewport.h"
#include <iterator>
#include <openrct2-ui/interface/Dropdown.h>
+1
View File
@@ -6,6 +6,7 @@
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Viewport.h"
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
+1
View File
@@ -29,6 +29,7 @@
#include "core/Path.hpp"
#include "entity/EntityRegistry.h"
#include "entity/EntityTweener.h"
#include "interface/Window.h"
#include "management/NewsItem.h"
#include "object/ObjectManager.h"
#include "object/ObjectRepository.h"
@@ -11,6 +11,7 @@
#include "../Diagnostic.h"
#include "../config/Config.h"
#include "../interface/Window.h"
using namespace OpenRCT2;
+1
View File
@@ -9,6 +9,7 @@
#pragma once
#include "../interface/Window.h"
#include "GameAction.h"
enum class LoadOrQuitModes : uint8_t
@@ -10,6 +10,7 @@
#include "RideFreezeRatingAction.h"
#include "../Diagnostic.h"
#include "../interface/Window.h"
using namespace OpenRCT2;
@@ -12,6 +12,7 @@
#include "../Context.h"
#include "../Diagnostic.h"
#include "../GameState.h"
#include "../interface/Window.h"
#include "../object/ObjectManager.h"
#include "../ride/Ride.h"
#include "../ride/RideData.h"
+1
View File
@@ -10,6 +10,7 @@
#include "EntityBase.h"
#include "../core/DataSerialiser.h"
#include "../interface/Viewport.h"
using namespace OpenRCT2;
+1
View File
@@ -26,6 +26,7 @@
#include "../entity/Balloon.h"
#include "../entity/EntityRegistry.h"
#include "../entity/EntityTweener.h"
#include "../interface/Viewport.h"
#include "../interface/Window_internal.h"
#include "../localisation/Formatter.h"
#include "../localisation/Formatting.h"
-6
View File
@@ -159,12 +159,6 @@ InteractionInfo GetMapCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int
InteractionInfo GetMapCoordinatesFromPosWindow(WindowBase* window, const ScreenCoordsXY& screenCoords, int32_t flags);
InteractionInfo SetInteractionInfoFromPaintSession(PaintSession* session, uint32_t viewFlags, uint16_t filter);
bool ViewportInteractionLeftOver(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionRightOver(const ScreenCoordsXY& screenCoords);
bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords);
CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords);
std::optional<CoordsXY> ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewport** viewport);
std::optional<CoordsXY> ScreenGetMapXYWithZ(const ScreenCoordsXY& screenCoords, int32_t z);
+1
View File
@@ -11,6 +11,7 @@
#include "NetworkUser.h"
#include <fstream>
#include <list>
#include <memory>
#ifndef DISABLE_NETWORK
+1
View File
@@ -16,6 +16,7 @@
#include "../core/Console.hpp"
#include "../core/JobPool.h"
#include "../core/Memory.hpp"
#include "../interface/Window.h"
#include "../localisation/StringIds.h"
#include "../ride/Ride.h"
#include "../ride/RideAudio.h"
+1
View File
@@ -19,6 +19,7 @@
#include "../interface/Chat.h"
#include "../interface/InteractiveConsole.h"
#include "../interface/Widget.h"
#include "../interface/Window.h"
#include "../localisation/FormatCodes.h"
#include "../localisation/Formatting.h"
#include "../localisation/Language.h"
@@ -9,6 +9,7 @@
#include "WoodenSupports.h"
#include "../../interface/Viewport.h"
#include "../../sprites.h"
#include "../../world/Map.h"
#include "../../world/Surface.h"
@@ -11,6 +11,7 @@
#include "../../core/Numerics.hpp"
#include "../../drawing/LightFX.h"
#include "../../interface/Viewport.h"
#include "../../object/PathAdditionEntry.h"
#include "../../profiling/Profiling.h"
#include "Paint.TileElement.h"
+1
View File
@@ -31,6 +31,7 @@
#include "../entity/EntityRegistry.h"
#include "../entity/Peep.h"
#include "../entity/Staff.h"
#include "../interface/Viewport.h"
#include "../interface/Window_internal.h"
#include "../localisation/Formatter.h"
#include "../localisation/Formatting.h"
+1
View File
@@ -13,6 +13,7 @@
#include "../actions/ResultWithMessage.h"
#include "../core/BitSet.hpp"
#include "../core/FixedPoint.hpp"
#include "../localisation/Formatter.h"
#include "../object/MusicObject.h"
#include "../rct2/DATLimits.h"
#include "../rct2/Limits.h"
-128
View File
@@ -1205,134 +1205,6 @@ money64 SetOperatingSettingNested(RideId rideId, RideSetSetting setting, uint8_t
return res.Error == GameActions::Status::Ok ? 0 : kMoney64Undefined;
}
/**
*
* rct2: 0x006CCF70
*/
CoordsXYZD RideGetEntranceOrExitPositionFromScreenPosition(const ScreenCoordsXY& screenCoords)
{
CoordsXYZD entranceExitCoords{};
gRideEntranceExitPlaceDirection = INVALID_DIRECTION;
// determine if the mouse is hovering over a station - that's the station to add the entrance to
auto info = GetMapCoordinatesFromPos(screenCoords, EnumsToFlags(ViewportInteractionItem::Ride));
if (info.SpriteType != ViewportInteractionItem::None)
{
if (info.Element->GetType() == TileElementType::Track)
{
const auto* trackElement = info.Element->AsTrack();
if (trackElement->GetRideIndex() == gRideEntranceExitPlaceRideIndex)
{
const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType());
if (std::get<0>(ted.SequenceProperties) & TRACK_SEQUENCE_FLAG_ORIGIN)
{
if (trackElement->GetTrackType() == TrackElemType::Maze)
{
gRideEntranceExitPlaceStationIndex = StationIndex::FromUnderlying(0);
}
else
{
gRideEntranceExitPlaceStationIndex = trackElement->GetStationIndex();
}
}
}
}
}
auto ride = GetRide(gRideEntranceExitPlaceRideIndex);
if (ride == nullptr)
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
auto stationBaseZ = ride->GetStation(gRideEntranceExitPlaceStationIndex).GetBaseZ();
auto coordsAtHeight = ScreenGetMapXYWithZ(screenCoords, stationBaseZ);
if (!coordsAtHeight.has_value())
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
entranceExitCoords = { coordsAtHeight->ToTileStart(), stationBaseZ, INVALID_DIRECTION };
if (ride->type == RIDE_TYPE_NULL)
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
auto stationStart = ride->GetStation(gRideEntranceExitPlaceStationIndex).Start;
if (stationStart.IsNull())
{
entranceExitCoords.SetNull();
return entranceExitCoords;
}
// find the quadrant the mouse is hovering over - that's the direction to start searching for a station TileElement
Direction startDirection = 0;
auto mapX = (coordsAtHeight->x & 0x1F) - 16;
auto mapY = (coordsAtHeight->y & 0x1F) - 16;
if (std::abs(mapX) < std::abs(mapY))
{
startDirection = mapY < 0 ? 3 : 1;
}
else
{
startDirection = mapX < 0 ? 0 : 2;
}
// check all 4 directions, starting with the mouse's quadrant
for (uint8_t directionIncrement = 0; directionIncrement < 4; directionIncrement++)
{
entranceExitCoords.direction = (startDirection + directionIncrement) & 3;
// search for TrackElement one tile over, shifted in the search direction
auto nextLocation = entranceExitCoords;
nextLocation += CoordsDirectionDelta[entranceExitCoords.direction];
if (MapIsLocationValid(nextLocation))
{
// iterate over every element in the tile until we find what we want
auto* tileElement = MapGetFirstElementAt(nextLocation);
if (tileElement == nullptr)
continue;
do
{
if (tileElement->GetType() != TileElementType::Track)
continue;
if (tileElement->GetBaseZ() != stationBaseZ)
continue;
auto* trackElement = tileElement->AsTrack();
if (trackElement->GetRideIndex() != gRideEntranceExitPlaceRideIndex)
continue;
if (trackElement->GetTrackType() == TrackElemType::Maze)
{
// if it's a maze, it can place the entrance and exit immediately
entranceExitCoords.direction = DirectionReverse(entranceExitCoords.direction);
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
return entranceExitCoords;
}
// if it's not a maze, the sequence properties for the TrackElement must be found to determine if an
// entrance can be placed on that side
gRideEntranceExitPlaceStationIndex = trackElement->GetStationIndex();
// get the ride entrance's side relative to the TrackElement
Direction direction = (DirectionReverse(entranceExitCoords.direction) - tileElement->GetDirection()) & 3;
const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType());
if (ted.SequenceProperties[trackElement->GetSequenceIndex()] & (1 << direction))
{
// if that side of the TrackElement supports stations, the ride entrance is valid and faces away from
// the station
entranceExitCoords.direction = DirectionReverse(entranceExitCoords.direction);
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
return entranceExitCoords;
}
} while (!(tileElement++)->IsLastForTile());
}
}
gRideEntranceExitPlaceDirection = INVALID_DIRECTION;
return entranceExitCoords;
}
/**
*
* rct2: 0x006CB945
-2
View File
@@ -91,8 +91,6 @@ void RideSelectPreviousSection();
bool RideModify(const CoordsXYE& input);
CoordsXYZD RideGetEntranceOrExitPositionFromScreenPosition(const ScreenCoordsXY& screenCoords);
bool RideSelectBackwardsFromFront();
bool RideSelectForwardsFromBack();
+1
View File
@@ -21,6 +21,7 @@
struct Ride;
struct ResultWithMessage;
enum class ViewportInteractionItem : uint8_t;
constexpr uint32_t kTrackPreviewImageSize = 370 * 217;
@@ -10,6 +10,7 @@
#include "SetLocation.h"
#include "../../../OpenRCT2.h"
#include "../../../interface/Viewport.h"
#include "../../../interface/Window.h"
#include "../../../interface/Window_internal.h"
#include "../../../world/Map.h"
+1 -159
View File
@@ -20,6 +20,7 @@
#include "../core/Guard.hpp"
#include "../entity/EntityList.h"
#include "../entity/EntityRegistry.h"
#include "../interface/Viewport.h"
#include "../interface/Window_internal.h"
#include "../management/Finance.h"
#include "../network/network.h"
@@ -231,165 +232,6 @@ void FootpathProvisionalUpdate()
FootpathProvisionalRemove();
}
/**
* Determines the location of the footpath at which we point with the cursor. If no footpath is underneath the cursor,
* then return the location of the ground tile. Besides the location it also computes the direction of the yellow arrow
* when we are going to build a footpath bridge/tunnel.
* rct2: 0x00689726
* In:
* screenX: eax
* screenY: ebx
* Out:
* x: ax
* y: bx
* direction: ecx
* tileElement: edx
*/
CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement)
{
WindowBase* window = WindowFindFromPoint(screenCoords);
if (window == nullptr || window->viewport == nullptr)
{
CoordsXY position{};
position.SetNull();
return position;
}
auto viewport = window->viewport;
auto info = GetMapCoordinatesFromPosWindow(window, screenCoords, EnumsToFlags(ViewportInteractionItem::Footpath));
if (info.SpriteType != ViewportInteractionItem::Footpath
|| !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL)))
{
info = GetMapCoordinatesFromPosWindow(
window, screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath));
if (info.SpriteType == ViewportInteractionItem::None)
{
auto position = info.Loc;
position.SetNull();
return position;
}
}
auto minPosition = info.Loc;
auto maxPosition = info.Loc + CoordsXY{ 31, 31 };
auto myTileElement = info.Element;
auto position = info.Loc.ToTileCentre();
auto z = 0;
if (info.SpriteType == ViewportInteractionItem::Footpath)
{
z = myTileElement->GetBaseZ();
if (myTileElement->AsPath()->IsSloped())
{
z += 8;
}
}
auto start_vp_pos = viewport->ScreenToViewportCoord(screenCoords);
for (int32_t i = 0; i < 5; i++)
{
if (info.SpriteType != ViewportInteractionItem::Footpath)
{
z = TileElementHeight(position);
}
position = ViewportPosToMapPos(start_vp_pos, z, viewport->rotation);
position.x = std::clamp(position.x, minPosition.x, maxPosition.x);
position.y = std::clamp(position.y, minPosition.y, maxPosition.y);
}
// Determine to which edge the cursor is closest
uint32_t myDirection;
int32_t mod_x = position.x & 0x1F, mod_y = position.y & 0x1F;
if (mod_x < mod_y)
{
if (mod_x + mod_y < 32)
{
myDirection = 0;
}
else
{
myDirection = 1;
}
}
else
{
if (mod_x + mod_y < 32)
{
myDirection = 3;
}
else
{
myDirection = 2;
}
}
position = position.ToTileStart();
if (direction != nullptr)
*direction = myDirection;
if (tileElement != nullptr)
*tileElement = myTileElement;
return position;
}
/**
*
* rct2: 0x0068A0C9
* screenX: eax
* screenY: ebx
* x: ax
* y: bx
* direction: cl
* tileElement: edx
*/
CoordsXY FootpathBridgeGetInfoFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement)
{
// First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit.
WindowBase* window = WindowFindFromPoint(screenCoords);
if (window == nullptr || window->viewport == nullptr)
{
CoordsXY ret{};
ret.SetNull();
return ret;
}
auto viewport = window->viewport;
auto info = GetMapCoordinatesFromPosWindow(window, screenCoords, EnumsToFlags(ViewportInteractionItem::Ride));
*tileElement = info.Element;
if (info.SpriteType == ViewportInteractionItem::Ride
&& viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL)
&& (*tileElement)->GetType() == TileElementType::Entrance)
{
uint32_t directions = (*tileElement)->AsEntrance()->GetDirections();
if (directions & 0x0F)
{
int32_t bx = UtilBitScanForward(directions);
bx += (*tileElement)->AsEntrance()->GetDirection();
bx &= 3;
if (direction != nullptr)
*direction = bx;
return info.Loc;
}
}
info = GetMapCoordinatesFromPosWindow(
window, screenCoords,
EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath, ViewportInteractionItem::Ride));
if (info.SpriteType == ViewportInteractionItem::Ride && (*tileElement)->GetType() == TileElementType::Entrance)
{
uint32_t directions = (*tileElement)->AsEntrance()->GetDirections();
if (directions & 0x0F)
{
int32_t bx = (*tileElement)->GetDirectionWithOffset(UtilBitScanForward(directions));
if (direction != nullptr)
*direction = bx;
return info.Loc;
}
}
// We point at something else
return FootpathGetCoordinatesFromPos(screenCoords, direction, tileElement);
}
/**
*
* rct2: 0x00673883
+1 -3
View File
@@ -10,13 +10,13 @@
#pragma once
#include "../Identifiers.h"
#include "../interface/Viewport.h"
#include "../object/Object.h"
class FootpathObject;
class FootpathSurfaceObject;
class FootpathRailingsObject;
struct PathElement;
struct TileElement;
enum
{
@@ -191,8 +191,6 @@ money64 FootpathProvisionalSet(
PathConstructFlags constructFlags);
void FootpathProvisionalRemove();
void FootpathProvisionalUpdate();
CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement);
CoordsXY FootpathBridgeGetInfoFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement);
void FootpathRemoveLitter(const CoordsXYZ& footpathPos);
void FootpathConnectEdges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags);
void FootpathUpdateQueueChains();