OpenTTD Source  14.0-RC3
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  EconomyAgeVehicle(this);
270 
271  if ((++this->day_counter & 7) == 0) {
272  DecreaseVehicleValue(this);
273  }
274 
275  CheckVehicleBreakdown(this);
276  CheckIfShipNeedsService(this);
277 
278  CheckOrders(this);
279 
280  if (this->running_ticks == 0) return;
281 
283 
284  this->profit_this_year -= cost.GetCost();
285  this->running_ticks = 0;
286 
288 
290  /* we need this for the profit */
292 }
293 
295 {
296  if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
297 
298  if (this->IsInDepot()) {
299  /* We'll assume the ship is facing outwards */
300  return DiagDirToDiagTrackdir(GetShipDepotDirection(this->tile));
301  }
302 
303  if (this->state == TRACK_BIT_WORMHOLE) {
304  /* ship on aqueduct, so just use its direction and assume a diagonal track */
305  return DiagDirToDiagTrackdir(DirToDiagDir(this->direction));
306  }
307 
308  return TrackDirectionToTrackdir(FindFirstTrack(this->state), this->direction);
309 }
310 
312 {
313  this->colourmap = PAL_NONE;
314  this->UpdateViewport(true, false);
315  this->UpdateCache();
316 }
317 
318 void Ship::PlayLeaveStationSound(bool force) const
319 {
320  if (PlayVehicleSound(this, VSE_START, force)) return;
321  SndPlayVehicleFx(ShipVehInfo(this->engine_type)->sfx, this);
322 }
323 
324 TileIndex Ship::GetOrderStationLocation(StationID station)
325 {
326  if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
327 
328  const Station *st = Station::Get(station);
329  if (CanVehicleUseStation(this, st)) {
330  return st->xy;
331  } else {
332  this->IncrementRealOrderIndex();
333  return 0;
334  }
335 }
336 
338 {
339  static const int8_t _delta_xy_table[8][4] = {
340  /* y_extent, x_extent, y_offs, x_offs */
341  { 6, 6, -3, -3}, // N
342  { 6, 32, -3, -16}, // NE
343  { 6, 6, -3, -3}, // E
344  {32, 6, -16, -3}, // SE
345  { 6, 6, -3, -3}, // S
346  { 6, 32, -3, -16}, // SW
347  { 6, 6, -3, -3}, // W
348  {32, 6, -16, -3}, // NW
349  };
350 
351  const int8_t *bb = _delta_xy_table[this->rotation];
352  this->x_offs = bb[3];
353  this->y_offs = bb[2];
354  this->x_extent = bb[1];
355  this->y_extent = bb[0];
356  this->z_extent = 6;
357 
358  if (this->direction != this->rotation) {
359  /* If we are rotating, then it is possible the ship was moved to its next position. In that
360  * case, because we are still showing the old direction, the ship will appear to glitch sideways
361  * slightly. We can work around this by applying an additional offset to make the ship appear
362  * where it was before it moved. */
363  this->x_offs -= this->x_pos - this->rotation_x_pos;
364  this->y_offs -= this->y_pos - this->rotation_y_pos;
365  }
366 }
367 
372 {
373  return v->type == VEH_SHIP && (v->vehstatus & (VS_HIDDEN | VS_STOPPED)) == 0 ? v : nullptr;
374 }
375 
376 static bool CheckReverseShip(const Ship *v, Trackdir *trackdir = nullptr)
377 {
378  /* Ask pathfinder for best direction */
379  bool reverse = false;
381  case VPF_NPF: reverse = NPFShipCheckReverse(v, trackdir); break;
382  case VPF_YAPF: reverse = YapfShipCheckReverse(v, trackdir); break;
383  default: NOT_REACHED();
384  }
385  return reverse;
386 }
387 
388 static bool CheckShipLeaveDepot(Ship *v)
389 {
390  if (!v->IsChainInDepot()) return false;
391 
392  /* Check if we should wait here for unbunching. */
393  if (v->IsWaitingForUnbunching()) return true;
394 
395  /* We are leaving a depot, but have to go to the exact same one; re-enter */
396  if (v->current_order.IsType(OT_GOTO_DEPOT) &&
399  return true;
400  }
401 
402  /* Don't leave depot if no destination set */
403  if (v->dest_tile == 0) return true;
404 
405  /* Don't leave depot if another vehicle is already entering/leaving */
406  /* This helps avoid CPU load if many ships are set to start at the same time */
407  if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoMovingShipProc)) return true;
408 
409  TileIndex tile = v->tile;
410  Axis axis = GetShipDepotAxis(tile);
411 
412  DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
413  TileIndex north_neighbour = TILE_ADD(tile, TileOffsByDiagDir(north_dir));
414  DiagDirection south_dir = AxisToDiagDir(axis);
415  TileIndex south_neighbour = TILE_ADD(tile, 2 * TileOffsByDiagDir(south_dir));
416 
417  TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
418  TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
419  if (north_tracks && south_tracks) {
420  if (CheckReverseShip(v)) north_tracks = TRACK_BIT_NONE;
421  }
422 
423  if (north_tracks) {
424  /* Leave towards north */
425  v->rotation = v->direction = DiagDirToDir(north_dir);
426  } else if (south_tracks) {
427  /* Leave towards south */
428  v->rotation = v->direction = DiagDirToDir(south_dir);
429  } else {
430  /* Both ways blocked */
431  return false;
432  }
433 
434  v->state = AxisToTrackBits(axis);
435  v->vehstatus &= ~VS_HIDDEN;
436 
437  v->cur_speed = 0;
438  v->UpdateViewport(true, true);
440 
443  v->PlayLeaveStationSound();
446 
447  return false;
448 }
449 
455 static uint ShipAccelerate(Vehicle *v)
456 {
457  uint speed;
458  speed = std::min<uint>(v->cur_speed + v->acceleration, v->vcache.cached_max_speed);
459  speed = std::min<uint>(speed, v->current_order.GetMaxSpeed() * 2);
460 
461  /* updates statusbar only if speed have changed to save CPU time */
462  if (speed != v->cur_speed) {
463  v->cur_speed = speed;
465  }
466 
467  const uint advance_speed = v->GetAdvanceSpeed(speed);
468  const uint number_of_steps = (advance_speed + v->progress) / v->GetAdvanceDistance();
469  const uint remainder = (advance_speed + v->progress) % v->GetAdvanceDistance();
470  assert(remainder <= std::numeric_limits<byte>::max());
471  v->progress = static_cast<byte>(remainder);
472  return number_of_steps;
473 }
474 
480 static void ShipArrivesAt(const Vehicle *v, Station *st)
481 {
482  /* Check if station was ever visited before */
483  if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
484  st->had_vehicle_of_type |= HVOT_SHIP;
485 
486  SetDParam(0, st->index);
488  STR_NEWS_FIRST_SHIP_ARRIVAL,
490  v->index,
491  st->index
492  );
493  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
494  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
495  }
496 }
497 
498 
508 static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
509 {
510  assert(IsValidDiagDirection(enterdir));
511 
512  bool path_found = true;
513  Track track;
514 
515  if (v->dest_tile == 0) {
516  /* No destination, don't invoke pathfinder. */
517  track = TrackBitsToTrack(v->state);
518  if (!IsDiagonalTrack(track)) track = TrackToOppositeTrack(track);
519  if (!HasBit(tracks, track)) track = FindFirstTrack(tracks);
520  path_found = false;
521  } else {
522  /* Attempt to follow cached path. */
523  if (!v->path.empty()) {
524  track = TrackdirToTrack(v->path.front());
525 
526  if (HasBit(tracks, track)) {
527  v->path.pop_front();
528  /* HandlePathfindResult() is not called here because this is not a new pathfinder result. */
529  return track;
530  }
531 
532  /* Cached path is invalid so continue with pathfinder. */
533  v->path.clear();
534  }
535 
537  case VPF_NPF: track = NPFShipChooseTrack(v, path_found); break;
538  case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found, v->path); break;
539  default: NOT_REACHED();
540  }
541  }
542 
543  v->HandlePathfindingResult(path_found);
544  return track;
545 }
546 
554 {
555  TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
556 
557  return tracks;
558 }
559 
562  byte x_subcoord;
563  byte y_subcoord;
565 };
572  // DIAGDIR_NE
573  {
574  {15, 8, DIR_NE}, // TRACK_X
575  { 0, 0, INVALID_DIR}, // TRACK_Y
576  { 0, 0, INVALID_DIR}, // TRACK_UPPER
577  {15, 8, DIR_E}, // TRACK_LOWER
578  {15, 7, DIR_N}, // TRACK_LEFT
579  { 0, 0, INVALID_DIR}, // TRACK_RIGHT
580  },
581  // DIAGDIR_SE
582  {
583  { 0, 0, INVALID_DIR}, // TRACK_X
584  { 8, 0, DIR_SE}, // TRACK_Y
585  { 7, 0, DIR_E}, // TRACK_UPPER
586  { 0, 0, INVALID_DIR}, // TRACK_LOWER
587  { 8, 0, DIR_S}, // TRACK_LEFT
588  { 0, 0, INVALID_DIR}, // TRACK_RIGHT
589  },
590  // DIAGDIR_SW
591  {
592  { 0, 8, DIR_SW}, // TRACK_X
593  { 0, 0, INVALID_DIR}, // TRACK_Y
594  { 0, 7, DIR_W}, // TRACK_UPPER
595  { 0, 0, INVALID_DIR}, // TRACK_LOWER
596  { 0, 0, INVALID_DIR}, // TRACK_LEFT
597  { 0, 8, DIR_S}, // TRACK_RIGHT
598  },
599  // DIAGDIR_NW
600  {
601  { 0, 0, INVALID_DIR}, // TRACK_X
602  { 8, 15, DIR_NW}, // TRACK_Y
603  { 0, 0, INVALID_DIR}, // TRACK_UPPER
604  { 8, 15, DIR_W}, // TRACK_LOWER
605  { 0, 0, INVALID_DIR}, // TRACK_LEFT
606  { 7, 15, DIR_N}, // TRACK_RIGHT
607  }
608 };
609 
615 static int ShipTestUpDownOnLock(const Ship *v)
616 {
617  /* Suitable tile? */
618  if (!IsTileType(v->tile, MP_WATER) || !IsLock(v->tile) || GetLockPart(v->tile) != LOCK_PART_MIDDLE) return 0;
619 
620  /* Must be at the centre of the lock */
621  if ((v->x_pos & 0xF) != 8 || (v->y_pos & 0xF) != 8) return 0;
622 
624  assert(IsValidDiagDirection(diagdir));
625 
626  if (DirToDiagDir(v->direction) == diagdir) {
627  /* Move up */
628  return (v->z_pos < GetTileMaxZ(v->tile) * (int)TILE_HEIGHT) ? 1 : 0;
629  } else {
630  /* Move down */
631  return (v->z_pos > GetTileZ(v->tile) * (int)TILE_HEIGHT) ? -1 : 0;
632  }
633 }
634 
640 static bool ShipMoveUpDownOnLock(Ship *v)
641 {
642  /* Moving up/down through lock */
643  int dz = ShipTestUpDownOnLock(v);
644  if (dz == 0) return false;
645 
646  if (v->cur_speed != 0) {
647  v->cur_speed = 0;
649  }
650 
651  if ((v->tick_counter & 7) == 0) {
652  v->z_pos += dz;
653  v->UpdatePosition();
654  v->UpdateViewport(true, true);
655  }
656 
657  return true;
658 }
659 
666 bool IsShipDestinationTile(TileIndex tile, StationID station)
667 {
668  assert(IsDockingTile(tile));
669  /* Check each tile adjacent to docking tile. */
670  for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
671  TileIndex t = tile + TileOffsByDiagDir(d);
672  if (!IsValidTile(t)) continue;
673  if (IsDockTile(t) && GetStationIndex(t) == station && IsDockWaterPart(t)) return true;
674  if (IsTileType(t, MP_INDUSTRY)) {
675  const Industry *i = Industry::GetByTile(t);
676  if (i->neutral_station != nullptr && i->neutral_station->index == station) return true;
677  }
678  if (IsTileType(t, MP_STATION) && IsOilRig(t) && GetStationIndex(t) == station) return true;
679  }
680  return false;
681 }
682 
683 static void ReverseShipIntoTrackdir(Ship *v, Trackdir trackdir)
684 {
685  static constexpr Direction _trackdir_to_direction[] = {
688  };
689 
690  v->direction = _trackdir_to_direction[trackdir];
691  assert(v->direction != INVALID_DIR);
693 
694  /* Remember our current location to avoid movement glitch */
695  v->rotation_x_pos = v->x_pos;
696  v->rotation_y_pos = v->y_pos;
697  v->cur_speed = 0;
698  v->path.clear();
699 
700  v->UpdatePosition();
701  v->UpdateViewport(true, true);
702 }
703 
704 static void ReverseShip(Ship *v)
705 {
706  v->direction = ReverseDir(v->direction);
707 
708  /* Remember our current location to avoid movement glitch */
709  v->rotation_x_pos = v->x_pos;
710  v->rotation_y_pos = v->y_pos;
711  v->cur_speed = 0;
712  v->path.clear();
713 
714  v->UpdatePosition();
715  v->UpdateViewport(true, true);
716 }
717 
718 static void ShipController(Ship *v)
719 {
720  v->tick_counter++;
721  v->current_order_time++;
722 
723  if (v->HandleBreakdown()) return;
724 
725  if (v->vehstatus & VS_STOPPED) return;
726 
727  if (ProcessOrders(v) && CheckReverseShip(v)) return ReverseShip(v);
728 
729  v->HandleLoading();
730 
731  if (v->current_order.IsType(OT_LOADING)) return;
732 
733  if (CheckShipLeaveDepot(v)) return;
734 
735  v->ShowVisualEffect();
736 
737  /* Rotating on spot */
738  if (v->direction != v->rotation) {
739  if ((v->tick_counter & 7) == 0) {
740  DirDiff diff = DirDifference(v->direction, v->rotation);
742  /* Invalidate the sprite cache direction to force recalculation of viewport */
744  v->UpdateViewport(true, true);
745  }
746  return;
747  }
748 
749  if (ShipMoveUpDownOnLock(v)) return;
750 
751  const uint number_of_steps = ShipAccelerate(v);
752  for (uint i = 0; i < number_of_steps; ++i) {
753  if (ShipMoveUpDownOnLock(v)) return;
754 
756  if (v->state != TRACK_BIT_WORMHOLE) {
757  /* Not on a bridge */
758  if (gp.old_tile == gp.new_tile) {
759  /* Staying in tile */
760  if (v->IsInDepot()) {
761  gp.x = v->x_pos;
762  gp.y = v->y_pos;
763  } else {
764  /* Not inside depot */
765  const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
766  if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
767 
768  /* A leave station order only needs one tick to get processed, so we can
769  * always skip ahead. */
770  if (v->current_order.IsType(OT_LEAVESTATION)) {
771  v->current_order.Free();
773  /* Test if continuing forward would lead to a dead-end, moving into the dock. */
774  const DiagDirection exitdir = VehicleExitDir(v->direction, v->state);
775  const TileIndex tile = TileAddByDiagDir(v->tile, exitdir);
776  if (TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0, exitdir)) == TRACK_BIT_NONE) return ReverseShip(v);
777  } else if (v->dest_tile != 0) {
778  /* We have a target, let's see if we reached it... */
779  if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
780  DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
781  /* We got within 3 tiles of our target buoy, so let's skip to our
782  * next order */
783  UpdateVehicleTimetable(v, true);
786  } else if (v->current_order.IsType(OT_GOTO_DEPOT) &&
787  v->dest_tile == gp.new_tile) {
788  /* Depot orders really need to reach the tile */
789  if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
791  return;
792  }
793  } else if (v->current_order.IsType(OT_GOTO_STATION) && IsDockingTile(gp.new_tile)) {
794  /* Process station in the orderlist. */
797  v->last_station_visited = st->index;
798  if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
799  ShipArrivesAt(v, st);
800  v->BeginLoading();
801  } else { // leave stations without docks right away
804  }
805  }
806  }
807  }
808  }
809  } else {
810  /* New tile */
811  if (!IsValidTile(gp.new_tile)) return ReverseShip(v);
812 
813  const DiagDirection diagdir = DiagdirBetweenTiles(gp.old_tile, gp.new_tile);
814  assert(diagdir != INVALID_DIAGDIR);
815  const TrackBits tracks = GetAvailShipTracks(gp.new_tile, diagdir);
816  if (tracks == TRACK_BIT_NONE) {
817  Trackdir trackdir = INVALID_TRACKDIR;
818  CheckReverseShip(v, &trackdir);
819  if (trackdir == INVALID_TRACKDIR) return ReverseShip(v);
820  return ReverseShipIntoTrackdir(v, trackdir);
821  }
822 
823  /* Choose a direction, and continue if we find one */
824  const Track track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
825  if (track == INVALID_TRACK) return ReverseShip(v);
826 
827  const ShipSubcoordData &b = _ship_subcoord[diagdir][track];
828 
829  gp.x = (gp.x & ~0xF) | b.x_subcoord;
830  gp.y = (gp.y & ~0xF) | b.y_subcoord;
831 
832  /* Call the landscape function and tell it that the vehicle entered the tile */
833  const VehicleEnterTileStatus r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
834  if (HasBit(r, VETS_CANNOT_ENTER)) return ReverseShip(v);
835 
836  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
837  v->tile = gp.new_tile;
838  v->state = TrackToTrackBits(track);
839 
840  /* Update ship cache when the water class changes. Aqueducts are always canals. */
842  }
843 
844  const Direction new_direction = b.dir;
845  const DirDiff diff = DirDifference(new_direction, v->direction);
846  switch (diff) {
847  case DIRDIFF_SAME:
848  case DIRDIFF_45RIGHT:
849  case DIRDIFF_45LEFT:
850  /* Continue at speed */
851  v->rotation = v->direction = new_direction;
852  break;
853 
854  default:
855  /* Stop for rotation */
856  v->cur_speed = 0;
857  v->direction = new_direction;
858  /* Remember our current location to avoid movement glitch */
859  v->rotation_x_pos = v->x_pos;
860  v->rotation_y_pos = v->y_pos;
861  break;
862  }
863  }
864  } else {
865  /* On a bridge */
867  v->x_pos = gp.x;
868  v->y_pos = gp.y;
869  v->UpdatePosition();
870  if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
871  return;
872  }
873 
874  /* Ship is back on the bridge head, we need to consume its path
875  * cache entry here as we didn't have to choose a ship track. */
876  if (!v->path.empty()) v->path.pop_front();
877  }
878 
879  /* update image of ship, as well as delta XY */
880  v->x_pos = gp.x;
881  v->y_pos = gp.y;
882 
883  v->UpdatePosition();
884  v->UpdateViewport(true, true);
885  }
886 }
887 
889 {
891 
892  if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
893 
894  ShipController(this);
895 
896  return true;
897 }
898 
899 void Ship::SetDestTile(TileIndex tile)
900 {
901  if (tile == this->dest_tile) return;
902  this->path.clear();
903  this->dest_tile = tile;
904 }
905 
915 {
916  tile = GetShipDepotNorthTile(tile);
917  if (flags & DC_EXEC) {
918  int x;
919  int y;
920 
921  const ShipVehicleInfo *svi = &e->u.ship;
922 
923  Ship *v = new Ship();
924  *ret = v;
925 
926  v->owner = _current_company;
927  v->tile = tile;
928  x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
929  y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
930  v->x_pos = x;
931  v->y_pos = y;
932  v->z_pos = GetSlopePixelZ(x, y);
933 
934  v->UpdateDeltaXY();
936 
937  v->spritenum = svi->image_index;
939  assert(IsValidCargoID(v->cargo_type));
940  v->cargo_cap = svi->capacity;
941  v->refit_cap = 0;
942 
943  v->last_station_visited = INVALID_STATION;
944  v->last_loading_station = INVALID_STATION;
945  v->engine_type = e->index;
946 
947  v->reliability = e->reliability;
949  v->max_age = e->GetLifeLengthInDays();
950 
951  v->state = TRACK_BIT_DEPOT;
952 
953  v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships);
957  v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
958  v->random_bits = Random();
959 
960  v->acceleration = svi->acceleration;
961  v->UpdateCache();
962 
964  v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
965 
967 
968  v->cargo_cap = e->DetermineCapacity(v);
969 
971 
972  v->UpdatePosition();
973  }
974 
975  return CommandCost();
976 }
977 
979 {
980  const Depot *depot = FindClosestShipDepot(this, MAX_SHIP_DEPOT_SEARCH_DISTANCE);
981  if (depot == nullptr) return ClosestDepot();
982 
983  return ClosestDepot(depot->xy, depot->index);
984 }
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:508
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:550
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:499
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:615
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:3204
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:339
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:3086
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:965
Vehicle::reliability_spd_dec
uint16_t reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:294
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:339
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:1719
WaterRegionPatchDesc
Describes a single interconnected patch of water within a particular water region.
Definition: water_regions.h:26
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:294
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:313
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:443
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:349
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:238
Vehicle::acceleration
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:326
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:914
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:29
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:347
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:1545
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:455
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:305
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:553
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:562
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:300
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:561
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:291
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:184
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:2189
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:624
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:306
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:2640
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:244
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:2537
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:452
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:298
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:330
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:319
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:333
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:350
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:324
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:978
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:146
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:458
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:2763
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
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:1824
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:80
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:334
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:387
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:2407
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:564
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:364
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:278
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:877
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:302
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:303
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:2135
spritecache.h
Vehicle::x_extent
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:312
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:362
Ship
All ships have this type.
Definition: ship.h:24
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
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:388
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:666
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:290
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:346
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:571
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:441
Vehicle::x_offs
int8_t x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:317
Ship::MarkDirty
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:311
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:314
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:292
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:500
Ship::Tick
bool Tick() override
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:888
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:371
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:293
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:77
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:480
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:79
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:301
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:345
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:640
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition: settings_type.h:500
AgeVehicle
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
Definition: vehicle.cpp:1437
Vehicle::progress
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:328
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:337
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
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:107
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:311
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:337
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:453
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:419
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1679
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:3034
Vehicle::HandleBreakdown
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Definition: vehicle.cpp:1359
DecreaseVehicleValue
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
Definition: vehicle.cpp:1297
GetNewVehiclePosResult::y
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:78
EconomyAgeVehicle
void EconomyAgeVehicle(Vehicle *v)
Update economy age of a vehicle.
Definition: vehicle.cpp:1425
PathfinderSettings::pathfinder_for_ships
uint8_t pathfinder_for_ships
the pathfinder to use for ships
Definition: settings_type.h:485
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:563
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:3112
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:3099
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:1228
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:2491
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:318
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:340
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:1770
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:443
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:28
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