Files
OpenRCT2-Web/src/openrct2/world/TileElement.cpp
T

157 lines
4.6 KiB
C++
Raw Normal View History

2018-05-01 17:47:00 +02:00
/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
2018-06-15 14:07:34 +02:00
*
* 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.
*****************************************************************************/
2018-05-01 17:47:00 +02:00
2018-06-22 23:17:03 +02:00
#include "TileElement.h"
2018-05-01 17:47:00 +02:00
#include "../core/Guard.hpp"
#include "../interface/Window.h"
#include "../localisation/Localisation.h"
#include "../ride/Track.h"
#include "Banner.h"
#include "LargeScenery.h"
#include "Location.hpp"
2018-05-01 17:47:00 +02:00
#include "Scenery.h"
2018-11-01 13:53:50 +01:00
bool tile_element_is_underground(TileElement* tileElement)
2018-05-01 17:47:00 +02:00
{
2018-06-22 23:17:03 +02:00
do
{
2018-05-01 17:47:00 +02:00
tileElement++;
if ((tileElement - 1)->IsLastForTile())
2018-05-01 17:47:00 +02:00
return false;
2021-12-11 00:39:39 +01:00
} while (tileElement->GetType() != TileElementType::Surface);
2018-05-01 17:47:00 +02:00
return true;
}
BannerIndex TileElement::GetBannerIndex() const
2018-05-01 17:47:00 +02:00
{
switch (GetType())
2018-06-22 23:17:03 +02:00
{
2021-12-11 00:39:39 +01:00
case TileElementType::LargeScenery:
{
auto* sceneryEntry = AsLargeScenery()->GetEntry();
if (sceneryEntry == nullptr || sceneryEntry->scrolling_mode == SCROLLING_MODE_NONE)
2021-11-24 22:25:36 +02:00
return BannerIndex::GetNull();
2018-05-01 17:47:00 +02:00
return AsLargeScenery()->GetBannerIndex();
}
2021-12-11 00:39:39 +01:00
case TileElementType::Wall:
{
auto* wallEntry = AsWall()->GetEntry();
if (wallEntry == nullptr || wallEntry->scrolling_mode == SCROLLING_MODE_NONE)
2021-11-24 22:25:36 +02:00
return BannerIndex::GetNull();
2018-05-01 17:47:00 +02:00
return AsWall()->GetBannerIndex();
}
2021-12-11 00:39:39 +01:00
case TileElementType::Banner:
return AsBanner()->GetIndex();
2018-06-22 23:17:03 +02:00
default:
2021-11-24 22:25:36 +02:00
return BannerIndex::GetNull();
2018-05-01 17:47:00 +02:00
}
}
void TileElement::SetBannerIndex(BannerIndex bannerIndex)
2018-05-01 17:47:00 +02:00
{
switch (GetType())
2018-05-01 17:47:00 +02:00
{
2021-12-11 00:39:39 +01:00
case TileElementType::Wall:
AsWall()->SetBannerIndex(bannerIndex);
2018-06-22 23:17:03 +02:00
break;
2021-12-11 00:39:39 +01:00
case TileElementType::LargeScenery:
AsLargeScenery()->SetBannerIndex(bannerIndex);
2018-06-22 23:17:03 +02:00
break;
2021-12-11 00:39:39 +01:00
case TileElementType::Banner:
AsBanner()->SetIndex(bannerIndex);
2018-06-22 23:17:03 +02:00
break;
default:
log_error("Tried to set banner index on unsuitable tile element!");
Guard::Assert(false);
2018-05-01 17:47:00 +02:00
}
}
void TileElement::RemoveBannerEntry()
2018-05-01 17:47:00 +02:00
{
auto bannerIndex = GetBannerIndex();
2019-07-26 17:24:19 +01:00
auto banner = GetBanner(bannerIndex);
2019-07-21 17:40:52 +01:00
if (banner != nullptr)
2018-06-22 23:17:03 +02:00
{
2021-11-24 19:58:07 +02:00
window_close_by_number(WC_BANNER, bannerIndex.ToUnderlying());
2021-07-27 10:25:58 +01:00
DeleteBanner(banner->id);
2018-05-01 17:47:00 +02:00
}
}
2022-01-19 15:17:11 +02:00
RideId TileElement::GetRideIndex() const
2018-05-01 17:47:00 +02:00
{
switch (GetType())
2018-05-01 17:47:00 +02:00
{
2021-12-11 00:39:39 +01:00
case TileElementType::Track:
return AsTrack()->GetRideIndex();
2021-12-11 00:39:39 +01:00
case TileElementType::Entrance:
return AsEntrance()->GetRideIndex();
2021-12-11 00:39:39 +01:00
case TileElementType::Path:
return AsPath()->GetRideIndex();
2018-06-22 23:17:03 +02:00
default:
return RideId::GetNull();
2018-05-01 17:47:00 +02:00
}
}
2018-09-23 14:05:17 +02:00
2021-12-11 00:39:39 +01:00
void TileElement::ClearAs(TileElementType newType)
2018-09-23 14:05:17 +02:00
{
2021-12-10 22:58:27 +01:00
type = 0;
2021-12-11 00:39:39 +01:00
SetType(newType);
2020-03-04 21:47:34 +01:00
Flags = 0;
2020-03-07 21:07:18 +01:00
base_height = MINIMUM_LAND_HEIGHT;
clearance_height = MINIMUM_LAND_HEIGHT;
2021-01-29 16:56:33 +01:00
owner = 0;
std::fill_n(pad_05, sizeof(pad_05), 0x00);
std::fill_n(pad_08, sizeof(pad_08), 0x00);
2018-09-23 14:05:17 +02:00
}
// Rotate both of the values amount
const QuarterTile QuarterTile::Rotate(uint8_t amount) const
{
switch (amount)
{
case 0:
return QuarterTile{ *this };
case 1:
{
auto rotVal1 = _val << 1;
auto rotVal2 = rotVal1 >> 4;
// Clear the bit from the tileQuarter
rotVal1 &= 0b11101110;
// Clear the bit from the zQuarter
rotVal2 &= 0b00010001;
return QuarterTile{ static_cast<uint8_t>(rotVal1 | rotVal2) };
}
case 2:
{
auto rotVal1 = _val << 2;
auto rotVal2 = rotVal1 >> 4;
// Clear the bit from the tileQuarter
rotVal1 &= 0b11001100;
// Clear the bit from the zQuarter
rotVal2 &= 0b00110011;
return QuarterTile{ static_cast<uint8_t>(rotVal1 | rotVal2) };
}
case 3:
{
auto rotVal1 = _val << 3;
auto rotVal2 = rotVal1 >> 4;
// Clear the bit from the tileQuarter
rotVal1 &= 0b10001000;
// Clear the bit from the zQuarter
rotVal2 &= 0b01110111;
return QuarterTile{ static_cast<uint8_t>(rotVal1 | rotVal2) };
}
default:
log_error("Tried to rotate QuarterTile invalid amount.");
return QuarterTile{ 0 };
}
}