OpenTTD
ship_cmd.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "ship.h"
14 #include "landscape.h"
15 #include "timetable.h"
16 #include "news_func.h"
17 #include "company_func.h"
19 #include "depot_base.h"
20 #include "station_base.h"
21 #include "newgrf_engine.h"
22 #include "pathfinder/yapf/yapf.h"
23 #include "newgrf_sound.h"
24 #include "spritecache.h"
25 #include "strings_func.h"
26 #include "window_func.h"
27 #include "date_func.h"
28 #include "vehicle_func.h"
29 #include "sound_func.h"
30 #include "ai/ai.hpp"
31 #include "game/game.hpp"
33 #include "engine_base.h"
34 #include "company_base.h"
35 #include "tunnelbridge_map.h"
36 #include "zoom_func.h"
37 #include "framerate_type.h"
38 
39 #include "table/strings.h"
40 
41 #include "safeguards.h"
42 
49 {
50  if (HasTileWaterClass(tile)) return GetWaterClass(tile);
51  if (IsTileType(tile, MP_TUNNELBRIDGE)) {
53  return WATER_CLASS_CANAL;
54  }
55  if (IsTileType(tile, MP_RAILWAY)) {
56  assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
57  return WATER_CLASS_SEA;
58  }
59  NOT_REACHED();
60 }
61 
62 static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
63 
64 template <>
65 bool IsValidImageIndex<VEH_SHIP>(uint8 image_index)
66 {
67  return image_index < lengthof(_ship_sprites);
68 }
69 
70 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
71 {
73 }
74 
75 static void GetShipIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
76 {
77  const Engine *e = Engine::Get(engine);
78  uint8 spritenum = e->u.ship.image_index;
79 
80  if (is_custom_sprite(spritenum)) {
81  GetCustomVehicleIcon(engine, DIR_W, image_type, result);
82  if (result->IsValid()) return;
83 
84  spritenum = e->original_image_index;
85  }
86 
87  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
88  result->Set(DIR_W + _ship_sprites[spritenum]);
89 }
90 
91 void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
92 {
93  VehicleSpriteSeq seq;
94  GetShipIcon(engine, image_type, &seq);
95 
96  Rect rect;
97  seq.GetBounds(&rect);
98  preferred_x = Clamp(preferred_x,
99  left - UnScaleGUI(rect.left),
100  right - UnScaleGUI(rect.right));
101 
102  seq.Draw(preferred_x, y, pal, pal == PALETTE_CRASH);
103 }
104 
114 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
115 {
116  VehicleSpriteSeq seq;
117  GetShipIcon(engine, image_type, &seq);
118 
119  Rect rect;
120  seq.GetBounds(&rect);
121 
122  width = UnScaleGUI(rect.right - rect.left + 1);
123  height = UnScaleGUI(rect.bottom - rect.top + 1);
124  xoffs = UnScaleGUI(rect.left);
125  yoffs = UnScaleGUI(rect.top);
126 }
127 
128 void Ship::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
129 {
130  uint8 spritenum = this->spritenum;
131 
132  if (image_type == EIT_ON_MAP) direction = this->rotation;
133 
134  if (is_custom_sprite(spritenum)) {
135  GetCustomVehicleSprite(this, direction, image_type, result);
136  if (result->IsValid()) return;
137 
138  spritenum = this->GetEngine()->original_image_index;
139  }
140 
141  assert(IsValidImageIndex<VEH_SHIP>(spritenum));
142  result->Set(_ship_sprites[spritenum] + direction);
143 }
144 
145 static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
146 {
147  /* Find the closest depot */
148  const Depot *depot;
149  const Depot *best_depot = NULL;
150  /* If we don't have a maximum distance, i.e. distance = 0,
151  * we want to find any depot so the best distance of no
152  * depot must be more than any correct distance. On the
153  * other hand if we have set a maximum distance, any depot
154  * further away than max_distance can safely be ignored. */
155  uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1;
156 
157  FOR_ALL_DEPOTS(depot) {
158  TileIndex tile = depot->xy;
159  if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
160  uint dist = DistanceManhattan(tile, v->tile);
161  if (dist < best_dist) {
162  best_dist = dist;
163  best_depot = depot;
164  }
165  }
166  }
167 
168  return best_depot;
169 }
170 
171 static void CheckIfShipNeedsService(Vehicle *v)
172 {
173  if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
174  if (v->IsChainInDepot()) {
176  return;
177  }
178 
179  uint max_distance;
181  case VPF_OPF: max_distance = 12; break;
184  default: NOT_REACHED();
185  }
186 
187  const Depot *depot = FindClosestShipDepot(v, max_distance);
188 
189  if (depot == NULL) {
190  if (v->current_order.IsType(OT_GOTO_DEPOT)) {
193  }
194  return;
195  }
196 
198  v->SetDestTile(depot->xy);
200 }
201 
206 {
207  const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
208 
209  /* Get speed fraction for the current water type. Aqueducts are always canals. */
210  bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
211  uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
212  this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
213 
214  /* Update cargo aging period. */
215  this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
216 
217  this->UpdateVisualEffect();
218 }
219 
221 {
222  const Engine *e = this->GetEngine();
223  uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
224  return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
225 }
226 
228 {
229  if ((++this->day_counter & 7) == 0) {
230  DecreaseVehicleValue(this);
231  }
232 
233  CheckVehicleBreakdown(this);
234  AgeVehicle(this);
235  CheckIfShipNeedsService(this);
236 
237  CheckOrders(this);
238 
239  if (this->running_ticks == 0) return;
240 
242 
243  this->profit_this_year -= cost.GetCost();
244  this->running_ticks = 0;
245 
247 
249  /* we need this for the profit */
251 }
252 
254 {
255  if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
256 
257  if (this->IsInDepot()) {
258  /* We'll assume the ship is facing outwards */
260  }
261 
262  if (this->state == TRACK_BIT_WORMHOLE) {
263  /* ship on aqueduct, so just use his direction and assume a diagonal track */
265  }
266 
268 }
269 
271 {
272  this->colourmap = PAL_NONE;
273  this->UpdateViewport(true, false);
274  this->UpdateCache();
275 }
276 
277 static void PlayShipSound(const Vehicle *v)
278 {
279  if (!PlayVehicleSound(v, VSE_START)) {
280  SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v);
281  }
282 }
283 
285 {
286  PlayShipSound(this);
287 }
288 
290 {
291  if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
292 
293  const Station *st = Station::Get(station);
294  if (st->dock_tile != INVALID_TILE) {
296  } else {
297  this->IncrementRealOrderIndex();
298  return 0;
299  }
300 }
301 
303 {
304  static const int8 _delta_xy_table[8][4] = {
305  /* y_extent, x_extent, y_offs, x_offs */
306  { 6, 6, -3, -3}, // N
307  { 6, 32, -3, -16}, // NE
308  { 6, 6, -3, -3}, // E
309  {32, 6, -16, -3}, // SE
310  { 6, 6, -3, -3}, // S
311  { 6, 32, -3, -16}, // SW
312  { 6, 6, -3, -3}, // W
313  {32, 6, -16, -3}, // NW
314  };
315 
316  const int8 *bb = _delta_xy_table[this->rotation];
317  this->x_offs = bb[3];
318  this->y_offs = bb[2];
319  this->x_extent = bb[1];
320  this->y_extent = bb[0];
321  this->z_extent = 6;
322 
323  if (this->direction != this->rotation) {
324  /* If we are rotating, then it is possible the ship was moved to its next position. In that
325  * case, because we are still showing the old direction, the ship will appear to glitch sideways
326  * slightly. We can work around this by applying an additional offset to make the ship appear
327  * where it was before it moved. */
328  this->x_offs -= this->x_pos - this->rotation_x_pos;
329  this->y_offs -= this->y_pos - this->rotation_y_pos;
330  }
331 }
332 
336 static Vehicle *EnsureNoVisibleShipProc(Vehicle *v, void *data)
337 {
338  return v->type == VEH_SHIP && (v->vehstatus & VS_HIDDEN) == 0 ? v : NULL;
339 }
340 
341 static bool CheckShipLeaveDepot(Ship *v)
342 {
343  if (!v->IsChainInDepot()) return false;
344 
345  /* We are leaving a depot, but have to go to the exact same one; re-enter */
346  if (v->current_order.IsType(OT_GOTO_DEPOT) &&
349  return true;
350  }
351 
352  /* Don't leave depot if no destination set */
353  if (v->dest_tile == 0) return true;
354 
355  /* Don't leave depot if another vehicle is already entering/leaving */
356  /* This helps avoid CPU load if many ships are set to start at the same time */
357  if (HasVehicleOnPos(v->tile, NULL, &EnsureNoVisibleShipProc)) return true;
358 
359  TileIndex tile = v->tile;
360  Axis axis = GetShipDepotAxis(tile);
361 
362  DiagDirection north_dir = ReverseDiagDir(AxisToDiagDir(axis));
363  TileIndex north_neighbour = TILE_ADD(tile, TileOffsByDiagDir(north_dir));
364  DiagDirection south_dir = AxisToDiagDir(axis);
365  TileIndex south_neighbour = TILE_ADD(tile, 2 * TileOffsByDiagDir(south_dir));
366 
367  TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
368  TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
369  if (north_tracks && south_tracks) {
370  /* Ask pathfinder for best direction */
371  bool reverse = false;
372  bool path_found;
374  case VPF_OPF: reverse = OPFShipChooseTrack(v, north_neighbour, north_dir, north_tracks, path_found) == INVALID_TRACK; break; // OPF always allows reversing
375  case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
376  case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
377  default: NOT_REACHED();
378  }
379  if (reverse) north_tracks = TRACK_BIT_NONE;
380  }
381 
382  if (north_tracks) {
383  /* Leave towards north */
384  v->rotation = v->direction = DiagDirToDir(north_dir);
385  } else if (south_tracks) {
386  /* Leave towards south */
387  v->rotation = v->direction = DiagDirToDir(south_dir);
388  } else {
389  /* Both ways blocked */
390  return false;
391  }
392 
393  v->state = AxisToTrackBits(axis);
394  v->vehstatus &= ~VS_HIDDEN;
395 
396  v->cur_speed = 0;
397  v->UpdateViewport(true, true);
399 
400  PlayShipSound(v);
404 
405  return false;
406 }
407 
408 static bool ShipAccelerate(Vehicle *v)
409 {
410  uint spd;
411  byte t;
412 
413  spd = min(v->cur_speed + 1, v->vcache.cached_max_speed);
414  spd = min(spd, v->current_order.GetMaxSpeed() * 2);
415 
416  /* updates statusbar only if speed have changed to save CPU time */
417  if (spd != v->cur_speed) {
418  v->cur_speed = spd;
420  }
421 
422  /* Convert direction-independent speed into direction-dependent speed. (old movement method) */
423  spd = v->GetOldAdvanceSpeed(spd);
424 
425  if (spd == 0) return false;
426  if ((byte)++spd == 0) return true;
427 
428  v->progress = (t = v->progress) - (byte)spd;
429 
430  return (t < v->progress);
431 }
432 
438 static void ShipArrivesAt(const Vehicle *v, Station *st)
439 {
440  /* Check if station was ever visited before */
441  if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
442  st->had_vehicle_of_type |= HVOT_SHIP;
443 
444  SetDParam(0, st->index);
446  STR_NEWS_FIRST_SHIP_ARRIVAL,
448  v->index,
449  st->index
450  );
451  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
452  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
453  }
454 }
455 
456 
467 {
468  assert(IsValidDiagDirection(enterdir));
469 
470  bool path_found = true;
471  Track track;
472 
473  if (v->dest_tile == 0 || DistanceManhattan(tile, v->dest_tile) > SHIP_MAX_ORDER_DISTANCE + 5) {
474  /* No destination or destination too far, don't invoke pathfinder. */
475  track = TrackBitsToTrack(v->state);
476  if (!IsDiagonalTrack(track)) track = TrackToOppositeTrack(track);
477  if (!HasBit(tracks, track)) {
478  /* Can't continue in same direction so pick first available track. */
481  if (tracks == TRACK_BIT_NONE) return INVALID_TRACK;
482  }
483  track = FindFirstTrack(tracks);
484  }
485  path_found = false;
486  } else {
487  /* Attempt to follow cached path. */
488  if (!v->path.empty()) {
489  track = TrackdirToTrack(v->path.front());
490 
491  if (HasBit(tracks, track)) {
492  v->path.pop_front();
493  /* HandlePathfindResult() is not called here because this is not a new pathfinder result. */
494  return track;
495  }
496 
497  /* Cached path is invalid so continue with pathfinder. */
498  v->path.clear();
499  }
500 
502  case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
503  case VPF_NPF: track = NPFShipChooseTrack(v, path_found); break;
504  case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found, v->path); break;
505  default: NOT_REACHED();
506  }
507  }
508 
509  v->HandlePathfindingResult(path_found);
510  return track;
511 }
512 
521 {
522  TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
523 
524  /* Do not remove 90 degree turns for OPF, as it isn't able to find paths taking it into account. */
526 
527  return tracks;
528 }
529 
530 static const byte _ship_subcoord[4][6][3] = {
531  {
532  {15, 8, 1},
533  { 0, 0, 0},
534  { 0, 0, 0},
535  {15, 8, 2},
536  {15, 7, 0},
537  { 0, 0, 0},
538  },
539  {
540  { 0, 0, 0},
541  { 8, 0, 3},
542  { 7, 0, 2},
543  { 0, 0, 0},
544  { 8, 0, 4},
545  { 0, 0, 0},
546  },
547  {
548  { 0, 8, 5},
549  { 0, 0, 0},
550  { 0, 7, 6},
551  { 0, 0, 0},
552  { 0, 0, 0},
553  { 0, 8, 4},
554  },
555  {
556  { 0, 0, 0},
557  { 8, 15, 7},
558  { 0, 0, 0},
559  { 8, 15, 6},
560  { 0, 0, 0},
561  { 7, 15, 0},
562  }
563 };
564 
570 static int ShipTestUpDownOnLock(const Ship *v)
571 {
572  /* Suitable tile? */
573  if (!IsTileType(v->tile, MP_WATER) || !IsLock(v->tile) || GetLockPart(v->tile) != LOCK_PART_MIDDLE) return 0;
574 
575  /* Must be at the centre of the lock */
576  if ((v->x_pos & 0xF) != 8 || (v->y_pos & 0xF) != 8) return 0;
577 
579  assert(IsValidDiagDirection(diagdir));
580 
581  if (DirToDiagDir(v->direction) == diagdir) {
582  /* Move up */
583  return (v->z_pos < GetTileMaxZ(v->tile) * (int)TILE_HEIGHT) ? 1 : 0;
584  } else {
585  /* Move down */
586  return (v->z_pos > GetTileZ(v->tile) * (int)TILE_HEIGHT) ? -1 : 0;
587  }
588 }
589 
595 static bool ShipMoveUpDownOnLock(Ship *v)
596 {
597  /* Moving up/down through lock */
598  int dz = ShipTestUpDownOnLock(v);
599  if (dz == 0) return false;
600 
601  if (v->cur_speed != 0) {
602  v->cur_speed = 0;
604  }
605 
606  if ((v->tick_counter & 7) == 0) {
607  v->z_pos += dz;
608  v->UpdatePosition();
609  v->UpdateViewport(true, true);
610  }
611 
612  return true;
613 }
614 
615 static void ShipController(Ship *v)
616 {
617  uint32 r;
618  const byte *b;
619  Track track;
620  TrackBits tracks;
621 
622  v->tick_counter++;
623  v->current_order_time++;
624 
625  if (v->HandleBreakdown()) return;
626 
627  if (v->vehstatus & VS_STOPPED) return;
628 
629  ProcessOrders(v);
630  v->HandleLoading();
631 
632  if (v->current_order.IsType(OT_LOADING)) return;
633 
634  if (CheckShipLeaveDepot(v)) return;
635 
636  v->ShowVisualEffect();
637 
638  /* Rotating on spot */
639  if (v->direction != v->rotation) {
640  if ((v->tick_counter & 7) == 0) {
641  DirDiff diff = DirDifference(v->direction, v->rotation);
643  v->UpdateViewport(true, true);
644  }
645  return;
646  }
647 
648  if (ShipMoveUpDownOnLock(v)) return;
649 
650  if (!ShipAccelerate(v)) return;
651 
653  if (v->state != TRACK_BIT_WORMHOLE) {
654  /* Not on a bridge */
655  if (gp.old_tile == gp.new_tile) {
656  /* Staying in tile */
657  if (v->IsInDepot()) {
658  gp.x = v->x_pos;
659  gp.y = v->y_pos;
660  } else {
661  /* Not inside depot */
662  r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
663  if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
664 
665  /* A leave station order only needs one tick to get processed, so we can
666  * always skip ahead. */
667  if (v->current_order.IsType(OT_LEAVESTATION)) {
668  v->current_order.Free();
670  /* Test if continuing forward would lead to a dead-end, moving into the dock. */
671  DiagDirection exitdir = VehicleExitDir(v->direction, v->state);
672  TileIndex tile = TileAddByDiagDir(v->tile, exitdir);
673  if (TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0, exitdir)) == TRACK_BIT_NONE) goto reverse_direction;
674  } else if (v->dest_tile != 0) {
675  /* We have a target, let's see if we reached it... */
676  if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
677  DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
678  /* We got within 3 tiles of our target buoy, so let's skip to our
679  * next order */
680  UpdateVehicleTimetable(v, true);
683  } else {
684  /* Non-buoy orders really need to reach the tile */
685  if (v->dest_tile == gp.new_tile) {
686  if (v->current_order.IsType(OT_GOTO_DEPOT)) {
687  if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
689  return;
690  }
691  } else if (v->current_order.IsType(OT_GOTO_STATION)) {
693 
694  /* Process station in the orderlist. */
696  if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
697  ShipArrivesAt(v, st);
698  v->BeginLoading();
699  } else { // leave stations without docks right aways
702  }
703  }
704  }
705  }
706  }
707  }
708  } else {
709  /* New tile */
710  if (!IsValidTile(gp.new_tile)) goto reverse_direction;
711 
713  assert(diagdir != INVALID_DIAGDIR);
714  tracks = GetAvailShipTracks(gp.new_tile, diagdir, v->GetVehicleTrackdir());
715  if (tracks == TRACK_BIT_NONE) goto reverse_direction;
716 
717  /* Choose a direction, and continue if we find one */
718  track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
719  if (track == INVALID_TRACK) goto reverse_direction;
720 
721  b = _ship_subcoord[diagdir][track];
722 
723  gp.x = (gp.x & ~0xF) | b[0];
724  gp.y = (gp.y & ~0xF) | b[1];
725 
726  /* Call the landscape function and tell it that the vehicle entered the tile */
727  r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
728  if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
729 
730  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
731  v->tile = gp.new_tile;
732  v->state = TrackToTrackBits(track);
733 
734  /* Update ship cache when the water class changes. Aqueducts are always canals. */
737  if (old_wc != new_wc) v->UpdateCache();
738  }
739 
740  Direction new_direction = (Direction)b[2];
741  DirDiff diff = DirDifference(new_direction, v->direction);
742  switch (diff) {
743  case DIRDIFF_SAME:
744  case DIRDIFF_45RIGHT:
745  case DIRDIFF_45LEFT:
746  /* Continue at speed */
747  v->rotation = v->direction = new_direction;
748  break;
749 
750  default:
751  /* Stop for rotation */
752  v->cur_speed = 0;
753  v->direction = new_direction;
754  /* Remember our current location to avoid movement glitch */
755  v->rotation_x_pos = v->x_pos;
756  v->rotation_y_pos = v->y_pos;
757  break;
758  }
759  }
760  } else {
761  /* On a bridge */
763  v->x_pos = gp.x;
764  v->y_pos = gp.y;
765  v->UpdatePosition();
766  if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
767  return;
768  }
769 
770  /* Ship is back on the bridge head, we need to comsume its path
771  * cache entry here as we didn't have to choose a ship track. */
772  if (!v->path.empty()) v->path.pop_front();
773  }
774 
775  /* update image of ship, as well as delta XY */
776  v->x_pos = gp.x;
777  v->y_pos = gp.y;
778 
779 getout:
780  v->UpdatePosition();
781  v->UpdateViewport(true, true);
782  return;
783 
784 reverse_direction:
785  v->direction = ReverseDir(v->direction);
786  /* Remember our current location to avoid movement glitch */
787  v->rotation_x_pos = v->x_pos;
788  v->rotation_y_pos = v->y_pos;
789  v->cur_speed = 0;
790  v->path.clear();
791  goto getout;
792 }
793 
795 {
797 
798  if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
799 
800  ShipController(this);
801 
802  return true;
803 }
804 
805 void Ship::SetDestTile(TileIndex tile)
806 {
807  if (tile == this->dest_tile) return;
808  this->path.clear();
809  this->dest_tile = tile;
810 }
811 
821 CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
822 {
823  tile = GetShipDepotNorthTile(tile);
824  if (flags & DC_EXEC) {
825  int x;
826  int y;
827 
828  const ShipVehicleInfo *svi = &e->u.ship;
829 
830  Ship *v = new Ship();
831  *ret = v;
832 
833  v->owner = _current_company;
834  v->tile = tile;
835  x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
836  y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
837  v->x_pos = x;
838  v->y_pos = y;
839  v->z_pos = GetSlopePixelZ(x, y);
840 
841  v->UpdateDeltaXY();
843 
844  v->spritenum = svi->image_index;
846  v->cargo_cap = svi->capacity;
847  v->refit_cap = 0;
848 
849  v->last_station_visited = INVALID_STATION;
850  v->last_loading_station = INVALID_STATION;
851  v->engine_type = e->index;
852 
853  v->reliability = e->reliability;
855  v->max_age = e->GetLifeLengthInDays();
856  _new_vehicle_id = v->index;
857 
858  v->state = TRACK_BIT_DEPOT;
859 
860  v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships);
862  v->build_year = _cur_year;
863  v->sprite_seq.Set(SPR_IMG_QUERY);
865 
866  v->UpdateCache();
867 
869  v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
870 
872 
873  v->cargo_cap = e->DetermineCapacity(v);
874 
876 
877  v->UpdatePosition();
878  }
879 
880  return CommandCost();
881 }
882 
883 bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
884 {
885  const Depot *depot = FindClosestShipDepot(this, 0);
886 
887  if (depot == NULL) return false;
888 
889  if (location != NULL) *location = depot->xy;
890  if (destination != NULL) *destination = depot->index;
891 
892  return true;
893 }
Information about a ship vehicle.
Definition: engine_type.h:66
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:235
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:520
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:513
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:27
Date max_age
Maximum age.
Definition: vehicle_base.h:259
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Vehicle is stopped by the player.
Definition: vehicle_base.h:33
First vehicle arrived for competitor.
Definition: news_type.h:25
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:143
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:1203
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:31
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition: vehicle.cpp:2510
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:320
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3201
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:30
DirectionByte direction
facing
Definition: vehicle_base.h:271
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:72
Yet Another PathFinder.
Definition: vehicle_type.h:65
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:1763
Functions related to time tabling.
Flag for an invalid DiagDirection.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
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:284
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:272
Use default vehicle palette.
Definition: vehicle_base.h:35
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:114
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
Definition: vehicle_type.h:90
bool Tick()
Calls the tick handler of the vehicle.
Definition: ship_cmd.cpp:794
Track
These are used to specify a single track.
Definition: track_type.h:21
uint16 cur_speed
current speed
Definition: vehicle_base.h:293
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
Definition: vehicle_base.h:124
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:98
Depot view; Window numbers:
Definition: window_type.h:346
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:279
Station has seen a ship.
Definition: station_type.h:71
Both directions faces to the same direction.
The Original PathFinder (only for ships)
Definition: vehicle_type.h:63
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition: engine_type.h:79
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:22
TileIndex dock_tile
The location of the dock.
Definition: station_base.h:461
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Definition: vehicle_base.h:303
bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: ship.h:50
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:237
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:824
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:23
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it...
Definition: vehicle.cpp:1437
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:128
PathfinderSettings pf
settings for all pathfinders
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:384
Vehicle data structure.
Definition: vehicle_base.h:212
static void ShipArrivesAt(const Vehicle *v, Station *st)
Ship arrives at a dock.
Definition: ship_cmd.cpp:438
Base for all depots (except hangars)
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:163
TrackBitsByte state
The "track" the ship is following.
Definition: ship.h:29
Start or stop this vehicle, and show information about the current state.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:30
DirectionByte rotation
Visible direction.
Definition: ship.h:31
bool forbid_90_deg
forbid trains to make 90 deg turns
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:241
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:302
uint16 reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:262
A railway.
Definition: tile_type.h:44
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition: vehicle.cpp:776
Common return value for all commands.
Definition: command_type.h:25
int16 rotation_y_pos
NOSAVE: Y Position before rotation.
Definition: ship.h:33
byte vehstatus
Status.
Definition: vehicle_base.h:317
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:89
byte flags
Flags of the engine.
Definition: engine_base.h:35
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:123
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition: vehicle.cpp:253
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:744
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:81
void OnNewDay()
Calls the new day handler of the vehicle.
Definition: ship_cmd.cpp:227
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Entry point for OpenTTD to YAPF.
byte VehicleRandomBits()
Get a value for a vehicle&#39;s random_bits.
Definition: vehicle.cpp:363
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:966
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:280
Direction
Defines the 8 directions on the map.
uint16 max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition: engine_type.h:69
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:123
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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:61
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:203
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:163
bool YapfShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using YAPF. ...
Definition: yapf_ship.cpp:252
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:41
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:307
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:216
Vehicle is crashed.
Definition: vehicle_base.h:39
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:46
static DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
Definition: map_func.h:396
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:205
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:28
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:152
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: ship_cmd.cpp:302
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Definition: ship_cmd.cpp:270
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:78
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
Definition: vehicle.cpp:1331
bool IsValid() const
Check whether the sequence contains any sprites.
Definition: vehicle_base.h:147
West.
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
void MakeDummy()
Makes this order a Dummy order.
Definition: order_cmd.cpp:135
int8 y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:287
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:49
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:343
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:24
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:281
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Definition: vehicle_base.h:460
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Definition: order_cmd.cpp:2171
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
Definition: ship_cmd.cpp:48
Water tile.
Definition: tile_type.h:49
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:283
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
Vehicle starting, i.e. leaving, the station.
Definition: newgrf_sound.h:21
Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
Finds the best track to choose on the next tile and returns INVALID_TRACK when it is better to revers...
Definition: opf_ship.cpp:196
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:305
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:336
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
Vehicle view; Window numbers:
Definition: window_type.h:334
Number of ticks before carried cargo is aged.
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
New PathFinder.
Definition: vehicle_type.h:64
Grass with a fence and shore or water on the free halftile.
Definition: rail_map.h:500
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:508
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Definition: ship_cmd.cpp:128
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:547
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition: vehicle.cpp:1675
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:286
StationFacilityByte facilities
The facilities that this station has.
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
DiagDirection
Enumeration for diagonal directions.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
static bool IsShipDepotTile(TileIndex t)
Is it a ship depot tile?
Definition: water_map.h:226
Station with a dock.
Definition: station_type.h:58
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:308
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:241
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:299
static bool ShipMoveUpDownOnLock(Ship *v)
Test and move a ship up or down in a lock.
Definition: ship_cmd.cpp:595
Functions related to sound.
uint16 reliability
Reliability.
Definition: vehicle_base.h:261
Functions to cache sprites in memory.
Running costs ships.
Definition: economy_type.h:156
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:314
All ships have this type.
Definition: ship.h:28
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:54
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:257
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:591
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=NULL) const
Determines capacity of a given vehicle from scratch.
Definition: engine.cpp:206
Ship vehicle type.
Definition: vehicle_type.h:28
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:238
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
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:583
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: ship_cmd.cpp:289
TileIndex old_tile
Current tile of the vehicle.
Definition: vehicle_func.h:79
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Definition: map_func.h:232
static bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:629
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:58
execute the given command
Definition: command_type.h:345
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:87
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:1621
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1560
Base class for engines.
Flag for an invalid track.
Definition: track_type.h:30
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:140
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
Definition: vehicle.cpp:164
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:3215
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:92
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:1265
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:143
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
Ships list; Window numbers:
Definition: window_type.h:315
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1580
Bitflag for a depot.
Definition: track_type.h:59
Middle part of a lock.
Definition: water_map.h:67
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:159
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition: vehicle.cpp:2032
void MakeLeaveStation()
Makes this order a Leave Station order.
Definition: order_cmd.cpp:126
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:260
Position information of a vehicle after it moved.
Definition: vehicle_func.h:77
First vehicle arrived for company.
Definition: news_type.h:24
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
void Free()
&#39;Free&#39; the order
Definition: order_cmd.cpp:65
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
Functions related to zooming.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: ship_cmd.cpp:253
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:187
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:373
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:270
Vehicle is not visible.
Definition: vehicle_base.h:32
Vehicle details; Window numbers:
Definition: window_type.h:195
static DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:724
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:570
uint32 maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Base for ships.
Original pathfinder for ships; very simple.
Functions that have tunnels and bridges in common.
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:41
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:315
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:282
static TileIndexDiffC GetDockOffset(TileIndex t)
Get the tileoffset from this tile a ship should target to get to this dock.
Definition: station_map.h:444
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
static TrackBits TrackCrossesTracks(Track track)
Maps a track to all tracks that make 90 deg turns with it.
Definition: track_func.h:430
int32 x_pos
x coordinate.
Definition: vehicle_base.h:268
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:32
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.
Base functions for all AIs.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
Definition: npf.cpp:1155
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:297
The vehicle cannot enter the tile.
Definition: tile_cmd.h:25
Specification of a rectangle with absolute coordinates of all edges.
int32 y_pos
y coordinate.
Definition: vehicle_base.h:269
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:194
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Definition: vehicle_base.h:510
Window functions not directly related to making/drawing windows.
Flag for an invalid trackdir.
Definition: track_type.h:93
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:246
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:239
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3229
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:821
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:330
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
Definition: date.cpp:28
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
TileIndex new_tile
Tile of the vehicle after moving.
Definition: vehicle_func.h:80
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:883
This depot order is because of the servicing limit.
Definition: order_type.h:101
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
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:2241
bool NPFShipCheckReverse(const Ship *v)
Returns true if it is better to reverse the ship before leaving depot using NPF.
Definition: npf.cpp:1176
Station data structure.
Definition: station_base.h:446
No track.
Definition: track_type.h:42
Axis
Allow incrementing of DiagDirDiff variables.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
Definition: vehicle_base.h:385
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:100
Date GetLifeLengthInDays() const
Returns the vehicle&#39;s (not model&#39;s!) life length in days.
Definition: engine.cpp:446
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:313
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
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:2387
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:3301
Money GetRunningCost() const
Gets the running cost of a vehicle.
Definition: ship_cmd.cpp:220
int16 rotation_x_pos
NOSAVE: X Position before rotation.
Definition: ship.h:32
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:254
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:466
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Ship()
We don&#39;t want GCC to zero our struct! It already is zeroed and has an index!
Definition: ship.h:36
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
Definition: news_func.h:32