Skip to content

Commit

Permalink
Move gLastEntranceStyle to GameState_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-Hopkinson committed Mar 9, 2024
1 parent d0592e0 commit 048276b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/openrct2-ui/ride/Construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Construction.h"

#include <openrct2/GameState.h>
#include <openrct2/actions/RideCreateAction.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideConstruction.h>
Expand All @@ -28,7 +29,8 @@ void RideConstructNew(RideSelection listItem)
int32_t colour1 = RideGetRandomColourPresetIndex(listItem.Type);
int32_t colour2 = RideGetUnusedPresetVehicleColour(rideEntryIndex);

auto gameAction = RideCreateAction(listItem.Type, listItem.EntryIndex, colour1, colour2, gLastEntranceStyle);
auto gameAction = RideCreateAction(
listItem.Type, listItem.EntryIndex, colour1, colour2, OpenRCT2::GetGameState().LastEntranceStyle);

gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) {
if (result->Error != GameActions::Status::Ok)
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2-ui/windows/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4322,7 +4322,7 @@ class RideWindow final : public Window
rideSetAppearanceAction.SetCallback([objIndex](const GameAction*, const GameActions::Result* res) {
if (res->Error != GameActions::Status::Ok)
return;
gLastEntranceStyle = objIndex;
GetGameState().LastEntranceStyle = objIndex;
});
GameActions::Execute(&rideSetAppearanceAction);
break;
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/EditorObjectSelectionSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ void FinishObjectSelection()
SetEveryRideEntryInvented();

auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
gLastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain");
if (gLastEntranceStyle == OBJECT_ENTRY_INDEX_NULL)
gameState.LastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain");
if (gameState.LastEntranceStyle == OBJECT_ENTRY_INDEX_NULL)
{
gLastEntranceStyle = 0;
gameState.LastEntranceStyle = 0;
}

gameState.EditorStep = EditorStep::RollercoasterDesigner;
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ namespace OpenRCT2
uint8_t SavedViewRotation;
ZoomLevel SavedViewZoom;

ObjectEntryIndex LastEntranceStyle;

/**
* Probability out of 65535, of gaining a new guest per game tick.
* new guests per second = 40 * (probability / 65535)
Expand Down
12 changes: 7 additions & 5 deletions src/openrct2/actions/TrackDesignAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,21 @@ GameActions::Result TrackDesignAction::Query() const
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP);
}

auto& gameState = GetGameState();
auto& objManager = GetContext()->GetObjectManager();
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.vehicle_object);
if (entryIndex == OBJECT_ENTRY_INDEX_NULL)
{
// Force a fallback if the entry is not invented yet a td6 of it is selected,
// which can happen in select-by-track-type mode
if (!RideEntryIsInvented(entryIndex) && !GetGameState().Cheats.IgnoreResearchStatus)
if (!RideEntryIsInvented(entryIndex) && !gameState.Cheats.IgnoreResearchStatus)
{
entryIndex = OBJECT_ENTRY_INDEX_NULL;
}
}

// Colours do not matter as will be overwritten
auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gLastEntranceStyle);
auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gameState.LastEntranceStyle);
rideCreateAction.SetFlags(GetFlags());
auto r = GameActions::ExecuteNested(&rideCreateAction);
if (r.Error != GameActions::Status::Ok)
Expand Down Expand Up @@ -136,20 +137,21 @@ GameActions::Result TrackDesignAction::Execute() const
res.Position.z = _loc.z;
res.Expenditure = ExpenditureType::RideConstruction;

auto& gameState = GetGameState();
auto& objManager = GetContext()->GetObjectManager();
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.vehicle_object);
if (entryIndex != OBJECT_ENTRY_INDEX_NULL)
{
// Force a fallback if the entry is not invented yet a track design using it is selected.
// This can happen on rides with multiple vehicles where some have been invented and some haven’t.
if (!RideEntryIsInvented(entryIndex) && !GetGameState().Cheats.IgnoreResearchStatus)
if (!RideEntryIsInvented(entryIndex) && !gameState.Cheats.IgnoreResearchStatus)
{
entryIndex = OBJECT_ENTRY_INDEX_NULL;
}
}

// Colours do not matter as will be overwritten
auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gLastEntranceStyle);
auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gameState.LastEntranceStyle);
rideCreateAction.SetFlags(GetFlags());
auto r = GameActions::ExecuteNested(&rideCreateAction);
if (r.Error != GameActions::Status::Ok)
Expand Down Expand Up @@ -247,7 +249,7 @@ GameActions::Result TrackDesignAction::Execute() const
ride->entrance_style = objManager.GetLoadedObjectEntryIndex(_td.StationObjectIdentifier);
if (ride->entrance_style == OBJECT_ENTRY_INDEX_NULL)
{
ride->entrance_style = gLastEntranceStyle;
ride->entrance_style = gameState.LastEntranceStyle;
}

for (int32_t i = 0; i < Limits::NumColourSchemes; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ namespace OpenRCT2
cs.Write(static_cast<int8_t>(gameState.SavedViewZoom));
}
cs.ReadWrite(gameState.SavedViewRotation);
cs.ReadWrite(gLastEntranceStyle);
cs.ReadWrite(gameState.LastEntranceStyle);
cs.ReadWrite(gameState.EditorStep);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ namespace RCT2
| (static_cast<uint64_t>(_s6.SamePriceThroughoutExtended) << 32);
gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests;
gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays;
gLastEntranceStyle = _s6.LastEntranceStyle;
gameState.LastEntranceStyle = _s6.LastEntranceStyle;
// rct1_water_colour
// Pad01358842
ImportResearchList(gameState);
Expand Down
2 changes: 0 additions & 2 deletions src/openrct2/ride/Ride.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,6 @@ std::string_view GetRideEntryName(ObjectEntryIndex index);

extern const StringId ColourSchemeNames[4];

extern ObjectEntryIndex gLastEntranceStyle;

int32_t RideGetCount();
void RideInitAll();
void ResetAllRideBuildDates();
Expand Down
2 changes: 0 additions & 2 deletions src/openrct2/ride/RideConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ uint8_t _currentSeatRotationAngle;

CoordsXYZD _unkF440C5;

ObjectEntryIndex gLastEntranceStyle;

uint8_t gRideEntranceExitPlaceType;
RideId gRideEntranceExitPlaceRideIndex;
StationIndex gRideEntranceExitPlaceStationIndex;
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/ride/TrackDesign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ int32_t TrackDesignGetZPlacement(TrackDesign* td6, Ride& ride, const CoordsXYZD&
static money64 TrackDesignCreateRide(int32_t type, int32_t subType, int32_t flags, RideId* outRideIndex)
{
// Don't set colours as will be set correctly later.
auto gameAction = RideCreateAction(type, subType, 0, 0, gLastEntranceStyle);
auto gameAction = RideCreateAction(type, subType, 0, 0, GetGameState().LastEntranceStyle);
gameAction.SetFlags(flags);

auto res = GameActions::ExecuteNested(&gameAction);
Expand All @@ -1900,6 +1900,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon
*outRide = nullptr;
*flags = 0;

auto& gameState = GetGameState();
auto& objManager = GetContext()->GetObjectManager();
auto entry_index = objManager.GetLoadedObjectEntryIndex(td6->vehicle_object);

Expand All @@ -1919,7 +1920,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon
ride->entrance_style = objManager.GetLoadedObjectEntryIndex(td6->StationObjectIdentifier);
if (ride->entrance_style == OBJECT_ENTRY_INDEX_NULL)
{
ride->entrance_style = gLastEntranceStyle;
ride->entrance_style = gameState.LastEntranceStyle;
}

for (int32_t i = 0; i < OpenRCT2::Limits::NumColourSchemes; i++)
Expand All @@ -1939,7 +1940,6 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon
}
}

auto& gameState = GetGameState();
_trackDesignDrawingPreview = true;
uint8_t backup_rotation = _currentTrackPieceDirection;
uint32_t backup_park_flags = gameState.ParkFlags;
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/scenario/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ void ScenarioReset(GameState_t& gameState)
Staff::ResetStats();

auto& objManager = GetContext()->GetObjectManager();
gLastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain");
if (gLastEntranceStyle == OBJECT_ENTRY_INDEX_NULL)
gameState.LastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain");
if (gameState.LastEntranceStyle == OBJECT_ENTRY_INDEX_NULL)
{
// Fall back to first entrance object
gLastEntranceStyle = 0;
gameState.LastEntranceStyle = 0;
}

gMarketingCampaigns.clear();
Expand Down

0 comments on commit 048276b

Please sign in to comment.