OpenTTD Source: src/waypoint_cmd.cpp Source File

OpenTTD Source 15.0-RC2

waypoint_cmd.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 "command_func.h"
13#include "landscape.h"
14#include "bridge_map.h"
15#include "town.h"
16#include "waypoint_base.h"
17#include "pathfinder/yapf/yapf_cache.h"
18#include "pathfinder/water_regions.h"
19#include "tilehighlight_func.h"
20#include "strings_func.h"
21#include "viewport_func.h"
22#include "viewport_kdtree.h"
23#include "station_kdtree.h"
24#include "window_func.h"
25#include "timer/timer_game_calendar.h"
26#include "vehicle_func.h"
27#include "string_func.h"
28#include "company_func.h"
29#include "newgrf_debug.h"
30#include "newgrf_station.h"
31#include "newgrf_roadstop.h"
32#include "company_base.h"
33#include "water.h"
34#include "company_gui.h"
35#include "waypoint_cmd.h"
36#include "landscape_cmd.h"
37#include "station_layout_type.h"
38
39#include "widgets/misc_widget.h"
40
41#include "table/strings.h"
42
43#include "safeguards.h"
44
48 void Waypoint::UpdateVirtCoord()
49{
50 Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
51 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
52
53 this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_BASE, GetString(STR_WAYPOINT_NAME, this->index));
54
55 _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
56
57 /* Recenter viewport */
58 InvalidateWindowData(WC_WAYPOINT_VIEW, this->index);
59}
60
65 void Waypoint::MoveSign(TileIndex new_xy)
66{
67 if (this->xy == new_xy) return;
68
69 this->BaseStation::MoveSign(new_xy);
70}
71
80 static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid, bool is_road)
81{
82 Waypoint *best = nullptr;
83 uint thres = 8;
84
85 for (Waypoint *wp : Waypoint::Iterate()) {
86 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid && HasBit(wp->waypoint_flags, WPF_ROAD) == is_road) {
87 uint cur_dist = DistanceManhattan(tile, wp->xy);
88
89 if (cur_dist < thres) {
90 thres = cur_dist;
91 best = wp;
92 }
93 }
94 }
95
96 return best;
97}
98
106 Axis GetAxisForNewRailWaypoint(TileIndex tile)
107{
108 /* The axis for rail waypoints is easy. */
109 if (IsRailWaypointTile(tile)) return GetRailStationAxis(tile);
110
111 /* Non-plain rail type, no valid axis for waypoints. */
112 if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RailTileType::Normal) return INVALID_AXIS;
113
114 switch (GetTrackBits(tile)) {
115 case TRACK_BIT_X: return AXIS_X;
116 case TRACK_BIT_Y: return AXIS_Y;
117 default: return INVALID_AXIS;
118 }
119}
120
128 Axis GetAxisForNewRoadWaypoint(TileIndex tile)
129{
130 /* The axis for existing road waypoints is easy. */
131 if (IsRoadWaypointTile(tile)) return GetDriveThroughStopAxis(tile);
132
133 /* Non-plain road type, no valid axis for waypoints. */
134 if (!IsNormalRoadTile(tile)) return INVALID_AXIS;
135
136 RoadBits bits = GetAllRoadBits(tile);
137
138 if ((bits & ROAD_Y) == 0) return AXIS_X;
139 if ((bits & ROAD_X) == 0) return AXIS_Y;
140
141 return INVALID_AXIS;
142}
143
144extern CommandCost ClearTile_Station(TileIndex tile, DoCommandFlags flags);
145
152 static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
153{
154 /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
155 * so waypoint points to StationID::Invalid() if we can build on any waypoint.
156 * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
157 if (waypoint != nullptr && IsTileType(tile, MP_STATION)) {
158 if (!IsRailWaypoint(tile)) {
159 return ClearTile_Station(tile, DoCommandFlag::Auto); // get error message
160 } else {
161 StationID wp = GetStationIndex(tile);
162 if (*waypoint == StationID::Invalid()) {
163 *waypoint = wp;
164 } else if (*waypoint != wp) {
165 return CommandCost(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
166 }
167 }
168 }
169
170 if (GetAxisForNewRailWaypoint(tile) != axis) return CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
171
172 Owner owner = GetTileOwner(tile);
173 CommandCost ret = CheckOwnership(owner);
174 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile);
175 if (ret.Failed()) return ret;
176
177 Slope tileh = GetTileSlope(tile);
178 if (tileh != SLOPE_FLAT &&
179 (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
180 return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
181 }
182
183 return CommandCost();
184}
185
186extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp, bool is_road);
187extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta);
188extern CommandCost CalculateRoadStopCost(TileArea tile_area, DoCommandFlags flags, bool is_drive_through, StationType station_type, const RoadStopSpec *roadstopspec, Axis axis, DiagDirection ddir, StationID *est, RoadType rt, Money unit_cost);
189extern CommandCost IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *spec, StationType type, StationGfx layout);
190
191extern CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlags flags, int replacement_spec_index);
192
207 CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
208{
209 if (!IsValidAxis(axis)) return CMD_ERROR;
210 /* Check if the given station class is valid */
211 if (static_cast<uint>(spec_class) >= StationClass::GetClassCount()) return CMD_ERROR;
212 const StationClass *cls = StationClass::Get(spec_class);
213 if (!IsWaypointClass(*cls)) return CMD_ERROR;
214 if (spec_index >= cls->GetSpecCount()) return CMD_ERROR;
215
216 /* The number of parts to build */
217 uint8_t count = axis == AXIS_X ? height : width;
218
219 if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
220 if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
221
222 bool reuse = (station_to_join != NEW_STATION);
223 if (!reuse) station_to_join = StationID::Invalid();
224 bool distant_join = (station_to_join != StationID::Invalid());
225
226 if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
227
228 TileArea new_location(start_tile, width, height);
229
230 /* only AddCost for non-existing waypoints */
231 CommandCost cost(EXPENSES_CONSTRUCTION);
232 for (TileIndex cur_tile : new_location) {
233 if (!IsRailWaypointTile(cur_tile)) cost.AddCost(_price[PR_BUILD_WAYPOINT_RAIL]);
234 }
235
236 /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
237 StationID est = StationID::Invalid();
238
239 const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
240 RailStationTileLayout stl{spec, count, 1};
241
242 /* Check whether the tiles we're building on are valid rail or not. */
243 TileIndexDiff offset = TileOffsByAxis(OtherAxis(axis));
244 for (auto [i, it, tile] = std::make_tuple(0, stl.begin(), start_tile); i < count; ++i, ++it, tile += offset) {
245 CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
246 if (ret.Failed()) return ret;
247
248 ret = IsRailStationBridgeAboveOk(tile, spec, StationType::RailWaypoint, *it + axis);
249 if (ret.Failed()) return ret;
250 }
251
252 Waypoint *wp = nullptr;
253 CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp, false);
254 if (ret.Failed()) return ret;
255
256 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
257 TileIndex center_tile = start_tile + (count / 2) * offset;
258 if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company, false);
259
260 if (wp != nullptr) {
261 /* Reuse an existing waypoint. */
262 if (wp->owner != _current_company) return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
263
264 /* Check if we want to expand an already existing waypoint. */
265 if (wp->train_station.tile != INVALID_TILE) {
266 ret = CanExpandRailStation(wp, new_location);
267 if (ret.Failed()) return ret;
268 }
269
270 ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
271 if (ret.Failed()) return ret;
272 } else {
273 /* Check if we can create a new waypoint. */
274 if (!Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING);
275 }
276
277 /* Check if we can allocate a custom spec to this waypoint. */
278 auto specindex = AllocateSpecToStation(spec, wp);
279 if (!specindex.has_value()) return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
280
281 if (flags.Test(DoCommandFlag::Execute)) {
282 if (wp == nullptr) {
283 wp = new Waypoint(start_tile);
284 } else if (!wp->IsInUse()) {
285 /* Move existing (recently deleted) waypoint to the new location */
286 wp->xy = start_tile;
287 }
288 wp->owner = GetTileOwner(start_tile);
289
290 wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
291 if (specindex.has_value()) AssignSpecToStation(spec, wp, *specindex);
292
293 wp->delete_ctr = 0;
294 wp->facilities.Set(StationFacility::Train);
295 wp->build_date = TimerGameCalendar::date;
296 wp->string_id = STR_SV_STNAME_WAYPOINT;
297 wp->train_station = new_location;
298
299 if (wp->town == nullptr) MakeDefaultName(wp);
300
301 wp->UpdateVirtCoord();
302
303 Company *c = Company::Get(wp->owner);
304 for (auto [i, it, tile] = std::make_tuple(0, stl.begin(), start_tile); i < count; ++i, ++it, tile += offset) {
305 uint8_t old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
306 if (!HasStationTileRail(tile)) c->infrastructure.station++;
307 bool reserved = IsTileType(tile, MP_RAILWAY) ?
308 HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis)) :
309 HasStationReservation(tile);
310 MakeRailWaypoint(tile, wp->owner, wp->index, axis, *it, GetRailType(tile));
311 SetCustomStationSpecIndex(tile, *specindex);
312
313 SetRailStationTileFlags(tile, spec);
314
315 SetRailStationReservation(tile, reserved);
316 MarkTileDirtyByTile(tile);
317
318 DeallocateSpecFromStation(wp, old_specindex);
319 if (spec == nullptr) DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
320 YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
321 }
322 DirtyCompanyInfrastructureWindows(wp->owner);
323 }
324
325 return cost;
326}
327
341 CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, RoadStopClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
342{
343 if (!IsValidAxis(axis)) return CMD_ERROR;
344 /* Check if the given station class is valid */
345 if (static_cast<uint>(spec_class) >= RoadStopClass::GetClassCount()) return CMD_ERROR;
346 const RoadStopClass *cls = RoadStopClass::Get(spec_class);
347 if (!IsWaypointClass(*cls)) return CMD_ERROR;
348 if (spec_index >= cls->GetSpecCount()) return CMD_ERROR;
349
350 const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index);
351
352 /* The number of parts to build */
353 uint8_t count = axis == AXIS_X ? height : width;
354
355 if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
356 if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
357
358 bool reuse = (station_to_join != NEW_STATION);
359 if (!reuse) station_to_join = StationID::Invalid();
360 bool distant_join = (station_to_join != StationID::Invalid());
361
362 if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
363
364 TileArea roadstop_area(start_tile, width, height);
365
366 /* Total road stop cost. */
367 Money unit_cost;
368 if (roadstopspec != nullptr) {
369 unit_cost = roadstopspec->GetBuildCost(PR_BUILD_STATION_TRUCK);
370 } else {
371 unit_cost = _price[PR_BUILD_STATION_TRUCK];
372 }
373 StationID est = StationID::Invalid();
374 CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, true, StationType::RoadWaypoint, roadstopspec, axis, AxisToDiagDir(axis), &est, INVALID_ROADTYPE, unit_cost);
375 if (cost.Failed()) return cost;
376
377 Waypoint *wp = nullptr;
378 CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, roadstop_area, &wp, true);
379 if (ret.Failed()) return ret;
380
381 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
382 TileIndex center_tile = start_tile + (count / 2) * TileOffsByAxis(OtherAxis(axis));
383 if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company, true);
384
385 if (wp != nullptr) {
386 /* Reuse an existing waypoint. */
387 if (!HasBit(wp->waypoint_flags, WPF_ROAD)) return CMD_ERROR;
388 if (wp->owner != _current_company) return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
389
390 ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
391 if (ret.Failed()) return ret;
392 } else {
393 /* Check if we can create a new waypoint. */
394 if (!Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING);
395 }
396
397 /* Check if we can allocate a custom spec to this waypoint. */
398 auto specindex = AllocateSpecToRoadStop(roadstopspec, wp);
399 if (!specindex.has_value()) return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
400
401 if (flags.Test(DoCommandFlag::Execute)) {
402 if (wp == nullptr) {
403 wp = new Waypoint(start_tile);
404 SetBit(wp->waypoint_flags, WPF_ROAD);
405 } else if (!wp->IsInUse()) {
406 /* Move existing (recently deleted) waypoint to the new location */
407 wp->xy = start_tile;
408 }
409 wp->owner = _current_company;
410
411 wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
412 if (specindex.has_value()) AssignSpecToRoadStop(roadstopspec, wp, *specindex);
413
414 if (roadstopspec != nullptr) {
415 /* Include this road stop spec's animation trigger bitmask
416 * in the station's cached copy. */
417 wp->cached_roadstop_anim_triggers.Set(roadstopspec->animation.triggers);
418 }
419
420 wp->delete_ctr = 0;
421 wp->facilities.Set({StationFacility::BusStop, StationFacility::TruckStop});
422 wp->build_date = TimerGameCalendar::date;
423 wp->string_id = STR_SV_STNAME_WAYPOINT;
424
425 if (wp->town == nullptr) MakeDefaultName(wp);
426
427 wp->UpdateVirtCoord();
428
429 /* Check every tile in the area. */
430 for (TileIndex cur_tile : roadstop_area) {
431 /* Get existing road types and owners before any tile clearing */
432 RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
433 RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
434 Owner road_owner = road_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_ROAD) : _current_company;
435 Owner tram_owner = tram_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_TRAM) : _current_company;
436
437 if (IsRoadWaypointTile(cur_tile)) {
438 RemoveRoadWaypointStop(cur_tile, flags, *specindex);
439 }
440
441 wp->road_waypoint_area.Add(cur_tile);
442
443 wp->rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
444
445 /* Update company infrastructure counts. If the current tile is a normal road tile, remove the old
446 * bits first. */
447 if (IsNormalRoadTile(cur_tile)) {
448 UpdateCompanyRoadInfrastructure(road_rt, road_owner, -(int)CountBits(GetRoadBits(cur_tile, RTT_ROAD)));
449 UpdateCompanyRoadInfrastructure(tram_rt, tram_owner, -(int)CountBits(GetRoadBits(cur_tile, RTT_TRAM)));
450 }
451
452 UpdateCompanyRoadInfrastructure(road_rt, road_owner, ROAD_STOP_TRACKBIT_FACTOR);
453 UpdateCompanyRoadInfrastructure(tram_rt, tram_owner, ROAD_STOP_TRACKBIT_FACTOR);
454
455 MakeDriveThroughRoadStop(cur_tile, wp->owner, road_owner, tram_owner, wp->index, StationType::RoadWaypoint, road_rt, tram_rt, axis);
456 SetCustomRoadStopSpecIndex(cur_tile, *specindex);
457 if (roadstopspec != nullptr) wp->SetRoadStopRandomBits(cur_tile, 0);
458
459 Company::Get(wp->owner)->infrastructure.station++;
460
461 MarkTileDirtyByTile(cur_tile);
462 }
463 DirtyCompanyInfrastructureWindows(wp->owner);
464 }
465 return cost;
466}
467
474 CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile)
475{
476 if (tile == 0 || !HasTileWaterGround(tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE);
477 if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
478
479 if (!IsTileFlat(tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE);
480
481 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
482 Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE, false);
483 if (wp == nullptr && !Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING);
484
485 CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
486 if (!IsWaterTile(tile)) {
487 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile);
488 if (ret.Failed()) return ret;
489 cost.AddCost(ret.GetCost());
490 }
491
492 if (flags.Test(DoCommandFlag::Execute)) {
493 if (wp == nullptr) {
494 wp = new Waypoint(tile);
495 } else {
496 /* Move existing (recently deleted) buoy to the new location */
497 wp->xy = tile;
498 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
499 }
500 wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
501
502 wp->string_id = STR_SV_STNAME_BUOY;
503
504 wp->facilities.Set(StationFacility::Dock);
505 wp->owner = OWNER_NONE;
506
507 wp->build_date = TimerGameCalendar::date;
508
509 if (wp->town == nullptr) MakeDefaultName(wp);
510
511 MakeBuoy(tile, wp->index, GetWaterClass(tile));
512 CheckForDockingTile(tile);
513 MarkTileDirtyByTile(tile);
514 ClearNeighbourNonFloodingStates(tile);
515
516 wp->UpdateVirtCoord();
517 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
518 }
519
520 return cost;
521}
522
530 CommandCost RemoveBuoy(TileIndex tile, DoCommandFlags flags)
531{
532 /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
533 if (!Company::IsValidID(_current_company) && !flags.Test(DoCommandFlag::Bankrupt)) return CommandCost(INVALID_STRING_ID);
534
535 Waypoint *wp = Waypoint::GetByTile(tile);
536
537 if (HasStationInUse(wp->index, false, _current_company)) return CommandCost(STR_ERROR_BUOY_IS_IN_USE);
538 /* remove the buoy if there is a ship on tile when company goes bankrupt... */
539 if (!flags.Test(DoCommandFlag::Bankrupt)) {
540 CommandCost ret = EnsureNoVehicleOnGround(tile);
541 if (ret.Failed()) return ret;
542 }
543
544 if (flags.Test(DoCommandFlag::Execute)) {
545 wp->facilities.Reset(StationFacility::Dock);
546
547 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
548
549 /* We have to set the water tile's state to the same state as before the
550 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
551 * remove it and flood the land (if the canal edge is at level 0) */
552 MakeWaterKeepingClass(tile, GetTileOwner(tile));
553
554 wp->rect.AfterRemoveTile(wp, tile);
555
556 wp->UpdateVirtCoord();
557 wp->delete_ctr = 0;
558 }
559
560 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
561}
562
568 static bool IsUniqueWaypointName(const std::string &name)
569{
570 for (const Waypoint *wp : Waypoint::Iterate()) {
571 if (!wp->name.empty() && wp->name == name) return false;
572 }
573
574 return true;
575}
576
584 CommandCost CmdRenameWaypoint(DoCommandFlags flags, StationID waypoint_id, const std::string &text)
585{
586 Waypoint *wp = Waypoint::GetIfValid(waypoint_id);
587 if (wp == nullptr) return CMD_ERROR;
588
589 if (wp->owner != OWNER_NONE) {
590 CommandCost ret = CheckOwnership(wp->owner);
591 if (ret.Failed()) return ret;
592 }
593
594 bool reset = text.empty();
595
596 if (!reset) {
597 if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
598 if (!IsUniqueWaypointName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
599 }
600
601 if (flags.Test(DoCommandFlag::Execute)) {
602 if (reset) {
603 wp->name.clear();
604 } else {
605 wp->name = text;
606 }
607
608 wp->UpdateVirtCoord();
609 }
610 return CommandCost();
611}
612
620std::tuple<CommandCost, StationID> CmdMoveWaypointName(DoCommandFlags flags, StationID waypoint_id, TileIndex tile)
621{
622 Waypoint *wp = Waypoint::GetIfValid(waypoint_id);
623 if (wp == nullptr) return { CMD_ERROR, StationID::Invalid() };
624
625 if (wp->owner != OWNER_NONE) {
626 CommandCost ret = CheckOwnership(wp->owner);
627 if (ret.Failed()) return { ret, StationID::Invalid() };
628 }
629
630 const StationRect *r = &wp->rect;
631 if (!r->PtInExtendedRect(TileX(tile), TileY(tile))) {
632 return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
633 }
634
635 bool other_station = false;
636 /* Check if the tile is the base tile of another station */
637 ForAllStationsRadius(tile, 0, [&](BaseStation *st) {
638 if (st != nullptr) {
639 if (st != wp && st->xy == tile) other_station = true;
640 }
641 });
642 if (other_station) return { CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
643
644 if (flags.Test(DoCommandFlag::Execute)) {
645 wp->MoveSign(tile);
646
647 wp->UpdateVirtCoord();
648 }
649 return { CommandCost(), waypoint_id };
650}
651
657 void CcMoveWaypointName(Commands, const CommandCost &result, StationID waypoint_id)
658{
659 if (result.Failed()) return;
660
661 ResetObjectToPlace();
662 Waypoint *wp = Waypoint::Get(waypoint_id);
663 SetViewportCatchmentWaypoint(wp, false);
664}
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition bitmath_func.hpp:238
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
bridge_map.h
Map accessor functions for bridges.
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:168
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition command_type.h:98
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition command_type.h:118
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:177
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition kdtree.hpp:396
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition kdtree.hpp:415
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition newgrf_class.h:26
NewGRFClass::Get
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Definition newgrf_class_func.h:82
NewGRFClass::GetSpecCount
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition newgrf_class.h:70
NewGRFClass::GetClassCount
static uint GetClassCount()
Get the number of allocated classes.
Definition newgrf_class_func.h:93
NewGRFClass::GetSpec
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Definition newgrf_class_func.h:114
OverflowSafeInt< int64_t >
RailStationTileLayout
Definition station_layout_type.h:16
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
command_func.h
Functions related to commands.
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition command_func.h:28
DoCommandFlag::Auto
@ Auto
don't allow building on structures
DoCommandFlag::Execute
@ Execute
execute the given command
DoCommandFlag::Bankrupt
@ Bankrupt
company bankrupts, skip money check, skip vehicle on tile check in some cases
Commands
Commands
List of commands.
Definition command_type.h:196
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition company_cmd.cpp:381
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition company_gui.cpp:2318
company_gui.h
GUI Functions related to companies.
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
IsValidAxis
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition direction_func.h:43
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition direction_func.h:232
OtherAxis
Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition direction_func.h:197
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition direction_type.h:127
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
AXIS_Y
@ AXIS_Y
The y axis.
Definition direction_type.h:125
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
ROAD_STOP_TRACKBIT_FACTOR
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
Definition economy_type.h:243
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition economy_type.h:179
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition viewport.cpp:2128
landscape.h
Functions related to OTTD's landscape.
RemapCoords2
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition landscape.h:97
landscape_cmd.h
Command definitions related to landscape (slopes etc.).
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:158
TileOffsByAxis
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:567
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
misc_widget.h
Types related to the misc widgets.
StationGfx
uint8_t StationGfx
Copy from station_map.h.
Definition newgrf_airport.h:23
newgrf_debug.h
Functions/types related to NewGRF debugging.
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition newgrf_debug_gui.cpp:726
newgrf_roadstop.h
NewGRF definitions and structures for road stops.
IsWaypointClass
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
Definition newgrf_roadstop.h:190
RoadStopClassID
RoadStopClassID
Definition newgrf_roadstop.h:33
AssignSpecToStation
void AssignSpecToStation(const StationSpec *spec, BaseStation *st, uint8_t specindex)
Assign a previously allocated StationSpec specindex to a Station.
Definition newgrf_station.cpp:740
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
Deallocate a StationSpec from a Station.
Definition newgrf_station.cpp:757
AllocateSpecToStation
std::optional< uint8_t > AllocateSpecToStation(const StationSpec *spec, BaseStation *st)
Allocate a StationSpec to a Station.
Definition newgrf_station.cpp:705
newgrf_station.h
Header file for NewGRF stations.
StationClassID
StationClassID
Definition newgrf_station.h:103
GetRailTileType
static RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition rail_map.h:36
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
GetTrackBits
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
RailTileType::Normal
@ Normal
Normal rail tile without signals.
GetRailReservationTrackBits
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
Definition rail_map.h:194
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition road_cmd.cpp:180
MayHaveRoad
bool MayHaveRoad(Tile t)
Test whether a tile can have road/tram types.
Definition road_map.cpp:21
GetRoadBits
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
GetAllRoadBits
RoadBits GetAllRoadBits(Tile tile)
Get all set RoadBits on the given tile.
Definition road_map.h:125
IsNormalRoadTile
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
GetRoadOwner
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
Definition road_map.h:218
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition road_type.h:56
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition road_type.h:63
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition road_type.h:62
RTT_ROAD
@ RTT_ROAD
Road road type.
Definition road_type.h:38
RTT_TRAM
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition slope_func.h:36
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
HasStationInUse
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Definition station_cmd.cpp:2845
SetRailStationTileFlags
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec)
Set rail station tile flags for the given tile.
Definition station_cmd.cpp:1402
station_kdtree.h
Declarations for accessing the k-d tree of stations.
ForAllStationsRadius
void ForAllStationsRadius(TileIndex center, uint radius, Func func)
Call a function on all stations whose sign is within a radius of a center tile.
Definition station_kdtree.h:34
station_layout_type.h
Functions related to station layouts.
SetCustomStationSpecIndex
void SetCustomStationSpecIndex(Tile t, uint8_t specindex)
Set the custom station spec for this tile.
Definition station_map.h:630
IsRailWaypointTile
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
Definition station_map.h:123
MakeDriveThroughRoadStop
void MakeDriveThroughRoadStop(Tile t, Owner station, Owner road, Owner tram, StationID sid, StationType rst, RoadType road_rt, RoadType tram_rt, Axis a)
Make the given tile a drivethrough roadstop tile.
Definition station_map.h:796
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition station_map.h:146
GetCustomStationSpecIndex
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
Definition station_map.h:642
IsRailWaypoint
bool IsRailWaypoint(Tile t)
Is this station tile a rail waypoint?
Definition station_map.h:113
SetRailStationReservation
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
Definition station_map.h:571
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition station_map.h:503
MakeRailWaypoint
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, uint8_t section, RailType rt)
Make the given tile a rail waypoint tile.
Definition station_map.h:759
IsRoadWaypointTile
bool IsRoadWaypointTile(Tile t)
Is this tile a station tile and a road waypoint?
Definition station_map.h:212
GetDriveThroughStopAxis
Axis GetDriveThroughStopAxis(Tile t)
Gets the axis of the drive through stop.
Definition station_map.h:356
MakeBuoy
void MakeBuoy(Tile t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
Definition station_map.h:823
HasStationReservation
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
Definition station_map.h:559
SetCustomRoadStopSpecIndex
void SetCustomRoadStopSpecIndex(Tile t, uint8_t specindex)
Set the custom road stop spec for this tile.
Definition station_map.h:666
StationFacility::Dock
@ Dock
Station with a dock.
StationFacility::TruckStop
@ TruckStop
Station with truck stops.
StationFacility::Train
@ Train
Station with train station.
StationFacility::BusStop
@ BusStop
Station with bus stops.
StationType
StationType
Station types.
Definition station_type.h:29
MAX_LENGTH_STATION_NAME_CHARS
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Definition station_type.h:124
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
Utf8StringLength
size_t Utf8StringLength(std::string_view str)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition string.cpp:349
string_func.h
Functions related to low-level strings.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:20
BaseStation
Base class for all station-ish types.
Definition base_station_base.h:58
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition base_station_base.h:64
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition base_station_base.h:59
BaseStation::facilities
StationFacilities facilities
The facilities that this station has.
Definition base_station_base.h:69
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition base_station_base.h:83
BaseStation::owner
Owner owner
The owner of this station.
Definition base_station_base.h:68
BaseStation::delete_ctr
uint8_t delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Definition base_station_base.h:61
BaseStation::cached_roadstop_anim_triggers
StationAnimationTriggers cached_roadstop_anim_triggers
NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing sh...
Definition base_station_base.h:79
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition base_station_base.h:84
BaseStation::IsInUse
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Definition base_station_base.h:171
BaseStation::town
Town * town
The town this station is associated with.
Definition base_station_base.h:67
BaseStation::GetByTile
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Definition base_station_base.h:160
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition base_station_base.h:60
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition base_station_base.h:74
BaseStation::name
std::string name
Custom name.
Definition base_station_base.h:63
CommandHelper
Definition command_func.h:83
CompanyInfrastructure::station
uint32_t station
Count of company owned station tiles.
Definition company_base.h:37
Company
Definition company_base.h:127
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition company_base.h:141
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition settings_type.h:411
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
GameSettings::station
StationSettings station
settings related to station management
Definition settings_type.h:644
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition tilearea.cpp:43
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_station_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition pool_type.hpp:357
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
RoadStopSpec
Road stop specification.
Definition newgrf_roadstop.h:129
RoadStopSpec::GetBuildCost
Money GetBuildCost(Price category) const
Get the cost for building a road stop of this type.
Definition newgrf_roadstop.h:152
SpecializedStation< Waypoint, true >::IsValidID
static bool IsValidID(auto index)
Tests whether given index is a valid index for station of this type.
Definition base_station_base.h:239
SpecializedStation< Waypoint, true >::Iterate
static Pool::IterateWrapper< Waypoint > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition base_station_base.h:299
SpecializedStation< Waypoint, true >::Get
static Waypoint * Get(auto index)
Gets station with given index.
Definition base_station_base.h:248
SpecializedStation< Waypoint, true >::GetIfValid
static Waypoint * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
Definition base_station_base.h:257
StationRect
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
Definition base_station_base.h:36
StationRect::PtInExtendedRect
bool PtInExtendedRect(int x, int y, int distance=0) const
Determines whether a given point (x, y) is within a certain distance of the station rectangle.
Definition station.cpp:564
StationSettings::station_spread
uint8_t station_spread
amount a station may spread
Definition settings_type.h:597
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition settings_type.h:595
StationSpec
Station specification.
Definition newgrf_station.h:123
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
Definition viewport_type.h:69
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition viewport_type.h:61
Waypoint
Representation of a waypoint.
Definition waypoint_base.h:23
Waypoint::road_waypoint_area
TileArea road_waypoint_area
Tile area the road waypoint part covers.
Definition waypoint_base.h:26
Waypoint::waypoint_flags
uint16_t waypoint_flags
Waypoint flags, see WaypointFlags.
Definition waypoint_base.h:25
Waypoint::MoveSign
void MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
Definition waypoint_cmd.cpp:65
Waypoint::UpdateVirtCoord
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
Definition waypoint_cmd.cpp:48
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition tile_map.cpp:95
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
TILE_SIZE
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3573
timer_game_calendar.h
Definition of the game-calendar-timer.
town.h
Base of the town class.
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition town.h:284
AxisToTrack
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition track_func.h:66
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition track_type.h:38
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition track_type.h:37
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition vehicle.cpp:527
vehicle_func.h
Functions related to vehicles.
SetViewportCatchmentWaypoint
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
Definition viewport.cpp:3759
viewport_func.h
Functions related to (drawing on) viewports.
water.h
Functions related to water (management)
ClearNeighbourNonFloodingStates
void ClearNeighbourNonFloodingStates(TileIndex tile)
Clear non-flooding state of the tiles around a tile.
Definition water_cmd.cpp:97
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition water_cmd.cpp:194
HasTileWaterGround
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
Definition water_map.h:352
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:114
IsWaterTile
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition water_map.h:192
water_regions.h
Handles dividing the water in the map into regions to assist pathfinding.
waypoint_base.h
Base of waypoints.
WPF_ROAD
@ WPF_ROAD
This is a road waypoint.
Definition waypoint_base.h:19
IsValidTileForWaypoint
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Definition waypoint_cmd.cpp:152
CmdBuildRoadWaypoint
CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, RoadStopClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Build a road waypoint on an existing road.
Definition waypoint_cmd.cpp:341
CmdBuildRailWaypoint
CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Convert existing rail to waypoint.
Definition waypoint_cmd.cpp:207
CcMoveWaypointName
void CcMoveWaypointName(Commands, const CommandCost &result, StationID waypoint_id)
Callback function that is called after a name is moved.
Definition waypoint_cmd.cpp:657
IsRailStationBridgeAboveOk
CommandCost IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *spec, StationType type, StationGfx layout)
Test if a rail station can be built below a bridge.
Definition station_cmd.cpp:922
CmdMoveWaypointName
std::tuple< CommandCost, StationID > CmdMoveWaypointName(DoCommandFlags flags, StationID waypoint_id, TileIndex tile)
Move a waypoint name.
Definition waypoint_cmd.cpp:620
CanExpandRailStation
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta)
Check whether we can expand the rail part of the given station.
Definition station_cmd.cpp:1178
GetAxisForNewRailWaypoint
Axis GetAxisForNewRailWaypoint(TileIndex tile)
Get the axis for a new rail waypoint.
Definition waypoint_cmd.cpp:106
GetAxisForNewRoadWaypoint
Axis GetAxisForNewRoadWaypoint(TileIndex tile)
Get the axis for a new road waypoint.
Definition waypoint_cmd.cpp:128
FindJoiningWaypoint
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp, bool is_road)
Find a nearby waypoint that joins this waypoint.
Definition station_cmd.cpp:1302
RemoveRoadWaypointStop
CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlags flags, int replacement_spec_index)
Remove a road waypoint.
Definition station_cmd.cpp:2342
RemoveBuoy
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlags flags)
Remove a buoy.
Definition waypoint_cmd.cpp:530
ClearTile_Station
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlags flags)
Clear a single tile of a station.
Definition station_cmd.cpp:4890
CmdRenameWaypoint
CommandCost CmdRenameWaypoint(DoCommandFlags flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
Definition waypoint_cmd.cpp:584
CmdBuildBuoy
CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile)
Build a buoy.
Definition waypoint_cmd.cpp:474
IsUniqueWaypointName
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
Definition waypoint_cmd.cpp:568
FindDeletedWaypointCloseTo
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid, bool is_road)
Find a deleted waypoint close to a tile.
Definition waypoint_cmd.cpp:80
CalculateRoadStopCost
CommandCost CalculateRoadStopCost(TileArea tile_area, DoCommandFlags flags, bool is_drive_through, StationType station_type, const RoadStopSpec *roadstopspec, Axis axis, DiagDirection ddir, StationID *est, RoadType rt, Money unit_cost)
Calculates cost of new road stops within the area.
Definition station_cmd.cpp:2012
waypoint_cmd.h
Command definitions related to waypoints.
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3294
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
yapf_cache.h
Entry point for OpenTTD to YAPF's cache.
YapfNotifyTrackLayoutChange
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition yapf_rail.cpp:665