OpenRCT2/src/openrct2/world/Entrance.cpp

332 lines
10 KiB
C++
Raw Normal View History

2017-02-25 14:51:30 +01:00
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
2017-02-25 14:51:30 +01:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2017-02-25 14:51:30 +01:00
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
2017-02-25 14:51:30 +01:00
*****************************************************************************/
2017-12-14 10:34:12 +01:00
#include "Entrance.h"
2018-06-22 23:17:03 +02:00
2017-12-13 13:02:24 +01:00
#include "../Cheats.h"
2017-11-30 18:17:06 +01:00
#include "../Game.h"
2018-06-22 23:17:03 +02:00
#include "../OpenRCT2.h"
#include "../actions/RideEntranceExitPlaceAction.hpp"
#include "../actions/RideEntranceExitRemoveAction.hpp"
2018-01-06 18:32:25 +01:00
#include "../localisation/StringIds.h"
2017-10-06 22:37:06 +02:00
#include "../management/Finance.h"
2018-06-22 23:17:03 +02:00
#include "../network/network.h"
#include "../ride/Station.h"
2018-06-22 23:17:03 +02:00
#include "../ride/Track.h"
#include "Footpath.h"
#include "Map.h"
#include "MapAnimation.h"
#include "Park.h"
#include "Sprite.h"
2017-02-25 14:51:30 +01:00
2018-12-15 20:20:04 +01:00
#include <algorithm>
bool gParkEntranceGhostExists = false;
LocationXYZ16 gParkEntranceGhostPosition = { 0, 0, 0 };
uint8_t gParkEntranceGhostDirection = 0;
std::vector<CoordsXYZD> gParkEntrances;
2017-02-25 14:51:30 +01:00
2018-02-16 09:50:40 +01:00
CoordsXYZD gRideEntranceExitGhostPosition;
uint8_t gRideEntranceExitGhostStationIndex;
static void ParkEntranceRemoveSegment(int32_t x, int32_t y, int32_t z)
2017-02-25 14:51:30 +01:00
{
EntranceElement* tileElement;
2017-02-25 14:51:30 +01:00
2017-10-31 14:03:45 +01:00
tileElement = map_get_park_entrance_element_at(x, y, z, true);
if (tileElement == nullptr)
2017-03-01 22:19:15 +01:00
{
return;
}
2017-02-25 14:51:30 +01:00
2017-10-31 14:03:45 +01:00
map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8);
tileElement->Remove();
2018-06-22 23:17:03 +02:00
update_park_fences({ x, y });
2017-02-25 14:51:30 +01:00
}
static money32 ParkEntranceRemove(int16_t x, int16_t y, uint8_t z, uint8_t flags)
2017-02-25 14:51:30 +01:00
{
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR) && !gCheatsSandboxMode)
2017-03-01 22:19:15 +01:00
{
return MONEY32_UNDEFINED;
}
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LAND_PURCHASE;
gCommandPosition.x = x;
gCommandPosition.y = y;
gCommandPosition.z = z * 16;
if (!(flags & GAME_COMMAND_FLAG_APPLY))
2017-03-01 22:19:15 +01:00
{
return 0;
}
auto entranceIndex = park_entrance_get_index(x, y, z * 16);
if (entranceIndex == -1)
2017-03-01 22:19:15 +01:00
{
return 0;
}
auto direction = (gParkEntrances[entranceIndex].direction - 1) & 3;
2017-03-01 22:19:15 +01:00
// Centre (sign)
ParkEntranceRemoveSegment(x, y, z * 2);
// Left post
2018-06-22 23:17:03 +02:00
ParkEntranceRemoveSegment(x + CoordsDirectionDelta[direction].x, y + CoordsDirectionDelta[direction].y, z * 2);
2017-03-01 22:19:15 +01:00
// Right post
2018-06-22 23:17:03 +02:00
ParkEntranceRemoveSegment(x - CoordsDirectionDelta[direction].x, y - CoordsDirectionDelta[direction].y, z * 2);
2017-03-01 22:19:15 +01:00
gParkEntrances.erase(gParkEntrances.begin() + entranceIndex);
2017-03-01 22:19:15 +01:00
return 0;
2017-02-25 14:51:30 +01:00
}
2018-06-22 23:17:03 +02:00
static money32 RideEntranceExitPlaceGhost(
2019-01-12 11:11:55 +01:00
ride_id_t rideIndex, int16_t x, int16_t y, uint8_t direction, uint8_t placeType, uint8_t stationNum)
{
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
{ x, y }, direction, rideIndex, stationNum, placeType == ENTRANCE_TYPE_RIDE_EXIT);
rideEntranceExitPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_GHOST);
auto res = GameActions::Execute(&rideEntranceExitPlaceAction);
return res->Error == GA_ERROR::OK ? res->Cost : MONEY32_UNDEFINED;
}
2017-02-25 14:51:30 +01:00
2018-02-01 18:49:14 +01:00
/**
*
* rct2: 0x00666A63
*/
void game_command_remove_park_entrance(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, [[maybe_unused]] int32_t* edi,
2018-06-22 23:17:03 +02:00
[[maybe_unused]] int32_t* ebp)
2017-02-25 14:51:30 +01:00
{
2018-06-22 23:17:03 +02:00
*ebx = ParkEntranceRemove(*eax & 0xFFFF, *ecx & 0xFFFF, *edx & 0xFF, *ebx & 0xFF);
2018-02-01 18:49:14 +01:00
}
2017-02-25 14:51:30 +01:00
2018-02-01 18:49:14 +01:00
/**
*
* rct2: 0x00666F9E
*/
void park_entrance_remove_ghost()
{
if (gParkEntranceGhostExists)
2017-02-25 14:51:30 +01:00
{
2018-02-01 18:49:14 +01:00
gParkEntranceGhostExists = false;
game_do_command(
gParkEntranceGhostPosition.x, GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_APPLY,
gParkEntranceGhostPosition.y, gParkEntranceGhostPosition.z, GAME_COMMAND_REMOVE_PARK_ENTRANCE, 0, 0);
2017-02-25 14:51:30 +01:00
}
2018-02-01 18:49:14 +01:00
}
2017-02-25 14:51:30 +01:00
int32_t park_entrance_get_index(int32_t x, int32_t y, int32_t z)
2018-02-01 18:49:14 +01:00
{
int32_t i = 0;
for (const auto& entrance : gParkEntrances)
2017-02-25 14:51:30 +01:00
{
if (x == entrance.x && y == entrance.y && z == entrance.z)
2017-03-01 22:19:15 +01:00
{
2018-02-01 18:49:14 +01:00
return i;
2017-03-01 22:19:15 +01:00
}
i++;
2017-02-25 14:51:30 +01:00
}
2018-02-01 18:49:14 +01:00
return -1;
}
void reset_park_entrance()
{
gParkEntrances.clear();
2018-02-01 18:49:14 +01:00
}
2018-02-01 18:49:14 +01:00
void ride_entrance_exit_place_provisional_ghost()
{
2018-06-22 23:17:03 +02:00
if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT)
{
RideEntranceExitPlaceGhost(
_currentRideIndex, gRideEntranceExitGhostPosition.x, gRideEntranceExitGhostPosition.y,
gRideEntranceExitGhostPosition.direction, gRideEntranceExitPlaceType, gRideEntranceExitGhostStationIndex);
}
2018-02-01 18:49:14 +01:00
}
2018-02-01 18:49:14 +01:00
void ride_entrance_exit_remove_ghost()
{
2018-06-22 23:17:03 +02:00
if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT)
{
auto rideEntranceExitRemove = RideEntranceExitRemoveAction(
{ gRideEntranceExitGhostPosition.x, gRideEntranceExitGhostPosition.y }, _currentRideIndex,
gRideEntranceExitGhostStationIndex, gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT);
2019-02-27 19:35:55 +01:00
rideEntranceExitRemove.SetFlags(GAME_COMMAND_FLAG_GHOST | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED);
GameActions::Execute(&rideEntranceExitRemove);
}
2018-02-01 18:49:14 +01:00
}
2018-02-01 18:49:14 +01:00
/**
*
* rct2: 0x006CA28C
*/
2018-06-22 23:17:03 +02:00
money32 ride_entrance_exit_place_ghost(
2019-02-13 21:16:42 +01:00
Ride* ride, int32_t x, int32_t y, int32_t direction, int32_t placeType, int32_t stationNum)
2018-02-01 18:49:14 +01:00
{
ride_construction_remove_ghosts();
2019-02-13 21:16:42 +01:00
money32 result = RideEntranceExitPlaceGhost(ride->id, x, y, direction, placeType, stationNum);
2018-02-01 18:49:14 +01:00
if (result != MONEY32_UNDEFINED)
2017-03-09 19:48:09 +01:00
{
2018-02-01 18:49:14 +01:00
_currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT;
gRideEntranceExitGhostPosition.x = x;
gRideEntranceExitGhostPosition.y = y;
gRideEntranceExitGhostPosition.direction = direction;
gRideEntranceExitGhostStationIndex = stationNum & 0xFF;
}
2018-02-01 18:49:14 +01:00
return result;
}
2018-02-01 18:49:14 +01:00
/**
* Replaces the outer hedge walls for an entrance placement removal.
* rct2: 0x00666D6F
*/
2018-11-01 13:53:50 +01:00
void maze_entrance_hedge_replacement(int32_t x, int32_t y, TileElement* tileElement)
2018-02-01 18:49:14 +01:00
{
int32_t direction = tileElement->GetDirection();
x += CoordsDirectionDelta[direction].x;
y += CoordsDirectionDelta[direction].y;
int32_t z = tileElement->base_height;
2019-01-12 11:11:55 +01:00
ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex();
2018-02-01 18:49:14 +01:00
tileElement = map_get_first_element_at(x >> 5, y >> 5);
2018-06-22 23:17:03 +02:00
do
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;
2018-09-18 13:10:29 +02:00
if (tileElement->AsTrack()->GetRideIndex() != rideIndex)
2018-06-22 23:17:03 +02:00
continue;
if (tileElement->base_height != z)
continue;
if (tileElement->AsTrack()->GetTrackType() != TRACK_ELEM_MAZE)
2018-06-22 23:17:03 +02:00
continue;
2018-02-01 18:49:14 +01:00
// Each maze element is split into 4 sections with 4 different walls
uint8_t mazeSection = direction * 4;
2018-02-01 18:49:14 +01:00
// Add the top outer wall
tileElement->AsTrack()->MazeEntryAdd(1 << ((mazeSection + 9) & 0x0F));
2018-02-01 18:49:14 +01:00
// Add the bottom outer wall
tileElement->AsTrack()->MazeEntryAdd(1 << ((mazeSection + 12) & 0x0F));
2018-02-01 18:49:14 +01:00
map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8);
return;
} while (!(tileElement++)->IsLastForTile());
2018-02-01 18:49:14 +01:00
}
2018-02-01 18:49:14 +01:00
/**
* Removes the hedge walls for an entrance placement.
* rct2: 0x00666CBE
*/
2018-11-01 13:53:50 +01:00
void maze_entrance_hedge_removal(int32_t x, int32_t y, TileElement* tileElement)
2018-02-01 18:49:14 +01:00
{
int32_t direction = tileElement->GetDirection();
x += CoordsDirectionDelta[direction].x;
y += CoordsDirectionDelta[direction].y;
int32_t z = tileElement->base_height;
2019-01-12 11:11:55 +01:00
ride_id_t rideIndex = tileElement->AsEntrance()->GetRideIndex();
2018-02-01 18:49:14 +01:00
tileElement = map_get_first_element_at(x >> 5, y >> 5);
2018-06-22 23:17:03 +02:00
do
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue;
2018-09-18 13:10:29 +02:00
if (tileElement->AsTrack()->GetRideIndex() != rideIndex)
2018-06-22 23:17:03 +02:00
continue;
if (tileElement->base_height != z)
continue;
if (tileElement->AsTrack()->GetTrackType() != TRACK_ELEM_MAZE)
2018-06-22 23:17:03 +02:00
continue;
2018-02-01 18:49:14 +01:00
// Each maze element is split into 4 sections with 4 different walls
uint8_t mazeSection = direction * 4;
2018-02-01 18:49:14 +01:00
// Remove the top outer wall
tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 9) & 0x0F));
2018-02-01 18:49:14 +01:00
// Remove the bottom outer wall
tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 12) & 0x0F));
2018-02-01 18:49:14 +01:00
// Remove the intersecting wall
tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 10) & 0x0F));
2018-02-01 18:49:14 +01:00
// Remove the top hedge section
tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 11) & 0x0F));
2018-02-01 18:49:14 +01:00
// Remove the bottom hedge section
tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 15) & 0x0F));
2018-02-01 18:49:14 +01:00
map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8);
return;
} while (!(tileElement++)->IsLastForTile());
2018-02-01 18:49:14 +01:00
}
void fix_park_entrance_locations(void)
{
// Fix gParkEntrance locations for which the tile_element no longer exists
gParkEntrances.erase(
std::remove_if(
gParkEntrances.begin(), gParkEntrances.end(),
[](const auto& entrance) {
return map_get_park_entrance_element_at(entrance.x, entrance.y, entrance.z >> 3, false) == nullptr;
}),
gParkEntrances.end());
}
uint8_t EntranceElement::GetStationIndex() const
{
2018-09-26 12:02:41 +02:00
return (index & MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK) >> 4;
}
void EntranceElement::SetStationIndex(uint8_t stationIndex)
{
2018-09-26 12:02:41 +02:00
index &= ~MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK;
index |= (stationIndex << 4);
}
2018-09-26 12:13:44 +02:00
uint8_t EntranceElement::GetEntranceType() const
{
return entranceType;
}
void EntranceElement::SetEntranceType(uint8_t newType)
{
entranceType = newType;
}
2018-09-26 12:30:27 +02:00
2019-01-12 11:11:55 +01:00
ride_id_t EntranceElement::GetRideIndex() const
2018-09-26 12:30:27 +02:00
{
return rideIndex;
}
2019-01-12 11:11:55 +01:00
void EntranceElement::SetRideIndex(ride_id_t newRideIndex)
2018-09-26 12:30:27 +02:00
{
rideIndex = newRideIndex;
}
uint8_t EntranceElement::GetSequenceIndex() const
{
return index & 0xF;
}
void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex)
{
index &= ~0xF;
index |= (newSequenceIndex & 0xF);
2018-09-26 13:02:51 +02:00
}
uint8_t EntranceElement::GetPathType() const
{
return pathType;
}
void EntranceElement::SetPathType(uint8_t newPathType)
{
pathType = newPathType;
2018-09-26 14:52:16 +02:00
}