Functions

# infrastructure_func.h File Reference

Functions for access to (shared) infrastructure. More...

`#include "vehicle_base.h"`
`#include "command_type.h"`
`#include "company_func.h"`
`#include "tile_cmd.h"`

Go to the source code of this file.

## Functions
void | PayStationSharingFee (Vehicle *v, const Station *st)
| Pay the fee for spending a single tick inside a station.
void | PayDailyTrackSharingFee (Train *v)
| Pay the daily fee for trains on foreign tracks.
bool | CheckSharingChangePossible (VehicleType type)
| Check if a sharing change is possible.
void | HandleSharingCompanyDeletion (Owner owner)
| Handle the removal (through reset_company or bankruptcy) of a company.
void | UpdateAllBlockSignals (Owner owner=INVALID_OWNER)
| Update all block signals on the map.
static FORCEINLINE bool | IsInfraUsageAllowed (VehicleType type, Owner veh_owner, Owner infra_owner)
| Check whether a vehicle of a given owner and type can use the infrastrucutre of a given company.
static FORCEINLINE bool | IsInfraTileUsageAllowed (VehicleType type, Owner veh_owner, TileIndex tile)
| Check whether a vehicle of a given owner and type can use the infrastrucutre on a given tile.
static FORCEINLINE CommandCost | CheckInfraUsageAllowed (VehicleType type, Owner infra_owner, TileIndex tile=0)
| Is a vehicle owned by _current_company allowed to use the infrastructure of infra_owner? If this is not allowed, this function provides the appropriate error message.
static FORCEINLINE bool | IsVehicleControlAllowed (const Vehicle *v, Owner o)
| Check whether a given company can control this vehicle.
static FORCEINLINE CommandCost | CheckVehicleControlAllowed (const Vehicle *v)
| Check whether _current_company can control this vehicle.
static FORCEINLINE bool | IsOneSignalBlock (Owner o1, Owner o2)
| Do signal states propagate from the tracks of one owner to the other?

## Detailed Description

Functions for access to (shared) infrastructure.

Definition in file infrastructure_func.h.

## Function Documentation

static FORCEINLINE CommandCost CheckInfraUsageAllowed | ( | VehicleType | type,
|  | Owner | infra_owner,
|  | TileIndex | tile = `0` |
| ) |  |  | `[static]`

Is a vehicle owned by _current_company allowed to use the infrastructure of infra_owner? If this is not allowed, this function provides the appropriate error message.

See also:
  IsInfraUsageAllowed
  CheckOwnership

Parameters:

  | type | Type of vehicle.
  | infra_owner | Owner of the infrastructure.
  | tile | Tile of the infrastructure.

Returns:
  CommandCost indicating success or failure.

Definition at line 61 of file infrastructure_func.h.

References _settings_game, CheckOwnership(), GameSettings::economy, EconomySettings::infrastructure_sharing, and OWNER_NONE.

Referenced by CmdInsertOrder().

bool CheckSharingChangePossible | ( | VehicleType | type | ) |

Check if a sharing change is possible.

If vehicles are still on others' infrastructure or using others' stations, The change is not possible and false is returned.

Parameters:

  | type | The type of vehicle whose setting will be changed.

Returns:
  True if the change can take place, false otherwise.

Definition at line 206 of file infrastructure.cpp.

References _settings_game, Vehicle::current_order, GameSettings::economy, Vehicle::FirstShared(), FixAllReservations(), FOR_ALL_VEHICLES, EconomySettings::infrastructure_sharing, INVALID_STRING_ID, INVALID_TILE, INVALID_TRACK, OrderDestinationIsAllowed(), Vehicle::Previous(), ShowErrorMessage(), BaseVehicle::type, VEH_AIRCRAFT, VEH_TRAIN, VehiclePositionIsAllowed(), WL_ERROR, and YapfNotifyTrackLayoutChange().

static FORCEINLINE CommandCost CheckVehicleControlAllowed | ( | const Vehicle * | v | ) | `[static]`

Check whether _current_company can control this vehicle.

If this is not allowed, this function provides the appropriate error message.

See also:
  IsVehicleControlAllowed

Parameters:

  | v | The vehicle which may or may not be controlled.

Returns:
  CommandCost indicating success or failure.

Definition at line 86 of file infrastructure_func.h.

References _current_company, CheckOwnership(), IsTileOwner(), Vehicle::owner, Vehicle::tile, BaseVehicle::type, and VEH_TRAIN.

Referenced by CmdForceTrainProceed(), CmdStartStopVehicle(), and CmdTurnRoadVeh().

void HandleSharingCompanyDeletion | ( | Owner | owner | ) |

Handle the removal (through reset_company or bankruptcy) of a company.

i.e. remove all vehicles owned by that company or on its infrastructure, and delete all now-invalid orders.

Parameters:

  | Owner | the company to be removed.

Definition at line 256 of file infrastructure.cpp.

References Vehicle::current_order, Vehicle::FirstShared(), FOR_ALL_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_TILE, INVALID_TRACK, INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), IsCompanyBuildableVehicleType(), Order::IsType(), Vehicle::LeaveStation(), Order::MakeDummy(), Vehicle::NextShared(), OrderDestinationIsAllowed(), Vehicle::owner, Vehicle::Previous(), RemoveAndSellVehicle(), SetWindowDirty(), VehiclePositionIsAllowed(), and YapfNotifyTrackLayoutChange().

Referenced by ChangeOwnershipOfCompanyItems().

static FORCEINLINE bool IsInfraTileUsageAllowed | ( | VehicleType | type,
|  | Owner | veh_owner,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Check whether a vehicle of a given owner and type can use the infrastrucutre on a given tile.

Parameters:

  | type | Type of vehicle we are talking about.
  | veh_owner | Owner of the vehicle in question.
  | tile | The tile that may or may not be used.

Returns:
  True if infrastructure usage is allowed, false otherwise.

Definition at line 46 of file infrastructure_func.h.

References GetTileOwner(), and IsInfraUsageAllowed().

Referenced by CanEnterTileOwnerCheck(), CmdBuildVehicle(), DepotWindow::OnPaint(), RoadFindPathToDest(), and VehiclePositionIsAllowed().

static FORCEINLINE bool IsInfraUsageAllowed | ( | VehicleType | type,
|  | Owner | veh_owner,
|  | Owner | infra_owner |
| ) |  |  | `[static]`

Check whether a vehicle of a given owner and type can use the infrastrucutre of a given company.

Parameters:

  | type | Type of vehicle we are talking about.
  | veh_owner | Owner of the vehicle in question.
  | infra_owner | The owner of the infrastructure.

Returns:
  True if infrastructure usage is allowed, false otherwise.

Definition at line 34 of file infrastructure_func.h.

References _settings_game, GameSettings::economy, EconomySettings::infrastructure_sharing, and OWNER_NONE.

Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdDepotMassAutoReplace(), FindNearestHangar(), IsInfraTileUsageAllowed(), OrderDestinationIsAllowed(), and VehiclePositionIsAllowed().

static FORCEINLINE bool IsOneSignalBlock | ( | Owner | o1,
|  | Owner | o2 |
| ) |  |  | `[static]`

Do signal states propagate from the tracks of one owner to the other?

Note:
  This function should be consistent, so if it returns true for (a, b) and (b, c), it should also return true for (a, c).

Parameters:

  | o1 | First track owner.
  | o2 | Second track owner.

Returns:
  True if tracks of the two owners are part of the same signal block.

Definition at line 100 of file infrastructure_func.h.

References _settings_game, GameSettings::economy, and EconomySettings::infrastructure_sharing.

Referenced by AddSideToSignalBuffer(), AddTrackToSignalBuffer(), ExploreSegment(), and UpdateAllBlockSignals().

static FORCEINLINE bool IsVehicleControlAllowed | ( | const Vehicle * | v,
|  | Owner | o |
| ) |  |  | `[static]`

Check whether a given company can control this vehicle.

Controlling a vehicle means permission to start, stop or reverse it or to make it ignore signals.

Parameters:

  | v | The vehicle which may or may not be controlled.
  | o | The company which may or may not control this vehicle.

Returns:
  True if the given company is allowed to control this vehicle.

Definition at line 74 of file infrastructure_func.h.

References IsTileOwner(), Vehicle::owner, Vehicle::tile, BaseVehicle::type, and VEH_TRAIN.

Referenced by VehicleViewWindow::OnPaint().

void PayDailyTrackSharingFee | ( | Train * | v | ) |

Pay the daily fee for trains on foreign tracks.

Parameters:

  | v | The vehicle to pay the fee for.

Definition at line 63 of file infrastructure.cpp.

References _settings_game, GroundVehicleCache::cached_weight, GameSettings::economy, GroundVehicle< T, Type >::gcache, GetTileOwner(), Vehicle::owner, PaySharingFee(), Vehicle::running_ticks, EconomySettings::sharing_fee, and Vehicle::tile.

Referenced by Train::OnNewDay().

void PayStationSharingFee | ( | Vehicle * | v,
|  | const Station * | st |
| ) |  |  |

Pay the fee for spending a single tick inside a station.

Parameters:

  | v | The vehicle that is using the station.
  | st | The station that it uses.

Definition at line 52 of file infrastructure.cpp.

References _settings_game, DAY_TICKS, GameSettings::economy, BaseStation::owner, Vehicle::owner, OWNER_NONE, PaySharingFee(), EconomySettings::sharing_fee, BaseVehicle::type, and VEH_TRAIN.

Referenced by Vehicle::HandleLoading().

void UpdateAllBlockSignals | ( | Owner | owner | ) |

Update all block signals on the map.

To be called after the setting for sharing of rails changes.

Parameters:

  | owner | Owner whose signals to update. If INVALID_OWNER, update everything.

Definition at line 302 of file infrastructure.cpp.

References AddTrackToSignalBuffer(), GetTileOwner(), GetTrackBits(), HasSignalOnTrack(), HasSignals(), INVALID_OWNER, IsLevelCrossingTile(), IsOneSignalBlock(), IsTileType(), MapSize(), MP_RAILWAY, RemoveFirstTrack(), TRACK_BIT_NONE, UpdateLevelCrossing(), and UpdateSignalsInBuffer().

Referenced by ChangeOwnershipOfCompanyItems().