OpenTTD Source
20240915-master-g3784a3d3d6
|
Go to the documentation of this file.
64 #include "table/strings.h"
69 static const uint GEN_HASHX_BITS = 6;
70 static const uint GEN_HASHY_BITS = 6;
73 static const uint GEN_HASHX_BUCKET_BITS = 7;
74 static const uint GEN_HASHY_BUCKET_BITS = 6;
77 #define GEN_HASHX(x) GB((x), GEN_HASHX_BUCKET_BITS + ZOOM_BASE_SHIFT, GEN_HASHX_BITS)
78 #define GEN_HASHY(y) (GB((y), GEN_HASHY_BUCKET_BITS + ZOOM_BASE_SHIFT, GEN_HASHY_BITS) << GEN_HASHX_BITS)
79 #define GEN_HASH(x, y) (GEN_HASHY(y) + GEN_HASHX(x))
82 static const int GEN_HASHX_SIZE = 1 << (GEN_HASHX_BUCKET_BITS + GEN_HASHX_BITS + ZOOM_BASE_SHIFT);
83 static const int GEN_HASHY_SIZE = 1 << (GEN_HASHY_BUCKET_BITS + GEN_HASHY_BITS + ZOOM_BASE_SHIFT);
86 static const int GEN_HASHX_INC = 1;
87 static const int GEN_HASHY_INC = 1 << GEN_HASHX_BITS;
90 static const uint GEN_HASHX_MASK = (1 << GEN_HASHX_BITS) - 1;
91 static const uint GEN_HASHY_MASK = ((1 << GEN_HASHY_BITS) - 1) << GEN_HASHX_BITS;
105 bounds->left = bounds->top = bounds->right = bounds->bottom = 0;
106 for (uint i = 0; i < this->count; ++i) {
109 bounds->left = spr->
x_offs;
110 bounds->top = spr->
y_offs;
114 if (spr->
x_offs < bounds->left) bounds->left = spr->
x_offs;
115 if (spr->
y_offs < bounds->top) bounds->top = spr->
y_offs;
118 if (right > bounds->right) bounds->right = right;
119 if (bottom > bounds->bottom) bounds->bottom = bottom;
133 for (uint i = 0; i < this->count; ++i) {
134 PaletteID pal = force_pal || !this->seq[i].
pal ? default_pal : this->seq[i].
pal;
169 assert(v !=
nullptr);
200 if (this->ServiceIntervalIsPercent()) {
221 bool pending_replace =
false;
226 bool replace_when_old =
false;
232 if (replace_when_old && !v->NeedsAutorenewing(c,
false))
continue;
235 CargoTypes available_cargo_types, union_mask;
238 if (union_mask != 0) {
243 if ((cargo_mask & new_engine_default_cargoes) != cargo_mask) {
259 pending_replace =
true;
260 needed_money += 2 *
Engine::Get(new_engine)->GetCost();
264 return pending_replace;
283 assert(this->
Previous() ==
nullptr);
289 for (
Vehicle *v =
this; v !=
nullptr; v = v->
Next()) {
293 v->MarkAllViewportsDirty();
323 if (grfconfig ==
nullptr)
return;
377 const int HASH_BITS = 7;
378 const int HASH_SIZE = 1 << HASH_BITS;
379 const int HASH_MASK = HASH_SIZE - 1;
380 const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2);
381 const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1;
385 const int HASH_RES = 0;
387 static Vehicle *_vehicle_tile_hash[TOTAL_HASH_SIZE];
389 static Vehicle *VehicleFromTileHash(
int xl,
int yl,
int xu,
int yu,
void *data, VehicleFromPosProc *proc,
bool find_first)
391 for (
int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) {
392 for (
int x = xl; ; x = (x + 1) & HASH_MASK) {
393 Vehicle *v = _vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK];
396 if (find_first && a !=
nullptr)
return a;
420 const int COLL_DIST = 6;
423 int xl =
GB((x - COLL_DIST) /
TILE_SIZE, HASH_RES, HASH_BITS);
424 int xu =
GB((x + COLL_DIST) /
TILE_SIZE, HASH_RES, HASH_BITS);
425 int yl =
GB((y - COLL_DIST) /
TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS;
426 int yu =
GB((y + COLL_DIST) /
TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS;
428 return VehicleFromTileHash(xl, yl, xu, yu, data, proc, find_first);
478 int x =
GB(
TileX(tile), HASH_RES, HASH_BITS);
479 int y =
GB(
TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS;
481 Vehicle *v = _vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK];
483 if (v->
tile != tile)
continue;
486 if (find_first && a !=
nullptr)
return a;
536 if (v->
z_pos > z)
return nullptr;
563 if (v == (
const Vehicle *)data)
return nullptr;
595 if ((t->track != rail_bits) && !
TracksOverlap(t->track | rail_bits))
return nullptr;
619 static void UpdateVehicleTileHash(
Vehicle *v,
bool remove)
628 int y =
GB(
TileY(v->
tile), HASH_RES, HASH_BITS) << HASH_BITS;
629 new_hash = &_vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK];
632 if (old_hash == new_hash)
return;
635 if (old_hash !=
nullptr) {
641 if (new_hash !=
nullptr) {
652 static Vehicle *_vehicle_viewport_hash[1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)];
654 static void UpdateVehicleViewportHash(
Vehicle *v,
int x,
int y,
int old_x,
int old_y)
656 Vehicle **old_hash, **new_hash;
658 new_hash = (x ==
INVALID_COORD) ?
nullptr : &_vehicle_viewport_hash[GEN_HASH(x, y)];
659 old_hash = (old_x ==
INVALID_COORD) ?
nullptr : &_vehicle_viewport_hash[GEN_HASH(old_x, old_y)];
661 if (old_hash == new_hash)
return;
664 if (old_hash !=
nullptr) {
670 if (new_hash !=
nullptr) {
678 void ResetVehicleHash()
681 memset(_vehicle_viewport_hash, 0,
sizeof(_vehicle_viewport_hash));
682 memset(_vehicle_tile_hash, 0,
sizeof(_vehicle_tile_hash));
685 void ResetVehicleColourMap()
697 void InitializeVehicles()
699 _vehicles_to_autoreplace.clear();
703 uint CountVehiclesInChain(
const Vehicle *v)
706 do count++;
while ((v = v->
Next()) !=
nullptr);
716 switch (this->
type) {
723 default:
return false;
733 switch (this->
type) {
738 default:
return false;
832 st->loading_vehicles.remove(
this);
890 StopGlobalFollowVehicle(
this);
909 UpdateVehicleTileHash(
this,
true);
939 if (_game_mode != GM_NORMAL)
return;
944 if (v ==
nullptr)
continue;
956 if (_game_mode != GM_NORMAL)
return;
961 if (v ==
nullptr)
continue;
967 if (
HasBit(callback, 0)) {
968 TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32);
984 void CallVehicleTicks()
986 _vehicles_to_autoreplace.clear();
1000 [[maybe_unused]]
size_t vehicle_index = v->
index;
1073 for (
auto &it : _vehicles_to_autoreplace) {
1076 cur_company.Change(v->
owner);
1101 if (error_message == STR_ERROR_AUTOREPLACE_NOTHING_TO_DO || error_message ==
INVALID_STRING_ID)
continue;
1103 if (error_message == STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY) error_message = STR_ERROR_AUTOREPLACE_MONEY_LIMIT;
1106 if (error_message == STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT) {
1107 message = error_message;
1109 message = STR_NEWS_VEHICLE_AUTORENEW_FAILED;
1117 cur_company.Restore();
1157 const int l = dpi->left;
1158 const int r = dpi->left + dpi->width;
1159 const int t = dpi->top;
1160 const int b = dpi->top + dpi->height;
1169 if (dpi->width + xb < GEN_HASHX_SIZE) {
1170 xl = GEN_HASHX(l - xb);
1175 xu = GEN_HASHX_MASK;
1178 if (dpi->height + yb < GEN_HASHY_SIZE) {
1179 yl = GEN_HASHY(t - yb);
1184 yu = GEN_HASHY_MASK;
1187 for (
int y = yl;; y = (y + GEN_HASHY_INC) & GEN_HASHY_MASK) {
1188 for (
int x = xl;; x = (x + GEN_HASHX_INC) & GEN_HASHX_MASK) {
1189 const Vehicle *v = _vehicle_viewport_hash[x + y];
1191 while (v !=
nullptr) {
1194 l <= v->
coord.right + xb &&
1195 t <= v->
coord.bottom + yb &&
1196 r >= v->
coord.left - xb &&
1197 b >= v->
coord.top - yb)
1225 if (l <= v->coord.right &&
1226 t <= v->coord.bottom &&
1227 r >= v->
coord.left &&
1251 uint dist, best_dist = UINT_MAX;
1253 if ((uint)(x -= vp->
left) >= (uint)vp->
width || (uint)(y -= vp->
top) >= (uint)vp->
height)
return nullptr;
1263 int xl = GEN_HASHX(x - xb);
1264 int xu = GEN_HASHX(x);
1265 int yl = GEN_HASHY(y - yb);
1266 int yu = GEN_HASHY(y);
1268 for (
int hy = yl;; hy = (hy + GEN_HASHY_INC) & GEN_HASHY_MASK) {
1269 for (
int hx = xl;; hx = (hx + GEN_HASHX_INC) & GEN_HASHX_MASK) {
1270 Vehicle *v = _vehicle_viewport_hash[hx + hy];
1272 while (v !=
nullptr) {
1274 x >= v->
coord.left && x <= v->coord.right &&
1275 y >= v->
coord.top && y <= v->coord.bottom) {
1282 if (dist < best_dist) {
1289 if (hx == xu)
break;
1291 if (hy == yu)
break;
1307 static const uint8_t _breakdown_chance[64] = {
1308 3, 3, 3, 3, 3, 3, 3, 3,
1309 4, 4, 5, 5, 6, 6, 7, 7,
1310 8, 8, 9, 9, 10, 10, 11, 11,
1311 12, 13, 13, 13, 13, 14, 15, 16,
1312 17, 19, 21, 25, 28, 31, 34, 37,
1313 40, 44, 48, 52, 56, 60, 64, 68,
1314 72, 80, 90, 100, 110, 120, 130, 140,
1315 150, 170, 190, 210, 230, 250, 250, 250,
1318 void CheckVehicleBreakdown(
Vehicle *v)
1331 v->
cur_speed < 5 || _game_mode == GM_MENU) {
1335 uint32_t r = Random();
1350 if (_breakdown_chance[ClampTo<uint16_t>(rel) >> 10] <= v->
breakdown_chance) {
1448 for (int32_t i = 0; i <= 4; i++) {
1471 str = STR_NEWS_VEHICLE_IS_GETTING_OLD;
1473 str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD;
1475 str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND;
1499 bool loading =
false;
1505 assert(colour ==
nullptr || (st !=
nullptr && is_loading));
1511 for (
const Vehicle *v = front; v !=
nullptr; v = v->
Next()) {
1514 if (v->
cargo_cap != 0 && colour !=
nullptr) {
1516 loading |= !order_no_load &&
1523 if (colour !=
nullptr) {
1524 if (unloading == 0 && loading) {
1525 *colour = STR_PERCENT_UP;
1526 }
else if (unloading == 0 && !loading) {
1527 *colour = STR_PERCENT_NONE;
1528 }
else if (cars == unloading || !loading) {
1529 *colour = STR_PERCENT_DOWN;
1531 *colour = STR_PERCENT_UP_DOWN;
1536 if (max == 0)
return 100;
1539 if (count * 2 < max) {
1541 return CeilDiv(count * 100, max);
1544 return (count * 100) / max;
1555 assert(v == v->
First());
1591 default: NOT_REACHED();
1608 TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
1633 _vehicles_to_autoreplace[v->
index] =
false;
1639 }
else if (cost.
GetCost() != 0) {
1655 _vehicles_to_autoreplace[v->
index] =
false;
1695 UpdateVehicleTileHash(
this,
false);
1708 new_coord.left += pt.x;
1709 new_coord.top += pt.y;
1710 new_coord.right += pt.x + 2 * ZOOM_BASE;
1711 new_coord.bottom += pt.y + 2 * ZOOM_BASE;
1728 this->
coord = new_coord;
1742 if (ignore_cached_coords) {
1745 UpdateVehicleViewportHash(
this, this->
coord.left, this->coord.top, this->sprite_cache.old_coord.left, this->sprite_cache.old_coord.top);
1749 if (ignore_cached_coords) {
1754 std::min(this->sprite_cache.old_coord.top, this->coord.top),
1755 std::max(this->sprite_cache.old_coord.right, this->coord.right),
1756 std::max(this->sprite_cache.old_coord.bottom, this->coord.bottom));
1786 static const int8_t _delta_coord[16] = {
1787 -1,-1,-1, 0, 1, 1, 1, 0,
1788 -1, 0, 1, 1, 1, 0,-1,-1,
1802 static const Direction _new_direction_table[] = {
1812 if (y >= v->
y_pos) {
1813 if (y != v->
y_pos) i += 3;
1817 if (x >= v->
x_pos) {
1818 if (x != v->
x_pos) i++;
1850 for (
auto it = std::begin(this->used_bitmap); it != std::end(this->used_bitmap); ++it) {
1851 BitmapStorage available = ~(*it);
1852 if (available == 0)
continue;
1853 return static_cast<UnitID>(std::distance(std::begin(this->used_bitmap), it) * BITMAP_SIZE +
FindFirstBit(available) + 1);
1855 return static_cast<UnitID>(this->used_bitmap.size() * BITMAP_SIZE + 1);
1865 if (index == 0 || index == UINT16_MAX)
return index;
1869 size_t slot = index / BITMAP_SIZE;
1870 if (slot >= this->used_bitmap.size()) this->used_bitmap.resize(slot + 1);
1871 SetBit(this->used_bitmap[index / BITMAP_SIZE], index % BITMAP_SIZE);
1882 if (index == 0 || index == UINT16_MAX)
return;
1886 assert(index / BITMAP_SIZE < this->used_bitmap.size());
1887 ClrBit(this->used_bitmap[index / BITMAP_SIZE], index % BITMAP_SIZE);
1904 default: NOT_REACHED();
1910 return c->freeunits[type].
NextID();
1940 default: NOT_REACHED();
1947 if (type ==
VEH_ROAD && GetRoadTramType(e->u.road.roadtype) != (RoadTramType)subtype)
continue;
1975 default: NOT_REACHED();
1980 engine_type = parent_engine_type;
1986 if (!
IsValidCargoID(cargo_type)) cargo_type = GetCargoIDByLabel(CT_GOODS);
1991 return LS_PASSENGER_WAGON_STEAM;
1994 switch (RailVehInfo(parent_engine_type)->engclass) {
1995 default: NOT_REACHED();
1996 case EC_STEAM:
return LS_PASSENGER_WAGON_STEAM;
1997 case EC_DIESEL:
return is_mu ? LS_DMU : LS_PASSENGER_WAGON_DIESEL;
1998 case EC_ELECTRIC:
return is_mu ? LS_EMU : LS_PASSENGER_WAGON_ELECTRIC;
1999 case EC_MONORAIL:
return LS_PASSENGER_WAGON_MONORAIL;
2000 case EC_MAGLEV:
return LS_PASSENGER_WAGON_MAGLEV;
2004 return LS_FREIGHT_WAGON;
2010 default: NOT_REACHED();
2012 case EC_DIESEL:
return is_mu ? LS_DMU : LS_DIESEL;
2013 case EC_ELECTRIC:
return is_mu ? LS_EMU : LS_ELECTRIC;
2022 engine_type = parent_engine_type;
2027 if (!
IsValidCargoID(cargo_type)) cargo_type = GetCargoIDByLabel(CT_GOODS);
2041 if (!
IsValidCargoID(cargo_type)) cargo_type = GetCargoIDByLabel(CT_GOODS);
2047 case AIR_HELI:
return LS_HELICOPTER;
2048 case AIR_CTOL:
return LS_SMALL_PLANE;
2049 case AIR_CTOL | AIR_FAST:
return LS_LARGE_PLANE;
2050 default: NOT_REACHED();
2083 if (c->livery[LS_DEFAULT].
in_use != 0) {
2089 return &c->livery[scheme];
2098 if (map != PAL_NONE)
return map;
2107 static_assert(PAL_NONE == 0);
2108 map =
GB(callback, 0, 14);
2111 if (!
HasBit(callback, 14)) {
2113 if (v !=
nullptr)
const_cast<Vehicle *
>(v)->colourmap = map;
2129 if (twocc) map += livery->
colour2 * 16;
2132 if (v !=
nullptr)
const_cast<Vehicle *
>(v)->colourmap = map;
2144 return GetEngineColourMap(engine_type, company,
INVALID_ENGINE,
nullptr);
2178 while (order !=
nullptr) {
2181 if (order->
IsType(OT_IMPLICIT)) {
2187 order = order->
next;
2192 if (order ==
nullptr) {
2209 this->current_order.GetDestination() == this->last_station_visited) {
2230 (in_list ==
nullptr || !in_list->
IsType(OT_IMPLICIT) ||
2235 if (prev_order ==
nullptr ||
2236 (!prev_order->
IsType(OT_IMPLICIT) && !prev_order->
IsType(OT_GOTO_STATION)) ||
2248 if (order ==
nullptr)
break;
2265 if (suppress_implicit_orders) {
2273 if (order->
IsType(OT_IMPLICIT)) {
2279 order = order->
next;
2284 if (order ==
nullptr) {
2288 assert(order !=
nullptr);
2291 }
else if (!suppress_implicit_orders &&
2336 for (
Vehicle *v =
this; v !=
nullptr; v = v->
next) {
2339 Debug(misc, 1,
"cancelling cargo reservation");
2382 st->loading_vehicles.remove(
this);
2445 if (order ==
nullptr ||
2446 (!order->
IsType(OT_IMPLICIT) && !order->
IsType(OT_GOTO_STATION)) ||
2453 case OT_DUMMY:
break;
2480 if (o->IsType(OT_CONDITIONAL))
return true;
2492 if (o->IsType(OT_GOTO_DEPOT) && o->GetDepotActionType() &
ODATFB_UNBUNCH)
return true;
2507 if (previous_order ==
nullptr || !previous_order->
IsType(OT_GOTO_DEPOT))
return false;
2527 int num_vehicles = 0;
2540 num_vehicles = std::max(num_vehicles, 1);
2543 TimerGameTick::Ticks separation = std::max((total_travel_time / num_vehicles / num_vehicles), 1);
2586 if (ret.
Failed())
return ret;
2626 static const StringID no_depot[] = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR};
2637 this->SetDestTile(closestDepot.location);
2670 uint8_t visual_effect;
2685 callback =
GB(callback, 0, 8);
2692 visual_effect = callback;
2724 static const int8_t _vehicle_smoke_pos[8] = {
2725 1, 1, 1, 0, -1, -1, -1, 0
2737 uint count =
GB(callback, 0, 2);
2738 bool auto_center =
HasBit(callback, 13);
2739 bool auto_rotate = !
HasBit(callback, 14);
2741 int8_t l_center = 0;
2754 int8_t x_center = _vehicle_smoke_pos[l_dir] * l_center;
2755 int8_t y_center = _vehicle_smoke_pos[t_dir] * l_center;
2757 for (uint i = 0; i < count; i++) {
2759 uint type =
GB(reg, 0, 8);
2760 int8_t x =
GB(reg, 8, 8);
2761 int8_t y =
GB(reg, 16, 8);
2762 int8_t z =
GB(reg, 24, 8);
2767 x = _vehicle_smoke_pos[l_dir] * l + _vehicle_smoke_pos[t_dir] * t;
2768 y = _vehicle_smoke_pos[t_dir] * l - _vehicle_smoke_pos[l_dir] * t;
2799 this->cur_speed < 2) {
2812 if (
HasBit(t->flags, VRF_REVERSING) ||
2828 if (effect_model >= VESM_END) effect_model =
VESM_NONE;
2855 switch (effect_model) {
2879 int power_weight_effect = 0;
2907 if (evt != EV_END && advanced) {
2910 }
else if (evt != EV_END) {
2918 int x = _vehicle_smoke_pos[v->
direction] * effect_offset;
2919 int y = _vehicle_smoke_pos[(v->
direction + 2) % 8] * effect_offset;
2928 }
while ((v = v->
Next()) !=
nullptr);
2939 assert(
this !=
next);
2941 if (this->next !=
nullptr) {
2943 for (
Vehicle *v = this->next; v !=
nullptr; v = v->
Next()) {
2951 if (this->next !=
nullptr) {
2955 for (
Vehicle *v = this->next; v !=
nullptr; v = v->
Next()) {
2970 if (shared_chain->
orders ==
nullptr) {
3010 }
else if (were_first) {
3061 assert(e !=
nullptr);
3108 return STR_ERROR_NO_RAIL_STATION;
3114 StringID err = rv->
IsBus() ? STR_ERROR_NO_BUS_STATION : STR_ERROR_NO_TRUCK_STATION;
3116 for (; rs !=
nullptr; rs = rs->
next) {
3119 err = STR_ERROR_NO_STOP_ARTICULATED_VEHICLE;
3126 err = RoadTypeIsRoad(rv->
roadtype) ? STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE : STR_ERROR_NO_STOP_COMPATIBLE_TRAM_TYPE;
3135 return STR_ERROR_NO_DOCK;
3140 return STR_ERROR_AIRPORT_NO_PLANES;
3142 return STR_ERROR_AIRPORT_NO_HELICOPTERS;
3226 for (; u !=
nullptr && num_vehicles > 0; num_vehicles--) {
3246 uint32_t max_weight = 0;
3248 for (
const Vehicle *u =
this; u !=
nullptr; u = u->
Next()) {
3249 max_weight += u->GetMaxWeight();
3262 if (max_weight == 0)
return 0;
3275 if (v1 ==
nullptr && v2 ==
nullptr)
return true;
3276 if (v1 ==
nullptr || v2 ==
nullptr)
return false;
3294 if (o1 ==
nullptr && o2 ==
nullptr)
return true;
3295 if (o1 ==
nullptr || o2 ==
nullptr)
return false;
3296 if (!o1->
Equals(*o2))
return false;
uint16_t height
Height of the sprite.
bool lost_vehicle_warn
if a vehicle can't find its destination, show a warning
uint8_t cached_vis_effect
Visual effect to show (see VisualEffect)
Buses, trucks and trams belong to this class.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ ROADSTOP_BUS
A standard stop for buses.
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
@ VRF_TOGGLE_REVERSE
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
std::map< VehicleID, bool > AutoreplaceMap
List of vehicles that should check for autoreplace this tick.
StationFacility facilities
The facilities that this station has.
StationID targetairport
Airport to go to next.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
uint8_t misc_flags
Miscellaneous flags.
int8_t x_bb_offs
x offset of vehicle bounding box
uint16_t animation_state
State primarily used to change the graphics/behaviour.
bool IsRefit() const
Is this order a refit order.
UnitID max_aircraft
max planes in game per company
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
bool is_viewport_candidate
This vehicle can potentially be drawn on a viewport.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Direction ReverseDir(Direction d)
Return the reverse of a direction.
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-...
void MakeDummy()
Makes this order a Dummy order.
bool Chance16I(const uint32_t a, const uint32_t b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
GoodsEntry goods[NUM_CARGO]
Goods at this station.
@ EV_ELECTRIC_SPARK
Sparcs of electric engines.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
@ VE_OFFSET_COUNT
Number of bits used for the offset.
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
@ VE_DISABLE_EFFECT
Flag to disable visual effect.
EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement for the given company and original engine type.
uint8_t breakdown_chance
Current chance of breakdowns.
bool IsType(OrderType type) const
Check whether this order is of the given type.
void PreDestructor()
Destroy all stuff that (still) needs the virtual functions to work properly.
uint16_t UnitID
Type for the company global vehicle unit number.
static Titem * Get(size_t index)
Returns Titem with given index.
void PrepareUnload(Vehicle *front_v)
Prepare the vehicle to be unloaded.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
@ CC_PASSENGERS
Passengers.
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
VehicleSpriteSeq sprite_seq
Vehicle appearance.
@ FACIL_TRAIN
Station with train station.
int16_t x_offs
Number of pixels to shift the sprite to the right.
static void CountEngine(const Vehicle *v, int delta)
Update num_engines when adding/removing an engine.
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
uint16_t reliability_spd_dec
Reliability decrease speed.
Money value
Value of the vehicle.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
TimerGameTick::Ticks round_trip_time
How many ticks for a single circumnavigation of the orders.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
const TileTypeProcs *const _tile_type_procs[16]
Tile callback functions for each type of tile.
bool HasEngineType() const
Check whether Vehicle::engine_type has any meaning.
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
@ GBUG_VEH_POWERED_WAGON
Powered wagon changed poweredness state when not inside a depot.
bool IsEngineCountable() const
Check if a vehicle is counted in num_engines in each company struct.
@ CBID_VEHICLE_VISUAL_EFFECT
Visual effects and wagon power.
The information about a vehicle list.
uint16_t cargo_cap
total capacity
static const int32_t INVALID_COORD
Sentinel for an invalid coordinate.
static DateFract date_fract
Fractional part of the day.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
bool HasAnyRailTypesAvail(const CompanyID company)
Test if any buildable railtype is available for a company.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Class to backup a specific variable and restore it later.
void MakeLoading(bool ordered)
Makes this order a Loading order.
void MakeLeaveStation()
Makes this order a Leave Station order.
@ FACIL_DOCK
Station with a dock.
@ PM_PAUSED_ERROR
A game paused because a (critical) error.
void LeaveStation()
Perform all actions when leaving a station.
Vehicle * Next() const
Get the next vehicle of this vehicle.
T * Next() const
Get next vehicle in the chain.
TileIndex xy
Position on the map.
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoID *cargo_type)
Get cargo mask of all cargoes carried by an articulated vehicle.
@ DIRDIFF_SAME
Both directions faces to the same direction.
DepotCommand
Flags for goto depot commands.
@ OLFB_FULL_LOAD
Full load all cargoes of the consist.
Gamelog _gamelog
Gamelog instance.
DestinationID GetDestination() const
Gets the destination of this order.
int width
Screen width of the viewport.
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static void SpawnAdvancedVisualEffect(const Vehicle *v)
Call CBID_VEHICLE_SPAWN_VISUAL_EFFECT and spawn requested effects.
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
uint32_t cached_weight
Total weight of the consist (valid only for the first engine).
static const uint IMPLICIT_ORDER_ONLY_CAP
Maximum number of orders in implicit-only lists before we start searching harder for duplicates.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
int height
Screen height of the viewport.
uint8_t y_extent
y-extent of vehicle bounding box
@ EC_STEAM
Steam rail engine.
An interval timer will fire every interval, and will continue to fire until it is deleted.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
GroupID parent
Parent group.
bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2)
Checks if two vehicles have the same list of orders.
Owner
Enum for all companies/owners.
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
@ VS_DEFPAL
Use default vehicle palette.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
@ VSE_BREAKDOWN
Vehicle breaking down.
Tindex index
Index of this pool item.
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
virtual uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
@ VEH_TRAIN
Train vehicle type.
static const int MAX_VEHICLE_PIXEL_Y
Maximum height of a vehicle in pixels in #ZOOM_BASE.
int top
Screen coordinate top edge of the viewport.
@ PFE_GL_ROADVEHS
Time spend processing road vehicles.
SpriteID sprite
The 'real' sprite.
GroupID group_id
Index of group Pool array.
Vehicle(VehicleType type=VEH_INVALID)
Vehicle constructor.
@ EF_NO_BREAKDOWN_SMOKE
Do not show black smoke during a breakdown.
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
DifficultySettings difficulty
settings related to the difficulty
uint32_t grf_bugs
NOSAVE: bugs in this GRF in this run,.
static void CountVehicle(const Vehicle *v, int delta)
Update num_vehicle when adding or removing a vehicle.
TimerGameTick::TickCounter depot_unbunching_next_departure
When the vehicle will next try to leave its unbunching depot.
uint8_t vehicle_breakdowns
likelihood of vehicles breaking down
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
@ Normal
The most basic (normal) sprite.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
int8_t trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
void HideFillingPercent(TextEffectID *te_id)
Hide vehicle loading indicators.
@ VE_TYPE_ELECTRIC
Electric sparks.
static void VehicleReachedMinAge(const Vehicle *v)
Add a vehicle to the profit sum of its group.
Vehicle * next
pointer to the next vehicle in the chain
@ ODTF_MANUAL
Manually initiated order.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
TimerGameTick::TickCounter last_loading_tick
Last TimerGameTick::counter tick that the vehicle has stopped at a station and could possibly leave w...
@ VF_LOADING_FINISHED
Vehicle has finished loading.
@ VEH_ROAD
Road vehicle type.
Livery livery
Custom colour scheme for vehicles in this group.
static const uint TILE_SIZE
Tile size in world coordinates.
@ RSRT_VEH_DEPARTS
Trigger roadstop when road vehicle leaves.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
Update signals, starting at one side of a tile Will check tile next to this at opposite side too.
static DateFract date_fract
Fractional part of the day.
static Station * Get(size_t index)
Gets station with given index.
@ EV_STEAM_SMOKE
Smoke of steam engines.
virtual ~Vehicle()
We want to 'destruct' the right class.
ClientSettings _settings_client
The current settings for this game.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
void VehicleLengthChanged(const Vehicle *u)
Logs a bug in GRF and shows a warning message if this is for the first time this happened.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
@ VE_TYPE_COUNT
Number of bits used for the effect type.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
void RunVehicleCalendarDayProc()
Age all vehicles, spreading out the action using the current TimerGameCalendar::date_fract.
bool IsRearDualheaded() const
Tell if we are dealing with the rear end of a multiheaded engine.
@ VS_TRAIN_SLOWING
Train is slowing down.
@ SND_3A_BREAKDOWN_TRAIN_SHIP_TOYLAND
58 == 0x3A Breakdown: train or ship (toyland)
@ WC_COMPANY
Company view; Window numbers:
void ReleaseID(UnitID index)
Release a unit number.
@ WC_STATION_VIEW
Station view; Window numbers:
static void ClearVehicle(const Vehicle *v)
Clear/update the (clone) vehicle from an order backup.
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
uint Return(uint max_move, StationCargoList *dest, StationID next_station, TileIndex current_tile)
Returns reserved cargo to the station and removes it from the cache.
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
virtual ClosestDepot FindClosestDepot()
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
static const int MAX_VEHICLE_PIXEL_X
Maximum width of a vehicle in pixels in #ZOOM_BASE.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
int virtual_top
Virtual top coordinate.
Owner owner
Which company owns the vehicle?
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
Calculates the set of vehicles that will be affected by a given selection.
uint64_t TickCounter
The type that the tick counter is stored in.
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
@ DC_EXEC
execute the given command
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
uint32_t PaletteID
The number of the palette.
uint8_t landscape
the landscape we're currently in
@ VSE_VISUAL_EFFECT
Vehicle visual effect (steam, diesel smoke or electric spark) is shown.
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type=INVALID_CARGO)
Trigger road stop randomisation.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
void RemoveVehicle(Vehicle *v)
Removes the vehicle from the shared order list.
StringID GetErrorMessage() const
Returns the error message of a command.
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
Delete all orders from a vehicle.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
bool Chance16(const uint32_t a, const uint32_t b, const std::source_location location=std::source_location::current())
Flips a coin with given probability.
@ VS_AIRCRAFT_BROKEN
Aircraft is broken down.
uint32_t motion_counter
counter to occasionally play a vehicle sound.
@ ROADSTOP_TRUCK
A standard stop for trucks.
DoCommandFlag
List of flags for a command.
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
@ VE_OFFSET_START
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
@ ODATFB_UNBUNCH
Service the vehicle and then unbunch it.
@ AIR_SHADOW
shadow of the aircraft
@ RVSB_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
TimerGameTick::TickCounter depot_unbunching_last_departure
When the vehicle last left its unbunching depot.
GRFBugs
Encountered GRF bugs.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
bool Succeeded() const
Did this command succeed?
@ SND_35_BREAKDOWN_ROADVEHICLE_TOYLAND
53 == 0x35 Breakdown: road vehicle (toyland)
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
void HandleAircraftEnterHangar(Aircraft *v)
Handle Aircraft specific tasks when an Aircraft enters a hangar.
int32_t x_pos
x coordinate.
bool vehicle_income_warn
if a vehicle isn't generating income, show a warning
GameCreationSettings game_creation
settings used during the creation of a game (map)
Vehicle * CheckClickOnVehicle(const Viewport *vp, int x, int y)
Find the vehicle close to the clicked coordinates.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
@ PFE_GL_TRAINS
Time spent processing trains.
@ EC_ELECTRIC
Electric rail engine.
OrderType GetType() const
Get the type of order of this order.
CargoList that is used for vehicles.
Aircraft, helicopters, rotors and their shadows belong to this class.
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
Insert a new order but skip the validation.
void UpdateCache()
Update the caches of this ship.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static constexpr TimerGame< struct Economy >::Date MAX_DATE
The date of the last day of the max year.
@ VF_STOP_LOADING
Don't load anymore during the next load cycle.
@ VE_TYPE_DIESEL
Diesel fumes.
@ ONSF_NO_STOP_AT_ANY_STATION
The vehicle will not stop at any stations it passes including the destination.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
uint8_t liveries
options for displaying company liveries, 0=none, 1=self, 2=all
virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
UnitID UseID(UnitID index)
Use a unit number.
@ EC_MAGLEV
Maglev engine.
@ SND_10_BREAKDOWN_TRAIN_SHIP
14 == 0x0E Breakdown: train or ship (non-toyland)
@ VRF_LEAVING_STATION
Train is just leaving a station.
OrderSettings order
settings related to orders
static size_t GetPoolSize()
Returns first unused index.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
@ VS_HIDDEN
Vehicle is not visible.
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Data structure for viewport, display of a part of the world.
EngineClass engclass
Class of engine for this vehicle.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
bool IsValid() const
Check whether the sequence contains any sprites.
@ OLF_FULL_LOAD_ANY
Full load a single cargo of the consist.
TileIndex dest_tile
Heading for this tile.
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
uint8_t subtype
Type of aircraft.
VehicleID disaster_vehicle
NOSAVE: Disaster vehicle targetting this vehicle.
@ VEH_DISASTER
Disaster vehicle type.
int16_t engine_renew_months
months before/after the maximum vehicle age a vehicle should be renewed
@ VE_TYPE_START
First bit used for the type of effect.
@ TO_INVALID
Invalid transparency option.
Cached, frequently calculated values.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
bool engine_renew
is autorenew enabled
CargoID GetRefitCargo() const
Get the cargo to to refit to.
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Common return value for all commands.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
void UpdateBoundingBoxCoordinates(bool update_cache) const
Update the bounding box co-ordinates of the vehicle.
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
Information about GRF, used in the game and (part of it) in savegames.
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
uint8_t in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
TrackBits
Allow incrementing of Track variables.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
void AgeCargo()
Ages the all cargo in this list.
int virtual_left
Virtual left coordinate.
void RemoveFromShared()
Removes the vehicle from the shared order list.
@ VF_CARGO_UNLOADING
Vehicle is unloading cargo.
UnitID max_ships
max ships in game per company
@ EV_BREAKDOWN_SMOKE_AIRCRAFT
Smoke of broken aircraft.
bool HasRating() const
Does this cargo have a rating at this station?
TileIndex tile
Current tile index.
void CancelReservation(StationID next, Station *st)
Return all reserved cargo packets to the station and reset all packets staged for transfer.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
uint8_t pos
Next desired position of the aircraft.
@ EIT_ON_MAP
Vehicle drawn in viewport.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
int left
Screen coordinate left edge of the viewport.
EngineID engine_type
The type of engine used for this vehicle.
static void DoDrawVehicle(const Vehicle *v)
Add vehicle sprite for drawing to the screen.
@ VS_CRASHED
Vehicle is crashed.
Sprite sequence for a vehicle part.
StationID last_station_visited
The last station we stopped at.
UnitID GetFreeUnitNumber(VehicleType type)
Get an unused unit number for a vehicle (if allowed).
@ PFE_GL_SHIPS
Time spent processing ships.
@ EF_USES_2CC
Vehicle uses two company colours.
VehicleCargoList cargo
The cargo this vehicle is carrying.
@ CBID_VEHICLE_SPAWN_VISUAL_EFFECT
Called to spawn visual effects for vehicles.
bool Failed() const
Did this command fail?
uint16_t width
Width of the sprite.
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
@ CCF_ARRANGE
Valid changes for arranging the consist in a depot.
Order current_order
The current order (+ status, like: loading)
uint32_t engine_renew_money
minimum amount of money before autorenew is used
LiveryScheme
List of different livery schemes.
@ VEH_SHIP
Ship vehicle type.
Airport airport
Tile area the airport covers.
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
Test if any buildable RoadType is available for a company.
@ EXPENSES_NEW_VEHICLES
New vehicles.
GroundVehicleCache gcache
Cache of often calculated values.
@ EC_DIESEL
Diesel rail engine.
struct AirportFTA * layout
state machine for airport
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
uint16_t cur_speed
current speed
Flags flags
Flags for this airport type.
const Livery * GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, uint8_t livery_setting)
Determines the livery for a vehicle.
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
Delete an order but skip the parameter validation.
Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn't exists.
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
static Vehicle * VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc, bool find_first)
Helper function for FindVehicleOnPos/HasVehicleOnPos.
CompanySettings settings
settings specific for each company
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Internal structure used in openttd - Finite sTate mAchine --> FTA.
uint32_t Pack() const
Pack a VehicleListIdentifier in a single uint32.
@ VS_STOPPED
Vehicle is stopped by the player.
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
VisualEffectSpawnModel
Models for spawning visual effects.
@ DontCancel
Don't cancel current goto depot command if any.
static void UpdateAutoreplace(CompanyID company)
Update autoreplace_defined and autoreplace_finished of all statistics of a company.
static Vehicle * VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc, bool find_first)
Helper function for FindVehicleOnPos/HasVehicleOnPos.
TileIndex new_tile
Tile of the vehicle after moving.
@ EF_RAIL_IS_MU
Rail vehicle is a multiple-unit (DMU/EMU)
void ResetRefitCaps()
Reset all refit_cap in the consist to cargo_cap.
static bool PreviousOrderIsUnbunching(const Vehicle *v)
Check if the previous order is a depot unbunching order.
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
bool VehiclesHaveSameEngineList(const Vehicle *v1, const Vehicle *v2)
Checks if two vehicle chains have the same list of engines.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
'Train' is either a loco or a wagon.
bool GRFBugReverse(uint32_t grfid, uint16_t internal_id)
Logs GRF bug - rail vehicle has different length after reversing.
Money GetCost() const
The costs as made up to this moment.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
void DeleteDepotHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a depot window.
@ WC_SHIPS_LIST
Ships list; Window numbers:
uint64_t block
64 bit blocks (st->airport.flags), should be enough for the most complex airports
StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
Get reason string why this station can't be used by the given vehicle.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
virtual void PlayLeaveStationSound([[maybe_unused]] bool force=false) const
Play the sound associated with leaving the station.
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
int8_t y_bb_offs
y offset of vehicle bounding box
bool _networking
are we in networking mode?
uint8_t smoke_amount
amount of smoke/sparks locomotives produce
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
bool MarkAllViewportsDirty() const
Marks viewports dirty where the vehicle's image is.
bool old_vehicle_warn
if a vehicle is getting old, show a warning
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
void KeepAll()
Marks all cargo in the vehicle as to be kept.
virtual void OnNewEconomyDay()
Calls the new economy day handler of the vehicle.
@ FACIL_TRUCK_STOP
Station with truck stops.
@ SRT_TRAIN_DEPARTS
Trigger platform when train leaves.
Coordinates of a point in 2D.
bool IsDepotTile(Tile tile)
Is the given tile a tile with a depot on it?
DirDiff
Allow incrementing of Direction variables.
@ WC_TRAINS_LIST
Trains list; Window numbers:
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
bool HasDepotOrder() const
Checks if a vehicle has a depot in its order list.
uint16_t cargo_age_counter
Ticks till cargo is aged next.
uint8_t previous_pos
Previous desired position of the aircraft.
bool show_track_reservation
highlight reserved tracks.
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical)
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command)
Send this vehicle to the depot using the given command(s).
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
void Leave(RoadVehicle *rv)
Leave the road stop.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
uint16_t num_vehicle
Number of vehicles.
uint16_t reliability
Current reliability of the engine.
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
@ VE_TYPE_DEFAULT
Use default from engine class.
SpriteID colourmap
NOSAVE: cached colour mapping.
static Vehicle * GetVehicleTunnelBridgeProc(Vehicle *v, void *data)
Procedure called for every vehicle found in tunnel/bridge in the hash map.
@ VESM_DIESEL
Diesel model.
@ RAILVEH_WAGON
simple wagon, not motorized
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
@ ODATFB_HALT
Service the vehicle and then halt it.
@ WC_VEHICLE_REFIT
Vehicle refit; Window numbers:
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
int32_t z_pos
z coordinate.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
uint16_t local_id
id defined by the grf file for this entity
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Increase capacity for a link stat given by station cargo and next hop.
Direction direction
facing
bool IsStationRoadStopTile(Tile t)
Is tile t a road stop station?
bool MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
void VehicleEnteredDepotThisTick(Vehicle *v)
Adds a vehicle to the list of vehicles that visited a depot this tick.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
uint8_t tick_counter
Increased by one for each tick.
@ CBID_VEHICLE_COLOUR_MAPPING
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Vehicle * next_shared
pointer to the next vehicle that shares the order
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
int32_t Ticks
The type to store ticks in.
VehicleCache vcache
Cache of often used vehicle values.
All ships have this type.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
void LoadUnloadStation(Station *st)
Load/unload the vehicles in this station according to the order they entered.
CompanyID _current_company
Company currently doing an action.
uint8_t breakdown_delay
Counter for managing breakdown length.
@ VESM_NONE
No visual effect.
bool revalidate_before_draw
We need to do a GetImage() and check bounds before drawing this sprite.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a group window.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Vehicle * hash_viewport_next
NOSAVE: Next vehicle in the visual location hash.
Base class for all pools.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
bool no_servicing_if_no_breakdowns
don't send vehicles to depot when breakdowns are disabled
uint8_t day_counter
Increased by one for each day.
TimerGameCalendar::Date max_age
Maximum age.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
@ PFE_GL_ECONOMY
Time spent processing cargo movement.
UnitID max_trains
max trains in game per company
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI.
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
@ CBM_VEHICLE_VISUAL_EFFECT
Visual effects and wagon power (trains, road vehicles and ships)
void Restore()
Restore the variable.
static void UpdateProfits()
Recompute the profits for all groups.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
uint8_t state
State of the airport.
int8_t x_offs
x offset for vehicle sprite
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
void SetDepotReservation(Tile t, bool b)
Set the reservation state of the depot.
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...
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
TimerGameEconomy::Date economy_age
Age in economy days.
@ OUFB_NO_UNLOAD
Totally no unloading will be done.
bool HasFullLoadOrder() const
Check if the current vehicle has a full load order.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
EffectVehicleType
Effect vehicle types.
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
int16_t y_offs
Number of pixels to shift the sprite downwards.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
@ SAT_TRAIN_DEPARTS
Trigger platform when train leaves.
Colours colour1
First colour, for all vehicles.
CargoPayment * cargo_payment
The cargo payment we're currently in.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
Determines the LiveryScheme for a vehicle.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
uint16_t reliability
Reliability.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
@ MTA_LOAD
Load the cargo from the station.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
TrackBits state
The "track" the ship is following.
Position information of a vehicle after it moved.
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
@ VE_DISABLE_WAGON_POWER
Flag to disable wagon power.
@ MP_STATION
A tile of a station.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TimerGameCalendar::Date age
Age in calendar days.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
UnitID NextID() const
Find first unused unit number.
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
static void RunEconomyVehicleDayProc()
Increases the day counter for all vehicles and calls 1-day and 32-day handlers.
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
@ EV_DIESEL_SMOKE
Smoke of diesel engines.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Direction
Defines the 8 directions on the map.
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
RoadStop * next
Next stop of the given type at this station.
@ DIRDIFF_90RIGHT
Angle of 90 degrees right.
UnitID unitnumber
unit number, for display purposes only
DestinationID destination
The DestinationID as used for orders.
A special vehicle is one of the following:
static const VehicleOrderID MAX_VEH_ORDER_ID
Last valid VehicleOrderID.
bool HasUnbunchingOrder() const
Check if the current vehicle has an unbunching order.
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
UnitID max_roadveh
max trucks in game per company
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
TileIndex old_tile
Current tile of the vehicle.
@ VE_ADVANCED_EFFECT
Flag for advanced effects.
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
int32_t y_pos
y coordinate.
Structure to return information about the closest depot location, and whether it could be found.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
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...
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoID cargo_type)
Trigger station randomisation.
uint32_t GetDisplayMaxWeight() const
Calculates the maximum weight of the ground vehicle when loaded.
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
bool NeedsServicing() const
Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for ser...
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
RoadStopType GetRoadStopType(Tile t)
Get the road stop type of this tile.
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
@ FACIL_BUS_STOP
Station with bus stops.
void AddVehicle([[maybe_unused]] Vehicle *v)
Adds the given vehicle to this shared order list.
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle in on a specific location.
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
ZoomLevel zoom
The zoom level of the viewport.
bool HasConditionalOrder() const
Check if the current vehicle has a conditional order.
bool NeedsAutorenewing(const Company *c, bool use_renew_setting=true) const
Function to tell if a vehicle needs to be autorenewed.
@ VF_PATHFINDER_LOST
Vehicle's pathfinder is lost.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
void ReleaseUnitNumber()
Release the vehicle's unit number.
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
Get the cargo mask of the parts of a given engine.
@ Service
The vehicle will leave the depot right after arrival (service only)
VehiclePool _vehicle_pool("Vehicle")
The pool with all our precious vehicles.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
VehicleType
Available vehicle types.
@ TFP_NONE
Normal operation.
@ CBID_VEHICLE_32DAY_CALLBACK
Called for every vehicle every 32 days (not all on same date though).
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
bool IsBus() const
Check whether a roadvehicle is a bus.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
uint GetNumVehicles() const
Return the number of vehicles that share this orders list.
uint8_t x_extent
x-extent of vehicle bounding box
CargoID cargo_type
type of cargo this vehicle is carrying
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
@ ODATF_SERVICE_ONLY
Only service the vehicle.
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
static Vehicle * EnsureNoVehicleProcZ(Vehicle *v, void *data)
Callback that returns 'real' vehicles lower or at height *(int*)data .
@ VSE_RUNNING
Vehicle running normally.
Train * GetNextUnit() const
Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consis...
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
@ EF_ROAD_TRAM
Road vehicle is a tram/light rail vehicle.
virtual void OnNewCalendarDay()
Calls the new calendar day handler of the vehicle.
PaletteID pal
The palette (use PAL_NONE) if not needed)
static Date date
Current date in days (day counter).
uint16_t & GetGroundVehicleFlags()
Access the ground vehicle flags of the vehicle.
VehicleSettings vehicle
options for vehicles
uint16_t EngineID
Unique identification number of an engine.
uint8_t CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
@ CBM_VEHICLE_COLOUR_REMAP
Change colour mapping of vehicle.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Money GetAvailableMoney(CompanyID company)
Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
A Stop for a Road Vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleType type
Type of vehicle.
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
@ HELICOPTERS
Can helicopters land on this airport type?
void ReleaseDisasterVehicle(VehicleID vehicle)
Notify disasters that we are about to delete a vehicle.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
virtual bool Tick()
Calls the tick handler of the vehicle.
void UpdatePositionAndViewport()
Update the position of the vehicle, and update the viewport.
const struct GRFFile * grffile
grf file that introduced this entity
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
@ VIWD_MODIFY_ORDERS
Other order modifications.
static constexpr int DAYS_IN_ECONOMY_MONTH
Days in an economy month, when in wallclock timekeeping mode.
void UpdatePosition()
Update the position of the vehicle.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
int y
x and y position of the vehicle after moving
void EconomyAgeVehicle(Vehicle *v)
Update economy age of a vehicle.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
@ VESM_ELECTRIC
Electric model.
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Specification of a rectangle with absolute coordinates of all edges.
bool IsLocalCompany()
Is the current company the local company?
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_MIN) When shifting right,...
@ VSE_STOPPED_16
Every 16 ticks while the vehicle is stopped (speed == 0).
@ AIRPLANES
Can planes land on this airport type?
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
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...
Colours colour2
Second colour, for vehicles with 2CC support.
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
uint16_t wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
OrderList * orders
Pointer to the order list for this vehicle.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
@ TRACK_BIT_DEPOT
Bitflag for a depot.
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.
Data structure describing a sprite.
static const uint8_t LIT_ALL
Show the liveries of all companies.
#define CLRBITS(x, y)
Clears several bits in a variable.
@ PM_PAUSED_NORMAL
A game normally paused.
void DeleteUnreachedImplicitOrders()
Delete all implicit orders which were not reached.
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
@ GBUG_VEH_LENGTH
Length of rail vehicle changes when not inside a depot.
Order * next
Pointer to next order. If nullptr, end of list.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
@ VS_SHADOW
Vehicle is a shadow vehicle.
Information about a particular livery.
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
TransparencyOption GetTransparencyOption() const
Determines the transparency option affecting the effect.
Rect old_coord
Co-ordinates from the last valid bounding box.
static const TimerGameEconomy::Date VEHICLE_PROFIT_MIN_AGE
Only vehicles older than this have a meaningful profit.
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
void ViewportAddVehicles(DrawPixelInfo *dpi)
Add the vehicle sprites that should be drawn at a part of the screen.
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
@ VE_OFFSET_CENTRE
Value of offset corresponding to a position above the centre of the vehicle.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates by given interval.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
void MakeImplicit(StationID destination)
Makes this order an implicit order.
T * GetFirstEnginePart()
Get the first part of an articulated engine.
@ FLYING
Vehicle is flying in the air.
@ VE_TYPE_STEAM
Steam plumes.
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
@ EV_BREAKDOWN_SMOKE
Smoke of broken vehicles except aircraft.
int8_t y_offs
y offset for vehicle sprite
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
@ SND_0F_BREAKDOWN_ROADVEHICLE
13 == 0x0D Breakdown: road vehicle (non-toyland)
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
uint16_t refit_cap
Capacity left over from before last refit.
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
@ OLFB_NO_LOAD
Do not load anything.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
const char * GetName() const
Get the name of this grf.
uint8_t z_extent
z-extent of vehicle bounding box
Data about how and where to blit pixels.
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
@ EC_MONORAIL
Mono rail engine.
@ VSE_RUNNING_16
Every 16 ticks while the vehicle is running (speed > 0).
static const uint8_t LIT_COMPANY
Show the liveries of your own company.
@ FACIL_AIRPORT
Station with an airport.
VehicleEnterTileProc * vehicle_enter_tile_proc
Called when a vehicle enters a tile.
static Date date
Current date in days (day counter).
uint8_t breakdown_ctr
Counter for managing breakdown events.
uint32_t GetDisplayMinPowerToWeight() const
Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.