OpenTTD Source: src/tunnelbridge_cmd.cpp Source File

OpenTTD Source 13.1

tunnelbridge_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 <http://www.gnu.org/licenses/>.
6 */
7
14 #include "stdafx.h"
15 #include "newgrf_object.h"
16 #include "viewport_func.h"
17 #include "command_func.h"
18 #include "town.h"
19 #include "train.h"
20 #include "ship.h"
21 #include "roadveh.h"
22 #include "pathfinder/yapf/yapf_cache.h"
23 #include "newgrf_sound.h"
24 #include "autoslope.h"
25 #include "tunnelbridge_map.h"
26 #include "strings_func.h"
27 #include "date_func.h"
28 #include "clear_func.h"
29 #include "vehicle_func.h"
30 #include "sound_func.h"
31 #include "tunnelbridge.h"
32 #include "cheat_type.h"
33 #include "elrail_func.h"
34 #include "pbs.h"
35 #include "company_base.h"
36 #include "newgrf_railtype.h"
37 #include "newgrf_roadtype.h"
38 #include "object_base.h"
39 #include "water.h"
40 #include "company_gui.h"
41 #include "station_func.h"
42 #include "tunnelbridge_cmd.h"
43 #include "landscape_cmd.h"
44 #include "terraform_cmd.h"
45
46 #include "table/strings.h"
47 #include "table/bridge_land.h"
48
49 #include "safeguards.h"
50
51 BridgeSpec _bridge[MAX_BRIDGES];
52 TileIndex _build_tunnel_endtile;
53
55 static const int BRIDGE_Z_START = 3;
56
57
66 void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
67 {
68 TileIndexDiff delta = TileOffsByDiagDir(direction);
69 for (TileIndex t = begin; t != end; t += delta) {
70 MarkTileDirtyByTile(t, bridge_height - TileHeight(t));
71 }
72 MarkTileDirtyByTile(end);
73 }
74
79 void MarkBridgeDirty(TileIndex tile)
80 {
81 MarkBridgeDirty(tile, GetOtherTunnelBridgeEnd(tile), GetTunnelBridgeDirection(tile), GetBridgeHeight(tile));
82 }
83
85 void ResetBridges()
86 {
87 /* First, free sprite table data */
88 for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
89 if (_bridge[i].sprite_table != nullptr) {
90 for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
91 free(_bridge[i].sprite_table);
92 }
93 }
94
95 /* Then, wipe out current bridges */
96 memset(&_bridge, 0, sizeof(_bridge));
97 /* And finally, reinstall default data */
98 memcpy(&_bridge, &_orig_bridge, sizeof(_orig_bridge));
99 }
100
107 int CalcBridgeLenCostFactor(int length)
108 {
109 if (length < 2) return length;
110
111 length -= 2;
112 int sum = 2;
113 for (int delta = 1;; delta++) {
114 for (int count = 0; count < delta; count++) {
115 if (length == 0) return sum;
116 sum += delta;
117 length--;
118 }
119 }
120 }
121
128 Foundation GetBridgeFoundation(Slope tileh, Axis axis)
129 {
130 if (tileh == SLOPE_FLAT ||
131 ((tileh == SLOPE_NE || tileh == SLOPE_SW) && axis == AXIS_X) ||
132 ((tileh == SLOPE_NW || tileh == SLOPE_SE) && axis == AXIS_Y)) return FOUNDATION_NONE;
133
134 return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh));
135 }
136
144 bool HasBridgeFlatRamp(Slope tileh, Axis axis)
145 {
146 ApplyFoundationToSlope(GetBridgeFoundation(tileh, axis), &tileh);
147 /* If the foundation slope is flat the bridge has a non-flat ramp and vice versa. */
148 return (tileh != SLOPE_FLAT);
149 }
150
151 static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table)
152 {
153 const BridgeSpec *bridge = GetBridgeSpec(index);
154 assert(table < BRIDGE_PIECE_INVALID);
155 if (bridge->sprite_table == nullptr || bridge->sprite_table[table] == nullptr) {
156 return _bridge_sprite_table[index][table];
157 } else {
158 return bridge->sprite_table[table];
159 }
160 }
161
162
172 static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope *tileh, int *z)
173 {
174 assert(bridge_piece == BRIDGE_PIECE_NORTH || bridge_piece == BRIDGE_PIECE_SOUTH);
175
176 Foundation f = GetBridgeFoundation(*tileh, axis);
177 *z += ApplyFoundationToSlope(f, tileh);
178
179 Slope valid_inclined;
180 if (bridge_piece == BRIDGE_PIECE_NORTH) {
181 valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW);
182 } else {
183 valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
184 }
185 if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
186
187 if (f == FOUNDATION_NONE) return CommandCost();
188
189 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
190 }
191
199 CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
200 {
201 if (flags & DC_QUERY_COST) {
202 if (bridge_len <= _settings_game.construction.max_bridge_length) return CommandCost();
203 return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
204 }
205
206 if (bridge_type >= MAX_BRIDGES) return CMD_ERROR;
207
208 const BridgeSpec *b = GetBridgeSpec(bridge_type);
209 if (b->avail_year > _cur_year) return CMD_ERROR;
210
211 uint max = std::min(b->max_length, _settings_game.construction.max_bridge_length);
212
213 if (b->min_length > bridge_len) return CMD_ERROR;
214 if (bridge_len <= max) return CommandCost();
215 return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
216 }
217
223 static Money TunnelBridgeClearCost(TileIndex tile, Price base_price)
224 {
225 Money base_cost = _price[base_price];
226
227 /* Add the cost of the transport that is on the tunnel/bridge. */
228 switch (GetTunnelBridgeTransportType(tile)) {
229 case TRANSPORT_ROAD: {
230 RoadType road_rt = GetRoadTypeRoad(tile);
231 RoadType tram_rt = GetRoadTypeTram(tile);
232
233 if (road_rt != INVALID_ROADTYPE) {
234 base_cost += 2 * RoadClearCost(road_rt);
235 }
236 if (tram_rt != INVALID_ROADTYPE) {
237 base_cost += 2 * RoadClearCost(tram_rt);
238 }
239 } break;
240
241 case TRANSPORT_RAIL: base_cost += RailClearCost(GetRailType(tile)); break;
242 /* Aquaducts have their own clear price. */
243 case TRANSPORT_WATER: base_cost = _price[PR_CLEAR_AQUEDUCT]; break;
244 default: break;
245 }
246
247 return base_cost;
248 }
249
260 CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex tile_start, TransportType transport_type, BridgeType bridge_type, byte road_rail_type)
261 {
262 CompanyID company = _current_company;
263
264 RailType railtype = INVALID_RAILTYPE;
265 RoadType roadtype = INVALID_ROADTYPE;
266
267 if (!IsValidTile(tile_start)) return_cmd_error(STR_ERROR_BRIDGE_THROUGH_MAP_BORDER);
268
269 /* type of bridge */
270 switch (transport_type) {
271 case TRANSPORT_ROAD:
272 roadtype = (RoadType)road_rail_type;
273 if (!ValParamRoadType(roadtype)) return CMD_ERROR;
274 break;
275
276 case TRANSPORT_RAIL:
277 railtype = (RailType)road_rail_type;
278 if (!ValParamRailtype(railtype)) return CMD_ERROR;
279 break;
280
281 case TRANSPORT_WATER:
282 break;
283
284 default:
285 /* Airports don't have bridges. */
286 return CMD_ERROR;
287 }
288
289 if (company == OWNER_DEITY) {
290 if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
291 const Town *town = CalcClosestTownFromTile(tile_start);
292
293 company = OWNER_TOWN;
294
295 /* If we are not within a town, we are not owned by the town */
296 if (town == nullptr || DistanceSquare(tile_start, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
297 company = OWNER_NONE;
298 }
299 }
300
301 if (tile_start == tile_end) {
302 return_cmd_error(STR_ERROR_CAN_T_START_AND_END_ON);
303 }
304
305 Axis direction;
306 if (TileX(tile_start) == TileX(tile_end)) {
307 direction = AXIS_Y;
308 } else if (TileY(tile_start) == TileY(tile_end)) {
309 direction = AXIS_X;
310 } else {
311 return_cmd_error(STR_ERROR_START_AND_END_MUST_BE_IN);
312 }
313
314 if (tile_end < tile_start) Swap(tile_start, tile_end);
315
316 uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end);
317 if (transport_type != TRANSPORT_WATER) {
318 /* set and test bridge length, availability */
319 CommandCost ret = CheckBridgeAvailability(bridge_type, bridge_len, flags);
320 if (ret.Failed()) return ret;
321 } else {
322 if (bridge_len > _settings_game.construction.max_bridge_length) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
323 }
324 bridge_len += 2; // begin and end tiles/ramps
325
326 int z_start;
327 int z_end;
328 Slope tileh_start = GetTileSlope(tile_start, &z_start);
329 Slope tileh_end = GetTileSlope(tile_end, &z_end);
330 bool pbs_reservation = false;
331
332 CommandCost terraform_cost_north = CheckBridgeSlope(BRIDGE_PIECE_NORTH, direction, &tileh_start, &z_start);
333 CommandCost terraform_cost_south = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, direction, &tileh_end, &z_end);
334
335 /* Aqueducts can't be built of flat land. */
336 if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
337 if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
338
339 CommandCost cost(EXPENSES_CONSTRUCTION);
340 Owner owner;
341 bool is_new_owner;
342 RoadType road_rt = INVALID_ROADTYPE;
343 RoadType tram_rt = INVALID_ROADTYPE;
344 if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
345 GetOtherBridgeEnd(tile_start) == tile_end &&
346 GetTunnelBridgeTransportType(tile_start) == transport_type) {
347 /* Replace a current bridge. */
348
349 switch (transport_type) {
350 case TRANSPORT_RAIL:
351 /* Keep the reservation, the path stays valid. */
352 pbs_reservation = HasTunnelBridgeReservation(tile_start);
353 break;
354
355 case TRANSPORT_ROAD:
356 /* Do not remove road types when upgrading a bridge */
357 road_rt = GetRoadTypeRoad(tile_start);
358 tram_rt = GetRoadTypeTram(tile_start);
359 break;
360
361 default: break;
362 }
363
364 /* If this is a railway bridge, make sure the railtypes match. */
365 if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
366 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
367 }
368
369 /* If this is a road bridge, make sure the roadtype matches. */
370 if (transport_type == TRANSPORT_ROAD) {
371 RoadType existing_rt = RoadTypeIsRoad(roadtype) ? road_rt : tram_rt;
372 if (existing_rt != roadtype && existing_rt != INVALID_ROADTYPE) {
373 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
374 }
375 }
376
377 /* Do not replace town bridges with lower speed bridges, unless in scenario editor. */
378 if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
379 GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed &&
380 _game_mode != GM_EDITOR) {
381 Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
382
383 if (t == nullptr) {
384 return CMD_ERROR;
385 } else {
386 SetDParam(0, t->index);
387 return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
388 }
389 }
390
391 /* Do not replace the bridge with the same bridge type. */
392 if (!(flags & DC_QUERY_COST) && (bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || road_rt == roadtype || tram_rt == roadtype)) {
393 return_cmd_error(STR_ERROR_ALREADY_BUILT);
394 }
395
396 /* Do not allow replacing another company's bridges. */
397 if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN) && !IsTileOwner(tile_start, OWNER_NONE)) {
398 return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
399 }
400
401 /* The cost of clearing the current bridge. */
402 cost.AddCost(bridge_len * TunnelBridgeClearCost(tile_start, PR_CLEAR_BRIDGE));
403 owner = GetTileOwner(tile_start);
404
405 /* If bridge belonged to bankrupt company, it has a new owner now */
406 is_new_owner = (owner == OWNER_NONE);
407 if (is_new_owner) owner = company;
408 } else {
409 /* Build a new bridge. */
410
411 bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
412
413 /* Try and clear the start landscape */
414 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_start);
415 if (ret.Failed()) return ret;
416 cost = ret;
417
418 if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
419 cost.AddCost(terraform_cost_north);
420
421 /* Try and clear the end landscape */
422 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end);
423 if (ret.Failed()) return ret;
424 cost.AddCost(ret);
425
426 /* false - end tile slope check */
427 if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
428 cost.AddCost(terraform_cost_south);
429
430 const TileIndex heads[] = {tile_start, tile_end};
431 for (int i = 0; i < 2; i++) {
432 if (IsBridgeAbove(heads[i])) {
433 TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
434
435 if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
436
437 if (z_start + 1 == GetBridgeHeight(north_head)) {
438 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
439 }
440 }
441 }
442
443 TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
444 for (TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
445 if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN);
446
447 if (z_start >= (GetTileZ(tile) + _settings_game.construction.max_bridge_height)) {
448 /*
449 * Disallow too high bridges.
450 * Properly rendering a map where very high bridges (might) exist is expensive.
451 * See http://www.tt-forums.net/viewtopic.php?f=33&t=40844&start=980#p1131762
452 * for a detailed discussion. z_start here is one heightlevel below the bridge level.
453 */
454 return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_FOR_TERRAIN);
455 }
456
457 if (IsBridgeAbove(tile)) {
458 /* Disallow crossing bridges for the time being */
459 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
460 }
461
462 switch (GetTileType(tile)) {
463 case MP_WATER:
464 if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
465 break;
466
467 case MP_RAILWAY:
468 if (!IsPlainRail(tile)) goto not_valid_below;
469 break;
470
471 case MP_ROAD:
472 if (IsRoadDepot(tile)) goto not_valid_below;
473 break;
474
475 case MP_TUNNELBRIDGE:
476 if (IsTunnel(tile)) break;
477 if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
478 if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
479 break;
480
481 case MP_OBJECT: {
482 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
483 if ((spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) == 0) goto not_valid_below;
484 if (GetTileMaxZ(tile) + spec->height > z_start) goto not_valid_below;
485 break;
486 }
487
488 case MP_CLEAR:
489 break;
490
491 default:
492 not_valid_below:;
493 /* try and clear the middle landscape */
494 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
495 if (ret.Failed()) return ret;
496 cost.AddCost(ret);
497 break;
498 }
499
500 if (flags & DC_EXEC) {
501 /* We do this here because when replacing a bridge with another
502 * type calling SetBridgeMiddle isn't needed. After all, the
503 * tile already has the has_bridge_above bits set. */
504 SetBridgeMiddle(tile, direction);
505 }
506 }
507
508 owner = company;
509 is_new_owner = true;
510 }
511
512 bool hasroad = road_rt != INVALID_ROADTYPE;
513 bool hastram = tram_rt != INVALID_ROADTYPE;
514 if (transport_type == TRANSPORT_ROAD) {
515 if (RoadTypeIsRoad(roadtype)) road_rt = roadtype;
516 if (RoadTypeIsTram(roadtype)) tram_rt = roadtype;
517 }
518
519 /* do the drill? */
520 if (flags & DC_EXEC) {
521 DiagDirection dir = AxisToDiagDir(direction);
522
523 Company *c = Company::GetIfValid(company);
524 switch (transport_type) {
525 case TRANSPORT_RAIL:
526 /* Add to company infrastructure count if required. */
527 if (is_new_owner && c != nullptr) c->infrastructure.rail[railtype] += bridge_len * TUNNELBRIDGE_TRACKBIT_FACTOR;
528 MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype);
529 MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype);
530 SetTunnelBridgeReservation(tile_start, pbs_reservation);
531 SetTunnelBridgeReservation(tile_end, pbs_reservation);
532 break;
533
534 case TRANSPORT_ROAD: {
535 if (is_new_owner) {
536 /* Also give unowned present roadtypes to new owner */
537 if (hasroad && GetRoadOwner(tile_start, RTT_ROAD) == OWNER_NONE) hasroad = false;
538 if (hastram && GetRoadOwner(tile_start, RTT_TRAM) == OWNER_NONE) hastram = false;
539 }
540 if (c != nullptr) {
541 /* Add all new road types to the company infrastructure counter. */
542 if (!hasroad && road_rt != INVALID_ROADTYPE) {
543 /* A full diagonal road tile has two road bits. */
544 c->infrastructure.road[road_rt] += bridge_len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
545 }
546 if (!hastram && tram_rt != INVALID_ROADTYPE) {
547 /* A full diagonal road tile has two road bits. */
548 c->infrastructure.road[tram_rt] += bridge_len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
549 }
550 }
551 Owner owner_road = hasroad ? GetRoadOwner(tile_start, RTT_ROAD) : company;
552 Owner owner_tram = hastram ? GetRoadOwner(tile_start, RTT_TRAM) : company;
553 MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, road_rt, tram_rt);
554 MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), road_rt, tram_rt);
555 break;
556 }
557
558 case TRANSPORT_WATER:
559 if (is_new_owner && c != nullptr) c->infrastructure.water += bridge_len * TUNNELBRIDGE_TRACKBIT_FACTOR;
560 MakeAqueductBridgeRamp(tile_start, owner, dir);
561 MakeAqueductBridgeRamp(tile_end, owner, ReverseDiagDir(dir));
562 CheckForDockingTile(tile_start);
563 CheckForDockingTile(tile_end);
564 break;
565
566 default:
567 NOT_REACHED();
568 }
569
570 /* Mark all tiles dirty */
571 MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
572 DirtyCompanyInfrastructureWindows(company);
573 }
574
575 if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
576 Track track = AxisToTrack(direction);
577 AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, company);
578 YapfNotifyTrackLayoutChange(tile_start, track);
579 }
580
581 /* Human players that build bridges get a selection to choose from (DC_QUERY_COST)
582 * It's unnecessary to execute this command every time for every bridge.
583 * So it is done only for humans and cost is computed in bridge_gui.cpp.
584 * For (non-spectated) AI, Towns this has to be of course calculated. */
585 Company *c = Company::GetIfValid(company);
586 if (!(flags & DC_QUERY_COST) || (c != nullptr && c->is_ai && company != _local_company)) {
587 switch (transport_type) {
588 case TRANSPORT_ROAD:
589 if (road_rt != INVALID_ROADTYPE) {
590 cost.AddCost(bridge_len * 2 * RoadBuildCost(road_rt));
591 }
592 if (tram_rt != INVALID_ROADTYPE) {
593 cost.AddCost(bridge_len * 2 * RoadBuildCost(tram_rt));
594 }
595 break;
596
597 case TRANSPORT_RAIL: cost.AddCost(bridge_len * RailBuildCost(railtype)); break;
598 default: break;
599 }
600
601 if (c != nullptr) bridge_len = CalcBridgeLenCostFactor(bridge_len);
602
603 if (transport_type != TRANSPORT_WATER) {
604 cost.AddCost((int64)bridge_len * _price[PR_BUILD_BRIDGE] * GetBridgeSpec(bridge_type)->price >> 8);
605 } else {
606 /* Aqueducts use a separate base cost. */
607 cost.AddCost((int64)bridge_len * _price[PR_BUILD_AQUEDUCT]);
608 }
609
610 }
611
612 return cost;
613 }
614
615
624 CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportType transport_type, byte road_rail_type)
625 {
626 CompanyID company = _current_company;
627
628 RailType railtype = INVALID_RAILTYPE;
629 RoadType roadtype = INVALID_ROADTYPE;
630 _build_tunnel_endtile = 0;
631 switch (transport_type) {
632 case TRANSPORT_RAIL:
633 railtype = (RailType)road_rail_type;
634 if (!ValParamRailtype(railtype)) return CMD_ERROR;
635 break;
636
637 case TRANSPORT_ROAD:
638 roadtype = (RoadType)road_rail_type;
639 if (!ValParamRoadType(roadtype)) return CMD_ERROR;
640 break;
641
642 default: return CMD_ERROR;
643 }
644
645 if (company == OWNER_DEITY) {
646 if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
647 const Town *town = CalcClosestTownFromTile(start_tile);
648
649 company = OWNER_TOWN;
650
651 /* If we are not within a town, we are not owned by the town */
652 if (town == nullptr || DistanceSquare(start_tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
653 company = OWNER_NONE;
654 }
655 }
656
657 int start_z;
658 int end_z;
659 Slope start_tileh = GetTileSlope(start_tile, &start_z);
660 DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
661 if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
662
663 if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
664
665 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, start_tile);
666 if (ret.Failed()) return ret;
667
668 /* XXX - do NOT change 'ret' in the loop, as it is used as the price
669 * for the clearing of the entrance of the tunnel. Assigning it to
670 * cost before the loop will yield different costs depending on start-
671 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
672
673 TileIndexDiff delta = TileOffsByDiagDir(direction);
674 DiagDirection tunnel_in_way_dir;
675 if (DiagDirToAxis(direction) == AXIS_Y) {
676 tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
677 } else {
678 tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
679 }
680
681 TileIndex end_tile = start_tile;
682
683 /* Tile shift coefficient. Will decrease for very long tunnels to avoid exponential growth of price*/
684 int tiles_coef = 3;
685 /* Number of tiles from start of tunnel */
686 int tiles = 0;
687 /* Number of tiles at which the cost increase coefficient per tile is halved */
688 int tiles_bump = 25;
689
690 CommandCost cost(EXPENSES_CONSTRUCTION);
691 Slope end_tileh;
692 for (;;) {
693 end_tile += delta;
694 if (!IsValidTile(end_tile)) return_cmd_error(STR_ERROR_TUNNEL_THROUGH_MAP_BORDER);
695 end_tileh = GetTileSlope(end_tile, &end_z);
696
697 if (start_z == end_z) break;
698
699 if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) {
700 return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
701 }
702
703 tiles++;
704 if (tiles == tiles_bump) {
705 tiles_coef++;
706 tiles_bump *= 2;
707 }
708
709 cost.AddCost(_price[PR_BUILD_TUNNEL]);
710 cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels
711 }
712
713 /* Add the cost of the entrance */
714 cost.AddCost(_price[PR_BUILD_TUNNEL]);
715 cost.AddCost(ret);
716
717 /* if the command fails from here on we want the end tile to be highlighted */
718 _build_tunnel_endtile = end_tile;
719
720 if (tiles > _settings_game.construction.max_tunnel_length) return_cmd_error(STR_ERROR_TUNNEL_TOO_LONG);
721
722 if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
723
724 /* Clear the tile in any case */
725 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile);
726 if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
727 cost.AddCost(ret);
728
729 /* slope of end tile must be complementary to the slope of the start tile */
730 if (end_tileh != ComplementSlope(start_tileh)) {
731 /* Mark the tile as already cleared for the terraform command.
732 * Do this for all tiles (like trees), not only objects. */
733 ClearedObjectArea *coa = FindClearedObject(end_tile);
734 if (coa == nullptr) {
735 coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
736 }
737
738 /* Hide the tile from the terraforming command */
739 TileIndex old_first_tile = coa->first_tile;
740 coa->first_tile = INVALID_TILE;
741
742 /* CMD_TERRAFORM_LAND may append further items to _cleared_object_areas,
743 * however it will never erase or re-order existing items.
744 * _cleared_object_areas is a value-type self-resizing vector, therefore appending items
745 * may result in a backing-store re-allocation, which would invalidate the coa pointer.
746 * The index of the coa pointer into the _cleared_object_areas vector remains valid,
747 * and can be used safely after the CMD_TERRAFORM_LAND operation.
748 * Deliberately clear the coa pointer to avoid leaving dangling pointers which could
749 * inadvertently be dereferenced.
750 */
751 ClearedObjectArea *begin = _cleared_object_areas.data();
752 assert(coa >= begin && coa < begin + _cleared_object_areas.size());
753 size_t coa_index = coa - begin;
754 assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
755 coa = nullptr;
756
757 ret = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, false));
758 _cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
759 if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
760 cost.AddCost(ret);
761 }
762 cost.AddCost(_price[PR_BUILD_TUNNEL]);
763
764 /* Pay for the rail/road in the tunnel including entrances */
765 switch (transport_type) {
766 case TRANSPORT_ROAD: cost.AddCost((tiles + 2) * RoadBuildCost(roadtype) * 2); break;
767 case TRANSPORT_RAIL: cost.AddCost((tiles + 2) * RailBuildCost(railtype)); break;
768 default: NOT_REACHED();
769 }
770
771 if (flags & DC_EXEC) {
772 Company *c = Company::GetIfValid(company);
773 uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
774 if (transport_type == TRANSPORT_RAIL) {
775 if (c != nullptr) c->infrastructure.rail[railtype] += num_pieces;
776 MakeRailTunnel(start_tile, company, direction, railtype);
777 MakeRailTunnel(end_tile, company, ReverseDiagDir(direction), railtype);
778 AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
779 YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
780 } else {
781 if (c != nullptr) c->infrastructure.road[roadtype] += num_pieces * 2; // A full diagonal road has two road bits.
782 RoadType road_rt = RoadTypeIsRoad(roadtype) ? roadtype : INVALID_ROADTYPE;
783 RoadType tram_rt = RoadTypeIsTram(roadtype) ? roadtype : INVALID_ROADTYPE;
784 MakeRoadTunnel(start_tile, company, direction, road_rt, tram_rt);
785 MakeRoadTunnel(end_tile, company, ReverseDiagDir(direction), road_rt, tram_rt);
786 }
787 DirtyCompanyInfrastructureWindows(company);
788 }
789
790 return cost;
791 }
792
793
799 static inline CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
800 {
801 /* Floods can remove anything as well as the scenario editor */
802 if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return CommandCost();
803
804 switch (GetTunnelBridgeTransportType(tile)) {
805 case TRANSPORT_ROAD: {
806 RoadType road_rt = GetRoadTypeRoad(tile);
807 RoadType tram_rt = GetRoadTypeTram(tile);
808 Owner road_owner = _current_company;
809 Owner tram_owner = _current_company;
810
811 if (road_rt != INVALID_ROADTYPE) road_owner = GetRoadOwner(tile, RTT_ROAD);
812 if (tram_rt != INVALID_ROADTYPE) tram_owner = GetRoadOwner(tile, RTT_TRAM);
813
814 /* We can remove unowned road and if the town allows it */
815 if (road_owner == OWNER_TOWN && _current_company != OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) {
816 /* Town does not allow */
817 return CheckTileOwnership(tile);
818 }
819 if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
820 if (tram_owner == OWNER_NONE) tram_owner = _current_company;
821
822 CommandCost ret = CheckOwnership(road_owner, tile);
823 if (ret.Succeeded()) ret = CheckOwnership(tram_owner, tile);
824 return ret;
825 }
826
827 case TRANSPORT_RAIL:
828 return CheckOwnership(GetTileOwner(tile));
829
830 case TRANSPORT_WATER: {
831 /* Always allow to remove aqueducts without owner. */
832 Owner aqueduct_owner = GetTileOwner(tile);
833 if (aqueduct_owner == OWNER_NONE) aqueduct_owner = _current_company;
834 return CheckOwnership(aqueduct_owner);
835 }
836
837 default: NOT_REACHED();
838 }
839 }
840
847 static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
848 {
849 CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
850 if (ret.Failed()) return ret;
851
852 TileIndex endtile = GetOtherTunnelEnd(tile);
853
854 ret = TunnelBridgeIsFree(tile, endtile);
855 if (ret.Failed()) return ret;
856
857 _build_tunnel_endtile = endtile;
858
859 Town *t = nullptr;
860 if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
861 t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
862
863 /* Check if you are allowed to remove the tunnel owned by a town
864 * Removal depends on difficulty settings */
865 CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
866 if (ret.Failed()) return ret;
867 }
868
869 /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
870 * you have a "Poor" (0) town rating */
871 if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
872 ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
873 }
874
875 Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_TUNNEL);
876 uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
877
878 if (flags & DC_EXEC) {
879 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
880 /* We first need to request values before calling DoClearSquare */
881 DiagDirection dir = GetTunnelBridgeDirection(tile);
882 Track track = DiagDirToDiagTrack(dir);
883 Owner owner = GetTileOwner(tile);
884
885 Train *v = nullptr;
886 if (HasTunnelBridgeReservation(tile)) {
887 v = GetTrainForReservation(tile, track);
888 if (v != nullptr) FreeTrainTrackReservation(v);
889 }
890
891 if (Company::IsValidID(owner)) {
892 Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
893 DirtyCompanyInfrastructureWindows(owner);
894 }
895
896 DoClearSquare(tile);
897 DoClearSquare(endtile);
898
899 /* cannot use INVALID_DIAGDIR for signal update because the tunnel doesn't exist anymore */
900 AddSideToSignalBuffer(tile, ReverseDiagDir(dir), owner);
901 AddSideToSignalBuffer(endtile, dir, owner);
902
903 YapfNotifyTrackLayoutChange(tile, track);
904 YapfNotifyTrackLayoutChange(endtile, track);
905
906 if (v != nullptr) TryPathReserve(v);
907 } else {
908 /* A full diagonal road tile has two road bits. */
909 UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
910 UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
911
912 DoClearSquare(tile);
913 DoClearSquare(endtile);
914 }
915 }
916
917 return CommandCost(EXPENSES_CONSTRUCTION, len * base_cost);
918 }
919
920
927 static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
928 {
929 CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
930 if (ret.Failed()) return ret;
931
932 TileIndex endtile = GetOtherBridgeEnd(tile);
933
934 ret = TunnelBridgeIsFree(tile, endtile);
935 if (ret.Failed()) return ret;
936
937 DiagDirection direction = GetTunnelBridgeDirection(tile);
938 TileIndexDiff delta = TileOffsByDiagDir(direction);
939
940 Town *t = nullptr;
941 if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
942 t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
943
944 /* Check if you are allowed to remove the bridge owned by a town
945 * Removal depends on difficulty settings */
946 CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
947 if (ret.Failed()) return ret;
948 }
949
950 /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
951 * you have a "Poor" (0) town rating */
952 if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
953 ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
954 }
955
956 Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_BRIDGE);
957 uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
958
959 if (flags & DC_EXEC) {
960 /* read this value before actual removal of bridge */
961 bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
962 Owner owner = GetTileOwner(tile);
963 int height = GetBridgeHeight(tile);
964 Train *v = nullptr;
965
966 if (rail && HasTunnelBridgeReservation(tile)) {
967 v = GetTrainForReservation(tile, DiagDirToDiagTrack(direction));
968 if (v != nullptr) FreeTrainTrackReservation(v);
969 }
970
971 /* Update company infrastructure counts. */
972 if (rail) {
973 if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
974 } else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
975 /* A full diagonal road tile has two road bits. */
976 UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
977 UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
978 } else { // Aqueduct
979 if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
980 }
981 DirtyCompanyInfrastructureWindows(owner);
982
983 DoClearSquare(tile);
984 DoClearSquare(endtile);
985
986 for (TileIndex c = tile + delta; c != endtile; c += delta) {
987 /* do not let trees appear from 'nowhere' after removing bridge */
988 if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) {
989 int minz = GetTileMaxZ(c) + 3;
990 if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
991 }
992 ClearBridgeMiddle(c);
993 MarkTileDirtyByTile(c, height - TileHeight(c));
994 }
995
996 if (rail) {
997 /* cannot use INVALID_DIAGDIR for signal update because the bridge doesn't exist anymore */
998 AddSideToSignalBuffer(tile, ReverseDiagDir(direction), owner);
999 AddSideToSignalBuffer(endtile, direction, owner);
1000
1001 Track track = DiagDirToDiagTrack(direction);
1002 YapfNotifyTrackLayoutChange(tile, track);
1003 YapfNotifyTrackLayoutChange(endtile, track);
1004
1005 if (v != nullptr) TryPathReserve(v, true);
1006 }
1007 }
1008
1009 return CommandCost(EXPENSES_CONSTRUCTION, len * base_cost);
1010 }
1011
1018 static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
1019 {
1020 if (IsTunnel(tile)) {
1021 if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST);
1022 return DoClearTunnel(tile, flags);
1023 } else { // IsBridge(tile)
1024 if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
1025 return DoClearBridge(tile, flags);
1026 }
1027 }
1028
1039 static inline void DrawPillar(const PalSpriteID *psid, int x, int y, int z, int w, int h, const SubSprite *subsprite)
1040 {
1041 static const int PILLAR_Z_OFFSET = TILE_HEIGHT - BRIDGE_Z_START;
1042 AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET, subsprite);
1043 }
1044
1056 static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, int x, int y, int w, int h)
1057 {
1058 int cur_z;
1059 for (cur_z = z_top; cur_z >= z_bottom; cur_z -= TILE_HEIGHT) {
1060 DrawPillar(psid, x, y, cur_z, w, h, nullptr);
1061 }
1062 return cur_z;
1063 }
1064
1076 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
1077 {
1078 static const int bounding_box_size[2] = {16, 2};
1079 static const int back_pillar_offset[2] = { 0, 9};
1080
1081 static const int INF = 1000;
1082 static const SubSprite half_pillar_sub_sprite[2][2] = {
1083 { { -14, -INF, INF, INF }, { -INF, -INF, -15, INF } }, // X axis, north and south
1084 { { -INF, -INF, 15, INF }, { 16, -INF, INF, INF } }, // Y axis, north and south
1085 };
1086
1087 if (psid->sprite == 0) return;
1088
1089 /* Determine ground height under pillars */
1090 DiagDirection south_dir = AxisToDiagDir(axis);
1091 int z_front_north = ti->z;
1092 int z_back_north = ti->z;
1093 int z_front_south = ti->z;
1094 int z_back_south = ti->z;
1095 GetSlopePixelZOnEdge(ti->tileh, south_dir, &z_front_south, &z_back_south);
1096 GetSlopePixelZOnEdge(ti->tileh, ReverseDiagDir(south_dir), &z_front_north, &z_back_north);
1097
1098 /* Shared height of pillars */
1099 int z_front = std::max(z_front_north, z_front_south);
1100 int z_back = std::max(z_back_north, z_back_south);
1101
1102 /* x and y size of bounding-box of pillars */
1103 int w = bounding_box_size[axis];
1104 int h = bounding_box_size[OtherAxis(axis)];
1105 /* sprite position of back facing pillar */
1106 int x_back = x - back_pillar_offset[axis];
1107 int y_back = y - back_pillar_offset[OtherAxis(axis)];
1108
1109 /* Draw front pillars */
1110 int bottom_z = DrawPillarColumn(z_front, z_bridge, psid, x, y, w, h);
1111 if (z_front_north < z_front) DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
1112 if (z_front_south < z_front) DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
1113
1114 /* Draw back pillars, skip top two parts, which are hidden by the bridge */
1115 int z_bridge_back = z_bridge - 2 * (int)TILE_HEIGHT;
1116 if (drawfarpillar && (z_back_north <= z_bridge_back || z_back_south <= z_bridge_back)) {
1117 bottom_z = DrawPillarColumn(z_back, z_bridge_back, psid, x_back, y_back, w, h);
1118 if (z_back_north < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
1119 if (z_back_south < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
1120 }
1121 }
1122
1132 static void GetBridgeRoadCatenary(const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
1133 {
1134 static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
1135 static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
1136
1137 /* Simplified from DrawRoadTypeCatenary() to remove all the special cases required for regular ground road */
1138 spr_back = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
1139 spr_front = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
1140 if (spr_back == 0 && spr_front == 0) {
1141 spr_back = SPR_TRAMWAY_BASE + back_offsets[offset];
1142 spr_front = SPR_TRAMWAY_BASE + front_offsets[offset];
1143 } else {
1144 if (spr_back != 0) spr_back += 23 + offset;
1145 if (spr_front != 0) spr_front += 23 + offset;
1146 }
1147 }
1148
1158 static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int offset, bool head)
1159 {
1160 RoadType road_rt = GetRoadTypeRoad(head_tile);
1161 RoadType tram_rt = GetRoadTypeTram(head_tile);
1162 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1163 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1164
1165 SpriteID seq_back[4] = { 0 };
1166 bool trans_back[4] = { false };
1167 SpriteID seq_front[4] = { 0 };
1168 bool trans_front[4] = { false };
1169
1170 static const SpriteID overlay_offsets[6] = { 0, 1, 11, 12, 13, 14 };
1171 if (head || !IsInvisibilitySet(TO_BRIDGES)) {
1172 /* Road underlay takes precedence over tram */
1173 trans_back[0] = !head && IsTransparencySet(TO_BRIDGES);
1174 if (road_rti != nullptr) {
1175 if (road_rti->UsesOverlay()) {
1176 seq_back[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
1177 }
1178 } else if (tram_rti != nullptr) {
1179 if (tram_rti->UsesOverlay()) {
1180 seq_back[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
1181 } else {
1182 seq_back[0] = SPR_TRAMWAY_BRIDGE + offset;
1183 }
1184 }
1185
1186 /* Draw road overlay */
1187 trans_back[1] = !head && IsTransparencySet(TO_BRIDGES);
1188 if (road_rti != nullptr) {
1189 if (road_rti->UsesOverlay()) {
1190 seq_back[1] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
1191 if (seq_back[1] != 0) seq_back[1] += overlay_offsets[offset];
1192 }
1193 }
1194
1195 /* Draw tram overlay */
1196 trans_back[2] = !head && IsTransparencySet(TO_BRIDGES);
1197 if (tram_rti != nullptr) {
1198 if (tram_rti->UsesOverlay()) {
1199 seq_back[2] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
1200 if (seq_back[2] != 0) seq_back[2] += overlay_offsets[offset];
1201 } else if (road_rti != nullptr) {
1202 seq_back[2] = SPR_TRAMWAY_OVERLAY + overlay_offsets[offset];
1203 }
1204 }
1205
1206 /* Road catenary takes precedence over tram */
1207 trans_back[3] = IsTransparencySet(TO_CATENARY);
1208 trans_front[0] = IsTransparencySet(TO_CATENARY);
1209 if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
1210 GetBridgeRoadCatenary(road_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
1211 } else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
1212 GetBridgeRoadCatenary(tram_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
1213 }
1214 }
1215
1216 static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 };
1217 static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 };
1218 static const uint front_bb_offset_x[6] = { 15, 0, 0, 15, 0, 15 };
1219 static const uint front_bb_offset_y[6] = { 0, 15, 15, 0, 15, 0 };
1220
1221 /* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called
1222 * The bounding boxes here are the same as for bridge front/roof */
1223 for (uint i = 0; i < lengthof(seq_back); ++i) {
1224 if (seq_back[i] != 0) {
1225 AddSortableSpriteToDraw(seq_back[i], PAL_NONE,
1226 x, y, size_x[offset], size_y[offset], 0x28, z,
1227 trans_back[i]);
1228 }
1229 }
1230
1231 /* Start a new SpriteCombine for the front part */
1232 EndSpriteCombine();
1233 StartSpriteCombine();
1234
1235 for (uint i = 0; i < lengthof(seq_front); ++i) {
1236 if (seq_front[i] != 0) {
1237 AddSortableSpriteToDraw(seq_front[i], PAL_NONE,
1238 x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
1239 trans_front[i],
1240 front_bb_offset_x[offset], front_bb_offset_y[offset]);
1241 }
1242 }
1243 }
1244
1258 static void DrawTile_TunnelBridge(TileInfo *ti)
1259 {
1260 TransportType transport_type = GetTunnelBridgeTransportType(ti->tile);
1261 DiagDirection tunnelbridge_direction = GetTunnelBridgeDirection(ti->tile);
1262
1263 if (IsTunnel(ti->tile)) {
1264 /* Front view of tunnel bounding boxes:
1265 *
1266 * 122223 <- BB_Z_SEPARATOR
1267 * 1 3
1268 * 1 3 1,3 = empty helper BB
1269 * 1 3 2 = SpriteCombine of tunnel-roof and catenary (tram & elrail)
1270 *
1271 */
1272
1273 static const int _tunnel_BB[4][12] = {
1274 /* tunnnel-roof | Z-separator | tram-catenary
1275 * w h bb_x bb_y| x y w h |bb_x bb_y w h */
1276 { 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // NE
1277 { 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // SE
1278 { 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // SW
1279 { 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // NW
1280 };
1281 const int *BB_data = _tunnel_BB[tunnelbridge_direction];
1282
1283 bool catenary = false;
1284
1285 SpriteID image;
1286 SpriteID railtype_overlay = 0;
1287 if (transport_type == TRANSPORT_RAIL) {
1288 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
1289 image = rti->base_sprites.tunnel;
1290 if (rti->UsesOverlay()) {
1291 /* Check if the railtype has custom tunnel portals. */
1292 railtype_overlay = GetCustomRailSprite(rti, ti->tile, RTSG_TUNNEL_PORTAL);
1293 if (railtype_overlay != 0) image = SPR_RAILTYPE_TUNNEL_BASE; // Draw blank grass tunnel base.
1294 }
1295 } else {
1296 image = SPR_TUNNEL_ENTRY_REAR_ROAD;
1297 }
1298
1299 if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += railtype_overlay != 0 ? 8 : 32;
1300
1301 image += tunnelbridge_direction * 2;
1302 DrawGroundSprite(image, PAL_NONE);
1303
1304 if (transport_type == TRANSPORT_ROAD) {
1305 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1306 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1307 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1308 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1309 uint sprite_offset = DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? 1 : 0;
1310 bool draw_underlay = true;
1311
1312 /* Road underlay takes precedence over tram */
1313 if (road_rti != nullptr) {
1314 if (road_rti->UsesOverlay()) {
1315 SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_TUNNEL);
1316 if (ground != 0) {
1317 DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE);
1318 draw_underlay = false;
1319 }
1320 }
1321 } else {
1322 if (tram_rti->UsesOverlay()) {
1323 SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_TUNNEL);
1324 if (ground != 0) {
1325 DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE);
1326 draw_underlay = false;
1327 }
1328 }
1329 }
1330
1331 DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset, draw_underlay);
1332
1333 /* Road catenary takes precedence over tram */
1334 SpriteID catenary_sprite_base = 0;
1335 if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
1336 catenary_sprite_base = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_CATENARY_FRONT);
1337 if (catenary_sprite_base == 0) {
1338 catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
1339 } else {
1340 catenary_sprite_base += 19;
1341 }
1342 } else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
1343 catenary_sprite_base = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_CATENARY_FRONT);
1344 if (catenary_sprite_base == 0) {
1345 catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
1346 } else {
1347 catenary_sprite_base += 19;
1348 }
1349 }
1350
1351 if (catenary_sprite_base != 0) {
1352 catenary = true;
1353 StartSpriteCombine();
1354 AddSortableSpriteToDraw(catenary_sprite_base + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
1355 }
1356 } else {
1357 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
1358 if (rti->UsesOverlay()) {
1359 SpriteID surface = GetCustomRailSprite(rti, ti->tile, RTSG_TUNNEL);
1360 if (surface != 0) DrawGroundSprite(surface + tunnelbridge_direction, PAL_NONE);
1361 }
1362
1363 /* PBS debugging, draw reserved tracks darker */
1364 if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasTunnelBridgeReservation(ti->tile)) {
1365 if (rti->UsesOverlay()) {
1366 SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
1367 DrawGroundSprite(overlay + RTO_X + DiagDirToAxis(tunnelbridge_direction), PALETTE_CRASH);
1368 } else {
1369 DrawGroundSprite(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH);
1370 }
1371 }
1372
1373 if (HasRailCatenaryDrawn(GetRailType(ti->tile))) {
1374 /* Maybe draw pylons on the entry side */
1375 DrawRailCatenary(ti);
1376
1377 catenary = true;
1378 StartSpriteCombine();
1379 /* Draw wire above the ramp */
1380 DrawRailCatenaryOnTunnel(ti);
1381 }
1382 }
1383
1384 if (railtype_overlay != 0 && !catenary) StartSpriteCombine();
1385
1386 AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, BB_data[0], BB_data[1], TILE_HEIGHT, ti->z, false, BB_data[2], BB_data[3], BB_Z_SEPARATOR);
1387 /* Draw railtype tunnel portal overlay if defined. */
1388 if (railtype_overlay != 0) AddSortableSpriteToDraw(railtype_overlay + tunnelbridge_direction, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, BB_data[0], BB_data[1], TILE_HEIGHT, ti->z, false, BB_data[2], BB_data[3], BB_Z_SEPARATOR);
1389
1390 if (catenary || railtype_overlay != 0) EndSpriteCombine();
1391
1392 /* Add helper BB for sprite sorting that separates the tunnel from things beside of it. */
1393 AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x, ti->y, BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
1394 AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x + BB_data[4], ti->y + BB_data[5], BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
1395
1396 DrawBridgeMiddle(ti);
1397 } else { // IsBridge(ti->tile)
1398 const PalSpriteID *psid;
1399 int base_offset;
1400 bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
1401
1402 if (transport_type == TRANSPORT_RAIL) {
1403 base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
1404 assert(base_offset != 8); // This one is used for roads
1405 } else {
1406 base_offset = 8;
1407 }
1408
1409 /* as the lower 3 bits are used for other stuff, make sure they are clear */
1410 assert( (base_offset & 0x07) == 0x00);
1411
1412 DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(tunnelbridge_direction)));
1413
1414 /* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
1415 base_offset += (6 - tunnelbridge_direction) % 4;
1416
1417 /* Table number BRIDGE_PIECE_HEAD always refers to the bridge heads for any bridge type */
1418 if (transport_type != TRANSPORT_WATER) {
1419 if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
1420 psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), BRIDGE_PIECE_HEAD)[base_offset];
1421 } else {
1422 psid = _aqueduct_sprites + base_offset;
1423 }
1424
1425 if (!ice) {
1426 TileIndex next = ti->tile + TileOffsByDiagDir(tunnelbridge_direction);
1427 if (ti->tileh != SLOPE_FLAT && ti->z == 0 && HasTileWaterClass(next) && GetWaterClass(next) == WATER_CLASS_SEA) {
1428 DrawShoreTile(ti->tileh);
1429 } else {
1430 DrawClearLandTile(ti, 3);
1431 }
1432 } else {
1433 DrawGroundSprite(SPR_FLAT_SNOW_DESERT_TILE + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
1434 }
1435
1436 /* draw ramp */
1437
1438 /* Draw Trambits and PBS Reservation as SpriteCombine */
1439 if (transport_type == TRANSPORT_ROAD || transport_type == TRANSPORT_RAIL) StartSpriteCombine();
1440
1441 /* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
1442 * it doesn't disappear behind it
1443 */
1444 /* Bridge heads are drawn solid no matter how invisibility/transparency is set */
1445 AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z);
1446
1447 if (transport_type == TRANSPORT_ROAD) {
1448 uint offset = tunnelbridge_direction;
1449 int z = ti->z;
1450 if (ti->tileh != SLOPE_FLAT) {
1451 offset = (offset + 1) & 1;
1452 z += TILE_HEIGHT;
1453 } else {
1454 offset += 2;
1455 }
1456
1457 /* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
1458 DrawBridgeRoadBits(ti->tile, ti->x, ti->y, z, offset, true);
1459
1460 EndSpriteCombine();
1461 } else if (transport_type == TRANSPORT_RAIL) {
1462 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
1463 if (rti->UsesOverlay()) {
1464 SpriteID surface = GetCustomRailSprite(rti, ti->tile, RTSG_BRIDGE);
1465 if (surface != 0) {
1466 if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
1467 AddSortableSpriteToDraw(surface + ((DiagDirToAxis(tunnelbridge_direction) == AXIS_X) ? RTBO_X : RTBO_Y), PAL_NONE, ti->x, ti->y, 16, 16, 0, ti->z + 8);
1468 } else {
1469 AddSortableSpriteToDraw(surface + RTBO_SLOPE + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, 16, 16, 8, ti->z);
1470 }
1471 }
1472 /* Don't fallback to non-overlay sprite -- the spec states that
1473 * if an overlay is present then the bridge surface must be
1474 * present. */
1475 }
1476
1477 /* PBS debugging, draw reserved tracks darker */
1478 if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasTunnelBridgeReservation(ti->tile)) {
1479 if (rti->UsesOverlay()) {
1480 SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
1481 if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
1482 AddSortableSpriteToDraw(overlay + RTO_X + DiagDirToAxis(tunnelbridge_direction), PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);
1483 } else {
1484 AddSortableSpriteToDraw(overlay + RTO_SLOPE_NE + tunnelbridge_direction, PALETTE_CRASH, ti->x, ti->y, 16, 16, 8, ti->z);
1485 }
1486 } else {
1487 if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
1488 AddSortableSpriteToDraw(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);
1489 } else {
1490 AddSortableSpriteToDraw(rti->base_sprites.single_sloped + tunnelbridge_direction, PALETTE_CRASH, ti->x, ti->y, 16, 16, 8, ti->z);
1491 }
1492 }
1493 }
1494
1495 EndSpriteCombine();
1496 if (HasRailCatenaryDrawn(GetRailType(ti->tile))) {
1497 DrawRailCatenary(ti);
1498 }
1499 }
1500
1501 DrawBridgeMiddle(ti);
1502 }
1503 }
1504
1505
1524 static BridgePieces CalcBridgePiece(uint north, uint south)
1525 {
1526 if (north == 1) {
1527 return BRIDGE_PIECE_NORTH;
1528 } else if (south == 1) {
1529 return BRIDGE_PIECE_SOUTH;
1530 } else if (north < south) {
1531 return north & 1 ? BRIDGE_PIECE_INNER_SOUTH : BRIDGE_PIECE_INNER_NORTH;
1532 } else if (north > south) {
1533 return south & 1 ? BRIDGE_PIECE_INNER_NORTH : BRIDGE_PIECE_INNER_SOUTH;
1534 } else {
1535 return north & 1 ? BRIDGE_PIECE_MIDDLE_EVEN : BRIDGE_PIECE_MIDDLE_ODD;
1536 }
1537 }
1538
1543 void DrawBridgeMiddle(const TileInfo *ti)
1544 {
1545 /* Sectional view of bridge bounding boxes:
1546 *
1547 * 1 2 1,2 = SpriteCombine of Bridge front/(back&floor) and RoadCatenary
1548 * 1 2 3 = empty helper BB
1549 * 1 7 2 4,5 = pillars under higher bridges
1550 * 1 6 88888 6 2 6 = elrail-pylons
1551 * 1 6 88888 6 2 7 = elrail-wire
1552 * 1 6 88888 6 2 <- TILE_HEIGHT 8 = rail-vehicle on bridge
1553 * 3333333333333 <- BB_Z_SEPARATOR
1554 * <- unused
1555 * 4 5 <- BB_HEIGHT_UNDER_BRIDGE
1556 * 4 5
1557 * 4 5
1558 *
1559 */
1560
1561 if (!IsBridgeAbove(ti->tile)) return;
1562
1563 TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile);
1564 TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile);
1565 TransportType transport_type = GetTunnelBridgeTransportType(rampsouth);
1566
1567 Axis axis = GetBridgeAxis(ti->tile);
1568 BridgePieces piece = CalcBridgePiece(
1569 GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
1570 GetTunnelBridgeLength(ti->tile, rampsouth) + 1
1571 );
1572
1573 const PalSpriteID *psid;
1574 bool drawfarpillar;
1575 if (transport_type != TRANSPORT_WATER) {
1576 BridgeType type = GetBridgeType(rampsouth);
1577 drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
1578
1579 uint base_offset;
1580 if (transport_type == TRANSPORT_RAIL) {
1581 base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
1582 } else {
1583 base_offset = 8;
1584 }
1585
1586 psid = base_offset + GetBridgeSpriteTable(type, piece);
1587 } else {
1588 drawfarpillar = true;
1589 psid = _aqueduct_sprites;
1590 }
1591
1592 if (axis != AXIS_X) psid += 4;
1593
1594 int x = ti->x;
1595 int y = ti->y;
1596 uint bridge_z = GetBridgePixelHeight(rampsouth);
1597 int z = bridge_z - BRIDGE_Z_START;
1598
1599 /* Add a bounding box that separates the bridge from things below it. */
1600 AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
1601
1602 /* Draw Trambits as SpriteCombine */
1603 if (transport_type == TRANSPORT_ROAD || transport_type == TRANSPORT_RAIL) StartSpriteCombine();
1604
1605 /* Draw floor and far part of bridge*/
1606 if (!IsInvisibilitySet(TO_BRIDGES)) {
1607 if (axis == AXIS_X) {
1608 AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
1609 } else {
1610 AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
1611 }
1612 }
1613
1614 psid++;
1615
1616 if (transport_type == TRANSPORT_ROAD) {
1617 /* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
1618 DrawBridgeRoadBits(rampsouth, x, y, bridge_z, axis ^ 1, false);
1619 } else if (transport_type == TRANSPORT_RAIL) {
1620 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(rampsouth));
1621 if (rti->UsesOverlay() && !IsInvisibilitySet(TO_BRIDGES)) {
1622 SpriteID surface = GetCustomRailSprite(rti, rampsouth, RTSG_BRIDGE, TCX_ON_BRIDGE);
1623 if (surface != 0) {
1624 AddSortableSpriteToDraw(surface + axis, PAL_NONE, x, y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
1625 }
1626 }
1627
1628 if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && !IsInvisibilitySet(TO_BRIDGES) && HasTunnelBridgeReservation(rampnorth)) {
1629 if (rti->UsesOverlay()) {
1630 SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
1631 AddSortableSpriteToDraw(overlay + RTO_X + axis, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
1632 } else {
1633 AddSortableSpriteToDraw(axis == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
1634 }
1635 }
1636
1637 EndSpriteCombine();
1638
1639 if (HasRailCatenaryDrawn(GetRailType(rampsouth))) {
1640 DrawRailCatenaryOnBridge(ti);
1641 }
1642 }
1643
1644 /* draw roof, the component of the bridge which is logically between the vehicle and the camera */
1645 if (!IsInvisibilitySet(TO_BRIDGES)) {
1646 if (axis == AXIS_X) {
1647 y += 12;
1648 if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 3, BRIDGE_Z_START);
1649 } else {
1650 x += 12;
1651 if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START);
1652 }
1653 }
1654
1655 /* Draw TramFront as SpriteCombine */
1656 if (transport_type == TRANSPORT_ROAD) EndSpriteCombine();
1657
1658 /* Do not draw anything more if bridges are invisible */
1659 if (IsInvisibilitySet(TO_BRIDGES)) return;
1660
1661 psid++;
1662 DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z);
1663 }
1664
1665
1666 static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y)
1667 {
1668 int z;
1669 Slope tileh = GetTilePixelSlope(tile, &z);
1670
1671 x &= 0xF;
1672 y &= 0xF;
1673
1674 if (IsTunnel(tile)) {
1675 uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
1676
1677 /* In the tunnel entrance? */
1678 if (5 <= pos && pos <= 10) return z;
1679 } else { // IsBridge(tile)
1680 DiagDirection dir = GetTunnelBridgeDirection(tile);
1681 uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
1682
1683 z += ApplyPixelFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
1684
1685 /* On the bridge ramp? */
1686 if (5 <= pos && pos <= 10) {
1687 int delta;
1688
1689 if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT;
1690
1691 switch (dir) {
1692 default: NOT_REACHED();
1693 case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
1694 case DIAGDIR_SE: delta = y / 2; break;
1695 case DIAGDIR_SW: delta = x / 2; break;
1696 case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
1697 }
1698 return z + 1 + delta;
1699 }
1700 }
1701
1702 return z + GetPartialPixelZ(x, y, tileh);
1703 }
1704
1705 static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
1706 {
1707 return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
1708 }
1709
1710 static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
1711 {
1712 TransportType tt = GetTunnelBridgeTransportType(tile);
1713
1714 if (IsTunnel(tile)) {
1715 td->str = (tt == TRANSPORT_RAIL) ? STR_LAI_TUNNEL_DESCRIPTION_RAILROAD : STR_LAI_TUNNEL_DESCRIPTION_ROAD;
1716 } else { // IsBridge(tile)
1717 td->str = (tt == TRANSPORT_WATER) ? STR_LAI_BRIDGE_DESCRIPTION_AQUEDUCT : GetBridgeSpec(GetBridgeType(tile))->transport_name[tt];
1718 }
1719 td->owner[0] = GetTileOwner(tile);
1720
1721 Owner road_owner = INVALID_OWNER;
1722 Owner tram_owner = INVALID_OWNER;
1723 RoadType road_rt = GetRoadTypeRoad(tile);
1724 RoadType tram_rt = GetRoadTypeTram(tile);
1725 if (road_rt != INVALID_ROADTYPE) {
1726 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
1727 td->roadtype = rti->strings.name;
1728 td->road_speed = rti->max_speed / 2;
1729 road_owner = GetRoadOwner(tile, RTT_ROAD);
1730 }
1731 if (tram_rt != INVALID_ROADTYPE) {
1732 const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
1733 td->tramtype = rti->strings.name;
1734 td->tram_speed = rti->max_speed / 2;
1735 tram_owner = GetRoadOwner(tile, RTT_TRAM);
1736 }
1737
1738 /* Is there a mix of owners? */
1739 if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
1740 (road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
1741 uint i = 1;
1742 if (road_owner != INVALID_OWNER) {
1743 td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
1744 td->owner[i] = road_owner;
1745 i++;
1746 }
1747 if (tram_owner != INVALID_OWNER) {
1748 td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
1749 td->owner[i] = tram_owner;
1750 }
1751 }
1752
1753 if (tt == TRANSPORT_RAIL) {
1754 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
1755 td->rail_speed = rti->max_speed;
1756 td->railtype = rti->strings.name;
1757
1758 if (!IsTunnel(tile)) {
1759 uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
1760 /* rail speed special-cases 0 as unlimited, hides display of limit etc. */
1761 if (spd == UINT16_MAX) spd = 0;
1762 if (td->rail_speed == 0 || spd < td->rail_speed) {
1763 td->rail_speed = spd;
1764 }
1765 }
1766 } else if (tt == TRANSPORT_ROAD && !IsTunnel(tile)) {
1767 uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
1768 /* road speed special-cases 0 as unlimited, hides display of limit etc. */
1769 if (spd == UINT16_MAX) spd = 0;
1770 if (road_rt != INVALID_ROADTYPE && (td->road_speed == 0 || spd < td->road_speed)) td->road_speed = spd;
1771 if (tram_rt != INVALID_ROADTYPE && (td->tram_speed == 0 || spd < td->tram_speed)) td->tram_speed = spd;
1772 }
1773 }
1774
1775
1776 static void TileLoop_TunnelBridge(TileIndex tile)
1777 {
1778 bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile);
1779 switch (_settings_game.game_creation.landscape) {
1780 case LT_ARCTIC: {
1781 /* As long as we do not have a snow density, we want to use the density
1782 * from the entry edge. For tunnels this is the lowest point for bridges the highest point.
1783 * (Independent of foundations) */
1784 int z = IsBridge(tile) ? GetTileMaxZ(tile) : GetTileZ(tile);
1785 if (snow_or_desert != (z > GetSnowLine())) {
1786 SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
1787 MarkTileDirtyByTile(tile);
1788 }
1789 break;
1790 }
1791
1792 case LT_TROPIC:
1793 if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
1794 SetTunnelBridgeSnowOrDesert(tile, true);
1795 MarkTileDirtyByTile(tile);
1796 }
1797 break;
1798
1799 default:
1800 break;
1801 }
1802 }
1803
1804 static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1805 {
1806 TransportType transport_type = GetTunnelBridgeTransportType(tile);
1807 if (transport_type != mode || (transport_type == TRANSPORT_ROAD && !HasTileRoadType(tile, (RoadTramType)sub_mode))) return 0;
1808
1809 DiagDirection dir = GetTunnelBridgeDirection(tile);
1810 if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
1811 return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE);
1812 }
1813
1814 static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner new_owner)
1815 {
1816 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
1817 /* Set number of pieces to zero if it's the southern tile as we
1818 * don't want to update the infrastructure counts twice. */
1819 uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0;
1820
1821 for (RoadTramType rtt : _roadtramtypes) {
1822 /* Update all roadtypes, no matter if they are present */
1823 if (GetRoadOwner(tile, rtt) == old_owner) {
1824 RoadType rt = GetRoadType(tile, rtt);
1825 if (rt != INVALID_ROADTYPE) {
1826 /* Update company infrastructure counts. A full diagonal road tile has two road bits.
1827 * No need to dirty windows here, we'll redraw the whole screen anyway. */
1828 Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2;
1829 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2;
1830 }
1831
1832 SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
1833 }
1834 }
1835
1836 if (!IsTileOwner(tile, old_owner)) return;
1837
1838 /* Update company infrastructure counts for rail and water as well.
1839 * No need to dirty windows here, we'll redraw the whole screen anyway. */
1840 TransportType tt = GetTunnelBridgeTransportType(tile);
1841 Company *old = Company::Get(old_owner);
1842 if (tt == TRANSPORT_RAIL) {
1843 old->infrastructure.rail[GetRailType(tile)] -= num_pieces;
1844 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += num_pieces;
1845 } else if (tt == TRANSPORT_WATER) {
1846 old->infrastructure.water -= num_pieces;
1847 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.water += num_pieces;
1848 }
1849
1850 if (new_owner != INVALID_OWNER) {
1851 SetTileOwner(tile, new_owner);
1852 } else {
1853 if (tt == TRANSPORT_RAIL) {
1854 /* Since all of our vehicles have been removed, it is safe to remove the rail
1855 * bridge / tunnel. */
1856 [[maybe_unused]] CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile);
1857 assert(ret.Succeeded());
1858 } else {
1859 /* In any other case, we can safely reassign the ownership to OWNER_NONE. */
1860 SetTileOwner(tile, OWNER_NONE);
1861 }
1862 }
1863 }
1864
1870 static const byte TUNNEL_SOUND_FRAME = 1;
1871
1880 extern const byte _tunnel_visibility_frame[DIAGDIR_END] = {12, 8, 8, 12};
1881
1882 static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
1883 {
1884 int z = GetSlopePixelZ(x, y) - v->z_pos;
1885
1886 if (abs(z) > 2) return VETSB_CANNOT_ENTER;
1887 /* Direction into the wormhole */
1888 const DiagDirection dir = GetTunnelBridgeDirection(tile);
1889 /* Direction of the vehicle */
1890 const DiagDirection vdir = DirToDiagDir(v->direction);
1891 /* New position of the vehicle on the tile */
1892 byte pos = (DiagDirToAxis(vdir) == AXIS_X ? x : y) & TILE_UNIT_MASK;
1893 /* Number of units moved by the vehicle since entering the tile */
1894 byte frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
1895
1896 if (IsTunnel(tile)) {
1897 if (v->type == VEH_TRAIN) {
1898 Train *t = Train::From(v);
1899
1900 if (t->track != TRACK_BIT_WORMHOLE && dir == vdir) {
1901 if (t->IsFrontEngine() && frame == TUNNEL_SOUND_FRAME) {
1902 if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
1903 SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
1904 }
1905 return VETSB_CONTINUE;
1906 }
1907 if (frame == _tunnel_visibility_frame[dir]) {
1908 t->tile = tile;
1909 t->track = TRACK_BIT_WORMHOLE;
1910 t->vehstatus |= VS_HIDDEN;
1911 return VETSB_ENTERED_WORMHOLE;
1912 }
1913 }
1914
1915 if (dir == ReverseDiagDir(vdir) && frame == TILE_SIZE - _tunnel_visibility_frame[dir] && z == 0) {
1916 /* We're at the tunnel exit ?? */
1917 t->tile = tile;
1918 t->track = DiagDirToDiagTrackBits(vdir);
1919 assert(t->track);
1920 t->vehstatus &= ~VS_HIDDEN;
1921 return VETSB_ENTERED_WORMHOLE;
1922 }
1923 } else if (v->type == VEH_ROAD) {
1924 RoadVehicle *rv = RoadVehicle::From(v);
1925
1926 /* Enter tunnel? */
1927 if (rv->state != RVSB_WORMHOLE && dir == vdir) {
1928 if (frame == _tunnel_visibility_frame[dir]) {
1929 /* Frame should be equal to the next frame number in the RV's movement */
1930 assert(frame == rv->frame + 1);
1931 rv->tile = tile;
1932 rv->state = RVSB_WORMHOLE;
1933 rv->vehstatus |= VS_HIDDEN;
1934 return VETSB_ENTERED_WORMHOLE;
1935 } else {
1936 return VETSB_CONTINUE;
1937 }
1938 }
1939
1940 /* We're at the tunnel exit ?? */
1941 if (dir == ReverseDiagDir(vdir) && frame == TILE_SIZE - _tunnel_visibility_frame[dir] && z == 0) {
1942 rv->tile = tile;
1943 rv->state = DiagDirToDiagTrackdir(vdir);
1944 rv->frame = frame;
1945 rv->vehstatus &= ~VS_HIDDEN;
1946 return VETSB_ENTERED_WORMHOLE;
1947 }
1948 }
1949 } else { // IsBridge(tile)
1950 if (v->type != VEH_SHIP) {
1951 /* modify speed of vehicle */
1952 uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
1953
1954 if (v->type == VEH_ROAD) spd *= 2;
1955 Vehicle *first = v->First();
1956 first->cur_speed = std::min(first->cur_speed, spd);
1957 }
1958
1959 if (vdir == dir) {
1960 /* Vehicle enters bridge at the last frame inside this tile. */
1961 if (frame != TILE_SIZE - 1) return VETSB_CONTINUE;
1962 switch (v->type) {
1963 case VEH_TRAIN: {
1964 Train *t = Train::From(v);
1965 t->track = TRACK_BIT_WORMHOLE;
1966 ClrBit(t->gv_flags, GVF_GOINGUP_BIT);
1967 ClrBit(t->gv_flags, GVF_GOINGDOWN_BIT);
1968 break;
1969 }
1970
1971 case VEH_ROAD: {
1972 RoadVehicle *rv = RoadVehicle::From(v);
1973 rv->state = RVSB_WORMHOLE;
1974 /* There are no slopes inside bridges / tunnels. */
1975 ClrBit(rv->gv_flags, GVF_GOINGUP_BIT);
1976 ClrBit(rv->gv_flags, GVF_GOINGDOWN_BIT);
1977 break;
1978 }
1979
1980 case VEH_SHIP:
1981 Ship::From(v)->state = TRACK_BIT_WORMHOLE;
1982 break;
1983
1984 default: NOT_REACHED();
1985 }
1986 return VETSB_ENTERED_WORMHOLE;
1987 } else if (vdir == ReverseDiagDir(dir)) {
1988 v->tile = tile;
1989 switch (v->type) {
1990 case VEH_TRAIN: {
1991 Train *t = Train::From(v);
1992 if (t->track == TRACK_BIT_WORMHOLE) {
1993 t->track = DiagDirToDiagTrackBits(vdir);
1994 return VETSB_ENTERED_WORMHOLE;
1995 }
1996 break;
1997 }
1998
1999 case VEH_ROAD: {
2000 RoadVehicle *rv = RoadVehicle::From(v);
2001 if (rv->state == RVSB_WORMHOLE) {
2002 rv->state = DiagDirToDiagTrackdir(vdir);
2003 rv->frame = 0;
2004 return VETSB_ENTERED_WORMHOLE;
2005 }
2006 break;
2007 }
2008
2009 case VEH_SHIP: {
2010 Ship *ship = Ship::From(v);
2011 if (ship->state == TRACK_BIT_WORMHOLE) {
2012 ship->state = DiagDirToDiagTrackBits(vdir);
2013 return VETSB_ENTERED_WORMHOLE;
2014 }
2015 break;
2016 }
2017
2018 default: NOT_REACHED();
2019 }
2020 }
2021 }
2022 return VETSB_CONTINUE;
2023 }
2024
2025 static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
2026 {
2027 if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) {
2028 DiagDirection direction = GetTunnelBridgeDirection(tile);
2029 Axis axis = DiagDirToAxis(direction);
2030 CommandCost res;
2031 int z_old;
2032 Slope tileh_old = GetTileSlope(tile, &z_old);
2033
2034 /* Check if new slope is valid for bridges in general (so we can safely call GetBridgeFoundation()) */
2035 if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
2036 CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_old, &z_old);
2037 res = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_new, &z_new);
2038 } else {
2039 CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_old, &z_old);
2040 res = CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_new, &z_new);
2041 }
2042
2043 /* Surface slope is valid and remains unchanged? */
2044 if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
2045 }
2046
2047 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
2048 }
2049
2050 extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
2051 DrawTile_TunnelBridge, // draw_tile_proc
2052 GetSlopePixelZ_TunnelBridge, // get_slope_z_proc
2053 ClearTile_TunnelBridge, // clear_tile_proc
2054 nullptr, // add_accepted_cargo_proc
2055 GetTileDesc_TunnelBridge, // get_tile_desc_proc
2056 GetTileTrackStatus_TunnelBridge, // get_tile_track_status_proc
2057 nullptr, // click_tile_proc
2058 nullptr, // animate_tile_proc
2059 TileLoop_TunnelBridge, // tile_loop_proc
2060 ChangeTileOwner_TunnelBridge, // change_tile_owner_proc
2061 nullptr, // add_produced_cargo_proc
2062 VehicleEnter_TunnelBridge, // vehicle_enter_tile_proc
2063 GetFoundation_TunnelBridge, // get_foundation_proc
2064 TerraformTile_TunnelBridge, // terraform_tile_proc
2065 };
BRIDGE_Z_START
static const int BRIDGE_Z_START
Z position of the bridge sprites relative to bridge height (downwards)
Definition: tunnelbridge_cmd.cpp:55
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
DoClearTunnel
static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
Remove a tunnel from the game, update town rating, etc.
Definition: tunnelbridge_cmd.cpp:847
TileInfo::z
int z
Height.
Definition: tile_cmd.h:47
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
SPRITE_MASK
@ SPRITE_MASK
The mask to for the main sprite.
Definition: sprites.h:1548
TRACK_BIT_WORMHOLE
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:55
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:80
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:96
tunnelbridge.h
VETSB_CANNOT_ENTER
@ VETSB_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:37
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
RoadTypeInfo
Definition: road.h:76
RoadVehicle::state
byte state
Definition: roadveh.h:109
TO_CATENARY
@ TO_CATENARY
catenary
Definition: transparency.h:30
sound_func.h
RailtypeInfo::single_x
SpriteID single_x
single piece of rail in X direction, without ground
Definition: rail.h:134
Cheats::crossing_tunnels
Cheat crossing_tunnels
allow tunnels that cross each other
Definition: cheat_type.h:30
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:127
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
RailtypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:228
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
water.h
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
ResetBridges
void ResetBridges()
Reset the data been eventually changed by the grf loaded.
Definition: tunnelbridge_cmd.cpp:85
train.h
GetBridgeType
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
BB_Z_SEPARATOR
static const uint BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
Definition: viewport_type.h:85
HasTileWaterClass
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:106
CheckBridgeSlope
static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope *tileh, int *z)
Determines the foundation for the bridge head, and tests if the resulting slope is valid.
Definition: tunnelbridge_cmd.cpp:172
command_func.h
VSE_TUNNEL
@ VSE_TUNNEL
Train entering a tunnel.
Definition: newgrf_sound.h:20
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
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:644
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
BridgeSpec::avail_year
Year avail_year
the year where it becomes available
Definition: bridge.h:42
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3594
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
RATING_TUNNEL_BRIDGE_MINIMUM
@ RATING_TUNNEL_BRIDGE_MINIMUM
minimum rating after removing tunnel or bridge
Definition: town_type.h:58
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:63
terraform_cmd.h
company_base.h
HasBridgeFlatRamp
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
Determines if the track on a bridge ramp is flat or goes up/down.
Definition: tunnelbridge_cmd.cpp:144
IsTransparencySet
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
tunnelbridge_map.h
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
company_gui.h
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:285
OtherAxis
static Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition: direction_func.h:197
elrail_func.h
SND_05_TRAIN_THROUGH_TUNNEL
@ SND_05_TRAIN_THROUGH_TUNNEL
3 == 0x03 Train enters tunnel: steam engine
Definition: sound_type.h:42
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:74
DrawPillar
static void DrawPillar(const PalSpriteID *psid, int x, int y, int z, int w, int h, const SubSprite *subsprite)
Draw a single pillar sprite.
Definition: tunnelbridge_cmd.cpp:1039
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
MakeRailTunnel
static void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
Makes a rail tunnel entrance.
Definition: tunnel_map.h:73
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
TownCache::squared_town_zone_radius
uint32 squared_town_zone_radius[HZB_END]
UpdateTownRadius updates this given the house count.
Definition: town.h:45
CompanyInfrastructure::water
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
BridgeSpec::sprite_table
PalSpriteID ** sprite_table
table of sprites for drawing the bridge
Definition: bridge.h:51
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
MakeAqueductBridgeRamp
static void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition: bridge_map.h:181
RailtypeInfo::single_y
SpriteID single_y
single piece of rail in Y direction, without ground
Definition: rail.h:135
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
TileDesc::tram_speed
uint16 tram_speed
Speed limit of tram (bridges and track)
Definition: tile_cmd.h:68
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
ship.h
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
DiagDirToDiagTrackdir
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:536
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
VETSB_CONTINUE
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition: tile_cmd.h:34
IsTunnelInWayDir
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?
Definition: tunnel_map.cpp:48
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
BB_HEIGHT_UNDER_BRIDGE
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
Definition: viewport_type.h:84
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:251
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:219
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
RailtypeInfo::single_sloped
SpriteID single_sloped
single piece of rail for slopes
Definition: rail.h:140
MakeRoadTunnel
static void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Makes a road tunnel entrance.
Definition: tunnel_map.h:50
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
IsCoast
static bool IsCoast(TileIndex t)
Is it a coast tile?
Definition: water_map.h:206
DrawRailCatenaryOnBridge
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
Definition: elrail.cpp:504
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:82
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
Definition: tunnelbridge_cmd.cpp:1543
CmdBuildTunnel
CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportType transport_type, byte road_rail_type)
Build Tunnel.
Definition: tunnelbridge_cmd.cpp:624
CheckAllowRemoveTunnelBridge
static CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
Are we allowed to remove the tunnel or bridge at tile?
Definition: tunnelbridge_cmd.cpp:799
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
BridgeSpec::speed
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:46
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
RailClearCost
static Money RailClearCost(RailType railtype)
Returns the 'cost' of clearing the specified railtype.
Definition: rail.h:383
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:229
CheckforTownRating
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
Definition: town_cmd.cpp:3710
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
FlatteningFoundation
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition: slope_func.h:369
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
SlopeToSpriteOffset
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition: slope_func.h:415
object_base.h
pbs.h
TUNNEL_SOUND_FRAME
static const byte TUNNEL_SOUND_FRAME
Frame when the 'enter tunnel' sound should be played.
Definition: tunnelbridge_cmd.cpp:1870
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
GVF_GOINGDOWN_BIT
@ GVF_GOINGDOWN_BIT
Vehicle is currently going downhill. (Cached track information for acceleration)
Definition: ground_vehicle.hpp:53
RTO_SLOPE_NE
@ RTO_SLOPE_NE
Piece of rail on slope with north-east raised.
Definition: rail.h:74
BridgeSpec
Struct containing information about a single bridge type.
Definition: bridge.h:41
RailtypeInfo::name
StringID name
Name of this rail type.
Definition: rail.h:173
DrawPillarColumn
static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, int x, int y, int w, int h)
Draw two bridge pillars (north and south).
Definition: tunnelbridge_cmd.cpp:1056
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
ValParamRailtype
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
Definition: rail.cpp:206
GetCustomRoadSprite
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_roadtype.cpp:100
TO_BRIDGES
@ TO_BRIDGES
bridges
Definition: transparency.h:28
GetBridgeSpec
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:65
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
RTBO_Y
@ RTBO_Y
Piece of rail in Y direction.
Definition: rail.h:91
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:81
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:183
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
landscape_cmd.h
TILE_UNIT_MASK
static const uint TILE_UNIT_MASK
For masking in/out the inner-tile world coordinate units.
Definition: tile_type.h:16
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:316
DirToDiagDir
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
_tunnel_visibility_frame
const byte _tunnel_visibility_frame[DIAGDIR_END]
Frame when a vehicle should be hidden in a tunnel with a certain direction.
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
RailtypeInfo::tunnel
SpriteID tunnel
tunnel sprites base
Definition: rail.h:142
CommandCost
Common return value for all commands.
Definition: command_type.h:24
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:656
HasTileWaterGround
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:355
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
clear_func.h
AxisToTrack
static 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:65
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
MAX_BRIDGES
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
Definition: bridge.h:34
RTSG_BRIDGE
@ RTSG_BRIDGE
Bridge surface images.
Definition: rail.h:53
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2772
_bridge
BridgeSpec _bridge[MAX_BRIDGES]
The specification of all bridges.
Definition: tunnelbridge_cmd.cpp:51
CalcClosestTownFromTile
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3576
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
GVF_GOINGUP_BIT
@ GVF_GOINGUP_BIT
Vehicle is currently going uphill. (Cached track information for acceleration)
Definition: ground_vehicle.hpp:52
TileIndexDiff
int32 TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:154
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
SetBridgeMiddle
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
autoslope.h
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:302
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition: tile_cmd.h:65
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
HasSlopeHighestCorner
static bool HasSlopeHighestCorner(Slope s)
Tests if a slope has a highest corner (i.e.
Definition: slope_func.h:113
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
RailtypeInfo::base_sprites
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition: object_base.h:85
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
station_func.h
GetRoadside
static Roadside GetRoadside(TileIndex tile)
Get the decorations of a road.
Definition: road_map.h:493
IsInvisibilitySet
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
ROADSIDE_PAVED
@ ROADSIDE_PAVED
Road with paved sidewalks.
Definition: road_map.h:480
ConstructionSettings::max_bridge_height
byte max_bridge_height
maximum height of bridges
Definition: settings_type.h:346
HasRoadCatenaryDrawn
static bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition: road_func.h:145
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:773
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition: economy_type.h:222
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:913
HasTileRoadType
static bool HasTileRoadType(TileIndex t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
Definition: road_map.h:211
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
DiagDirToDiagTrack
static Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
Definition: track_func.h:511
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
RailBuildCost
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition: rail.h:372
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:387
Train
'Train' is either a loco or a wagon.
Definition: train.h:88
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
FreeTrainTrackReservation
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
Definition: train_cmd.cpp:2342
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
IsBridge
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
ObjectSpec::height
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Definition: newgrf_object.h:75
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition: newgrf_commons.h:25
ROTSG_BRIDGE
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition: road.h:64
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:763
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:84
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
AutoslopeEnabled
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition: autoslope.h:44
CompanyInfrastructure::road
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:32
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
IsRoadDepot
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:106
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:101
ValParamRoadType
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:142
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:49
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
RTBO_SLOPE
@ RTBO_SLOPE
Sloped rail pieces, in order NE, SE, SW, NW.
Definition: rail.h:92
GetSlopePixelZOnEdge
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
Determine the Z height of the corners of a specific tile edge.
Definition: landscape.cpp:397
ROADSIDE_TREES
@ ROADSIDE_TREES
Road with trees on paved sidewalks.
Definition: road_map.h:483
tunnelbridge_cmd.h
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
GUISettings::show_track_reservation
bool show_track_reservation
highlight reserved tracks.
Definition: settings_type.h:162
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:36
stdafx.h
DrawRoadOverlays
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay)
Draw road underlay and overlay sprites.
Definition: road_cmd.cpp:1495
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
ConstructionSettings::extra_dynamite
bool extra_dynamite
extra dynamite
Definition: settings_type.h:349
GetBridgeFoundation
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
Definition: tunnelbridge_cmd.cpp:128
CalcBridgeLenCostFactor
int CalcBridgeLenCostFactor(int length)
Calculate the price factor for building a long bridge.
Definition: tunnelbridge_cmd.cpp:107
HasTunnelBridgeSnowOrDesert
static bool HasTunnelBridgeSnowOrDesert(TileIndex t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
Definition: tunnelbridge_map.h:52
GetBridgeRoadCatenary
static void GetBridgeRoadCatenary(const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
Retrieve the sprites required for catenary on a road/tram bridge.
Definition: tunnelbridge_cmd.cpp:1132
SPR_RAILTYPE_TUNNEL_BASE
static const SpriteID SPR_RAILTYPE_TUNNEL_BASE
Tunnel sprites with grass only for custom railtype tunnel.
Definition: sprites.h:299
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
RTSG_OVERLAY
@ RTSG_OVERLAY
Images for overlaying track.
Definition: rail.h:48
viewport_func.h
DoClearBridge
static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
Remove a bridge from the game, update town rating, etc.
Definition: tunnelbridge_cmd.cpp:927
AxisToDiagDir
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
ChangeTownRating
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
Definition: town_cmd.cpp:3673
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:667
GetBridgeAxis
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
yapf_cache.h
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:286
newgrf_object.h
BridgeSpec::min_length
byte min_length
the minimum length (not counting start and end tile)
Definition: bridge.h:43
ApplyPixelFoundationToSlope
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:474
ConstructionSettings::max_bridge_length
uint16 max_bridge_length
maximum length of bridges
Definition: settings_type.h:345
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:174
RTSG_TUNNEL
@ RTSG_TUNNEL
Main group of ground images for snow or desert.
Definition: rail.h:50
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
Ship
All ships have this type.
Definition: ship.h:26
GetCustomRailSprite
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_railtype.cpp:95
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
newgrf_sound.h
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1598
strings_func.h
RTBO_X
@ RTBO_X
Piece of rail in X direction.
Definition: rail.h:90
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:623
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:117
newgrf_roadtype.h
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:529
BridgeSpec::max_length
uint16 max_length
the maximum length (not counting start and end tile)
Definition: bridge.h:44
ClearTile_TunnelBridge
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
Remove a tunnel or a bridge from the game.
Definition: tunnelbridge_cmd.cpp:1018
IsPlainRail
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:49
ClearBridgeMiddle
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
TryPathReserve
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
Definition: train_cmd.cpp:2807
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1183
IsTunnel
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:23
HasTunnelBridgeReservation
static bool HasTunnelBridgeReservation(TileIndex t)
Get the reservation state of the rail tunnel/bridge.
Definition: tunnelbridge_map.h:91
TCX_ON_BRIDGE
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
Definition: newgrf_commons.h:27
HasRailCatenaryDrawn
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Definition: elrail_func.h:30
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:343
ROTSG_OVERLAY
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition: road.h:59
RTO_X
@ RTO_X
Piece of rail in X direction.
Definition: rail.h:68
RoadClearCost
static Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition: road.h:261
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
cheat_type.h
SetTunnelBridgeReservation
static void SetTunnelBridgeReservation(TileIndex t, bool b)
Set the reservation state of the rail tunnel/bridge.
Definition: tunnelbridge_map.h:104
OBJECT_FLAG_ALLOW_UNDER_BRIDGE
@ OBJECT_FLAG_ALLOW_UNDER_BRIDGE
Object can built under a bridge.
Definition: newgrf_object.h:37
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:1998
ObjectSpec::GetByTile
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Definition: newgrf_object.cpp:50
AddSideToSignalBuffer
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition: signal.cpp:610
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
CompanyInfrastructure::rail
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:34
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
ROTSG_CATENARY_FRONT
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition: road.h:62
Town::cache
TownCache cache
Container for all cacheable data.
Definition: town.h:53
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition: road_cmd.cpp:197
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
GroundVehicle::gv_flags
uint16 gv_flags
Definition: ground_vehicle.hpp:81
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:52
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:358
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:22
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
ROTSG_TUNNEL
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition: road.h:61
GetOtherTunnelEnd
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
Definition: tunnel_map.cpp:22
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
PlayVehicleSound
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
Definition: newgrf_sound.cpp:187
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
DrawRailCatenaryOnTunnel
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
Definition: elrail.cpp:247
MarkBridgeDirty
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
Definition: tunnelbridge_cmd.cpp:66
CalcBridgePiece
static BridgePieces CalcBridgePiece(uint north, uint south)
Compute bridge piece.
Definition: tunnelbridge_cmd.cpp:1524
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition: company_cmd.cpp:334
CommandHelper
Definition: command_func.h:94
GetTunnelBridgeLength
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Town
Town data structure.
Definition: town.h:50
RVSB_WORMHOLE
@ RVSB_WORMHOLE
The vehicle is in a tunnel and/or bridge.
Definition: roadveh.h:40
TileDesc::rail_speed
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:64
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:523
RoadTypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:140
GetBridgePixelHeight
static int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition: bridge_map.h:84
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
OverflowSafeInt< int64 >
DrawTile_TunnelBridge
static void DrawTile_TunnelBridge(TileInfo *ti)
Draws a tunnel of bridge tile.
Definition: tunnelbridge_cmd.cpp:1258
DrawRailCatenary
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Definition: elrail.cpp:566
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:250
IsNormalRoadTile
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Definition: road_map.h:74
CheckBridgeAvailability
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
Is a bridge of the specified type and length available?
Definition: tunnelbridge_cmd.cpp:199
SetRoadside
static void SetRoadside(TileIndex tile, Roadside s)
Set the decorations of a road.
Definition: road_map.h:503
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
GetRoadOwner
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:234
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:54
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
MakeRoadBridgeRamp
static void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Make a bridge ramp for roads.
Definition: bridge_map.h:153
CmdBuildBridge
CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex tile_start, TransportType transport_type, BridgeType bridge_type, byte road_rail_type)
Build a Bridge.
Definition: tunnelbridge_cmd.cpp:260
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
RailtypeInfo::strings
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition: tile_cmd.h:67
IsWater
static bool IsWater(TileIndex t)
Is it a plain water tile?
Definition: water_map.h:152
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:359
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:215
TUNNELBRIDGE_REMOVE
@ TUNNELBRIDGE_REMOVE
Removal of a tunnel or bridge owned by the towb.
Definition: town.h:169
GetTilePixelSlope
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
InclinedFoundation
static Foundation InclinedFoundation(Axis axis)
Returns the along a specific axis inclined foundation.
Definition: slope_func.h:380
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:166
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:84
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
TunnelBridgeClearCost
static Money TunnelBridgeClearCost(TileIndex tile, Price base_price)
Calculate the base cost of clearing a tunnel/bridge per tile.
Definition: tunnelbridge_cmd.cpp:223
Company
Definition: company_base.h:117
ConstructionSettings::max_tunnel_length
uint16 max_tunnel_length
maximum length of tunnels
Definition: settings_type.h:347
BridgePieces
BridgePieces
This enum is related to the definition of bridge pieces, which is used to determine the proper sprite...
Definition: bridge.h:21
MakeRailBridgeRamp
static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Definition: bridge_map.h:169
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
ROTSG_CATENARY_BACK
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition: road.h:63
SetTunnelBridgeSnowOrDesert
static void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
Definition: tunnelbridge_map.h:66
DrawBridgePillars
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
Draws the pillars under high bridges.
Definition: tunnelbridge_cmd.cpp:1076
bridge_land.h
ComplementSlope
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
Definition: slope_func.h:76
RATING_TUNNEL_BRIDGE_DOWN_STEP
@ RATING_TUNNEL_BRIDGE_DOWN_STEP
penalty for removing town owned tunnel or bridge
Definition: town_type.h:57
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:20
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
newgrf_railtype.h
TunnelBridgeIsFree
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
Definition: vehicle.cpp:568
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:583
_build_tunnel_endtile
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Definition: tunnelbridge_cmd.cpp:52
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
GetTrainForReservation
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition: pbs.cpp:330
GetInclinedSlopeDirection
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
RailtypeInfo::bridge_offset
SpriteID bridge_offset
Bridge offset.
Definition: rail.h:193
SPR_TRAMWAY_BASE
static const SpriteID SPR_TRAMWAY_BASE
Tramway sprites.
Definition: sprites.h:272
DrawBridgeRoadBits
static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int offset, bool head)
Draws the road and trambits over an already drawn (lower end) of a bridge.
Definition: tunnelbridge_cmd.cpp:1158
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
VETSB_ENTERED_WORMHOLE
@ VETSB_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:36
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
roadveh.h
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
ObjectSpec::flags
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:72
TileDesc::road_speed
uint16 road_speed
Speed limit of road (bridges and track)
Definition: tile_cmd.h:66
RTSG_TUNNEL_PORTAL
@ RTSG_TUNNEL_PORTAL
Tunnel portal overlay.
Definition: rail.h:57