# infrastructure_func.h File Reference

Functions for infrastructure sharing. More...

`#include "vehicle_base.h"`
`#include "functions.h"`
`#include "company_func.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 | GetSharingSetting (VehicleType type)
| Get the value of the sharing setting for a vehicle type.
static FORCEINLINE bool | IsInfraUsageAllowed (Owner infra_owner, Owner veh_owner, VehicleType type)
| Check whether a vehicle of a given owner and type can use the infrastrucutre of a given company.
static FORCEINLINE bool | IsInfraTileUsageAllowed (TileIndex tile, Owner veh_owner, VehicleType type)
| Check whether a vehicle of a given owner and type can use the infrastrucutre on a given tile.
static FORCEINLINE bool | CheckInfraUsageAllowed (Owner infra_owner, VehicleType type)
| Is a vehicle owned by _current_company allowed to use the infrastructure of infra_owner?
static FORCEINLINE bool | IsVehicleControlAllowed (const Vehicle *v, Owner o)
| Check whether a given company can control this vehicle.
static FORCEINLINE bool | 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 infrastructure sharing.

Definition in file infrastructure_func.h.

## Function Documentation

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

Is a vehicle owned by _current_company allowed to use the infrastructure of infra_owner?

See also:
  IsInfraUsageAllowed

Note:
  This function is to be called from DoCommands.

Parameters:

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

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

Definition at line 73 of file infrastructure_func.h.

References GetSharingSetting(), and OWNER_NONE.

Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), CmdDepotMassAutoReplace(), and 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 211 of file infrastructure.cpp.

References FixAllReservations(), GetSharingSetting(), INVALID_STRING_ID, INVALID_TILE, INVALID_TRACK, OrderDestinationIsAllowed(), ShowErrorMessage(), VEH_AIRCRAFT, VEH_TRAIN, VehiclePositionIsAllowed(), and YapfNotifyTrackLayoutChange().

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

Check whether _current_company can control this vehicle.

Note:
  This function is to be called from DoCommands.

See also:
  IsVehicleControlAllowed

Parameters:

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

Returns:
  True if _current_company is allowed to control this vehicle.

Definition at line 97 of file infrastructure_func.h.

References IsTileOwner(), and VEH_TRAIN.

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

static FORCEINLINE bool GetSharingSetting | ( | VehicleType | type | ) | `[static]`

Get the value of the sharing setting for a vehicle type.

Parameters:

  | type | The type of vehicle.

Returns:
  True if sharing is enabled for the given vehicle type.

Definition at line 30 of file infrastructure_func.h.

References _settings_game, GameSettings::sharing, SharingSettings::sharing_air, SharingSettings::sharing_rail, SharingSettings::sharing_road, SharingSettings::sharing_water, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by CheckInfraUsageAllowed(), CheckSharingChangePossible(), and IsInfraUsageAllowed().

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 261 of file infrastructure.cpp.

References INVALID_TILE, INVALID_TRACK, INVALID_VEH_ORDER_ID, InvalidateVehicleOrder(), OrderDestinationIsAllowed(), RemoveAndSellVehicle(), SetWindowDirty(), VehiclePositionIsAllowed(), and YapfNotifyTrackLayoutChange().

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

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

Parameters:

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

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

Definition at line 60 of file infrastructure_func.h.

References GetTileOwner(), and IsInfraUsageAllowed().

Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanEnterTileOwnerCheck(), and RoadFindPathToDest().

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

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

Parameters:

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

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

Definition at line 48 of file infrastructure_func.h.

References GetSharingSetting(), and OWNER_NONE.

Referenced by 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 110 of file infrastructure_func.h.

References _settings_game, GameSettings::sharing, and SharingSettings::sharing_rail.

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 85 of file infrastructure_func.h.

References IsTileOwner(), 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 68 of file infrastructure.cpp.

References _settings_game, TrainCache::cached_weight, DAY_TICKS, SharingSettings::fee_rail, GetTileOwner(), PaySharingFee(), GameSettings::sharing, and Train::tcache.

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 51 of file infrastructure.cpp.

References _settings_game, DAY_TICKS, SharingSettings::fee_air, SharingSettings::fee_road, SharingSettings::fee_water, BaseStation::owner, OWNER_NONE, PaySharingFee(), GameSettings::sharing, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

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 307 of file infrastructure.cpp.

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