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"
|
2020-07-06 10:10:39 -03:00
|
|
|
#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++;
|
2018-05-24 11:44:53 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 11:28:39 +01:00
|
|
|
BannerIndex TileElement::GetBannerIndex() const
|
2018-05-01 17:47:00 +02:00
|
|
|
{
|
2021-01-02 11:28:39 +01:00
|
|
|
switch (GetType())
|
2018-06-22 23:17:03 +02:00
|
|
|
{
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::LargeScenery:
|
2021-06-04 12:41:23 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2021-01-02 11:28:39 +01:00
|
|
|
return AsLargeScenery()->GetBannerIndex();
|
2021-06-04 12:41:23 +01:00
|
|
|
}
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Wall:
|
2021-06-03 13:26:00 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2021-01-02 11:28:39 +01:00
|
|
|
return AsWall()->GetBannerIndex();
|
2021-06-03 13:26:00 +01:00
|
|
|
}
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Banner:
|
2021-01-02 11:28:39 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 11:28:39 +01:00
|
|
|
void TileElement::SetBannerIndex(BannerIndex bannerIndex)
|
2018-05-01 17:47:00 +02:00
|
|
|
{
|
2021-01-02 11:28:39 +01:00
|
|
|
switch (GetType())
|
2018-05-01 17:47:00 +02:00
|
|
|
{
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Wall:
|
2021-01-02 11:28:39 +01:00
|
|
|
AsWall()->SetBannerIndex(bannerIndex);
|
2018-06-22 23:17:03 +02:00
|
|
|
break;
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::LargeScenery:
|
2021-01-02 11:28:39 +01:00
|
|
|
AsLargeScenery()->SetBannerIndex(bannerIndex);
|
2018-06-22 23:17:03 +02:00
|
|
|
break;
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Banner:
|
2021-01-02 11:28:39 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 11:28:39 +01:00
|
|
|
void TileElement::RemoveBannerEntry()
|
2018-05-01 17:47:00 +02:00
|
|
|
{
|
2021-01-02 11:28:39 +01: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
|
|
|
{
|
2020-10-27 21:59:55 +01:00
|
|
|
switch (GetType())
|
2018-05-01 17:47:00 +02:00
|
|
|
{
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Track:
|
2020-10-27 21:59:55 +01:00
|
|
|
return AsTrack()->GetRideIndex();
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Entrance:
|
2020-10-27 21:59:55 +01:00
|
|
|
return AsEntrance()->GetRideIndex();
|
2021-12-11 00:39:39 +01:00
|
|
|
case TileElementType::Path:
|
2020-10-27 21:59:55 +01:00
|
|
|
return AsPath()->GetRideIndex();
|
2018-06-22 23:17:03 +02:00
|
|
|
default:
|
2022-01-19 18:24:23 +02:00
|
|
|
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);
|
2019-08-24 22:41:01 +02:00
|
|
|
std::fill_n(pad_08, sizeof(pad_08), 0x00);
|
2018-09-23 14:05:17 +02:00
|
|
|
}
|
2018-09-26 13:20:47 +02:00
|
|
|
|
2019-02-20 08:32:34 +00: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 };
|
|
|
|
|
}
|
|
|
|
|
}
|