OpenTTD Source  13.0-beta1
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"
35 #include "date_func.h"
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"
42 
43 #include "table/strings.h"
44 
45 #include "safeguards.h"
46 
50 static const uint8 _flood_from_dirs[] = {
51  (1 << DIR_NW) | (1 << DIR_SW) | (1 << DIR_SE) | (1 << DIR_NE), // SLOPE_FLAT
52  (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_W
53  (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_S
54  (1 << DIR_NE), // SLOPE_SW
55  (1 << DIR_NW) | (1 << DIR_SW), // SLOPE_E
56  0, // SLOPE_EW
57  (1 << DIR_NW), // SLOPE_SE
58  (1 << DIR_N ) | (1 << DIR_NW) | (1 << DIR_NE), // SLOPE_WSE, SLOPE_STEEP_S
59  (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_N
60  (1 << DIR_SE), // SLOPE_NW
61  0, // SLOPE_NS
62  (1 << DIR_E ) | (1 << DIR_NE) | (1 << DIR_SE), // SLOPE_NWS, SLOPE_STEEP_W
63  (1 << DIR_SW), // SLOPE_NE
64  (1 << DIR_S ) | (1 << DIR_SW) | (1 << DIR_SE), // SLOPE_ENW, SLOPE_STEEP_N
65  (1 << DIR_W ) | (1 << DIR_SW) | (1 << DIR_NW), // SLOPE_SEN, SLOPE_STEEP_E
66 };
67 
74 static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
75 {
76  if (IsValidTile(tile) && IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
77 }
78 
86 {
87  for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
89  }
90 }
91 
92 
101 {
102  if (!IsValidAxis(axis)) return CMD_ERROR;
103  TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
104 
105  if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
106  return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
107  }
108 
109  if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
110 
111  if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
112  /* Prevent depots on rapids */
113  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
114  }
115 
116  if (!Depot::CanAllocateItem()) return CMD_ERROR;
117 
118  WaterClass wc1 = GetWaterClass(tile);
119  WaterClass wc2 = GetWaterClass(tile2);
120  CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
121 
122  bool add_cost = !IsWaterTile(tile);
124  if (ret.Failed()) return ret;
125  if (add_cost) {
126  cost.AddCost(ret);
127  }
128  add_cost = !IsWaterTile(tile2);
129  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_AUTO, tile2);
130  if (ret.Failed()) return ret;
131  if (add_cost) {
132  cost.AddCost(ret);
133  }
134 
135  if (flags & DC_EXEC) {
136  Depot *depot = new Depot(tile);
137  depot->build_date = _date;
138 
139  if (wc1 == WATER_CLASS_CANAL || wc2 == WATER_CLASS_CANAL) {
140  /* Update infrastructure counts after the unconditional clear earlier. */
141  Company::Get(_current_company)->infrastructure.water += wc1 == WATER_CLASS_CANAL && wc2 == WATER_CLASS_CANAL ? 2 : 1;
142  }
143  Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR;
145 
146  MakeShipDepot(tile, _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1);
147  MakeShipDepot(tile2, _current_company, depot->index, DEPOT_PART_SOUTH, axis, wc2);
148  CheckForDockingTile(tile);
149  CheckForDockingTile(tile2);
150  MarkTileDirtyByTile(tile);
151  MarkTileDirtyByTile(tile2);
152  MakeDefaultName(depot);
153  }
154 
155  return cost;
156 }
157 
158 bool IsPossibleDockingTile(TileIndex t)
159 {
160  assert(IsValidTile(t));
161  switch (GetTileType(t)) {
162  case MP_WATER:
163  if (IsLock(t) && GetLockPart(t) == LOCK_PART_MIDDLE) return false;
164  FALLTHROUGH;
165  case MP_RAILWAY:
166  case MP_STATION:
167  case MP_TUNNELBRIDGE:
169 
170  default:
171  return false;
172  }
173 }
174 
181 {
182  for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
183  TileIndex tile = t + TileOffsByDiagDir(d);
184  if (!IsValidTile(tile)) continue;
185 
186  if (IsDockTile(tile) && IsValidDockingDirectionForDock(tile, d)) {
188  SetDockingTile(t, true);
189  }
190  if (IsTileType(tile, MP_INDUSTRY)) {
192  if (st != nullptr) {
193  st->docking_station.Add(t);
194  SetDockingTile(t, true);
195  }
196  }
197  if (IsTileType(tile, MP_STATION) && IsOilRig(tile)) {
199  SetDockingTile(t, true);
200  }
201  }
202 }
203 
204 void MakeWaterKeepingClass(TileIndex tile, Owner o)
205 {
206  WaterClass wc = GetWaterClass(tile);
207 
208  /* Autoslope might turn an originally canal or river tile into land */
209  int z;
210  Slope slope = GetTileSlope(tile, &z);
211 
212  if (slope != SLOPE_FLAT) {
213  if (wc == WATER_CLASS_CANAL) {
214  /* If we clear the canal, we have to remove it from the infrastructure count as well. */
216  if (c != nullptr) {
217  c->infrastructure.water--;
219  }
220  /* Sloped canals are locks and no natural water remains whatever the slope direction */
221  wc = WATER_CLASS_INVALID;
222  }
223 
224  /* Only river water should be restored on appropriate slopes. Other water would be invalid on slopes */
226  wc = WATER_CLASS_INVALID;
227  }
228  }
229 
230  if (wc == WATER_CLASS_SEA && z > 0) {
231  /* Update company infrastructure count. */
233  if (c != nullptr) {
234  c->infrastructure.water++;
236  }
237 
238  wc = WATER_CLASS_CANAL;
239  }
240 
241  /* Zero map array and terminate animation */
242  DoClearSquare(tile);
243 
244  /* Maybe change to water */
245  switch (wc) {
246  case WATER_CLASS_SEA: MakeSea(tile); break;
247  case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
248  case WATER_CLASS_RIVER: MakeRiver(tile, Random()); break;
249  default: break;
250  }
251 
252  if (wc != WATER_CLASS_INVALID) CheckForDockingTile(tile);
253  MarkTileDirtyByTile(tile);
254 }
255 
256 static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
257 {
258  if (!IsShipDepot(tile)) return CMD_ERROR;
259 
260  CommandCost ret = CheckTileOwnership(tile);
261  if (ret.Failed()) return ret;
262 
263  TileIndex tile2 = GetOtherShipDepotTile(tile);
264 
265  /* do not check for ship on tile when company goes bankrupt */
266  if (!(flags & DC_BANKRUPT)) {
268  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
269  if (ret.Failed()) return ret;
270  }
271 
272  if (flags & DC_EXEC) {
273  delete Depot::GetByTile(tile);
274 
276  if (c != nullptr) {
279  }
280 
281  MakeWaterKeepingClass(tile, GetTileOwner(tile));
282  MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
283  }
284 
285  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
286 }
287 
296 {
298 
299  int delta = TileOffsByDiagDir(dir);
301  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
302  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
303  if (ret.Failed()) return ret;
304 
305  /* middle tile */
306  WaterClass wc_middle = HasTileWaterGround(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
307  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
308  if (ret.Failed()) return ret;
309  cost.AddCost(ret);
310 
311  /* lower tile */
312  if (!IsWaterTile(tile - delta)) {
313  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta);
314  if (ret.Failed()) return ret;
315  cost.AddCost(ret);
316  cost.AddCost(_price[PR_BUILD_CANAL]);
317  }
318  if (!IsTileFlat(tile - delta)) {
319  return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
320  }
321  WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
322 
323  /* upper tile */
324  if (!IsWaterTile(tile + delta)) {
325  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta);
326  if (ret.Failed()) return ret;
327  cost.AddCost(ret);
328  cost.AddCost(_price[PR_BUILD_CANAL]);
329  }
330  if (!IsTileFlat(tile + delta)) {
331  return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
332  }
333  WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
334 
335  if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) {
336  return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
337  }
338 
339  if (flags & DC_EXEC) {
340  /* Update company infrastructure counts. */
342  if (c != nullptr) {
343  /* Counts for the water. */
344  if (!IsWaterTile(tile - delta)) c->infrastructure.water++;
345  if (!IsWaterTile(tile + delta)) c->infrastructure.water++;
346  /* Count for the lock itself. */
347  c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles.
349  }
350 
351  MakeLock(tile, _current_company, dir, wc_lower, wc_upper, wc_middle);
352  CheckForDockingTile(tile - delta);
353  CheckForDockingTile(tile + delta);
354  MarkTileDirtyByTile(tile);
355  MarkTileDirtyByTile(tile - delta);
356  MarkTileDirtyByTile(tile + delta);
357  MarkCanalsAndRiversAroundDirty(tile - delta);
358  MarkCanalsAndRiversAroundDirty(tile + delta);
359  }
360  cost.AddCost(_price[PR_BUILD_LOCK]);
361 
362  return cost;
363 }
364 
372 {
373  if (GetTileOwner(tile) != OWNER_NONE) {
374  CommandCost ret = CheckTileOwnership(tile);
375  if (ret.Failed()) return ret;
376  }
377 
379 
380  /* make sure no vehicle is on the tile. */
382  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
383  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
384  if (ret.Failed()) return ret;
385 
386  if (flags & DC_EXEC) {
387  /* Remove middle part from company infrastructure count. */
389  if (c != nullptr) {
390  c->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // three parts of the lock.
392  }
393 
394  if (GetWaterClass(tile) == WATER_CLASS_RIVER) {
395  MakeRiver(tile, Random());
396  } else {
397  DoClearSquare(tile);
398  }
399  MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
400  MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
402  MarkCanalsAndRiversAroundDirty(tile - delta);
403  MarkCanalsAndRiversAroundDirty(tile + delta);
404  }
405 
406  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
407 }
408 
416 {
418  if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
419 
420  return DoBuildLock(tile, dir, flags);
421 }
422 
425 {
427  return false;
428 }
429 
439 CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
440 {
441  if (start_tile >= MapSize() || !IsValidWaterClass(wc)) return CMD_ERROR;
442 
443  /* Outside of the editor you can only build canals, not oceans */
444  if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
445 
446  /* Outside the editor you can only drag canals, and not areas */
447  if (_game_mode != GM_EDITOR) {
448  TileArea ta(tile, start_tile);
449  if (ta.w != 1 && ta.h != 1) return CMD_ERROR;
450  }
451 
453 
454  std::unique_ptr<TileIterator> iter;
455  if (diagonal) {
456  iter = std::make_unique<DiagonalTileIterator>(tile, start_tile);
457  } else {
458  iter = std::make_unique<OrthogonalTileIterator>(tile, start_tile);
459  }
460 
461  for (; *iter != INVALID_TILE; ++(*iter)) {
462  TileIndex current_tile = *iter;
463  CommandCost ret;
464 
465  Slope slope = GetTileSlope(current_tile);
466  if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
467  return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
468  }
469 
470  bool water = IsWaterTile(current_tile);
471 
472  /* Outside the editor, prevent building canals over your own or OWNER_NONE owned canals */
473  if (water && IsCanal(current_tile) && _game_mode != GM_EDITOR && (IsTileOwner(current_tile, _current_company) || IsTileOwner(current_tile, OWNER_NONE))) continue;
474 
475  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
476  if (ret.Failed()) return ret;
477 
478  if (!water) cost.AddCost(ret);
479 
480  if (flags & DC_EXEC) {
481  switch (wc) {
482  case WATER_CLASS_RIVER:
483  MakeRiver(current_tile, Random());
484  if (_game_mode == GM_EDITOR) {
485  TileIndex tile2 = current_tile;
487  }
488  break;
489 
490  case WATER_CLASS_SEA:
491  if (TileHeight(current_tile) == 0) {
492  MakeSea(current_tile);
493  break;
494  }
495  FALLTHROUGH;
496 
497  default:
498  /* If we overbuild a water object with a canal, don't update the infrastructure total. */
499  bool is_existing_canal = IsTileType(current_tile, MP_WATER) && IsCanal(current_tile);
500  if (Company::IsValidID(_current_company) && !is_existing_canal) {
501  Company::Get(_current_company)->infrastructure.water++;
503  }
504 
505  MakeCanal(current_tile, _current_company, Random());
506  break;
507  }
508  MarkTileDirtyByTile(current_tile);
509  MarkCanalsAndRiversAroundDirty(current_tile);
510  CheckForDockingTile(current_tile);
511  }
512 
513  cost.AddCost(_price[PR_BUILD_CANAL]);
514  }
515 
516  if (cost.GetCost() == 0) {
517  return_cmd_error(STR_ERROR_ALREADY_BUILT);
518  } else {
519  return cost;
520  }
521 }
522 
523 static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
524 {
525  switch (GetWaterTileType(tile)) {
526  case WATER_TILE_CLEAR: {
527  if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
528 
529  Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER];
530  /* Make sure freeform edges are allowed or it's not an edge tile. */
531  if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
532  !IsInsideMM(TileY(tile), 1, MapMaxY() - 1))) {
533  return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
534  }
535 
536  /* Make sure no vehicle is on the tile */
538  if (ret.Failed()) return ret;
539 
540  Owner owner = GetTileOwner(tile);
541  if (owner != OWNER_WATER && owner != OWNER_NONE) {
542  CommandCost ret = CheckTileOwnership(tile);
543  if (ret.Failed()) return ret;
544  }
545 
546  if (flags & DC_EXEC) {
547  if (IsCanal(tile) && Company::IsValidID(owner)) {
548  Company::Get(owner)->infrastructure.water--;
550  }
551  DoClearSquare(tile);
553  }
554 
555  return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
556  }
557 
558  case WATER_TILE_COAST: {
559  Slope slope = GetTileSlope(tile);
560 
561  /* Make sure no vehicle is on the tile */
563  if (ret.Failed()) return ret;
564 
565  if (flags & DC_EXEC) {
566  DoClearSquare(tile);
568  }
569  if (IsSlopeWithOneCornerRaised(slope)) {
570  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
571  } else {
572  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]);
573  }
574  }
575 
576  case WATER_TILE_LOCK: {
577  static const TileIndexDiffC _lock_tomiddle_offs[][DIAGDIR_END] = {
578  /* NE SE SW NW */
579  { { 0, 0}, {0, 0}, { 0, 0}, {0, 0} }, // LOCK_PART_MIDDLE
580  { {-1, 0}, {0, 1}, { 1, 0}, {0, -1} }, // LOCK_PART_LOWER
581  { { 1, 0}, {0, -1}, {-1, 0}, {0, 1} }, // LOCK_PART_UPPER
582  };
583 
584  if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
585  if (_current_company == OWNER_WATER) return CMD_ERROR;
586  /* move to the middle tile.. */
587  return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetLockPart(tile)][GetLockDirection(tile)]), flags);
588  }
589 
590  case WATER_TILE_DEPOT:
591  if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
592  return RemoveShipDepot(tile, flags);
593 
594  default:
595  NOT_REACHED();
596  }
597 }
598 
608 {
609  switch (GetTileType(tile)) {
610  case MP_WATER:
611  switch (GetWaterTileType(tile)) {
612  default: NOT_REACHED();
613  case WATER_TILE_DEPOT: case WATER_TILE_CLEAR: return true;
615 
616  case WATER_TILE_COAST:
617  switch (GetTileSlope(tile)) {
618  case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
619  case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
620  case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
621  case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
622  default: return false;
623  }
624  }
625 
626  case MP_RAILWAY:
627  if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
628  assert(IsPlainRail(tile));
629  switch (GetTileSlope(tile)) {
630  case SLOPE_W: return (from == DIR_SE) || (from == DIR_E) || (from == DIR_NE);
631  case SLOPE_S: return (from == DIR_NE) || (from == DIR_N) || (from == DIR_NW);
632  case SLOPE_E: return (from == DIR_NW) || (from == DIR_W) || (from == DIR_SW);
633  case SLOPE_N: return (from == DIR_SW) || (from == DIR_S) || (from == DIR_SE);
634  default: return false;
635  }
636  }
637  return false;
638 
639  case MP_STATION:
640  if (IsOilRig(tile)) {
641  /* Do not draw waterborders inside of industries.
642  * Note: There is no easy way to detect the industry of an oilrig tile. */
643  TileIndex src_tile = tile + TileOffsByDir(from);
644  if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
645  (IsTileType(src_tile, MP_INDUSTRY))) return true;
646 
647  return IsTileOnWater(tile);
648  }
649  return (IsDock(tile) && IsTileFlat(tile)) || IsBuoy(tile);
650 
651  case MP_INDUSTRY: {
652  /* Do not draw waterborders inside of industries.
653  * Note: There is no easy way to detect the industry of an oilrig tile. */
654  TileIndex src_tile = tile + TileOffsByDir(from);
655  if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
656  (IsTileType(src_tile, MP_INDUSTRY) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
657 
658  return IsTileOnWater(tile);
659  }
660 
661  case MP_OBJECT: return IsTileOnWater(tile);
662 
664 
665  case MP_VOID: return true; // consider map border as water, esp. for rivers
666 
667  default: return false;
668  }
669 }
670 
678 static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
679 {
680  if (base != SPR_FLAT_WATER_TILE) {
681  /* Only call offset callback if the sprite is NewGRF-provided. */
682  offset = GetCanalSpriteOffset(feature, tile, offset);
683  }
684  DrawGroundSprite(base + offset, PAL_NONE);
685 }
686 
693 static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
694 {
695  CanalFeature feature;
696  SpriteID base = 0;
697  if (canal) {
698  feature = CF_DIKES;
699  base = GetCanalSprite(CF_DIKES, tile);
700  if (base == 0) base = SPR_CANAL_DIKES_BASE;
701  } else {
702  feature = CF_RIVER_EDGE;
703  base = GetCanalSprite(CF_RIVER_EDGE, tile);
704  if (base == 0) return; // Don't draw if no sprites provided.
705  }
706 
707  uint wa;
708 
709  /* determine the edges around with water. */
710  wa = IsWateredTile(TILE_ADDXY(tile, -1, 0), DIR_SW) << 0;
711  wa += IsWateredTile(TILE_ADDXY(tile, 0, 1), DIR_NW) << 1;
712  wa += IsWateredTile(TILE_ADDXY(tile, 1, 0), DIR_NE) << 2;
713  wa += IsWateredTile(TILE_ADDXY(tile, 0, -1), DIR_SE) << 3;
714 
715  if (!(wa & 1)) DrawWaterSprite(base, offset, feature, tile);
716  if (!(wa & 2)) DrawWaterSprite(base, offset + 1, feature, tile);
717  if (!(wa & 4)) DrawWaterSprite(base, offset + 2, feature, tile);
718  if (!(wa & 8)) DrawWaterSprite(base, offset + 3, feature, tile);
719 
720  /* right corner */
721  switch (wa & 0x03) {
722  case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
723  case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
724  }
725 
726  /* bottom corner */
727  switch (wa & 0x06) {
728  case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
729  case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
730  }
731 
732  /* left corner */
733  switch (wa & 0x0C) {
734  case 0: DrawWaterSprite(base, offset + 6, feature, tile); break;
735  case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
736  }
737 
738  /* upper corner */
739  switch (wa & 0x09) {
740  case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
741  case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
742  }
743 }
744 
746 static void DrawSeaWater(TileIndex tile)
747 {
748  DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
749 }
750 
752 static void DrawCanalWater(TileIndex tile)
753 {
754  SpriteID image = SPR_FLAT_WATER_TILE;
755  if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
756  /* First water slope sprite is flat water. */
757  image = GetCanalSprite(CF_WATERSLOPE, tile);
758  if (image == 0) image = SPR_FLAT_WATER_TILE;
759  }
760  DrawWaterSprite(image, 0, CF_WATERSLOPE, tile);
761 
762  DrawWaterEdges(true, 0, tile);
763 }
764 
765 #include "table/water_land.h"
766 
776 static void DrawWaterTileStruct(const TileInfo *ti, const DrawTileSeqStruct *dtss, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
777 {
778  /* Don't draw if buildings are invisible. */
779  if (IsInvisibilitySet(TO_BUILDINGS)) return;
780 
781  for (; !dtss->IsTerminator(); dtss++) {
782  uint tile_offs = offset + dtss->image.sprite;
783  if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
784  AddSortableSpriteToDraw(base + tile_offs, palette,
785  ti->x + dtss->delta_x, ti->y + dtss->delta_y,
786  dtss->size_x, dtss->size_y,
787  dtss->size_z, ti->z + dtss->delta_z,
789  }
790 }
791 
793 static void DrawWaterLock(const TileInfo *ti)
794 {
795  int part = GetLockPart(ti->tile);
796  const DrawTileSprites &dts = _lock_display_data[part][GetLockDirection(ti->tile)];
797 
798  /* Draw ground sprite. */
799  SpriteID image = dts.ground.sprite;
800 
801  SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
802  if (water_base == 0) {
803  /* Use default sprites. */
804  water_base = SPR_CANALS_BASE;
805  } else if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
806  /* NewGRF supplies a flat sprite as first sprite. */
807  if (image == SPR_FLAT_WATER_TILE) {
808  image = water_base;
809  } else {
810  image++;
811  }
812  }
813 
814  if (image < 5) image += water_base;
815  DrawGroundSprite(image, PAL_NONE);
816 
817  /* Draw structures. */
818  uint zoffs = 0;
819  SpriteID base = GetCanalSprite(CF_LOCKS, ti->tile);
820 
821  if (base == 0) {
822  /* If no custom graphics, use defaults. */
823  base = SPR_LOCK_BASE;
824  uint8 z_threshold = part == LOCK_PART_UPPER ? 8 : 0;
825  zoffs = ti->z > z_threshold ? 24 : 0;
826  }
827 
828  DrawWaterTileStruct(ti, dts.seq, base, zoffs, PAL_NONE, CF_LOCKS);
829 }
830 
832 static void DrawWaterDepot(const TileInfo *ti)
833 {
834  DrawWaterClassGround(ti);
835  DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][GetShipDepotPart(ti->tile)].seq, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END);
836 }
837 
838 static void DrawRiverWater(const TileInfo *ti)
839 {
840  SpriteID image = SPR_FLAT_WATER_TILE;
841  uint offset = 0;
842  uint edges_offset = 0;
843 
844  if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
845  image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
846  if (image == 0) {
847  switch (ti->tileh) {
848  case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
849  case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP; break;
850  case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP; break;
851  case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
852  default: image = SPR_FLAT_WATER_TILE; break;
853  }
854  } else {
855  /* Flag bit 0 indicates that the first sprite is flat water. */
856  offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;
857 
858  switch (ti->tileh) {
859  case SLOPE_SE: edges_offset += 12; break;
860  case SLOPE_NE: offset += 1; edges_offset += 24; break;
861  case SLOPE_SW: offset += 2; edges_offset += 36; break;
862  case SLOPE_NW: offset += 3; edges_offset += 48; break;
863  default: offset = 0; break;
864  }
865 
866  offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
867  }
868  }
869 
870  DrawGroundSprite(image + offset, PAL_NONE);
871 
872  /* Draw river edges if available. */
873  DrawWaterEdges(false, edges_offset, ti->tile);
874 }
875 
876 void DrawShoreTile(Slope tileh)
877 {
878  /* Converts the enum Slope into an offset based on SPR_SHORE_BASE.
879  * This allows to calculate the proper sprite to display for this Slope */
880  static const byte tileh_to_shoresprite[32] = {
881  0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0,
882  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0,
883  };
884 
885  assert(!IsHalftileSlope(tileh)); // Halftile slopes need to get handled earlier.
886  assert(tileh != SLOPE_FLAT); // Shore is never flat
887 
888  assert((tileh != SLOPE_EW) && (tileh != SLOPE_NS)); // No suitable sprites for current flooding behaviour
889 
890  DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[tileh], PAL_NONE);
891 }
892 
893 void DrawWaterClassGround(const TileInfo *ti)
894 {
895  switch (GetWaterClass(ti->tile)) {
896  case WATER_CLASS_SEA: DrawSeaWater(ti->tile); break;
897  case WATER_CLASS_CANAL: DrawCanalWater(ti->tile); break;
898  case WATER_CLASS_RIVER: DrawRiverWater(ti); break;
899  default: NOT_REACHED();
900  }
901 }
902 
903 static void DrawTile_Water(TileInfo *ti)
904 {
905  switch (GetWaterTileType(ti->tile)) {
906  case WATER_TILE_CLEAR:
907  DrawWaterClassGround(ti);
908  DrawBridgeMiddle(ti);
909  break;
910 
911  case WATER_TILE_COAST: {
912  DrawShoreTile(ti->tileh);
913  DrawBridgeMiddle(ti);
914  break;
915  }
916 
917  case WATER_TILE_LOCK:
918  DrawWaterLock(ti);
919  break;
920 
921  case WATER_TILE_DEPOT:
922  DrawWaterDepot(ti);
923  break;
924  }
925 }
926 
927 void DrawShipDepotSprite(int x, int y, Axis axis, DepotPart part)
928 {
929  const DrawTileSprites &dts = _shipdepot_display_data[axis][part];
930 
931  DrawSprite(dts.ground.sprite, dts.ground.pal, x, y);
932  DrawOrigTileSeqInGUI(x, y, &dts, COMPANY_SPRITE_COLOUR(_local_company));
933 }
934 
935 
936 static int GetSlopePixelZ_Water(TileIndex tile, uint x, uint y)
937 {
938  int z;
939  Slope tileh = GetTilePixelSlope(tile, &z);
940 
941  return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
942 }
943 
944 static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
945 {
946  return FOUNDATION_NONE;
947 }
948 
949 static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
950 {
951  switch (GetWaterTileType(tile)) {
952  case WATER_TILE_CLEAR:
953  switch (GetWaterClass(tile)) {
954  case WATER_CLASS_SEA: td->str = STR_LAI_WATER_DESCRIPTION_WATER; break;
955  case WATER_CLASS_CANAL: td->str = STR_LAI_WATER_DESCRIPTION_CANAL; break;
956  case WATER_CLASS_RIVER: td->str = STR_LAI_WATER_DESCRIPTION_RIVER; break;
957  default: NOT_REACHED();
958  }
959  break;
960  case WATER_TILE_COAST: td->str = STR_LAI_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break;
961  case WATER_TILE_LOCK : td->str = STR_LAI_WATER_DESCRIPTION_LOCK; break;
962  case WATER_TILE_DEPOT:
963  td->str = STR_LAI_WATER_DESCRIPTION_SHIP_DEPOT;
964  td->build_date = Depot::GetByTile(tile)->build_date;
965  break;
966  default: NOT_REACHED();
967  }
968 
969  td->owner[0] = GetTileOwner(tile);
970 }
971 
977 static void FloodVehicle(Vehicle *v)
978 {
979  uint pass = v->Crash(true);
980 
981  AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED));
982  Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED));
983  SetDParam(0, pass);
984  AddTileNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NT_ACCIDENT, v->tile);
986  if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
987 }
988 
995 static Vehicle *FloodVehicleProc(Vehicle *v, void *data)
996 {
997  if ((v->vehstatus & VS_CRASHED) != 0) return nullptr;
998 
999  switch (v->type) {
1000  default: break;
1001 
1002  case VEH_AIRCRAFT: {
1003  if (!IsAirportTile(v->tile) || GetTileMaxZ(v->tile) != 0) break;
1004  if (v->subtype == AIR_SHADOW) break;
1005 
1006  /* We compare v->z_pos against delta_z + 1 because the shadow
1007  * is at delta_z and the actual aircraft at delta_z + 1. */
1008  const Station *st = Station::GetByTile(v->tile);
1009  const AirportFTAClass *airport = st->airport.GetFTA();
1010  if (v->z_pos != airport->delta_z + 1) break;
1011 
1012  FloodVehicle(v);
1013  break;
1014  }
1015 
1016  case VEH_TRAIN:
1017  case VEH_ROAD: {
1018  int z = *(int*)data;
1019  if (v->z_pos > z) break;
1020  FloodVehicle(v->First());
1021  break;
1022  }
1023  }
1024 
1025  return nullptr;
1026 }
1027 
1033 static void FloodVehicles(TileIndex tile)
1034 {
1035  int z = 0;
1036 
1037  if (IsAirportTile(tile)) {
1038  const Station *st = Station::GetByTile(tile);
1039  for (TileIndex airport_tile : st->airport) {
1040  if (st->TileBelongsToAirport(airport_tile)) FindVehicleOnPos(airport_tile, &z, &FloodVehicleProc);
1041  }
1042 
1043  /* No vehicle could be flooded on this airport anymore */
1044  return;
1045  }
1046 
1047  if (!IsBridgeTile(tile)) {
1048  FindVehicleOnPos(tile, &z, &FloodVehicleProc);
1049  return;
1050  }
1051 
1052  TileIndex end = GetOtherBridgeEnd(tile);
1053  z = GetBridgePixelHeight(tile);
1054 
1055  FindVehicleOnPos(tile, &z, &FloodVehicleProc);
1057 }
1058 
1065 {
1066  /* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
1067  * FLOOD_DRYUP: coast with more than one corner raised, coast with rail-track, coast with trees
1068  * FLOOD_PASSIVE: (not used)
1069  * FLOOD_NONE: canals, rivers, everything else
1070  */
1071  switch (GetTileType(tile)) {
1072  case MP_WATER:
1073  if (IsCoast(tile)) {
1074  Slope tileh = GetTileSlope(tile);
1076  }
1077  FALLTHROUGH;
1078  case MP_STATION:
1079  case MP_INDUSTRY:
1080  case MP_OBJECT:
1081  return (GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE;
1082 
1083  case MP_RAILWAY:
1084  if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
1086  }
1087  return FLOOD_NONE;
1088 
1089  case MP_TREES:
1090  return (GetTreeGround(tile) == TREE_GROUND_SHORE ? FLOOD_DRYUP : FLOOD_NONE);
1091 
1092  default:
1093  return FLOOD_NONE;
1094  }
1095 }
1096 
1101 {
1102  assert(!IsTileType(target, MP_WATER));
1103 
1104  bool flooded = false; // Will be set to true if something is changed.
1105 
1106  Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
1107 
1108  Slope tileh = GetTileSlope(target);
1109  if (tileh != SLOPE_FLAT) {
1110  /* make coast.. */
1111  switch (GetTileType(target)) {
1112  case MP_RAILWAY: {
1113  if (!IsPlainRail(target)) break;
1114  FloodVehicles(target);
1115  flooded = FloodHalftile(target);
1116  break;
1117  }
1118 
1119  case MP_TREES:
1120  if (!IsSlopeWithOneCornerRaised(tileh)) {
1122  MarkTileDirtyByTile(target);
1123  flooded = true;
1124  break;
1125  }
1126  FALLTHROUGH;
1127 
1128  case MP_CLEAR:
1129  if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, target).Succeeded()) {
1130  MakeShore(target);
1131  MarkTileDirtyByTile(target);
1132  flooded = true;
1133  }
1134  break;
1135 
1136  default:
1137  break;
1138  }
1139  } else {
1140  /* Flood vehicles */
1141  FloodVehicles(target);
1142 
1143  /* flood flat tile */
1144  if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, target).Succeeded()) {
1145  MakeSea(target);
1146  MarkTileDirtyByTile(target);
1147  flooded = true;
1148  }
1149  }
1150 
1151  if (flooded) {
1152  /* Mark surrounding canal tiles dirty too to avoid glitches */
1154 
1155  /* update signals if needed */
1157 
1158  if (IsPossibleDockingTile(target)) CheckForDockingTile(target);
1159  }
1160 
1161  cur_company.Restore();
1162 }
1163 
1167 static void DoDryUp(TileIndex tile)
1168 {
1169  Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
1170 
1171  switch (GetTileType(tile)) {
1172  case MP_RAILWAY:
1173  assert(IsPlainRail(tile));
1174  assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
1175 
1176  RailGroundType new_ground;
1177  switch (GetTrackBits(tile)) {
1178  case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
1179  case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
1180  case TRACK_BIT_LEFT: new_ground = RAIL_GROUND_FENCE_VERT1; break;
1181  case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
1182  default: NOT_REACHED();
1183  }
1184  SetRailGroundType(tile, new_ground);
1185  MarkTileDirtyByTile(tile);
1186  break;
1187 
1188  case MP_TREES:
1190  MarkTileDirtyByTile(tile);
1191  break;
1192 
1193  case MP_WATER:
1194  assert(IsCoast(tile));
1195 
1196  if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile).Succeeded()) {
1197  MakeClear(tile, CLEAR_GRASS, 3);
1198  MarkTileDirtyByTile(tile);
1199  }
1200  break;
1201 
1202  default: NOT_REACHED();
1203  }
1204 
1205  cur_company.Restore();
1206 }
1207 
1215 {
1216  if (IsTileType(tile, MP_WATER)) AmbientSoundEffect(tile);
1217 
1218  switch (GetFloodingBehaviour(tile)) {
1219  case FLOOD_ACTIVE:
1220  for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
1221  TileIndex dest = tile + TileOffsByDir(dir);
1222  if (!IsValidTile(dest)) continue;
1223  /* do not try to flood water tiles - increases performance a lot */
1224  if (IsTileType(dest, MP_WATER)) continue;
1225 
1226  /* TREE_GROUND_SHORE is the sign of a previous flood. */
1227  if (IsTileType(dest, MP_TREES) && GetTreeGround(dest) == TREE_GROUND_SHORE) continue;
1228 
1229  int z_dest;
1230  Slope slope_dest = GetFoundationSlope(dest, &z_dest) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
1231  if (z_dest > 0) continue;
1232 
1233  if (!HasBit(_flood_from_dirs[slope_dest], ReverseDir(dir))) continue;
1234 
1235  DoFloodTile(dest);
1236  }
1237  break;
1238 
1239  case FLOOD_DRYUP: {
1240  Slope slope_here = GetFoundationSlope(tile) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
1241  for (uint dir : SetBitIterator(_flood_from_dirs[slope_here])) {
1242  TileIndex dest = tile + TileOffsByDir((Direction)dir);
1243  if (!IsValidTile(dest)) continue;
1244 
1245  FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
1246  if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
1247  }
1248  DoDryUp(tile);
1249  break;
1250  }
1251 
1252  default: return;
1253  }
1254 }
1255 
1256 void ConvertGroundTilesIntoWaterTiles()
1257 {
1258  int z;
1259 
1260  for (TileIndex tile = 0; tile < MapSize(); ++tile) {
1261  Slope slope = GetTileSlope(tile, &z);
1262  if (IsTileType(tile, MP_CLEAR) && z == 0) {
1263  /* Make both water for tiles at level 0
1264  * and make shore, as that looks much better
1265  * during the generation. */
1266  switch (slope) {
1267  case SLOPE_FLAT:
1268  MakeSea(tile);
1269  break;
1270 
1271  case SLOPE_N:
1272  case SLOPE_E:
1273  case SLOPE_S:
1274  case SLOPE_W:
1275  MakeShore(tile);
1276  break;
1277 
1278  default:
1279  for (uint dir : SetBitIterator(_flood_from_dirs[slope & ~SLOPE_STEEP])) {
1280  TileIndex dest = TileAddByDir(tile, (Direction)dir);
1281  Slope slope_dest = GetTileSlope(dest) & ~SLOPE_STEEP;
1282  if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest)) {
1283  MakeShore(tile);
1284  break;
1285  }
1286  }
1287  break;
1288  }
1289  }
1290  }
1291 }
1292 
1293 static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1294 {
1297 
1298  TrackBits ts;
1299 
1300  if (mode != TRANSPORT_WATER) return 0;
1301 
1302  switch (GetWaterTileType(tile)) {
1303  case WATER_TILE_CLEAR: ts = IsTileFlat(tile) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
1304  case WATER_TILE_COAST: ts = coast_tracks[GetTileSlope(tile) & 0xF]; break;
1305  case WATER_TILE_LOCK: ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
1306  case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
1307  default: return 0;
1308  }
1309  if (TileX(tile) == 0) {
1310  /* NE border: remove tracks that connects NE tile edge */
1312  }
1313  if (TileY(tile) == 0) {
1314  /* NW border: remove tracks that connects NW tile edge */
1316  }
1318 }
1319 
1320 static bool ClickTile_Water(TileIndex tile)
1321 {
1322  if (GetWaterTileType(tile) == WATER_TILE_DEPOT) {
1324  return true;
1325  }
1326  return false;
1327 }
1328 
1329 static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_owner)
1330 {
1331  if (!IsTileOwner(tile, old_owner)) return;
1332 
1333  bool is_lock_middle = IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE;
1334 
1335  /* No need to dirty company windows here, we'll redraw the whole screen anyway. */
1336  if (is_lock_middle) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1337  if (new_owner != INVALID_OWNER) {
1338  if (is_lock_middle) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
1339  /* Only subtract from the old owner here if the new owner is valid,
1340  * otherwise we clear ship depots and canal water below. */
1341  if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) {
1342  Company::Get(old_owner)->infrastructure.water--;
1343  Company::Get(new_owner)->infrastructure.water++;
1344  }
1345  if (IsShipDepot(tile)) {
1346  Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
1347  Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
1348  }
1349 
1350  SetTileOwner(tile, new_owner);
1351  return;
1352  }
1353 
1354  /* Remove depot */
1356 
1357  /* Set owner of canals and locks ... and also canal under dock there was before.
1358  * Check if the new owner after removing depot isn't OWNER_WATER. */
1359  if (IsTileOwner(tile, old_owner)) {
1360  if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
1361  SetTileOwner(tile, OWNER_NONE);
1362  }
1363 }
1364 
1365 static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
1366 {
1367  return VETSB_CONTINUE;
1368 }
1369 
1370 static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
1371 {
1372  /* Canals can't be terraformed */
1373  if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
1374 
1375  return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
1376 }
1377 
1378 
1379 extern const TileTypeProcs _tile_type_water_procs = {
1380  DrawTile_Water, // draw_tile_proc
1381  GetSlopePixelZ_Water, // get_slope_z_proc
1382  ClearTile_Water, // clear_tile_proc
1383  nullptr, // add_accepted_cargo_proc
1384  GetTileDesc_Water, // get_tile_desc_proc
1385  GetTileTrackStatus_Water, // get_tile_track_status_proc
1386  ClickTile_Water, // click_tile_proc
1387  nullptr, // animate_tile_proc
1388  TileLoop_Water, // tile_loop_proc
1389  ChangeTileOwner_Water, // change_tile_owner_proc
1390  nullptr, // add_produced_cargo_proc
1391  VehicleEnter_Water, // vehicle_enter_tile_proc
1392  GetFoundation_Water, // get_foundation_proc
1393  TerraformTile_Water, // terraform_tile_proc
1394 };
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
game.hpp
TileInfo::z
int z
Height.
Definition: tile_cmd.h:47
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
FLOOD_DRYUP
@ FLOOD_DRYUP
The tile drys up if it is not constantly flooded from neighboured tiles.
Definition: water.h:23
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
LOCK_PART_UPPER
@ LOCK_PART_UPPER
Upper part of a lock.
Definition: water_map.h:78
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
Station::docking_station
TileArea docking_station
Tile area the docking tiles cover.
Definition: station_base.h:470
DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
IsInsideMM
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:204
sound_func.h
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
IsValidAxis
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
IsCanal
static bool IsCanal(TileIndex t)
Is it a canal tile?
Definition: water_map.h:174
GetOtherShipDepotTile
static TileIndex GetOtherShipDepotTile(TileIndex t)
Get the other tile of the ship depot.
Definition: water_map.h:283
DIR_BEGIN
@ DIR_BEGIN
Used to iterate.
Definition: direction_type.h:25
water.h
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
SPR_SHORE_BASE
static const SpriteID SPR_SHORE_BASE
shore tiles - action 05-0D
Definition: sprites.h:224
DrawOrigTileSeqInGUI
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition: sprite.h:115
UpdateSignalsInBuffer
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:468
command_func.h
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
TO_BUILDINGS
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition: transparency.h:27
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
company_base.h
IsTransparencySet
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
tunnelbridge_map.h
GetLockDirection
static DiagDirection GetLockDirection(TileIndex t)
Get the direction of the water lock.
Definition: water_map.h:319
DrawWaterLock
static void DrawWaterLock(const TileInfo *ti)
Draw a lock tile.
Definition: water_cmd.cpp:793
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
Station
Station data structure.
Definition: station_base.h:454
company_gui.h
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:285
AmbientSoundEffect
static void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
Definition: newgrf_generic.h:53
FloodVehicles
static void FloodVehicles(TileIndex tile)
Finds a vehicle to flood.
Definition: water_cmd.cpp:1033
IsAirportTile
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
Definition: station_map.h:167
IsWateredTile
bool IsWateredTile(TileIndex tile, Direction from)
return true if a tile is a water tile wrt.
Definition: water_cmd.cpp:607
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
MakeSea
static void MakeSea(TileIndex t)
Make a sea tile.
Definition: water_map.h:425
TileAddByDir
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition: map_func.h:370
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
MakeClear
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
CompanyInfrastructure::water
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35
depot_func.h
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
Vehicle::Crash
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
Definition: vehicle.cpp:260
AxisToTrackBits
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:87
FloodHalftile
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:764
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
DoBuildLock
static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag flags)
Builds a lock.
Definition: water_cmd.cpp:295
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
IsHalftileSlope
static bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition: slope_func.h:47
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition: sound_type.h:55
RAIL_GROUND_FENCE_VERT1
@ RAIL_GROUND_FENCE_VERT1
Grass with a fence at the eastern side.
Definition: rail_map.h:494
GetCanalSpriteOffset
uint GetCanalSpriteOffset(CanalFeature feature, TileIndex tile, uint cur_offset)
Get the new sprite offset for a water tile.
Definition: newgrf_canal.cpp:171
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
VETSB_CONTINUE
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition: tile_cmd.h:34
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
DrawWaterTileStruct
static void DrawWaterTileStruct(const TileInfo *ti, const DrawTileSeqStruct *dtss, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
Draw a build sprite sequence for water tiles.
Definition: water_cmd.cpp:776
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:219
aircraft.h
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
Definition: tunnelbridge_cmd.cpp:1523
water_land.h
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
RAIL_GROUND_FENCE_VERT2
@ RAIL_GROUND_FENCE_VERT2
Grass with a fence at the western side.
Definition: rail_map.h:495
IsCoast
static bool IsCoast(TileIndex t)
Is it a coast tile?
Definition: water_map.h:206
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:353
CFF_HAS_FLAT_SPRITE
@ CFF_HAS_FLAT_SPRITE
Additional flat ground sprite in the beginning.
Definition: newgrf_canal.h:18
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:43
SLOPE_S
@ SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:51
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
clear_map.h
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
WATER_TILE_DEPOT
@ WATER_TILE_DEPOT
Water Depot.
Definition: water_map.h:43
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
EV_EXPLOSION_LARGE
@ EV_EXPLOSION_LARGE
Various explosions.
Definition: effectvehicle_func.h:22
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:350
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26
WATER_CLASS_INVALID
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
SLOPE_E
@ SLOPE_E
the east corner of the tile is raised
Definition: slope_type.h:52
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:348
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
CmdBuildLock
CommandCost CmdBuildLock(DoCommandFlag flags, TileIndex tile)
Builds a lock.
Definition: water_cmd.cpp:415
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
newgrf_generic.h
AIR_SHADOW
@ AIR_SHADOW
shadow of the aircraft
Definition: aircraft.h:33
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:69
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:42
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
industry_map.h
GetLockPart
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:331
DEPOT_PART_NORTH
@ DEPOT_PART_NORTH
Northern part of a depot.
Definition: water_map.h:69
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:595
effectvehicle_func.h
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:45
Airport::GetFTA
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Definition: station_base.h:329
ai.hpp
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:141
GetShipDepotNorthTile
static TileIndex GetShipDepotNorthTile(TileIndex t)
Get the most northern tile of a ship depot.
Definition: water_map.h:294
TileDesc::build_date
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:55
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
ToTileIndexDiff
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition: map_func.h:230
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
WATER_TILE_COAST
@ WATER_TILE_COAST
Coast.
Definition: water_map.h:41
DrawTileSeqStruct::delta_x
int8 delta_x
0x80 is sequence terminator
Definition: sprite.h:26
depot_base.h
landscape_cmd.h
DirToDiagDir
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:234
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
CommandCost
Common return value for all commands.
Definition: command_type.h:24
HasTileWaterGround
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:355
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
SetTropicZone
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
Definition: tile_map.h:225
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:601
CircularTileSearch
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:258
FloodVehicleProc
static Vehicle * FloodVehicleProc(Vehicle *v, void *data)
Flood a vehicle if we are allowed to flood it, i.e.
Definition: water_cmd.cpp:995
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
DrawTileSeqStruct::delta_z
int8 delta_z
0x80 identifies child sprites
Definition: sprite.h:28
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:144
WATER_TILE_CLEAR
@ WATER_TILE_CLEAR
Plain water.
Definition: water_map.h:40
MakeLock
static void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper, WaterClass wc_middle)
Make a water lock.
Definition: water_map.h:507
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2776
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
TileIndexDiff
int32 TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:154
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:362
DrawCanalWater
static void DrawCanalWater(TileIndex tile)
draw a canal styled water tile with dikes around
Definition: water_cmd.cpp:752
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:41
IsBuoy
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:306
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
IsInvisibilitySet
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
RiverModifyDesertZone
bool RiverModifyDesertZone(TileIndex tile, void *)
Callback to create non-desert around a river tile.
Definition: water_cmd.cpp:424
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:468
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
IsShipDepot
static bool IsShipDepot(TileIndex t)
Is it a water tile with a ship depot on it?
Definition: water_map.h:227
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
LOCK_PART_MIDDLE
@ LOCK_PART_MIDDLE
Middle part of a lock.
Definition: water_map.h:76
IsValidWaterClass
static bool IsValidWaterClass(WaterClass wc)
Checks if a water class is valid.
Definition: water_map.h:62
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
_water_feature
WaterFeature _water_feature[CF_END]
Table of canal 'feature' sprite groups.
Definition: newgrf_canal.cpp:21
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:141
DrawTileSeqStruct::IsTerminator
bool IsTerminator() const
Check whether this is a sequence terminator.
Definition: sprite.h:41
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:40
TileOffsByDir
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition: map_func.h:355
industry.h
safeguards.h
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:387
SetDockingTile
static void SetDockingTile(TileIndex t, bool b)
Set the docking tile state of a tile.
Definition: water_map.h:366
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:348
GetCanalSprite
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
Lookup the base sprite to use for a canal.
Definition: newgrf_canal.cpp:140
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
DIR_S
@ DIR_S
South.
Definition: direction_type.h:30
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:84
DrawSprite
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:1044
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition: airport.h:143
SoundSettings::disaster
bool disaster
Play disaster and accident sounds.
Definition: settings_type.h:213
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
SLOPE_NS
@ SLOPE_NS
north and south corner are raised
Definition: slope_type.h:60
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
MarkCanalsAndRiversAroundDirty
static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
Marks the tiles around a tile as dirty, if they are canals or rivers.
Definition: water_cmd.cpp:85
WATER_CLASS_RIVER
@ WATER_CLASS_RIVER
River.
Definition: water_map.h:50
GetFoundationSlope
Slope GetFoundationSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.cpp:426
TRACK_BIT_ALL
@ TRACK_BIT_ALL
All possible tracks.
Definition: track_type.h:53
SLOPE_HALFTILE_MASK
@ SLOPE_HALFTILE_MASK
three bits used for halftile slopes
Definition: slope_type.h:72
CreateEffectVehicleRel
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
Definition: effectvehicle.cpp:638
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition: track_type.h:43
GetShipDepotPart
static DepotPart GetShipDepotPart(TileIndex t)
Get the part of a ship depot.
Definition: water_map.h:260
stdafx.h
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:356
IsValidDockingDirectionForDock
bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d)
Check if a dock tile can be docked from the given direction.
Definition: station_cmd.cpp:2603
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition: water_cmd.cpp:1214
viewport_func.h
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
RailGroundType
RailGroundType
The ground 'under' the rail.
Definition: rail_map.h:485
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:666
TREE_GROUND_GRASS
@ TREE_GROUND_GRASS
normal grass
Definition: tree_map.h:53
SLOPE_W
@ SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:50
RAIL_GROUND_WATER
@ RAIL_GROUND_WATER
Grass with a fence and shore or water on the free halftile.
Definition: rail_map.h:499
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:57
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:180
AirportFTAClass::delta_z
byte delta_z
Z adjustment for helicopter pads.
Definition: airport.h:183
DEPOT_PART_SOUTH
@ DEPOT_PART_SOUTH
Southern part of a depot.
Definition: water_map.h:70
ReverseDir
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
Definition: direction_func.h:54
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:245
IsDockTile
static bool IsDockTile(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:295
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
NT_ACCIDENT
@ NT_ACCIDENT
An accident or disaster has occurred.
Definition: news_type.h:24
FloodVehicle
static void FloodVehicle(Vehicle *v)
Handle the flooding of a vehicle.
Definition: water_cmd.cpp:977
FLOOD_PASSIVE
@ FLOOD_PASSIVE
The tile does not actively flood neighboured tiles, but it prevents them from drying up.
Definition: water.h:22
station_base.h
strings_func.h
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:613
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:117
RAIL_GROUND_FENCE_HORIZ1
@ RAIL_GROUND_FENCE_HORIZ1
Grass with a fence at the southern side.
Definition: rail_map.h:496
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
DoFloodTile
void DoFloodTile(TileIndex target)
Floods a tile.
Definition: water_cmd.cpp:1100
SLOPE_EW
@ SLOPE_EW
east and west corner are raised
Definition: slope_type.h:59
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:44
DrawSeaWater
static void DrawSeaWater(TileIndex tile)
Draw a plain sea water tile with no edges.
Definition: water_cmd.cpp:746
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
IsPlainRail
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:49
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
GetWaterTileType
static WaterTileType GetWaterTileType(TileIndex t)
Get the water tile type at a tile.
Definition: water_map.h:88
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
IsSlopeWithOneCornerRaised
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
MakeShipDepot
static void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart part, Axis a, WaterClass original_water_class)
Make a ship depot section.
Definition: water_map.h:461
DIR_END
@ DIR_END
Used to iterate.
Definition: direction_type.h:34
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:195
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
tree_map.h
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1988
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
MakeShore
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
Definition: water_map.h:386
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
FloodingBehaviour
FloodingBehaviour
Describes the behaviour of a tile during flooding.
Definition: water.h:19
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:238
RIVER_OFFSET_DESERT_DISTANCE
static const uint RIVER_OFFSET_DESERT_DISTANCE
Circular tile search radius to create non-desert around a river tile.
Definition: water.h:42
FindVehicleOnPos
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:498
FLOOD_NONE
@ FLOOD_NONE
The tile does not flood neighboured tiles.
Definition: water.h:20
Pool::PoolItem<&_depot_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:307
IsLock
static bool IsLock(TileIndex t)
Is there a lock on a given water tile?
Definition: water_map.h:308
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
GetShipDepotAxis
static Axis GetShipDepotAxis(TileIndex t)
Get the axis of the ship depot.
Definition: water_map.h:248
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:52
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:351
company_func.h
IsRiver
static bool IsRiver(TileIndex t)
Is it a river water tile?
Definition: water_map.h:185
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
GetTreeGround
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
_flood_from_dirs
static const uint8 _flood_from_dirs[]
Describes from which directions a specific slope can be flooded (if the tile is floodable at all).
Definition: water_cmd.cpp:50
LOCK_DEPOT_TILE_FACTOR
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition: economy_type.h:230
DrawWaterDepot
static void DrawWaterDepot(const TileInfo *ti)
Draw a ship depot tile.
Definition: water_cmd.cpp:832
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:342
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition: company_cmd.cpp:331
CommandHelper
Definition: command_func.h:94
DrawTileSprites::seq
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
Depot::build_date
Date build_date
Date of construction.
Definition: depot_base.h:25
FLOOD_ACTIVE
@ FLOOD_ACTIVE
The tile floods neighboured tiles.
Definition: water.h:21
Depot
Definition: depot_base.h:19
MakeCanal
static void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
Make a canal tile.
Definition: water_map.h:446
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:523
GetBridgePixelHeight
static int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition: bridge_map.h:84
IsDock
static bool IsDock(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:285
random_func.hpp
newgrf_canal.h
OverflowSafeInt< int64 >
IsOilRig
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
Definition: station_map.h:274
RemoveLock
static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags)
Remove a lock.
Definition: water_cmd.cpp:371
GetFloodingBehaviour
FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
Returns the behaviour of a tile during flooding.
Definition: water_cmd.cpp:1064
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
RAIL_GROUND_FENCE_HORIZ2
@ RAIL_GROUND_FENCE_HORIZ2
Grass with a fence at the northern side.
Definition: rail_map.h:497
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:41
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:582
IsInclinedSlope
static bool IsInclinedSlope(Slope s)
Tests if a specific slope is an inclined slope.
Definition: slope_func.h:228
CmdBuildShipDepot
CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, Axis axis)
Build a ship depot.
Definition: water_cmd.cpp:100
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
TROPICZONE_NORMAL
@ TROPICZONE_NORMAL
Normal tropiczone.
Definition: tile_type.h:77
WATER_TILE_LOCK
@ WATER_TILE_LOCK
Water lock.
Definition: water_map.h:42
GetTilePixelSlope
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
CmdBuildCanal
CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, WaterClass wc, bool diagonal)
Build a piece of canal.
Definition: water_cmd.cpp:439
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
ShowDepotWindow
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
Definition: depot_gui.cpp:1103
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:117
DepotPart
DepotPart
Sections of the water depot.
Definition: water_map.h:68
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
DrawWaterSprite
static void DrawWaterSprite(SpriteID base, uint offset, CanalFeature feature, TileIndex tile)
Draw a water sprite, potentially with a NewGRF-modified sprite offset.
Definition: water_cmd.cpp:678
SLOPE_STEEP
@ SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:54
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:20
DrawWaterEdges
static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
Draw canal or river edges.
Definition: water_cmd.cpp:693
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:582
MakeRiver
static void MakeRiver(TileIndex t, uint8 random_bits)
Make a river tile.
Definition: water_map.h:435
SetTreeGroundDensity
static void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition: tree_map.h:130
GetInclinedSlopeDirection
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
MarkTileDirtyIfCanalOrRiver
static void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
Marks tile dirty if it is a canal or river tile.
Definition: water_cmd.cpp:74
news_func.h
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
water_cmd.h
DrawTileSeqStruct
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition: sprite.h:25
DoDryUp
static void DoDryUp(TileIndex tile)
Drys a tile up.
Definition: water_cmd.cpp:1167
backup_type.hpp
CanalFeature
CanalFeature
List of different canal 'features'.
Definition: newgrf.h:25