OpenTTD Source 20260206-master-g4d4e37dbf1
water_cmd.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "landscape.h"
12#include "viewport_func.h"
13#include "command_func.h"
14#include "town.h"
15#include "news_func.h"
16#include "depot_base.h"
17#include "depot_func.h"
18#include "water.h"
19#include "industry_map.h"
20#include "newgrf_canal.h"
21#include "strings_func.h"
22#include "vehicle_func.h"
23#include "sound_func.h"
24#include "company_func.h"
25#include "clear_map.h"
26#include "tree_map.h"
27#include "aircraft.h"
28#include "effectvehicle_func.h"
29#include "tunnelbridge_map.h"
30#include "station_base.h"
31#include "ai/ai.hpp"
32#include "game/game.hpp"
33#include "core/random_func.hpp"
34#include "core/backup_type.hpp"
36#include "company_base.h"
37#include "company_gui.h"
38#include "newgrf_generic.h"
39#include "industry.h"
40#include "water_cmd.h"
41#include "landscape_cmd.h"
43#include "town_type.h"
44
45#include "table/strings.h"
46
47#include "safeguards.h"
48
52static const Directions _flood_from_dirs[] = {
53 {DIR_NW, DIR_SW, DIR_SE, DIR_NE}, // SLOPE_FLAT
54 {DIR_NE, DIR_SE}, // SLOPE_W
55 {DIR_NW, DIR_NE}, // SLOPE_S
56 {DIR_NE}, // SLOPE_SW
57 {DIR_NW, DIR_SW}, // SLOPE_E
58 {}, // SLOPE_EW
59 {DIR_NW}, // SLOPE_SE
60 {DIR_N, DIR_NW, DIR_NE}, // SLOPE_WSE, SLOPE_STEEP_S
61 {DIR_SW, DIR_SE}, // SLOPE_N
62 {DIR_SE}, // SLOPE_NW
63 {}, // SLOPE_NS
64 {DIR_E, DIR_NE, DIR_SE}, // SLOPE_NWS, SLOPE_STEEP_W
65 {DIR_SW}, // SLOPE_NE
66 {DIR_S, DIR_SW, DIR_SE}, // SLOPE_ENW, SLOPE_STEEP_N
67 {DIR_W, DIR_SW, DIR_NW}, // SLOPE_SEN, SLOPE_STEEP_E
68};
69
76static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
77{
78 if (IsValidTile(tile) && IsTileType(tile, TileType::Water) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
79}
80
88{
89 for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
91 }
92}
93
99{
100 for (Direction dir = DIR_BEGIN; dir != DIR_END; dir++) {
101 TileIndex dest = tile + TileOffsByDir(dir);
102 if (IsValidTile(dest) && IsTileType(dest, TileType::Water)) SetNonFloodingWaterTile(dest, false);
103 }
104}
105
113CommandCost CmdBuildShipDepot(DoCommandFlags flags, TileIndex tile, Axis axis)
114{
115 if (!IsValidAxis(axis)) return CMD_ERROR;
116 TileIndex tile2 = tile + TileOffsByAxis(axis);
117
118 if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
119 return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER);
120 }
121
122 if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
123
124 if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
125 /* Prevent depots on rapids */
126 return CommandCost(STR_ERROR_SITE_UNSUITABLE);
127 }
128
129 if (!Depot::CanAllocateItem()) return CMD_ERROR;
130
131 WaterClass wc1 = GetWaterClass(tile);
132 WaterClass wc2 = GetWaterClass(tile2);
134
135 bool add_cost = !IsWaterTile(tile);
136 CommandCost ret = Command<Commands::LandscapeClear>::Do(flags | DoCommandFlag::Auto, tile);
137 if (ret.Failed()) return ret;
138 if (add_cost) {
139 cost.AddCost(ret.GetCost());
140 }
141 add_cost = !IsWaterTile(tile2);
142 ret = Command<Commands::LandscapeClear>::Do(flags | DoCommandFlag::Auto, tile2);
143 if (ret.Failed()) return ret;
144 if (add_cost) {
145 cost.AddCost(ret.GetCost());
146 }
147
148 if (flags.Test(DoCommandFlag::Execute)) {
149 Depot *depot = Depot::Create(tile);
150
151 uint new_water_infra = 2 * LOCK_DEPOT_TILE_FACTOR;
152 /* Update infrastructure counts after the tile clears earlier.
153 * Clearing object tiles may result in water tiles which are already accounted for in the water infrastructure total.
154 * See: MakeWaterKeepingClass() */
155 if (wc1 == WaterClass::Canal && !(HasTileWaterClass(tile) && GetWaterClass(tile) == WaterClass::Canal && IsTileOwner(tile, _current_company))) new_water_infra++;
156 if (wc2 == WaterClass::Canal && !(HasTileWaterClass(tile2) && GetWaterClass(tile2) == WaterClass::Canal && IsTileOwner(tile2, _current_company))) new_water_infra++;
157
158 Company::Get(_current_company)->infrastructure.water += new_water_infra;
160
161 MakeShipDepot(tile, _current_company, depot->index, DepotPart::North, axis, wc1);
162 MakeShipDepot(tile2, _current_company, depot->index, DepotPart::South, axis, wc2);
164 CheckForDockingTile(tile2);
166 MarkTileDirtyByTile(tile2);
167 MakeDefaultName(depot);
168 }
169
170 return cost;
171}
172
173bool IsPossibleDockingTile(Tile t)
174{
175 assert(IsValidTile(t));
176 switch (GetTileType(t)) {
177 case TileType::Water:
178 if (IsLock(t) && GetLockPart(t) == LockPart::Middle) return false;
179 [[fallthrough]];
184
185 default:
186 return false;
187 }
188}
189
196{
197 for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
198 TileIndex tile = t + TileOffsByDiagDir(d);
199 if (!IsValidTile(tile)) continue;
200
201 if (IsDockTile(tile) && IsDockWaterPart(tile)) {
202 Station::GetByTile(tile)->docking_station.Add(t);
203 SetDockingTile(t, true);
204 }
205 if (IsTileType(tile, TileType::Industry)) {
207 if (st != nullptr) {
208 st->docking_station.Add(t);
209 SetDockingTile(t, true);
210 }
211 }
212 if (IsTileType(tile, TileType::Station) && IsOilRig(tile)) {
213 Station::GetByTile(tile)->docking_station.Add(t);
214 SetDockingTile(t, true);
215 }
216 }
217}
218
219void MakeWaterKeepingClass(TileIndex tile, Owner o)
220{
221 WaterClass wc = GetWaterClass(tile);
222
223 /* Autoslope might turn an originally canal or river tile into land */
224 auto [slope, z] = GetTileSlopeZ(tile);
225
226 if (slope != SLOPE_FLAT) {
227 if (wc == WaterClass::Canal) {
228 /* If we clear the canal, we have to remove it from the infrastructure count as well. */
230 if (c != nullptr) {
233 }
234 /* Sloped canals are locks and no natural water remains whatever the slope direction */
236 }
237
238 /* Only river water should be restored on appropriate slopes. Other water would be invalid on slopes */
241 }
242 }
243
244 if (wc == WaterClass::Sea && z > 0) {
245 /* Update company infrastructure count. */
247 if (c != nullptr) {
250 }
251
253 }
254
255 /* Zero map array and terminate animation */
256 DoClearSquare(tile);
257
258 /* Maybe change to water */
259 switch (wc) {
260 case WaterClass::Sea: MakeSea(tile); break;
261 case WaterClass::Canal: MakeCanal(tile, o, Random()); break;
262 case WaterClass::River: MakeRiver(tile, Random()); break;
263 default: break;
264 }
265
268}
269
270static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlags flags)
271{
272 if (!IsShipDepot(tile)) return CMD_ERROR;
273
275 if (ret.Failed()) return ret;
276
277 TileIndex tile2 = GetOtherShipDepotTile(tile);
278
279 /* do not check for ship on tile when company goes bankrupt */
280 if (!flags.Test(DoCommandFlag::Bankrupt)) {
281 ret = EnsureNoVehicleOnGround(tile);
282 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
283 if (ret.Failed()) return ret;
284 }
285
286 bool do_clear = flags.Test(DoCommandFlag::ForceClearTile);
287
288 if (flags.Test(DoCommandFlag::Execute)) {
289 delete Depot::GetByTile(tile);
290
292 if (c != nullptr) {
294 if (do_clear && GetWaterClass(tile) == WaterClass::Canal) c->infrastructure.water--;
296 }
297
298 if (!do_clear) MakeWaterKeepingClass(tile, GetTileOwner(tile));
299 MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
300 }
301
303}
304
311{
312 static constexpr uint8_t MINIMAL_BRIDGE_HEIGHT[to_underlying(LockPart::End)] = {
313 2, // LockPart::Middle
314 3, // LockPart::Lower
315 2, // LockPart::Upper
316 };
317 return MINIMAL_BRIDGE_HEIGHT[to_underlying(lock_part)];
318}
319
327static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags flags)
328{
330
331 TileIndexDiff delta = TileOffsByDiagDir(dir);
333 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
334 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
335 if (ret.Failed()) return ret;
336
337 /* middle tile */
339 ret = Command<Commands::LandscapeClear>::Do(flags, tile);
340 if (ret.Failed()) return ret;
341 cost.AddCost(ret.GetCost());
342
343 /* lower tile */
344 if (!IsWaterTile(tile - delta)) {
345 ret = Command<Commands::LandscapeClear>::Do(flags, tile - delta);
346 if (ret.Failed()) return ret;
347 cost.AddCost(ret.GetCost());
348 cost.AddCost(_price[Price::BuildCanal]);
349 }
350 if (!IsTileFlat(tile - delta)) {
351 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
352 }
353 WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WaterClass::Canal;
354
355 /* upper tile */
356 if (!IsWaterTile(tile + delta)) {
357 ret = Command<Commands::LandscapeClear>::Do(flags, tile + delta);
358 if (ret.Failed()) return ret;
359 cost.AddCost(ret.GetCost());
360 cost.AddCost(_price[Price::BuildCanal]);
361 }
362 if (!IsTileFlat(tile + delta)) {
363 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
364 }
365 WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WaterClass::Canal;
366
367 for (LockPart lock_part = LockPart::Middle; TileIndex t : {tile, tile - delta, tile + delta}) {
370 return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff);
371 }
372 ++lock_part;
373 }
374
375 if (flags.Test(DoCommandFlag::Execute)) {
376 /* Update company infrastructure counts. */
378 if (c != nullptr) {
379 /* Counts for the water. */
380 if (!IsWaterTile(tile - delta)) c->infrastructure.water++;
381 if (!IsWaterTile(tile + delta)) c->infrastructure.water++;
382 /* Count for the lock itself. */
383 c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles.
385 }
386
387 MakeLock(tile, _current_company, dir, wc_lower, wc_upper, wc_middle);
388 CheckForDockingTile(tile - delta);
389 CheckForDockingTile(tile + delta);
391 MarkTileDirtyByTile(tile - delta);
392 MarkTileDirtyByTile(tile + delta);
393 MarkCanalsAndRiversAroundDirty(tile - delta);
394 MarkCanalsAndRiversAroundDirty(tile + delta);
395 InvalidateWaterRegion(tile - delta);
396 InvalidateWaterRegion(tile + delta);
397 }
398 cost.AddCost(_price[Price::BuildLock]);
399
400 return cost;
401}
402
409static CommandCost RemoveLock(TileIndex tile, DoCommandFlags flags)
410{
411 if (GetTileOwner(tile) != OWNER_NONE) {
413 if (ret.Failed()) return ret;
414 }
415
417
418 /* make sure no vehicle is on the tile. */
420 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
421 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
422 if (ret.Failed()) return ret;
423
424 if (flags.Test(DoCommandFlag::Execute)) {
425 /* Remove middle part from company infrastructure count. */
427 if (c != nullptr) {
428 c->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // three parts of the lock.
430 }
431
432 if (GetWaterClass(tile) == WaterClass::River) {
433 MakeRiver(tile, Random());
434 } else {
435 DoClearSquare(tile);
437 }
438 MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
439 MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
441 MarkCanalsAndRiversAroundDirty(tile - delta);
442 MarkCanalsAndRiversAroundDirty(tile + delta);
443 }
444
446}
447
454CommandCost CmdBuildLock(DoCommandFlags flags, TileIndex tile)
455{
457 if (dir == INVALID_DIAGDIR) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
458
459 TileIndex lower_tile = TileAddByDiagDir(tile, ReverseDiagDir(dir));
460
461 /* If freeform edges are disabled, don't allow building on edge tiles. */
462 if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(lower_tile), 1, Map::MaxX() - 1) || !IsInsideMM(TileY(lower_tile), 1, Map::MaxY() - 1))) {
463 return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
464 }
465
466 return DoBuildLock(tile, dir, flags);
467}
468
474{
475 MakeRiver(tile, Random());
477
478 /* Remove desert directly around the river tile. */
481 }
482}
483
493CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
494{
495 if (start_tile >= Map::Size() || !IsValidWaterClass(wc)) return CMD_ERROR;
496
497 /* Outside of the editor you can only build canals, not oceans */
498 if (wc != WaterClass::Canal && _game_mode != GM_EDITOR) return CMD_ERROR;
499
501
502 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
503 for (; *iter != INVALID_TILE; ++(*iter)) {
504 TileIndex current_tile = *iter;
505 CommandCost ret;
506
507 Slope slope = GetTileSlope(current_tile);
508 if (slope != SLOPE_FLAT && (wc != WaterClass::River || !IsInclinedSlope(slope))) {
509 return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
510 }
511
512 bool water = IsWaterTile(current_tile);
513
514 /* Outside the editor, prevent building canals over your own or OWNER_NONE owned canals */
515 if (water && IsCanal(current_tile) && _game_mode != GM_EDITOR && (IsTileOwner(current_tile, _current_company) || IsTileOwner(current_tile, OWNER_NONE))) continue;
516
517 ret = Command<Commands::LandscapeClear>::Do(flags, current_tile);
518 if (ret.Failed()) return ret;
519
520 if (!water) cost.AddCost(ret.GetCost());
521
522 if (flags.Test(DoCommandFlag::Execute)) {
523 if (IsTileType(current_tile, TileType::Water) && IsCanal(current_tile)) {
524 Owner owner = GetTileOwner(current_tile);
525 if (Company::IsValidID(owner)) {
526 Company::Get(owner)->infrastructure.water--;
528 }
529 }
530
531 switch (wc) {
533 MakeRiver(current_tile, Random());
534 if (_game_mode == GM_EDITOR) {
535 /* Remove desert directly around the river tile. */
536 for (auto t : SpiralTileSequence(current_tile, RIVER_OFFSET_DESERT_DISTANCE)) {
538 }
539 }
540 break;
541
542 case WaterClass::Sea:
543 if (TileHeight(current_tile) == 0) {
544 MakeSea(current_tile);
545 break;
546 }
547 [[fallthrough]];
548
549 default:
550 MakeCanal(current_tile, _current_company, Random());
552 Company::Get(_current_company)->infrastructure.water++;
554 }
555 break;
556 }
557 MarkTileDirtyByTile(current_tile);
558 MarkCanalsAndRiversAroundDirty(current_tile);
559 CheckForDockingTile(current_tile);
560 }
561
562 cost.AddCost(_price[Price::BuildCanal]);
563 }
564
565 if (cost.GetCost() == 0) {
566 return CommandCost(STR_ERROR_ALREADY_BUILT);
567 } else {
568 return cost;
569 }
570}
571
572
573static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlags flags)
574{
575 switch (GetWaterTileType(tile)) {
577 if (flags.Test(DoCommandFlag::NoWater)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
578
579 Money base_cost = IsCanal(tile) ? _price[Price::ClearCanal] : _price[Price::ClearWater];
580 /* Make sure freeform edges are allowed or it's not an edge tile. */
581 if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, Map::MaxX() - 1) ||
582 !IsInsideMM(TileY(tile), 1, Map::MaxY() - 1))) {
583 return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
584 }
585
586 /* Make sure no vehicle is on the tile */
588 if (ret.Failed()) return ret;
589
590 Owner owner = GetTileOwner(tile);
591 if (owner != OWNER_WATER && owner != OWNER_NONE) {
592 ret = CheckTileOwnership(tile);
593 if (ret.Failed()) return ret;
594 }
595
596 if (flags.Test(DoCommandFlag::Execute)) {
597 if (IsCanal(tile) && Company::IsValidID(owner)) {
598 Company::Get(owner)->infrastructure.water--;
600 }
601
602 /* Handle local authority impact */
603 if (IsRiver(tile)) {
605 Town *town = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
606 if (town != nullptr) ChangeTownRating(town, RATING_WATER_RIVER_DOWN_STEP, RATING_WATER_MINIMUM, flags);
607 }
608 }
609
610 DoClearSquare(tile);
613 }
614
615 return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
616 }
617
619 Slope slope = GetTileSlope(tile);
620
621 /* Make sure no vehicle is on the tile */
623 if (ret.Failed()) return ret;
624
625 if (flags.Test(DoCommandFlag::Execute)) {
626 DoClearSquare(tile);
629 }
630 if (IsSlopeWithOneCornerRaised(slope)) {
632 } else {
634 }
635 }
636
637 case WaterTileType::Lock: {
638 static const TileIndexDiffC _lock_tomiddle_offs[to_underlying(LockPart::End)][DIAGDIR_END] = {
639 /* NE SE SW NW */
640 { { 0, 0}, {0, 0}, { 0, 0}, {0, 0} }, // LockPart::Middle
641 { {-1, 0}, {0, 1}, { 1, 0}, {0, -1} }, // LockPart::Lower
642 { { 1, 0}, {0, -1}, {-1, 0}, {0, 1} }, // LockPart::Upper
643 };
644
645 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
647 /* move to the middle tile.. */
648 return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[to_underlying(GetLockPart(tile))][GetLockDirection(tile)]), flags);
649 }
650
652 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
653 return RemoveShipDepot(tile, flags);
654
655 default:
656 NOT_REACHED();
657 }
658}
659
669{
670 switch (GetTileType(tile)) {
671 case TileType::Water:
672 switch (GetWaterTileType(tile)) {
673 default: NOT_REACHED();
674 case WaterTileType::Depot: case WaterTileType::Clear: return true;
676
678 switch (GetTileSlope(tile)) {
679 case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
680 case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
681 case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
682 case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
683 default: return false;
684 }
685 }
686
688 if (GetRailGroundType(tile) == RailGroundType::HalfTileWater) {
689 assert(IsPlainRail(tile));
690 switch (GetTileSlope(tile)) {
691 case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
692 case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
693 case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
694 case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
695 default: return false;
696 }
697 }
698 return false;
699
701 if (IsOilRig(tile)) {
702 /* Do not draw waterborders inside of industries.
703 * Note: There is no easy way to detect the industry of an oilrig tile. */
704 TileIndex src_tile = tile + TileOffsByDir(from);
705 if ((IsTileType(src_tile, TileType::Station) && IsOilRig(src_tile)) ||
706 (IsTileType(src_tile, TileType::Industry))) return true;
707
708 return IsTileOnWater(tile);
709 }
710 return (IsDock(tile) && IsTileFlat(tile)) || IsBuoy(tile);
711
712 case TileType::Industry: {
713 /* Do not draw waterborders inside of industries.
714 * Note: There is no easy way to detect the industry of an oilrig tile. */
715 TileIndex src_tile = tile + TileOffsByDir(from);
716 if ((IsTileType(src_tile, TileType::Station) && IsOilRig(src_tile)) ||
717 (IsTileType(src_tile, TileType::Industry) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
718
719 return IsTileOnWater(tile);
720 }
721
722 case TileType::Object: return IsTileOnWater(tile);
723
725
726 case TileType::Void: return true; // consider map border as water, esp. for rivers
727
728 default: return false;
729 }
730}
731
739static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
740{
741 if (base != SPR_FLAT_WATER_TILE) {
742 /* Only call offset callback if the sprite is NewGRF-provided. */
743 offset = GetCanalSpriteOffset(feature, tile, offset);
744 }
745 DrawGroundSprite(base + offset, PAL_NONE);
746}
747
754static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
755{
756 CanalFeature feature;
757 SpriteID base = 0;
758 if (canal) {
759 feature = CF_DIKES;
760 base = GetCanalSprite(CF_DIKES, tile);
761 if (base == 0) base = SPR_CANAL_DIKES_BASE;
762 } else {
763 feature = CF_RIVER_EDGE;
764 base = GetCanalSprite(CF_RIVER_EDGE, tile);
765 if (base == 0) return; // Don't draw if no sprites provided.
766 }
767
768 uint wa;
769
770 /* determine the edges around with water. */
771 wa = IsWateredTile(TileAddXY(tile, -1, 0), DIR_SW) << 0;
772 wa += IsWateredTile(TileAddXY(tile, 0, 1), DIR_NW) << 1;
773 wa += IsWateredTile(TileAddXY(tile, 1, 0), DIR_NE) << 2;
774 wa += IsWateredTile(TileAddXY(tile, 0, -1), DIR_SE) << 3;
775
776 if (!(wa & 1)) DrawWaterSprite(base, offset, feature, tile);
777 if (!(wa & 2)) DrawWaterSprite(base, offset + 1, feature, tile);
778 if (!(wa & 4)) DrawWaterSprite(base, offset + 2, feature, tile);
779 if (!(wa & 8)) DrawWaterSprite(base, offset + 3, feature, tile);
780
781 /* right corner */
782 switch (wa & 0x03) {
783 case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
784 case 3: if (!IsWateredTile(TileAddXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
785 }
786
787 /* bottom corner */
788 switch (wa & 0x06) {
789 case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
790 case 6: if (!IsWateredTile(TileAddXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
791 }
792
793 /* left corner */
794 switch (wa & 0x0C) {
795 case 0: DrawWaterSprite(base, offset + 6, feature, tile); break;
796 case 12: if (!IsWateredTile(TileAddXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
797 }
798
799 /* upper corner */
800 switch (wa & 0x09) {
801 case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
802 case 9: if (!IsWateredTile(TileAddXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
803 }
804}
805
808{
809 DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
810}
811
813static void DrawCanalWater(TileIndex tile)
814{
815 SpriteID image = SPR_FLAT_WATER_TILE;
816 if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
817 /* First water slope sprite is flat water. */
818 image = GetCanalSprite(CF_WATERSLOPE, tile);
819 if (image == 0) image = SPR_FLAT_WATER_TILE;
820 }
821 DrawWaterSprite(image, 0, CF_WATERSLOPE, tile);
822
823 DrawWaterEdges(true, 0, tile);
824}
825
826#include "table/water_land.h"
827
838static void DrawWaterTileStruct(const TileInfo *ti, std::span<const DrawTileSeqStruct> seq, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
839{
840 /* Don't draw if buildings are invisible. */
841 if (IsInvisibilitySet(TO_BUILDINGS)) return;
842
843 for (const DrawTileSeqStruct &dtss : seq) {
844 uint tile_offs = offset + dtss.image.sprite;
845 if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
846 AddSortableSpriteToDraw(base + tile_offs, palette, *ti, dtss, IsTransparencySet(TO_BUILDINGS));
847 }
848}
849
851static void DrawWaterLock(const TileInfo *ti)
852{
853 LockPart part = GetLockPart(ti->tile);
854 const DrawTileSprites &dts = _lock_display_data[to_underlying(part)][GetLockDirection(ti->tile)];
855
856 /* Draw ground sprite. */
857 SpriteID image = dts.ground.sprite;
858
859 SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
860 if (water_base == 0) {
861 /* Use default sprites. */
862 water_base = SPR_CANALS_BASE;
863 } else if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
864 /* NewGRF supplies a flat sprite as first sprite. */
865 if (image == SPR_FLAT_WATER_TILE) {
866 image = water_base;
867 } else {
868 image++;
869 }
870 }
871
872 if (image < 5) image += water_base;
873 DrawGroundSprite(image, PAL_NONE);
874
875 /* Draw structures. */
876 uint zoffs = 0;
877 SpriteID base = GetCanalSprite(CF_LOCKS, ti->tile);
878
879 if (base == 0) {
880 /* If no custom graphics, use defaults. */
881 base = SPR_LOCK_BASE;
882 uint8_t z_threshold = part == LockPart::Upper ? 8 : 0;
883 zoffs = ti->z > z_threshold ? 24 : 0;
884 }
885
886 DrawWaterTileStruct(ti, dts.GetSequence(), base, zoffs, PAL_NONE, CF_LOCKS);
887}
888
890static void DrawWaterDepot(const TileInfo *ti)
891{
892 DrawWaterClassGround(ti);
893 DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][to_underlying(GetShipDepotPart(ti->tile))].seq, 0, 0, GetCompanyPalette(GetTileOwner(ti->tile)), CF_END);
894}
895
896static void DrawRiverWater(const TileInfo *ti)
897{
898 SpriteID image = SPR_FLAT_WATER_TILE;
899 uint offset = 0;
900 uint edges_offset = 0;
901
902 if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
903 image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
904 if (image == 0) {
905 switch (ti->tileh) {
906 case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
907 case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP; break;
908 case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP; break;
909 case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
910 default: image = SPR_FLAT_WATER_TILE; break;
911 }
912 } else {
913 /* Flag bit 0 indicates that the first sprite is flat water. */
914 offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;
915
916 switch (ti->tileh) {
917 case SLOPE_SE: edges_offset += 12; break;
918 case SLOPE_NE: offset += 1; edges_offset += 24; break;
919 case SLOPE_SW: offset += 2; edges_offset += 36; break;
920 case SLOPE_NW: offset += 3; edges_offset += 48; break;
921 default: offset = 0; break;
922 }
923
924 offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
925 }
926 }
927
928 DrawGroundSprite(image + offset, PAL_NONE);
929
930 /* Draw river edges if available. */
931 DrawWaterEdges(false, edges_offset, ti->tile);
932}
933
934void DrawShoreTile(Slope tileh)
935{
936 /* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
937 * This allows to calculate the proper sprite to display for this Slope */
938 static const uint8_t tileh_to_shoresprite[32] = {
939 0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
940 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0,
941 };
942
943 assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier.
944 assert(tileh != SLOPE_FLAT); // Shore is never flat
945
946 assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour
947
948 DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE);
949}
950
951void DrawWaterClassGround(const TileInfo *ti)
952{
953 switch (GetWaterClass(ti->tile)) {
954 case WaterClass::Sea: DrawSeaWater(ti->tile); break;
955 case WaterClass::Canal: DrawCanalWater(ti->tile); break;
956 case WaterClass::River: DrawRiverWater(ti); break;
957 default: NOT_REACHED();
958 }
959}
960
961static void DrawTile_Water(TileInfo *ti)
962{
963 switch (GetWaterTileType(ti->tile)) {
965 DrawWaterClassGround(ti);
966 /* A plain water tile can be traversed in any direction, so setting blocked pillars here would mean all bridges
967 * with edges would have no pillars above water. Instead prefer current behaviour of ships passing through. */
968 DrawBridgeMiddle(ti, {});
969 break;
970
972 DrawShoreTile(ti->tileh);
973 DrawBridgeMiddle(ti, {});
974 break;
975 }
976
978 DrawWaterLock(ti);
980 ? BridgePillarFlags{BridgePillarFlag::EdgeNE, BridgePillarFlag::EdgeSW}
981 : BridgePillarFlags{BridgePillarFlag::EdgeNW, BridgePillarFlag::EdgeSE});
982 break;
983
985 DrawWaterDepot(ti);
986 break;
987 }
988}
989
990void DrawShipDepotSprite(int x, int y, Axis axis, DepotPart part)
991{
992 const DrawTileSprites &dts = _shipdepot_display_data[axis][to_underlying(part)];
993
994 DrawSprite(dts.ground.sprite, dts.ground.pal, x, y);
996}
997
998
999static int GetSlopePixelZ_Water(TileIndex tile, uint x, uint y, bool)
1000{
1001 auto [tileh, z] = GetTilePixelSlope(tile);
1002
1003 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
1004}
1005
1006static Foundation GetFoundation_Water(TileIndex, Slope)
1007{
1008 return FOUNDATION_NONE;
1009}
1010
1011static void GetTileDesc_Water(TileIndex tile, TileDesc &td)
1012{
1013 switch (GetWaterTileType(tile)) {
1015 switch (GetWaterClass(tile)) {
1016 case WaterClass::Sea: td.str = STR_LAI_WATER_DESCRIPTION_WATER; break;
1017 case WaterClass::Canal: td.str = STR_LAI_WATER_DESCRIPTION_CANAL; break;
1018 case WaterClass::River: td.str = STR_LAI_WATER_DESCRIPTION_RIVER; break;
1019 default: NOT_REACHED();
1020 }
1021 break;
1022 case WaterTileType::Coast: td.str = STR_LAI_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break;
1023 case WaterTileType::Lock : td.str = STR_LAI_WATER_DESCRIPTION_LOCK; break;
1025 td.str = STR_LAI_WATER_DESCRIPTION_SHIP_DEPOT;
1026 td.build_date = Depot::GetByTile(tile)->build_date;
1027 break;
1028 default: NOT_REACHED();
1029 }
1030
1031 td.owner[0] = GetTileOwner(tile);
1032}
1033
1039static void FloodVehicle(Vehicle *v)
1040{
1041 uint victims = v->Crash(true);
1042
1043 AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims, v->owner));
1044 Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims, v->owner));
1045 AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_FLOOD_VEHICLE, victims), NewsType::Accident, v->tile);
1047 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
1048}
1049
1055static void FloodVehicleProc(Vehicle *v, int z)
1056{
1057 if (v->vehstatus.Test(VehState::Crashed)) return;
1058
1059 switch (v->type) {
1060 default: break;
1061
1062 case VEH_AIRCRAFT: {
1063 if (!IsAirportTile(v->tile) || GetTileMaxZ(v->tile) != 0) break;
1064 if (v->subtype == AIR_SHADOW) break;
1065
1066 /* We compare v->z_pos against delta_z + 1 because the shadow
1067 * is at delta_z and the actual aircraft at delta_z + 1. */
1068 const Station *st = Station::GetByTile(v->tile);
1069 const AirportFTAClass *airport = st->airport.GetFTA();
1070 if (v->z_pos != airport->delta_z + 1) break;
1071
1072 FloodVehicle(v);
1073 break;
1074 }
1075
1076 case VEH_TRAIN:
1077 case VEH_ROAD: {
1078 if (v->z_pos > z) break;
1079 FloodVehicle(v->First());
1080 break;
1081 }
1082 }
1083}
1084
1085static void FloodVehiclesOnTile(TileIndex tile, int z)
1086{
1087 for (Vehicle *v : VehiclesOnTile(tile)) {
1088 FloodVehicleProc(v, z);
1089 }
1090}
1091
1097static void FloodVehicles(TileIndex tile)
1098{
1099 if (IsAirportTile(tile)) {
1100 const Station *st = Station::GetByTile(tile);
1101 for (TileIndex airport_tile : st->airport) {
1102 if (st->TileBelongsToAirport(airport_tile)) FloodVehiclesOnTile(airport_tile, 0);
1103 }
1104
1105 /* No vehicle could be flooded on this airport anymore */
1106 return;
1107 }
1108
1109 if (!IsBridgeTile(tile)) {
1110 FloodVehiclesOnTile(tile, 0);
1111 return;
1112 }
1113
1114 TileIndex end = GetOtherBridgeEnd(tile);
1115 int z = GetBridgePixelHeight(tile);
1116
1117 FloodVehiclesOnTile(tile, z);
1118 FloodVehiclesOnTile(end, z);
1119}
1120
1127{
1128 /* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
1129 * FLOOD_DRYUP: coast with more than one corner raised, coast with rail-track, coast with trees
1130 * FLOOD_PASSIVE: (not used)
1131 * FLOOD_NONE: canals, rivers, everything else
1132 */
1133 switch (GetTileType(tile)) {
1134 case TileType::Water:
1135 if (IsCoast(tile)) {
1136 Slope tileh = GetTileSlope(tile);
1138 }
1139 [[fallthrough]];
1140 case TileType::Station:
1141 case TileType::Industry:
1142 case TileType::Object:
1144
1145 case TileType::Railway:
1146 if (GetRailGroundType(tile) == RailGroundType::HalfTileWater) {
1148 }
1149 return FLOOD_NONE;
1150
1151 case TileType::Trees:
1153
1154 case TileType::Void:
1155 return FLOOD_ACTIVE;
1156
1157 default:
1158 return FLOOD_NONE;
1159 }
1160}
1161
1165static void DoFloodTile(TileIndex target)
1166{
1167 assert(!IsTileType(target, TileType::Water));
1168
1169 bool flooded = false; // Will be set to true if something is changed.
1170
1172
1173 Slope tileh = GetTileSlope(target);
1174 if (tileh != SLOPE_FLAT) {
1175 /* make coast.. */
1176 switch (GetTileType(target)) {
1177 case TileType::Railway: {
1178 if (!IsPlainRail(target)) break;
1179 FloodVehicles(target);
1180 flooded = FloodHalftile(target);
1181 break;
1182 }
1183
1184 case TileType::Trees:
1185 if (!IsSlopeWithOneCornerRaised(tileh)) {
1187 MarkTileDirtyByTile(target);
1188 flooded = true;
1189 break;
1190 }
1191 [[fallthrough]];
1192
1193 case TileType::Clear:
1194 if (Command<Commands::LandscapeClear>::Do(DoCommandFlag::Execute, target).Succeeded()) {
1195 MakeShore(target);
1196 MarkTileDirtyByTile(target);
1197 flooded = true;
1198 }
1199 break;
1200
1201 default:
1202 break;
1203 }
1204 } else {
1205 /* Flood vehicles */
1206 FloodVehicles(target);
1207
1208 /* flood flat tile */
1209 if (Command<Commands::LandscapeClear>::Do(DoCommandFlag::Execute, target).Succeeded()) {
1210 MakeSea(target);
1211 MarkTileDirtyByTile(target);
1212 flooded = true;
1213 }
1214 }
1215
1216 if (flooded) {
1217 /* Mark surrounding canal tiles dirty too to avoid glitches */
1219
1220 /* update signals if needed */
1222
1223 if (IsPossibleDockingTile(target)) CheckForDockingTile(target);
1224 InvalidateWaterRegion(target);
1225 }
1226
1227 cur_company.Restore();
1228}
1229
1233static void DoDryUp(TileIndex tile)
1234{
1236
1237 switch (GetTileType(tile)) {
1238 case TileType::Railway:
1239 assert(IsPlainRail(tile));
1240 assert(GetRailGroundType(tile) == RailGroundType::HalfTileWater);
1241
1242 RailGroundType new_ground;
1243 switch (GetTrackBits(tile)) {
1244 case TRACK_BIT_UPPER: new_ground = RailGroundType::FenceHoriz1; break;
1245 case TRACK_BIT_LOWER: new_ground = RailGroundType::FenceHoriz2; break;
1246 case TRACK_BIT_LEFT: new_ground = RailGroundType::FenceVert1; break;
1247 case TRACK_BIT_RIGHT: new_ground = RailGroundType::FenceVert2; break;
1248 default: NOT_REACHED();
1249 }
1250 SetRailGroundType(tile, new_ground);
1251 MarkTileDirtyByTile(tile);
1252 break;
1253
1254 case TileType::Trees:
1256 MarkTileDirtyByTile(tile);
1257 break;
1258
1259 case TileType::Water:
1260 assert(IsCoast(tile));
1261
1262 if (Command<Commands::LandscapeClear>::Do(DoCommandFlag::Execute, tile).Succeeded()) {
1263 MakeClear(tile, ClearGround::Grass, 3);
1264 MarkTileDirtyByTile(tile);
1265 }
1266 break;
1267
1268 default: NOT_REACHED();
1269 }
1270
1271 cur_company.Restore();
1272}
1273
1281{
1282 if (IsTileType(tile, TileType::Water)) {
1283 AmbientSoundEffect(tile);
1284 if (IsNonFloodingWaterTile(tile)) return;
1285 }
1286
1287 switch (GetFloodingBehaviour(tile)) {
1288 case FLOOD_ACTIVE: {
1289 bool continue_flooding = false;
1290 for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
1292 /* Contrary to drying up, flooding does not consider TileType::Void tiles. */
1293 if (!IsValidTile(dest)) continue;
1294 /* do not try to flood water tiles - increases performance a lot */
1295 if (IsTileType(dest, TileType::Water)) continue;
1296
1297 /* Buoys and docks cannot be flooded, and when removed turn into flooding water. */
1298 if (IsTileType(dest, TileType::Station) && (IsBuoy(dest) || IsDock(dest))) continue;
1299
1300 /* This neighbour tile might be floodable later if the tile is cleared, so allow flooding to continue. */
1301 continue_flooding = true;
1302
1303 /* TreeGround::Shore is the sign of a previous flood. */
1304 if (IsTileType(dest, TileType::Trees) && GetTreeGround(dest) == TreeGround::Shore) continue;
1305
1306 auto [slope_dest, z_dest] = GetFoundationSlope(dest);
1307 if (z_dest > 0) continue;
1308
1309 if (!_flood_from_dirs[slope_dest & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP].Test(ReverseDir(dir))) continue;
1310
1311 DoFloodTile(dest);
1312 }
1313 if (!continue_flooding && IsTileType(tile, TileType::Water)) SetNonFloodingWaterTile(tile, true);
1314 break;
1315 }
1316
1317 case FLOOD_DRYUP: {
1318 Slope slope_here = std::get<0>(GetFoundationSlope(tile)) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
1319 for (Direction dir : _flood_from_dirs[slope_here]) {
1321 /* Contrary to flooding, drying up does consider TileType::Void tiles. */
1322 if (dest == INVALID_TILE) continue;
1323
1324 FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
1325 if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
1326 }
1327 DoDryUp(tile);
1328 break;
1329 }
1330
1331 default: return;
1332 }
1333}
1334
1335void ConvertGroundTilesIntoWaterTiles()
1336{
1337 for (const auto tile : Map::Iterate()) {
1338 auto [slope, z] = GetTileSlopeZ(tile);
1339 if (IsTileType(tile, TileType::Clear) && z == 0) {
1340 /* Make both water for tiles at level 0
1341 * and make shore, as that looks much better
1342 * during the generation. */
1343 switch (slope) {
1344 case SLOPE_FLAT:
1345 MakeSea(tile);
1346 break;
1347
1348 case SLOPE_N:
1349 case SLOPE_E:
1350 case SLOPE_S:
1351 case SLOPE_W:
1352 MakeShore(tile);
1353 break;
1354
1355 default:
1356 for (Direction dir : _flood_from_dirs[slope & ~SLOPE_STEEP]) {
1357 TileIndex dest = TileAddByDir(tile, dir);
1358 Slope slope_dest = GetTileSlope(dest) & ~SLOPE_STEEP;
1359 if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest) || IsTileType(dest, TileType::Void)) {
1360 MakeShore(tile);
1361 break;
1362 }
1363 }
1364 break;
1365 }
1366 }
1367 }
1368}
1369
1370static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint, DiagDirection)
1371{
1374
1375 TrackBits ts;
1376
1377 if (mode != TRANSPORT_WATER) return 0;
1378
1379 switch (GetWaterTileType(tile)) {
1380 case WaterTileType::Clear: ts = IsTileFlat(tile) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
1381 case WaterTileType::Coast: ts = coast_tracks[GetTileSlope(tile) & 0xF]; break;
1383 case WaterTileType::Depot: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
1384 default: return 0;
1385 }
1386 if (TileX(tile) == 0) {
1387 /* NE border: remove tracks that connects NE tile edge */
1389 }
1390 if (TileY(tile) == 0) {
1391 /* NW border: remove tracks that connects NW tile edge */
1393 }
1395}
1396
1397static bool ClickTile_Water(TileIndex tile)
1398{
1401 return true;
1402 }
1403 return false;
1404}
1405
1406static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
1407{
1408 if (!IsTileOwner(tile, old_owner)) return;
1409
1410 bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LockPart::Middle;
1411
1412 /* No need to dirty company windows here, we'll redraw the whole screen anyway. */
1413 if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1414 if (new_owner != INVALID_OWNER) {
1415 if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1416 /* Only subtract from the old owner here if the new owner is valid,
1417 * otherwise we clear ship depots and canal water below. */
1418 if (GetWaterClass(tile) == WaterClass::Canal && !is_lock_middle) {
1419 Company::Get(old_owner)->infrastructure.water--;
1420 Company::Get(new_owner)->infrastructure.water++;
1421 }
1422 if (IsShipDepot(tile)) {
1423 Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
1424 Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
1425 }
1426
1427 SetTileOwner(tile, new_owner);
1428 return;
1429 }
1430
1431 /* Remove depot */
1432 if (IsShipDepot(tile)) Command<Commands::LandscapeClear>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile);
1433
1434 /* Set owner of canals and locks ... and also canal under dock there was before.
1435 * Check if the new owner after removing depot isn't OWNER_WATER. */
1436 if (IsTileOwner(tile, old_owner)) {
1437 if (GetWaterClass(tile) == WaterClass::Canal && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
1438 SetTileOwner(tile, OWNER_NONE);
1439 }
1440}
1441
1442static VehicleEnterTileStates VehicleEnter_Water(Vehicle *, TileIndex, int, int)
1443{
1444 return {};
1445}
1446
1447static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlags flags, int, Slope)
1448{
1449 /* Canals can't be terraformed */
1450 if (IsWaterTile(tile) && IsCanal(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
1451
1452 /* Rivers can't be terraformed */
1453 if (IsWaterTile(tile) && IsRiver(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_RIVER_FIRST);
1454
1455 return Command<Commands::LandscapeClear>::Do(flags, tile);
1456}
1457
1458static CommandCost CheckBuildAbove_Water(TileIndex tile, DoCommandFlags flags, Axis, int height)
1459{
1460 if (IsWater(tile) || IsCoast(tile)) return CommandCost();
1461 if (IsLock(tile)) {
1462 if (GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(GetLockPart(tile)) <= height) return CommandCost();
1463 int height_diff = (GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(GetLockPart(tile)) - height) * TILE_HEIGHT_STEP;
1464 return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff);
1465 }
1466 return Command<Commands::LandscapeClear>::Do(flags, tile);
1467}
1468
1469extern const TileTypeProcs _tile_type_water_procs = {
1470 DrawTile_Water, // draw_tile_proc
1471 GetSlopePixelZ_Water, // get_slope_z_proc
1472 ClearTile_Water, // clear_tile_proc
1473 nullptr, // add_accepted_cargo_proc
1474 GetTileDesc_Water, // get_tile_desc_proc
1475 GetTileTrackStatus_Water, // get_tile_track_status_proc
1476 ClickTile_Water, // click_tile_proc
1477 nullptr, // animate_tile_proc
1478 TileLoop_Water, // tile_loop_proc
1479 ChangeTileOwner_Water, // change_tile_owner_proc
1480 nullptr, // add_produced_cargo_proc
1481 VehicleEnter_Water, // vehicle_enter_tile_proc
1482 GetFoundation_Water, // get_foundation_proc
1483 TerraformTile_Water, // terraform_tile_proc
1484 CheckBuildAbove_Water, // check_build_above_proc
1485};
Base functions for all AIs.
Base for aircraft.
@ AIR_SHADOW
shadow of the aircraft
Definition aircraft.h:31
Class for backupping variables and making sure they are restored later.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars)
Draw the middle bits of a bridge.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition bridge_map.h:84
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition ai_core.cpp:235
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Generate TileIndices around a center tile or tile area, with increasing distance.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Definition tilearea.cpp:291
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
Iterate over all vehicles on a tile.
Map accessors for 'clear' tiles.
@ Grass
Plain grass with dirt transition (0-3).
Definition clear_map.h:22
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition clear_map.h:252
CommandCost CommandCostWithParam(StringID str, uint64_t value)
Return an error status, with string and parameter.
Definition command.cpp:416
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Auto
don't allow building on structures
@ NoWater
don't allow building on water
@ Execute
execute the given command
@ Bankrupt
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ ForceClearTile
do not only remove the object on the tile, but also clear any water left on it
Definition of stuff that is very close to a company, like the company struct itself.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
GUI Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner INVALID_OWNER
An invalid owner.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Base for all depots (except hangars).
Functions related to depots.
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Direction
Defines the 8 directions on the map.
@ DIR_BEGIN
Used to iterate.
@ DIR_SW
Southwest.
@ DIR_NW
Northwest.
@ DIR_N
North.
@ DIR_SE
Southeast.
@ DIR_S
South.
@ DIR_NE
Northeast.
@ DIR_END
Used to iterate.
@ DIR_W
West.
@ DIR_E
East.
EnumBitSet< Direction, uint8_t > Directions
Allow incrementing of Direction variables.
Axis
Allow incrementing of DiagDirDiff variables.
@ AXIS_X
The X axis.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
@ EXPENSES_CONSTRUCTION
Construction costs.
@ ClearCanal
Price for destroying canals.
@ ClearRough
Price for destroying rough land.
@ BuildDepotShip
Price for building ship depots.
@ BuildCanal
Price for building new canals.
@ ClearWater
Price for destroying water e.g. see, rives.
@ ClearDepotShip
Price for destroying ship depots.
@ ClearLock
Price for destroying locks.
@ BuildLock
Price for building new locks.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
Functions related to effect vehicles.
@ EV_EXPLOSION_LARGE
Various explosions.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:17
Base functions for all Games.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1038
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
Marks the tiles around a tile as dirty, if they are canals or rivers.
Definition water_cmd.cpp:87
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Base of all industries.
Accessors to map for industries.
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
std::tuple< Slope, int > GetFoundationSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Functions related to OTTD's landscape.
Command definitions related to landscape (slopes etc.).
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:472
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Definition map_func.h:517
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition map_func.h:601
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition map_func.h:442
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition map_func.h:613
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:557
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:427
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:417
TileIndexDiffC TileIndexDiffCByDir(Direction dir)
Returns the TileIndexDiffC offset from a Direction.
Definition map_func.h:499
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition map_func.h:586
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:572
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
CanalFeature
List of different canal 'features'.
Definition newgrf.h:27
uint GetCanalSpriteOffset(CanalFeature feature, TileIndex tile, uint cur_offset)
Get the new sprite offset for a water tile.
std::array< WaterFeature, CF_END > _water_feature
Table of canal 'feature' sprite groups.
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
Lookup the base sprite to use for a canal.
Handling of NewGRF canals.
@ CFF_HAS_FLAT_SPRITE
Additional flat ground sprite in the beginning.
Functions related to generic callbacks.
void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
Functions related to news.
@ Accident
An accident or disaster has occurred.
Definition news_type.h:32
bool FloodHalftile(TileIndex t)
Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore.
Definition rail_cmd.cpp:759
static bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
Definition rail_map.h:49
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
RailGroundType
The ground 'under' the rail.
Definition rail_map.h:484
@ FenceVert2
Grass with a fence at the western side.
Definition rail_map.h:494
@ FenceHoriz2
Grass with a fence at the northern side.
Definition rail_map.h:496
@ HalfTileWater
Grass with a fence and shore or water on the free halftile.
Definition rail_map.h:498
@ FenceVert1
Grass with a fence at the eastern side.
Definition rail_map.h:493
@ FenceHoriz1
Grass with a fence at the southern side.
Definition rail_map.h:495
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void UpdateSignalsInBuffer()
Update signals in buffer Called from 'outside'.
Definition signal.cpp:573
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition slope_func.h:88
bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
Definition slope_func.h:228
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition slope_func.h:47
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition slope_func.h:239
Slope
Enumeration for the slope-type.
Definition slope_type.h:47
@ SLOPE_W
the west corner of the tile is raised
Definition slope_type.h:49
@ SLOPE_HALFTILE_MASK
three bits used for halftile slopes
Definition slope_type.h:71
@ SLOPE_NS
north and south corner are raised
Definition slope_type.h:59
@ SLOPE_E
the east corner of the tile is raised
Definition slope_type.h:51
@ SLOPE_S
the south corner of the tile is raised
Definition slope_type.h:50
@ SLOPE_N
the north corner of the tile is raised
Definition slope_type.h:52
@ SLOPE_SW
south and west corner are raised
Definition slope_type.h:55
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:48
@ SLOPE_NE
north and east corner are raised
Definition slope_type.h:57
@ SLOPE_SE
south and east corner are raised
Definition slope_type.h:56
@ SLOPE_NW
north and west corner are raised
Definition slope_type.h:54
@ SLOPE_EW
east and west corner are raised
Definition slope_type.h:58
@ SLOPE_STEEP
indicates the slope is steep
Definition slope_type.h:53
Foundation
Enumeration for Foundations.
Definition slope_type.h:92
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:93
Functions related to sound.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition sound_type.h:64
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:137
static const SpriteID SPR_SHORE_BASE
shore tiles - action 05-0D
Definition sprites.h:226
Base classes/functions for stations.
bool IsAirportTile(Tile t)
Is this tile a station tile and an airport tile?
bool IsBuoy(Tile t)
Is tile t a buoy tile?
bool IsDockTile(Tile t)
Is tile t a dock tile?
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
bool IsDockWaterPart(Tile t)
Check whether a dock tile is the tile on water.
bool IsDock(Tile t)
Is tile t a dock tile?
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
Functions related to OTTD's strings.
Finite sTate mAchine (FTA) of an airport.
Definition airport.h:158
uint8_t delta_z
Z adjustment for helicopter pads.
Definition airport.h:196
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Class to backup a specific variable and restore it later.
void Restore()
Restore the variable.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
VehicleType type
Type of vehicle.
uint32_t water
Count of company owned track bits for canals.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
T z
Z coordinate.
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:33
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:251
Station * neutral_station
Associated neutral station.
Definition industry.h:108
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:365
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
static uint Size()
Get the size of the map.
Definition map_func.h:280
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition tilearea.cpp:43
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PaletteID pal
The palette (use PAL_NONE) if not needed).
Definition gfx_type.h:24
static Company * Get(auto index)
static bool CanAllocateItem(size_t n=1)
static T * Create(Targs &&... args)
static Company * GetIfValid(auto index)
Station data structure.
TileArea docking_station
Tile area the docking tiles cover.
Airport airport
Tile area the airport covers.
Tile description for the 'land area information' tool.
Definition tile_cmd.h:38
StringID str
Description of the tile.
Definition tile_cmd.h:39
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:43
std::array< Owner, 4 > owner
Name of the owner(s).
Definition tile_cmd.h:41
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
Tile information, used while rendering the tile.
Definition tile_cmd.h:32
Slope tileh
Slope of the tile.
Definition tile_cmd.h:33
TileIndex tile
Tile index.
Definition tile_cmd.h:34
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:154
Town data structure.
Definition town.h:63
Vehicle data structure.
int32_t z_pos
z coordinate.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition vehicle.cpp:291
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
VehStates vehstatus
Status.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
TileIndex tile
Current tile index.
Owner owner
Which company owns the vehicle?
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition tile_map.cpp:94
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.cpp:55
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:135
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition tile_map.h:214
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
Definition tile_map.h:289
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition tile_map.h:238
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
Definition tile_map.h:225
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
@ TROPICZONE_DESERT
Tile is desert.
Definition tile_type.h:83
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition tile_type.h:82
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ Water
Water tile.
Definition tile_type.h:55
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Object
Contains objects such as transmitters and owned land.
Definition tile_type.h:59
@ Industry
Part of an industry.
Definition tile_type.h:57
@ Railway
A tile with railway.
Definition tile_type.h:50
@ Void
Invisible tiles at the SW and SE border.
Definition tile_type.h:56
@ Trees
Tile with one or more trees.
Definition tile_type.h:53
@ Clear
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:49
Definition of the game-calendar-timer.
Base of the town class.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlags flags)
Changes town rating of the current company.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition town.h:285
Types related to towns.
static constexpr int RATING_WATER_MINIMUM
minimum rating after removing water features near town
Definition town_type.h:81
static constexpr int RATING_WATER_RIVER_DOWN_STEP
removing a river tile
Definition town_type.h:80
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition track_func.h:319
TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition track_func.h:388
TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition track_func.h:88
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition track_func.h:524
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition track_func.h:363
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
@ TRACK_BIT_UPPER
Upper track.
Definition track_type.h:39
@ TRACK_BIT_LEFT
Left track.
Definition track_type.h:41
@ TRACK_BIT_Y
Y-axis track.
Definition track_type.h:38
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
@ TRACK_BIT_X
X-axis track.
Definition track_type.h:37
@ TRACK_BIT_LOWER
Lower track.
Definition track_type.h:40
@ TRACK_BIT_ALL
All possible tracks.
Definition track_type.h:50
@ TRACK_BIT_RIGHT
Right track.
Definition track_type.h:42
@ TRACKDIR_BIT_NONE
No track build.
Definition track_type.h:98
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...
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...
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
TransportType
Available types of transport.
@ TRANSPORT_WATER
Transport over water.
Map accessors for tree tiles.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition tree_map.h:102
@ Shore
Shore.
Definition tree_map.h:56
@ Grass
Normal grass.
Definition tree_map.h:53
void SetTreeGroundDensity(Tile t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition tree_map.h:144
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition vehicle.cpp:528
@ Crashed
Vehicle is crashed.
Functions related to vehicles.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition viewport.cpp:658
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:579
Functions related to (drawing on) viewports.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Functions related to water management.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
FloodingBehaviour
Describes the behaviour of a tile during flooding.
Definition water.h:19
@ FLOOD_NONE
The tile does not flood neighboured tiles.
Definition water.h:20
@ FLOOD_ACTIVE
The tile floods neighboured tiles.
Definition water.h:21
@ FLOOD_DRYUP
The tile drys up if it is not constantly flooded from neighboured tiles.
Definition water.h:23
@ FLOOD_PASSIVE
The tile does not actively flood neighboured tiles, but it prevents them from drying up.
Definition water.h:22
static const uint RIVER_OFFSET_DESERT_DISTANCE
Circular tile search diameter to create non-desert around a river tile.
Definition water.h:44
static uint8_t GetLockPartMinimalBridgeHeight(LockPart lock_part)
Get the minimal height required for a bridge above a lock part.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
static void DrawWaterDepot(const TileInfo *ti)
Draw a ship depot tile.
static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
Draw a water sprite, potentially with a NewGRF-modified sprite offset.
static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags flags)
Builds a lock.
CommandCost CmdBuildLock(DoCommandFlags flags, TileIndex tile)
Builds a lock.
static CommandCost RemoveLock(TileIndex tile, DoCommandFlags flags)
Remove a lock.
static void DrawWaterLock(const TileInfo *ti)
Draw a lock tile.
static void FloodVehicle(Vehicle *v)
Handle the flooding of a vehicle.
static void FloodVehicles(TileIndex tile)
Finds a vehicle to flood.
static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
Draw canal or river edges.
static void FloodVehicleProc(Vehicle *v, int z)
Flood a vehicle if we are allowed to flood it, i.e.
static const Directions _flood_from_dirs[]
Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
Definition water_cmd.cpp:52
void ClearNeighbourNonFloodingStates(TileIndex tile)
Clear non-flooding state of the tiles around a tile.
Definition water_cmd.cpp:98
static void DrawWaterTileStruct(const TileInfo *ti, std::span< const DrawTileSeqStruct > seq, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
Draw a build sprite sequence for water tiles.
static void DoDryUp(TileIndex tile)
Drys a tile up.
static void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
Marks tile dirty if it is a canal or river tile.
Definition water_cmd.cpp:76
FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
Returns the behaviour of a tile during flooding.
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
static void DrawSeaWater(TileIndex)
Draw a plain sea water tile with no edges.
CommandCost CmdBuildShipDepot(DoCommandFlags flags, TileIndex tile, Axis axis)
Build a ship depot.
static void DrawCanalWater(TileIndex tile)
draw a canal styled water tile with dikes around
void MakeRiverAndModifyDesertZoneAround(TileIndex tile)
Make a river tile and remove desert directly around it.
static void DoFloodTile(TileIndex target)
Floods a tile.
bool IsWateredTile(TileIndex tile, Direction from)
return true if a tile is a water tile wrt.
CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
Build a piece of canal.
Command definitions related to water tiles.
Sprites to use and how to display them for water tiles (depots/locks).
void MakeShore(Tile t)
Helper function to make a coast tile.
Definition water_map.h:383
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
Definition water_map.h:352
TileIndex GetShipDepotNorthTile(Tile t)
Get the most northern tile of a ship depot.
Definition water_map.h:291
void MakeLock(Tile t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper, WaterClass wc_middle)
Make a water lock.
Definition water_map.h:512
DepotPart GetShipDepotPart(Tile t)
Get the part of a ship depot.
Definition water_map.h:257
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:138
bool IsShipDepot(Tile t)
Is it a water tile with a ship depot on it?
Definition water_map.h:224
bool IsValidWaterClass(WaterClass wc)
Checks if a water class is valid.
Definition water_map.h:52
bool IsRiver(Tile t)
Is it a river water tile?
Definition water_map.h:182
DiagDirection GetLockDirection(Tile t)
Get the direction of the water lock.
Definition water_map.h:316
WaterClass
classes of water (for WaterTileType::Clear water tile type).
Definition water_map.h:39
@ River
River.
Definition water_map.h:42
@ Invalid
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition water_map.h:43
@ Canal
Canal.
Definition water_map.h:41
@ Sea
Sea.
Definition water_map.h:40
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition water_map.h:103
bool IsCanal(Tile t)
Is it a canal tile?
Definition water_map.h:171
bool IsCoast(Tile t)
Is it a coast tile?
Definition water_map.h:203
void MakeRiver(Tile t, uint8_t random_bits)
Make a river tile.
Definition water_map.h:436
WaterTileType GetWaterTileType(Tile t)
Get the water tile type of a tile.
Definition water_map.h:80
void SetNonFloodingWaterTile(Tile t, bool b)
Set the non-flooding water tile state of a tile.
Definition water_map.h:530
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:114
void MakeCanal(Tile t, Owner o, uint8_t random_bits)
Make a canal tile.
Definition water_map.h:447
TileIndex GetOtherShipDepotTile(Tile t)
Get the other tile of the ship depot.
Definition water_map.h:280
DepotPart
Sections of the water depot.
Definition water_map.h:58
@ South
Southern part of a depot.
Definition water_map.h:60
@ North
Northern part of a depot.
Definition water_map.h:59
@ Coast
Coast.
Definition water_map.h:33
@ Depot
Water Depot.
Definition water_map.h:35
@ Lock
Water lock.
Definition water_map.h:34
@ Clear
Plain water.
Definition water_map.h:32
bool IsNonFloodingWaterTile(Tile t)
Checks whether the tile is marked as a non-flooding water tile.
Definition water_map.h:539
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition water_map.h:363
LockPart
Sections of the water lock.
Definition water_map.h:65
@ Upper
Upper part of a lock.
Definition water_map.h:68
@ End
End marker.
Definition water_map.h:69
@ Middle
Middle part of a lock.
Definition water_map.h:66
bool IsWater(Tile t)
Is it a plain water tile?
Definition water_map.h:149
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition water_map.h:192
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition water_map.h:305
void MakeShipDepot(Tile t, Owner o, DepotID did, DepotPart part, Axis a, WaterClass original_water_class)
Make a ship depot section.
Definition water_map.h:462
void MakeSea(Tile t)
Make a sea tile.
Definition water_map.h:426
LockPart GetLockPart(Tile t)
Get the part of a lock.
Definition water_map.h:328
Axis GetShipDepotAxis(Tile t)
Get the axis of the ship depot.
Definition water_map.h:245
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Handles dividing the water in the map into regions to assist pathfinding.