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

211 lines
6.0 KiB
C++
Raw Normal View History

2018-05-01 17:47:00 +02:00
/*****************************************************************************
2019-03-17 08:16:15 +01:00
* Copyright (c) 2014-2019 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 "Scenery.h"
uint8_t TileElementBase::GetType() const
2018-05-01 17:47:00 +02:00
{
return this->type & TILE_ELEMENT_TYPE_MASK;
}
void TileElementBase::SetType(uint8_t newType)
{
2018-05-02 14:11:51 +02:00
this->type &= ~TILE_ELEMENT_TYPE_MASK;
this->type |= (newType & TILE_ELEMENT_TYPE_MASK);
}
uint8_t TileElementBase::GetDirection() const
{
return this->type & TILE_ELEMENT_DIRECTION_MASK;
}
void TileElementBase::SetDirection(uint8_t direction)
{
2018-05-02 14:11:51 +02:00
this->type &= ~TILE_ELEMENT_DIRECTION_MASK;
this->type |= (direction & TILE_ELEMENT_DIRECTION_MASK);
}
uint8_t TileElementBase::GetDirectionWithOffset(uint8_t offset) const
{
return ((this->type & TILE_ELEMENT_DIRECTION_MASK) + offset) & TILE_ELEMENT_DIRECTION_MASK;
}
bool TileElementBase::IsLastForTile() const
{
return (this->flags & TILE_ELEMENT_FLAG_LAST_TILE) != 0;
}
bool TileElementBase::IsGhost() const
{
return (this->flags & TILE_ELEMENT_FLAG_GHOST) != 0;
}
2019-02-26 08:50:04 +00:00
void TileElementBase::SetGhost(bool isGhost)
2019-02-25 15:08:49 +00:00
{
if (isGhost)
{
this->flags |= TILE_ELEMENT_FLAG_GHOST;
}
else
{
this->flags &= ~TILE_ELEMENT_FLAG_GHOST;
}
2019-02-25 15:08:49 +00:00
}
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;
} while (tileElement->GetType() != TILE_ELEMENT_TYPE_SURFACE);
2018-05-01 17:47:00 +02:00
return true;
}
2018-11-01 13:53:50 +01:00
BannerIndex tile_element_get_banner_index(TileElement* tileElement)
2018-05-01 17:47:00 +02:00
{
rct_scenery_entry* sceneryEntry;
2018-06-22 23:17:03 +02:00
switch (tileElement->GetType())
{
case TILE_ELEMENT_TYPE_LARGE_SCENERY:
2018-09-14 12:12:22 +02:00
sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
2019-02-14 22:41:48 +01:00
if (sceneryEntry->large_scenery.scrolling_mode == SCROLLING_MODE_NONE)
2018-06-22 23:17:03 +02:00
return BANNER_INDEX_NULL;
2018-05-01 17:47:00 +02:00
2018-09-14 12:12:22 +02:00
return tileElement->AsLargeScenery()->GetBannerIndex();
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_WALL:
2018-09-17 15:42:34 +02:00
sceneryEntry = tileElement->AsWall()->GetEntry();
2019-02-14 22:41:48 +01:00
if (sceneryEntry == nullptr || sceneryEntry->wall.scrolling_mode == SCROLLING_MODE_NONE)
2018-06-22 23:17:03 +02:00
return BANNER_INDEX_NULL;
2018-05-01 17:47:00 +02:00
2018-09-17 15:42:34 +02:00
return tileElement->AsWall()->GetBannerIndex();
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_BANNER:
2018-09-26 14:07:04 +02:00
return tileElement->AsBanner()->GetIndex();
2018-06-22 23:17:03 +02:00
default:
return BANNER_INDEX_NULL;
2018-05-01 17:47:00 +02:00
}
}
2018-11-01 13:53:50 +01:00
void tile_element_set_banner_index(TileElement* tileElement, BannerIndex bannerIndex)
2018-05-01 17:47:00 +02:00
{
switch (tileElement->GetType())
2018-05-01 17:47:00 +02:00
{
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_WALL:
2018-09-17 15:42:34 +02:00
tileElement->AsWall()->SetBannerIndex(bannerIndex);
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_TYPE_LARGE_SCENERY:
2018-09-14 12:12:22 +02:00
tileElement->AsLargeScenery()->SetBannerIndex(bannerIndex);
2018-06-22 23:17:03 +02:00
break;
case TILE_ELEMENT_TYPE_BANNER:
2018-09-26 14:07:04 +02:00
tileElement->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
}
}
2018-11-01 13:53:50 +01:00
void tile_element_remove_banner_entry(TileElement* tileElement)
2018-05-01 17:47:00 +02:00
{
2018-06-09 13:51:45 +02:00
BannerIndex bannerIndex = tile_element_get_banner_index(tileElement);
2018-05-01 17:47:00 +02:00
if (bannerIndex == BANNER_INDEX_NULL)
return;
2019-07-26 17:24:19 +01:00
auto banner = GetBanner(bannerIndex);
2018-06-22 23:17:03 +02:00
if (banner->type != BANNER_NULL)
{
2018-06-09 13:51:45 +02:00
rct_windownumber windowNumber = bannerIndex;
window_close_by_number(WC_BANNER, windowNumber);
2018-05-01 17:47:00 +02:00
banner->type = BANNER_NULL;
user_string_free(banner->string_idx);
}
}
2018-11-01 13:53:50 +01:00
uint8_t tile_element_get_ride_index(const TileElement* tileElement)
2018-05-01 17:47:00 +02:00
{
switch (tileElement->GetType())
2018-05-01 17:47:00 +02:00
{
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_TRACK:
2018-09-18 13:10:29 +02:00
return tileElement->AsTrack()->GetRideIndex();
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_ENTRANCE:
2018-09-26 12:30:27 +02:00
return tileElement->AsEntrance()->GetRideIndex();
2018-06-22 23:17:03 +02:00
case TILE_ELEMENT_TYPE_PATH:
return tileElement->AsPath()->GetRideIndex();
2018-06-22 23:17:03 +02:00
default:
2019-01-18 18:46:22 +00:00
return RIDE_ID_NULL;
2018-05-01 17:47:00 +02:00
}
}
2018-09-23 14:05:17 +02:00
2018-11-01 13:53:50 +01:00
void TileElement::ClearAs(uint8_t newType)
2018-09-23 14:05:17 +02:00
{
type = newType;
flags = 0;
base_height = 2;
clearance_height = 2;
std::fill_n(pad_04, sizeof(pad_04), 0x00);
2018-09-23 14:05:17 +02:00
}
void TileElementBase::Remove()
{
2018-11-01 13:53:50 +01:00
tile_element_remove((TileElement*)this);
}
// Rotate both of the values amount
const QuarterTile QuarterTile::Rotate(uint8_t amount) const
{
switch (amount)
{
case 0:
return QuarterTile{ *this };
break;
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 };
}
}