Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #15750: Multiple park entrance types in one park #21909

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.4.11 (in development)
------------------------------------------------------------------------
- Feature: [#11512] Coloured usernames by group on multiplayer servers.
- Feature: [#15750] Allow using different types of park entrance in one park.
- Feature: [#21734] Park admittance price can now be set via text input.
- Improved: [#21769] Expose “animation is backwards” wall property in Tile Inspector.
- Improved: [#21855] Add a separator between “Load Game” and “Save Game”, to avoid accidental overwriting.
Expand Down
91 changes: 79 additions & 12 deletions src/openrct2-ui/windows/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*****************************************************************************/

#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
Expand All @@ -29,6 +30,8 @@
#include <openrct2/entity/Staff.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/object/EntranceObject.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/object/TerrainSurfaceObject.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
Expand Down Expand Up @@ -194,6 +197,8 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {
std::vector<uint8_t> _mapImageData;
bool _mapWidthAndHeightLinked{ true };
bool _recalculateScrollbars = false;
std::vector<Dropdown::Item> _entranceTypeDropdown{};
ObjectEntryIndex _selectedEntranceType = 0;
enum class ResizeDirection
{
Both,
Expand Down Expand Up @@ -237,6 +242,8 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {

// Reset land rights tool size
_landRightsToolSize = 1;

InitParkEntranceDropdownItems();
}

void OnClose() override
Expand Down Expand Up @@ -301,16 +308,7 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {
Invalidate();
break;
case WIDX_BUILD_PARK_ENTRANCE:
Invalidate();
if (ToolSet(*this, widgetIndex, Tool::UpArrow))
break;

gParkEntranceGhostExists = false;
InputSetFlag(INPUT_FLAG_6, true);

ShowGridlines();
ShowLandRights();
ShowConstructionRights();
BuildParkEntranceToggle();
break;
case WIDX_ROTATE_90:
gWindowSceneryRotation = (gWindowSceneryRotation + 1) & 3;
Expand Down Expand Up @@ -382,6 +380,9 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {

Invalidate();
break;
case WIDX_BUILD_PARK_ENTRANCE:
ShowParkEntranceDropdown(widgets[widgetIndex]);
break;
}
}

Expand Down Expand Up @@ -585,7 +586,7 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {

ParkEntranceRemoveGhost();

auto gameAction = ParkEntrancePlaceAction(parkEntrancePosition, gFootpathSelectedId);
auto gameAction = ParkEntrancePlaceAction(parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType);
gameAction.SetFlags(GAME_COMMAND_FLAG_GHOST);

auto result = GameActions::Execute(&gameAction);
Expand All @@ -603,7 +604,7 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {
CoordsXYZD parkEntrancePosition = PlaceParkEntranceGetMapPosition(screenCoords);
if (!parkEntrancePosition.IsNull())
{
auto gameAction = ParkEntrancePlaceAction(parkEntrancePosition, gFootpathSelectedId);
auto gameAction = ParkEntrancePlaceAction(parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType);
auto result = GameActions::Execute(&gameAction);
if (result.Error == GameActions::Status::Ok)
{
Expand Down Expand Up @@ -991,6 +992,22 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {
CentreMapOnViewPoint();
}

void OnDropdown(WidgetIndex widgetIndex, int32_t selectedIndex) override
{
if (selectedIndex == -1)
{
return;
}

switch (widgetIndex)
{
case WIDX_BUILD_PARK_ENTRANCE:
BuildParkEntranceToggle();
BuildParkEntranceClick(selectedIndex);
break;
}
}

private:
void InitMap()
{
Expand Down Expand Up @@ -1494,6 +1511,56 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = {
width = std::max(min_width, width);
_recalculateScrollbars = true;
}

void InitParkEntranceDropdownItems()
{
_entranceTypeDropdown.clear();
for (auto objectIndex = 0; objectIndex < OBJECT_ENTRY_INDEX_NULL; objectIndex++)
{
auto& objManager = GetContext()->GetObjectManager();
auto* object = static_cast<EntranceObject*>(objManager.GetLoadedObject(ObjectType::ParkEntrance, objectIndex));
if (object != nullptr)
{
const auto* legacyData = reinterpret_cast<const EntranceEntry*>(object->GetLegacyData());
_entranceTypeDropdown.push_back({ .Format = legacyData->string_idx, .Args = objectIndex, .Flags = 0 });
}
}
}

void ShowParkEntranceDropdown(Widget& widget)
{
gDropdownDefaultIndex = 0;
auto numItems = _entranceTypeDropdown.size();
for (auto dropdownIndex = 0u; dropdownIndex < numItems; dropdownIndex++)
{
gDropdownItems[dropdownIndex] = _entranceTypeDropdown[dropdownIndex];

if (gDropdownItems[dropdownIndex].Args == _selectedEntranceType)
gDropdownDefaultIndex = dropdownIndex;
}

WindowDropdownShowText(
{ windowPos.x + widget.left, windowPos.y + widget.top }, widget.height() + 1, colours[1] | 0x80, 0, numItems);
}

void BuildParkEntranceToggle()
{
Invalidate();
if (ToolSet(*this, WIDX_BUILD_PARK_ENTRANCE, Tool::UpArrow))
return;

gParkEntranceGhostExists = false;
InputSetFlag(INPUT_FLAG_6, true);

ShowGridlines();
ShowLandRights();
ShowConstructionRights();
}

void BuildParkEntranceClick(int16_t dropdownIndex)
{
_selectedEntranceType = gDropdownItems[dropdownIndex].Args;
}
};

WindowBase* MapOpen()
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/EditorObjectSelectionSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ void SetupInUseSelectionFlags()
if (parkEntranceEl->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE)
break;

Editor::SetSelectedObject(ObjectType::ParkEntrance, 0, ObjectSelectionFlags::InUse);
type = iter.element->AsEntrance()->getEntryIndex();
Editor::SetSelectedObject(ObjectType::ParkEntrance, type, ObjectSelectionFlags::InUse);

// Skip if not the middle part
if (parkEntranceEl->GetSequenceIndex() != 0)
Expand Down Expand Up @@ -687,9 +688,8 @@ int32_t EditorRemoveUnusedObjects()
if (ObjectTypeIsIntransient(objectType))
continue;

// These object types require exactly one object to be selected at all times.
// Removing that object can badly break the game state.
if (objectType == ObjectType::ParkEntrance || objectType == ObjectType::Water)
// The water type controls the entire palette. Removing that object can badly break the game state.
if (objectType == ObjectType::Water)
continue;

// It’s hard to determine exactly if a scenery group is used, so do not remove these automatically.
Expand Down
7 changes: 6 additions & 1 deletion src/openrct2/actions/ParkEntrancePlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@

using namespace OpenRCT2;

ParkEntrancePlaceAction::ParkEntrancePlaceAction(const CoordsXYZD& location, ObjectEntryIndex pathType)
ParkEntrancePlaceAction::ParkEntrancePlaceAction(
const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType)
: _loc(location)
, _pathType(pathType)
, _entranceType(entranceType)
{
}

void ParkEntrancePlaceAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit(_loc);
visitor.Visit("footpathSurfaceObject", _pathType);
visitor.Visit("entranceObject", _entranceType);
}

uint16_t ParkEntrancePlaceAction::GetActionFlags() const
Expand All @@ -47,6 +50,7 @@ void ParkEntrancePlaceAction::Serialise(DataSerialiser& stream)

stream << DS_TAG(_loc);
stream << DS_TAG(_pathType);
stream << DS_TAG(_entranceType);
}

GameActions::Result ParkEntrancePlaceAction::Query() const
Expand Down Expand Up @@ -156,6 +160,7 @@ GameActions::Result ParkEntrancePlaceAction::Execute() const
entranceElement->SetDirection(_loc.direction);
entranceElement->SetSequenceIndex(index);
entranceElement->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE);
entranceElement->setEntryIndex(_entranceType);
if (gFootpathSelection.LegacyPath == OBJECT_ENTRY_INDEX_NULL)
{
entranceElement->SetSurfaceEntryIndex(gFootpathSelection.NormalSurface);
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/actions/ParkEntrancePlaceAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class ParkEntrancePlaceAction final : public GameActionBase<GameCommand::PlacePa
private:
CoordsXYZD _loc;
ObjectEntryIndex _pathType;
ObjectEntryIndex _entranceType;

public:
ParkEntrancePlaceAction() = default;
ParkEntrancePlaceAction(const CoordsXYZD& location, ObjectEntryIndex pathType);
ParkEntrancePlaceAction(const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType);

void AcceptParameters(GameActionParameterVisitor& visitor) override;

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/libopenrct2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@
<ClCompile Include="Version.cpp" />
<ClCompile Include="windows\Intent.cpp" />
<ClCompile Include="windows\_legacy.cpp" />
<ClCompile Include="world\tile_element\Entrance.cpp" />
<ClCompile Include="world\Banner.cpp" />
<ClCompile Include="world\Climate.cpp" />
<ClCompile Include="world\ConstructionClearance.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/object/ObjectLimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constexpr uint16_t MAX_BANNER_OBJECTS = 255;
constexpr uint16_t MAX_PATH_OBJECTS = 255;
constexpr uint16_t MAX_PATH_ADDITION_OBJECTS = 255;
constexpr uint16_t MAX_SCENERY_GROUP_OBJECTS = 255;
constexpr uint16_t MAX_PARK_ENTRANCE_OBJECTS = 1;
constexpr uint16_t MAX_PARK_ENTRANCE_OBJECTS = 4;
constexpr uint16_t MAX_WATER_OBJECTS = 1;
constexpr uint16_t MAX_SCENARIO_TEXT_OBJECTS = 0;
constexpr uint16_t MAX_TERRAIN_SURFACE_OBJECTS = 255;
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/paint/tile_element/Paint.Entrance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ static void PaintParkEntrance(PaintSession& session, uint8_t direction, int32_t
}

auto& objManager = GetContext()->GetObjectManager();
auto entrance = reinterpret_cast<EntranceObject*>(objManager.GetLoadedObject(ObjectType::ParkEntrance, 0));
auto entrance = reinterpret_cast<EntranceObject*>(
objManager.GetLoadedObject(ObjectType::ParkEntrance, entranceEl.getEntryIndex()));
auto sequence = entranceEl.GetSequenceIndex();
switch (sequence)
{
Expand Down
104 changes: 0 additions & 104 deletions src/openrct2/world/Entrance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,107 +238,3 @@ void ParkEntranceUpdateLocations()
}
}
}

StationIndex EntranceElement::GetStationIndex() const
{
return stationIndex;
}

void EntranceElement::SetStationIndex(StationIndex newStationIndex)
{
stationIndex = newStationIndex;
}

uint8_t EntranceElement::GetEntranceType() const
{
return entranceType;
}

void EntranceElement::SetEntranceType(uint8_t newType)
{
entranceType = newType;
}

RideId EntranceElement::GetRideIndex() const
{
return rideIndex;
}

void EntranceElement::SetRideIndex(RideId newRideIndex)
{
rideIndex = newRideIndex;
}

uint8_t EntranceElement::GetSequenceIndex() const
{
return SequenceIndex & 0xF;
}

void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex)
{
SequenceIndex &= ~0xF;
SequenceIndex |= (newSequenceIndex & 0xF);
}

bool EntranceElement::HasLegacyPathEntry() const
{
return (flags2 & ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) != 0;
}

ObjectEntryIndex EntranceElement::GetLegacyPathEntryIndex() const
{
if (HasLegacyPathEntry())
return PathType;

return OBJECT_ENTRY_INDEX_NULL;
}

const FootpathObject* EntranceElement::GetLegacyPathEntry() const
{
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
return static_cast<FootpathObject*>(objMgr.GetLoadedObject(ObjectType::Paths, GetLegacyPathEntryIndex()));
}

void EntranceElement::SetLegacyPathEntryIndex(ObjectEntryIndex newPathType)
{
PathType = newPathType;
flags2 |= ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY;
}

ObjectEntryIndex EntranceElement::GetSurfaceEntryIndex() const
{
if (HasLegacyPathEntry())
return OBJECT_ENTRY_INDEX_NULL;

return PathType;
}

const FootpathSurfaceObject* EntranceElement::GetSurfaceEntry() const
{
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
return static_cast<FootpathSurfaceObject*>(objMgr.GetLoadedObject(ObjectType::FootpathSurface, GetSurfaceEntryIndex()));
}

void EntranceElement::SetSurfaceEntryIndex(ObjectEntryIndex newIndex)
{
PathType = newIndex;
flags2 &= ~ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY;
}

const PathSurfaceDescriptor* EntranceElement::GetPathSurfaceDescriptor() const
{
if (HasLegacyPathEntry())
{
const auto* legacyPathEntry = GetLegacyPathEntry();
if (legacyPathEntry == nullptr)
return nullptr;

return &legacyPathEntry->GetPathSurfaceDescriptor();
}

const auto* surfaceEntry = GetSurfaceEntry();
if (surfaceEntry == nullptr)
return nullptr;

return &surfaceEntry->GetDescriptor();
}