OpenTTD Source  14.0-beta3
roadveh_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 "roadveh.h"
12 #include "command_func.h"
13 #include "error_func.h"
14 #include "news_func.h"
16 #include "station_base.h"
17 #include "company_func.h"
18 #include "articulated_vehicles.h"
19 #include "newgrf_sound.h"
20 #include "pathfinder/yapf/yapf.h"
21 #include "strings_func.h"
22 #include "tunnelbridge_map.h"
25 #include "vehicle_func.h"
26 #include "sound_func.h"
27 #include "ai/ai.hpp"
28 #include "game/game.hpp"
29 #include "depot_map.h"
30 #include "effectvehicle_func.h"
31 #include "roadstop_base.h"
32 #include "spritecache.h"
33 #include "core/random_func.hpp"
34 #include "company_base.h"
35 #include "core/backup_type.hpp"
36 #include "newgrf.h"
37 #include "zoom_func.h"
38 #include "framerate_type.h"
39 #include "roadveh_cmd.h"
40 #include "road_cmd.h"
41 
42 #include "table/strings.h"
43 
44 #include "safeguards.h"
45 
46 static const uint16_t _roadveh_images[] = {
47  0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
48  0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74,
49  0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C,
50  0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC,
51  0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC,
52  0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4,
53  0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C,
54  0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4
55 };
56 
57 static const uint16_t _roadveh_full_adder[] = {
58  0, 88, 0, 0, 0, 0, 48, 48,
59  48, 48, 0, 0, 64, 64, 0, 16,
60  16, 0, 88, 0, 0, 0, 0, 48,
61  48, 48, 48, 0, 0, 64, 64, 0,
62  16, 16, 0, 88, 0, 0, 0, 0,
63  48, 48, 48, 48, 0, 0, 64, 64,
64  0, 16, 16, 0, 8, 8, 8, 8,
65  0, 0, 0, 8, 8, 8, 8
66 };
67 static_assert(lengthof(_roadveh_images) == lengthof(_roadveh_full_adder));
68 
69 template <>
70 bool IsValidImageIndex<VEH_ROAD>(uint8_t image_index)
71 {
72  return image_index < lengthof(_roadveh_images);
73 }
74 
75 static const Trackdir _road_reverse_table[DIAGDIR_END] = {
77 };
78 
83 bool RoadVehicle::IsBus() const
84 {
85  assert(this->IsFrontEngine());
87 }
88 
95 {
96  int reference_width = ROADVEHINFO_DEFAULT_VEHICLE_WIDTH;
97 
98  if (offset != nullptr) {
99  offset->x = ScaleSpriteTrad(reference_width) / 2;
100  offset->y = 0;
101  }
102  return ScaleSpriteTrad(this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH);
103 }
104 
105 static void GetRoadVehIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
106 {
107  const Engine *e = Engine::Get(engine);
108  uint8_t spritenum = e->u.road.image_index;
109 
110  if (is_custom_sprite(spritenum)) {
111  GetCustomVehicleIcon(engine, DIR_W, image_type, result);
112  if (result->IsValid()) return;
113 
115  }
116 
117  assert(IsValidImageIndex<VEH_ROAD>(spritenum));
118  result->Set(DIR_W + _roadveh_images[spritenum]);
119 }
120 
121 void RoadVehicle::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
122 {
123  uint8_t spritenum = this->spritenum;
124 
125  if (is_custom_sprite(spritenum)) {
126  GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum)), image_type, result);
127  if (result->IsValid()) return;
128 
130  }
131 
132  assert(IsValidImageIndex<VEH_ROAD>(spritenum));
133  SpriteID sprite = direction + _roadveh_images[spritenum];
134 
135  if (this->cargo.StoredCount() >= this->cargo_cap / 2U) sprite += _roadveh_full_adder[spritenum];
136 
137  result->Set(sprite);
138 }
139 
149 void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
150 {
151  VehicleSpriteSeq seq;
152  GetRoadVehIcon(engine, image_type, &seq);
153 
154  Rect rect;
155  seq.GetBounds(&rect);
156  preferred_x = Clamp(preferred_x,
157  left - UnScaleGUI(rect.left),
158  right - UnScaleGUI(rect.right));
159 
160  seq.Draw(preferred_x, y, pal, pal == PALETTE_CRASH);
161 }
162 
172 void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
173 {
174  VehicleSpriteSeq seq;
175  GetRoadVehIcon(engine, image_type, &seq);
176 
177  Rect rect;
178  seq.GetBounds(&rect);
179 
180  width = UnScaleGUI(rect.Width());
181  height = UnScaleGUI(rect.Height());
182  xoffs = UnScaleGUI(rect.left);
183  yoffs = UnScaleGUI(rect.top);
184 }
185 
191 static uint GetRoadVehLength(const RoadVehicle *v)
192 {
193  const Engine *e = v->GetEngine();
194  uint length = VEHICLE_LENGTH;
195 
196  uint16_t veh_len = CALLBACK_FAILED;
197  if (e->GetGRF() != nullptr && e->GetGRF()->grf_version >= 8) {
198  /* Use callback 36 */
199  veh_len = GetVehicleProperty(v, PROP_ROADVEH_SHORTEN_FACTOR, CALLBACK_FAILED);
200  if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len);
201  } else {
202  /* Use callback 11 */
203  veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v);
204  }
205  if (veh_len == CALLBACK_FAILED) veh_len = e->u.road.shorten_factor;
206  if (veh_len != 0) {
207  length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
208  }
209 
210  return length;
211 }
212 
219 void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
220 {
221  assert(v->type == VEH_ROAD);
222  assert(v->IsFrontEngine());
223 
225 
227 
228  for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
229  /* Check the v->first cache. */
230  assert(u->First() == v);
231 
232  /* Update the 'first engine' */
233  u->gcache.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type;
234 
235  /* Update the length of the vehicle. */
236  uint veh_len = GetRoadVehLength(u);
237  /* Verify length hasn't changed. */
238  if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(u);
239 
240  u->gcache.cached_veh_length = veh_len;
241  v->gcache.cached_total_length += u->gcache.cached_veh_length;
242 
243  /* Update visual effect */
244  u->UpdateVisualEffect();
245 
246  /* Update cargo aging period. */
247  u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_ROADVEH_CARGO_AGE_PERIOD, EngInfo(u->engine_type)->cargo_age_period);
248  }
249 
250  uint max_speed = GetVehicleProperty(v, PROP_ROADVEH_SPEED, 0);
251  v->vcache.cached_max_speed = (max_speed != 0) ? max_speed * 4 : RoadVehInfo(v->engine_type)->max_speed;
252 }
253 
263 {
264  /* Check that the vehicle can drive on the road in question */
265  RoadType rt = e->u.road.roadtype;
266  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
267  if (!HasTileAnyRoadType(tile, rti->powered_roadtypes)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE);
268 
269  if (flags & DC_EXEC) {
270  const RoadVehicleInfo *rvi = &e->u.road;
271 
272  RoadVehicle *v = new RoadVehicle();
273  *ret = v;
275  v->owner = _current_company;
276 
277  v->tile = tile;
278  int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
279  int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
280  v->x_pos = x;
281  v->y_pos = y;
282  v->z_pos = GetSlopePixelZ(x, y, true);
283 
284  v->state = RVSB_IN_DEPOT;
286 
287  v->spritenum = rvi->image_index;
289  assert(IsValidCargoID(v->cargo_type));
290  v->cargo_cap = rvi->capacity;
291  v->refit_cap = 0;
292 
293  v->last_station_visited = INVALID_STATION;
294  v->last_loading_station = INVALID_STATION;
295  v->engine_type = e->index;
296  v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
297 
298  v->reliability = e->reliability;
300  v->max_age = e->GetLifeLengthInDays();
301 
302  v->SetServiceInterval(Company::Get(v->owner)->settings.vehicle.servint_roadveh);
303 
307 
308  v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
309  v->random_bits = Random();
310  v->SetFrontEngine();
311 
312  v->roadtype = rt;
315 
317  v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
318 
321 
322  /* Call various callbacks after the whole consist has been constructed */
323  for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
324  u->cargo_cap = u->GetEngine()->DetermineCapacity(u);
325  u->refit_cap = 0;
327  u->InvalidateNewGRFCache();
328  }
330  /* Initialize cached values for realistic acceleration. */
332 
333  v->UpdatePosition();
334 
336  }
337 
338  return CommandCost();
339 }
340 
341 static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance)
342 {
343  if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
344 
346  case VPF_NPF: return NPFRoadVehicleFindNearestDepot(v, max_distance);
347  case VPF_YAPF: return YapfRoadVehicleFindNearestDepot(v, max_distance);
348 
349  default: NOT_REACHED();
350  }
351 }
352 
354 {
355  FindDepotData rfdd = FindClosestRoadDepot(this, 0);
356  if (rfdd.best_length == UINT_MAX) return ClosestDepot();
357 
358  return ClosestDepot(rfdd.tile, GetDepotIndex(rfdd.tile));
359 }
360 
368 {
370  if (v == nullptr) return CMD_ERROR;
371 
372  if (!v->IsPrimaryVehicle()) return CMD_ERROR;
373 
374  CommandCost ret = CheckOwnership(v->owner);
375  if (ret.Failed()) return ret;
376 
377  if ((v->vehstatus & VS_STOPPED) ||
378  (v->vehstatus & VS_CRASHED) ||
379  v->breakdown_ctr != 0 ||
380  v->overtaking != 0 ||
381  v->state == RVSB_WORMHOLE ||
382  v->IsInDepot() ||
383  v->current_order.IsType(OT_LOADING)) {
384  return CMD_ERROR;
385  }
386 
388 
390 
391  if (flags & DC_EXEC) {
392  v->reverse_ctr = 180;
393 
394  /* Unbunching data is no longer valid. */
396  }
397 
398  return CommandCost();
399 }
400 
401 
403 {
404  for (RoadVehicle *v = this; v != nullptr; v = v->Next()) {
405  v->colourmap = PAL_NONE;
406  v->UpdateViewport(true, false);
407  }
408  this->CargoChanged();
409 }
410 
412 {
413  static const int8_t _delta_xy_table[8][10] = {
414  /* y_extent, x_extent, y_offs, x_offs, y_bb_offs, x_bb_offs, y_extent_shorten, x_extent_shorten, y_bb_offs_shorten, x_bb_offs_shorten */
415  {3, 3, -1, -1, 0, 0, -1, -1, -1, -1}, // N
416  {3, 7, -1, -3, 0, -1, 0, -1, 0, 0}, // NE
417  {3, 3, -1, -1, 0, 0, 1, -1, 1, -1}, // E
418  {7, 3, -3, -1, -1, 0, 0, 0, 1, 0}, // SE
419  {3, 3, -1, -1, 0, 0, 1, 1, 1, 1}, // S
420  {3, 7, -1, -3, 0, -1, 0, 0, 0, 1}, // SW
421  {3, 3, -1, -1, 0, 0, -1, 1, -1, 1}, // W
422  {7, 3, -3, -1, -1, 0, -1, 0, 0, 0}, // NW
423  };
424 
425  int shorten = VEHICLE_LENGTH - this->gcache.cached_veh_length;
426  if (!IsDiagonalDirection(this->direction)) shorten >>= 1;
427 
428  const int8_t *bb = _delta_xy_table[this->direction];
429  this->x_bb_offs = bb[5] + bb[9] * shorten;
430  this->y_bb_offs = bb[4] + bb[8] * shorten;;
431  this->x_offs = bb[3];
432  this->y_offs = bb[2];
433  this->x_extent = bb[1] + bb[7] * shorten;
434  this->y_extent = bb[0] + bb[6] * shorten;
435  this->z_extent = 6;
436 }
437 
443 {
444  int max_speed = this->gcache.cached_max_track_speed;
445 
446  /* Limit speed to 50% while reversing, 75% in curves. */
447  for (const RoadVehicle *u = this; u != nullptr; u = u->Next()) {
448  if (_settings_game.vehicle.roadveh_acceleration_model == AM_REALISTIC) {
450  max_speed = this->gcache.cached_max_track_speed / 2;
451  break;
452  } else if ((u->direction & 1) == 0) {
453  max_speed = this->gcache.cached_max_track_speed * 3 / 4;
454  }
455  }
456 
457  /* Vehicle is on the middle part of a bridge. */
458  if (u->state == RVSB_WORMHOLE && !(u->vehstatus & VS_HIDDEN)) {
459  max_speed = std::min(max_speed, GetBridgeSpec(GetBridgeType(u->tile))->speed * 2);
460  }
461  }
462 
463  return std::min(max_speed, this->current_order.GetMaxSpeed() * 2);
464 }
465 
471 {
472  RoadVehicle *first = v->First();
473  Vehicle *u = v;
474  for (; v->Next() != nullptr; v = v->Next()) u = v;
475  u->SetNext(nullptr);
476  v->last_station_visited = first->last_station_visited; // for PreDestructor
477 
478  /* Only leave the road stop when we're really gone. */
479  if (IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile))->Leave(v);
480 
481  delete v;
482 }
483 
484 static void RoadVehSetRandomDirection(RoadVehicle *v)
485 {
486  static const DirDiff delta[] = {
488  };
489 
490  do {
491  uint32_t r = Random();
492 
493  v->direction = ChangeDir(v->direction, delta[r & 3]);
494  v->UpdateViewport(true, true);
495  } while ((v = v->Next()) != nullptr);
496 }
497 
504 {
505  v->crashed_ctr++;
506  if (v->crashed_ctr == 2) {
508  } else if (v->crashed_ctr <= 45) {
509  if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v);
510  } else if (v->crashed_ctr >= 2220 && !(v->tick_counter & 0x1F)) {
511  bool ret = v->Next() != nullptr;
513  return ret;
514  }
515 
516  return true;
517 }
518 
526 {
527  const Vehicle *u = (Vehicle*)data;
528 
529  return (v->type == VEH_TRAIN &&
530  abs(v->z_pos - u->z_pos) <= 6 &&
531  abs(v->x_pos - u->x_pos) <= 4 &&
532  abs(v->y_pos - u->y_pos) <= 4) ? v : nullptr;
533 }
534 
535 uint RoadVehicle::Crash(bool flooded)
536 {
537  uint pass = this->GroundVehicleBase::Crash(flooded);
538  if (this->IsFrontEngine()) {
539  pass += 1; // driver
540 
541  /* If we're in a drive through road stop we ought to leave it */
542  if (IsInsideMM(this->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) {
543  RoadStop::GetByTile(this->tile, GetRoadStopType(this->tile))->Leave(this);
544  }
545  }
546  this->crashed_ctr = flooded ? 2000 : 1; // max 2220, disappear pretty fast when flooded
547  return pass;
548 }
549 
550 static void RoadVehCrash(RoadVehicle *v)
551 {
552  uint pass = v->Crash();
553 
554  AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING));
555  Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING));
556 
557  SetDParam(0, pass);
558  StringID newsitem = (pass == 1) ? STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER : STR_NEWS_ROAD_VEHICLE_CRASH;
559  NewsType newstype = NT_ACCIDENT;
560 
561  if (v->owner != _local_company) {
562  newstype = NT_ACCIDENT_OTHER;
563  }
564 
565  AddTileNewsItem(newsitem, newstype, v->tile);
566 
567  ModifyStationRatingAround(v->tile, v->owner, -160, 22);
568  if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
569 }
570 
571 static bool RoadVehCheckTrainCrash(RoadVehicle *v)
572 {
573  for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
574  if (u->state == RVSB_WORMHOLE) continue;
575 
576  TileIndex tile = u->tile;
577 
578  if (!IsLevelCrossingTile(tile)) continue;
579 
581  RoadVehCrash(v);
582  return true;
583  }
584  }
585 
586  return false;
587 }
588 
589 TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
590 {
591  if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
592 
593  const Station *st = Station::Get(station);
594  if (!CanVehicleUseStation(this, st)) {
595  /* There is no stop left at the station, so don't even TRY to go there */
596  this->IncrementRealOrderIndex();
597  return 0;
598  }
599 
600  return st->xy;
601 }
602 
603 static void StartRoadVehSound(const RoadVehicle *v)
604 {
605  if (!PlayVehicleSound(v, VSE_START)) {
606  SoundID s = RoadVehInfo(v->engine_type)->sfx;
607  if (s == SND_19_DEPARTURE_OLD_RV_1 && (v->tick_counter & 3) == 0) {
609  }
610  SndPlayVehicleFx(s, v);
611  }
612 }
613 
615  int x;
616  int y;
617  const Vehicle *veh;
618  Vehicle *best;
619  uint best_diff;
620  Direction dir;
621 };
622 
623 static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
624 {
625  static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
626  static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
627 
628  RoadVehFindData *rvf = (RoadVehFindData*)data;
629 
630  short x_diff = v->x_pos - rvf->x;
631  short y_diff = v->y_pos - rvf->y;
632 
633  if (v->type == VEH_ROAD &&
634  !v->IsInDepot() &&
635  abs(v->z_pos - rvf->veh->z_pos) < 6 &&
636  v->direction == rvf->dir &&
637  rvf->veh->First() != v->First() &&
638  (dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
639  (dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) &&
640  (dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) &&
641  (dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0))) {
642  uint diff = abs(x_diff) + abs(y_diff);
643 
644  if (diff < rvf->best_diff || (diff == rvf->best_diff && v->index < rvf->best->index)) {
645  rvf->best = v;
646  rvf->best_diff = diff;
647  }
648  }
649 
650  return nullptr;
651 }
652 
653 static RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction dir, bool update_blocked_ctr = true)
654 {
655  RoadVehFindData rvf;
656  RoadVehicle *front = v->First();
657 
658  if (front->reverse_ctr != 0) return nullptr;
659 
660  rvf.x = x;
661  rvf.y = y;
662  rvf.dir = dir;
663  rvf.veh = v;
664  rvf.best_diff = UINT_MAX;
665 
666  if (front->state == RVSB_WORMHOLE) {
667  FindVehicleOnPos(v->tile, &rvf, EnumCheckRoadVehClose);
668  FindVehicleOnPos(GetOtherTunnelBridgeEnd(v->tile), &rvf, EnumCheckRoadVehClose);
669  } else {
670  FindVehicleOnPosXY(x, y, &rvf, EnumCheckRoadVehClose);
671  }
672 
673  /* This code protects a roadvehicle from being blocked for ever
674  * If more than 1480 / 74 days a road vehicle is blocked, it will
675  * drive just through it. The ultimate backup-code of TTD.
676  * It can be disabled. */
677  if (rvf.best_diff == UINT_MAX) {
678  front->blocked_ctr = 0;
679  return nullptr;
680  }
681 
682  if (update_blocked_ctr && ++front->blocked_ctr > 1480) return nullptr;
683 
684  return RoadVehicle::From(rvf.best);
685 }
686 
692 static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
693 {
694  if (v->IsBus()) {
695  /* Check if station was ever visited before */
696  if (!(st->had_vehicle_of_type & HVOT_BUS)) {
697  st->had_vehicle_of_type |= HVOT_BUS;
698  SetDParam(0, st->index);
700  RoadTypeIsRoad(v->roadtype) ? STR_NEWS_FIRST_BUS_ARRIVAL : STR_NEWS_FIRST_PASSENGER_TRAM_ARRIVAL,
702  v->index,
703  st->index
704  );
705  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
706  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
707  }
708  } else {
709  /* Check if station was ever visited before */
710  if (!(st->had_vehicle_of_type & HVOT_TRUCK)) {
711  st->had_vehicle_of_type |= HVOT_TRUCK;
712  SetDParam(0, st->index);
714  RoadTypeIsRoad(v->roadtype) ? STR_NEWS_FIRST_TRUCK_ARRIVAL : STR_NEWS_FIRST_CARGO_TRAM_ARRIVAL,
716  v->index,
717  st->index
718  );
719  AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
720  Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
721  }
722  }
723 }
724 
733 {
735  default: NOT_REACHED();
736  case AM_ORIGINAL:
737  return this->DoUpdateSpeed(this->overtaking != 0 ? 512 : 256, 0, this->GetCurrentMaxSpeed());
738 
739  case AM_REALISTIC:
740  return this->DoUpdateSpeed(this->GetAcceleration() + (this->overtaking != 0 ? 256 : 0), this->GetAccelerationStatus() == AS_BRAKE ? 0 : 4, this->GetCurrentMaxSpeed());
741  }
742 }
743 
744 static Direction RoadVehGetNewDirection(const RoadVehicle *v, int x, int y)
745 {
746  static const Direction _roadveh_new_dir[] = {
749  DIR_E , DIR_SE, DIR_S
750  };
751 
752  x = x - v->x_pos + 1;
753  y = y - v->y_pos + 1;
754 
755  if ((uint)x > 2 || (uint)y > 2) return v->direction;
756  return _roadveh_new_dir[y * 4 + x];
757 }
758 
759 static Direction RoadVehGetSlidingDirection(const RoadVehicle *v, int x, int y)
760 {
761  Direction new_dir = RoadVehGetNewDirection(v, x, y);
762  Direction old_dir = v->direction;
763  DirDiff delta;
764 
765  if (new_dir == old_dir) return old_dir;
766  delta = (DirDifference(new_dir, old_dir) > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT);
767  return ChangeDir(old_dir, delta);
768 }
769 
770 struct OvertakeData {
771  const RoadVehicle *u;
772  const RoadVehicle *v;
773  TileIndex tile;
774  Trackdir trackdir;
775 };
776 
777 static Vehicle *EnumFindVehBlockingOvertake(Vehicle *v, void *data)
778 {
779  const OvertakeData *od = (OvertakeData*)data;
780 
781  return (v->type == VEH_ROAD && v->First() == v && v != od->u && v != od->v) ? v : nullptr;
782 }
783 
791 {
792  if (!HasTileAnyRoadType(od->tile, od->v->compatible_roadtypes)) return true;
793  TrackStatus ts = GetTileTrackStatus(od->tile, TRANSPORT_ROAD, GetRoadTramType(od->v->roadtype));
794  TrackdirBits trackdirbits = TrackStatusToTrackdirBits(ts);
795  TrackdirBits red_signals = TrackStatusToRedSignals(ts); // barred level crossing
796  TrackBits trackbits = TrackdirBitsToTrackBits(trackdirbits);
797 
798  /* Track does not continue along overtaking direction || track has junction || levelcrossing is barred */
799  if (!HasBit(trackdirbits, od->trackdir) || (trackbits & ~TRACK_BIT_CROSS) || (red_signals != TRACKDIR_BIT_NONE)) return true;
800 
801  /* Are there more vehicles on the tile except the two vehicles involved in overtaking */
802  return HasVehicleOnPos(od->tile, od, EnumFindVehBlockingOvertake);
803 }
804 
805 static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u)
806 {
807  OvertakeData od;
808 
809  od.v = v;
810  od.u = u;
811 
812  /* Trams can't overtake other trams */
813  if (RoadTypeIsTram(v->roadtype)) return;
814 
815  /* Don't overtake in stations */
816  if (IsTileType(v->tile, MP_STATION) || IsTileType(u->tile, MP_STATION)) return;
817 
818  /* For now, articulated road vehicles can't overtake anything. */
819  if (v->HasArticulatedPart()) return;
820 
821  /* Vehicles are not driving in same direction || direction is not a diagonal direction */
822  if (v->direction != u->direction || !(v->direction & 1)) return;
823 
824  /* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
826 
827  /* Can't overtake a vehicle that is moving faster than us. If the vehicle in front is
828  * accelerating, take the maximum speed for the comparison, else the current speed.
829  * Original acceleration always accelerates, so always use the maximum speed. */
830  int u_speed = (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL || u->GetAcceleration() > 0) ? u->GetCurrentMaxSpeed() : u->cur_speed;
831  if (u_speed >= v->GetCurrentMaxSpeed() &&
832  !(u->vehstatus & VS_STOPPED) &&
833  u->cur_speed != 0) {
834  return;
835  }
836 
837  od.trackdir = DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
838 
839  /* Are the current and the next tile suitable for overtaking?
840  * - Does the track continue along od.trackdir
841  * - No junctions
842  * - No barred levelcrossing
843  * - No other vehicles in the way
844  */
845  od.tile = v->tile;
846  if (CheckRoadBlockedForOvertaking(&od)) return;
847 
848  od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
849  if (CheckRoadBlockedForOvertaking(&od)) return;
850 
851  /* When the vehicle in front of us is stopped we may only take
852  * half the time to pass it than when the vehicle is moving. */
853  v->overtaking_ctr = (od.u->cur_speed == 0 || (od.u->vehstatus & VS_STOPPED)) ? RV_OVERTAKE_TIMEOUT / 2 : 0;
855 }
856 
857 static void RoadZPosAffectSpeed(RoadVehicle *v, int old_z)
858 {
859  if (old_z == v->z_pos || _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) return;
860 
861  if (old_z < v->z_pos) {
862  v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10%
863  } else {
864  uint16_t spd = v->cur_speed + 2;
865  if (spd <= v->gcache.cached_max_track_speed) v->cur_speed = spd;
866  }
867 }
868 
869 static int PickRandomBit(uint bits)
870 {
871  uint i;
872  uint num = RandomRange(CountBits(bits));
873 
874  for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {}
875  return i;
876 }
877 
887 {
888 #define return_track(x) { best_track = (Trackdir)x; goto found_best_track; }
889 
890  TileIndex desttile;
891  Trackdir best_track;
892  bool path_found = true;
893 
894  TrackStatus ts = GetTileTrackStatus(tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype));
895  TrackdirBits red_signals = TrackStatusToRedSignals(ts); // crossing
896  TrackdirBits trackdirs = TrackStatusToTrackdirBits(ts);
897 
898  if (IsTileType(tile, MP_ROAD)) {
899  if (IsRoadDepot(tile) && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir)) {
900  /* Road depot owned by another company or with the wrong orientation */
901  trackdirs = TRACKDIR_BIT_NONE;
902  }
903  } else if (IsTileType(tile, MP_STATION) && IsBayRoadStopTile(tile)) {
904  /* Standard road stop (drive-through stops are treated as normal road) */
905 
906  if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir || v->HasArticulatedPart()) {
907  /* different station owner or wrong orientation or the vehicle has articulated parts */
908  trackdirs = TRACKDIR_BIT_NONE;
909  } else {
910  /* Our station */
911  RoadStopType rstype = v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK;
912 
913  if (GetRoadStopType(tile) != rstype) {
914  /* Wrong station type */
915  trackdirs = TRACKDIR_BIT_NONE;
916  } else {
917  /* Proper station type, check if there is free loading bay */
919  !RoadStop::GetByTile(tile, rstype)->HasFreeBay()) {
920  /* Station is full and RV queuing is off */
921  trackdirs = TRACKDIR_BIT_NONE;
922  }
923  }
924  }
925  }
926  /* The above lookups should be moved to GetTileTrackStatus in the
927  * future, but that requires more changes to the pathfinder and other
928  * stuff, probably even more arguments to GTTS.
929  */
930 
931  /* Remove tracks unreachable from the enter dir */
932  trackdirs &= DiagdirReachesTrackdirs(enterdir);
933  if (trackdirs == TRACKDIR_BIT_NONE) {
934  /* If vehicle expected a path, it no longer exists, so invalidate it. */
935  if (!v->path.empty()) v->path.clear();
936  /* No reachable tracks, so we'll reverse */
937  return_track(_road_reverse_table[enterdir]);
938  }
939 
940  if (v->reverse_ctr != 0) {
941  bool reverse = true;
942  if (RoadTypeIsTram(v->roadtype)) {
943  /* Trams may only reverse on a tile if it contains at least the straight
944  * trackbits or when it is a valid turning tile (i.e. one roadbit) */
945  RoadBits rb = GetAnyRoadBits(tile, RTT_TRAM);
946  RoadBits straight = AxisToRoadBits(DiagDirToAxis(enterdir));
947  reverse = ((rb & straight) == straight) ||
948  (rb == DiagDirToRoadBits(enterdir));
949  }
950  if (reverse) {
951  v->reverse_ctr = 0;
952  if (v->tile != tile) {
953  return_track(_road_reverse_table[enterdir]);
954  }
955  }
956  }
957 
958  desttile = v->dest_tile;
959  if (desttile == 0) {
960  /* We've got no destination, pick a random track */
961  return_track(PickRandomBit(trackdirs));
962  }
963 
964  /* Only one track to choose between? */
965  if (KillFirstBit(trackdirs) == TRACKDIR_BIT_NONE) {
966  if (!v->path.empty() && v->path.tile.front() == tile) {
967  /* Vehicle expected a choice here, invalidate its path. */
968  v->path.clear();
969  }
970  return_track(FindFirstBit(trackdirs));
971  }
972 
973  /* Attempt to follow cached path. */
974  if (!v->path.empty()) {
975  if (v->path.tile.front() != tile) {
976  /* Vehicle didn't expect a choice here, invalidate its path. */
977  v->path.clear();
978  } else {
979  Trackdir trackdir = v->path.td.front();
980 
981  if (HasBit(trackdirs, trackdir)) {
982  v->path.td.pop_front();
983  v->path.tile.pop_front();
984  return_track(trackdir);
985  }
986 
987  /* Vehicle expected a choice which is no longer available. */
988  v->path.clear();
989  }
990  }
991 
993  case VPF_NPF: best_track = NPFRoadVehicleChooseTrack(v, tile, enterdir, path_found); break;
994  case VPF_YAPF: best_track = YapfRoadVehicleChooseTrack(v, tile, enterdir, trackdirs, path_found, v->path); break;
995 
996  default: NOT_REACHED();
997  }
998  v->HandlePathfindingResult(path_found);
999 
1000 found_best_track:;
1001 
1002  if (HasBit(red_signals, best_track)) return INVALID_TRACKDIR;
1003 
1004  return best_track;
1005 }
1006 
1008  byte x, y;
1009 };
1010 
1011 #include "table/roadveh_movement.h"
1012 
1013 bool RoadVehLeaveDepot(RoadVehicle *v, bool first)
1014 {
1015  /* Don't leave unless v and following wagons are in the depot. */
1016  for (const RoadVehicle *u = v; u != nullptr; u = u->Next()) {
1017  if (u->state != RVSB_IN_DEPOT || u->tile != v->tile) return false;
1018  }
1019 
1021  v->direction = DiagDirToDir(dir);
1022 
1023  Trackdir tdir = DiagDirToDiagTrackdir(dir);
1024  const RoadDriveEntry *rdp = _road_drive_data[GetRoadTramType(v->roadtype)][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + tdir];
1025 
1026  int x = TileX(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].x & 0xF);
1027  int y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF);
1028 
1029  if (first) {
1030  /* We are leaving a depot, but have to go to the exact same one; re-enter */
1031  if (v->current_order.IsType(OT_GOTO_DEPOT) && v->tile == v->dest_tile) {
1032  VehicleEnterDepot(v);
1033  return true;
1034  }
1035 
1036  if (RoadVehFindCloseTo(v, x, y, v->direction, false) != nullptr) return true;
1037 
1039  v->LeaveUnbunchingDepot();
1040 
1041  StartRoadVehSound(v);
1042 
1043  /* Vehicle is about to leave a depot */
1044  v->cur_speed = 0;
1045  }
1046 
1047  v->vehstatus &= ~VS_HIDDEN;
1048  v->state = tdir;
1049  v->frame = RVC_DEPOT_START_FRAME;
1050 
1051  v->x_pos = x;
1052  v->y_pos = y;
1053  v->UpdatePosition();
1054  v->UpdateInclination(true, true);
1055 
1057 
1058  return true;
1059 }
1060 
1061 static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
1062 {
1063  if (prev->tile == v->tile && !already_reversed) {
1064  /* If the previous vehicle is on the same tile as this vehicle is
1065  * then it must have reversed. */
1066  return _road_reverse_table[entry_dir];
1067  }
1068 
1069  byte prev_state = prev->state;
1070  Trackdir dir;
1071 
1072  if (prev_state == RVSB_WORMHOLE || prev_state == RVSB_IN_DEPOT) {
1073  DiagDirection diag_dir = INVALID_DIAGDIR;
1074 
1075  if (IsTileType(tile, MP_TUNNELBRIDGE)) {
1076  diag_dir = GetTunnelBridgeDirection(tile);
1077  } else if (IsRoadDepotTile(tile)) {
1078  diag_dir = ReverseDiagDir(GetRoadDepotDirection(tile));
1079  }
1080 
1081  if (diag_dir == INVALID_DIAGDIR) return INVALID_TRACKDIR;
1082  dir = DiagDirToDiagTrackdir(diag_dir);
1083  } else {
1084  if (already_reversed && prev->tile != tile) {
1085  /*
1086  * The vehicle has reversed, but did not go straight back.
1087  * It immediately turn onto another tile. This means that
1088  * the roadstate of the previous vehicle cannot be used
1089  * as the direction we have to go with this vehicle.
1090  *
1091  * Next table is build in the following way:
1092  * - first row for when the vehicle in front went to the northern or
1093  * western tile, second for southern and eastern.
1094  * - columns represent the entry direction.
1095  * - cell values are determined by the Trackdir one has to take from
1096  * the entry dir (column) to the tile in north or south by only
1097  * going over the trackdirs used for turning 90 degrees, i.e.
1098  * TRACKDIR_{UPPER,RIGHT,LOWER,LEFT}_{N,E,S,W}.
1099  */
1100  static const Trackdir reversed_turn_lookup[2][DIAGDIR_END] = {
1103  dir = reversed_turn_lookup[prev->tile < tile ? 0 : 1][ReverseDiagDir(entry_dir)];
1104  } else if (HasBit(prev_state, RVS_IN_DT_ROAD_STOP)) {
1105  dir = (Trackdir)(prev_state & RVSB_ROAD_STOP_TRACKDIR_MASK);
1106  } else if (prev_state < TRACKDIR_END) {
1107  dir = (Trackdir)prev_state;
1108  } else {
1109  return INVALID_TRACKDIR;
1110  }
1111  }
1112 
1113  /* Do some sanity checking. */
1114  static const RoadBits required_roadbits[] = {
1117  };
1118  RoadBits required = required_roadbits[dir & 0x07];
1119 
1120  if ((required & GetAnyRoadBits(tile, GetRoadTramType(v->roadtype), true)) == ROAD_NONE) {
1121  dir = INVALID_TRACKDIR;
1122  }
1123 
1124  return dir;
1125 }
1126 
1136 {
1137  /* The 'current' company is not necessarily the owner of the vehicle. */
1138  Backup<CompanyID> cur_company(_current_company, c, FILE_LINE);
1139 
1141 
1142  cur_company.Restore();
1143  return ret.Succeeded();
1144 }
1145 
1146 bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
1147 {
1148  if (v->overtaking != 0) {
1149  if (IsTileType(v->tile, MP_STATION)) {
1150  /* Force us to be not overtaking! */
1151  v->overtaking = 0;
1152  } else if (++v->overtaking_ctr >= RV_OVERTAKE_TIMEOUT) {
1153  /* If overtaking just aborts at a random moment, we can have a out-of-bound problem,
1154  * if the vehicle started a corner. To protect that, only allow an abort of
1155  * overtake if we are on straight roads */
1157  v->overtaking = 0;
1158  }
1159  }
1160  }
1161 
1162  /* If this vehicle is in a depot and we've reached this point it must be
1163  * one of the articulated parts. It will stay in the depot until activated
1164  * by the previous vehicle in the chain when it gets to the right place. */
1165  if (v->IsInDepot()) return true;
1166 
1167  if (v->state == RVSB_WORMHOLE) {
1168  /* Vehicle is entering a depot or is on a bridge or in a tunnel */
1170 
1171  if (v->IsFrontEngine()) {
1172  const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction);
1173  if (u != nullptr) {
1174  v->cur_speed = u->First()->cur_speed;
1175  return false;
1176  }
1177  }
1178 
1180  /* Vehicle has just entered a bridge or tunnel */
1181  v->x_pos = gp.x;
1182  v->y_pos = gp.y;
1183  v->UpdatePosition();
1184  v->UpdateInclination(true, true);
1185  return true;
1186  }
1187 
1188  v->x_pos = gp.x;
1189  v->y_pos = gp.y;
1190  v->UpdatePosition();
1191  if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
1192  return true;
1193  }
1194 
1195  /* Get move position data for next frame.
1196  * For a drive-through road stop use 'straight road' move data.
1197  * In this case v->state is masked to give the road stop entry direction. */
1198  RoadDriveEntry rd = _road_drive_data[GetRoadTramType(v->roadtype)][(
1200  (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->overtaking][v->frame + 1];
1201 
1202  if (rd.x & RDE_NEXT_TILE) {
1203  TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
1204  Trackdir dir;
1205 
1206  if (v->IsFrontEngine()) {
1207  /* If this is the front engine, look for the right path. */
1208  if (HasTileAnyRoadType(tile, v->compatible_roadtypes)) {
1209  dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3));
1210  } else {
1211  dir = _road_reverse_table[(DiagDirection)(rd.x & 3)];
1212  }
1213  } else {
1214  dir = FollowPreviousRoadVehicle(v, prev, tile, (DiagDirection)(rd.x & 3), false);
1215  }
1216 
1217  if (dir == INVALID_TRACKDIR) {
1218  if (!v->IsFrontEngine()) FatalError("Disconnecting road vehicle.");
1219  v->cur_speed = 0;
1220  return false;
1221  }
1222 
1223 again:
1224  uint start_frame = RVC_DEFAULT_START_FRAME;
1225  if (IsReversingRoadTrackdir(dir)) {
1226  /* When turning around we can't be overtaking. */
1227  v->overtaking = 0;
1228 
1229  /* Turning around */
1230  if (RoadTypeIsTram(v->roadtype)) {
1231  /* Determine the road bits the tram needs to be able to turn around
1232  * using the 'big' corner loop. */
1233  RoadBits needed;
1234  switch (dir) {
1235  default: NOT_REACHED();
1236  case TRACKDIR_RVREV_NE: needed = ROAD_SW; break;
1237  case TRACKDIR_RVREV_SE: needed = ROAD_NW; break;
1238  case TRACKDIR_RVREV_SW: needed = ROAD_NE; break;
1239  case TRACKDIR_RVREV_NW: needed = ROAD_SE; break;
1240  }
1241  if ((v->Previous() != nullptr && v->Previous()->tile == tile) ||
1242  (v->IsFrontEngine() && IsNormalRoadTile(tile) && !HasRoadWorks(tile) &&
1244  (needed & GetRoadBits(tile, RTT_TRAM)) != ROAD_NONE)) {
1245  /*
1246  * Taking the 'big' corner for trams only happens when:
1247  * - The previous vehicle in this (articulated) tram chain is
1248  * already on the 'next' tile, we just follow them regardless of
1249  * anything. When it is NOT on the 'next' tile, the tram started
1250  * doing a reversing turn when the piece of tram track on the next
1251  * tile did not exist yet. Do not use the big tram loop as that is
1252  * going to cause the tram to split up.
1253  * - Or the front of the tram can drive over the next tile.
1254  */
1255  } else if (!v->IsFrontEngine() || !CanBuildTramTrackOnTile(v->owner, tile, v->roadtype, needed) || ((~needed & GetAnyRoadBits(v->tile, RTT_TRAM, false)) == ROAD_NONE)) {
1256  /*
1257  * Taking the 'small' corner for trams only happens when:
1258  * - We are not the from vehicle of an articulated tram.
1259  * - Or when the company cannot build on the next tile.
1260  *
1261  * The 'small' corner means that the vehicle is on the end of a
1262  * tram track and needs to start turning there. To do this properly
1263  * the tram needs to start at an offset in the tram turning 'code'
1264  * for 'big' corners. It furthermore does not go to the next tile,
1265  * so that needs to be fixed too.
1266  */
1267  tile = v->tile;
1268  start_frame = RVC_TURN_AROUND_START_FRAME_SHORT_TRAM;
1269  } else {
1270  /* The company can build on the next tile, so wait till they do. */
1271  v->cur_speed = 0;
1272  return false;
1273  }
1274  } else if (IsNormalRoadTile(v->tile) && GetDisallowedRoadDirections(v->tile) != DRD_NONE) {
1275  v->cur_speed = 0;
1276  return false;
1277  } else {
1278  tile = v->tile;
1279  }
1280  }
1281 
1282  /* Get position data for first frame on the new tile */
1283  const RoadDriveEntry *rdp = _road_drive_data[GetRoadTramType(v->roadtype)][(dir + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)) ^ v->overtaking];
1284 
1285  int x = TileX(tile) * TILE_SIZE + rdp[start_frame].x;
1286  int y = TileY(tile) * TILE_SIZE + rdp[start_frame].y;
1287 
1288  Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1289  if (v->IsFrontEngine()) {
1290  const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
1291  if (u != nullptr) {
1292  v->cur_speed = u->First()->cur_speed;
1293  /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */
1294  v->path.tile.push_front(tile);
1295  v->path.td.push_front(dir);
1296  return false;
1297  }
1298  }
1299 
1300  uint32_t r = VehicleEnterTile(v, tile, x, y);
1301  if (HasBit(r, VETS_CANNOT_ENTER)) {
1302  if (!IsTileType(tile, MP_TUNNELBRIDGE)) {
1303  v->cur_speed = 0;
1304  return false;
1305  }
1306  /* Try an about turn to re-enter the previous tile */
1307  dir = _road_reverse_table[rd.x & 3];
1308  goto again;
1309  }
1310 
1311  if (IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && IsTileType(v->tile, MP_STATION)) {
1312  if (IsReversingRoadTrackdir(dir) && IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) {
1313  /* New direction is trying to turn vehicle around.
1314  * We can't turn at the exit of a road stop so wait.*/
1315  v->cur_speed = 0;
1316  return false;
1317  }
1318 
1319  /* If we are a drive through road stop and the next tile is of
1320  * the same road stop and the next tile isn't this one (i.e. we
1321  * are not reversing), then keep the reservation and state.
1322  * This way we will not be shortly unregister from the road
1323  * stop. It also makes it possible to load when on the edge of
1324  * two road stops; otherwise you could get vehicles that should
1325  * be loading but are not actually loading. */
1326  if (IsDriveThroughStopTile(v->tile) &&
1328  v->tile != tile) {
1329  /* So, keep 'our' state */
1330  dir = (Trackdir)v->state;
1331  } else if (IsRoadStop(v->tile)) {
1332  /* We're not continuing our drive through road stop, so leave. */
1334  }
1335  }
1336 
1337  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
1338  TileIndex old_tile = v->tile;
1339 
1340  v->tile = tile;
1341  v->state = (byte)dir;
1342  v->frame = start_frame;
1343  RoadTramType rtt = GetRoadTramType(v->roadtype);
1344  if (GetRoadType(old_tile, rtt) != GetRoadType(tile, rtt)) {
1345  if (v->IsFrontEngine()) {
1346  RoadVehUpdateCache(v);
1347  }
1348  v->First()->CargoChanged();
1349  }
1350  }
1351  if (new_dir != v->direction) {
1352  v->direction = new_dir;
1353  if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) v->cur_speed -= v->cur_speed >> 2;
1354  }
1355  v->x_pos = x;
1356  v->y_pos = y;
1357  v->UpdatePosition();
1358  RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
1359  return true;
1360  }
1361 
1362  if (rd.x & RDE_TURNED) {
1363  /* Vehicle has finished turning around, it will now head back onto the same tile */
1364  Trackdir dir;
1365  uint turn_around_start_frame = RVC_TURN_AROUND_START_FRAME;
1366 
1367  if (RoadTypeIsTram(v->roadtype) && !IsRoadDepotTile(v->tile) && HasExactlyOneBit(GetAnyRoadBits(v->tile, RTT_TRAM, true))) {
1368  /*
1369  * The tram is turning around with one tram 'roadbit'. This means that
1370  * it is using the 'big' corner 'drive data'. However, to support the
1371  * trams to take a small corner, there is a 'turned' marker in the middle
1372  * of the turning 'drive data'. When the tram took the long corner, we
1373  * will still use the 'big' corner drive data, but we advance it one
1374  * frame. We furthermore set the driving direction so the turning is
1375  * going to be properly shown.
1376  */
1377  turn_around_start_frame = RVC_START_FRAME_AFTER_LONG_TRAM;
1378  switch (rd.x & 0x3) {
1379  default: NOT_REACHED();
1380  case DIAGDIR_NW: dir = TRACKDIR_RVREV_SE; break;
1381  case DIAGDIR_NE: dir = TRACKDIR_RVREV_SW; break;
1382  case DIAGDIR_SE: dir = TRACKDIR_RVREV_NW; break;
1383  case DIAGDIR_SW: dir = TRACKDIR_RVREV_NE; break;
1384  }
1385  } else {
1386  if (v->IsFrontEngine()) {
1387  /* If this is the front engine, look for the right path. */
1388  dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3));
1389  } else {
1390  dir = FollowPreviousRoadVehicle(v, prev, v->tile, (DiagDirection)(rd.x & 3), true);
1391  }
1392  }
1393 
1394  if (dir == INVALID_TRACKDIR) {
1395  v->cur_speed = 0;
1396  return false;
1397  }
1398 
1399  const RoadDriveEntry *rdp = _road_drive_data[GetRoadTramType(v->roadtype)][(_settings_game.vehicle.road_side << RVS_DRIVE_SIDE) + dir];
1400 
1401  int x = TileX(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].x;
1402  int y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y;
1403 
1404  Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1405  if (v->IsFrontEngine()) {
1406  const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
1407  if (u != nullptr) {
1408  v->cur_speed = u->First()->cur_speed;
1409  /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */
1410  v->path.tile.push_front(v->tile);
1411  v->path.td.push_front(dir);
1412  return false;
1413  }
1414  }
1415 
1416  uint32_t r = VehicleEnterTile(v, v->tile, x, y);
1417  if (HasBit(r, VETS_CANNOT_ENTER)) {
1418  v->cur_speed = 0;
1419  return false;
1420  }
1421 
1422  v->state = dir;
1423  v->frame = turn_around_start_frame;
1424 
1425  if (new_dir != v->direction) {
1426  v->direction = new_dir;
1427  if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) v->cur_speed -= v->cur_speed >> 2;
1428  }
1429 
1430  v->x_pos = x;
1431  v->y_pos = y;
1432  v->UpdatePosition();
1433  RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
1434  return true;
1435  }
1436 
1437  /* This vehicle is not in a wormhole and it hasn't entered a new tile. If
1438  * it's on a depot tile, check if it's time to activate the next vehicle in
1439  * the chain yet. */
1440  if (v->Next() != nullptr && IsRoadDepotTile(v->tile)) {
1441  if (v->frame == v->gcache.cached_veh_length + RVC_DEPOT_START_FRAME) {
1442  RoadVehLeaveDepot(v->Next(), false);
1443  }
1444  }
1445 
1446  /* Calculate new position for the vehicle */
1447  int x = (v->x_pos & ~15) + (rd.x & 15);
1448  int y = (v->y_pos & ~15) + (rd.y & 15);
1449 
1450  Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1451 
1452  if (v->IsFrontEngine() && !IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) {
1453  /* Vehicle is not in a road stop.
1454  * Check for another vehicle to overtake */
1455  RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
1456 
1457  if (u != nullptr) {
1458  u = u->First();
1459  /* There is a vehicle in front overtake it if possible */
1460  if (v->overtaking == 0) RoadVehCheckOvertake(v, u);
1461  if (v->overtaking == 0) v->cur_speed = u->cur_speed;
1462 
1463  /* In case an RV is stopped in a road stop, why not try to load? */
1464  if (v->cur_speed == 0 && IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
1466  v->owner == GetTileOwner(v->tile) && !v->current_order.IsType(OT_LEAVESTATION) &&
1468  Station *st = Station::GetByTile(v->tile);
1469  v->last_station_visited = st->index;
1470  RoadVehArrivesAt(v, st);
1471  v->BeginLoading();
1472  }
1473  return false;
1474  }
1475  }
1476 
1477  Direction old_dir = v->direction;
1478  if (new_dir != old_dir) {
1479  v->direction = new_dir;
1480  if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) v->cur_speed -= v->cur_speed >> 2;
1481 
1482  /* Delay the vehicle in curves by making it require one additional frame per turning direction (two in total).
1483  * A vehicle has to spend at least 9 frames on a tile, so the following articulated part can follow.
1484  * (The following part may only be one tile behind, and the front part is moved before the following ones.)
1485  * The short (inner) curve has 8 frames, this elongates it to 10. */
1486  v->UpdateViewport(true, true);
1487  return true;
1488  }
1489 
1490  /* If the vehicle is in a normal road stop and the frame equals the stop frame OR
1491  * if the vehicle is in a drive-through road stop and this is the destination station
1492  * and it's the correct type of stop (bus or truck) and the frame equals the stop frame...
1493  * (the station test and stop type test ensure that other vehicles, using the road stop as
1494  * a through route, do not stop) */
1495  if (v->IsFrontEngine() && ((IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
1497  (IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
1499  v->owner == GetTileOwner(v->tile) &&
1501  v->frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
1502 
1504  Station *st = Station::GetByTile(v->tile);
1505 
1506  /* Vehicle is at the stop position (at a bay) in a road stop.
1507  * Note, if vehicle is loading/unloading it has already been handled,
1508  * so if we get here the vehicle has just arrived or is just ready to leave. */
1509  if (!HasBit(v->state, RVS_ENTERED_STOP)) {
1510  /* Vehicle has arrived at a bay in a road stop */
1511 
1512  if (IsDriveThroughStopTile(v->tile)) {
1513  TileIndex next_tile = TileAddByDir(v->tile, v->direction);
1514 
1515  /* Check if next inline bay is free and has compatible road. */
1517  v->frame++;
1518  v->x_pos = x;
1519  v->y_pos = y;
1520  v->UpdatePosition();
1521  RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
1522  return true;
1523  }
1524  }
1525 
1526  rs->SetEntranceBusy(false);
1528 
1529  v->last_station_visited = st->index;
1530 
1531  if (IsDriveThroughStopTile(v->tile) || (v->current_order.IsType(OT_GOTO_STATION) && v->current_order.GetDestination() == st->index)) {
1532  RoadVehArrivesAt(v, st);
1533  v->BeginLoading();
1534  return false;
1535  }
1536  } else {
1537  /* Vehicle is ready to leave a bay in a road stop */
1538  if (rs->IsEntranceBusy()) {
1539  /* Road stop entrance is busy, so wait as there is nowhere else to go */
1540  v->cur_speed = 0;
1541  return false;
1542  }
1543  if (v->current_order.IsType(OT_LEAVESTATION)) v->current_order.Free();
1544  }
1545 
1546  if (IsBayRoadStopTile(v->tile)) rs->SetEntranceBusy(true);
1547 
1548  StartRoadVehSound(v);
1550  }
1551 
1552  /* Check tile position conditions - i.e. stop position in depot,
1553  * entry onto bridge or into tunnel */
1554  uint32_t r = VehicleEnterTile(v, v->tile, x, y);
1555  if (HasBit(r, VETS_CANNOT_ENTER)) {
1556  v->cur_speed = 0;
1557  return false;
1558  }
1559 
1560  if (v->current_order.IsType(OT_LEAVESTATION) && IsDriveThroughStopTile(v->tile)) {
1561  v->current_order.Free();
1562  }
1563 
1564  /* Move to next frame unless vehicle arrived at a stop position
1565  * in a depot or entered a tunnel/bridge */
1566  if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
1567  v->x_pos = x;
1568  v->y_pos = y;
1569  v->UpdatePosition();
1570  RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
1571  return true;
1572 }
1573 
1574 static bool RoadVehController(RoadVehicle *v)
1575 {
1576  /* decrease counters */
1577  v->current_order_time++;
1578  if (v->reverse_ctr != 0) v->reverse_ctr--;
1579 
1580  /* handle crashed */
1581  if (v->vehstatus & VS_CRASHED || RoadVehCheckTrainCrash(v)) {
1582  return RoadVehIsCrashed(v);
1583  }
1584 
1585  /* road vehicle has broken down? */
1586  if (v->HandleBreakdown()) return true;
1587  if (v->vehstatus & VS_STOPPED) {
1588  v->SetLastSpeed();
1589  return true;
1590  }
1591 
1592  ProcessOrders(v);
1593  v->HandleLoading();
1594 
1595  if (v->current_order.IsType(OT_LOADING)) return true;
1596 
1597  if (v->IsInDepot()) {
1598  /* Check if we should wait here for unbunching. */
1599  if (v->IsWaitingForUnbunching()) return true;
1600  if (RoadVehLeaveDepot(v, true)) return true;
1601  }
1602 
1603  v->ShowVisualEffect();
1604 
1605  /* Check how far the vehicle needs to proceed */
1606  int j = v->UpdateSpeed();
1607 
1608  int adv_spd = v->GetAdvanceDistance();
1609  bool blocked = false;
1610  while (j >= adv_spd) {
1611  j -= adv_spd;
1612 
1613  RoadVehicle *u = v;
1614  for (RoadVehicle *prev = nullptr; u != nullptr; prev = u, u = u->Next()) {
1615  if (!IndividualRoadVehicleController(u, prev)) {
1616  blocked = true;
1617  break;
1618  }
1619  }
1620  if (blocked) break;
1621 
1622  /* Determine distance to next map position */
1623  adv_spd = v->GetAdvanceDistance();
1624 
1625  /* Test for a collision, but only if another movement will occur. */
1626  if (j >= adv_spd && RoadVehCheckTrainCrash(v)) break;
1627  }
1628 
1629  v->SetLastSpeed();
1630 
1631  for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
1632  if ((u->vehstatus & VS_HIDDEN) != 0) continue;
1633 
1634  u->UpdateViewport(false, false);
1635  }
1636 
1637  /* If movement is blocked, set 'progress' to its maximum, so the roadvehicle does
1638  * not accelerate again before it can actually move. I.e. make sure it tries to advance again
1639  * on next tick to discover whether it is still blocked. */
1640  if (v->progress == 0) v->progress = blocked ? adv_spd - 1 : j;
1641 
1642  return true;
1643 }
1644 
1646 {
1647  const Engine *e = this->GetEngine();
1648  if (e->u.road.running_cost_class == INVALID_PRICE) return 0;
1649 
1650  uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost);
1651  if (cost_factor == 0) return 0;
1652 
1653  return GetPrice(e->u.road.running_cost_class, cost_factor, e->GetGRF());
1654 }
1655 
1657 {
1659 
1660  this->tick_counter++;
1661 
1662  if (this->IsFrontEngine()) {
1663  if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
1664  return RoadVehController(this);
1665  }
1666 
1667  return true;
1668 }
1669 
1670 void RoadVehicle::SetDestTile(TileIndex tile)
1671 {
1672  if (tile == this->dest_tile) return;
1673  this->path.clear();
1674  this->dest_tile = tile;
1675 }
1676 
1677 static void CheckIfRoadVehNeedsService(RoadVehicle *v)
1678 {
1679  /* If we already got a slot at a stop, use that FIRST, and go to a depot later */
1680  if (Company::Get(v->owner)->settings.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
1681  if (v->IsChainInDepot()) {
1683  return;
1684  }
1685 
1686  uint max_penalty;
1688  case VPF_NPF: max_penalty = _settings_game.pf.npf.maximum_go_to_depot_penalty; break;
1689  case VPF_YAPF: max_penalty = _settings_game.pf.yapf.maximum_go_to_depot_penalty; break;
1690  default: NOT_REACHED();
1691  }
1692 
1693  FindDepotData rfdd = FindClosestRoadDepot(v, max_penalty);
1694  /* Only go to the depot if it is not too far out of our way. */
1695  if (rfdd.best_length == UINT_MAX || rfdd.best_length > max_penalty) {
1696  if (v->current_order.IsType(OT_GOTO_DEPOT)) {
1697  /* If we were already heading for a depot but it has
1698  * suddenly moved farther away, we continue our normal
1699  * schedule? */
1700  v->current_order.MakeDummy();
1702  }
1703  return;
1704  }
1705 
1706  DepotID depot = GetDepotIndex(rfdd.tile);
1707 
1708  if (v->current_order.IsType(OT_GOTO_DEPOT) &&
1710  !Chance16(1, 20)) {
1711  return;
1712  }
1713 
1716  v->SetDestTile(rfdd.tile);
1718 }
1719 
1722 {
1723  if (!this->IsFrontEngine()) return;
1724  AgeVehicle(this);
1725 }
1726 
1729 {
1730  if (!this->IsFrontEngine()) return;
1731 
1732  if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
1733  if (this->blocked_ctr == 0) CheckVehicleBreakdown(this);
1734 
1735  CheckIfRoadVehNeedsService(this);
1736 
1737  CheckOrders(this);
1738 
1739  if (this->running_ticks == 0) return;
1740 
1742 
1743  this->profit_this_year -= cost.GetCost();
1744  this->running_ticks = 0;
1745 
1746  SubtractMoneyFromCompanyFract(this->owner, cost);
1747 
1750 }
1751 
1753 {
1754  if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
1755 
1756  if (this->IsInDepot()) {
1757  /* We'll assume the road vehicle is facing outwards */
1758  return DiagDirToDiagTrackdir(GetRoadDepotDirection(this->tile));
1759  }
1760 
1761  if (IsBayRoadStopTile(this->tile)) {
1762  /* We'll assume the road vehicle is facing outwards */
1763  return DiagDirToDiagTrackdir(GetRoadStopDir(this->tile)); // Road vehicle in a station
1764  }
1765 
1766  /* Drive through road stops / wormholes (tunnels) */
1767  if (this->state > RVSB_TRACKDIR_MASK) return DiagDirToDiagTrackdir(DirToDiagDir(this->direction));
1768 
1769  /* If vehicle's state is a valid track direction (vehicle is not turning around) return it,
1770  * otherwise transform it into a valid track direction */
1771  return (Trackdir)((IsReversingRoadTrackdir((Trackdir)this->state)) ? (this->state - 6) : this->state);
1772 }
1773 
1775 {
1776  uint16_t weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnits(this->GetEngine()->DetermineCapacity(this));
1777 
1778  /* Vehicle weight is not added for articulated parts. */
1779  if (!this->IsArticulatedPart()) {
1780  /* Road vehicle weight is in units of 1/4 t. */
1781  weight += GetVehicleProperty(this, PROP_ROADVEH_WEIGHT, RoadVehInfo(this->engine_type)->weight) / 4;
1782  }
1783 
1784  return weight;
1785 }
RoadVehicle::overtaking
byte overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
Definition: roadveh.h:111
VSE_START
@ VSE_START
Vehicle starting, i.e. leaving, the station.
Definition: newgrf_sound.h:19
game.hpp
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:106
TRACKDIR_RVREV_SW
@ TRACKDIR_RVREV_SW
(Road vehicle) reverse direction south-west
Definition: track_type.h:83
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
Vehicle::IsFrontEngine
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:931
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:206
Vehicle::x_bb_offs
int8_t x_bb_offs
x offset of vehicle bounding box
Definition: vehicle_base.h:314
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:314
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:434
PathfinderSettings::npf
NPFSettings npf
pathfinder settings for the new pathfinder
Definition: settings_type.h:500
RoadTypeInfo
Definition: road.h:78
RoadVehicle::state
byte state
Definition: roadveh.h:108
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
Order::MakeDummy
void MakeDummy()
Makes this order a Dummy order.
Definition: order_cmd.cpp:133
sound_func.h
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition: economy_type.h:176
DIRDIFF_REVERSE
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
Definition: direction_type.h:62
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
GetDisallowedRoadDirections
DisallowedRoadDirections GetDisallowedRoadDirections(Tile t)
Gets the disallowed directions.
Definition: road_map.h:301
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:196
TRACKDIR_LOWER_E
@ TRACKDIR_LOWER_E
Lower track and direction to east.
Definition: track_type.h:72
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:970
Vehicle::reliability_spd_dec
uint16_t reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:293
NT_ARRIVAL_OTHER
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
Definition: news_type.h:25
DIRDIFF_45LEFT
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
Definition: direction_type.h:64
RoadStopType
RoadStopType
Types of RoadStops.
Definition: station_type.h:43
GroundVehicle< RoadVehicle, VEH_ROAD >::GetAcceleration
int GetAcceleration() const
Calculates the acceleration of the vehicle under its current conditions.
Definition: ground_vehicle.cpp:105
ROADSTOP_TRUCK
@ ROADSTOP_TRUCK
A standard stop for trucks.
Definition: station_type.h:45
FindDepotData
Helper container to find a depot.
Definition: pathfinder_type.h:51
command_func.h
RoadVehicle::GetAccelerationStatus
AccelStatus GetAccelerationStatus() const
Checks the current acceleration status of this vehicle.
Definition: roadveh.h:230
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
ODTFB_SERVICE
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
Definition: order_type.h:95
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
TrackStatusToTrackdirBits
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:352
RoadStop::IsEntranceBusy
bool IsEntranceBusy() const
Checks whether the entrance of the road stop is occupied by a vehicle.
Definition: roadstop_base.h:103
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:338
TRACKDIR_RIGHT_S
@ TRACKDIR_RIGHT_S
Right track and direction to south.
Definition: track_type.h:74
HasVehicleOnPos
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:520
CheckOrders
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Definition: order_cmd.cpp:1711
GVF_SUPPRESS_IMPLICIT_ORDERS
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
Definition: ground_vehicle.hpp:54
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
GroundVehicleCache::first_engine
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Definition: ground_vehicle.hpp:43
company_base.h
RoadVehFindData
Definition: roadveh_cmd.cpp:614
Engine::reliability_spd_dec
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
Definition: engine_base.h:42
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1116
CheckConsistencyOfArticulatedVehicle
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
Definition: articulated_vehicles.cpp:297
tunnelbridge_map.h
timer_game_calendar.h
OvertakeData
Definition: roadveh_cmd.cpp:770
DIRDIFF_SAME
@ DIRDIFF_SAME
Both directions faces to the same direction.
Definition: direction_type.h:59
Vehicle::y_extent
byte y_extent
y-extent of vehicle bounding box
Definition: vehicle_base.h:312
Station
Station data structure.
Definition: station_base.h:442
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
Vehicle::NeedsAutomaticServicing
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Definition: vehicle.cpp:272
Engine::GetLifeLengthInDays
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:443
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
RoadVehicle::UpdateSpeed
int UpdateSpeed()
This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables.
Definition: roadveh_cmd.cpp:732
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:164
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
RDE_NEXT_TILE
static const uint RDE_NEXT_TILE
State information about the Road Vehicle controller.
Definition: roadveh.h:61
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
VPF_YAPF
@ VPF_YAPF
Yet Another PathFinder.
Definition: vehicle_type.h:60
VS_DEFPAL
@ VS_DEFPAL
Use default vehicle palette.
Definition: vehicle_base.h:36
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition: vehicle.cpp:2862
PROP_ROADVEH_SHORTEN_FACTOR
@ PROP_ROADVEH_SHORTEN_FACTOR
Shorter vehicles.
Definition: newgrf_properties.h:41
RVSB_IN_ROAD_STOP
@ RVSB_IN_ROAD_STOP
The vehicle is in a road stop.
Definition: roadveh.h:49
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:131
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:219
AddArticulatedParts
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
Definition: articulated_vehicles.cpp:339
PFE_GL_ROADVEHS
@ PFE_GL_ROADVEHS
Time spend processing road vehicles.
Definition: framerate_type.h:52
RoadVehicle::path
RoadVehPathCache path
Cached path.
Definition: roadveh.h:107
Order::Free
void Free()
'Free' the order
Definition: order_cmd.cpp:63
TRACKDIR_LOWER_W
@ TRACKDIR_LOWER_W
Lower track and direction to west.
Definition: track_type.h:80
SND_12_EXPLOSION
@ SND_12_EXPLOSION
16 == 0x10 Destruction, crashes, disasters, ...
Definition: sound_type.h:55
BaseConsist::vehicle_flags
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:34
RoadVehicle::overtaking_ctr
byte overtaking_ctr
The length of the current overtake attempt.
Definition: roadveh.h:112
RoadStop::GetByTile
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition: roadstop.cpp:266
TRACKDIR_RVREV_NW
@ TRACKDIR_RVREV_NW
(Road vehicle) reverse direction north-west
Definition: track_type.h:84
zoom_func.h
WID_VV_START_STOP
@ WID_VV_START_STOP
Start or stop this vehicle, and show information about the current state.
Definition: vehicle_widget.h:17
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Vehicle::running_ticks
byte running_ticks
Number of ticks this vehicle was not stopped this day.
Definition: vehicle_base.h:346
IsLevelCrossingTile
bool IsLevelCrossingTile(Tile t)
Return whether a tile is a level crossing tile.
Definition: road_map.h:95
SND_19_DEPARTURE_OLD_RV_1
@ SND_19_DEPARTURE_OLD_RV_1
23 == 0x17 Station departure: truck and old bus (1) (non-toyland)
Definition: sound_type.h:62
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
VehicleEnterDepot
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
Definition: vehicle.cpp:1534
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:374
VehicleLengthChanged
void VehicleLengthChanged(const Vehicle *u)
Logs a bug in GRF and shows a warning message if this is for the first time this happened.
Definition: vehicle.cpp:346
GetRoadStopDir
DiagDirection GetRoadStopDir(Tile t)
Gets the direction the road stop entrance points towards.
Definition: station_map.h:258
BaseConsist::current_order_time
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:21
RDE_TURNED
static const uint RDE_TURNED
We just finished turning.
Definition: roadveh.h:62
BridgeSpec::speed
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:47
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:116
ChangeDir
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
Definition: direction_func.h:104
VehicleSettings::road_side
byte road_side
the side of the road vehicles drive on
Definition: settings_type.h:533
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
Engine
Definition: engine_base.h:37
TRACKDIR_UPPER_E
@ TRACKDIR_UPPER_E
Upper track and direction to east.
Definition: track_type.h:71
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:50
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
DeleteLastRoadVeh
static void DeleteLastRoadVeh(RoadVehicle *v)
Delete last vehicle of a chain road vehicles.
Definition: roadveh_cmd.cpp:470
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:96
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:131
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:128
Chance16
bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
Definition: random_func.hpp:131
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:304
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
RoadVehicle::UpdateDeltaXY
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
Definition: roadveh_cmd.cpp:411
EV_EXPLOSION_LARGE
@ EV_EXPLOSION_LARGE
Various explosions.
Definition: effectvehicle_func.h:22
Vehicle::IsInDepot
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Definition: vehicle_base.h:543
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:299
TRACKDIR_RVREV_SE
@ TRACKDIR_RVREV_SE
(Road vehicle) reverse direction south-east
Definition: track_type.h:76
Engine::GetGRFID
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:157
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
HasExactlyOneBit
constexpr bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
Definition: bitmath_func.hpp:259
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
VehicleServiceInDepot
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
Definition: vehicle.cpp:167
KillFirstBit
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:231
RVSB_IN_DT_ROAD_STOP
@ RVSB_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
Definition: roadveh.h:51
EnumCheckRoadVehCrashTrain
static Vehicle * EnumCheckRoadVehCrashTrain(Vehicle *v, void *data)
Check routine whether a road and a train vehicle have collided.
Definition: roadveh_cmd.cpp:525
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
TrackStatusToRedSignals
TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
Returns the red-signal-information of a TrackStatus.
Definition: track_func.h:376
RandomRange
static uint32_t RandomRange(uint32_t limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:299
GroundVehicle::gv_flags
uint16_t gv_flags
Definition: ground_vehicle.hpp:81
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:556
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:940
effectvehicle_func.h
ai.hpp
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:58
TRACKDIR_LEFT_N
@ TRACKDIR_LEFT_N
Left track and direction to north.
Definition: track_type.h:81
RVS_DRIVE_SIDE
@ RVS_DRIVE_SIDE
Only used when retrieving move data.
Definition: roadveh.h:44
TRACK_BIT_CROSS
@ TRACK_BIT_CROSS
X-Y-axis cross.
Definition: track_type.h:43
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:167
GetRoadDepotDirection
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition: road_map.h:565
Vehicle::date_of_last_service
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
Definition: vehicle_base.h:290
NT_ARRIVAL_COMPANY
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
Definition: news_type.h:24
ENGINE_EXCLUSIVE_PREVIEW
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
Definition: engine_type.h:184
VehicleCache::cached_max_speed
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:124
RoadVehicle::GetMaxWeight
uint16_t GetMaxWeight() const override
Calculates the weight value that this vehicle will have when fully loaded with its current cargo.
Definition: roadveh_cmd.cpp:1774
RoadVehicle::OnNewEconomyDay
void OnNewEconomyDay() override
Economy day handler.
Definition: roadveh_cmd.cpp:1728
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
@ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:74
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:59
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:141
Vehicle::BeginLoading
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Definition: vehicle.cpp:2174
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:625
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
PROP_ROADVEH_SPEED
@ PROP_ROADVEH_SPEED
Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h.
Definition: newgrf_properties.h:38
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:294
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:33
FindDepotData::best_length
uint best_length
The distance towards the depot in penalty, or UINT_MAX if not found.
Definition: pathfinder_type.h:53
DirDifference
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Definition: direction_func.h:68
error_func.h
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:122
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:360
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:267
Vehicle::HandlePathfindingResult
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Definition: vehicle.cpp:791
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
CheckRoadBlockedForOvertaking
static bool CheckRoadBlockedForOvertaking(OvertakeData *od)
Check if overtaking is possible on a piece of track.
Definition: roadveh_cmd.cpp:790
ROAD_NE
@ ROAD_NE
North-east part.
Definition: road_type.h:57
IsBayRoadStopTile
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
Definition: station_map.h:223
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:235
_road_stop_stop_frame
const byte _road_stop_stop_frame[]
Table of road stop stop frames, when to stop at a road stop.
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetBridgeSpec
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:66
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:339
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
PROP_ROADVEH_CARGO_AGE_PERIOD
@ PROP_ROADVEH_CARGO_AGE_PERIOD
Number of ticks before carried cargo is aged.
Definition: newgrf_properties.h:40
Vehicle::IsWaitingForUnbunching
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Definition: vehicle.cpp:2481
GroundVehicleCache::cached_max_track_speed
uint16_t cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine).
Definition: ground_vehicle.hpp:37
IsStraightRoadTrackdir
bool IsStraightRoadTrackdir(Trackdir dir)
Checks whether the given trackdir is a straight road.
Definition: track_func.h:684
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
roadstop_base.h
NewsType
NewsType
Type of news.
Definition: news_type.h:23
SubtractMoneyFromCompanyFract
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
Definition: company_cmd.cpp:297
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
npf_func.h
RoadVehicle::GetRunningCost
Money GetRunningCost() const override
Gets the running cost of a vehicle.
Definition: roadveh_cmd.cpp:1645
Vehicle::random_bits
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition: vehicle_base.h:329
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:318
RoadVehicleInfo
Information about a road vehicle.
Definition: engine_type.h:114
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
VETS_CANNOT_ENTER
@ VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:24
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:131
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:99
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:332
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:340
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:349
HVOT_TRUCK
@ HVOT_TRUCK
Station has seen a truck.
Definition: station_type.h:66
GroundVehicle::IsChainInDepot
bool IsChainInDepot() const override
Check whether the whole vehicle chain is in the depot.
Definition: ground_vehicle.cpp:190
YapfRoadVehicleChooseTrack
Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
Finds the best path for given road vehicle using YAPF.
Definition: yapf_road.cpp:526
DiagDirToDir
Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
Definition: direction_func.h:182
GroundVehicle< RoadVehicle, VEH_ROAD >::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
RoadVehicle::IsInDepot
bool IsInDepot() const override
Check whether the vehicle is in the depot.
Definition: roadveh.h:135
GroundVehicle::SetFrontEngine
void SetFrontEngine()
Set front engine state.
Definition: ground_vehicle.hpp:248
RVSB_TRACKDIR_MASK
@ RVSB_TRACKDIR_MASK
The mask used to extract track dirs.
Definition: roadveh.h:56
Vehicle::cur_speed
uint16_t cur_speed
current speed
Definition: vehicle_base.h:323
DiagdirReachesTrackdirs
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:555
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
RoadDriveEntry
Definition: roadveh_cmd.cpp:1007
RVS_ENTERED_STOP
@ RVS_ENTERED_STOP
Only set when a vehicle has entered the stop.
Definition: roadveh.h:43
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:287
NPFRoadVehicleFindNearestDepot
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using NPF.
Definition: npf.cpp:1152
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:200
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:147
RoadVehicle::GetCurrentMaxSpeed
int GetCurrentMaxSpeed() const override
Calculates the maximum speed of the vehicle under its current conditions.
Definition: roadveh_cmd.cpp:442
TrackdirBitsToTrackBits
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:308
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:34
RoadVehicle::Crash
uint Crash(bool flooded=false) override
Crash the (whole) vehicle chain.
Definition: roadveh_cmd.cpp:535
Vehicle::ShowVisualEffect
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
Definition: vehicle.cpp:2712
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:747
VehicleEnterTile
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
Definition: vehicle.cpp:1813
safeguards.h
GroundVehicle::SetLastSpeed
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
Definition: ground_vehicle.hpp:340
GetNewVehiclePosResult::new_tile
TileIndex new_tile
Tile of the vehicle after moving.
Definition: vehicle_func.h:78
Vehicle::last_loading_station
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Definition: vehicle_base.h:333
IsNormalRoadTile
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition: road_map.h:74
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
DirToDiagDir
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
DIR_S
@ DIR_S
South.
Definition: direction_type.h:30
Vehicle::profit_this_year
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Definition: vehicle_base.h:269
RVSB_DRIVE_SIDE
@ RVSB_DRIVE_SIDE
The vehicle is at the opposite side of the road.
Definition: roadveh.h:54
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
Vehicle::y_bb_offs
int8_t y_bb_offs
y offset of vehicle bounding box
Definition: vehicle_base.h:315
RoadVehicle::Tick
bool Tick() override
Calls the tick handler of the vehicle.
Definition: roadveh_cmd.cpp:1656
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:80
YapfRoadVehicleFindNearestDepot
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
Definition: yapf_road.cpp:541
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:117
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
RoadVehicle::MarkDirty
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Definition: roadveh_cmd.cpp:402
SoundSettings::disaster
bool disaster
Play disaster and accident sounds.
Definition: settings_type.h:242
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
RoadVehIsCrashed
static bool RoadVehIsCrashed(RoadVehicle *v)
Road vehicle chain has crashed.
Definition: roadveh_cmd.cpp:503
CanBuildTramTrackOnTile
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadBits r)
Can a tram track build without destruction on the given tile?
Definition: roadveh_cmd.cpp:1135
HasRoadWorks
bool HasRoadWorks(Tile t)
Check if a tile has road works.
Definition: road_map.h:513
DirDiff
DirDiff
Allow incrementing of Direction variables.
Definition: direction_type.h:58
DiagDirToRoadBits
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:96
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
NT_ACCIDENT_OTHER
@ NT_ACCIDENT_OTHER
An accident or disaster has occurred.
Definition: news_type.h:27
NPFRoadVehicleChooseTrack
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
Finds the best path for given road vehicle using NPF.
Definition: npf.cpp:1169
Vehicle::HandleLoading
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
Definition: vehicle.cpp:2392
CreateEffectVehicleRel
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
Definition: effectvehicle.cpp:638
RoadFindPathToDest
static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
Returns direction to for a road vehicle to take or INVALID_TRACKDIR if the direction is currently blo...
Definition: roadveh_cmd.cpp:886
TRACKDIR_UPPER_W
@ TRACKDIR_UPPER_W
Upper track and direction to west.
Definition: track_type.h:79
RoadStop::SetEntranceBusy
void SetEntranceBusy(bool busy)
Makes an entrance occupied or free.
Definition: roadstop_base.h:112
stdafx.h
TileAddByDir
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition: map_func.h:592
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:363
RoadStop::Leave
void Leave(RoadVehicle *rv)
Leave the road stop.
Definition: roadstop.cpp:216
DRD_NONE
@ DRD_NONE
None of the directions are disallowed.
Definition: road_type.h:74
VPF_NPF
@ VPF_NPF
New PathFinder.
Definition: vehicle_type.h:59
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:243
GetDepotIndex
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:52
AddVehicleNewsItem
void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
Definition: news_func.h:30
Engine::reliability
uint16_t reliability
Current reliability of the engine.
Definition: engine_base.h:41
Vehicle::colourmap
SpriteID colourmap
NOSAVE: cached colour mapping.
Definition: vehicle_base.h:284
RoadVehicle::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition: roadveh_cmd.cpp:1752
SND_1A_DEPARTURE_OLD_RV_2
@ SND_1A_DEPARTURE_OLD_RV_2
24 == 0x18 Station departure: truck and old bus (2) (random variation of SND_19_DEPARTURE_OLD_RV_1) (...
Definition: sound_type.h:63
BaseConsist::ResetDepotUnbunching
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
Definition: base_consist.cpp:49
Vehicle::IncrementRealOrderIndex
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
Definition: vehicle_base.h:872
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:301
VF_BUILT_AS_PROTOTYPE
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:47
IsDiagonalDirection
bool IsDiagonalDirection(Direction dir)
Checks if a given Direction is diagonal.
Definition: direction_func.h:273
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:302
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:519
PerformanceAccumulator
RAII class for measuring multi-step elements of performance.
Definition: framerate_type.h:114
ProcessOrders
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Definition: order_cmd.cpp:2127
GetAnyRoadBits
RoadBits GetAnyRoadBits(Tile tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition: road_map.cpp:33
spritecache.h
Vehicle::x_extent
byte x_extent
x-extent of vehicle bounding box
Definition: vehicle_base.h:311
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
DepotID
uint16_t DepotID
Type for the unique identifier of depots.
Definition: depot_type.h:13
ROADSTOP_BUS
@ ROADSTOP_BUS
A standard stop for buses.
Definition: station_type.h:44
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:361
RoadVehicle::OnNewCalendarDay
void OnNewCalendarDay() override
Calandar day handler.
Definition: roadveh_cmd.cpp:1721
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
GroundVehicle::UpdateInclination
int UpdateInclination(bool new_tile, bool update_delta)
Checks if the vehicle is in a slope and sets the required flags in that case.
Definition: ground_vehicle.hpp:231
vehicle_func.h
NT_ACCIDENT
@ NT_ACCIDENT
An accident or disaster has occurred.
Definition: news_type.h:26
station_base.h
newgrf_sound.h
RoadVehicleInfo::shorten_factor
byte shorten_factor
length on main map for this type is 8 - shorten_factor
Definition: engine_type.h:127
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:76
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
strings_func.h
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:640
Vehicle::max_age
TimerGameCalendar::Date max_age
Maximum age.
Definition: vehicle_base.h:289
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:345
yapf.h
RoadVehicle::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
Definition: roadveh_cmd.cpp:94
GetRoadVehLength
static uint GetRoadVehLength(const RoadVehicle *v)
Get length of a road vehicle.
Definition: roadveh_cmd.cpp:191
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
Vehicle::x_offs
int8_t x_offs
x offset for vehicle sprite
Definition: vehicle_base.h:316
DIRDIFF_45RIGHT
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
Definition: direction_type.h:60
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
Vehicle::z_extent
byte z_extent
z-extent of vehicle bounding box
Definition: vehicle_base.h:313
Vehicle::date_of_last_service_newgrf
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
Definition: vehicle_base.h:291
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:499
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
framerate_type.h
RoadStop::IsDriveThroughRoadStopContinuation
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same dir...
Definition: roadstop.cpp:305
Vehicle::reliability
uint16_t reliability
Reliability.
Definition: vehicle_base.h:292
IsRoadStop
bool IsRoadStop(Tile t)
Is the station at t a road station?
Definition: station_map.h:202
GetNewVehiclePosResult
Position information of a vehicle after it moved.
Definition: vehicle_func.h:75
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:351
newgrf.h
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:278
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:949
FindVehicleOnPos
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:505
EngineInfo::cargo_age_period
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
Definition: engine_type.h:159
TRACKDIR_END
@ TRACKDIR_END
Used for iterations.
Definition: track_type.h:85
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
GetRoadBits
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:128
FindDepotData::tile
TileIndex tile
The tile of the depot.
Definition: pathfinder_type.h:52
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
depot_map.h
SpecializedVehicle< RoadVehicle, Type >::GetIfValid
static RoadVehicle * GetIfValid(size_t index)
Returns vehicle if the index is a valid index for this vehicle type.
Definition: vehicle_base.h:1191
company_func.h
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:52
IsReversingRoadTrackdir
bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
Definition: track_func.h:673
GetOtherTunnelBridgeEnd
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
Order::GetMaxSpeed
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:202
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:300
ClosestDepot
Structure to return information about the closest depot location, and whether it could be found.
Definition: vehicle_base.h:226
PlayVehicleSound
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
Definition: newgrf_sound.cpp:187
Order::ShouldStopAtStation
bool ShouldStopAtStation(const Vehicle *v, StationID station) const
Check whether the given vehicle should stop at the given station based on this order and the non-stop...
Definition: order_cmd.cpp:2225
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:499
Vehicle::InvalidateNewGRFCache
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:490
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
GetRoadStopType
RoadStopType GetRoadStopType(Tile t)
Get the road stop type of this tile.
Definition: station_map.h:56
CommandHelper
Definition: command_func.h:93
PathfinderSettings::roadveh_queue
bool roadveh_queue
buggy road vehicle queueing
Definition: settings_type.h:489
UnScaleGUI
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
Vehicle::day_counter
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:344
FindVehicleOnPosXY
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:445
ROAD_NW
@ ROAD_NW
North-west part.
Definition: road_type.h:54
TRACKDIR_RVREV_NE
@ TRACKDIR_RVREV_NE
(Road vehicle) reverse direction north-east
Definition: track_type.h:75
ROAD_SW
@ ROAD_SW
South-west part.
Definition: road_type.h:55
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
RVSB_WORMHOLE
@ RVSB_WORMHOLE
The vehicle is in a tunnel and/or bridge.
Definition: roadveh.h:39
RoadVehicle::FindClosestDepot
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: roadveh_cmd.cpp:353
HasVehicleOnPosXY
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle in on a specific location.
Definition: vehicle.cpp:461
ROAD_NONE
@ ROAD_NONE
No road-part is build.
Definition: road_type.h:53
ROAD_SE
@ ROAD_SE
South-east part.
Definition: road_type.h:56
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition: settings_type.h:501
random_func.hpp
RV_OVERTAKE_TIMEOUT
static const byte RV_OVERTAKE_TIMEOUT
The number of ticks a vehicle has for overtaking.
Definition: roadveh.h:79
AgeVehicle
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
Definition: vehicle.cpp:1423
Vehicle::progress
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
Definition: vehicle_base.h:327
OverflowSafeInt< int64_t >
CmdBuildRoadVehicle
CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build a road vehicle.
Definition: roadveh_cmd.cpp:262
GroundVehicle::CargoChanged
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Definition: ground_vehicle.cpp:79
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:83
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
Engine::original_image_index
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
Definition: engine_base.h:55
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:103
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:310
RoadVehicle::crashed_ctr
uint16_t crashed_ctr
Animation counter when the vehicle has crashed.
Definition: roadveh.h:113
RVS_IN_DT_ROAD_STOP
@ RVS_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
Definition: roadveh.h:46
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
CBID_VEHICLE_LENGTH
@ CBID_VEHICLE_LENGTH
Vehicle length, returns the amount of 1/8's the vehicle is shorter for trains and RVs.
Definition: newgrf_callbacks.h:33
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
RoadVehArrivesAt
static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
A road vehicle arrives at a station.
Definition: roadveh_cmd.cpp:692
SpecializedVehicle::Previous
T * Previous() const
Get previous vehicle in the chain.
Definition: vehicle_base.h:1122
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:48
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Vehicle::GetAdvanceDistance
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Definition: vehicle_base.h:452
TRACKDIR_LEFT_S
@ TRACKDIR_LEFT_S
Left track and direction to south.
Definition: track_type.h:73
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
RoadVehicle::IsPrimaryVehicle
bool IsPrimaryVehicle() const override
Whether this is the primary vehicle in the chain.
Definition: roadveh.h:129
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition: track_type.h:98
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition: vehicle_base.h:1098
NPFSettings::maximum_go_to_depot_penalty
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Definition: settings_type.h:420
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1668
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:49
PathfinderSettings::pathfinder_for_roadvehs
uint8_t pathfinder_for_roadvehs
the pathfinder to use for roadvehicles
Definition: settings_type.h:485
AS_BRAKE
@ AS_BRAKE
We want to stop.
Definition: ground_vehicle.hpp:22
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition: direction_type.h:35
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2983
Vehicle::HandleBreakdown
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
Definition: vehicle.cpp:1357
DecreaseVehicleValue
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
Definition: vehicle.cpp:1295
GetNewVehiclePosResult::y
int y
x and y position of the vehicle after moving
Definition: vehicle_func.h:76
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1149
HasTileAnyRoadType
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
Definition: road_map.h:222
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
IsCargoInClass
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:230
GroundVehicle::Crash
uint Crash(bool flooded) override
Common code executed for crashed ground vehicles.
Definition: ground_vehicle.hpp:100
DrawRoadVehEngine
void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw a road vehicle engine.
Definition: roadveh_cmd.cpp:149
PROP_ROADVEH_RUNNING_COST_FACTOR
@ PROP_ROADVEH_RUNNING_COST_FACTOR
Yearly runningcost.
Definition: newgrf_properties.h:33
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition: roadveh.h:38
TimerGameConst< struct Calendar >::DAYS_IN_YEAR
static constexpr int DAYS_IN_YEAR
days per year
Definition: timer_game_common.h:149
GroundVehicleCache::cached_veh_length
uint8_t cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
Definition: ground_vehicle.hpp:44
GroundVehicle< RoadVehicle, VEH_ROAD >::DoUpdateSpeed
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
Definition: ground_vehicle.hpp:362
RoadVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition: engine_type.h:120
IsTileOwner
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3108
VehicleSpriteSeq::GetBounds
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Definition: vehicle.cpp:103
DiagDirToDiagTrackdir
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:537
TRACKDIR_RIGHT_N
@ TRACKDIR_RIGHT_N
Right track and direction to north.
Definition: track_type.h:82
roadveh_movement.h
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3095
Order::MakeGoToDepot
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:90
GroundVehicleCache::cached_total_length
uint16_t cached_total_length
Length of the whole vehicle (valid only for the first engine).
Definition: ground_vehicle.hpp:42
Vehicle::first
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
Definition: vehicle_base.h:246
SpecializedVehicle::UpdateViewport
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Definition: vehicle_base.h:1223
HVOT_BUS
@ HVOT_BUS
Station has seen a bus.
Definition: station_type.h:65
GetRoadVehSpriteSize
void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a road vehicle sprite heading west (used for lists).
Definition: roadveh_cmd.cpp:172
Vehicle::LeaveUnbunchingDepot
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
Definition: vehicle.cpp:2438
roadveh_cmd.h
IsRoadDepot
static debug_inline bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
Definition: road_map.h:106
AxisToRoadBits
RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:111
road_cmd.h
timer_game_economy.h
IsDriveThroughStopTile
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station?
Definition: station_map.h:233
Vehicle::y_offs
int8_t y_offs
y offset for vehicle sprite
Definition: vehicle_base.h:317
CmdTurnRoadVeh
CommandCost CmdTurnRoadVeh(DoCommandFlag flags, VehicleID veh_id)
Turn a roadvehicle around.
Definition: roadveh_cmd.cpp:367
GetBridgeType
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
RVSB_ROAD_STOP_TRACKDIR_MASK
@ RVSB_ROAD_STOP_TRACKDIR_MASK
Only bits 0 and 3 are used to encode the trackdir for road stops.
Definition: roadveh.h:57
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:339
GetNewVehiclePos
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
Definition: vehicle.cpp:1759
IsRoadDepotTile
static debug_inline bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition: road_map.h:116
YAPFSettings::maximum_go_to_depot_penalty
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
Definition: settings_type.h:444
PROP_ROADVEH_WEIGHT
@ PROP_ROADVEH_WEIGHT
Weight in 1/4 t.
Definition: newgrf_properties.h:37
news_func.h
roadveh.h
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
backup_type.hpp
VETS_ENTERED_WORMHOLE
@ VETS_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:23
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition: timer_game_economy.h:37
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition: bitmath_func.hpp:194
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103