Files
OpenRCT2-Web/src/openrct2-ui/interface/ViewportInteraction.cpp
T

699 lines
25 KiB
C++
Raw Normal View History

2014-11-05 19:42:19 +00: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
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2014-11-05 19:42:19 +00:00
*****************************************************************************/
2018-06-22 23:20:47 +02:00
#include "Viewport.h"
#include "Window.h"
2018-08-12 12:50:40 +01:00
#include <algorithm>
2018-06-22 23:20:47 +02:00
#include <openrct2/Context.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
2019-07-21 10:33:15 +01:00
#include <openrct2/GameState.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
2019-05-14 20:54:54 +01:00
#include <openrct2/actions/BalloonPressAction.hpp>
2019-03-02 07:44:15 +00:00
#include <openrct2/actions/FootpathSceneryRemoveAction.hpp>
2019-01-03 02:20:35 +01:00
#include <openrct2/actions/LargeSceneryRemoveAction.hpp>
2019-03-24 20:41:14 +00:00
#include <openrct2/actions/ParkEntranceRemoveAction.hpp>
2019-01-03 02:20:35 +01:00
#include <openrct2/actions/SmallSceneryRemoveAction.hpp>
2018-06-22 23:20:47 +02:00
#include <openrct2/actions/WallRemoveAction.hpp>
#include <openrct2/localisation/Localisation.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/Track.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Banner.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/LargeScenery.h>
2018-06-22 23:20:47 +02:00
#include <openrct2/world/Map.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/world/Park.h>
2018-06-22 23:20:47 +02:00
#include <openrct2/world/Scenery.h>
2018-06-02 14:34:01 +01:00
#include <openrct2/world/Sprite.h>
#include <openrct2/world/Surface.h>
#include <openrct2/world/Wall.h>
2014-11-05 19:42:19 +00:00
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_scenery(TileElement* tileElement, CoordsXY mapCoords);
static void viewport_interaction_remove_footpath(TileElement* tileElement, CoordsXY mapCoords);
static void viewport_interaction_remove_footpath_item(TileElement* tileElement, CoordsXY mapCoords);
static void viewport_interaction_remove_park_wall(TileElement* tileElement, CoordsXY mapCoords);
static void viewport_interaction_remove_large_scenery(TileElement* tileElement, CoordsXY mapCoords);
static void viewport_interaction_remove_park_entrance(TileElement* tileElement, CoordsXY mapCoords);
2019-11-21 17:49:34 -03:00
static Peep* viewport_interaction_get_closest_peep(ScreenCoordsXY screenCoords, int32_t maxDistance);
2014-11-05 19:42:19 +00:00
/**
*
* rct2: 0x006ED9D0
*/
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_get_item_left(ScreenCoordsXY screenCoords, viewport_interaction_info* info)
{
2018-11-01 13:53:50 +01:00
TileElement* tileElement;
2018-06-22 23:20:47 +02:00
rct_sprite* sprite;
2020-01-19 15:53:17 +00:00
Vehicle* vehicle;
2017-06-06 23:24:18 +02:00
// No click input for title screen or scenario editor or track manager
if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER))
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2017-06-06 23:24:18 +02:00
//
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2019-11-21 17:49:34 -03:00
CoordsXY mapCoord = {};
2018-06-22 23:20:47 +02:00
get_map_coordinates_from_pos(
2019-11-21 17:49:34 -03:00
screenCoords, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK,
mapCoord, &info->type, &info->tileElement, nullptr);
2017-06-06 23:24:18 +02:00
info->x = mapCoord.x;
info->y = mapCoord.y;
2017-10-31 14:03:45 +01:00
tileElement = info->tileElement;
2020-01-19 16:54:40 +00:00
sprite = info->sprite;
2018-06-22 23:20:47 +02:00
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (sprite->generic.sprite_identifier)
2018-06-22 23:20:47 +02:00
{
case SPRITE_IDENTIFIER_VEHICLE:
vehicle = &(sprite->vehicle);
if (vehicle->ride_subtype != RIDE_ENTRY_INDEX_NULL)
2018-06-22 23:20:47 +02:00
vehicle_set_map_toolbar(vehicle);
else
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
break;
case SPRITE_IDENTIFIER_PEEP:
peep_set_map_tooltip(&sprite->peep);
break;
}
2017-06-06 23:24:18 +02:00
break;
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_RIDE:
ride_set_map_tooltip(tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
2019-07-21 10:33:15 +01:00
{
auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark();
auto parkName = park.Name.c_str();
set_map_tooltip_format_arg(0, rct_string_id, STR_STRING);
set_map_tooltip_format_arg(2, const char*, parkName);
2018-06-22 23:20:47 +02:00
break;
2019-07-21 10:33:15 +01:00
}
2018-06-22 23:20:47 +02:00
default:
info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2017-06-06 23:24:18 +02:00
break;
}
2017-06-06 23:24:18 +02:00
// If nothing is under cursor, find a close by peep
2018-06-22 23:20:47 +02:00
if (info->type == VIEWPORT_INTERACTION_ITEM_NONE)
{
2019-11-21 17:49:34 -03:00
info->peep = viewport_interaction_get_closest_peep(screenCoords, 32);
2018-01-07 21:43:07 +01:00
if (info->peep == nullptr)
2017-06-06 23:24:18 +02:00
return VIEWPORT_INTERACTION_ITEM_NONE;
2017-06-06 23:24:18 +02:00
info->type = VIEWPORT_INTERACTION_ITEM_SPRITE;
info->x = info->peep->x;
info->y = info->peep->y;
peep_set_map_tooltip(info->peep);
}
2017-06-06 23:24:18 +02:00
return info->type;
}
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_left_over(ScreenCoordsXY screenCoords)
{
2017-06-06 23:24:18 +02:00
viewport_interaction_info info;
2019-11-21 17:49:34 -03:00
switch (viewport_interaction_get_item_left(screenCoords, &info))
2018-06-22 23:20:47 +02:00
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
case VIEWPORT_INTERACTION_ITEM_RIDE:
case VIEWPORT_INTERACTION_ITEM_PARK:
return 1;
default:
return 0;
2017-06-06 23:24:18 +02:00
}
}
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_left_click(ScreenCoordsXY screenCoords)
{
2017-06-06 23:24:18 +02:00
viewport_interaction_info info;
2019-11-21 17:49:34 -03:00
switch (viewport_interaction_get_item_left(screenCoords, &info))
2018-06-22 23:20:47 +02:00
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (info.sprite->generic.sprite_identifier)
2018-06-22 23:20:47 +02:00
{
case SPRITE_IDENTIFIER_VEHICLE:
{
auto intent = Intent(WD_VEHICLE);
intent.putExtra(INTENT_EXTRA_VEHICLE, info.vehicle);
context_open_intent(&intent);
2017-06-06 23:24:18 +02:00
break;
}
2018-06-22 23:20:47 +02:00
case SPRITE_IDENTIFIER_PEEP:
{
auto intent = Intent(WC_PEEP);
intent.putExtra(INTENT_EXTRA_PEEP, info.peep);
context_open_intent(&intent);
break;
}
case SPRITE_IDENTIFIER_MISC:
if (game_is_not_paused())
{
switch (info.sprite->generic.type)
2018-06-22 23:20:47 +02:00
{
case SPRITE_MISC_BALLOON:
2019-05-14 20:54:54 +01:00
{
auto balloonPress = BalloonPressAction(info.sprite->AsBalloon()->sprite_index);
GameActions::Execute(&balloonPress);
}
break;
2018-06-22 23:20:47 +02:00
case SPRITE_MISC_DUCK:
duck_press(&info.sprite->duck);
break;
}
}
break;
2017-06-06 23:24:18 +02:00
}
2018-06-22 23:20:47 +02:00
return 1;
case VIEWPORT_INTERACTION_ITEM_RIDE:
{
auto intent = Intent(WD_TRACK);
intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.tileElement);
context_open_intent(&intent);
return true;
2017-06-06 23:24:18 +02:00
}
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_PARK:
context_open_window(WC_PARK_INFORMATION);
return 1;
default:
return 0;
2017-06-06 23:24:18 +02:00
}
}
2014-11-05 19:42:19 +00:00
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006EDE88
*/
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_get_item_right(ScreenCoordsXY screenCoords, viewport_interaction_info* info)
2014-11-05 19:42:19 +00:00
{
2018-11-01 13:53:50 +01:00
TileElement* tileElement;
2018-06-22 23:20:47 +02:00
rct_scenery_entry* sceneryEntry;
Ride* ride;
int32_t i, stationIndex;
2014-11-05 19:42:19 +00:00
2017-06-06 23:24:18 +02:00
// No click input for title screen or track manager
if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_MANAGER))
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2014-11-05 19:42:19 +00:00
2017-06-06 23:24:18 +02:00
//
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2014-11-05 19:42:19 +00:00
2019-11-21 17:49:34 -03:00
CoordsXY mapCoord = {};
2018-06-22 23:20:47 +02:00
get_map_coordinates_from_pos(
2019-11-21 17:49:34 -03:00
screenCoords, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), mapCoord, &info->type,
2018-07-21 13:51:54 +02:00
&info->tileElement, nullptr);
2017-06-06 23:24:18 +02:00
info->x = mapCoord.x;
info->y = mapCoord.y;
2017-10-31 14:03:45 +01:00
tileElement = info->tileElement;
rct_sprite* sprite = info->sprite;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_VEHICLE)
2017-06-06 23:24:18 +02:00
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2018-06-22 23:20:47 +02:00
ride = get_ride(sprite->vehicle.ride);
if (ride != nullptr && ride->status == RIDE_STATUS_CLOSED)
2018-06-22 23:20:47 +02:00
{
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
ride->FormatNameTo(gMapTooltipFormatArgs + 2);
2018-06-22 23:20:47 +02:00
}
return info->type;
case VIEWPORT_INTERACTION_ITEM_RIDE:
{
2018-06-22 23:20:47 +02:00
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
ride = get_ride(tile_element_get_ride_index(tileElement));
if (ride == nullptr)
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2018-06-22 23:20:47 +02:00
if (ride->status != RIDE_STATUS_CLOSED)
return info->type;
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)
{
rct_string_id stringId;
2018-09-26 12:13:44 +02:00
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
2018-06-22 23:20:47 +02:00
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_ENTRANCE;
}
else
{
stringId = STR_RIDE_ENTRANCE;
}
}
else
{
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X_EXIT;
}
else
{
stringId = STR_RIDE_EXIT;
}
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
}
else if (track_element_is_station(tileElement))
{
rct_string_id stringId;
if (ride->num_stations > 1)
{
stringId = STR_RIDE_STATION_X;
}
else
{
stringId = STR_RIDE_STATION;
}
set_map_tooltip_format_arg(2, rct_string_id, stringId);
}
else
{
// FIXME: Why does it *2 the value?
if (!gCheatsSandboxMode && !map_is_location_owned({ info->x, info->y, tileElement->GetBaseZ() * 2 }))
2018-06-22 23:20:47 +02:00
{
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
ride->FormatNameTo(gMapTooltipFormatArgs + 2);
2018-06-22 23:20:47 +02:00
return info->type;
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
auto nameArgLen = ride->FormatNameTo(gMapTooltipFormatArgs + 4);
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(
4 + nameArgLen, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);
2018-09-23 11:55:37 +02:00
if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)
stationIndex = tileElement->AsEntrance()->GetStationIndex();
else
stationIndex = tileElement->AsTrack()->GetStationIndex();
2018-09-23 11:55:37 +02:00
2018-06-22 23:20:47 +02:00
for (i = stationIndex; i >= 0; i--)
if (ride->stations[i].Start.isNull())
2018-06-22 23:20:47 +02:00
stationIndex--;
stationIndex++;
set_map_tooltip_format_arg(4 + nameArgLen + 2, uint16_t, stationIndex);
2017-06-06 23:24:18 +02:00
return info->type;
}
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_WALL:
2018-09-17 15:42:34 +02:00
sceneryEntry = tileElement->AsWall()->GetEntry();
2019-02-14 22:41:48 +01:00
if (sceneryEntry->wall.scrolling_mode != SCROLLING_MODE_NONE)
2018-06-22 23:20:47 +02:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsWall()->GetBanner();
2019-07-21 17:40:52 +01:00
size_t argPos = 0;
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
argPos += sizeof(rct_string_id);
argPos += banner->FormatTextTo(gMapTooltipFormatArgs + argPos);
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
argPos += sizeof(rct_string_id);
set_map_tooltip_format_arg(argPos, rct_string_id, sceneryEntry->name);
2018-06-22 23:20:47 +02:00
return info->type;
}
break;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_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:20:47 +02:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsLargeScenery()->GetBanner();
2019-07-21 17:40:52 +01:00
size_t argPos = 0;
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
argPos += sizeof(rct_string_id);
argPos += banner->FormatTextTo(gMapTooltipFormatArgs + argPos);
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
argPos += sizeof(rct_string_id);
set_map_tooltip_format_arg(argPos, rct_string_id, sceneryEntry->name);
2018-06-22 23:20:47 +02:00
return info->type;
}
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
2019-07-21 15:16:44 +01:00
{
2019-07-25 17:51:22 +01:00
auto banner = tileElement->AsBanner()->GetBanner();
2018-06-22 23:20:47 +02:00
sceneryEntry = get_banner_entry(banner->type);
2014-11-05 19:42:19 +00:00
2019-07-21 17:40:52 +01:00
size_t argPos = 0;
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID);
argPos += sizeof(rct_string_id);
argPos += banner->FormatTextTo(gMapTooltipFormatArgs + argPos);
set_map_tooltip_format_arg(argPos, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
2019-07-21 22:52:53 +01:00
argPos += sizeof(rct_string_id);
2019-07-21 17:40:52 +01:00
set_map_tooltip_format_arg(argPos, rct_string_id, sceneryEntry->name);
2017-06-06 23:24:18 +02:00
return info->type;
2019-07-21 15:16:44 +01:00
}
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE)))
{
if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr)
{
2017-06-06 23:24:18 +02:00
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
}
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
switch (info->type)
{
case VIEWPORT_INTERACTION_ITEM_SCENERY:
2018-09-13 18:12:20 +02:00
sceneryEntry = tileElement->AsSmallScenery()->GetEntry();
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
2017-06-06 23:24:18 +02:00
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
2018-06-22 23:20:47 +02:00
return info->type;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, STR_FOOTPATH_MAP_TIP);
2018-10-03 10:57:29 +02:00
if (tileElement->AsPath()->IsQueue())
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(2, rct_string_id, STR_QUEUE_LINE_MAP_TIP);
return info->type;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
sceneryEntry = tileElement->AsPath()->GetAdditionEntry();
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
2019-02-26 09:29:25 +00:00
if (tileElement->AsPath()->IsBroken())
2018-06-22 23:20:47 +02:00
{
set_map_tooltip_format_arg(2, rct_string_id, STR_BROKEN);
set_map_tooltip_format_arg(4, rct_string_id, sceneryEntry->name);
}
else
{
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
}
return info->type;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_PARK:
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
break;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
break;
2014-11-05 19:42:19 +00:00
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, STR_OBJECT_SELECTION_PARK_ENTRANCE);
return info->type;
case VIEWPORT_INTERACTION_ITEM_WALL:
2018-09-17 15:42:34 +02:00
sceneryEntry = tileElement->AsWall()->GetEntry();
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
2018-09-14 12:12:22 +02:00
sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
2018-06-22 23:20:47 +02:00
set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
return info->type;
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
2017-06-06 23:24:18 +02:00
return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
2014-11-05 19:42:19 +00:00
}
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_right_over(ScreenCoordsXY screenCoords)
2014-11-05 19:42:19 +00:00
{
2017-06-06 23:24:18 +02:00
viewport_interaction_info info;
2014-11-05 19:42:19 +00:00
2019-11-21 17:49:34 -03:00
return viewport_interaction_get_item_right(screenCoords, &info) != 0;
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E8A62
*/
2019-11-21 17:49:34 -03:00
int32_t viewport_interaction_right_click(ScreenCoordsXY screenCoords)
2014-11-05 19:42:19 +00:00
{
2018-02-15 17:42:53 +01:00
CoordsXYE tileElement;
2017-06-06 23:24:18 +02:00
viewport_interaction_info info;
2014-11-05 19:42:19 +00:00
2019-11-21 17:49:34 -03:00
switch (viewport_interaction_get_item_right(screenCoords, &info))
2018-06-22 23:20:47 +02:00
{
case VIEWPORT_INTERACTION_ITEM_NONE:
return 0;
2018-06-22 23:20:47 +02:00
case VIEWPORT_INTERACTION_ITEM_SPRITE:
if (info.sprite->generic.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE)
2019-08-09 18:29:34 +01:00
{
auto ride = get_ride(info.sprite->vehicle.ride);
if (ride != nullptr)
{
ride_construct(ride);
}
}
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_RIDE:
tileElement.x = info.x;
tileElement.y = info.y;
tileElement.element = info.tileElement;
ride_modify(&tileElement);
break;
case VIEWPORT_INTERACTION_ITEM_SCENERY:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_scenery(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_footpath(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_footpath_item(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_PARK:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_park_entrance(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_WALL:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_park_wall(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
2019-11-24 19:45:56 -03:00
viewport_interaction_remove_large_scenery(info.tileElement, { info.x, info.y });
2018-06-22 23:20:47 +02:00
break;
case VIEWPORT_INTERACTION_ITEM_BANNER:
2018-09-26 14:07:04 +02:00
context_open_detail_window(WD_BANNER, info.tileElement->AsBanner()->GetIndex());
2018-06-22 23:20:47 +02:00
break;
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
return 1;
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E08D2
*/
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_scenery(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2019-01-03 02:20:35 +01:00
auto removeSceneryAction = SmallSceneryRemoveAction(
2019-12-22 22:14:02 +01:00
{ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() }, tileElement->AsSmallScenery()->GetSceneryQuadrant(),
2018-12-22 18:11:08 +01:00
tileElement->AsSmallScenery()->GetEntryIndex());
GameActions::Execute(&removeSceneryAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006A614A
*/
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_footpath(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2018-06-22 23:20:47 +02:00
rct_window* w;
2018-11-01 13:53:50 +01:00
TileElement* tileElement2;
2014-11-05 19:42:19 +00:00
2019-12-22 22:14:02 +01:00
auto z = tileElement->GetBaseZ();
2015-10-20 20:16:30 +02:00
2017-06-06 23:24:18 +02:00
w = window_find_by_class(WC_FOOTPATH);
2018-01-07 21:43:07 +01:00
if (w != nullptr)
2017-06-06 23:24:18 +02:00
footpath_provisional_update();
2014-11-05 19:42:19 +00:00
tileElement2 = map_get_first_element_at(mapCoords);
if (tileElement2 == nullptr)
return;
2018-06-22 23:20:47 +02:00
do
{
2019-12-22 22:14:02 +01:00
if (tileElement2->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement2->GetBaseZ() == z)
2018-06-22 23:20:47 +02:00
{
footpath_remove({ mapCoords, z }, GAME_COMMAND_FLAG_APPLY);
2017-06-06 23:24:18 +02:00
break;
}
} while (!(tileElement2++)->IsLastForTile());
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006A61AB
*/
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_footpath_item(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2019-12-22 22:14:02 +01:00
auto footpathSceneryRemoveAction = FootpathSceneryRemoveAction({ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() });
GameActions::Execute(&footpathSceneryRemoveAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x00666C0E
*/
2019-11-24 19:45:56 -03:00
void viewport_interaction_remove_park_entrance(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2018-09-14 11:14:19 +02:00
int32_t rotation = tileElement->GetDirectionWithOffset(1);
switch (tileElement->AsEntrance()->GetSequenceIndex())
2018-06-22 23:20:47 +02:00
{
case 1:
2019-11-25 23:08:31 -03:00
mapCoords += CoordsDirectionDelta[rotation];
2018-06-22 23:20:47 +02:00
break;
case 2:
2019-11-25 23:08:31 -03:00
mapCoords -= CoordsDirectionDelta[rotation];
2018-06-22 23:20:47 +02:00
break;
2017-06-06 23:24:18 +02:00
}
2019-12-22 22:14:02 +01:00
auto parkEntranceRemoveAction = ParkEntranceRemoveAction({ mapCoords.x, mapCoords.y, tileElement->GetBaseZ() });
2019-03-24 20:41:14 +00:00
GameActions::Execute(&parkEntranceRemoveAction);
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006E57A9
*/
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_park_wall(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2018-09-17 15:42:34 +02:00
rct_scenery_entry* sceneryEntry = tileElement->AsWall()->GetEntry();
2019-02-14 22:41:48 +01:00
if (sceneryEntry->wall.scrolling_mode != SCROLLING_MODE_NONE)
{
2018-09-17 15:42:34 +02:00
context_open_detail_window(WD_SIGN_SMALL, tileElement->AsWall()->GetBannerIndex());
}
else
{
2019-12-22 22:14:02 +01:00
CoordsXYZD wallLocation = { mapCoords.x, mapCoords.y, tileElement->GetBaseZ(), tileElement->GetDirection() };
2018-05-14 12:36:45 +02:00
auto wallRemoveAction = WallRemoveAction(wallLocation);
GameActions::Execute(&wallRemoveAction);
2017-06-06 23:24:18 +02:00
}
2014-11-05 19:42:19 +00:00
}
/**
2015-10-20 20:16:30 +02:00
*
2014-11-05 19:42:19 +00:00
* rct2: 0x006B88DC
*/
2019-11-24 19:45:56 -03:00
static void viewport_interaction_remove_large_scenery(TileElement* tileElement, CoordsXY mapCoords)
2014-11-05 19:42:19 +00:00
{
2018-09-14 12:12:22 +02:00
rct_scenery_entry* sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
2014-11-05 19:42:19 +00:00
2019-02-14 22:41:48 +01:00
if (sceneryEntry->large_scenery.scrolling_mode != SCROLLING_MODE_NONE)
{
2018-09-14 12:12:22 +02:00
BannerIndex bannerIndex = tileElement->AsLargeScenery()->GetBannerIndex();
2018-06-09 13:51:45 +02:00
context_open_detail_window(WD_SIGN, bannerIndex);
2018-06-22 23:20:47 +02:00
}
else
{
2019-01-03 02:20:35 +01:00
auto removeSceneryAction = LargeSceneryRemoveAction(
2019-12-22 22:14:02 +01:00
{ mapCoords.x, mapCoords.y, tileElement->GetBaseZ(), tileElement->GetDirection() },
2019-07-07 04:53:59 +03:00
tileElement->AsLargeScenery()->GetSequenceIndex());
2018-12-22 19:46:59 +01:00
GameActions::Execute(&removeSceneryAction);
2017-06-06 23:24:18 +02:00
}
}
2019-11-21 17:49:34 -03:00
static Peep* viewport_interaction_get_closest_peep(ScreenCoordsXY screenCoords, int32_t maxDistance)
{
int32_t distance, closestDistance;
uint16_t spriteIndex;
2018-06-22 23:20:47 +02:00
rct_window* w;
rct_viewport* viewport;
2019-02-28 19:28:58 +00:00
Peep *peep, *closestPeep;
2019-11-21 17:49:34 -03:00
w = window_find_from_point(screenCoords);
2018-01-07 21:43:07 +01:00
if (w == nullptr)
return nullptr;
2015-10-20 20:16:30 +02:00
2017-06-06 23:24:18 +02:00
viewport = w->viewport;
2018-01-07 21:43:07 +01:00
if (viewport == nullptr || viewport->zoom >= 2)
return nullptr;
2019-11-21 17:49:34 -03:00
screenCoords.x = ((screenCoords.x - viewport->x) << viewport->zoom) + viewport->view_x;
screenCoords.y = ((screenCoords.y - viewport->y) << viewport->zoom) + viewport->view_y;
2018-01-07 21:43:07 +01:00
closestPeep = nullptr;
2017-06-06 23:24:18 +02:00
closestDistance = 0xFFFF;
2018-06-22 23:20:47 +02:00
FOR_ALL_PEEPS (spriteIndex, peep)
{
if (peep->sprite_left == LOCATION_NULL)
2017-06-06 23:24:18 +02:00
continue;
2019-11-21 17:49:34 -03:00
distance = abs(((peep->sprite_left + peep->sprite_right) / 2) - screenCoords.x)
+ abs(((peep->sprite_top + peep->sprite_bottom) / 2) - screenCoords.y);
2017-06-06 23:24:18 +02:00
if (distance > maxDistance)
continue;
2018-06-22 23:20:47 +02:00
if (distance < closestDistance)
{
2017-06-06 23:24:18 +02:00
closestPeep = peep;
closestDistance = distance;
}
}
2017-06-06 23:24:18 +02:00
return closestPeep;
2015-04-21 18:19:11 +01:00
}
/**
*
* rct2: 0x0068A15E
*/
2019-11-14 19:09:27 -03:00
CoordsXY sub_68A15E(ScreenCoordsXY screenCoords)
2015-04-21 18:19:11 +01:00
{
CoordsXY mapCoords;
2019-10-07 18:56:31 +01:00
CoordsXY initialPos{};
int32_t interactionType;
2019-10-07 18:56:31 +01:00
TileElement* tileElement;
2018-06-22 23:20:47 +02:00
rct_viewport* viewport;
get_map_coordinates_from_pos(
screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, mapCoords, &interactionType,
&tileElement, &viewport);
initialPos = mapCoords;
2015-04-21 18:19:11 +01:00
2018-06-22 23:20:47 +02:00
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{
initialPos.setNull();
2019-11-14 19:09:27 -03:00
return initialPos;
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
2019-10-07 18:56:31 +01:00
int16_t waterHeight = 0;
2018-06-22 23:20:47 +02:00
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER)
{
2020-01-19 16:12:48 +01:00
waterHeight = tileElement->AsSurface()->GetWaterHeight();
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
auto initialVPPos = screen_coord_to_viewport_coord(viewport, screenCoords);
CoordsXY mapPos = initialPos + CoordsXY{ 16, 16 };
2015-04-21 18:19:11 +01:00
2018-06-22 23:20:47 +02:00
for (int32_t i = 0; i < 5; i++)
{
2019-10-07 18:56:31 +01:00
int16_t z = waterHeight;
2018-06-22 23:20:47 +02:00
if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER)
{
z = tile_element_height(mapPos);
2017-06-06 23:24:18 +02:00
}
2019-10-07 18:56:31 +01:00
mapPos = viewport_coord_to_map_coord(initialVPPos.x, initialVPPos.y, z);
mapPos.x = std::clamp(mapPos.x, initialPos.x, initialPos.x + 31);
mapPos.y = std::clamp(mapPos.y, initialPos.y, initialPos.y + 31);
2017-06-06 23:24:18 +02:00
}
2015-04-21 18:19:11 +01:00
return mapPos.ToTileStart();
}