OpenTTD Source 20250312-master-gcdcc6b491d
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 <http://www.gnu.org/licenses/>.
6 */
7
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
44#include "table/strings.h"
45
46#include "safeguards.h"
47
51static const uint8_t _flood_from_dirs[] = {
52 (1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE), // SLOPE_FLAT
53 (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_W
54 (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_S
55 (1 << DIR_NE), // SLOPE_SW
56 (1 << DIR_NW) | (1 << DIR_SW), // SLOPE_E
57 0, // SLOPE_EW
58 (1 << DIR_NW), // SLOPE_SE
59 (1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_WSE, SLOPE_STEEP_S
60 (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_N
61 (1 << DIR_SE), // SLOPE_NW
62 0, // SLOPE_NS
63 (1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_NWS, SLOPE_STEEP_W
64 (1 << DIR_SW), // SLOPE_NE
65 (1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_ENW, SLOPE_STEEP_N
66 (1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW), // SLOPE_SEN, SLOPE_STEEP_E
67};
68
75static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
76{
77 if (IsValidTile(tile) && IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
78}
79
87{
88 for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
90 }
91}
92
98{
99 for (Direction dir = DIR_BEGIN; dir != DIR_END; dir++) {
100 TileIndex dest = tile + TileOffsByDir(dir);
101 if (IsValidTile(dest) && IsTileType(dest, MP_WATER)) SetNonFloodingWaterTile(dest, false);
102 }
103}
104
113{
114 if (!IsValidAxis(axis)) return CMD_ERROR;
115 TileIndex tile2 = tile + TileOffsByAxis(axis);
116
117 if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
118 return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER);
119 }
120
121 if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
122
123 if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
124 /* Prevent depots on rapids */
125 return CommandCost(STR_ERROR_SITE_UNSUITABLE);
126 }
127
128 if (!Depot::CanAllocateItem()) return CMD_ERROR;
129
130 WaterClass wc1 = GetWaterClass(tile);
131 WaterClass wc2 = GetWaterClass(tile2);
132 CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
133
134 bool add_cost = !IsWaterTile(tile);
136 if (ret.Failed()) return ret;
137 if (add_cost) {
138 cost.AddCost(ret);
139 }
140 add_cost = !IsWaterTile(tile2);
142 if (ret.Failed()) return ret;
143 if (add_cost) {
144 cost.AddCost(ret);
145 }
146
147 if (flags.Test(DoCommandFlag::Execute)) {
148 Depot *depot = new Depot(tile);
149
150 uint new_water_infra = 2 * LOCK_DEPOT_TILE_FACTOR;
151 /* Update infrastructure counts after the tile clears earlier.
152 * Clearing object tiles may result in water tiles which are already accounted for in the water infrastructure total.
153 * See: MakeWaterKeepingClass() */
154 if (wc1 == WATER_CLASS_CANAL && !(HasTileWaterClass(tile) && GetWaterClass(tile) == WATER_CLASS_CANAL && IsTileOwner(tile, _current_company))) new_water_infra++;
155 if (wc2 == WATER_CLASS_CANAL && !(HasTileWaterClass(tile2) && GetWaterClass(tile2) == WATER_CLASS_CANAL && IsTileOwner(tile2, _current_company))) new_water_infra++;
156
157 Company::Get(_current_company)->infrastructure.water += new_water_infra;
159
160 MakeShipDepot(tile, _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1);
161 MakeShipDepot(tile2, _current_company, depot->index, DEPOT_PART_SOUTH, axis, wc2);
163 CheckForDockingTile(tile2);
165 MarkTileDirtyByTile(tile2);
166 MakeDefaultName(depot);
167 }
168
169 return cost;
170}
171
172bool IsPossibleDockingTile(Tile t)
173{
174 assert(IsValidTile(t));
175 switch (GetTileType(t)) {
176 case MP_WATER:
177 if (IsLock(t) && GetLockPart(t) == LOCK_PART_MIDDLE) return false;
178 [[fallthrough]];
179 case MP_RAILWAY:
180 case MP_STATION:
181 case MP_TUNNELBRIDGE:
183
184 default:
185 return false;
186 }
187}
188
195{
196 for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
197 TileIndex tile = t + TileOffsByDiagDir(d);
198 if (!IsValidTile(tile)) continue;
199
200 if (IsDockTile(tile) && IsDockWaterPart(tile)) {
201 Station::GetByTile(tile)->docking_station.Add(t);
202 SetDockingTile(t, true);
203 }
204 if (IsTileType(tile, MP_INDUSTRY)) {
206 if (st != nullptr) {
207 st->docking_station.Add(t);
208 SetDockingTile(t, true);
209 }
210 }
211 if (IsTileType(tile, MP_STATION) && IsOilRig(tile)) {
212 Station::GetByTile(tile)->docking_station.Add(t);
213 SetDockingTile(t, true);
214 }
215 }
216}
217
218void MakeWaterKeepingClass(TileIndex tile, Owner o)
219{
220 WaterClass wc = GetWaterClass(tile);
221
222 /* Autoslope might turn an originally canal or river tile into land */
223 auto [slope, z] = GetTileSlopeZ(tile);
224
225 if (slope != SLOPE_FLAT) {
226 if (wc == WATER_CLASS_CANAL) {
227 /* If we clear the canal, we have to remove it from the infrastructure count as well. */
229 if (c != nullptr) {
232 }
233 /* Sloped canals are locks and no natural water remains whatever the slope direction */
235 }
236
237 /* Only river water should be restored on appropriate slopes. Other water would be invalid on slopes */
240 }
241 }
242
243 if (wc == WATER_CLASS_SEA && z > 0) {
244 /* Update company infrastructure count. */
246 if (c != nullptr) {
249 }
250
252 }
253
254 /* Zero map array and terminate animation */
255 DoClearSquare(tile);
256
257 /* Maybe change to water */
258 switch (wc) {
259 case WATER_CLASS_SEA: MakeSea(tile); break;
260 case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
261 case WATER_CLASS_RIVER: MakeRiver(tile, Random()); break;
262 default: break;
263 }
264
267}
268
269static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlags flags)
270{
271 if (!IsShipDepot(tile)) return CMD_ERROR;
272
274 if (ret.Failed()) return ret;
275
276 TileIndex tile2 = GetOtherShipDepotTile(tile);
277
278 /* do not check for ship on tile when company goes bankrupt */
279 if (!flags.Test(DoCommandFlag::Bankrupt)) {
280 ret = EnsureNoVehicleOnGround(tile);
281 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
282 if (ret.Failed()) return ret;
283 }
284
285 bool do_clear = flags.Test(DoCommandFlag::ForceClearTile);
286
287 if (flags.Test(DoCommandFlag::Execute)) {
288 delete Depot::GetByTile(tile);
289
291 if (c != nullptr) {
293 if (do_clear && GetWaterClass(tile) == WATER_CLASS_CANAL) c->infrastructure.water--;
295 }
296
297 if (!do_clear) MakeWaterKeepingClass(tile, GetTileOwner(tile));
298 MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
299 }
300
301 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
302}
303
312{
314
315 TileIndexDiff delta = TileOffsByDiagDir(dir);
317 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
318 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
319 if (ret.Failed()) return ret;
320
321 /* middle tile */
323 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
324 if (ret.Failed()) return ret;
325 cost.AddCost(ret);
326
327 /* lower tile */
328 if (!IsWaterTile(tile - delta)) {
329 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta);
330 if (ret.Failed()) return ret;
331 cost.AddCost(ret);
332 cost.AddCost(_price[PR_BUILD_CANAL]);
333 }
334 if (!IsTileFlat(tile - delta)) {
335 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
336 }
337 WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
338
339 /* upper tile */
340 if (!IsWaterTile(tile + delta)) {
341 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta);
342 if (ret.Failed()) return ret;
343 cost.AddCost(ret);
344 cost.AddCost(_price[PR_BUILD_CANAL]);
345 }
346 if (!IsTileFlat(tile + delta)) {
347 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
348 }
349 WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
350
351 if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) {
352 return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
353 }
354
355 if (flags.Test(DoCommandFlag::Execute)) {
356 /* Update company infrastructure counts. */
358 if (c != nullptr) {
359 /* Counts for the water. */
360 if (!IsWaterTile(tile - delta)) c->infrastructure.water++;
361 if (!IsWaterTile(tile + delta)) c->infrastructure.water++;
362 /* Count for the lock itself. */
363 c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles.
365 }
366
367 MakeLock(tile, _current_company, dir, wc_lower, wc_upper, wc_middle);
368 CheckForDockingTile(tile - delta);
369 CheckForDockingTile(tile + delta);
371 MarkTileDirtyByTile(tile - delta);
372 MarkTileDirtyByTile(tile + delta);
373 MarkCanalsAndRiversAroundDirty(tile - delta);
374 MarkCanalsAndRiversAroundDirty(tile + delta);
375 InvalidateWaterRegion(tile - delta);
376 InvalidateWaterRegion(tile + delta);
377 }
378 cost.AddCost(_price[PR_BUILD_LOCK]);
379
380 return cost;
381}
382
390{
391 if (GetTileOwner(tile) != OWNER_NONE) {
393 if (ret.Failed()) return ret;
394 }
395
397
398 /* make sure no vehicle is on the tile. */
400 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
401 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
402 if (ret.Failed()) return ret;
403
404 if (flags.Test(DoCommandFlag::Execute)) {
405 /* Remove middle part from company infrastructure count. */
407 if (c != nullptr) {
408 c->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // three parts of the lock.
410 }
411
412 if (GetWaterClass(tile) == WATER_CLASS_RIVER) {
413 MakeRiver(tile, Random());
414 } else {
415 DoClearSquare(tile);
417 }
418 MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
419 MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
421 MarkCanalsAndRiversAroundDirty(tile - delta);
422 MarkCanalsAndRiversAroundDirty(tile + delta);
423 }
424
425 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
426}
427
435{
437 if (dir == INVALID_DIAGDIR) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
438
439 return DoBuildLock(tile, dir, flags);
440}
441
443static bool RiverModifyDesertZone(TileIndex tile, void *)
444{
446 return false;
447}
448
454{
455 MakeRiver(tile, Random());
457
458 /* Remove desert directly around the river tile. */
460}
461
471CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
472{
473 if (start_tile >= Map::Size() || !IsValidWaterClass(wc)) return CMD_ERROR;
474
475 /* Outside of the editor you can only build canals, not oceans */
476 if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
477
479
480 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
481 for (; *iter != INVALID_TILE; ++(*iter)) {
482 TileIndex current_tile = *iter;
483 CommandCost ret;
484
485 Slope slope = GetTileSlope(current_tile);
486 if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
487 return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
488 }
489
490 bool water = IsWaterTile(current_tile);
491
492 /* Outside the editor, prevent building canals over your own or OWNER_NONE owned canals */
493 if (water && IsCanal(current_tile) && _game_mode != GM_EDITOR && (IsTileOwner(current_tile, _current_company) || IsTileOwner(current_tile, OWNER_NONE))) continue;
494
495 ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
496 if (ret.Failed()) return ret;
497
498 if (!water) cost.AddCost(ret);
499
500 if (flags.Test(DoCommandFlag::Execute)) {
501 if (IsTileType(current_tile, MP_WATER) && IsCanal(current_tile)) {
502 Owner owner = GetTileOwner(current_tile);
503 if (Company::IsValidID(owner)) {
504 Company::Get(owner)->infrastructure.water--;
506 }
507 }
508
509 switch (wc) {
511 MakeRiver(current_tile, Random());
512 if (_game_mode == GM_EDITOR) {
513 TileIndex tile2 = current_tile;
515 }
516 break;
517
518 case WATER_CLASS_SEA:
519 if (TileHeight(current_tile) == 0) {
520 MakeSea(current_tile);
521 break;
522 }
523 [[fallthrough]];
524
525 default:
526 MakeCanal(current_tile, _current_company, Random());
528 Company::Get(_current_company)->infrastructure.water++;
530 }
531 break;
532 }
533 MarkTileDirtyByTile(current_tile);
534 MarkCanalsAndRiversAroundDirty(current_tile);
535 CheckForDockingTile(current_tile);
536 }
537
538 cost.AddCost(_price[PR_BUILD_CANAL]);
539 }
540
541 if (cost.GetCost() == 0) {
542 return CommandCost(STR_ERROR_ALREADY_BUILT);
543 } else {
544 return cost;
545 }
546}
547
548
549static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlags flags)
550{
551 switch (GetWaterTileType(tile)) {
552 case WATER_TILE_CLEAR: {
553 if (flags.Test(DoCommandFlag::NoWater)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
554
555 Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER];
556 /* Make sure freeform edges are allowed or it's not an edge tile. */
558 !IsInsideMM(TileY(tile), 1, Map::MaxY() - 1))) {
559 return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
560 }
561
562 /* Make sure no vehicle is on the tile */
564 if (ret.Failed()) return ret;
565
566 Owner owner = GetTileOwner(tile);
567 if (owner != OWNER_WATER && owner != OWNER_NONE) {
568 ret = CheckTileOwnership(tile);
569 if (ret.Failed()) return ret;
570 }
571
572 if (flags.Test(DoCommandFlag::Execute)) {
573 if (IsCanal(tile) && Company::IsValidID(owner)) {
574 Company::Get(owner)->infrastructure.water--;
576 }
577 DoClearSquare(tile);
580 }
581
582 return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
583 }
584
585 case WATER_TILE_COAST: {
586 Slope slope = GetTileSlope(tile);
587
588 /* Make sure no vehicle is on the tile */
590 if (ret.Failed()) return ret;
591
592 if (flags.Test(DoCommandFlag::Execute)) {
593 DoClearSquare(tile);
596 }
597 if (IsSlopeWithOneCornerRaised(slope)) {
598 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
599 } else {
600 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]);
601 }
602 }
603
604 case WATER_TILE_LOCK: {
605 static const TileIndexDiffC _lock_tomiddle_offs[][DIAGDIR_END] = {
606 /* NE SE SW NW */
607 { { 0, 0}, {0, 0}, { 0, 0}, {0, 0} }, // LOCK_PART_MIDDLE
608 { {-1, 0}, {0, 1}, { 1, 0}, {0, -1} }, // LOCK_PART_LOWER
609 { { 1, 0}, {0, -1}, {-1, 0}, {0, 1} }, // LOCK_PART_UPPER
610 };
611
612 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
614 /* move to the middle tile.. */
615 return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetLockPart(tile)][GetLockDirection(tile)]), flags);
616 }
617
618 case WATER_TILE_DEPOT:
619 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
620 return RemoveShipDepot(tile, flags);
621
622 default:
623 NOT_REACHED();
624 }
625}
626
636{
637 switch (GetTileType(tile)) {
638 case MP_WATER:
639 switch (GetWaterTileType(tile)) {
640 default: NOT_REACHED();
641 case WATER_TILE_DEPOT: case WATER_TILE_CLEAR: return true;
643
644 case WATER_TILE_COAST:
645 switch (GetTileSlope(tile)) {
646 case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
647 case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
648 case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
649 case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
650 default: return false;
651 }
652 }
653
654 case MP_RAILWAY:
655 if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
656 assert(IsPlainRail(tile));
657 switch (GetTileSlope(tile)) {
658 case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
659 case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
660 case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
661 case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
662 default: return false;
663 }
664 }
665 return false;
666
667 case MP_STATION:
668 if (IsOilRig(tile)) {
669 /* Do not draw waterborders inside of industries.
670 * Note: There is no easy way to detect the industry of an oilrig tile. */
671 TileIndex src_tile = tile + TileOffsByDir(from);
672 if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
673 (IsTileType(src_tile, MP_INDUSTRY))) return true;
674
675 return IsTileOnWater(tile);
676 }
677 return (IsDock(tile) && IsTileFlat(tile)) || IsBuoy(tile);
678
679 case MP_INDUSTRY: {
680 /* Do not draw waterborders inside of industries.
681 * Note: There is no easy way to detect the industry of an oilrig tile. */
682 TileIndex src_tile = tile + TileOffsByDir(from);
683 if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
684 (IsTileType(src_tile, MP_INDUSTRY) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
685
686 return IsTileOnWater(tile);
687 }
688
689 case MP_OBJECT: return IsTileOnWater(tile);
690
692
693 case MP_VOID: return true; // consider map border as water, esp. for rivers
694
695 default: return false;
696 }
697}
698
706static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
707{
708 if (base != SPR_FLAT_WATER_TILE) {
709 /* Only call offset callback if the sprite is NewGRF-provided. */
710 offset = GetCanalSpriteOffset(feature, tile, offset);
711 }
712 DrawGroundSprite(base + offset, PAL_NONE);
713}
714
721static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
722{
723 CanalFeature feature;
724 SpriteID base = 0;
725 if (canal) {
726 feature = CF_DIKES;
727 base = GetCanalSprite(CF_DIKES, tile);
728 if (base == 0) base = SPR_CANAL_DIKES_BASE;
729 } else {
730 feature = CF_RIVER_EDGE;
731 base = GetCanalSprite(CF_RIVER_EDGE, tile);
732 if (base == 0) return; // Don't draw if no sprites provided.
733 }
734
735 uint wa;
736
737 /* determine the edges around with water. */
738 wa = IsWateredTile(TileAddXY(tile, -1, 0), DIR_SW) << 0;
739 wa += IsWateredTile(TileAddXY(tile, 0, 1), DIR_NW) << 1;
740 wa += IsWateredTile(TileAddXY(tile, 1, 0), DIR_NE) << 2;
741 wa += IsWateredTile(TileAddXY(tile, 0, -1), DIR_SE) << 3;
742
743 if (!(wa & 1)) DrawWaterSprite(base, offset, feature, tile);
744 if (!(wa & 2)) DrawWaterSprite(base, offset + 1, feature, tile);
745 if (!(wa & 4)) DrawWaterSprite(base, offset + 2, feature, tile);
746 if (!(wa & 8)) DrawWaterSprite(base, offset + 3, feature, tile);
747
748 /* right corner */
749 switch (wa & 0x03) {
750 case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
751 case 3: if (!IsWateredTile(TileAddXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
752 }
753
754 /* bottom corner */
755 switch (wa & 0x06) {
756 case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
757 case 6: if (!IsWateredTile(TileAddXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
758 }
759
760 /* left corner */
761 switch (wa & 0x0C) {
762 case 0: DrawWaterSprite(base, offset + 6, feature, tile); break;
763 case 12: if (!IsWateredTile(TileAddXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
764 }
765
766 /* upper corner */
767 switch (wa & 0x09) {
768 case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
769 case 9: if (!IsWateredTile(TileAddXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
770 }
771}
772
775{
776 DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
777}
778
780static void DrawCanalWater(TileIndex tile)
781{
782 SpriteID image = SPR_FLAT_WATER_TILE;
783 if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
784 /* First water slope sprite is flat water. */
785 image = GetCanalSprite(CF_WATERSLOPE, tile);
786 if (image == 0) image = SPR_FLAT_WATER_TILE;
787 }
788 DrawWaterSprite(image, 0, CF_WATERSLOPE, tile);
789
790 DrawWaterEdges(true, 0, tile);
791}
792
793#include "table/water_land.h"
794
804static void DrawWaterTileStruct(const TileInfo *ti, std::span<const DrawTileSeqStruct> seq, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
805{
806 /* Don't draw if buildings are invisible. */
807 if (IsInvisibilitySet(TO_BUILDINGS)) return;
808
809 for (const DrawTileSeqStruct &dtss : seq) {
810 uint tile_offs = offset + dtss.image.sprite;
811 if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
812 AddSortableSpriteToDraw(base + tile_offs, palette,
813 ti->x + dtss.delta_x, ti->y + dtss.delta_y,
814 dtss.size_x, dtss.size_y,
815 dtss.size_z, ti->z + dtss.delta_z,
817 }
818}
819
821static void DrawWaterLock(const TileInfo *ti)
822{
823 int part = GetLockPart(ti->tile);
824 const DrawTileSprites &dts = _lock_display_data[part][GetLockDirection(ti->tile)];
825
826 /* Draw ground sprite. */
827 SpriteID image = dts.ground.sprite;
828
829 SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
830 if (water_base == 0) {
831 /* Use default sprites. */
832 water_base = SPR_CANALS_BASE;
833 } else if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
834 /* NewGRF supplies a flat sprite as first sprite. */
835 if (image == SPR_FLAT_WATER_TILE) {
836 image = water_base;
837 } else {
838 image++;
839 }
840 }
841
842 if (image < 5) image += water_base;
843 DrawGroundSprite(image, PAL_NONE);
844
845 /* Draw structures. */
846 uint zoffs = 0;
847 SpriteID base = GetCanalSprite(CF_LOCKS, ti->tile);
848
849 if (base == 0) {
850 /* If no custom graphics, use defaults. */
851 base = SPR_LOCK_BASE;
852 uint8_t z_threshold = part == LOCK_PART_UPPER ? 8 : 0;
853 zoffs = ti->z > z_threshold ? 24 : 0;
854 }
855
856 DrawWaterTileStruct(ti, dts.GetSequence(), base, zoffs, PAL_NONE, CF_LOCKS);
857}
858
860static void DrawWaterDepot(const TileInfo *ti)
861{
862 DrawWaterClassGround(ti);
863 DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][GetShipDepotPart(ti->tile)].seq, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END);
864}
865
866static void DrawRiverWater(const TileInfo *ti)
867{
868 SpriteID image = SPR_FLAT_WATER_TILE;
869 uint offset = 0;
870 uint edges_offset = 0;
871
872 if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
873 image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
874 if (image == 0) {
875 switch (ti->tileh) {
876 case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
877 case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP; break;
878 case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP; break;
879 case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
880 default: image = SPR_FLAT_WATER_TILE; break;
881 }
882 } else {
883 /* Flag bit 0 indicates that the first sprite is flat water. */
884 offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;
885
886 switch (ti->tileh) {
887 case SLOPE_SE: edges_offset += 12; break;
888 case SLOPE_NE: offset += 1; edges_offset += 24; break;
889 case SLOPE_SW: offset += 2; edges_offset += 36; break;
890 case SLOPE_NW: offset += 3; edges_offset += 48; break;
891 default: offset = 0; break;
892 }
893
894 offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
895 }
896 }
897
898 DrawGroundSprite(image + offset, PAL_NONE);
899
900 /* Draw river edges if available. */
901 DrawWaterEdges(false, edges_offset, ti->tile);
902}
903
904void DrawShoreTile(Slope tileh)
905{
906 /* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
907 * This allows to calculate the proper sprite to display for this Slope */
908 static const uint8_t tileh_to_shoresprite[32] = {
909 0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
910 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0,
911 };
912
913 assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier.
914 assert(tileh != SLOPE_FLAT); // Shore is never flat
915
916 assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour
917
918 DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE);
919}
920
921void DrawWaterClassGround(const TileInfo *ti)
922{
923 switch (GetWaterClass(ti->tile)) {
924 case WATER_CLASS_SEA: DrawSeaWater(ti->tile); break;
925 case WATER_CLASS_CANAL: DrawCanalWater(ti->tile); break;
926 case WATER_CLASS_RIVER: DrawRiverWater(ti); break;
927 default: NOT_REACHED();
928 }
929}
930
931static void DrawTile_Water(TileInfo *ti)
932{
933 switch (GetWaterTileType(ti->tile)) {
934 case WATER_TILE_CLEAR:
935 DrawWaterClassGround(ti);
937 break;
938
939 case WATER_TILE_COAST: {
940 DrawShoreTile(ti->tileh);
942 break;
943 }
944
945 case WATER_TILE_LOCK:
946 DrawWaterLock(ti);
947 break;
948
949 case WATER_TILE_DEPOT:
950 DrawWaterDepot(ti);
951 break;
952 }
953}
954
955void DrawShipDepotSprite(int x, int y, Axis axis, DepotPart part)
956{
957 const DrawTileSprites &dts = _shipdepot_display_data[axis][part];
958
959 DrawSprite(dts.ground.sprite, dts.ground.pal, x, y);
960 DrawOrigTileSeqInGUI(x, y, &dts, COMPANY_SPRITE_COLOUR(_local_company));
961}
962
963
964static int GetSlopePixelZ_Water(TileIndex tile, uint x, uint y, bool)
965{
966 auto [tileh, z] = GetTilePixelSlope(tile);
967
968 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
969}
970
971static Foundation GetFoundation_Water(TileIndex, Slope)
972{
973 return FOUNDATION_NONE;
974}
975
976static void GetTileDesc_Water(TileIndex tile, TileDesc &td)
977{
978 switch (GetWaterTileType(tile)) {
979 case WATER_TILE_CLEAR:
980 switch (GetWaterClass(tile)) {
981 case WATER_CLASS_SEA: td.str = STR_LAI_WATER_DESCRIPTION_WATER; break;
982 case WATER_CLASS_CANAL: td.str = STR_LAI_WATER_DESCRIPTION_CANAL; break;
983 case WATER_CLASS_RIVER: td.str = STR_LAI_WATER_DESCRIPTION_RIVER; break;
984 default: NOT_REACHED();
985 }
986 break;
987 case WATER_TILE_COAST: td.str = STR_LAI_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break;
988 case WATER_TILE_LOCK : td.str = STR_LAI_WATER_DESCRIPTION_LOCK; break;
989 case WATER_TILE_DEPOT:
990 td.str = STR_LAI_WATER_DESCRIPTION_SHIP_DEPOT;
991 td.build_date = Depot::GetByTile(tile)->build_date;
992 break;
993 default: NOT_REACHED();
994 }
995
996 td.owner[0] = GetTileOwner(tile);
997}
998
1004static void FloodVehicle(Vehicle *v)
1005{
1006 uint victims = v->Crash(true);
1007
1008 AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
1009 Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
1010 AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_FLOOD_VEHICLE, victims), NewsType::Accident, v->tile);
1012 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
1013}
1014
1021static Vehicle *FloodVehicleProc(Vehicle *v, void *data)
1022{
1023 if (v->vehstatus.Test(VehState::Crashed)) return nullptr;
1024
1025 switch (v->type) {
1026 default: break;
1027
1028 case VEH_AIRCRAFT: {
1029 if (!IsAirportTile(v->tile) || GetTileMaxZ(v->tile) != 0) break;
1030 if (v->subtype == AIR_SHADOW) break;
1031
1032 /* We compare v->z_pos against delta_z + 1 because the shadow
1033 * is at delta_z and the actual aircraft at delta_z + 1. */
1034 const Station *st = Station::GetByTile(v->tile);
1035 const AirportFTAClass *airport = st->airport.GetFTA();
1036 if (v->z_pos != airport->delta_z + 1) break;
1037
1038 FloodVehicle(v);
1039 break;
1040 }
1041
1042 case VEH_TRAIN:
1043 case VEH_ROAD: {
1044 int z = *(int*)data;
1045 if (v->z_pos > z) break;
1046 FloodVehicle(v->First());
1047 break;
1048 }
1049 }
1050
1051 return nullptr;
1052}
1053
1059static void FloodVehicles(TileIndex tile)
1060{
1061 int z = 0;
1062
1063 if (IsAirportTile(tile)) {
1064 const Station *st = Station::GetByTile(tile);
1065 for (TileIndex airport_tile : st->airport) {
1066 if (st->TileBelongsToAirport(airport_tile)) FindVehicleOnPos(airport_tile, &z, &FloodVehicleProc);
1067 }
1068
1069 /* No vehicle could be flooded on this airport anymore */
1070 return;
1071 }
1072
1073 if (!IsBridgeTile(tile)) {
1075 return;
1076 }
1077
1078 TileIndex end = GetOtherBridgeEnd(tile);
1079 z = GetBridgePixelHeight(tile);
1080
1083}
1084
1091{
1092 /* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
1093 * FLOOD_DRYUP: coast with more than one corner raised, coast with rail-track, coast with trees
1094 * FLOOD_PASSIVE: (not used)
1095 * FLOOD_NONE: canals, rivers, everything else
1096 */
1097 switch (GetTileType(tile)) {
1098 case MP_WATER:
1099 if (IsCoast(tile)) {
1100 Slope tileh = GetTileSlope(tile);
1102 }
1103 [[fallthrough]];
1104 case MP_STATION:
1105 case MP_INDUSTRY:
1106 case MP_OBJECT:
1108
1109 case MP_RAILWAY:
1110 if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
1112 }
1113 return FLOOD_NONE;
1114
1115 case MP_TREES:
1117
1118 case MP_VOID:
1119 return FLOOD_ACTIVE;
1120
1121 default:
1122 return FLOOD_NONE;
1123 }
1124}
1125
1129static void DoFloodTile(TileIndex target)
1130{
1131 assert(!IsTileType(target, MP_WATER));
1132
1133 bool flooded = false; // Will be set to true if something is changed.
1134
1136
1137 Slope tileh = GetTileSlope(target);
1138 if (tileh != SLOPE_FLAT) {
1139 /* make coast.. */
1140 switch (GetTileType(target)) {
1141 case MP_RAILWAY: {
1142 if (!IsPlainRail(target)) break;
1143 FloodVehicles(target);
1144 flooded = FloodHalftile(target);
1145 break;
1146 }
1147
1148 case MP_TREES:
1149 if (!IsSlopeWithOneCornerRaised(tileh)) {
1151 MarkTileDirtyByTile(target);
1152 flooded = true;
1153 break;
1154 }
1155 [[fallthrough]];
1156
1157 case MP_CLEAR:
1159 MakeShore(target);
1160 MarkTileDirtyByTile(target);
1161 flooded = true;
1162 }
1163 break;
1164
1165 default:
1166 break;
1167 }
1168 } else {
1169 /* Flood vehicles */
1170 FloodVehicles(target);
1171
1172 /* flood flat tile */
1174 MakeSea(target);
1175 MarkTileDirtyByTile(target);
1176 flooded = true;
1177 }
1178 }
1179
1180 if (flooded) {
1181 /* Mark surrounding canal tiles dirty too to avoid glitches */
1183
1184 /* update signals if needed */
1186
1187 if (IsPossibleDockingTile(target)) CheckForDockingTile(target);
1188 InvalidateWaterRegion(target);
1189 }
1190
1191 cur_company.Restore();
1192}
1193
1197static void DoDryUp(TileIndex tile)
1198{
1200
1201 switch (GetTileType(tile)) {
1202 case MP_RAILWAY:
1203 assert(IsPlainRail(tile));
1204 assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
1205
1206 RailGroundType new_ground;
1207 switch (GetTrackBits(tile)) {
1208 case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
1209 case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
1210 case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break;
1211 case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
1212 default: NOT_REACHED();
1213 }
1214 SetRailGroundType(tile, new_ground);
1215 MarkTileDirtyByTile(tile);
1216 break;
1217
1218 case MP_TREES:
1220 MarkTileDirtyByTile(tile);
1221 break;
1222
1223 case MP_WATER:
1224 assert(IsCoast(tile));
1225
1227 MakeClear(tile, CLEAR_GRASS, 3);
1228 MarkTileDirtyByTile(tile);
1229 }
1230 break;
1231
1232 default: NOT_REACHED();
1233 }
1234
1235 cur_company.Restore();
1236}
1237
1245{
1246 if (IsTileType(tile, MP_WATER)) {
1247 AmbientSoundEffect(tile);
1248 if (IsNonFloodingWaterTile(tile)) return;
1249 }
1250
1251 switch (GetFloodingBehaviour(tile)) {
1252 case FLOOD_ACTIVE: {
1253 bool continue_flooding = false;
1254 for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
1256 /* Contrary to drying up, flooding does not consider MP_VOID tiles. */
1257 if (!IsValidTile(dest)) continue;
1258 /* do not try to flood water tiles - increases performance a lot */
1259 if (IsTileType(dest, MP_WATER)) continue;
1260
1261 /* Buoys and docks cannot be flooded, and when removed turn into flooding water. */
1262 if (IsTileType(dest, MP_STATION) && (IsBuoy(dest) || IsDock(dest))) continue;
1263
1264 /* This neighbour tile might be floodable later if the tile is cleared, so allow flooding to continue. */
1265 continue_flooding = true;
1266
1267 /* TREE_GROUND_SHORE is the sign of a previous flood. */
1268 if (IsTileType(dest, MP_TREES) && GetTreeGround(dest) == TREE_GROUND_SHORE) continue;
1269
1270 auto [slope_dest, z_dest] = GetFoundationSlope(dest);
1271 if (z_dest > 0) continue;
1272
1273 if (!HasBit(_flood_from_dirs[slope_dest & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP], ReverseDir(dir))) continue;
1274
1275 DoFloodTile(dest);
1276 }
1277 if (!continue_flooding && IsTileType(tile, MP_WATER)) SetNonFloodingWaterTile(tile, true);
1278 break;
1279 }
1280
1281 case FLOOD_DRYUP: {
1282 Slope slope_here = std::get<0>(GetFoundationSlope(tile)) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
1283 for (Direction dir : SetBitIterator<Direction>(_flood_from_dirs[slope_here])) {
1285 /* Contrary to flooding, drying up does consider MP_VOID tiles. */
1286 if (dest == INVALID_TILE) continue;
1287
1288 FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
1289 if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
1290 }
1291 DoDryUp(tile);
1292 break;
1293 }
1294
1295 default: return;
1296 }
1297}
1298
1299void ConvertGroundTilesIntoWaterTiles()
1300{
1301 for (const auto tile : Map::Iterate()) {
1302 auto [slope, z] = GetTileSlopeZ(tile);
1303 if (IsTileType(tile, MP_CLEAR) && z == 0) {
1304 /* Make both water for tiles at level 0
1305 * and make shore, as that looks much better
1306 * during the generation. */
1307 switch (slope) {
1308 case SLOPE_FLAT:
1309 MakeSea(tile);
1310 break;
1311
1312 case SLOPE_N:
1313 case SLOPE_E:
1314 case SLOPE_S:
1315 case SLOPE_W:
1316 MakeShore(tile);
1317 break;
1318
1319 default:
1321 TileIndex dest = TileAddByDir(tile, dir);
1322 Slope slope_dest = GetTileSlope(dest) & ~SLOPE_STEEP;
1323 if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest) || IsTileType(dest, MP_VOID)) {
1324 MakeShore(tile);
1325 break;
1326 }
1327 }
1328 break;
1329 }
1330 }
1331 }
1332}
1333
1334static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint, DiagDirection)
1335{
1338
1339 TrackBits ts;
1340
1341 if (mode != TRANSPORT_WATER) return 0;
1342
1343 switch (GetWaterTileType(tile)) {
1344 case WATER_TILE_CLEAR: ts = IsTileFlat(tile) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
1345 case WATER_TILE_COAST: ts = coast_tracks[GetTileSlope(tile) & 0xF]; break;
1347 case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
1348 default: return 0;
1349 }
1350 if (TileX(tile) == 0) {
1351 /* NE border: remove tracks that connects NE tile edge */
1353 }
1354 if (TileY(tile) == 0) {
1355 /* NW border: remove tracks that connects NW tile edge */
1357 }
1359}
1360
1361static bool ClickTile_Water(TileIndex tile)
1362{
1363 if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
1365 return true;
1366 }
1367 return false;
1368}
1369
1370static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
1371{
1372 if (!IsTileOwner(tile, old_owner)) return;
1373
1374 bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE;
1375
1376 /* No need to dirty company windows here, we'll redraw the whole screen anyway. */
1377 if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1378 if (new_owner != INVALID_OWNER) {
1379 if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1380 /* Only subtract from the old owner here if the new owner is valid,
1381 * otherwise we clear ship depots and canal water below. */
1382 if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) {
1383 Company::Get(old_owner)->infrastructure.water--;
1384 Company::Get(new_owner)->infrastructure.water++;
1385 }
1386 if (IsShipDepot(tile)) {
1387 Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
1388 Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
1389 }
1390
1391 SetTileOwner(tile, new_owner);
1392 return;
1393 }
1394
1395 /* Remove depot */
1397
1398 /* Set owner of canals and locks ... and also canal under dock there was before.
1399 * Check if the new owner after removing depot isn't OWNER_WATER. */
1400 if (IsTileOwner(tile, old_owner)) {
1401 if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
1402 SetTileOwner(tile, OWNER_NONE);
1403 }
1404}
1405
1406static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *, TileIndex, int, int)
1407{
1408 return VETSB_CONTINUE;
1409}
1410
1411static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlags flags, int, Slope)
1412{
1413 /* Canals can't be terraformed */
1414 if (IsWaterTile(tile) && IsCanal(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
1415
1416 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
1417}
1418
1419
1420extern const TileTypeProcs _tile_type_water_procs = {
1421 DrawTile_Water, // draw_tile_proc
1422 GetSlopePixelZ_Water, // get_slope_z_proc
1423 ClearTile_Water, // clear_tile_proc
1424 nullptr, // add_accepted_cargo_proc
1425 GetTileDesc_Water, // get_tile_desc_proc
1426 GetTileTrackStatus_Water, // get_tile_track_status_proc
1427 ClickTile_Water, // click_tile_proc
1428 nullptr, // animate_tile_proc
1429 TileLoop_Water, // tile_loop_proc
1430 ChangeTileOwner_Water, // change_tile_owner_proc
1431 nullptr, // add_produced_cargo_proc
1432 VehicleEnter_Water, // vehicle_enter_tile_proc
1433 GetFoundation_Water, // get_foundation_proc
1434 TerraformTile_Water, // terraform_tile_proc
1435};
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.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
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:243
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?
Enum-as-bit-set wrapper.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
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
Map accessors for 'clear' tiles.
@ CLEAR_GRASS
0-3
Definition clear_map.h:20
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition clear_map.h:247
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Execute
execute the given command
@ Bankrupt
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ NoWater
don't allow building on water
@ Auto
don't allow building on structures
@ 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.
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.
Axis
Allow incrementing of DiagDirDiff variables.
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.
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.
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:989
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:86
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 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.).
@ Random
Randomise borders.
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition map.cpp:243
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:469
TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
Definition map_func.h:514
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition map_func.h:598
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition map_func.h:439
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:554
TileIndexDiffC TileIndexDiffCByDir(Direction dir)
Returns the TileIndexDiffC offset from a Direction.
Definition map_func.h:496
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition map_func.h:583
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:569
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.
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:762
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:485
@ RAIL_GROUND_FENCE_HORIZ1
Grass with a fence at the southern side.
Definition rail_map.h:496
@ RAIL_GROUND_FENCE_VERT1
Grass with a fence at the eastern side.
Definition rail_map.h:494
@ RAIL_GROUND_FENCE_HORIZ2
Grass with a fence at the northern side.
Definition rail_map.h:497
@ RAIL_GROUND_WATER
Grass with a fence and shore or water on the free halftile.
Definition rail_map.h:499
@ RAIL_GROUND_FENCE_VERT2
Grass with a fence at the western side.
Definition rail_map.h:495
static debug_inline bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
Definition rail_map.h:49
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:58
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:57
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:48
@ SLOPE_W
the west corner of the tile is raised
Definition slope_type.h:50
@ SLOPE_HALFTILE_MASK
three bits used for halftile slopes
Definition slope_type.h:72
@ SLOPE_NS
north and south corner are raised
Definition slope_type.h:60
@ SLOPE_E
the east corner of the tile is raised
Definition slope_type.h:52
@ SLOPE_S
the south corner of the tile is raised
Definition slope_type.h:51
@ SLOPE_N
the north corner of the tile is raised
Definition slope_type.h:53
@ SLOPE_SW
south and west corner are raised
Definition slope_type.h:56
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
@ SLOPE_NE
north and east corner are raised
Definition slope_type.h:58
@ SLOPE_SE
south and east corner are raised
Definition slope_type.h:57
@ SLOPE_NW
north and west corner are raised
Definition slope_type.h:55
@ SLOPE_EW
east and west corner are raised
Definition slope_type.h:59
@ SLOPE_STEEP
indicates the slope is steep
Definition slope_type.h:54
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:94
Functions related to sound.
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition sound_type.h:63
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:121
static const SpriteID SPR_SHORE_BASE
shore tiles - action 05-0D
Definition sprites.h:224
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.
SoundSettings sound
sound effect settings
uint32_t water
Count of company owned track bits for canals.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
bool freeform_edges
allow terraforming the tiles at the map edges
TimerGameCalendar::Date build_date
Date of construction.
Definition depot_base.h:26
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:25
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:46
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:47
ConstructionSettings construction
construction of things in-game
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:235
Station * neutral_station
Associated neutral station.
Definition industry.h:93
Size related data of the map.
Definition map_func.h:206
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:305
static debug_inline uint Size()
Get the size of the map.
Definition map_func.h:287
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:296
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 Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Iterable ensemble of each set bit in a value.
bool disaster
Play disaster and accident sounds.
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:52
StringID str
Description of the tile.
Definition tile_cmd.h:53
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:57
std::array< Owner, 4 > owner
Name of the owner(s)
Definition tile_cmd.h:55
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
Tile information, used while rendering the tile.
Definition tile_cmd.h:43
int z
Height.
Definition tile_cmd.h:48
int x
X position of the tile in unit coordinates.
Definition tile_cmd.h:44
Slope tileh
Slope of the tile.
Definition tile_cmd.h:46
TileIndex tile
Tile index.
Definition tile_cmd.h:47
int y
Y position of the tile in unit coordinates.
Definition tile_cmd.h:45
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:159
Vehicle data structure.
int32_t z_pos
z coordinate.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition vehicle.cpp:280
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?
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition tile_cmd.h:21
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition tile_cmd.h:35
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition tile_map.cpp:95
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:136
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
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
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
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
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 debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
@ TROPICZONE_DESERT
Tile is desert.
Definition tile_type.h:78
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition tile_type.h:77
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
@ MP_TREES
Tile got trees.
Definition tile_type.h:52
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:48
@ MP_WATER
Water tile.
Definition tile_type.h:54
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
@ MP_INDUSTRY
Part of an industry.
Definition tile_type.h:56
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition tile_type.h:55
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
Definition of the game-calendar-timer.
Base of the town class.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition town.h:246
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:99
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
@ TREE_GROUND_GRASS
normal grass
Definition tree_map.h:53
@ TREE_GROUND_SHORE
shore
Definition tree_map.h:56
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:543
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition vehicle.cpp:502
@ 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 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:673
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:589
Functions related to (drawing on) viewports.
Functions related to water (management)
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 radius to create non-desert around a river tile.
Definition water.h:42
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 bool RiverModifyDesertZone(TileIndex tile, void *)
Callback to create non-desert around a river 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.
void ClearNeighbourNonFloodingStates(TileIndex tile)
Clear non-flooding state of the tiles around a tile.
Definition water_cmd.cpp:97
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 Vehicle * FloodVehicleProc(Vehicle *v, void *data)
Flood a vehicle if we are allowed to flood it, i.e.
static void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
Marks tile dirty if it is a canal or river tile.
Definition water_cmd.cpp:75
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 const uint8_t _flood_from_dirs[]
Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
Definition water_cmd.cpp:51
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:381
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
Definition water_map.h:350
TileIndex GetShipDepotNorthTile(Tile t)
Get the most northern tile of a ship depot.
Definition water_map.h:289
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:506
DepotPart GetShipDepotPart(Tile t)
Get the part of a ship depot.
Definition water_map.h:255
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:136
bool IsShipDepot(Tile t)
Is it a water tile with a ship depot on it?
Definition water_map.h:222
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:180
DiagDirection GetLockDirection(Tile t)
Get the direction of the water lock.
Definition water_map.h:314
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition water_map.h:39
@ WATER_CLASS_SEA
Sea.
Definition water_map.h:40
@ WATER_CLASS_CANAL
Canal.
Definition water_map.h:41
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition water_map.h:43
@ WATER_CLASS_RIVER
River.
Definition water_map.h:42
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition water_map.h:101
bool IsCanal(Tile t)
Is it a canal tile?
Definition water_map.h:169
bool IsCoast(Tile t)
Is it a coast tile?
Definition water_map.h:201
void MakeRiver(Tile t, uint8_t random_bits)
Make a river tile.
Definition water_map.h:432
WaterTileType GetWaterTileType(Tile t)
Get the water tile type of a tile.
Definition water_map.h:78
void SetNonFloodingWaterTile(Tile t, bool b)
Set the non-flooding water tile state of a tile.
Definition water_map.h:524
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:112
void MakeCanal(Tile t, Owner o, uint8_t random_bits)
Make a canal tile.
Definition water_map.h:443
uint8_t GetLockPart(Tile t)
Get the part of a lock.
Definition water_map.h:326
TileIndex GetOtherShipDepotTile(Tile t)
Get the other tile of the ship depot.
Definition water_map.h:278
DepotPart
Sections of the water depot.
Definition water_map.h:58
@ DEPOT_PART_NORTH
Northern part of a depot.
Definition water_map.h:59
@ DEPOT_PART_SOUTH
Southern part of a depot.
Definition water_map.h:60
@ WATER_TILE_COAST
Coast.
Definition water_map.h:33
@ WATER_TILE_LOCK
Water lock.
Definition water_map.h:34
@ WATER_TILE_DEPOT
Water Depot.
Definition water_map.h:35
@ WATER_TILE_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:533
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition water_map.h:361
@ LOCK_PART_UPPER
Upper part of a lock.
Definition water_map.h:68
@ LOCK_PART_MIDDLE
Middle part of a lock.
Definition water_map.h:66
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition water_map.h:190
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition water_map.h:303
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:458
void MakeSea(Tile t)
Make a sea tile.
Definition water_map.h:422
Axis GetShipDepotAxis(Tile t)
Get the axis of the ship depot.
Definition water_map.h:243
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.