OpenTTD Source  14.0-beta1
ship_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 "ship.h"
12 #include "landscape.h"
13 #include "timetable.h"
14 #include "news_func.h"
15 #include "company_func.h"
17 #include "depot_base.h"
18 #include "station_base.h"
19 #include "newgrf_engine.h"
20 #include "pathfinder/yapf/yapf.h"
22 #include "newgrf_sound.h"
23 #include "spritecache.h"
24 #include "strings_func.h"
25 #include "window_func.h"
28 #include "vehicle_func.h"
29 #include "sound_func.h"
30 #include "ai/ai.hpp"
31 #include "game/game.hpp"
32 #include "engine_base.h"
33 #include "company_base.h"
34 #include "tunnelbridge_map.h"
35 #include "zoom_func.h"
36 #include "framerate_type.h"
37 #include "industry.h"
38 #include "industry_map.h"
39 #include "ship_cmd.h"
40 
41 #include "table/strings.h"
42 
43 #include <unordered_set>
44 
45 #include "safeguards.h"
46 
48 constexpr int MAX_SHIP_DEPOT_SEARCH_DISTANCE = 80;
49 
56 {
57  if (HasTileWaterClass(tile)) return GetWaterClass(tile);
58  if (IsTileType(tile, MP_TUNNELBRIDGE)) {
60  return WATER_CLASS_CANAL;
61  }
62  if (IsTileType(tile, MP_RAILWAY)) {
63  assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
64  return WATER_CLASS_SEA;
65  }
66  NOT_REACHED();
67 }
68 
69 static const uint16_t _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
70 
71 template <>
72 bool IsValidImageIndex<VEH_SHIP>(uint8_t image_index)
73 {
74  return image_index < lengthof(_ship_sprites);
75 }
76 
77 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
78 {
80 }
81 
82 static void GetShipIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
83 {
84  const Engine *e = Engine::Get(engine);
85  uint8_t spritenum = e->u.ship.image_index;
86 
87  if (is_custom_sprite(spritenum)) {
88  GetCustomVehicleIcon(engine, DIR_W, image_type, result);
89  if (result->IsValid()) return;
90 
91  spritenum = e->original_image_index;
92  }
93 
94  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
95  result->Set(DIR_W + _ship_sprites[spritenum]);
96 }
97 
98 void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
99 {
100  VehicleSpriteSeq seq;
101  GetShipIcon(engine, image_type, &seq);
102 
103  Rect rect;
104  seq.GetBounds(&rect);
105  preferred_x = Clamp(preferred_x,
106  left - UnScaleGUI(rect.left),
107  right - UnScaleGUI(rect.right));
108 
109  seq.Draw(preferred_x, y, pal, pal == PALETTE_CRASH);
110 }
111 
121 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
122 {
123  VehicleSpriteSeq seq;
124  GetShipIcon(engine, image_type, &seq);
125 
126  Rect rect;
127  seq.GetBounds(&rect);
128 
129  width = UnScaleGUI(rect.Width());
130  height = UnScaleGUI(rect.Height());
131  xoffs = UnScaleGUI(rect.left);
132  yoffs = UnScaleGUI(rect.top);
133 }
134 
135 void Ship::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
136 {
137  uint8_t spritenum = this->spritenum;
138 
139  if (image_type == EIT_ON_MAP) direction = this->rotation;
140 
141  if (is_custom_sprite(spritenum)) {
142  GetCustomVehicleSprite(this, direction, image_type, result);
143  if (result->IsValid()) return;
144 
146  }
147 
148  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
149  result->Set(_ship_sprites[spritenum] + direction);
150 }
151 
152 static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
153 {
154  const int max_region_distance = (max_distance / WATER_REGION_EDGE_LENGTH) + 1;
155 
156  static std::unordered_set<int> visited_patch_hashes;
157  static std::deque<WaterRegionPatchDesc> patches_to_search;
158  visited_patch_hashes.clear();
159  patches_to_search.clear();
160 
161  /* Step 1: find a set of reachable Water Region Patches using BFS. */
162  const WaterRegionPatchDesc start_patch = GetWaterRegionPatchInfo(v->tile);
163  patches_to_search.push_back(start_patch);
164  visited_patch_hashes.insert(CalculateWaterRegionPatchHash(start_patch));
165 
166  while (!patches_to_search.empty()) {
167  /* Remove first patch from the queue and make it the current patch. */
168  const WaterRegionPatchDesc current_node = patches_to_search.front();
169  patches_to_search.pop_front();
170 
171  /* Add neighbors of the current patch to the search queue. */
172  TVisitWaterRegionPatchCallBack visitFunc = [&](const WaterRegionPatchDesc &water_region_patch) {
173  /* Note that we check the max distance per axis, not the total distance. */
174  if (std::abs(water_region_patch.x - start_patch.x) > max_region_distance ||
175  std::abs(water_region_patch.y - start_patch.y) > max_region_distance) return;
176 
177  const int hash = CalculateWaterRegionPatchHash(water_region_patch);
178  if (visited_patch_hashes.count(hash) == 0) {
179  visited_patch_hashes.insert(hash);
180  patches_to_search.push_back(water_region_patch);
181  }
182  };
183 
184  VisitWaterRegionPatchNeighbors(current_node, visitFunc);
185  }
186 
187  /* Step 2: Find the closest depot within the reachable Water Region Patches. */
188  const Depot *best_depot = nullptr;
189  uint best_dist_sq = std::numeric_limits<uint>::max();
190  for (const Depot *depot : Depot::Iterate()) {
191  const TileIndex tile = depot->xy;
192  if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
193  const uint dist_sq = DistanceSquare(tile, v->tile);
194  if (dist_sq < best_dist_sq && dist_sq <= max_distance * max_distance &&
195  visited_patch_hashes.count(CalculateWaterRegionPatchHash(GetWaterRegionPatchInfo(tile))) > 0) {
196  best_dist_sq = dist_sq;
197  best_depot = depot;
198  }
199  }
200  }
201 
202  return best_depot;
203 }
204 
205 static void CheckIfShipNeedsService(Vehicle *v)
206 {
207  if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
208  if (v->IsChainInDepot()) {
210  return;
211  }
212 
213  uint max_distance;
217  default: NOT_REACHED();
218  }
219 
220  const Depot *depot = FindClosestShipDepot(v, max_distance);
221 
222  if (depot == nullptr) {
223  if (v->current_order.IsType(OT_GOTO_DEPOT)) {
226  }
227  return;
228  }
229 
231  v->SetDestTile(depot->xy);
233 }
234 
239 {
240  const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
241 
242  /* Get speed fraction for the current water type. Aqueducts are always canals. */
243  bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
244  uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
245  this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
246 
247  /* Update cargo aging period. */
248  this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
249 
250  this->UpdateVisualEffect();
251 }
252 
254 {
255  const Engine *e = this->GetEngine();
256  uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
257  return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
258 }
259 
262 {
263  AgeVehicle(this);
264 }
265 
268 {
269  if ((++this->day_counter & 7) == 0) {
270  DecreaseVehicleValue(this);
271  }
272 
273  CheckVehicleBreakdown(this);
274  CheckIfShipNeedsService(this);
275 
276  CheckOrders(this);
277 
278  if (this->running_ticks == 0) return;
279 
281 
282  this->profit_this_year -= cost.GetCost();
283  this->running_ticks = 0;
284 
286 
288  /* we need this for the profit */
290 }
291 
293 {
294  if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
295 
296  if (this->IsInDepot()) {
297  /* We'll assume the ship is facing outwards */
298  return DiagDirToDiagTrackdir(GetShipDepotDirection(this->tile));
299  }
300 
301  if (this->state == TRACK_BIT_WORMHOLE) {
302  /* ship on aqueduct, so just use its direction and assume a diagonal track */
303  return DiagDirToDiagTrackdir(DirToDiagDir(this->direction));
304  }
305 
306  return TrackDirectionToTrackdir(FindFirstTrack(this->state), this->direction);
307 }
308 
310 {
311  this->colourmap = PAL_NONE;
312  this->UpdateViewport(true, false);
313  this->UpdateCache();
314 }
315 
316 void Ship::PlayLeaveStationSound(bool force) const
317 {
318  if (PlayVehicleSound(this, VSE_START, force)) return;
319  SndPlayVehicleFx(ShipVehInfo(this->engine_type)->sfx, this);
320 }
321 
322 TileIndex Ship::GetOrderStationLocation(StationID station)
323 {
324  if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
325 
326  const Station *st = Station::Get(station);
327  if (CanVehicleUseStation(this, st)) {
328  return st->xy;
329  } else {
330  this->IncrementRealOrderIndex();
331  return 0;
332  }
333 }
334 
336 {
337  static const int8_t _delta_xy_table[8][4] = {
338  /* y_extent, x_extent, y_offs, x_offs */
339  { 6, 6, -3, -3}, // N
340  { 6, 32, -3, -16}, // NE
341  { 6, 6, -3, -3}, // E
342  {32, 6, -16, -3}, // SE
343  { 6, 6, -3, -3}, // S
344  { 6, 32, -3, -16}, // SW
345  { 6, 6, -3, -3}, // W
346  {32, 6, -16, -3}, // NW
347  };
348 
349  const int8_t *bb = _delta_xy_table[this->rotation];
350  this->x_offs = bb[3];
351  this->y_offs = bb[2];
352  this->x_extent = bb[1];
353  this->y_extent = bb[0];
354  this->z_extent = 6;
355 
356  if (this->direction != this->rotation) {
357  /* If we are rotating, then it is possible the ship was moved to its next position. In that
358  * case, because we are still showing the old direction, the ship will appear to glitch sideways
359  * slightly. We can work around this by applying an additional offset to make the ship appear
360  * where it was before it moved. */
361  this->x_offs -= this->x_pos - this->rotation_x_pos;
362  this->y_offs -= this->y_pos - this->rotation_y_pos;
363  }
364 }
365 
370 {
371  return v->type == VEH_SHIP && (v->vehstatus & (VS_HIDDEN | VS_STOPPED)) == 0 ? v : nullptr;
372 }
373 
374 static bool CheckReverseShip(const Ship *v, Trackdir *trackdir = nullptr)
375 {
376  /* Ask pathfinder for best direction */
377  bool reverse = false;
379  case VPF_NPF: reverse = NPFShipCheckReverse(v, trackdir); break;
380  case VPF_YAPF: reverse = YapfShipCheckReverse(v, trackdir); break;
381  default: NOT_REACHED();
382  }
383  return reverse;
384 }
385 
386 static bool CheckShipLeaveDepot(Ship *v)
387 {
388  if (!v->IsChainInDepot()) return false;
389 
390  /* Check if we should wait here for unbunching. */
391  if (v->IsWaitingForUnbunching()) return true;
392 
393  /* We are leaving a depot, but have to go to the exact same one; re-enter */
394  if (v->current_order.IsType(OT_GOTO_DEPOT) &&
397  return true;
398  }
399 
400  /* Don't leave depot if no destination set */
401  if (v->dest_tile == 0) return true;
402 
403  /* Don't leave depot if another vehicle is already entering/leaving */
404  /* This helps avoid CPU load if many ships are set to start at the same time */
405  if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoMovingShipProc)) return true;
406 
407  TileIndex tile = v->tile;
408  Axis axis = GetShipDepotAxis(tile);
409 
410  DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
411  TileIndex north_neighbour = TILE_ADD(tile, TileOffsByDiagDir(north_dir));
412  DiagDirection south_dir = AxisToDiagDir(axis);
413  TileIndex south_neighbour = TILE_ADD(tile, 2 * TileOffsByDiagDir(south_dir));
414 
415  TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
416  TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
417  if (north_tracks && south_tracks) {
418  if (CheckReverseShip(v)) north_tracks = TRACK_BIT_NONE;
419  }
420 
421  if (north_tracks) {
422  /* Leave towards north */
423  v->rotation = v->direction = DiagDirToDir(north_dir);
424  } else if (south_tracks) {
425  /* Leave towards south */
426  v->rotation = v->direction = DiagDirToDir(south_dir);
427  } else {
428  /* Both ways blocked */
429  return false;
430  }
431 
432  v->state = AxisToTrackBits(axis);
433  v->vehstatus &= ~VS_HIDDEN;
434 
435  v->cur_speed = 0;
436  v->UpdateViewport(true, true);
438 
441  v->PlayLeaveStationSound();
444 
445  return false;
446 }
447 
453 static uint ShipAccelerate(Vehicle *v)
454 {
455  uint speed;
456  speed = std::min<uint>(v->cur_speed + v->acceleration, v->vcache.cached_max_speed);
457  speed = std::min<uint>(speed, v->current_order.GetMaxSpeed() * 2);
458 
459  /* updates statusbar only if speed have changed to save CPU time */
460  if (speed != v->cur_speed) {
461  v->cur_speed = speed;
463  }
464 
465  const uint advance_speed = v->GetAdvanceSpeed(speed);
466  const uint number_of_steps = (advance_speed + v->progress) / v->GetAdvanceDistance();
467  const uint remainder = (advance_speed + v->progress) % v->GetAdvanceDistance();
468  assert(remainder <= std::numeric_limits<byte>::max());
469  v->progress = static_cast<byte>(remainder);
470  return number_of_steps;
471 }
472 
478 static void ShipArrivesAt(const Vehicle *v, Station *st)
479 {
480  /* Check if station was ever visited before */
481  if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
482  st->had_vehicle_of_type |= HVOT_SHIP;
483 
484  SetDParam(0, st->index);
486  STR_NEWS_FIRST_SHIP_ARRIVAL,
488  v->index,
489  st->index
490  );
491  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
492  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
493  }
494 }
495 
496 
506 static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
507 {
508  assert(IsValidDiagDirection(enterdir));
509 
510  bool path_found = true;
511  Track track;
512 
513  if (v->dest_tile == 0) {
514  /* No destination, don't invoke pathfinder. */
515  track = TrackBitsToTrack(v->state);
516  if (!IsDiagonalTrack(track)) track = TrackToOppositeTrack(track);
517  if (!HasBit(tracks, track)) track = FindFirstTrack(tracks);
518  path_found = false;
519  } else {
520  /* Attempt to follow cached path. */
521  if (!v->path.empty()) {
522  track = TrackdirToTrack(v->path.front());
523 
524  if (HasBit(tracks, track)) {
525  v->path.pop_front();
526  /* HandlePathfindResult() is not called here because this is not a new pathfinder result. */
527  return track;
528  }
529 
530  /* Cached path is invalid so continue with pathfinder. */
531  v->path.clear();
532  }
533 
535  case VPF_NPF: track = NPFShipChooseTrack(v, path_found); break;
536  case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found, v->path); break;
537  default: NOT_REACHED();
538  }
539  }
540 
541  v->HandlePathfindingResult(path_found);
542  return track;
543 }
544 
552 {
553  TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
554 
555  return tracks;
556 }
557 
560  byte x_subcoord;
561  byte y_subcoord;
563 };
570  // DIAGDIR_NE
571  {
572  {15, 8, DIR_NE}, // TRACK_X
573  { 0, 0, INVALID_DIR}, // TRACK_Y
574  { 0, 0, INVALID_DIR}, // TRACK_UPPER
575  {15, 8, DIR_E}, // TRACK_LOWER
576  {15, 7, DIR_N}, // TRACK_LEFT
577  { 0, 0, INVALID_DIR}, // TRACK_RIGHT
578  },
579  // DIAGDIR_SE
580  {
581  { 0, 0, INVALID_DIR}, // TRACK_X
582  { 8, 0, DIR_SE}, // TRACK_Y
583  { 7, 0, DIR_E}, // TRACK_UPPER
584  { 0, 0, INVALID_DIR}, // TRACK_LOWER
585  { 8, 0, DIR_S}, // TRACK_LEFT
586  { 0, 0, INVALID_DIR}, // TRACK_RIGHT
587  },
588  // DIAGDIR_SW
589  {
590  { 0, 8, DIR_SW}, // TRACK_X
591  { 0, 0, INVALID_DIR}, // TRACK_Y
592  { 0, 7, DIR_W}, // TRACK_UPPER
593  { 0, 0, INVALID_DIR}, // TRACK_LOWER
594  { 0, 0, INVALID_DIR}, // TRACK_LEFT
595  { 0, 8, DIR_S}, // TRACK_RIGHT
596  },
597  // DIAGDIR_NW
598  {
599  { 0, 0, INVALID_DIR}, // TRACK_X
600  { 8, 15, DIR_NW}, // TRACK_Y
601  { 0, 0, INVALID_DIR}, // TRACK_UPPER
602  { 8, 15, DIR_W}, // TRACK_LOWER
603  { 0, 0, INVALID_DIR}, // TRACK_LEFT
604  { 7, 15, DIR_N}, // TRACK_RIGHT
605  }
606 };
607 
613 static int ShipTestUpDownOnLock(const Ship *v)
614 {
615  /* Suitable tile? */
616  if (!IsTileType(v->tile, MP_WATER) || !IsLock(v->tile) || GetLockPart(v->tile) != LOCK_PART_MIDDLE) return 0;
617 
618  /* Must be at the centre of the lock */
619  if ((v->x_pos & 0xF) != 8 || (v->y_pos & 0xF) != 8) return 0;
620 
622  assert(IsValidDiagDirection(diagdir));
623 
624  if (DirToDiagDir(v->direction) == diagdir) {
625  /* Move up */
626  return (v->z_pos < GetTileMaxZ(v->tile) * (int)TILE_HEIGHT) ? 1 : 0;
627  } else {
628  /* Move down */
629  return (v->z_pos > GetTileZ(v->tile) * (int)TILE_HEIGHT) ? -1 : 0;
630  }
631 }
632 
638 static bool ShipMoveUpDownOnLock(Ship *v)
639 {
640  /* Moving up/down through lock */
641  int dz = ShipTestUpDownOnLock(v);
642  if (dz == 0) return false;
643 
644  if (v->cur_speed != 0) {
645  v->cur_speed = 0;
647  }
648 
649  if ((v->tick_counter & 7) == 0) {
650  v->z_pos += dz;
651  v->UpdatePosition();
652  v->UpdateViewport(true, true);
653  }
654 
655  return true;
656 }
657 
664 bool IsShipDestinationTile(TileIndex tile, StationID station)
665 {
666  assert(IsDockingTile(tile));
667  /* Check each tile adjacent to docking tile. */
668  for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
669  TileIndex t = tile + TileOffsByDiagDir(d);
670  if (!IsValidTile(t)) continue;
671  if (IsDockTile(t) && GetStationIndex(t) == station && IsDockWaterPart(t)) return true;
672  if (IsTileType(t, MP_INDUSTRY)) {
673  const Industry *i = Industry::GetByTile(t);
674  if (i->neutral_station != nullptr && i->neutral_station->index == station) return true;
675  }
676  if (IsTileType(t, MP_STATION) && IsOilRig(t) && GetStationIndex(t) == station) return true;
677  }
678  return false;
679 }
680 
681 static void ReverseShipIntoTrackdir(Ship *v, Trackdir trackdir)
682 {
683  static constexpr Direction _trackdir_to_direction[] = {
686  };
687 
688  v->direction = _trackdir_to_direction[trackdir];
689  assert(v->direction != INVALID_DIR);
691 
692  /* Remember our current location to avoid movement glitch */
693  v->rotation_x_pos = v->x_pos;
694  v->rotation_y_pos = v->y_pos;
695  v->cur_speed = 0;
696  v->path.clear();
697 
698  v->UpdatePosition();
699  v->UpdateViewport(true, true);
700 }
701 
702 static void ReverseShip(Ship *v)
703 {
704  v->direction = ReverseDir(v->direction);
705 
706  /* Remember our current location to avoid movement glitch */
707  v->rotation_x_pos = v->x_pos;
708  v->rotation_y_pos = v->y_pos;
709  v->cur_speed = 0;
710  v->path.clear();
711 
712  v->UpdatePosition();
713  v->UpdateViewport(true, true);
714 }
715 
716 static void ShipController(Ship *v)
717 {
718  v->tick_counter++;
719  v->current_order_time++;
720 
721  if (v->HandleBreakdown()) return;
722 
723  if (v->vehstatus & VS_STOPPED) return;
724 
725  if (ProcessOrders(v) && CheckReverseShip(v)) return ReverseShip(v);
726 
727  v->HandleLoading();
728 
729  if (v->current_order.IsType(OT_LOADING)) return;
730 
731  if (CheckShipLeaveDepot(v)) return;
732 
733  v->ShowVisualEffect();
734 
735  /* Rotating on spot */
736  if (v->direction != v->rotation) {
737  if ((v->tick_counter & 7) == 0) {
738  DirDiff diff = DirDifference(v->direction, v->rotation);
740  /* Invalidate the sprite cache direction to force recalculation of viewport */
742  v->UpdateViewport(true, true);
743  }
744  return;
745  }
746 
747  if (ShipMoveUpDownOnLock(v)) return;
748 
749  const uint number_of_steps = ShipAccelerate(v);
750  for (uint i = 0; i < number_of_steps; ++i) {
751  if (ShipMoveUpDownOnLock(v)) return;
752 
754  if (v->state != TRACK_BIT_WORMHOLE) {
755  /* Not on a bridge */
756  if (gp.old_tile == gp.new_tile) {
757  /* Staying in tile */
758  if (v->IsInDepot()) {
759  gp.x = v->x_pos;
760  gp.y = v->y_pos;
761  } else {
762  /* Not inside depot */
763  const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
764  if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
765 
766  /* A leave station order only needs one tick to get processed, so we can
767  * always skip ahead. */
768  if (v->current_order.IsType(OT_LEAVESTATION)) {
769  v->current_order.Free();
771  /* Test if continuing forward would lead to a dead-end, moving into the dock. */
772  const DiagDirection exitdir = VehicleExitDir(v->direction, v->state);
773  const TileIndex tile = TileAddByDiagDir(v->tile, exitdir);
774  if (TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0, exitdir)) == TRACK_BIT_NONE) return ReverseShip(v);
775  } else if (v->dest_tile != 0) {
776  /* We have a target, let's see if we reached it... */
777  if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
778  DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
779  /* We got within 3 tiles of our target buoy, so let's skip to our
780  * next order */
781  UpdateVehicleTimetable(v, true);
784  } else if (v->current_order.IsType(OT_GOTO_DEPOT) &&
785  v->dest_tile == gp.new_tile) {
786  /* Depot orders really need to reach the tile */
787  if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
789  return;
790  }
791  } else if (v->current_order.IsType(OT_GOTO_STATION) && IsDockingTile(gp.new_tile)) {
792  /* Process station in the orderlist. */
795  v->last_station_visited = st->index;
796  if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
797  ShipArrivesAt(v, st);
798  v->BeginLoading();
799  } else { // leave stations without docks right away
802  }
803  }
804  }
805  }
806  }
807  } else {
808  /* New tile */
809  if (!IsValidTile(gp.new_tile)) return ReverseShip(v);
810 
811  const DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
812  assert(diagdir != INVALID_DIAGDIR);
813  const TrackBits tracks = GetAvailShipTracks(gp.new_tile, diagdir);
814  if (tracks == TRACK_BIT_NONE) {
815  Trackdir trackdir = INVALID_TRACKDIR;
816  CheckReverseShip(v, &trackdir);
817  if (trackdir == INVALID_TRACKDIR) return ReverseShip(v);
818  return ReverseShipIntoTrackdir(v, trackdir);
819  }
820 
821  /* Choose a direction, and continue if we find one */
822  const Track track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
823  if (track == INVALID_TRACK) return ReverseShip(v);
824 
825  const ShipSubcoordData &b = _ship_subcoord[diagdir][track];
826 
827  gp.x = (gp.x & ~0xF) | b.x_subcoord;
828  gp.y = (gp.y & ~0xF) | b.y_subcoord;
829 
830  /* Call the landscape function and tell it that the vehicle entered the tile */
831  const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
832  if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
833 
834  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
835  v->tile = gp.new_tile;
836  v->state = TrackToTrackBits(track);
837 
838  /* Update ship cache when the water class changes. Aqueducts are always canals. */
840  }
841 
842  const Direction new_direction = b.dir;
843  const DirDiff diff = DirDifference(new_direction, v->direction);
844  switch (diff) {
845  case DIRDIFF_SAME:
846  case DIRDIFF_45RIGHT:
847  case DIRDIFF_45LEFT:
848  /* Continue at speed */
849  v->rotation = v->direction = new_direction;
850  break;
851 
852  default:
853  /* Stop for rotation */
854  v->cur_speed = 0;
855  v->direction = new_direction;
856  /* Remember our current location to avoid movement glitch */
857  v->rotation_x_pos = v->x_pos;
858  v->rotation_y_pos = v->y_pos;
859  break;
860  }
861  }
862  } else {
863  /* On a bridge */
865  v->x_pos = gp.x;
866  v->y_pos = gp.y;
867  v->UpdatePosition();
868  if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
869  return;
870  }
871 
872  /* Ship is back on the bridge head, we need to consume its path
873  * cache entry here as we didn't have to choose a ship track. */
874  if (!v->path.empty()) v->path.pop_front();
875  }
876 
877  /* update image of ship, as well as delta XY */
878  v->x_pos = gp.x;
879  v->y_pos = gp.y;
880 
881  v->UpdatePosition();
882  v->UpdateViewport(true, true);
883  }
884 }
885 
887 {
889 
890  if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
891 
892  ShipController(this);
893 
894  return true;
895 }
896 
897 void Ship::SetDestTile(TileIndex tile)
898 {
899  if (tile == this->dest_tile) return;
900  this->path.clear();
901  this->dest_tile = tile;
902 }
903 
913 {
914  tile = GetShipDepotNorthTile(tile);
915  if (flags & DC_EXEC) {
916  int x;
917  int y;
918 
919  const ShipVehicleInfo *svi = &e->u.ship;
920 
921  Ship *v = new Ship();
922  *ret = v;
923 
924  v->owner = _current_company;
925  v->tile = tile;
926  x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
927  y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
928  v->x_pos = x;
929  v->y_pos = y;
930  v->z_pos = GetSlopePixelZ(x, y);
931 
932  v->UpdateDeltaXY();
934 
935  v->spritenum = svi->image_index;
937  v->cargo_cap = svi->capacity;
938  v->refit_cap = 0;
939 
940  v->last_station_visited = INVALID_STATION;
941  v->last_loading_station = INVALID_STATION;
942  v->engine_type = e->index;
943 
944  v->reliability = e->reliability;
946  v->max_age = e->GetLifeLengthInDays();
947 
948  v->state = TRACK_BIT_DEPOT;
949 
950  v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships);
954  v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
955  v->random_bits = Random();
956 
957  v->acceleration = svi->acceleration;
958  v->UpdateCache();
959 
961  v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
962 
964 
965  v->cargo_cap = e->DetermineCapacity(v);
966 
968 
969  v->UpdatePosition();
970  }
971 
972  return CommandCost();
973 }
974 
976 {
977  const Depot *depot = FindClosestShipDepot(this, MAX_SHIP_DEPOT_SEARCH_DISTANCE);
978  if (depot == nullptr) return ClosestDepot();
979 
980  return ClosestDepot(depot->xy, depot->index);
981 }
VSE_START
@ VSE_START
Vehicle starting, i.e. leaving, the station.
Definition: newgrf_sound.h:19
game.hpp
ChooseShipTrack
static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
Runs the pathfinder to choose a track to continue along.
Definition: ship_cmd.cpp:506
DiagdirReachesTracks
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:573
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
Vehicle::IsChainInDepot
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:549
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
TRACK_BIT_WORMHOLE
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:52
PathfinderSettings::npf
NPFSettings npf
pathfinder settings for the new pathfinder
Definition: settings_type.h:500
ShipTestUpDownOnLock
static int ShipTestUpDownOnLock(const Ship *v)
Test if a ship is in the centre of a lock and should move up or down.
Definition: ship_cmd.cpp:613
TILE_ADD
#define TILE_ADD(x, y)
Adds two tiles together.
Definition: map_func.h:466
Station::docking_station
TileArea docking_station
Tile area the docking tiles cover.
Definition: station_base.h:458
ReverseDir
Direction ReverseDir(Direction d)
Return the reverse of a direction.
Definition: direction_func.h:54
DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
Ship::GetRunningCost
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:253
Order::MakeDummy
void MakeDummy()
Makes this order a Dummy order.
Definition: order_cmd.cpp:133
sound_func.h
UpdateVehicleTimetable
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
Definition: timetable_cmd.cpp:469
MutableSpriteCache::last_direction
Direction last_direction
Last direction we obtained sprites for.
Definition: vehicle_base.h:192
FindFirstTrack
Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:177
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:36
DIRDIFF_REVERSE
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
Definition: direction_type.h:62
VehicleCache::cached_cargo_age_period
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:125
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
Ship::IsInDepot
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition: ship.h:46
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:196
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:970
Vehicle::reliability_spd_dec
uint16_t reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:293
NT_ARRIVAL_OTHER
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
Definition: news_type.h:25
DIRDIFF_45LEFT
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
Definition: direction_type.h:64
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
ODTFB_SERVICE
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
Definition: order_type.h:95
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:338
HasVehicleOnPos
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:520
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition: water_map.h:115
CheckOrders
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Definition: order_cmd.cpp:1716
WaterRegionPatchDesc
Describes a single interconnected patch of water within a particular water region.
Definition: water_regions.h:25
Order::MakeLeaveStation
void MakeLeaveStation()
Makes this order a Leave Station order.
Definition: order_cmd.cpp:124
Ship::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:292
GetLockPart
byte GetLockPart(Tile t)
Get the part of a lock.
Definition: water_map.h:329
company_base.h
Engine::reliability_spd_dec
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:42
tunnelbridge_map.h
timer_game_calendar.h
DIRDIFF_SAME
@ DIRDIFF_SAME
Both directions faces to the same direction.
Definition: direction_type.h:59
Vehicle::y_extent
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:312
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
Station
Station data structure.
Definition: station_base.h:442
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
Vehicle::NeedsAutomaticServicing
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition: vehicle.cpp:272
TrackdirToTrack
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:262
Engine::GetLifeLengthInDays
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:441
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:164
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
Ship::path
ShipPathCache path
Cached path.
Definition: ship.h:26
TrackdirToTrackdirBits
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:111
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
VPF_YAPF
@ VPF_YAPF
Yet Another PathFinder.
Definition: vehicle_type.h:60
VS_DEFPAL
@ VS_DEFPAL
Use default vehicle palette.
Definition: vehicle_base.h:36
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
Vehicle::acceleration
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:325
Order::Free
void Free()
'Free' the order
Definition: order_cmd.cpp:63
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
ship.h
Ship::rotation
Direction rotation
Visible direction.
Definition: ship.h:27
IsOilRig
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
Definition: station_map.h:275
BaseConsist::vehicle_flags
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:34
CmdBuildShip
CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build a ship.
Definition: ship_cmd.cpp:912
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
WaterRegionPatchDesc::y
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Definition: water_regions.h:28
zoom_func.h
WID_VV_START_STOP
@ WID_VV_START_STOP
Start or stop this vehicle, and show information about the current state.
Definition: vehicle_widget.h:17
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Vehicle::running_ticks
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:346
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
VehicleEnterDepot
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
Definition: vehicle.cpp:1534
BaseConsist::current_order_time
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:21
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
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
ShipAccelerate
static uint ShipAccelerate(Vehicle *v)
Accelerates the ship towards its target speed.
Definition: ship_cmd.cpp:453
ChangeDir
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
Definition: direction_func.h:104
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Engine
Definition: engine_base.h:37
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:96
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:131
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:304
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:299
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26
GetAvailShipTracks
static TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir)
Get the available water tracks on a tile for a ship entering a tile.
Definition: ship_cmd.cpp:551
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
VehicleServiceInDepot
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
Definition: vehicle.cpp:167
IsLock
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition: water_map.h:306
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:98
TrackToTrackBits
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:77
ShipSubcoordData::x_subcoord
byte x_subcoord
New X sub-coordinate on the new tile.
Definition: ship_cmd.cpp:560
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:299
industry_map.h
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:556
ai.hpp
ShipSubcoordData
Structure for ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
Definition: ship_cmd.cpp:559
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:238
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:167
Vehicle::date_of_last_service
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
Definition: vehicle_base.h:290
NT_ARRIVAL_COMPANY
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
Definition: news_type.h:24
ENGINE_EXCLUSIVE_PREVIEW
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
Definition: engine_type.h:183
VehicleCache::cached_max_speed
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:124
Engine::DetermineCapacity
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:201
Vehicle::BeginLoading
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition: vehicle.cpp:2171
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:625
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
GetWaterRegionPatchInfo
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
Definition: water_regions.cpp:269
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:33
depot_base.h
Vehicle::UpdateVisualEffect
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
Definition: vehicle.cpp:2586
DirDifference
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Definition: direction_func.h:68
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:267
Ship::OnNewEconomyDay
void OnNewEconomyDay() override
Economy day handler.
Definition: ship_cmd.cpp:267
Vehicle::HandlePathfindingResult
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition: vehicle.cpp:791
timetable.h
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:235
ship_cmd.h
CommandCost
Common return value for all commands.
Definition: command_type.h:23
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:339
newgrf_engine.h
Vehicle::IsWaitingForUnbunching
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Definition: vehicle.cpp:2478
yapf_ship_regions.h
TrackBitsToTrack
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:193
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
YapfShipChooseTrack
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache)
Finds the best path for given ship using YAPF.
Definition: yapf_ship.cpp:431
YAPF_TILE_LENGTH
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Definition: pathfinder_type.h:29
SubtractMoneyFromCompanyFract
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
Definition: company_cmd.cpp:297
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
npf_func.h
EIT_ON_MAP
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition: vehicle_type.h:86
Vehicle::random_bits
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition: vehicle_base.h:329
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:318
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
VETS_CANNOT_ENTER
@ VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:24
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:131
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:332
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
PFE_GL_SHIPS
@ PFE_GL_SHIPS
Time spent processing ships.
Definition: framerate_type.h:53
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:349
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
IsShipDepotTile
bool IsShipDepotTile(Tile t)
Is it a ship depot tile?
Definition: water_map.h:235
DiagDirToDir
Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
Definition: direction_func.h:182
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition: vehicle_base.h:323
LOCK_PART_MIDDLE
@ LOCK_PART_MIDDLE
Middle part of a lock.
Definition: water_map.h:74
Ship::FindClosestDepot
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: ship_cmd.cpp:975
Ship::rotation_y_pos
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:29
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:287
HVOT_SHIP
@ HVOT_SHIP
Station has seen a ship.
Definition: station_type.h:68
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:200
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:147
TrackdirBitsToTrackBits
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:308
YapfShipCheckReverse
bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
Returns true if it is better to reverse the ship before leaving depot using YAPF.
Definition: yapf_ship.cpp:437
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:34
Vehicle::ShowVisualEffect
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition: vehicle.cpp:2709
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
PROP_SHIP_CARGO_AGE_PERIOD
@ PROP_SHIP_CARGO_AGE_PERIOD
Number of ticks before carried cargo is aged.
Definition: newgrf_properties.h:47
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:747
VehicleEnterTile
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition: vehicle.cpp:1813
industry.h
safeguards.h
VehicleExitDir
DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:714
GetNewVehiclePosResult::new_tile
TileIndex new_tile
Tile of the vehicle after moving.
Definition: vehicle_func.h:78
Vehicle::last_loading_station
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Definition: vehicle_base.h:333
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:320
DirToDiagDir
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
DIR_S
@ DIR_S
South.
Definition: direction_type.h:30
Vehicle::profit_this_year
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:269
VisitWaterRegionPatchNeighbors
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...
Definition: water_regions.cpp:340
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
GetShipDepotDirection
DiagDirection GetShipDepotDirection(Tile t)
Get the direction of the ship depot.
Definition: water_map.h:270
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:80
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
DirDiff
DirDiff
Allow incrementing of Direction variables.
Definition: direction_type.h:58
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
Vehicle::HandleLoading
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
Definition: vehicle.cpp:2389
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
GetShipSpriteSize
void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a ship sprite heading west (used for lists).
Definition: ship_cmd.cpp:121
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:363
stdafx.h
ShipSubcoordData::dir
Direction dir
New Direction to move in on the new track.
Definition: ship_cmd.cpp:562
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:363
landscape.h
VPF_NPF
@ VPF_NPF
New PathFinder.
Definition: vehicle_type.h:59
GetDepotIndex
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
CalculateWaterRegionPatchHash
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
Definition: water_regions.cpp:241
AddVehicleNewsItem
void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
Definition: news_func.h:30
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition: engine_base.h:41
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
Vehicle::colourmap
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:284
PROP_SHIP_RUNNING_COST_FACTOR
@ PROP_SHIP_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:46
HasTileWaterClass
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:104
Vehicle::IncrementRealOrderIndex
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
Definition: vehicle_base.h:872
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:301
VF_BUILT_AS_PROTOTYPE
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:47
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
RAIL_GROUND_WATER
@ RAIL_GROUND_WATER
Grass with a fence and shore or water on the free halftile.
Definition: rail_map.h:499
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:302
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:53
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:176
TRACK_END
@ TRACK_END
Used for iterations.
Definition: track_type.h:27
PerformanceAccumulator
RAII class for measuring multi-step elements of performance.
Definition: framerate_type.h:114
ProcessOrders
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Definition: order_cmd.cpp:2132
spritecache.h
Vehicle::x_extent
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:311
IsValidDiagDirection
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:361
Ship
All ships have this type.
Definition: ship.h:24
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
station_base.h
newgrf_sound.h
DiagdirBetweenTiles
DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
Definition: map_func.h:616
Pool::PoolItem<&_depot_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
strings_func.h
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:664
IsDiagonalTrack
bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:619
Vehicle::max_age
TimerGameCalendar::Date max_age
Maximum age.
Definition: vehicle_base.h:289
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:345
yapf.h
MAX_SHIP_DEPOT_SEARCH_DISTANCE
constexpr int MAX_SHIP_DEPOT_SEARCH_DISTANCE
Max distance in tiles (as the crow flies) to search for depots when user clicks "go to depot".
Definition: ship_cmd.cpp:48
_ship_subcoord
static const ShipSubcoordData _ship_subcoord[DIAGDIR_END][TRACK_END]
Ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
Definition: ship_cmd.cpp:569
IsDockingTile
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:374
Vehicle::GetAdvanceSpeed
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Definition: vehicle_base.h:440
Vehicle::x_offs
int8_t x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:316
Ship::MarkDirty
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:309
DIRDIFF_45RIGHT
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
Definition: direction_type.h:60
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
Vehicle::z_extent
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:313
Vehicle::date_of_last_service_newgrf
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
Definition: vehicle_base.h:291
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:499
Ship::Tick
bool Tick() override
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:886
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
framerate_type.h
EnsureNoMovingShipProc
static Vehicle * EnsureNoMovingShipProc(Vehicle *v, void *)
Test-procedure for HasVehicleOnPos to check for any ships which are visible and not stopped by the pl...
Definition: ship_cmd.cpp:369
ShipVehicleInfo::acceleration
uint8_t acceleration
Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick)
Definition: engine_type.h:70
Vehicle::reliability
uint16_t reliability
Reliability.
Definition: vehicle_base.h:292
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:25
GetNewVehiclePosResult
Position information of a vehicle after it moved.
Definition: vehicle_func.h:75
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:351
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
NPF_TILE_LENGTH
static const int NPF_TILE_LENGTH
Length (penalty) of one tile with NPF.
Definition: pathfinder_type.h:17
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile 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
ShipVehicleInfo
Information about a ship vehicle.
Definition: engine_type.h:67
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:74
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
company_func.h
NPFShipChooseTrack
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
Definition: npf.cpp:1191
ShipArrivesAt
static void ShipArrivesAt(const Vehicle *v, Station *st)
Ship arrives at a dock.
Definition: ship_cmd.cpp:478
Order::GetMaxSpeed
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:202
GetNewVehiclePosResult::old_tile
TileIndex old_tile
Current tile of the vehicle.
Definition: vehicle_func.h:77
IsDockWaterPart
bool IsDockWaterPart(Tile t)
Check whether a dock tile is the tile on water.
Definition: station_map.h:512
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:300
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition: vehicle_base.h:226
PlayVehicleSound
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
Definition: newgrf_sound.cpp:187
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
GetShipDepotNorthTile
TileIndex GetShipDepotNorthTile(Tile t)
Get the most northern tile of a ship depot.
Definition: water_map.h:292
UnScaleGUI
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
Vehicle::day_counter
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:344
window_func.h
Depot
Definition: depot_base.h:20
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
ShipMoveUpDownOnLock
static bool ShipMoveUpDownOnLock(Ship *v)
Test and move a ship up or down in a lock.
Definition: ship_cmd.cpp:638
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition: settings_type.h:501
AgeVehicle
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
Definition: vehicle.cpp:1423
Vehicle::progress
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:327
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
OverflowSafeInt< int64_t >
engine_base.h
Ship::OnNewCalendarDay
void OnNewCalendarDay() override
Calendar day handler.
Definition: ship_cmd.cpp:261
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
ShipVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition: engine_type.h:71
Engine::original_image_index
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:55
NPFShipCheckReverse
bool NPFShipCheckReverse(const Ship *v, Trackdir *best_td)
Returns true if it is better to reverse the ship before leaving depot using NPF.
Definition: npf.cpp:1212
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:310
AxisToTrackBits
TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:88
Ship::UpdateDeltaXY
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:335
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
IsDockTile
bool IsDockTile(Tile t)
Is tile t a dock tile?
Definition: station_map.h:296
PROP_SHIP_SPEED
@ PROP_SHIP_SPEED
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
Definition: newgrf_properties.h:44
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:48
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
TrackDirectionToTrackdir
Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
Maps a track and a full (8-way) direction to the trackdir that represents the track running in the gi...
Definition: track_func.h:498
Vehicle::GetAdvanceDistance
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Definition: vehicle_base.h:452
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
NPFSettings::maximum_go_to_depot_penalty
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Definition: settings_type.h:420
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1668
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:49
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition: direction_type.h:35
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2980
Vehicle::HandleBreakdown
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Definition: vehicle.cpp:1357
DecreaseVehicleValue
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
Definition: vehicle.cpp:1295
GetNewVehiclePosResult::y
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:76
PathfinderSettings::pathfinder_for_ships
uint8_t pathfinder_for_ships
the pathfinder to use for ships
Definition: settings_type.h:486
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
ShipSubcoordData::y_subcoord
byte y_subcoord
New Y sub-coordinate on the new tile.
Definition: ship_cmd.cpp:561
GetShipDepotAxis
Axis GetShipDepotAxis(Tile t)
Get the axis of the ship depot.
Definition: water_map.h:246
TimerGameConst< struct Calendar >::DAYS_IN_YEAR
static constexpr int DAYS_IN_YEAR
days per year
Definition: timer_game_common.h:149
IsTileOwner
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3108
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:103
DiagDirToDiagTrackdir
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:537
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3095
Order::MakeGoToDepot
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:90
ShipVehicleInfo::ApplyWaterClassSpeedFrac
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition: engine_type.h:81
TileAddByDiagDir
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:604
SpecializedVehicle< Ship, VEH_SHIP >::UpdateViewport
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Definition: vehicle_base.h:1223
GetInclinedSlopeDirection
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
Vehicle::LeaveUnbunchingDepot
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
Definition: vehicle.cpp:2435
Ship::rotation_x_pos
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:28
GetEffectiveWaterClass
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:55
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:178
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:21
timer_game_economy.h
Vehicle::y_offs
int8_t y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:317
OrthogonalTileArea::Contains
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
Definition: tilearea.cpp:104
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:339
GetNewVehiclePos
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
Definition: vehicle.cpp:1759
YAPFSettings::maximum_go_to_depot_penalty
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Definition: settings_type.h:444
WaterRegionPatchDesc::x
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
Definition: water_regions.h:27
news_func.h
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
VETS_ENTERED_WORMHOLE
@ VETS_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:23
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37
TrackToOppositeTrack
Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
Definition: track_func.h:231
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103