From 128cff60dbf712e7f2ef527b505723002873e935 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 28 Sep 2017 21:48:53 +0200 Subject: [PATCH] Add virtual floor painting functions. --- .../paint/tile_element/TileElement.cpp | 63 ++++++++++++++++++- src/openrct2/paint/tile_element/TileElement.h | 1 + src/openrct2/world/Map.cpp | 18 ++++++ src/openrct2/world/Map.h | 5 ++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/openrct2/paint/tile_element/TileElement.cpp b/src/openrct2/paint/tile_element/TileElement.cpp index 52cf91a113..a92a9509fd 100644 --- a/src/openrct2/paint/tile_element/TileElement.cpp +++ b/src/openrct2/paint/tile_element/TileElement.cpp @@ -17,6 +17,7 @@ #include "../../config/Config.h" #include "../../core/Math.hpp" #include "../../drawing/Drawing.h" +#include "../../Input.h" #include "../../Game.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" @@ -31,9 +32,9 @@ #include "../../sprites.h" #include "../Paint.h" #include "../Supports.h" +#include "Surface.h" #include "TileElement.h" - #ifdef __TESTPAINT__ uint16 testPaintVerticalTunnelHeight; #endif @@ -316,6 +317,8 @@ static void sub_68B3FB(paint_session * session, sint32 x, sint32 y) session->MapPosition = dword_9DE574; } while (!tile_element_is_last_for_tile(tile_element++)); + virtual_floor_paint(session); + if (!gShowSupportSegmentHeights) { return; } @@ -355,6 +358,64 @@ static void sub_68B3FB(paint_session * session, sint32 x, sint32 y) } } +void virtual_floor_paint(paint_session * session) +{ + if (!input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z | PLACE_OBJECT_MODIFIER_SHIFT_Z)) + { + return; + } + + bool showFade = false; + bool showLit = false; + + if ((gMapSelectFlags & MAP_SELECT_FLAG_ENABLE) && + session->MapPosition.x >= gMapSelectPositionA.x - gMapVirtualFloorBaseSize && + session->MapPosition.y >= gMapSelectPositionA.y - gMapVirtualFloorBaseSize && + session->MapPosition.x <= gMapSelectPositionB.x + gMapVirtualFloorBaseSize && + session->MapPosition.y <= gMapSelectPositionB.y + gMapVirtualFloorBaseSize) + { + showFade = true; + } + + if (!showFade && !(gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)) + { + return; + } + + LocationXY16 * tile; + for (tile = gMapSelectionTiles; tile->x != -1; tile++) { + if (session->MapPosition.x >= tile->x - gMapVirtualFloorBaseSize && + session->MapPosition.y >= tile->y - gMapVirtualFloorBaseSize && + session->MapPosition.x <= tile->x + gMapVirtualFloorBaseSize && + session->MapPosition.y <= tile->y + gMapVirtualFloorBaseSize) + { + showFade = true; + } + } + + if (!showFade) + { + return; + } + + for (tile = gMapSelectionTiles; tile->x != -1; tile++) { + if (session->MapPosition.x == tile->x && + session->MapPosition.y == tile->y) + { + showLit = true; + break; + } + } + + session->InteractionType = VIEWPORT_INTERACTION_ITEM_NONE; + uint32 image_id = SPR_TERRAIN_SELECTION_SQUARE | COLOUR_GREY << 24 | COLOUR_DARK_PURPLE << 19 | IMAGE_TYPE_REMAP; + if (showLit) + { + image_id = SPR_TERRAIN_SELECTION_PATROL_AREA | COLOUR_YELLOW << 19 | IMAGE_TYPE_REMAP; + } + sub_98196C(session, image_id, 0, 0, 10, 10, -1, gMapVirtualFloorHeight, get_current_rotation()); +} + void paint_util_push_tunnel_left(paint_session * session, uint16 height, uint8 type) { session->LeftTunnels[session->LeftTunnelCount] = {static_cast((height / 16)), type}; diff --git a/src/openrct2/paint/tile_element/TileElement.h b/src/openrct2/paint/tile_element/TileElement.h index 3c2da871ec..a037cabfe2 100644 --- a/src/openrct2/paint/tile_element/TileElement.h +++ b/src/openrct2/paint/tile_element/TileElement.h @@ -109,6 +109,7 @@ void scenery_paint(paint_session * session, uint8 direction, sint32 height, rct_ void fence_paint(paint_session * session, uint8 direction, sint32 height, rct_tile_element* tileElement); void large_scenery_paint(paint_session * session, uint8 direction, uint16 height, rct_tile_element *tileElement); void track_paint(paint_session * session, uint8 direction, sint32 height, rct_tile_element *tileElement); +void virtual_floor_paint(paint_session * session); #ifdef __cplusplus } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 74d7f7054a..57ddba82ad 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -25,6 +25,7 @@ #include "../interface/Window.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" +#include "../Input.h" #include "../management/Finance.h" #include "../network/network.h" #include "../OpenRCT2.h" @@ -85,6 +86,9 @@ LocationXY16 gMapSelectPositionB; LocationXYZ16 gMapSelectArrowPosition; uint8 gMapSelectArrowDirection; +uint16 gMapVirtualFloorBaseSize = 5*32; +uint16 gMapVirtualFloorHeight; + uint8 gMapGroundFlags; uint16 gWidePathTileLoopX; @@ -4729,3 +4733,17 @@ uint8 tile_element_get_ride_index(const rct_tile_element * tileElement) return 0xFF; } } + +void map_set_virtual_floor_height(sint16 height) +{ + if (gMapVirtualFloorHeight != height && input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z | PLACE_OBJECT_MODIFIER_SHIFT_Z)) + { + map_invalidate_virtual_floor_tiles(); + } + + gMapVirtualFloorHeight = height; +} + +void map_invalidate_virtual_floor_tiles() +{ +} diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 1a76199839..1dabf80f6c 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -383,6 +383,9 @@ extern LocationXY16 gMapSelectPositionB; extern LocationXYZ16 gMapSelectArrowPosition; extern uint8 gMapSelectArrowDirection; +extern uint16 gMapVirtualFloorHeight; +extern uint16 gMapVirtualFloorBaseSize; + extern uint8 gMapGroundFlags; extern rct_tile_element gTileElements[]; @@ -456,6 +459,8 @@ void map_reorganise_elements(); bool map_check_free_elements_and_reorganise(sint32 num_elements); rct_tile_element *tile_element_insert(sint32 x, sint32 y, sint32 z, sint32 flags); bool tile_element_check_address(const rct_tile_element * const element); +void map_set_virtual_floor_height(sint16 height); +void map_invalidate_virtual_floor_tiles(); typedef sint32 (CLEAR_FUNC)(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price); sint32 map_place_non_scenery_clear_func(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price);