Implementation of infrastructure sharing. More...
#include "stdafx.h"
#include "infrastructure_func.h"
#include "train.h"
#include "aircraft.h"
#include "vehicle_func.h"
#include "station_base.h"
#include "depot_base.h"
#include "pbs.h"
#include "signal_func.h"
#include "window_func.h"
#include "gui.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "company_base.h"
#include "table/strings.h"
Go to the source code of this file.
Functions | |
static void | PaySharingFee (Vehicle *v, Owner infra_owner, Money cost) |
Helper function for transferring sharing fees. | |
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. | |
static bool | VehiclePositionIsAllowed (const Vehicle *v, Owner owner=INVALID_OWNER) |
Check whether a vehicle is in an allowed position. | |
static bool | OrderDestinationIsAllowed (const Order *order, const Vehicle *v, Owner owner=INVALID_OWNER) |
Check whether an order has a destination that is allowed. | |
static void | RemoveAndSellVehicle (Vehicle *v, bool give_money) |
Sell a vehicle, no matter where it may be. | |
static void | FixAllReservations () |
Check all path reservations, and reserve a new path if the current path is invalid. | |
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) |
Update all block signals on the map. |
Implementation of infrastructure sharing.
Definition in file infrastructure.cpp.
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.
type | The type of vehicle whose setting will be changed. |
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().
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.
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 bool OrderDestinationIsAllowed | ( | const Order * | order, | |
const Vehicle * | v, | |||
Owner | owner = INVALID_OWNER | |||
) | [static] |
Check whether an order has a destination that is allowed.
I.e. it refers to a station/depot/waypoint the vehicle is allowed to visit.
order | The order to check | |
v | The vehicle this order belongs to. | |
owner | Owner whose infrastructure is not allowed, because the company will be removed. Ignored if INVALID_OWNER. |
Definition at line 121 of file infrastructure.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::Get(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::Get(), Order::GetDestination(), GetTileOwner(), Order::GetType(), IsInfraUsageAllowed(), Vehicle::last_station_visited, Vehicle::owner, BaseStation::owner, and BaseVehicle::type.
Referenced by CheckSharingChangePossible(), and HandleSharingCompanyDeletion().
void PayDailyTrackSharingFee | ( | Train * | v | ) |
Pay the daily fee for trains on foreign tracks.
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().
Helper function for transferring sharing fees.
v | The vehicle involved | |
infra_owner | The owner of the infrastructure | |
cost | Amount to transfer as money fraction (shifted 8 bits to the left) |
Definition at line 34 of file infrastructure.cpp.
References _settings_game, CompanyProperties::current_loan, GameSettings::economy, EXPENSES_SHARING_COST, EXPENSES_SHARING_INC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), min(), CompanyProperties::money, Vehicle::owner, Vehicle::profit_this_year, EconomySettings::sharing_payment_in_debt, and SubtractMoneyFromCompanyFract().
Referenced by PayDailyTrackSharingFee(), and PayStationSharingFee().
Pay the fee for spending a single tick inside a station.
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().
static void RemoveAndSellVehicle | ( | Vehicle * | v, | |
bool | give_money | |||
) | [static] |
Sell a vehicle, no matter where it may be.
v | The vehicle to sell | |
give_money | Do we actually need to give money to the vehicle owner? |
Definition at line 139 of file infrastructure.cpp.
References _current_company, _settings_game, DeleteVisibleTrain(), GameSettings::economy, EXPENSES_NEW_VEHICLES, Vehicle::First(), SpecializedVehicle< Train, Type >::From(), EconomySettings::infrastructure_sharing, Vehicle::IsFrontEngine(), Vehicle::Next(), Vehicle::owner, Vehicle::Previous(), SubtractMoneyFromCompany(), BaseVehicle::type, Vehicle::value, and VEH_TRAIN.
Referenced by HandleSharingCompanyDeletion().
void UpdateAllBlockSignals | ( | Owner | owner | ) |
Update all block signals on the map.
To be called after the setting for sharing of rails changes.
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().
Check whether a vehicle is in an allowed position.
v | The vehicle to check. | |
owner | Owner whose infrastructure is not allowed, because the company will be removed. Ignored if INVALID_OWNER. |
Definition at line 81 of file infrastructure.cpp.
References FLYING, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedStation< Station, false >::Get(), GetTileOwner(), IsInfraTileUsageAllowed(), IsInfraUsageAllowed(), IsRoadDepotTile(), IsShipDepotTile(), IsStandardRoadStopTile(), Vehicle::IsStoppedInDepot(), SpecializedStation< Station, false >::IsValidID(), Vehicle::Next(), BaseStation::owner, Vehicle::owner, Aircraft::state, Aircraft::targetairport, Vehicle::tile, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by CheckSharingChangePossible(), and HandleSharingCompanyDeletion().