OpenTTD
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"
21 #include "newgrf_sound.h"
22 #include "spritecache.h"
23 #include "strings_func.h"
24 #include "window_func.h"
25 #include "date_func.h"
26 #include "vehicle_func.h"
27 #include "sound_func.h"
28 #include "ai/ai.hpp"
29 #include "game/game.hpp"
30 #include "engine_base.h"
31 #include "company_base.h"
32 #include "tunnelbridge_map.h"
33 #include "zoom_func.h"
34 #include "framerate_type.h"
35 #include "industry.h"
36 #include "industry_map.h"
37 
38 #include "table/strings.h"
39 
40 #include "safeguards.h"
41 
48 {
49  if (HasTileWaterClass(tile)) return GetWaterClass(tile);
50  if (IsTileType(tile, MP_TUNNELBRIDGE)) {
52  return WATER_CLASS_CANAL;
53  }
54  if (IsTileType(tile, MP_RAILWAY)) {
55  assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
56  return WATER_CLASS_SEA;
57  }
58  NOT_REACHED();
59 }
60 
61 static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
62 
63 template <>
64 bool IsValidImageIndex<VEH_SHIP>(uint8 image_index)
65 {
66  return image_index < lengthof(_ship_sprites);
67 }
68 
69 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
70 {
72 }
73 
74 static void GetShipIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
75 {
76  const Engine *e = Engine::Get(engine);
77  uint8 spritenum = e->u.ship.image_index;
78 
79  if (is_custom_sprite(spritenum)) {
80  GetCustomVehicleIcon(engine, DIR_W, image_type, result);
81  if (result->IsValid()) return;
82 
83  spritenum = e->original_image_index;
84  }
85 
86  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
87  result->Set(DIR_W + _ship_sprites[spritenum]);
88 }
89 
90 void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
91 {
92  VehicleSpriteSeq seq;
93  GetShipIcon(engine, image_type, &seq);
94 
95  Rect rect;
96  seq.GetBounds(&rect);
97  preferred_x = Clamp(preferred_x,
98  left - UnScaleGUI(rect.left),
99  right - UnScaleGUI(rect.right));
100 
101  seq.Draw(preferred_x, y, pal, pal == PALETTE_CRASH);
102 }
103 
113 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
114 {
115  VehicleSpriteSeq seq;
116  GetShipIcon(engine, image_type, &seq);
117 
118  Rect rect;
119  seq.GetBounds(&rect);
120 
121  width = UnScaleGUI(rect.right - rect.left + 1);
122  height = UnScaleGUI(rect.bottom - rect.top + 1);
123  xoffs = UnScaleGUI(rect.left);
124  yoffs = UnScaleGUI(rect.top);
125 }
126 
127 void Ship::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
128 {
129  uint8 spritenum = this->spritenum;
130 
131  if (image_type == EIT_ON_MAP) direction = this->rotation;
132 
133  if (is_custom_sprite(spritenum)) {
134  GetCustomVehicleSprite(this, direction, image_type, result);
135  if (result->IsValid()) return;
136 
137  spritenum = this->GetEngine()->original_image_index;
138  }
139 
140  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
141  result->Set(_ship_sprites[spritenum] + direction);
142 }
143 
144 static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
145 {
146  /* Find the closest depot */
147  const Depot *best_depot = nullptr;
148  /* If we don't have a maximum distance, i.e. distance = 0,
149  * we want to find any depot so the best distance of no
150  * depot must be more than any correct distance. On the
151  * other hand if we have set a maximum distance, any depot
152  * further away than max_distance can safely be ignored. */
153  uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1;
154 
155  for (const Depot *depot : Depot::Iterate()) {
156  TileIndex tile = depot->xy;
157  if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
158  uint dist = DistanceManhattan(tile, v->tile);
159  if (dist < best_dist) {
160  best_dist = dist;
161  best_depot = depot;
162  }
163  }
164  }
165 
166  return best_depot;
167 }
168 
169 static void CheckIfShipNeedsService(Vehicle *v)
170 {
171  if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
172  if (v->IsChainInDepot()) {
174  return;
175  }
176 
177  uint max_distance;
181  default: NOT_REACHED();
182  }
183 
184  const Depot *depot = FindClosestShipDepot(v, max_distance);
185 
186  if (depot == nullptr) {
187  if (v->current_order.IsType(OT_GOTO_DEPOT)) {
190  }
191  return;
192  }
193 
195  v->SetDestTile(depot->xy);
197 }
198 
203 {
204  const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
205 
206  /* Get speed fraction for the current water type. Aqueducts are always canals. */
207  bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
208  uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
209  this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
210 
211  /* Update cargo aging period. */
212  this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
213 
214  this->UpdateVisualEffect();
215 }
216 
218 {
219  const Engine *e = this->GetEngine();
220  uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
221  return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
222 }
223 
225 {
226  if ((++this->day_counter & 7) == 0) {
227  DecreaseVehicleValue(this);
228  }
229 
230  CheckVehicleBreakdown(this);
231  AgeVehicle(this);
232  CheckIfShipNeedsService(this);
233 
234  CheckOrders(this);
235 
236  if (this->running_ticks == 0) return;
237 
239 
240  this->profit_this_year -= cost.GetCost();
241  this->running_ticks = 0;
242 
244 
246  /* we need this for the profit */
248 }
249 
251 {
252  if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
253 
254  if (this->IsInDepot()) {
255  /* We'll assume the ship is facing outwards */
257  }
258 
259  if (this->state == TRACK_BIT_WORMHOLE) {
260  /* ship on aqueduct, so just use his direction and assume a diagonal track */
262  }
263 
265 }
266 
268 {
269  this->colourmap = PAL_NONE;
270  this->UpdateViewport(true, false);
271  this->UpdateCache();
272 }
273 
274 static void PlayShipSound(const Vehicle *v)
275 {
276  if (!PlayVehicleSound(v, VSE_START)) {
277  SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v);
278  }
279 }
280 
282 {
283  PlayShipSound(this);
284 }
285 
287 {
288  if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
289 
290  const Station *st = Station::Get(station);
291  if (CanVehicleUseStation(this, st)) {
292  return st->xy;
293  } else {
294  this->IncrementRealOrderIndex();
295  return 0;
296  }
297 }
298 
300 {
301  static const int8 _delta_xy_table[8][4] = {
302  /* y_extent, x_extent, y_offs, x_offs */
303  { 6, 6, -3, -3}, // N
304  { 6, 32, -3, -16}, // NE
305  { 6, 6, -3, -3}, // E
306  {32, 6, -16, -3}, // SE
307  { 6, 6, -3, -3}, // S
308  { 6, 32, -3, -16}, // SW
309  { 6, 6, -3, -3}, // W
310  {32, 6, -16, -3}, // NW
311  };
312 
313  const int8 *bb = _delta_xy_table[this->rotation];
314  this->x_offs = bb[3];
315  this->y_offs = bb[2];
316  this->x_extent = bb[1];
317  this->y_extent = bb[0];
318  this->z_extent = 6;
319 
320  if (this->direction != this->rotation) {
321  /* If we are rotating, then it is possible the ship was moved to its next position. In that
322  * case, because we are still showing the old direction, the ship will appear to glitch sideways
323  * slightly. We can work around this by applying an additional offset to make the ship appear
324  * where it was before it moved. */
325  this->x_offs -= this->x_pos - this->rotation_x_pos;
326  this->y_offs -= this->y_pos - this->rotation_y_pos;
327  }
328 }
329 
333 static Vehicle *EnsureNoVisibleShipProc(Vehicle *v, void *data)
334 {
335  return v->type == VEH_SHIP && (v->vehstatus & VS_HIDDEN) == 0 ? v : nullptr;
336 }
337 
338 static bool CheckShipLeaveDepot(Ship *v)
339 {
340  if (!v->IsChainInDepot()) return false;
341 
342  /* We are leaving a depot, but have to go to the exact same one; re-enter */
343  if (v->current_order.IsType(OT_GOTO_DEPOT) &&
346  return true;
347  }
348 
349  /* Don't leave depot if no destination set */
350  if (v->dest_tile == 0) return true;
351 
352  /* Don't leave depot if another vehicle is already entering/leaving */
353  /* This helps avoid CPU load if many ships are set to start at the same time */
354  if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoVisibleShipProc)) return true;
355 
356  TileIndex tile = v->tile;
357  Axis axis = GetShipDepotAxis(tile);
358 
359  DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
360  TileIndex north_neighbour = TILE_ADD(tile, TileOffsByDiagDir(north_dir));
361  DiagDirection south_dir = AxisToDiagDir(axis);
362  TileIndex south_neighbour = TILE_ADD(tile, 2 * TileOffsByDiagDir(south_dir));
363 
364  TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
365  TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
366  if (north_tracks && south_tracks) {
367  /* Ask pathfinder for best direction */
368  bool reverse = false;
370  case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
371  case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
372  default: NOT_REACHED();
373  }
374  if (reverse) north_tracks = TRACK_BIT_NONE;
375  }
376 
377  if (north_tracks) {
378  /* Leave towards north */
379  v->rotation = v->direction = DiagDirToDir(north_dir);
380  } else if (south_tracks) {
381  /* Leave towards south */
382  v->rotation = v->direction = DiagDirToDir(south_dir);
383  } else {
384  /* Both ways blocked */
385  return false;
386  }
387 
388  v->state = AxisToTrackBits(axis);
389  v->vehstatus &= ~VS_HIDDEN;
390 
391  v->cur_speed = 0;
392  v->UpdateViewport(true, true);
394 
395  PlayShipSound(v);
399 
400  return false;
401 }
402 
403 static bool ShipAccelerate(Vehicle *v)
404 {
405  uint spd;
406  byte t;
407 
408  spd = min(v->cur_speed + 1, v->vcache.cached_max_speed);
409  spd = min(spd, v->current_order.GetMaxSpeed() * 2);
410 
411  /* updates statusbar only if speed have changed to save CPU time */
412  if (spd != v->cur_speed) {
413  v->cur_speed = spd;
415  }
416 
417  /* Convert direction-independent speed into direction-dependent speed. (old movement method) */
418  spd = v->GetOldAdvanceSpeed(spd);
419 
420  if (spd == 0) return false;
421  if ((byte)++spd == 0) return true;
422 
423  v->progress = (t = v->progress) - (byte)spd;
424 
425  return (t < v->progress);
426 }
427 
433 static void ShipArrivesAt(const Vehicle *v, Station *st)
434 {
435  /* Check if station was ever visited before */
436  if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
437  st->had_vehicle_of_type |= HVOT_SHIP;
438 
439  SetDParam(0, st->index);
441  STR_NEWS_FIRST_SHIP_ARRIVAL,
443  v->index,
444  st->index
445  );
446  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
447  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
448  }
449 }
450 
451 
462 {
463  assert(IsValidDiagDirection(enterdir));
464 
465  bool path_found = true;
466  Track track;
467 
468  if (v->dest_tile == 0) {
469  /* No destination, don't invoke pathfinder. */
470  track = TrackBitsToTrack(v->state);
471  if (!IsDiagonalTrack(track)) track = TrackToOppositeTrack(track);
472  if (!HasBit(tracks, track)) track = FindFirstTrack(tracks);
473  path_found = false;
474  } else {
475  /* Attempt to follow cached path. */
476  if (!v->path.empty()) {
477  track = TrackdirToTrack(v->path.front());
478 
479  if (HasBit(tracks, track)) {
480  v->path.pop_front();
481  /* HandlePathfindResult() is not called here because this is not a new pathfinder result. */
482  return track;
483  }
484 
485  /* Cached path is invalid so continue with pathfinder. */
486  v->path.clear();
487  }
488 
490  case VPF_NPF: track = NPFShipChooseTrack(v, path_found); break;
491  case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found, v->path); break;
492  default: NOT_REACHED();
493  }
494  }
495 
496  v->HandlePathfindingResult(path_found);
497  return track;
498 }
499 
508 {
509  TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
510 
511  return tracks;
512 }
513 
514 static const byte _ship_subcoord[4][6][3] = {
515  {
516  {15, 8, 1},
517  { 0, 0, 0},
518  { 0, 0, 0},
519  {15, 8, 2},
520  {15, 7, 0},
521  { 0, 0, 0},
522  },
523  {
524  { 0, 0, 0},
525  { 8, 0, 3},
526  { 7, 0, 2},
527  { 0, 0, 0},
528  { 8, 0, 4},
529  { 0, 0, 0},
530  },
531  {
532  { 0, 8, 5},
533  { 0, 0, 0},
534  { 0, 7, 6},
535  { 0, 0, 0},
536  { 0, 0, 0},
537  { 0, 8, 4},
538  },
539  {
540  { 0, 0, 0},
541  { 8, 15, 7},
542  { 0, 0, 0},
543  { 8, 15, 6},
544  { 0, 0, 0},
545  { 7, 15, 0},
546  }
547 };
548 
554 static int ShipTestUpDownOnLock(const Ship *v)
555 {
556  /* Suitable tile? */
557  if (!IsTileType(v->tile, MP_WATER) || !IsLock(v->tile) || GetLockPart(v->tile) != LOCK_PART_MIDDLE) return 0;
558 
559  /* Must be at the centre of the lock */
560  if ((v->x_pos & 0xF) != 8 || (v->y_pos & 0xF) != 8) return 0;
561 
563  assert(IsValidDiagDirection(diagdir));
564 
565  if (DirToDiagDir(v->direction) == diagdir) {
566  /* Move up */
567  return (v->z_pos < GetTileMaxZ(v->tile) * (int)TILE_HEIGHT) ? 1 : 0;
568  } else {
569  /* Move down */
570  return (v->z_pos > GetTileZ(v->tile) * (int)TILE_HEIGHT) ? -1 : 0;
571  }
572 }
573 
579 static bool ShipMoveUpDownOnLock(Ship *v)
580 {
581  /* Moving up/down through lock */
582  int dz = ShipTestUpDownOnLock(v);
583  if (dz == 0) return false;
584 
585  if (v->cur_speed != 0) {
586  v->cur_speed = 0;
588  }
589 
590  if ((v->tick_counter & 7) == 0) {
591  v->z_pos += dz;
592  v->UpdatePosition();
593  v->UpdateViewport(true, true);
594  }
595 
596  return true;
597 }
598 
605 bool IsShipDestinationTile(TileIndex tile, StationID station)
606 {
607  assert(IsDockingTile(tile));
608  /* Check each tile adjacent to docking tile. */
609  for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
610  TileIndex t = tile + TileOffsByDiagDir(d);
611  if (!IsValidTile(t)) continue;
612  if (IsDockTile(t) && GetStationIndex(t) == station && IsValidDockingDirectionForDock(t, d)) return true;
613  if (IsTileType(t, MP_INDUSTRY)) {
614  const Industry *i = Industry::GetByTile(t);
615  if (i->neutral_station != nullptr && i->neutral_station->index == station) return true;
616  }
617  }
618  return false;
619 }
620 
621 static void ShipController(Ship *v)
622 {
623  uint32 r;
624  const byte *b;
625  Track track;
626  TrackBits tracks;
627 
628  v->tick_counter++;
629  v->current_order_time++;
630 
631  if (v->HandleBreakdown()) return;
632 
633  if (v->vehstatus & VS_STOPPED) return;
634 
635  ProcessOrders(v);
636  v->HandleLoading();
637 
638  if (v->current_order.IsType(OT_LOADING)) return;
639 
640  if (CheckShipLeaveDepot(v)) return;
641 
642  v->ShowVisualEffect();
643 
644  /* Rotating on spot */
645  if (v->direction != v->rotation) {
646  if ((v->tick_counter & 7) == 0) {
647  DirDiff diff = DirDifference(v->direction, v->rotation);
649  v->UpdateViewport(true, true);
650  }
651  return;
652  }
653 
654  if (ShipMoveUpDownOnLock(v)) return;
655 
656  if (!ShipAccelerate(v)) return;
657 
659  if (v->state != TRACK_BIT_WORMHOLE) {
660  /* Not on a bridge */
661  if (gp.old_tile == gp.new_tile) {
662  /* Staying in tile */
663  if (v->IsInDepot()) {
664  gp.x = v->x_pos;
665  gp.y = v->y_pos;
666  } else {
667  /* Not inside depot */
668  r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
669  if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
670 
671  /* A leave station order only needs one tick to get processed, so we can
672  * always skip ahead. */
673  if (v->current_order.IsType(OT_LEAVESTATION)) {
674  v->current_order.Free();
676  /* Test if continuing forward would lead to a dead-end, moving into the dock. */
677  DiagDirection exitdir = VehicleExitDir(v->direction, v->state);
678  TileIndex tile = TileAddByDiagDir(v->tile, exitdir);
679  if (TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0, exitdir)) == TRACK_BIT_NONE) goto reverse_direction;
680  } else if (v->dest_tile != 0) {
681  /* We have a target, let's see if we reached it... */
682  if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
683  DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
684  /* We got within 3 tiles of our target buoy, so let's skip to our
685  * next order */
686  UpdateVehicleTimetable(v, true);
689  } else if (v->current_order.IsType(OT_GOTO_DEPOT) &&
690  v->dest_tile == gp.new_tile) {
691  /* Depot orders really need to reach the tile */
692  if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
694  return;
695  }
696  } else if (v->current_order.IsType(OT_GOTO_STATION) && IsDockingTile(gp.new_tile)) {
697  /* Process station in the orderlist. */
700  v->last_station_visited = st->index;
701  if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
702  ShipArrivesAt(v, st);
703  v->BeginLoading();
704  } else { // leave stations without docks right away
707  }
708  }
709  }
710  }
711  }
712  } else {
713  /* New tile */
714  if (!IsValidTile(gp.new_tile)) goto reverse_direction;
715 
717  assert(diagdir != INVALID_DIAGDIR);
718  tracks = GetAvailShipTracks(gp.new_tile, diagdir, v->GetVehicleTrackdir());
719  if (tracks == TRACK_BIT_NONE) goto reverse_direction;
720 
721  /* Choose a direction, and continue if we find one */
722  track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
723  if (track == INVALID_TRACK) goto reverse_direction;
724 
725  b = _ship_subcoord[diagdir][track];
726 
727  gp.x = (gp.x & ~0xF) | b[0];
728  gp.y = (gp.y & ~0xF) | b[1];
729 
730  /* Call the landscape function and tell it that the vehicle entered the tile */
731  r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
732  if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
733 
734  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
735  v->tile = gp.new_tile;
736  v->state = TrackToTrackBits(track);
737 
738  /* Update ship cache when the water class changes. Aqueducts are always canals. */
741  if (old_wc != new_wc) v->UpdateCache();
742  }
743 
744  Direction new_direction = (Direction)b[2];
745  DirDiff diff = DirDifference(new_direction, v->direction);
746  switch (diff) {
747  case DIRDIFF_SAME:
748  case DIRDIFF_45RIGHT:
749  case DIRDIFF_45LEFT:
750  /* Continue at speed */
751  v->rotation = v->direction = new_direction;
752  break;
753 
754  default:
755  /* Stop for rotation */
756  v->cur_speed = 0;
757  v->direction = new_direction;
758  /* Remember our current location to avoid movement glitch */
759  v->rotation_x_pos = v->x_pos;
760  v->rotation_y_pos = v->y_pos;
761  break;
762  }
763  }
764  } else {
765  /* On a bridge */
767  v->x_pos = gp.x;
768  v->y_pos = gp.y;
769  v->UpdatePosition();
770  if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
771  return;
772  }
773 
774  /* Ship is back on the bridge head, we need to consume its path
775  * cache entry here as we didn't have to choose a ship track. */
776  if (!v->path.empty()) v->path.pop_front();
777  }
778 
779  /* update image of ship, as well as delta XY */
780  v->x_pos = gp.x;
781  v->y_pos = gp.y;
782 
783 getout:
784  v->UpdatePosition();
785  v->UpdateViewport(true, true);
786  return;
787 
788 reverse_direction:
789  v->direction = ReverseDir(v->direction);
790  /* Remember our current location to avoid movement glitch */
791  v->rotation_x_pos = v->x_pos;
792  v->rotation_y_pos = v->y_pos;
793  v->cur_speed = 0;
794  v->path.clear();
795  goto getout;
796 }
797 
799 {
801 
802  if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
803 
804  ShipController(this);
805 
806  return true;
807 }
808 
809 void Ship::SetDestTile(TileIndex tile)
810 {
811  if (tile == this->dest_tile) return;
812  this->path.clear();
813  this->dest_tile = tile;
814 }
815 
825 CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
826 {
827  tile = GetShipDepotNorthTile(tile);
828  if (flags & DC_EXEC) {
829  int x;
830  int y;
831 
832  const ShipVehicleInfo *svi = &e->u.ship;
833 
834  Ship *v = new Ship();
835  *ret = v;
836 
837  v->owner = _current_company;
838  v->tile = tile;
839  x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
840  y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
841  v->x_pos = x;
842  v->y_pos = y;
843  v->z_pos = GetSlopePixelZ(x, y);
844 
845  v->UpdateDeltaXY();
847 
848  v->spritenum = svi->image_index;
850  v->cargo_cap = svi->capacity;
851  v->refit_cap = 0;
852 
853  v->last_station_visited = INVALID_STATION;
854  v->last_loading_station = INVALID_STATION;
855  v->engine_type = e->index;
856 
857  v->reliability = e->reliability;
859  v->max_age = e->GetLifeLengthInDays();
860  _new_vehicle_id = v->index;
861 
862  v->state = TRACK_BIT_DEPOT;
863 
864  v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships);
866  v->build_year = _cur_year;
867  v->sprite_seq.Set(SPR_IMG_QUERY);
869 
870  v->UpdateCache();
871 
873  v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
874 
876 
877  v->cargo_cap = e->DetermineCapacity(v);
878 
880 
881  v->UpdatePosition();
882  }
883 
884  return CommandCost();
885 }
886 
887 bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
888 {
889  const Depot *depot = FindClosestShipDepot(this, 0);
890 
891  if (depot == nullptr) return false;
892 
893  if (location != nullptr) *location = depot->xy;
894  if (destination != nullptr) *destination = depot->index;
895 
896  return true;
897 }
Information about a ship vehicle.
Definition: engine_type.h:65
Functions related to OTTD&#39;s strings.
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:351
static TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir, Trackdir trackdir)
Get the available water tracks on a tile for a ship entering a tile.
Definition: ship_cmd.cpp:507
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:511
This vehicle is in the exclusive preview stage, either being used or being offered to a company...
Definition: engine_type.h:169
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:25
Date max_age
Maximum age.
Definition: vehicle_base.h:257
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
StationFacility facilities
The facilities that this station has.
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
First vehicle arrived for competitor.
Definition: news_type.h:23
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
Definition: tilearea.cpp:104
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:141
Definition of stuff that is very close to a company, like the company struct itself.
Functions for NewGRF engines.
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
Definition: vehicle.cpp:1199
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Direction direction
facing
Definition: vehicle_base.h:269
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition: vehicle.cpp:2509
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:320
Flag for an invalid track.
Definition: track_type.h:28
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3215
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
static Axis GetShipDepotAxis(TileIndex t)
Get the axis of the ship depot.
Definition: water_map.h:237
ShipPathCache path
Cached path.
Definition: ship.h:28
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
Yet Another PathFinder.
Definition: vehicle_type.h:61
uint32 maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Definition: order_cmd.cpp:1724
Part of an industry.
Definition: tile_type.h:49
Station has seen a ship.
Definition: station_type.h:68
Functions related to time tabling.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
Angle of 45 degrees left.
void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
Definition: ship_cmd.cpp:281
static TileIndex GetShipDepotNorthTile(TileIndex t)
Get the most northern tile of a ship depot.
Definition: water_map.h:283
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:270
Use default vehicle palette.
Definition: vehicle_base.h:33
West.
Used for iterations.
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:113
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
Definition: vehicle_type.h:86
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:798
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
uint16 cur_speed
current speed
Definition: vehicle_base.h:291
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:122
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:96
Ship vehicle type.
Definition: vehicle_type.h:26
Depot view; Window numbers:
Definition: window_type.h:344
Types for recording game performance data.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:277
Both directions faces to the same direction.
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition: engine_type.h:78
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:20
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Definition: vehicle_base.h:301
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:48
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:235
Transport over water.
NPFSettings npf
pathfinder settings for the new pathfinder
Functions related to vehicles.
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:822
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:21
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it...
Definition: vehicle.cpp:1436
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:126
PathfinderSettings pf
settings for all pathfinders
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:382
Vehicle data structure.
Definition: vehicle_base.h:210
static void ShipArrivesAt(const Vehicle *v, Station *st)
Ship arrives at a dock.
Definition: ship_cmd.cpp:433
Base for all depots (except hangars)
Defines the internal data of a functional industry.
Definition: industry.h:40
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:161
Start or stop this vehicle, and show information about the current state.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:605
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
static Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
Definition: track_func.h:239
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:300
uint16 reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:260
A railway.
Definition: tile_type.h:42
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:82
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition: vehicle.cpp:773
Direction rotation
Visible direction.
Definition: ship.h:29
Flag for an invalid DiagDirection.
Common return value for all commands.
Definition: command_type.h:23
Accessors for industries.
int16 rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:31
byte vehstatus
Status.
Definition: vehicle_base.h:315
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
byte flags
Flags of the engine.
Definition: engine_base.h:33
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:24
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:121
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition: vehicle.cpp:251
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:79
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:224
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
Entry point for OpenTTD to YAPF.
byte VehicleRandomBits()
Get a value for a vehicle&#39;s random_bits.
Definition: vehicle.cpp:361
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:942
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:278
uint16 max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition: engine_type.h:68
static bool IsLock(TileIndex t)
Is there a lock on a given water tile?
Definition: water_map.h:297
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
Angle of 45 degrees right.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:201
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
bool YapfShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using YAPF. ...
Definition: yapf_ship.cpp:366
TileArea docking_station
Tile area the docking tiles cover.
Definition: station_base.h:466
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:305
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
Vehicle is crashed.
Definition: vehicle_base.h:37
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:44
static DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
Definition: map_func.h:394
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:26
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
Subtract money from a company, including the money fraction.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:299
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:267
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:76
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
Definition: vehicle.cpp:1327
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:145
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
void MakeDummy()
Makes this order a Dummy order.
Definition: order_cmd.cpp:132
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:285
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:342
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:22
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:279
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Definition: vehicle_base.h:458
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Definition: order_cmd.cpp:2130
Direction
Defines the 8 directions on the map.
Flag for an invalid trackdir.
Definition: track_type.h:89
static bool IsDockTile(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:295
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:47
Water tile.
Definition: tile_type.h:47
DirDiff
Enumeration for the difference between two directions.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:281
Vehicle starting, i.e. leaving, the station.
Definition: newgrf_sound.h:19
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:365
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:303
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
static Vehicle * EnsureNoVisibleShipProc(Vehicle *v, void *data)
Test-procedure for HasVehicleOnPos to check for a ship.
Definition: ship_cmd.cpp:333
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:16
Vehicle view; Window numbers:
Definition: window_type.h:332
Number of ticks before carried cargo is aged.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
TileIndex tile
Current tile index.
Definition: vehicle_base.h:228
New PathFinder.
Definition: vehicle_type.h:60
Grass with a fence and shore or water on the free halftile.
Definition: rail_map.h:499
Functions to access the new pathfinder.
static 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:506
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: ship_cmd.cpp:127
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:545
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2779
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition: vehicle.cpp:1674
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
int8 x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:284
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:271
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
static bool IsShipDepotTile(TileIndex t)
Is it a ship depot tile?
Definition: water_map.h:226
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:306
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:297
static bool ShipMoveUpDownOnLock(Ship *v)
Test and move a ship up or down in a lock.
Definition: ship_cmd.cpp:579
Functions related to sound.
uint16 reliability
Reliability.
Definition: vehicle_base.h:259
Functions to cache sprites in memory.
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:312
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:55
All ships have this type.
Definition: ship.h:26
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:255
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:589
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:234
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
static TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction...
Definition: track_func.h:581
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:286
TileIndex old_tile
Current tile of the vehicle.
Definition: vehicle_func.h:77
bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d)
Check if a dock tile can be docked from the given direction.
Bitflag for a depot.
Definition: track_type.h:56
static bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:627
execute the given command
Definition: command_type.h:344
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:85
Functions related to companies.
static DiagDirection GetShipDepotDirection(TileIndex t)
Get the direction of the ship depot.
Definition: water_map.h:261
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing...
Definition: vehicle.cpp:1620
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1559
Station with a dock.
Definition: station_type.h:56
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
No track.
Definition: track_type.h:39
Base class for engines.
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:50
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:94
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:138
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
Definition: vehicle.cpp:162
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3229
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:89
Time spent processing ships.
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds, and ending the breakdown when appropriate.
Definition: vehicle.cpp:1261
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
Ships list; Window numbers:
Definition: window_type.h:313
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1587
Used for iterations.
Middle part of a lock.
Definition: water_map.h:65
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition: vehicle.cpp:2033
void MakeLeaveStation()
Makes this order a Leave Station order.
Definition: order_cmd.cpp:123
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:258
Position information of a vehicle after it moved.
Definition: vehicle_func.h:75
First vehicle arrived for company.
Definition: news_type.h:22
Track
These are used to specify a single track.
Definition: track_type.h:19
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
void Free()
&#39;Free&#39; the order
Definition: order_cmd.cpp:62
TileIndex xy
Base tile of the station.
Functions related to zooming.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:250
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:185
RAII class for measuring multi-step elements of performance.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
Functions related to OTTD&#39;s landscape.
static const int NPF_TILE_LENGTH
Length (penalty) of one tile with NPF.
int32 z_pos
z coordinate.
Definition: vehicle_base.h:268
Vehicle is not visible.
Definition: vehicle_base.h:30
Vehicle details; Window numbers:
Definition: window_type.h:193
Station * neutral_station
Associated neutral station.
Definition: industry.h:43
static DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:722
Base functions for all Games.
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:554
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:45
uint32 maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Base for ships.
Running costs ships.
Definition: economy_type.h:154
Functions that have tunnels and bridges in common.
Base of all industries.
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:39
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:313
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:280
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:286
int32 x_pos
x coordinate.
Definition: vehicle_base.h:266
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:30
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:95
Functions related to NewGRF provided sounds.
DiagDirection
Enumeration for diagonal directions.
Base functions for all AIs.
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
Definition: npf.cpp:1197
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:295
The vehicle cannot enter the tile.
Definition: tile_cmd.h:23
Specification of a rectangle with absolute coordinates of all edges.
int32 y_pos
y coordinate.
Definition: vehicle_base.h:267
uint16 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:192
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:113
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:508
Window functions not directly related to making/drawing windows.
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
uint8 pathfinder_for_ships
the pathfinder to use for ships
One direction is the opposite of the other one.
#define TILE_ADD(x, y)
Adds to tiles together.
Definition: map_func.h:244
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:237
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3243
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:204
Functions related to news.
Base classes/functions for stations.
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
Build a ship.
Definition: ship_cmd.cpp:825
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:328
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
Definition: date.cpp:26
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
TileIndex new_tile
Tile of the vehicle after moving.
Definition: vehicle_func.h:78
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: ship_cmd.cpp:887
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
This depot order is because of the servicing limit.
Definition: order_type.h:95
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:2242
bool NPFShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using NPF.
Definition: npf.cpp:1218
Station data structure.
Definition: station_base.h:450
Axis
Allow incrementing of DiagDirDiff variables.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:383
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:98
Date GetLifeLengthInDays() const
Returns the vehicle&#39;s (not model&#39;s!) life length in days.
Definition: engine.cpp:444
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:311
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:316
static Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
Definition: vehicle.cpp:2386
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:3316
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:217
int16 rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:30
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:252
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:461
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
Ship()
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:34
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
Definition: news_func.h:30