57 #include "table/strings.h" 109 if (!T::IsValidID(t))
continue;
111 if (closest_station == INVALID_STATION) {
113 }
else if (closest_station != t) {
118 *st = (closest_station == INVALID_STATION) ? NULL : T::Get(closest_station);
139 for (
int dx = -3; dx <= 3; dx++) {
140 for (
int dy = -3; dy <= 3; dy++) {
196 #define M(x) ((x) - STR_SV_STNAME) 201 STATIONNAMING_AIRPORT,
202 STATIONNAMING_OILRIG,
204 STATIONNAMING_HELIPORT,
229 if (
GetIndustrySpec(indtype)->station_name == STR_UNDEFINED)
return false;
233 sni->
free_names &= ~(1 << M(STR_SV_STNAME_OILFIELD) | 1 << M(STR_SV_STNAME_MINES));
239 static const uint32 _gen_station_name_bits[] = {
242 1U << M(STR_SV_STNAME_AIRPORT),
243 1U << M(STR_SV_STNAME_OILFIELD),
244 1U << M(STR_SV_STNAME_DOCKS),
245 1U << M(STR_SV_STNAME_HELIPORT),
252 memset(indtypes, 0,
sizeof(indtypes));
255 FOR_ALL_STATIONS(s) {
256 if (s != st && s->
town == t) {
257 if (s->
indtype != IT_INVALID) {
260 if (name != STR_UNDEFINED) {
271 if (str == M(STR_SV_STNAME_FOREST)) {
272 str = M(STR_SV_STNAME_WOODS);
288 return STR_SV_STNAME_FALLBACK;
296 uint32 tmp = free_names & _gen_station_name_bits[name_class];
300 if (
HasBit(free_names, M(STR_SV_STNAME_MINES))) {
302 return STR_SV_STNAME_MINES;
308 if (
HasBit(free_names, M(STR_SV_STNAME)))
return STR_SV_STNAME;
310 if (
HasBit(free_names, M(STR_SV_STNAME_CENTRAL)))
return STR_SV_STNAME_CENTRAL;
314 if (
HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
317 return STR_SV_STNAME_LAKESIDE;
321 if (
HasBit(free_names, M(STR_SV_STNAME_WOODS)) && (
332 if (
HasBit(free_names, M(STR_SV_STNAME_VALLEY)))
return STR_SV_STNAME_VALLEY;
334 if (
HasBit(free_names, M(STR_SV_STNAME_HEIGHTS)))
return STR_SV_STNAME_HEIGHTS;
338 static const int8 _direction_and_table[] = {
339 ~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
340 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
341 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
342 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ),
345 free_names &= _direction_and_table[
349 tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30));
350 return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME +
FindFirstBit(tmp));
365 FOR_ALL_STATIONS(st) {
369 if (cur_dist < threshold) {
370 threshold = cur_dist;
384 *ta = this->train_station;
387 case STATION_AIRPORT:
392 *ta = this->truck_station;
396 *ta = this->bus_station;
401 ta->
tile = this->dock_tile;
404 default: NOT_REACHED();
418 pt.y -= 32 * ZOOM_LVL_BASE;
423 this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
433 FOR_ALL_BASE_STATIONS(st) {
459 for (uint i = 0; i < num_items; i++) {
484 int x1 =
max(x - rad, 0);
487 int y1 =
max(y - rad, 0);
507 FOR_ALL_INDUSTRIES(i) {
530 if (always_accepted != NULL) *always_accepted = 0;
539 int x1 =
max(x - rad, 0);
540 int y1 =
max(y - rad, 0);
547 for (
int yc = y1; yc != y2; yc++) {
548 for (
int xc = x1; xc != x2; xc++) {
550 AddAcceptedCargo(tile, acceptance, always_accepted);
569 if (!st->
rect.IsEmpty()) {
581 uint amt = acceptance[i];
599 if (old_acc == new_acc)
return;
605 static const StringID accept_msg[] = {
606 STR_NEWS_STATION_NOW_ACCEPTS_CARGO,
607 STR_NEWS_STATION_NOW_ACCEPTS_CARGO_AND_CARGO,
609 static const StringID reject_msg[] = {
610 STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO,
611 STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_OR_CARGO,
625 accepts[num_acc++] = i;
630 rejects[num_rej++] = i;
644 static void UpdateStationSignCoord(
BaseStation *st)
648 if (r->IsEmpty())
return;
682 CommandCost ret = (*st)->rect.BeforeAddRect(area.
tile, area.
w, area.
h, StationRect::ADD_TEST);
683 if (ret.
Failed())
return ret;
692 (*st)->string_id = GenerateStationName(*st, area.
tile, name_class);
715 UpdateStationSignCoord(st);
736 if (ret.
Failed())
return ret;
759 cost.
AddCost(_price[PR_BUILD_FOUNDATION]);
766 }
else if (allowed_z != flat_z) {
786 if (ret.
Failed())
return ret;
790 if (ret.
Failed())
return ret;
811 static CommandCost CheckFlatLandRailStation(
TileArea tile_area,
DoCommandFlag flags,
Axis axis, StationID *station,
RailType rt,
SmallVector<Train *, 4> &affected_vehicles,
StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks)
815 uint invalid_dirs = 5 << axis;
822 if (ret.
Failed())
return ret;
828 if (ret.
Failed())
return ret;
839 if (*station == INVALID_STATION) {
841 }
else if (*station != st) {
866 *affected_vehicles.
Append() = v;
870 if (ret.
Failed())
return ret;
877 if (ret.
Failed())
return ret;
904 if (ret.
Failed())
return ret;
923 if (*station == INVALID_STATION) {
925 }
else if (*station != st) {
949 uint num_roadbits = 0;
950 if (build_over_road) {
958 if (ret.
Failed())
return ret;
972 if (ret.
Failed())
return ret;
981 if (ret.
Failed())
return ret;
985 uint roadbits_to_build =
CountBits(rts) * 2 - num_roadbits;
986 cost.
AddCost(_price[PR_BUILD_ROAD] * roadbits_to_build);
1019 static inline byte *CreateSingle(byte *layout,
int n)
1022 do *layout++ = 0;
while (--i);
1023 layout[((n - 1) >> 1) - n] = 2;
1027 static inline byte *CreateMulti(byte *layout,
int n, byte b)
1030 do *layout++ = b;
while (--i);
1033 layout[n - 1 - n] = 0;
1047 if (statspec != NULL && statspec->lengths >= plat_len &&
1048 statspec->platforms[plat_len - 1] >= numtracks &&
1049 statspec->layouts[plat_len - 1][numtracks - 1]) {
1051 memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
1052 plat_len * numtracks);
1056 if (plat_len == 1) {
1057 CreateSingle(layout, numtracks);
1059 if (numtracks & 1) layout = CreateSingle(layout, plat_len);
1062 while (--numtracks >= 0) {
1063 layout = CreateMulti(layout, plat_len, 4);
1064 layout = CreateMulti(layout, plat_len, 6);
1080 template <
class T, StringID error_message>
1083 assert(*st == NULL);
1084 bool check_surrounding =
true;
1087 if (existing_station != INVALID_STATION) {
1088 if (adjacent && existing_station != station_to_join) {
1095 *st = T::GetIfValid(existing_station);
1096 check_surrounding = (*st == NULL);
1101 if (adjacent) check_surrounding =
false;
1105 if (check_surrounding) {
1108 if (ret.
Failed())
return ret;
1112 if (*st == NULL && station_to_join != INVALID_STATION) *st = T::GetIfValid(station_to_join);
1128 return FindJoiningBaseStation<Station, STR_ERROR_MUST_REMOVE_RAILWAY_STATION_FIRST>(existing_station, station_to_join, adjacent, ta, st);
1142 return FindJoiningBaseStation<Waypoint, STR_ERROR_MUST_REMOVE_RAILWAYPOINT_FIRST>(existing_waypoint, waypoint_to_join, adjacent, ta, wp);
1189 RailType rt = Extract<RailType, 0, 4>(p1);
1190 Axis axis = Extract<Axis, 4, 1>(p1);
1191 byte numtracks =
GB(p1, 8, 8);
1192 byte plat_len =
GB(p1, 16, 8);
1193 bool adjacent =
HasBit(p1, 24);
1196 byte spec_index =
GB(p2, 8, 8);
1197 StationID station_to_join =
GB(p2, 16, 16);
1201 if (ret.
Failed())
return ret;
1208 if (plat_len == 0 || numtracks == 0)
return CMD_ERROR;
1219 bool reuse = (station_to_join != NEW_STATION);
1220 if (!reuse) station_to_join = INVALID_STATION;
1221 bool distant_join = (station_to_join != INVALID_STATION);
1228 TileArea new_location(tile_org, w_org, h_org);
1231 StationID est = INVALID_STATION;
1235 if (cost.
Failed())
return cost;
1237 cost.
AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
1242 if (ret.
Failed())
return ret;
1244 ret =
BuildStationPart(&st, flags, reuse, new_location, STATIONNAMING_RAIL);
1245 if (ret.
Failed())
return ret;
1249 if (ret.
Failed())
return ret;
1257 if (statspec != NULL) {
1272 if (flags & DC_EXEC) {
1275 byte numtracks_orig;
1281 st->
rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
1283 if (statspec != NULL) {
1292 layout_ptr =
AllocaM(byte, numtracks * plat_len);
1295 numtracks_orig = numtracks;
1303 byte layout = *layout_ptr++;
1308 *affected_vehicles.
Append() = v;
1333 if (statspec != NULL) {
1348 TriggerStationAnimation(st, tile,
SAT_BUILT);
1356 }
while (--numtracks);
1358 for (uint i = 0; i < affected_vehicles.
Length(); ++i) {
1366 update_reservation_area =
TileArea(tile_org, 1, numtracks_orig);
1368 update_reservation_area =
TileArea(tile_org, numtracks_orig, 1);
1382 platform_begin = next_tile;
1385 platform_end = next_tile;
1389 bool reservation =
false;
1390 for (
TileIndex t = platform_begin; !reservation && t <= platform_end; t += tile_offset) {
1412 static void MakeRailStationAreaSmaller(
BaseStation *st)
1419 if (ta.
w != 0 && ta.
h != 0) {
1493 if (ret.
Failed())
continue;
1496 T *st = T::GetByTile(tile);
1497 if (st == NULL)
continue;
1502 if (ret.
Failed())
continue;
1511 total_cost.
AddCost(-_price[PR_CLEAR_RAIL]);
1530 DoClearSquare(tile);
1536 st->rect.AfterRemoveTile(st, tile);
1542 affected_stations.
Include(st);
1550 for (T **stp = affected_stations.
Begin(); stp != affected_stations.
End(); stp++) {
1556 MakeRailStationAreaSmaller(st);
1557 UpdateStationSignCoord(st);
1563 st->UpdateVirtCoord();
1568 total_cost.
AddCost(quantity * removal_cost);
1592 if (ret.
Failed())
return ret;
1595 for (
Station **stp = affected_stations.
Begin(); stp != affected_stations.
End(); stp++) {
1644 if (ret.
Failed())
return ret;
1650 assert(ta.
w != 0 && ta.
h != 0);
1656 if (st->TileBelongsToRailStation(tile)) {
1659 if (ret.
Failed())
return ret;
1714 if (*primary_stop == NULL) {
1716 return primary_stop;
1720 while (stop->
next != NULL) stop = stop->
next;
1738 return FindJoiningBaseStation<Station, STR_ERROR_MUST_REMOVE_ROAD_STOP_FIRST>(existing_stop, station_to_join, adjacent, ta, st);
1759 bool type =
HasBit(p2, 0);
1760 bool is_drive_through =
HasBit(p2, 1);
1761 RoadTypes rts = Extract<RoadTypes, 2, 2>(p2);
1762 StationID station_to_join =
GB(p2, 16, 16);
1763 bool reuse = (station_to_join != NEW_STATION);
1764 if (!reuse) station_to_join = INVALID_STATION;
1765 bool distant_join = (station_to_join != INVALID_STATION);
1767 uint8 width = (uint8)
GB(p1, 0, 8);
1768 uint8 lenght = (uint8)
GB(p1, 8, 8);
1773 if (width == 0 || lenght == 0)
return CMD_ERROR;
1777 TileArea roadstop_area(tile, width, lenght);
1788 if (is_drive_through) {
1790 axis = Extract<Axis, 6, 1>(p2);
1794 ddir = Extract<DiagDirection, 6, 2>(p2);
1799 if (ret.
Failed())
return ret;
1803 StationID est = INVALID_STATION;
1804 ret =
CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << axis : 1 << ddir, is_drive_through, type, axis, &est, rts);
1805 if (ret.
Failed())
return ret;
1810 if (ret.
Failed())
return ret;
1815 ret =
BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
1816 if (ret.
Failed())
return ret;
1832 *currstop = road_stop;
1843 st->
rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
1846 if (is_drive_through) {
1913 if (ret.
Failed())
return ret;
1928 assert(cur_stop != NULL);
1936 if (ret.
Failed())
return ret;
1940 if (*primary_stop == cur_stop) {
1942 *primary_stop = cur_stop->
next;
1944 if (*primary_stop == NULL) {
1950 while (pred->
next != cur_stop) pred = pred->
next;
1970 DoClearSquare(tile);
1978 FOR_ALL_ROADVEHICLES(v) {
1985 st->
rect.AfterRemoveTile(st, tile);
2017 uint8 width = (uint8)
GB(p1, 0, 8);
2018 uint8 height = (uint8)
GB(p1, 8, 8);
2019 bool keep_drive_through_roads = !
HasBit(p2, 1);
2022 if (width == 0 || height == 0)
return CMD_ERROR;
2028 TileArea roadstop_area(tile, width, height);
2031 CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
2032 bool had_success =
false;
2078 return had_success ? cost : last_error;
2089 uint mindist = UINT_MAX;
2123 uint noise_reduction = distance / town_tolerance_distance;
2139 Town *t, *nearest = NULL;
2141 uint mindist = UINT_MAX - add;
2147 if (dist < mindist) {
2166 FOR_ALL_STATIONS(st) {
2191 StationID station_to_join =
GB(p2, 16, 16);
2192 bool reuse = (station_to_join != NEW_STATION);
2193 if (!reuse) station_to_join = INVALID_STATION;
2194 bool distant_join = (station_to_join != INVALID_STATION);
2195 byte airport_type =
GB(p1, 0, 8);
2196 byte layout =
GB(p1, 8, 8);
2203 if (ret.
Failed())
return ret;
2220 if (cost.
Failed())
return cost;
2228 StringID authority_refuse_message = STR_NULL;
2229 Town *authority_refuse_town = NULL;
2234 authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE;
2235 authority_refuse_town = nearest;
2241 FOR_ALL_STATIONS(st) {
2245 authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT;
2246 authority_refuse_town = t;
2250 if (authority_refuse_message != STR_NULL) {
2257 if (ret.
Failed())
return ret;
2263 if (ret.
Failed())
return ret;
2270 cost.
AddCost(_price[PR_BUILD_STATION_AIRPORT]);
2283 st->
rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
2295 AirportTileAnimationTrigger(st, iter,
AAT_BUILT);
2330 if (ret.
Failed())
return ret;
2354 if (!st->TileBelongsToAirport(tile_cur))
continue;
2357 if (ret.
Failed())
return ret;
2359 cost.
AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
2361 if (flags & DC_EXEC) {
2364 DoClearSquare(tile_cur);
2369 if (flags & DC_EXEC) {
2419 if (ret.
Failed())
return ret;
2438 if ((v->
owner == company) == include_company) {
2440 FOR_VEHICLE_ORDERS(v, order) {
2456 static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
2457 static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
2470 StationID station_to_join =
GB(p2, 16, 16);
2471 bool reuse = (station_to_join != NEW_STATION);
2472 if (!reuse) station_to_join = INVALID_STATION;
2473 bool distant_join = (station_to_join != INVALID_STATION);
2485 if (ret.
Failed())
return ret;
2490 if (ret.
Failed())
return ret;
2504 if (ret.
Failed())
return ret;
2512 _dock_w_chk[direction], _dock_h_chk[direction]);
2517 if (ret.
Failed())
return ret;
2523 if (ret.
Failed())
return ret;
2531 st->
rect.BeforeAddRect(dock_area.
tile, dock_area.
w, dock_area.
h, StationRect::ADD_TRY);
2564 if (ret.
Failed())
return ret;
2573 if (ret.
Failed())
return ret;
2576 DoClearSquare(tile1);
2578 MakeWaterKeepingClass(tile2, st->
owner);
2580 st->
rect.AfterRemoveTile(st, tile1);
2581 st->
rect.AfterRemoveTile(st, tile2);
2618 return &_station_display_datas[st][gfx];
2634 case SPR_RAIL_TRACK_X:
2635 snow_desert =
false;
2636 *overlay_offset =
RTO_X;
2639 case SPR_RAIL_TRACK_Y:
2640 snow_desert =
false;
2641 *overlay_offset =
RTO_Y;
2644 case SPR_RAIL_TRACK_X_SNOW:
2646 *overlay_offset =
RTO_X;
2649 case SPR_RAIL_TRACK_Y_SNOW:
2651 *overlay_offset =
RTO_Y;
2674 *ground = snow_desert ? SPR_FLAT_SNOW_DESERT_TILE : SPR_FLAT_GRASS_TILE;
2678 static void DrawTile_Station(
TileInfo *ti)
2686 uint32 relocation = 0;
2687 uint32 ground_relocation = 0;
2690 uint tile_layout = 0;
2702 if (statspec != NULL) {
2739 case APT_RADAR_GRASS_FENCE_SW:
2742 case APT_GRASS_FENCE_NE_FLAG:
2745 case APT_RADAR_FENCE_SW:
2748 case APT_RADAR_FENCE_NE:
2751 case APT_GRASS_FENCE_NE_FLAG_2:
2761 palette = COMPANY_SPRITE_COLOUR(owner);
2764 palette = PALETTE_TO_GREY;
2767 if (layout == NULL && (t == NULL || t->
seq == NULL)) t = GetStationTileLayout(
GetStationType(ti->
tile), gfx);
2777 if (!HasFoundationNW(ti->
tile, slope, z))
SetBit(edge_info, 0);
2778 if (!HasFoundationNE(ti->
tile, slope, z))
SetBit(edge_info, 1);
2780 if (image == 0)
goto draw_default_foundation;
2785 static const uint8 foundation_parts[] = {
2798 static const uint8 composite_foundation_parts[] = {
2800 0x00, 0xD1, 0xE4, 0xE0,
2802 0xCA, 0xC9, 0xC4, 0xC0,
2804 0xD2, 0x91, 0xE4, 0xA0,
2809 uint8 parts = composite_foundation_parts[ti->
tileh];
2820 goto draw_default_foundation;
2824 for (
int i = 0; i < 8; i++) {
2835 draw_default_foundation:
2841 DrawWaterClassGround(ti);
2843 if (sprite != 0) total_offset = sprite - SPR_IMG_BUOY;
2846 DrawWaterClassGround(ti);
2852 DrawShoreTile(ti->
tileh);
2854 DrawClearLandTile(ti, 3);
2858 if (layout != NULL) {
2868 t = &tmp_rail_layout;
2870 }
else if (statspec != NULL) {
2922 int32 total_offset = 0;
2937 DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
2950 static int GetSlopePixelZ_Station(
TileIndex tile, uint x, uint y)
2975 td->
owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
2976 td->
owner[i] = road_owner;
2980 td->
owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
2981 td->
owner[i] = tram_owner;
3024 default: NOT_REACHED();
3025 case STATION_RAIL: str = STR_LAI_STATION_DESCRIPTION_RAILROAD_STATION;
break;
3026 case STATION_AIRPORT:
3027 str = (
IsHangar(tile) ? STR_LAI_STATION_DESCRIPTION_AIRCRAFT_HANGAR : STR_LAI_STATION_DESCRIPTION_AIRPORT);
3029 case STATION_TRUCK: str = STR_LAI_STATION_DESCRIPTION_TRUCK_LOADING_AREA;
break;
3030 case STATION_BUS: str = STR_LAI_STATION_DESCRIPTION_BUS_STATION;
break;
3031 case STATION_OILRIG: str = STR_INDUSTRY_NAME_OIL_RIG;
break;
3032 case STATION_DOCK: str = STR_LAI_STATION_DESCRIPTION_SHIP_DOCK;
break;
3033 case STATION_BUOY: str = STR_LAI_STATION_DESCRIPTION_BUOY;
break;
3034 case STATION_WAYPOINT: str = STR_LAI_STATION_DESCRIPTION_WAYPOINT;
break;
3083 static void TileLoop_Station(
TileIndex tile)
3088 case STATION_AIRPORT:
3096 case STATION_OILRIG:
3106 static void AnimateTile_Station(
TileIndex tile)
3109 AnimateStationTile(tile);
3114 AnimateAirportTile(tile);
3119 static bool ClickTile_Station(
TileIndex tile)
3163 }
else if (x < stop) {
3165 uint16 spd =
max(0, (stop - x) * 20 - 15);
3166 if (spd < v->cur_speed) v->
cur_speed = spd;
3195 if (cargoes == 0)
return;
3234 static inline void byte_inc_sat(byte *p)
3251 StationCargoAmountMap waiting_per_source;
3253 for (StationCargoAmountMap::iterator i(waiting_per_source.begin()); i != waiting_per_source.end(); ++i) {
3255 if (source_station == NULL)
continue;
3262 static void UpdateStationRating(
Station *st)
3264 bool waiting_changed =
false;
3266 byte_inc_sat(&st->time_since_load);
3267 byte_inc_sat(&st->time_since_unload);
3270 FOR_ALL_CARGOSPECS(cs) {
3286 waiting_changed =
true;
3305 uint waiting_avg = waiting / (num_dests + 1);
3316 uint32 var10 = (st->last_vehicle_type ==
VEH_INVALID) ? 0x0 : (st->last_vehicle_type + 0x10);
3320 rating =
GB(callback, 0, 14);
3323 if (
HasBit(callback, 14)) rating -= 0x4000;
3329 if (b >= 0) rating += b >> 2;
3332 if (st->last_vehicle_type ==
VEH_SHIP) waittime >>= 2;
3334 (rating += 25, waittime > 12) ||
3335 (rating += 25, waittime > 6) ||
3336 (rating += 45, waittime > 3) ||
3337 (rating += 35,
true);
3344 (rating += 10,
true);
3351 (rating += 10, age >= 2) ||
3352 (rating += 10, age >= 1) ||
3353 (rating += 13,
true);
3363 if (rating <= 64 && waiting_avg >= 100) {
3364 int dec = Random() & 0x1F;
3365 if (waiting_avg < 200) dec &= 7;
3366 waiting -= (dec + 1) * num_dests;
3367 waiting_changed =
true;
3371 if (rating <= 127 && waiting != 0) {
3372 uint32 r = Random();
3373 if (rating <= (
int)
GB(r, 0, 7)) {
3375 waiting =
max((
int)waiting - (
int)((
GB(r, 8, 2) - 1) * num_dests), 0);
3376 waiting_changed =
true;
3383 static const uint WAITING_CARGO_THRESHOLD = 1 << 12;
3384 static const uint WAITING_CARGO_CUT_FACTOR = 1 << 6;
3385 static const uint MAX_WAITING_CARGO = 1 << 15;
3387 if (waiting > WAITING_CARGO_THRESHOLD) {
3388 uint difference = waiting - WAITING_CARGO_THRESHOLD;
3389 waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
3391 waiting =
min(waiting, MAX_WAITING_CARGO);
3392 waiting_changed =
true;
3397 if (waiting_changed && waiting < ge->cargo.AvailableCount()) {
3411 StationID index = st->
index;
3412 if (waiting_changed) {
3435 for (std::list<Vehicle *>::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) {
3436 for (
Vehicle *v = *it; v != NULL; v = v->
Next()) {
3457 if (lg == NULL)
continue;
3460 Edge edge = it->second;
3467 bool updated =
false;
3469 if (auto_distributed) {
3474 FOR_ALL_ORDER_LISTS(l) {
3475 bool found_from =
false;
3476 bool found_to =
false;
3478 if (!order->IsType(OT_GOTO_STATION) && !order->IsType(OT_IMPLICIT))
continue;
3479 if (order->GetDestination() == from->
index) {
3481 if (found_to)
break;
3482 }
else if (order->GetDestination() == to->
index) {
3484 if (found_from)
break;
3487 if (!found_to || !found_from)
continue;
3492 while (iter != vehicles.
End()) {
3503 *iter = next_shared;
3506 vehicles.
Erase(iter);
3509 if (iter == vehicles.
End()) iter = vehicles.
Begin();
3557 DEBUG(misc, 0,
"Can't allocate link graph");
3566 }
else if (ge2.
link_graph == INVALID_LINK_GRAPH) {
3585 (*lg)[ge1.
node].UpdateEdge(ge2.
node, capacity, usage, mode);
3597 for (
const Vehicle *v = front; v != NULL; v = v->
Next()) {
3612 static void StationHandleSmallTick(
BaseStation *st)
3623 void OnTick_Station()
3625 if (_game_mode == GM_EDITOR)
return;
3628 FOR_ALL_BASE_STATIONS(st) {
3629 StationHandleSmallTick(st);
3653 FOR_ALL_STATIONS(st) {
3663 void ModifyStationRatingAround(
TileIndex tile,
Owner owner,
int amount, uint radius)
3667 FOR_ALL_STATIONS(st) {
3668 if (st->
owner == owner &&
3693 if (amount == 0)
return 0;
3705 DEBUG(misc, 0,
"Can't allocate link graph");
3710 if (lg != NULL) (*lg)[ge.
node].UpdateSupply(amount);
3726 static bool IsUniqueStationName(
const char *name)
3730 FOR_ALL_STATIONS(st) {
3731 if (st->
name != NULL && strcmp(st->
name, name) == 0)
return false;
3752 if (ret.
Failed())
return ret;
3758 if (!IsUniqueStationName(text))
return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
3786 uint min_x = (x > max_rad) ? x - max_rad : 0;
3787 uint max_x = x + location.
w + max_rad;
3788 uint min_y = (y > max_rad) ? y - max_rad : 0;
3789 uint max_y = y + location.
h + max_rad;
3796 for (uint cy = min_y; cy < max_y; cy++) {
3797 for (uint cx = min_x; cx < max_x; cx++) {
3803 if (st == NULL)
continue;
3810 if (rad_x < -rad || rad_x >= rad + location.
w)
continue;
3811 if (rad_y < -rad || rad_y >= rad + location.
h)
continue;
3832 return &this->stations;
3838 if (amount == 0)
return 0;
3842 uint best_rating1 = 0;
3843 uint best_rating2 = 0;
3845 for (
Station *
const *st_iter = all_stations->
Begin(); st_iter != all_stations->
End(); ++st_iter) {
3862 if (st1 == NULL || st->
goods[type].
rating >= best_rating1) {
3863 st2 = st1; best_rating2 = best_rating1; st1 = st; best_rating1 = st->
goods[type].
rating;
3864 }
else if (st2 == NULL || st->
goods[type].
rating >= best_rating2) {
3870 if (st1 == NULL)
return 0;
3874 amount *= best_rating1 + 1;
3878 return UpdateStationWaiting(st1, type, amount, source_type, source_id);
3882 assert(st1 != NULL);
3883 assert(st2 != NULL);
3884 assert(best_rating1 != 0 || best_rating2 != 0);
3891 uint worst_cargo = amount * best_rating2 / (best_rating1 + best_rating2);
3892 assert(worst_cargo <= (amount - worst_cargo));
3895 uint moved = UpdateStationWaiting(st1, type, amount - worst_cargo, source_type, source_id);
3898 return moved + UpdateStationWaiting(st2, type, worst_cargo, source_type, source_id);
3904 DEBUG(misc, 0,
"Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
3911 st->
string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
3924 st->
rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
3942 st->
rect.AfterRemoveTile(st, tile);
3946 if (!st->
IsInUse())
delete st;
3978 case STATION_WAYPOINT:
4070 case STATION_WAYPOINT:
return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
4071 case STATION_AIRPORT:
return_cmd_error(STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST);
4076 case STATION_OILRIG:
4077 SetDParam(1, STR_INDUSTRY_NAME_OIL_RIG);
4096 case STATION_BUOY:
return RemoveBuoy(tile, flags);
4097 case STATION_DOCK:
return RemoveDock(tile, flags);
4112 case STATION_WAYPOINT:
4113 case STATION_RAIL: {
4120 case STATION_AIRPORT:
4148 for (SharesMap::const_iterator it = this->shares.begin(); it != this->shares.end(); ++it) {
4149 if (it->second == st) {
4150 return it->first - prev;
4166 if (this->unrestricted == 0)
return INVALID_STATION;
4167 assert(!this->shares.empty());
4168 SharesMap::const_iterator it = this->shares.upper_bound(
RandomRange(this->unrestricted));
4169 assert(it != this->shares.end() && it->first <= this->unrestricted);
4170 if (it->second != excluded && it->second != excluded2)
return it->second;
4175 uint end = it->first;
4176 uint begin = (it == this->shares.begin() ? 0 : (--it)->first);
4177 uint interval = end - begin;
4178 if (interval >= this->unrestricted)
return INVALID_STATION;
4179 uint new_max = this->unrestricted - interval;
4181 SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) :
4182 this->shares.upper_bound(rand + interval);
4183 assert(it2 != this->shares.end() && it2->first <= this->unrestricted);
4184 if (it2->second != excluded && it2->second != excluded2)
return it2->second;
4189 uint end2 = it2->first;
4190 uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first);
4191 uint interval2 = end2 - begin2;
4192 if (interval2 >= new_max)
return INVALID_STATION;
4193 new_max -= interval2;
4194 if (begin > begin2) {
4195 Swap(begin, begin2);
4197 Swap(interval, interval2);
4200 SharesMap::const_iterator it3 = this->shares.upper_bound(this->unrestricted);
4202 it3 = this->shares.upper_bound(rand);
4203 }
else if (rand < begin2 - interval) {
4204 it3 = this->shares.upper_bound(rand + interval);
4206 it3 = this->shares.upper_bound(rand + interval + interval2);
4208 assert(it3 != this->shares.end() && it3->first <= this->unrestricted);
4219 assert(!this->shares.empty());
4220 SharesMap new_shares;
4222 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4223 new_shares[++i] = it->second;
4224 if (it->first == this->unrestricted) this->unrestricted = i;
4226 this->shares.swap(new_shares);
4227 assert(!this->shares.empty() && this->unrestricted <= (--this->shares.end())->first);
4240 assert(!this->shares.empty());
4242 uint removed_shares = 0;
4243 uint added_shares = 0;
4244 uint last_share = 0;
4245 SharesMap new_shares;
4246 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4247 if (it->second == st) {
4249 uint share = it->first - last_share;
4250 if (flow == INT_MIN || (uint)(-flow) >= share) {
4251 removed_shares += share;
4252 if (it->first <= this->unrestricted) this->unrestricted -= share;
4253 if (flow != INT_MIN) flow += share;
4254 last_share = it->first;
4257 removed_shares += (uint)(-flow);
4259 added_shares += (uint)(flow);
4261 if (it->first <= this->unrestricted) this->unrestricted += flow;
4267 new_shares[it->first + added_shares - removed_shares] = it->second;
4268 last_share = it->first;
4271 new_shares[last_share + (uint)flow] = st;
4272 if (this->unrestricted < last_share) {
4273 this->ReleaseShare(st);
4275 this->unrestricted += flow;
4278 this->shares.swap(new_shares);
4288 assert(!this->shares.empty());
4290 uint last_share = 0;
4291 SharesMap new_shares;
4292 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4294 if (it->first > this->unrestricted)
return;
4295 if (it->second == st) {
4296 flow = it->first - last_share;
4297 this->unrestricted -= flow;
4299 new_shares[it->first] = it->second;
4302 new_shares[it->first - flow] = it->second;
4304 last_share = it->first;
4306 if (flow == 0)
return;
4307 new_shares[last_share + flow] = st;
4308 this->shares.swap(new_shares);
4309 assert(!this->shares.empty());
4319 assert(!this->shares.empty());
4321 uint next_share = 0;
4323 for (SharesMap::reverse_iterator it(this->shares.rbegin()); it != this->shares.rend(); ++it) {
4324 if (it->first < this->unrestricted)
return;
4326 flow = next_share - it->first;
4327 this->unrestricted += flow;
4330 if (it->first == this->unrestricted)
return;
4331 if (it->second == st) found =
true;
4333 next_share = it->first;
4335 if (flow == 0)
return;
4336 SharesMap new_shares;
4337 new_shares[flow] = st;
4338 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4339 if (it->second != st) {
4340 new_shares[flow + it->first] = it->second;
4345 this->shares.swap(new_shares);
4346 assert(!this->shares.empty());
4356 assert(runtime > 0);
4357 SharesMap new_shares;
4359 for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
4360 share =
max(share + 1, i->first * 30 / runtime);
4361 new_shares[share] = i->second;
4362 if (this->unrestricted == i->first) this->unrestricted = share;
4364 this->shares.swap(new_shares);
4375 FlowStatMap::iterator origin_it = this->find(origin);
4376 if (origin_it == this->end()) {
4377 this->insert(std::make_pair(origin,
FlowStat(via, flow)));
4379 origin_it->second.ChangeShare(via, flow);
4380 assert(!origin_it->second.GetShares()->empty());
4394 FlowStatMap::iterator prev_it = this->find(origin);
4395 if (prev_it == this->end()) {
4398 this->insert(std::make_pair(origin, fs));
4400 prev_it->second.ChangeShare(via, flow);
4401 prev_it->second.ChangeShare(INVALID_STATION, flow);
4402 assert(!prev_it->second.GetShares()->empty());
4412 for (FlowStatMap::iterator i = this->begin(); i != this->end(); ++i) {
4414 uint local = fs.
GetShare(INVALID_STATION);
4415 if (local > INT_MAX) {
4438 for (FlowStatMap::iterator f_it = this->begin(); f_it != this->end();) {
4442 ret.
Push(f_it->first);
4443 this->erase(f_it++);
4457 for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) {
4458 it->second.RestrictShare(via);
4468 for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) {
4469 it->second.ReleaseShare(via);
4480 for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
4481 ret += (--(i->second.GetShares()->end()))->first;
4494 for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
4495 ret += i->second.GetShare(via);
4507 FlowStatMap::const_iterator i = this->find(from);
4508 if (i == this->end())
return 0;
4509 return (--(i->second.GetShares()->end()))->first;
4520 FlowStatMap::const_iterator i = this->find(from);
4521 if (i == this->end())
return 0;
4522 return i->second.GetShare(via);
4527 GetSlopePixelZ_Station,
4530 GetTileDesc_Station,
4531 GetTileTrackStatus_Station,
4533 AnimateTile_Station,
4535 ChangeTileOwner_Station,
4537 VehicleEnter_Station,
4538 GetFoundation_Station,
4539 TerraformTile_Station,
Functions related to OTTD's strings.
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type)
Trigger station randomisation.
don't allow building on structures
static void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail station tile.
EdgeIterator Begin()
Get an iterator pointing to the start of the edges array.
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Functions/types related to NewGRF debugging.
static void Swap(T &a, T &b)
Type safe swap operation.
byte type
Type of this airport,.
uint32 PaletteID
The number of the palette.
static void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
Make the given tile a dock tile.
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
VehicleCargoList cargo
The cargo this vehicle is carrying.
static uint MapSizeX()
Get the size of the map along the X.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge=true)
Checks if the given tile is buildable, flat and has a certain height.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
void ShowWaypointWindow(const Waypoint *wp)
Show the window for the given waypoint.
Use callback to select a sprite layout to use.
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
bool enabled
entity still available (by default true).newgrf can disable it, though
bool IsAvailable() const
Check whether this airport is available to build.
static bool FindNearIndustryName(TileIndex tile, void *user_data)
Find a station action 0 property 24 station name, or reduce the free_names if needed.
NewGRF handling of rail types.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Select station (when joining stations); Window numbers:
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
A standard stop for trucks.
static const uint COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
static uint MapSizeY()
Get the size of the map along the Y.
static bool IsCustomStationSpecIndex(TileIndex t)
Is there a custom rail station spec on this tile?
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Tile information, used while rendering the tile.
TileArea bus_station
Tile area the bus 'station' part covers.
CompanyMask statues
which companies have a statue?
Definition of link refreshing utility.
StationID targetairport
Airport to go to next.
CommandCost GetStationAround(TileArea ta, StationID closest_station, T **st)
Look for a station around the given tile area.
Minimal stack that uses a pool to avoid pointers.
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Some typedefs for the main game.
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check)
Is it allowed to remove the given road bits from the given tile?
const AirportFTAClass * GetAirport(const byte airport_type)
Get the finite state machine of an airport type.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
byte landscape
the landscape we're currently in
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted...
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet)...
DirectionByte direction
facing
byte size_y
size of airport in y direction
Iterator to iterate over all tiles belonging to an airport.
company buildings - depots, stations, HQ, ...
RailType
Enumeration for all possible railtypes.
Base class for roadstops.
Non-existing type of vehicle.
static bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
void Queue(LinkGraph *lg)
Queue a link graph for execution.
Date LastUnrestrictedUpdate() const
Get the date of the last update to the edge's unrestricted capacity.
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
uint16 triggers
The triggers that trigger animation.
virtual void UpdateVirtCoord()=0
Update the coordinated of the sign (as shown in the viewport).
uint GetNumHangars() const
Get the number of hangars on this airport.
static bool IsRailStation(TileIndex t)
Is this station tile a rail station?
EconomySettings economy
settings to change the economy
static RoadBits GetAllRoadBits(TileIndex tile)
Get all set RoadBits on the given tile.
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Flag for an invalid DiagDirection.
int32 TileIndexDiff
An offset value between to tiles.
static bool IsWater(TileIndex t)
Is it a plain water tile?
virtual TileIterator * Clone() const =0
Allocate a new iterator that is a copy of this one.
static Titem * Get(size_t index)
Returns Titem with given index.
static Station * GetClosestDeletedStation(TileIndex tile)
Find the closest deleted station of the current company.
static RoadStop ** FindRoadStopSpot(bool truck_station, Station *st)
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
const char * grf
newGRF used for the tile contents
uint GetSpecCount() const
Get the number of allocated specs within the class.
CompanyByte exclusivity
which company has exclusivity
static const AirportTileSpec * GetByTile(TileIndex tile)
Retrieve airport tile spec for the given airport tile.
static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
Remove an airport.
Base for the train class.
The vehicle is in a drive-through road stop.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrackOffset *overlay_offset)
Check whether a sprite is a track sprite, which can be replaced by a non-track ground sprite and a ra...
Track
These are used to specify a single track.
Can planes land on this airport type?
uint16 cur_speed
current speed
A tile with road (or tram tracks)
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
bool distant_join_stations
allow to join non-adjacent stations
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Depot view; Window numbers:
Slope tileh
Slope of the tile.
Full road along the x-axis (south-west + north-east)
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval...
Functions used internally by the roads.
Specification of a cargo type.
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
Lookup the base sprite to use for a canal.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
TileIndex dock_tile
The location of the dock.
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
TileIndex dest_tile
Heading for this tile.
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
void MakeDriveThrough()
Join this road stop to another 'base' road stop if possible; fill all necessary data to become an act...
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
Functions related to vehicles.
Aircraft, helicopters, rotors and their shadows belong to this class.
Set when cargo was delivered for final delivery this month.
Manual distribution. No link graph calculations are run.
static const uint INVALID_AIRPORTTILE
id for an invalid airport tile
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
static DiagDirection GetDockDirection(TileIndex t)
Get the direction of a dock.
static uint TileX(TileIndex tile)
Get the X component of a tile.
A standard stop for buses.
TileArea train_station
Tile area the train 'station' part covers.
static bool CMSATree(TileIndex tile)
Check whether the tile is a tree.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
Make the given tile an oilrig tile.
byte station_spread
amount a station may spread
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
static bool HasTileRoadType(TileIndex t, RoadType rt)
Check if a tile has a specific road type.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Iterator to iterate over all tiles belonging to an airport spec.
uint GetFlowVia(StationID via) const
Get the sum of flows via a specific station from this FlowStatMap.
Defines the internal data of a functional industry.
const T * Begin() const
Get the pointer to the first item (const)
Tile description for the 'land area information' tool.
void LeaveStation()
Perform all actions when leaving a station.
DifficultySettings difficulty
settings related to the difficulty
Stores station stats for a single cargo.
Tindex index
Index of this pool item.
Vehicle is flying in the air.
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
#define FOR_EACH_SET_ROADTYPE(var, road_types)
Iterate through each set RoadType in a RoadTypes value.
static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
Remove a dock.
static StationGfx GetAirportGfx(TileIndex t)
Get the station graphics of this airport tile.
Northeast, upper right on your monitor.
void ReleaseFlows(StationID via)
Release all flows at a station for specific cargo and destination.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
T * First() const
Get the first vehicle in the chain.
static void FreeTrainReservation(Train *v)
Clear platform reservation during station building/removing.
Helper functions to extract data from command parameters.
void PassOnFlow(StationID origin, StationID via, uint amount)
Pass on some flow, remembering it as invalid, for later subtraction from locally consumed flow...
const DrawTileSeqStruct * GetLayout(PalSpriteID *ground) const
Returns the result spritelayout after preprocessing.
static CommandCost FindJoiningRoadStop(StationID existing_stop, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
Find a nearby station that joins this road stop.
void FinalizeLocalConsumption(StationID self)
Subtract invalid flows from locally consumed flow.
Representation of a waypoint.
Simple vector template class.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
CommandCost FindJoiningBaseStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, T **st)
Find a nearby station that joins this station.
uint32 station
Count of company owned station tiles.
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Common return value for all commands.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
RoadType
The different roadtypes we support.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 classes
Classes of this cargo type.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Town * town
The town this station is associated with.
bool HasRating() const
Does this cargo have a rating at this station?
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
uint8 status
Status; 0: no looping, 1: looping, 0xFF: no animation.
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
uint GetFlowFrom(StationID from) const
Get the sum of flows from a specific station from this FlowStatMap.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
uint tiles
Number of tile layouts.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
uint16 w
The width of the area.
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
void Clear()
Clears the 'tile area', i.e.
Determine whether a newstation should be made available to build.
The vehicle entered a station.
static Slope GetFoundationPixelSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTilePixelSlope.
const T * End() const
Get the pointer behind the last valid item (const)
uint16 noise_reached
level of noise that all the airports are generating
uint16 rail_speed
Speed limit of rail (bridges and track)
byte nof_depots
the number of hangar tiles in this airport
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
StationSettings station
settings related to station management
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static const uint TILE_SIZE
Tile size in world coordinates.
static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
Remove a rail waypoint.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
RoadStopType
Types of RoadStops.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
Direction
Defines the 8 directions on the map.
void UpdateStationAcceptance(Station *st, bool show_msg)
Update the acceptance for a station.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
const AirportTileTable *const * table
list of the tiles composing the airport
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a bus or truck stop.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
This struct contains all the info that is needed to draw and construct tracks.
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
T * Append(uint to_add=1)
Append an item and return it.
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Order * next
Pointer to next order. If NULL, end of list.
bool selectgoods
only send the goods to station if a train has been there
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
company bankrupts, skip money check, skip vehicle on tile check in some cases
Functions related to (drawing on) viewports.
Pseudo random number generator.
uint32 always_accepted
Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept c...
void TriggerWatchedCargoCallbacks(Station *st)
Run the watched cargo callback for all houses in the catchment area.
A connected component of a link graph.
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length)
Get the stop location of (the center) of the front vehicle of a train at a platform of a station...
bool freeform_edges
allow terraforming the tiles at the map edges
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
Set when cargo was delivered for final delivery last month.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
SpriteID single_y
single piece of rail in Y direction, without ground
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
void ScaleToMonthly(uint runtime)
Scale all shares from link graph's runtime to monthly values.
Triggered in the periodic tile loop.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
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...
static bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
TrackBits
Bitfield corresponding to Track.
Buses, trucks and trams belong to this class.
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...
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
static void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Maximal number of airports in total.
byte noise_level
noise that this airport generates
uint GetShare(StationID st) const
Get flow for a station.
static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
Check if a drive-through road stop tile can be cleared.
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
Functions related to low-level strings.
byte amount_fract
Fractional part of the amount in the cargo list.
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
uint x
X position of the tile in unit coordinates.
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
Resolve sprites for drawing a station tile.
uint Size() const
Get the current size of the component.
byte rating
Station rating for this cargo.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
EdgeIterator End()
Get an iterator pointing beyond the end of the edges array.
Foundation
Enumeration for Foundations.
TileIndex xy
town center tile
static void SetStationTileRandomBits(TileIndex t, byte random_bits)
Set the random bits for a station tile.
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Triggered when the airport is built (for all tiles at the same time).
CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector< T *, 4 > &affected_stations, DoCommandFlag flags, Money removal_cost, bool keep_rail)
Remove a number of tiles from any rail station within the area.
static void MakeAirport(TileIndex t, Owner o, StationID sid, byte section, WaterClass wc)
Make the given tile an airport tile.
void UpdateVirtCoord()
Update the virtual coords needed to draw the station sign.
TileIndex tile
Tile index.
AirportClassID cls_id
the class to which this airport type belongs
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Track along the y-axis (north-west to south-east)
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
uint32 PrepareLayout(uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, uint constr_stage, bool separate_ground) const
Prepares a sprite layout before resolving action-1-2-3 chains.
RoadStop * truck_stops
All the truck stops.
This indicates whether a cargo has a rating at the station.
uint Length() const
Get the number of items in the list.
StationID GetVia(StationID source) const
Get the best next hop for a cargo packet from station source.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
Counts the numbers of tiles matching a specific type in the area around.
static Owner GetRoadOwner(TileIndex t, RoadType rt)
Get the owner of a specific road type.
StringID owner_type[4]
Type of each owner.
void ClearDriveThrough()
Prepare for removal of this stop; update other neighbouring stops if needed.
The tile is leveled up to a flat slope.
LinkGraphID link_graph
Link graph this station belongs to.
Information about GRF, used in the game and (part of it) in savegames.
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Ground palette sprite of a tile, together with its sprite layout.
#define FIND_FIRST_BIT(x)
Returns the first non-zero bit in a 6-bit value (from right).
bool road_stop_on_competitor_road
allow building of drive-through road stops on roads owned by competitors
static void SetStationGfx(TileIndex t, StationGfx gfx)
Set the station graphics of this tile.
static void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
Set the owner of a specific road type.
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove bus or truck stops.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Images for overlaying track.
static bool StationHandleBigTick(BaseStation *st)
This function is called for each station once every 250 ticks.
static bool IsTruckStop(TileIndex t)
Is the station at t a truck stop?
const Direction * rotation
the rotation of each tiletable
static void TruncateCargo(const CargoSpec *cs, GoodsEntry *ge, uint amount=UINT_MAX)
Truncate the cargo by a specific amount.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
StationID GetVia() const
Get a station a package can be routed to.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts)
Finds out, whether given company has all given RoadTypes available.
Entry point for OpenTTD to YAPF's cache.
bool IsType(OrderType type) const
Check whether this order is of the given type.
TileArea truck_station
Tile area the truck 'station' part covers.
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
Functions related to NewGRF houses.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
bool Intersects(const OrthogonalTileArea &ta) const
Does this tile area intersect with another?
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Station with truck stops.
ClientSettings _settings_client
The current settings for this game.
byte status
Status of this cargo, see GoodsEntryStatus.
Piece of rail in X direction.
bool Succeeded() const
Did this command succeed?
Container for cargo from the same location and time.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, EdgeUpdateMode mode)
Increase capacity for a link stat given by station cargo and next hop.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
byte layout
Airport layout number.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
static const Date INVALID_DATE
Representation of an invalid date.
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, uint32 *always_accepted)
Get the acceptance of cargoes around the tile in 1/8.
Shift the VehicleEnterTileStatus this many bits to the right to get the station ID when VETS_ENTERED_...
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
A number of safeguards to prevent using unsafe methods.
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
Trigger station every 250 ticks.
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
static const uint64 AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
IndustryType type
type of industry.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
Remove a bus station/truck stop.
The vehicle cannot enter the tile.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
uint y
Y position of the tile in unit coordinates.
struct RoadStop * next
Next stop of the given type at this station.
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Liquids (Oil, Water, Rubber)
uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIterator &it, TileIndex town_tile)
Get a possible noise reduction factor based on distance from town center.
RoadBits
Enumeration for the road parts on a tile.
uint8 callback_mask
Bitmask of cargo callbacks that have to be called.
Trackdir
Enumeration for tracks and directions.
void ProcessRegisters(uint8 resolved_var10, uint32 resolved_sprite, bool separate_ground) const
Evaluates the register modifiers and integrates them into the preprocessed sprite layout...
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
TileArea location
Location of the industry.
byte num_table
number of elements in the table
NodeID node
ID of node in link graph referring to this goods entry.
void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
static bool CMSAMine(TileIndex tile)
Check whether the tile is a mine.
CommandCost CheckFlatLand(TileArea tile_area, DoCommandFlag flags)
Tries to clear the given area.
bool IsHangar(TileIndex t)
Check whether the given tile is a hangar.
CargoID cargo_type
type of cargo this vehicle is carrying
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Represents the covered area of e.g.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
GUI Functions related to companies.
static bool IsAirport(TileIndex t)
Is this station tile an airport?
CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
Remove a rail station/waypoint.
StringID name
Tile Subname string, land information on this tile will give you "AirportName (TileSubname)".
Functions related to order backups.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
bool road_stop_on_town_road
allow building of drive-through road stops on town owned roads
Trigger station on new cargo arrival.
void RecomputeIndustriesNear()
Recomputes Station::industries_near, list of industries possibly accepting cargo in station's catchme...
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Order * GetFirstOrder() const
Get the first order of the order chain.
Map accessor functions for bridges.
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Set when a sprite originates from an Action 1.
TileIndex tile
Current tile index.
Defines the data structure for constructing industry.
StationSpecList * speclist
List of station specs of this station.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
void Push(const Titem &item)
Pushes a new item onto the stack if there is still space in the underlying pool.
static uint GetMinimalAirportDistanceToTile(TileIterator &it, TileIndex town_tile)
Computes the minimal distance from town's xy to any airport's tile.
Base class for tile iterators.
static const int STATION_RATING_TICKS
cycle duration for updating station rating
The tile has no ownership.
static const AirportSpec * Get(byte type)
Retrieve airport spec for the given airport.
PersistentStorage * psa
Persistent storage for NewGRF airports.
CargoID produced_cargo[2]
2 production cargo slots
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
Station view; Window numbers:
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a dock/haven.
Date LastRestrictedUpdate() const
Get the date of the last update to the edge's restricted capacity.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map...
Bit value for coloured news.
SpriteID single_x
single piece of rail in X direction, without ground
Called when building a station to customize the tile layout.
static const uint8 ANIM_STATUS_NO_ANIMATION
There is no animation.
void RestrictShare(StationID st)
Restrict a flow by moving it to the end of the map and decreasing the amount of unrestricted flow...
StationFacilityByte facilities
The facilities that this station has.
void AddFlow(StationID origin, StationID via, uint amount)
Add some flow from "origin", going via "via".
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a station.
static const SharesMap empty_sharesmap
Static instance of FlowStat::SharesMap.
DiagDirection
Enumeration for diagonal directions.
Catchment for all stations with "modified catchment" disabled.
#define lengthof(x)
Return the length of an fixed size array.
byte last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
uint8 cached_anim_triggers
NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen...
static T min(const T a, const T b)
Returns the minimum of two values.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
static void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
StringID railtype
Type of rail on the tile.
StringID airport_tile_name
Name of the airport tile.
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Piece of rail in Y direction.
uint16 refit_cap
Capacity left over from before last refit.
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Functions related to autoslope.
NewGRF supplied spritelayout.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
bool build_on_slopes
allow building on slopes
Date LastCompression() const
Get date of last compression.
bool Failed() const
Did this command fail?
StringID station_name
Type of station within the class.
byte last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
static StationGfx GetStationGfx(TileIndex t)
Get the station graphics of this tile.
DirectionByte rotation
How this airport is rotated.
All ships have this type.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Date LastUpdate() const
Get the date of the last update to any part of the edge's capacity.
RoadStop * bus_stops
All the road stops.
uint16 MaxTownNoise() const
Calculate the max town noise.
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.
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
NewGRF handling of airport tiles.
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
byte state
State of the airport.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=NULL)
Truncates where each destination loses roughly the same percentage of its cargo.
#define FOR_ALL_SHIPS(var)
Iterate over all ships.
void DrawRoadCatenary(const TileInfo *ti, RoadBits tram)
Draws the catenary for the given tile.
Station list; Window numbers:
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
FlowStatMap flows
Planned flows through this station.
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges. ...
CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
bool Enter(RoadVehicle *rv)
Enter the road stop.
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
#define DEBUG(name, level,...)
Output a line of debugging information.
'Train' is either a loco or a wagon.
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
SourceType
Types of cargo source and destination.
void ChangeShare(StationID st, int flow)
Change share for specified station.
Maximal number of cargo types in a game.
Functions related to clear (MP_CLEAR) land.
EdgeUpdateMode
Special modes for updating links.
TileIndex tile
The base tile of the area.
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size...
OwnerByte owner
The owner of this station.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
A pair-construct of a TileIndexDiff.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
bool(* CMSAMatcher)(TileIndex tile)
Function to check whether the given tile matches some criterion.
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
void ReleaseShare(StationID st)
Release ("unrestrict") a flow by moving it to the begin of the map and increasing the amount of unres...
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Handling of NewGRF canals.
byte StationGfx
Copy from station_map.h.
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
execute the given command
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
PalSpriteID ground
Palette and sprite for the ground.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reuse, TileArea area, StationNaming name_class)
Common part of building various station parts and possibly attaching them to an existing one...
static uint MapSize()
Get the size of the map.
StationType
Station types.
this bit is set when a recolouring process is in action
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Class for storing amounts of cargo.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
static bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Header file for NewGRF stations.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Open/close an airport to incoming aircraft.
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
Check the slope of a tile of a new station.
GUISettings gui
settings related to the GUI
DestinationID GetDestination() const
Gets the destination of this order.
Only bits 0 and 3 are used to encode the trackdir for road stops.
static Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
bool station_noise_level
build new airports when the town noise level is still within accepted limits
uint max_waiting_cargo
Max cargo from this station waiting at any station.
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(), or whether it can be used directly.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void StationMonthlyLoop()
Monthly loop for stations.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
CompanyByte _current_company
Company currently doing an action.
Set of callback functions for performing tile operations of a given tile type.
T * Last()
Get the last vehicle in the chain.
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Use different sprite set for ground sprites.
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
Evaluate a tile's position within a station, and return the result in a bit-stuffed format...
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Cargo support for NewGRFs.
Town * AirportGetNearestTown(const AirportSpec *as, const TileIterator &it)
Finds the town nearest to given airport.
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
void Invalidate()
Reduce all flows to minimum capacity so that they don't get in the way of link usage statistics too m...
A town owns the tile, or a town is expanding.
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
Items contains the two cargo names that are to be accepted or rejected.
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, void *free_data=NULL)
Add a new newsitem to be shown.
Vehicle * Next() const
Get the next vehicle of this vehicle.
StringID name
name of this airport
Extended foundation block instead of simple.
bool modified_catchment
different-size catchment areas
Trigger station on new cargo arrival.
byte fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations...
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
OrderSettings order
settings related to orders
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
AnimationInfo animation
Information about the animation.
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Sprites to use and how to display them for station tiles.
void Free()
'Free' the order
Bit sets of the above specified bits.
byte town_council_tolerance
minimum required town ratings to be allowed to demolish stuff
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
OwnerByte owner
Which company owns the vehicle?
void GetTileArea(TileArea *ta, StationType type) const
Get the tile area for a given station type.
Availability of station in construction window.
byte size_x
size of airport in x direction
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
TileIndex xy
Base tile of the station.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
StringID airport_name
Name of the airport.
A type of cargo is (no longer) accepted.
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
Slope
Enumeration for the slope-type.
Town view; Window numbers:
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
static void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
Make the given tile a roadstop tile.
bool Include(const T &item)
Tests whether a item is present in the vector, and appends it to the end if not.
void Erase(T *item)
Removes given item from this vector.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
bool show_track_reservation
highlight reserved tracks.
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Main group of ground images.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
uint8 exclusive_counter
months till the exclusivity expires
Station with train station.
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Transport by road vehicle.
Flow statistics telling how much flow should be sent along a link.
static const int STATION_LINKGRAPH_TICKS
cycle duration for cleaning dead links
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
The vehicle is in a road stop.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
static uint CountBits(T value)
Counts the number of set bits in a variable.
Defines the data structure of each individual tile of an airport.
Functions related to commands.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single tile from a rail station.
Coordinates of a point in 2D.
remove a single rail track
A Stop for a Road Vehicle.
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
CargoID Index() const
Determines index of this cargospec.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircrafts.
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Date build_date
Date of construction of tile contents.
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
uint GetFlowFromVia(StationID from, StationID via) const
Get the flow from a specific station via a specific other station.
header file for electrified rail specific functions
Triggered every 250 ticks (for all tiles at the same time).
static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, SmallVector< Train *, 4 > &affected_vehicles, StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks)
Checks if a rail station can be built at the given area.
static void DeleteStationIfEmpty(BaseStation *st)
This is called right after a station was deleted.
bool adjacent_stations
allow stations to be built directly adjacent to other stations
static void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram)
Make a normal road tile.
ConstructionSettings construction
construction of things in-game
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
const char * GetName() const
Get the name of this grf.
static RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
Functions related to waypoints.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Airport airport
Tile area the airport covers.
static bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
Autoslope check for tiles with an entrance on an edge.
StringID name
Name of this rail type.
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Place an Airport.
RailTrackOffset
Offsets for sprites within an overlay/underlay set.
static TileIndexDiffC GetDockOffset(TileIndex t)
Get the tileoffset from this tile a ship should target to get to this dock.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
const struct GRFFile * grffile
grf file that introduced this entity
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
StringID str
Description of the tile.
StringID station_name
Default name for nearby station.
static bool IsHangarTile(TileIndex t)
Is tile t an hangar tile?
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
remove a (rectangle of) tiles from a rail station
void DeleteStaleLinks(Station *from)
Check all next hops of cargo packets in this station for existance of a a valid link they may use to ...
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
StringID station_class
Class of station.
byte callback_mask
Bitmask of station callbacks that have to be called.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
byte disallowed_lengths
Bitmask of platform lengths available for the station.
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail station.
Choose a sprite layout to draw, instead of the standard 0-7 range.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const uint NEW_AIRPORTTILE_OFFSET
offset of first newgrf airport tile
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
void UpdateAirplanesOnNewStation(const Station *st)
Updates the status of the Aircraft heading or in the station.
Specification of a rectangle with absolute coordinates of all edges.
Full road along the y-axis (north-west + south-east)
byte CargoID
Cargo slots to indicate a cargo type within a game.
IndustryType indtype
Industry type to get the name from.
Flag for invalid railtype.
Enum of the default airport tiles.
Check slope of new station tiles.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
NewGRFSpriteLayout * renderdata
Array of tile layouts.
Small news item. (Information window with text and viewport)
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Owner
Enum for all companies/owners.
byte time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
StringID name
Name of this station.
Maximum catchment for airports with "modified catchment" enabled.
Defines the data structure for an airport.
Track along the x-axis (north-east to south-west)
Functions related to water (management)
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
static bool CMSAWater(TileIndex tile)
Check whether the tile is water.
An iterator for non-const edges.
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
#define TILE_ADD(x, y)
Adds to tiles together.
StationGfx GetTranslatedAirportTileID(StationGfx gfx)
Do airporttile gfx ID translation for NewGRFs.
static void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a)
Make the given tile a drivethrough roadstop tile.
SpriteID sprite
The 'real' sprite.
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single tile from a waypoint.
byte disallowed_platforms
Bitmask of number of platforms available for the station.
StringID airport_class
Name of the airport class.
Functions related to news.
void FindStationsAroundTiles(const TileArea &location, StationList *stations)
Find all stations around a rectangular producer (industry, house, headquarter, ...)
uint GetFlow() const
Get the sum of all flows from this FlowStatMap.
StationClassID cls_id
The class to which this spec belongs.
Base classes/functions for stations.
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
static bool IsDock(TileIndex t)
Is tile t a dock tile?
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
uint16 h
The height of the area.
Triggered when new cargo arrives at the station (for all tiles at the same time). ...
GRFFileProps grf_prop
properties related the the grf file
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
StringID string_id
Default name (town area) of station.
The tile/execution is done by "water".
remove a (rectangle of) tiles from a rail waypoint
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
VehicleTypeByte type
Type of vehicle.
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
void Merge(LinkGraph *other)
Merge a link graph with another one.
Base class for all station-ish types.
static const int STATION_ACCEPTANCE_TICKS
cycle duration for updating station acceptance
Axis
Allow incrementing of DiagDirDiff variables.
static CommandCost FindJoiningStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
Find a nearby station that joins this station.
struct GRFFileProps grf_prop
Properties related to the grf file.
custom station rating for this cargo type
LinkGraphSettings linkgraph
settings for link graph calculations
Used for industry tiles on land (also for oilrig if newgrf says so).
static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, bool is_drive_through, bool is_truck_stop, Axis axis, StationID *station, RoadTypes rts)
Checks if a road stop can be built at the given tile.
Set when the station accepts the cargo currently for final deliveries.
static uint GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Order current_order
The current order (+ status, like: loading)
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Date build_date
Date of construction.
Called to calculate part of a station rating.
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-...
static void RestoreTrainReservation(Train *v)
Restore platform reservation during station building/removing.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes)
Run watched cargo accepted callback for a house.
PaletteID pal
The palette (use PAL_NONE) if not needed)
uint32 water
Count of company owned track bits for canals.
StringID name
Name of this class.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.