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