OpenTTD Source: src/waypoint.cpp Source File

OpenTTD Source 15.0-RC2

waypoint.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11
12#include "order_func.h"
13#include "window_func.h"
14#include "newgrf_station.h"
15#include "waypoint_base.h"
16#include "viewport_kdtree.h"
17
18#include "safeguards.h"
19
28 void DrawWaypointSprite(int x, int y, StationClassID station_class, uint16_t station_type, RailType railtype)
29{
30 if (!DrawStationTile(x, y, railtype, AXIS_X, station_class, station_type)) {
31 StationPickerDrawSprite(x, y, StationType::RailWaypoint, railtype, INVALID_ROADTYPE, AXIS_X);
32 }
33}
34
35 TileArea Waypoint::GetTileArea(StationType type) const
36{
37 switch (type) {
38 case StationType::RailWaypoint: return this->train_station;
39 case StationType::RoadWaypoint: return this->road_waypoint_area;
40 case StationType::Buoy: return {this->xy, 1, 1};
41 default: NOT_REACHED();
42 }
43}
44
45Waypoint::~Waypoint()
46{
47 if (CleaningPool()) return;
48 CloseWindowById(WC_WAYPOINT_VIEW, this->index);
49 RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
50 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
51}
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition kdtree.hpp:415
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
DrawStationTile
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Definition newgrf_station.cpp:804
newgrf_station.h
Header file for NewGRF stations.
StationClassID
StationClassID
Definition newgrf_station.h:103
RemoveOrderFromAllVehicles
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition order_cmd.cpp:1753
order_func.h
Functions related to orders.
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
safeguards.h
A number of safeguards to prevent using unsafe methods.
StationType
StationType
Station types.
Definition station_type.h:29
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition base_station_base.h:59
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition base_station_base.h:83
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition base_station_base.h:60
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_station_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition pool_type.hpp:366
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition viewport_type.h:61
Waypoint::road_waypoint_area
TileArea road_waypoint_area
Tile area the road waypoint part covers.
Definition waypoint_base.h:26
Waypoint::GetTileArea
TileArea GetTileArea(StationType type) const override
Get the tile area for a given station type.
Definition waypoint.cpp:35
DrawWaypointSprite
void DrawWaypointSprite(int x, int y, StationClassID station_class, uint16_t station_type, RailType railtype)
Draw a waypoint.
Definition waypoint.cpp:28
waypoint_base.h
Base of waypoints.
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1193
window_func.h
Window functions not directly related to making/drawing windows.
WC_WAYPOINT_VIEW
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Definition window_type.h:362