1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #pragma once
11 
12 #include "../world/Location.hpp"
13 #include "Window.h"
14 
15 #include <limits>
16 #include <optional>
17 #include <vector>
18 
19 struct paint_session;
20 struct RecordedPaintSession;
21 struct paint_struct;
22 struct rct_drawpixelinfo;
23 struct TileElement;
24 struct rct_window;
25 struct EntityBase;
26 struct Guest;
27 struct Staff;
28 union paint_entry;
29 
30 enum
31 {
32     VIEWPORT_FLAG_UNDERGROUND_INSIDE = (1 << 0),
33     VIEWPORT_FLAG_SEETHROUGH_RIDES = (1 << 1),
34     VIEWPORT_FLAG_SEETHROUGH_SCENERY = (1 << 2),
35     VIEWPORT_FLAG_INVISIBLE_SUPPORTS = (1 << 3),
36     VIEWPORT_FLAG_LAND_HEIGHTS = (1 << 4),
37     VIEWPORT_FLAG_TRACK_HEIGHTS = (1 << 5),
38     VIEWPORT_FLAG_PATH_HEIGHTS = (1 << 6),
39     VIEWPORT_FLAG_GRIDLINES = (1 << 7),
40     VIEWPORT_FLAG_LAND_OWNERSHIP = (1 << 8),
41     VIEWPORT_FLAG_CONSTRUCTION_RIGHTS = (1 << 9),
42     VIEWPORT_FLAG_SOUND_ON = (1 << 10),
43     VIEWPORT_FLAG_INVISIBLE_PEEPS = (1 << 11),
44     VIEWPORT_FLAG_HIDE_BASE = (1 << 12),
45     VIEWPORT_FLAG_HIDE_VERTICAL = (1 << 13),
46     VIEWPORT_FLAG_INVISIBLE_SPRITES = (1 << 14),
47     VIEWPORT_FLAG_15 = (1 << 15),
48     VIEWPORT_FLAG_SEETHROUGH_PATHS = (1 << 16),
49     VIEWPORT_FLAG_CLIP_VIEW = (1 << 17),
50     VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES = (1 << 18),
51     VIEWPORT_FLAG_TRANSPARENT_BACKGROUND = (1 << 19),
52 };
53 
54 enum class ViewportInteractionItem : uint8_t
55 {
56     None,
57     Terrain,
58     Entity,
59     Ride,
60     Water,
61     Scenery,
62     Footpath,
63     FootpathItem,
64     ParkEntrance,
65     Wall,
66     LargeScenery,
67     Label,
68     Banner
69 };
70 
71 constexpr uint16_t ViewportInteractionItemAll = std::numeric_limits<uint16_t>::max();
72 
73 struct InteractionInfo
74 {
75     InteractionInfo() = default;
76     InteractionInfo(const paint_struct* ps);
77     CoordsXY Loc;
78     union
79     {
80         TileElement* Element = nullptr;
81         EntityBase* Entity;
82     };
83     ViewportInteractionItem SpriteType = ViewportInteractionItem::None;
84 };
85 
86 #define MAX_VIEWPORT_COUNT WINDOW_LIMIT_MAX
87 
88 /**
89  * A reference counter for whether something is forcing the grid lines to show. When the counter
90  * is decremented to 0, the grid lines are hidden.
91  */
92 extern uint8_t gShowGridLinesRefCount;
93 extern uint8_t gShowLandRightsRefCount;
94 extern uint8_t gShowConstuctionRightsRefCount;
95 
96 // rct2: 0x014234BC
97 extern rct_viewport* g_music_tracking_viewport;
98 extern ScreenCoordsXY gSavedView;
99 extern ZoomLevel gSavedViewZoom;
100 extern uint8_t gSavedViewRotation;
101 
102 extern paint_entry* gNextFreePaintStruct;
103 extern uint8_t gCurrentRotation;
104 
105 void viewport_init_all();
106 std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, rct_viewport* viewport);
107 void viewport_create(rct_window* w, const ScreenCoordsXY& screenCoords, int32_t width, int32_t height, const Focus& focus);
108 void viewport_remove(rct_viewport* viewport);
109 void viewports_invalidate(const ScreenRect& screenRect, int32_t maxZoom = -1);
110 void viewport_update_position(rct_window* window);
111 void viewport_update_sprite_follow(rct_window* window);
112 void viewport_update_smart_sprite_follow(rct_window* window);
113 void viewport_update_smart_guest_follow(rct_window* window, const Guest* peep);
114 void viewport_update_smart_staff_follow(rct_window* window, const Staff* peep);
115 void viewport_update_smart_vehicle_follow(rct_window* window);
116 void viewport_render(
117     rct_drawpixelinfo* dpi, const rct_viewport* viewport, const ScreenRect& screenRect,
118     std::vector<RecordedPaintSession>* sessions = nullptr);
119 void viewport_paint(
120     const rct_viewport* viewport, rct_drawpixelinfo* dpi, const ScreenRect& screenRect,
121     std::vector<RecordedPaintSession>* sessions = nullptr);
122 
123 CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY& startCoords);
124 
125 CoordsXY viewport_coord_to_map_coord(const ScreenCoordsXY& coords, int32_t z);
126 std::optional<CoordsXY> screen_pos_to_map_pos(const ScreenCoordsXY& screenCoords, int32_t* direction);
127 
128 void show_gridlines();
129 void hide_gridlines();
130 void show_land_rights();
131 void hide_land_rights();
132 void show_construction_rights();
133 void hide_construction_rights();
134 void viewport_set_visibility(uint8_t mode);
135 
136 InteractionInfo get_map_coordinates_from_pos(const ScreenCoordsXY& screenCoords, int32_t flags);
137 InteractionInfo get_map_coordinates_from_pos_window(rct_window* window, const ScreenCoordsXY& screenCoords, int32_t flags);
138 
139 InteractionInfo set_interaction_info_from_paint_session(paint_session* session, uint16_t filter);
140 InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoords);
141 bool ViewportInteractionLeftOver(const ScreenCoordsXY& screenCoords);
142 bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords);
143 InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoords);
144 bool ViewportInteractionRightOver(const ScreenCoordsXY& screenCoords);
145 bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords);
146 
147 CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords);
148 
149 void viewport_invalidate(const rct_viewport* viewport, const ScreenRect& screenRect);
150 
151 std::optional<CoordsXY> screen_get_map_xy(const ScreenCoordsXY& screenCoords, rct_viewport** viewport);
152 std::optional<CoordsXY> screen_get_map_xy_with_z(const ScreenCoordsXY& screenCoords, int32_t z);
153 std::optional<CoordsXY> screen_get_map_xy_quadrant(const ScreenCoordsXY& screenCoords, uint8_t* quadrant);
154 std::optional<CoordsXY> screen_get_map_xy_quadrant_with_z(const ScreenCoordsXY& screenCoords, int32_t z, uint8_t* quadrant);
155 std::optional<CoordsXY> screen_get_map_xy_side(const ScreenCoordsXY& screenCoords, uint8_t* side);
156 std::optional<CoordsXY> screen_get_map_xy_side_with_z(const ScreenCoordsXY& screenCoords, int32_t z, uint8_t* side);
157 
158 uint8_t get_current_rotation();
159 int32_t get_height_marker_offset();
160 
161 void viewport_set_saved_view();
162