1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 21:43:06 +01:00

Backport scenery window from NSF

Co-authored-by: IntelOrca <IntelOrca@users.noreply.github.com>
Co-authored-by: Gymnasiast <Gymnasiast@users.noreply.github.com>
This commit is contained in:
duncanspumpkin
2021-09-30 17:47:49 +01:00
parent 976d15ce10
commit fea69cc86c
8 changed files with 769 additions and 663 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1725,13 +1725,11 @@ static void window_top_toolbar_scenery_tool_down(const ScreenCoordsXY& windowPos
return;
}
ScenerySelection selectedTab = gWindowSceneryTabSelections[gWindowSceneryActiveTabIndex];
auto selectedTab = gWindowSceneryTabSelections.size() > gWindowSceneryActiveTabIndex
? gWindowSceneryTabSelections[gWindowSceneryActiveTabIndex]
: ScenerySelection{};
uint8_t sceneryType = selectedTab.SceneryType;
uint16_t selectedScenery = selectedTab.EntryIndex;
if (selectedTab.IsUndefined())
return;
CoordsXY gridPos;
switch (sceneryType)
@@ -2623,8 +2621,12 @@ static void top_toolbar_tool_update_scenery(const ScreenCoordsXY& screenPos)
if (gWindowSceneryEyedropperEnabled)
return;
ScenerySelection selection = gWindowSceneryTabSelections[gWindowSceneryActiveTabIndex];
if (gWindowSceneryActiveTabIndex >= gWindowSceneryTabSelections.size())
{
scenery_remove_ghost_tool_placement();
return;
}
const auto& selection = gWindowSceneryTabSelections[gWindowSceneryActiveTabIndex];
if (selection.IsUndefined())
{
scenery_remove_ghost_tool_placement();

View File

@@ -23,8 +23,8 @@ struct Vehicle;
enum class GuestListFilterType : int32_t;
enum class ScatterToolDensity : uint8_t;
extern ScenerySelection gWindowSceneryTabSelections[];
extern uint8_t gWindowSceneryActiveTabIndex;
extern std::vector<ScenerySelection> gWindowSceneryTabSelections;
extern size_t gWindowSceneryActiveTabIndex;
extern bool gWindowSceneryScatterEnabled;
extern uint16_t gWindowSceneryScatterSize;
extern ScatterToolDensity gWindowSceneryScatterDensity;

View File

@@ -309,12 +309,6 @@ struct ride_variables
int32_t var_486;
};
struct scenery_variables
{
ScenerySelection SelectedScenery;
int16_t hover_counter;
};
struct track_list_variables
{
bool track_list_being_updated;
@@ -525,9 +519,9 @@ enum
#define WC_RIDE_CONSTRUCTION__WIDX_ENTRANCE 29
#define WC_RIDE_CONSTRUCTION__WIDX_EXIT 30
#define WC_RIDE_CONSTRUCTION__WIDX_ROTATE 32
#define WC_SCENERY__WIDX_SCENERY_TAB_1 4
#define WC_SCENERY__WIDX_SCENERY_ROTATE_OBJECTS_BUTTON 25
#define WC_SCENERY__WIDX_SCENERY_EYEDROPPER_BUTTON 30
#define WC_SCENERY__WIDX_SCENERY_TAB_1 12
#define WC_SCENERY__WIDX_SCENERY_ROTATE_OBJECTS_BUTTON 5
#define WC_SCENERY__WIDX_SCENERY_EYEDROPPER_BUTTON 10
#define WC_PEEP__WIDX_PATROL 10
#define WC_PEEP__WIDX_ACTION_LBL 13
#define WC_PEEP__WIDX_PICKUP 14

View File

@@ -63,7 +63,6 @@ struct rct_window
news_variables news;
map_variables map;
ride_variables ride;
scenery_variables scenery;
track_list_variables track_list;
error_variables error;
void* custom_info;

View File

@@ -26,6 +26,7 @@
#include "Climate.h"
#include "Footpath.h"
#include "Fountain.h"
#include "LargeScenery.h"
#include "Map.h"
#include "Park.h"
#include "SmallScenery.h"
@@ -52,6 +53,8 @@ int16_t gSceneryCtrlPressZ;
money64 gClearSceneryCost;
static std::vector<ScenerySelection> _restrictedScenery;
// rct2: 0x009A3E74
const CoordsXY SceneryQuadrantOffsets[] = { { 7, 7 }, { 7, 23 }, { 23, 23 }, { 23, 7 } };
@@ -280,3 +283,111 @@ int32_t wall_entry_get_door_sound(const WallSceneryEntry* wallEntry)
{
return (wallEntry->flags2 & WALL_SCENERY_2_DOOR_SOUND_MASK) >> WALL_SCENERY_2_DOOR_SOUND_SHIFT;
}
bool IsSceneryAvailableToBuild(ScenerySelection item)
{
if (!gCheatsIgnoreResearchStatus)
{
if (!scenery_is_invented(item))
{
return false;
}
}
if (!gCheatsSandboxMode)
{
if (IsSceneryItemRestricted(item))
{
return false;
}
}
return true;
}
static size_t GetMaxObjectsForSceneryType(uint8_t sceneryType)
{
switch (sceneryType)
{
case SCENERY_TYPE_SMALL:
return MAX_SMALL_SCENERY_OBJECTS;
case SCENERY_TYPE_PATH_ITEM:
return MAX_PATH_ADDITION_OBJECTS;
case SCENERY_TYPE_WALL:
return MAX_WALL_SCENERY_OBJECTS;
case SCENERY_TYPE_LARGE:
return MAX_LARGE_SCENERY_OBJECTS;
case SCENERY_TYPE_BANNER:
return MAX_BANNER_OBJECTS;
default:
return 0;
}
}
static SceneryEntryBase* GetSceneryEntry(ScenerySelection item)
{
switch (item.SceneryType)
{
case SCENERY_TYPE_SMALL:
return get_small_scenery_entry(item.EntryIndex);
case SCENERY_TYPE_PATH_ITEM:
return get_footpath_item_entry(item.EntryIndex);
case SCENERY_TYPE_WALL:
return get_wall_entry(item.EntryIndex);
case SCENERY_TYPE_LARGE:
return get_large_scenery_entry(item.EntryIndex);
case SCENERY_TYPE_BANNER:
return get_banner_entry(item.EntryIndex);
default:
return nullptr;
}
}
bool IsSceneryItemRestricted(ScenerySelection item)
{
auto it = std::find(_restrictedScenery.begin(), _restrictedScenery.end(), item);
return it != _restrictedScenery.end();
}
void ClearRestrictedScenery()
{
_restrictedScenery.clear();
}
std::vector<ScenerySelection>& GetRestrictedScenery()
{
return _restrictedScenery;
}
void RestrictAllMiscScenery()
{
std::vector<ScenerySelection> nonMiscScenery;
for (ObjectEntryIndex i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
{
auto sgEntry = get_scenery_group_entry(i);
if (sgEntry != nullptr)
{
for (size_t j = 0; j < sgEntry->entry_count; j++)
{
nonMiscScenery.push_back(sgEntry->scenery_entries[j]);
}
}
}
for (uint8_t sceneryType = SCENERY_TYPE_SMALL; sceneryType < SCENERY_TYPE_COUNT; sceneryType++)
{
auto maxObjects = GetMaxObjectsForSceneryType(sceneryType);
for (ObjectEntryIndex i = 0; i < maxObjects; i++)
{
ScenerySelection sceneryItem = { sceneryType, i };
auto sceneryEntry = GetSceneryEntry(sceneryItem);
if (sceneryEntry != nullptr)
{
auto it = std::find(nonMiscScenery.begin(), nonMiscScenery.end(), sceneryItem);
if (it == nonMiscScenery.end())
{
_restrictedScenery.push_back(sceneryItem);
}
}
}
}
}

View File

@@ -294,3 +294,10 @@ PathBitEntry* get_footpath_item_entry(ObjectEntryIndex entryIndex);
rct_scenery_group_entry* get_scenery_group_entry(ObjectEntryIndex entryIndex);
int32_t wall_entry_get_door_sound(const WallSceneryEntry* wallEntry);
bool IsSceneryAvailableToBuild(ScenerySelection item);
bool IsSceneryItemRestricted(ScenerySelection item);
void ClearRestrictedScenery();
void RestrictAllMiscScenery();
std::vector<ScenerySelection>& GetRestrictedScenery();

View File

@@ -18,26 +18,16 @@ constexpr auto WINDOW_SCENERY_TAB_SELECTION_UNDEFINED = std::numeric_limits<uint
struct ScenerySelection
{
uint8_t SceneryType;
ObjectEntryIndex EntryIndex;
uint8_t SceneryType{};
ObjectEntryIndex EntryIndex = OBJECT_ENTRY_INDEX_NULL;
inline bool operator==(const ScenerySelection& rhs)
inline bool operator==(const ScenerySelection& rhs) const
{
return SceneryType == rhs.SceneryType && EntryIndex == rhs.EntryIndex;
}
bool IsUndefined() const
{
return EntryIndex == WINDOW_SCENERY_TAB_SELECTION_UNDEFINED;
}
void SetUndefined()
{
EntryIndex = WINDOW_SCENERY_TAB_SELECTION_UNDEFINED;
}
static ScenerySelection CreateUndefined()
{
return ScenerySelection{ 0, WINDOW_SCENERY_TAB_SELECTION_UNDEFINED };
return EntryIndex == OBJECT_ENTRY_INDEX_NULL;
}
};