OpenRCT2/test/testpaint/Compat.cpp

320 lines
9.9 KiB
C++
Raw Normal View History

2016-08-24 13:19:25 +02:00
/*****************************************************************************
* Copyright (c) 2014-2018 OpenRCT2 developers
2016-08-24 13:19:25 +02:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-08-24 13:19:25 +02:00
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-08-24 13:19:25 +02:00
*****************************************************************************/
2018-05-15 12:54:58 +02:00
#include "Addresses.h"
2017-02-20 21:05:59 +01:00
#include <openrct2/config/Config.h>
2018-01-06 00:08:58 +01:00
#include <openrct2/interface/Colour.h>
2018-01-06 00:45:53 +01:00
#include <openrct2/interface/Viewport.h>
2018-05-15 12:54:58 +02:00
#include <openrct2/object/Object.h>
#include <openrct2/paint/tile_element/Paint.TileElement.h>
2017-12-31 13:21:34 +01:00
#include <openrct2/ride/Ride.h>
2017-10-17 13:51:47 +02:00
#include <openrct2/ride/Track.h>
2018-05-15 12:54:58 +02:00
#include <openrct2/world/Location.hpp>
2018-01-11 10:59:26 +01:00
#include <openrct2/world/Sprite.h>
2018-05-01 20:21:21 +02:00
#include <openrct2/world/Surface.h>
2016-09-12 17:37:57 +02:00
2017-12-04 19:57:41 +01:00
#define gRideEntries RCT2_ADDRESS(0x009ACFA4, rct_ride_entry *)
#define gTileElementTilePointers RCT2_ADDRESS(0x013CE9A4, rct_tile_element *)
rct_sprite *sprite_list = RCT2_ADDRESS(0x010E63BC, rct_sprite);
2017-12-03 23:07:24 +01:00
Ride gRideList[MAX_RIDES];
int16_t gMapSizeUnits;
int16_t gMapBaseZ;
2016-09-12 17:37:57 +02:00
bool gTrackDesignSaveMode = false;
uint8_t gTrackDesignSaveRideIndex = 255;
uint8_t gClipHeight = 255;
2018-05-15 12:54:58 +02:00
LocationXY8 gClipSelectionA = { 0, 0 };
LocationXY8 gClipSelectionB = { MAXIMUM_MAP_SIZE_TECHNICAL - 1, MAXIMUM_MAP_SIZE_TECHNICAL - 1 };
uint32_t gCurrentViewportFlags;
uint32_t gScenarioTicks;
uint8_t gCurrentRotation;
2016-08-24 13:19:25 +02:00
2018-05-03 13:17:00 +02:00
const CoordsXY CoordsDirectionDelta[] = {
{ -32, 0 },
{ 0, +32 },
{ +32, 0 },
{ 0, -32 },
{ -32, +32 },
{ +32, +32 },
{ +32, -32 },
{ -32, -32 }
};
const TileCoordsXY TileDirectionDelta[] = {
{ -1, 0 },
{ 0, +1 },
{ +1, 0 },
{ 0, -1 },
{ -1, +1 },
{ +1, +1 },
{ +1, -1 },
{ -1, -1 }
2016-08-24 13:19:25 +02:00
};
TileCoordsXYZD ride_get_entrance_location(const Ride * ride, const int32_t stationIndex);
TileCoordsXYZD ride_get_exit_location(const Ride * ride, const int32_t stationIndex);
uint8_t get_current_rotation() {
return gCurrentRotation & 3;
2016-08-24 13:19:25 +02:00
}
const uint32_t construction_markers[] = {
COLOUR_DARK_GREEN << 19 | COLOUR_GREY << 24 | IMAGE_TYPE_REMAP, // White
2 << 19 | 0b110000 << 19 | IMAGE_TYPE_TRANSPARENT, // Translucent
2016-08-24 13:19:25 +02:00
};
int object_entry_group_counts[] = {
128, // rides
252, // small scenery
128, // large scenery
128, // walls
32, // banners
16, // paths
15, // path bits
19, // scenery sets
1, // park entrance
1, // water
1 // scenario text
2016-08-24 13:19:25 +02:00
};
2017-02-21 07:29:06 +01:00
GeneralConfiguration gConfigGeneral;
uint16_t gMapSelectFlags;
uint16_t gMapSelectType;
LocationXY16 gMapSelectPositionA;
LocationXY16 gMapSelectPositionB;
LocationXYZ16 gMapSelectArrowPosition;
uint8_t gMapSelectArrowDirection;
2016-08-24 13:19:25 +02:00
void entrance_paint(paint_session * session, uint8_t direction, int height, const rct_tile_element * tile_element) {}
void banner_paint(paint_session * session, uint8_t direction, int height, const rct_tile_element * tile_element) {}
void surface_paint(paint_session * session, uint8_t direction, uint16_t height, const rct_tile_element * tileElement) {}
void path_paint(paint_session * session, uint16_t height, const rct_tile_element * tileElement) {}
void scenery_paint(paint_session * session, uint8_t direction, int height, const rct_tile_element * tileElement) {}
void fence_paint(paint_session * session, uint8_t direction, int height, const rct_tile_element * tileElement) {}
void large_scenery_paint(paint_session * session, uint8_t direction, uint16_t height, const rct_tile_element * tileElement) {}
2016-08-24 13:19:25 +02:00
2017-09-12 11:29:43 +02:00
Ride *get_ride(int index) {
if (index < 0 || index >= MAX_RIDES) {
log_error("invalid index %d for ride", index);
2018-01-29 17:06:01 +01:00
return nullptr;
}
return &gRideList[index];
2016-08-24 13:19:25 +02:00
}
rct_ride_entry *get_ride_entry(int index) {
if (index < 0 || index >= object_entry_group_counts[OBJECT_TYPE_RIDE]) {
log_error("invalid index %d for ride type", index);
2018-01-29 17:06:01 +01:00
return nullptr;
}
return gRideEntries[index];
2016-08-24 13:19:25 +02:00
}
2017-09-12 11:29:43 +02:00
rct_ride_entry *get_ride_entry_by_ride(Ride *ride) {
rct_ride_entry * type = get_ride_entry(ride->subtype);
2018-01-29 17:06:01 +01:00
if (type == nullptr) {
log_error("Invalid ride subtype for ride");
}
return type;
2016-08-24 13:19:25 +02:00
}
rct_sprite *get_sprite(size_t sprite_idx) {
assert(sprite_idx < MAX_SPRITES);
return &sprite_list[sprite_idx];
2016-08-24 13:19:25 +02:00
}
2018-05-24 13:13:51 +02:00
bool rct_tile_element::IsLastForTile() const
{
return (this->flags & TILE_ELEMENT_FLAG_LAST_TILE) != 0;
2016-08-24 13:19:25 +02:00
}
uint8_t rct_tile_element::GetType() const
{
return this->type & TILE_ELEMENT_TYPE_MASK;
2016-08-24 13:19:25 +02:00
}
2017-10-31 12:57:40 +01:00
int tile_element_get_direction(const rct_tile_element *element) {
return element->type & TILE_ELEMENT_DIRECTION_MASK;
2016-08-24 13:19:25 +02:00
}
int tile_element_get_direction_with_offset(const rct_tile_element *element, uint8_t offset) {
2017-10-31 12:57:40 +01:00
return ((element->type & TILE_ELEMENT_DIRECTION_MASK) + offset) & TILE_ELEMENT_DIRECTION_MASK;
}
2017-10-31 12:57:40 +01:00
rct_tile_element *map_get_first_element_at(int x, int y) {
if (x < 0 || y < 0 || x > 255 || y > 255) {
log_error("Trying to access element outside of range");
2018-01-29 17:06:01 +01:00
return nullptr;
}
2017-10-31 14:03:45 +01:00
return gTileElementTilePointers[x + y * 256];
2016-08-24 13:19:25 +02:00
}
2017-10-31 14:03:45 +01:00
int tile_element_get_station(const rct_tile_element * tileElement) {
return (tileElement->properties.track.sequence & MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK) >> 4;
}
void tile_element_set_station(rct_tile_element * tileElement, uint32_t stationIndex)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence &= ~MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK;
tileElement->properties.track.sequence |= (stationIndex << 4);
2016-08-24 13:19:25 +02:00
}
int32_t tile_element_get_track_sequence(const rct_tile_element * tileElement)
{
2017-10-31 14:03:45 +01:00
return tileElement->properties.track.sequence & MAP_ELEM_TRACK_SEQUENCE_SEQUENCE_MASK;
}
2017-10-31 14:03:45 +01:00
void tile_element_set_track_sequence(rct_tile_element * tileElement, int trackSequence)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence &= ~MAP_ELEM_TRACK_SEQUENCE_SEQUENCE_MASK;
tileElement->properties.track.sequence |= (trackSequence & MAP_ELEM_TRACK_SEQUENCE_SEQUENCE_MASK);
}
2017-10-31 14:03:45 +01:00
bool tile_element_get_green_light(const rct_tile_element * tileElement)
{
2017-10-31 14:03:45 +01:00
return (tileElement->properties.track.sequence & MAP_ELEM_TRACK_SEQUENCE_GREEN_LIGHT) != 0;
}
2017-10-31 14:03:45 +01:00
void tile_element_set_green_light(rct_tile_element * tileElement, bool greenLight)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence &= ~MAP_ELEM_TRACK_SEQUENCE_GREEN_LIGHT;
if (greenLight)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence |= MAP_ELEM_TRACK_SEQUENCE_GREEN_LIGHT;
}
}
2017-10-31 14:03:45 +01:00
int tile_element_get_brake_booster_speed(const rct_tile_element *tileElement)
{
2017-10-31 14:03:45 +01:00
return (tileElement->properties.track.sequence >> 4) << 1;
}
2017-10-31 14:03:45 +01:00
void tile_element_set_brake_booster_speed(rct_tile_element *tileElement, int speed)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence = tile_element_get_track_sequence(tileElement) | ((speed >> 1) << 4);
}
2017-10-31 14:03:45 +01:00
bool tile_element_is_taking_photo(const rct_tile_element * tileElement)
{
2017-10-31 14:03:45 +01:00
return (tileElement->properties.track.sequence & MAP_ELEM_TRACK_SEQUENCE_TAKING_PHOTO_MASK) != 0;
}
2017-10-31 14:03:45 +01:00
void tile_element_set_onride_photo_timeout(rct_tile_element * tileElement)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence &= MAP_ELEM_TRACK_SEQUENCE_SEQUENCE_MASK;
tileElement->properties.track.sequence |= (3 << 4);
}
2017-10-31 14:03:45 +01:00
void tile_element_decrement_onride_photo_timout(rct_tile_element * tileElement)
{
// We should only touch the upper 4 bits, avoid underflow into the lower 4.
2017-10-31 14:03:45 +01:00
if (tileElement->properties.track.sequence & MAP_ELEM_TRACK_SEQUENCE_TAKING_PHOTO_MASK)
{
2017-10-31 14:03:45 +01:00
tileElement->properties.track.sequence -= (1 << 4);
}
}
int32_t surface_get_water_height(const rct_tile_element * tileElement)
2017-07-27 17:15:56 +02:00
{
return tileElement->properties.surface.terrain & TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK;
2017-07-27 17:15:56 +02:00
}
2016-08-24 13:19:25 +02:00
bool ride_type_has_flag(int rideType, int flag)
{
return (RideProperties[rideType].flags & flag) != 0;
2016-08-24 13:19:25 +02:00
}
2016-09-12 22:56:52 +02:00
int16_t get_height_marker_offset()
2016-09-12 22:56:52 +02:00
{
return 0;
2016-09-12 22:56:52 +02:00
}
2018-02-11 23:45:27 +01:00
bool track_element_is_lift_hill(const rct_tile_element *trackElement)
{
return trackElement->type & 0x80;
}
2018-02-11 23:45:27 +01:00
bool track_element_is_cable_lift(const rct_tile_element *trackElement)
{
return trackElement->properties.track.colour & TRACK_ELEMENT_COLOUR_FLAG_CABLE_LIFT;
}
2016-10-09 04:35:39 +02:00
2018-02-11 23:45:27 +01:00
bool track_element_is_inverted(const rct_tile_element *trackElement)
2016-10-09 04:35:39 +02:00
{
return trackElement->properties.track.colour & TRACK_ELEMENT_COLOUR_FLAG_INVERTED;
2016-10-09 04:35:39 +02:00
}
2017-11-16 10:34:22 +01:00
void track_element_set_inverted(rct_tile_element * tileElement, bool inverted)
{
if (inverted)
{
tileElement->properties.track.colour |= TRACK_ELEMENT_COLOUR_FLAG_INVERTED;
}
else
{
tileElement->properties.track.colour &= ~TRACK_ELEMENT_COLOUR_FLAG_INVERTED;
}
}
bool is_csg_loaded()
{
return false;
}
2017-10-04 17:14:53 +02:00
uint8_t track_element_get_colour_scheme(const rct_tile_element * tileElement)
2017-10-04 17:14:53 +02:00
{
2017-10-31 14:03:45 +01:00
return tileElement->properties.track.colour & 0x3;
2017-10-04 17:14:53 +02:00
}
2017-11-14 13:27:30 +01:00
uint16_t track_element_get_maze_entry(const rct_tile_element * tileElement)
2017-11-14 13:27:30 +01:00
{
return tileElement->properties.track.maze_entry;
}
uint8_t track_element_get_ride_index(const rct_tile_element * tileElement)
2017-11-14 13:27:30 +01:00
{
return tileElement->properties.track.ride_index;
}
void track_element_set_ride_index(rct_tile_element * tileElement, uint8_t rideIndex)
2017-11-14 13:27:30 +01:00
{
tileElement->properties.track.ride_index = rideIndex;
}
uint8_t track_element_get_type(const rct_tile_element * tileElement)
{
return tileElement->properties.track.type;
}
void track_element_set_type(rct_tile_element * tileElement, uint8_t type)
{
tileElement->properties.track.type = type;
}
void track_element_set_cable_lift(rct_tile_element * trackElement)
{
trackElement->properties.track.colour |= TRACK_ELEMENT_COLOUR_FLAG_CABLE_LIFT;
}
void track_element_clear_cable_lift(rct_tile_element * trackElement)
{
trackElement->properties.track.colour &= ~TRACK_ELEMENT_COLOUR_FLAG_CABLE_LIFT;
2018-01-04 13:36:08 +01:00
}
TileCoordsXYZD ride_get_entrance_location(const Ride * ride, const int32_t stationIndex)
{
return ride->entrances[stationIndex];
}
TileCoordsXYZD ride_get_exit_location(const Ride * ride, const int32_t stationIndex)
{
return ride->exits[stationIndex];
2018-05-15 12:54:58 +02:00
}