Implementation of cargo destinations. More...
#include "stdafx.h"
#include "cargodest_type.h"
#include "cargodest_base.h"
#include "cargodest_func.h"
#include "core/bitmath_func.hpp"
#include "core/random_func.hpp"
#include "core/pool_func.hpp"
#include "cargotype.h"
#include "settings_type.h"
#include "town.h"
#include "industry.h"
#include "window_func.h"
#include "vehicle_base.h"
#include "station_base.h"
#include "pathfinder/yapf/yapf.h"
#include "company_base.h"
Go to the source code of this file.
Data Structures | |
struct | EnumRandomData |
Information for the town/industry enumerators. More... | |
Functions | |
bool | CargoHasDestinations (CargoID cid) |
Are cargo destinations for this cargo type enabled? | |
bool | CargoDestinationsDisabled () |
Are cargo destinations for all cargo types disabled? | |
static bool | IsTownCargo (CargoID cid) |
Should this cargo type primarily have towns as a destination? | |
static bool | IsSymmetricCargo (CargoID cid) |
Does this cargo have a symmetric demand? | |
static bool | IsPassengerCargo (CargoID cid) |
Is this a passenger cargo. | |
static bool | IsNearby (TileIndex t1, TileIndex t2, uint32 dist_square) |
Test whether two tiles are nearby with map-size scaling. | |
static bool | IsTownNearby (const Town *t, TileIndex ti) |
Test whether a tiles is near a town. | |
static bool | IsIndustryNearby (const Industry *ind, TileIndex ti) |
Test whether a tiles is near an industry. | |
static bool | EnumAnyDest (const CargoSourceSink *dest, EnumRandomData *erd) |
Common helper for town/industry enumeration. | |
static bool | EnumAnyTown (const Town *t, void *data) |
Enumerate any town not already a destination and accepting a specific cargo. | |
static bool | EnumCity (const Town *t, void *data) |
Enumerate cities. | |
static bool | EnumBigTown (const Town *t, void *data) |
Enumerate towns with a big population. | |
static bool | EnumNearbyTown (const Town *t, void *data) |
Enumerate nearby towns. | |
static bool | EnumAnyIndustry (const Industry *ind, void *data) |
Enumerate any industry not already a destination and accepting a specific cargo. | |
static bool | EnumNearbyIndustry (const Industry *ind, void *data) |
Enumerate nearby industries. | |
static bool | EnumProducingIndustry (const Industry *ind, void *data) |
Enumerate industries that are producing cargo. | |
template<typename T > | |
static bool | EnumAnySupplier (const T *css, void *data) |
Enumerate cargo sources supplying a specific cargo. | |
static bool | EnumNearbySupplier (const Industry *ind, void *data) |
Enumerate nearby cargo sources supplying a specific cargo. | |
static bool | EnumNearbySupplier (const Town *t, void *data) |
Enumerate nearby cargo sources supplying a specific cargo. | |
static CargoSourceSink * | FindTownDestination (byte &weight_mod, CargoSourceSink *source, TileIndex source_xy, CargoID cid, const uint8 destclass_chance[4], TownID skip=INVALID_TOWN) |
Find a town as a destination. | |
static CargoSourceSink * | FindIndustryDestination (byte &weight_mod, CargoSourceSink *source, TileIndex source_xy, CargoID cid, IndustryID skip=INVALID_INDUSTRY) |
Find an industry as a destination. | |
static CargoSourceSink * | FindSupplySource (Industry *dest, CargoID cid) |
Find a supply for a cargo type. | |
static void | RemoveLowestLink (CargoSourceSink *source, CargoID cid) |
Remove the link with the lowest weight from a cargo source. | |
static void | CreateNewLinks (CargoSourceSink *source, TileIndex source_xy, CargoID cid, uint chance_a, uint chance_b, const uint8 town_chance[], TownID skip_town, IndustryID skip_ind) |
Create missing cargo links for a source. | |
static void | RemoveInvalidLinks (CargoSourceSink *css) |
Remove invalid links from a cargo source/sink. | |
void | UpdateExpectedLinks (Town *t) |
Updated the desired link count for each cargo. | |
void | UpdateExpectedLinks (Industry *ind) |
Updated the desired link count for each cargo. | |
void | AddMissingIndustryLinks (Industry *ind) |
Make sure an industry has at least one incoming link for each accepted cargo. | |
void | UpdateCargoLinks (Town *t) |
Update the demand links. | |
void | UpdateCargoLinks (Industry *ind) |
Update the demand links. | |
void | UpdateLinkWeights (Town *t) |
Recalculate the link weights. | |
void | UpdateLinkWeights (CargoSourceSink *css) |
Recalculate the link weights. | |
void | RebuildCargoLinkCounts () |
Rebuild the cached count of incoming cargo links. | |
void | UpdateCargoLinks () |
Update the demand links of all towns and industries. | |
static bool | EnumAcceptingTown (const Town *t, void *data) |
Enumerate all towns accepting a specific cargo. | |
static bool | EnumAcceptingIndustry (const Industry *ind, void *data) |
Enumerate all industries accepting a specific cargo. | |
bool | MoveCargoWithDestinationToStationWorker (CargoID cid, uint *amount, SourceType source_type, SourceID source_id, const StationList *all_stations, TileIndex src_tile) |
Move a single packet of cargo to a station with destination information. | |
bool | MoveCargoWithDestinationToStation (CargoID cid, uint *amount, SourceType source_type, SourceID source_id, const StationList *all_stations, TileIndex src_tile) |
Move cargo to a station with destination information. | |
RouteLink * | FindRouteLinkForCargo (Station *st, CargoID cid, const CargoPacket *cp, StationID *next_unload, OrderID order, bool *found) |
Get the current best route link for a cargo packet at a station. | |
void | UpdateVehicleRouteLinks (const Vehicle *v, uint32 cargos, bool clear_others, Station *from, OrderID from_oid, StationID to_id, OrderID to_oid, uint32 travel_time) |
Update or create a single route link for a specific vehicle and cargo. | |
void | UpdateVehicleRouteLinks (const Vehicle *v, StationID arrived_at) |
Update route links after a vehicle has arrived at a station. | |
void | PrefillRouteLinks (const Vehicle *v) |
Pre-fill the route links from the orders of a vehicle. | |
void | InvalidateStationRouteLinks (Station *station) |
Remove all route links to and from a station. | |
void | InvalidateOrderRouteLinks (OrderID order) |
Remove all route links referencing an order. | |
void | AgeRouteLinks (Station *st) |
Age and expire route links of a station. | |
Variables | |
static const byte | LWM_ANYWHERE = 1 |
Weight modifier for undetermined destinations. | |
static const byte | LWM_TONY_ANY = 2 |
Default weight modifier for towns. | |
static const byte | LWM_TONY_BIG = 3 |
Weight modifier for big towns. | |
static const byte | LWM_TONY_CITY = 4 |
Weight modifier for cities. | |
static const byte | LWM_TONY_NEARBY = 5 |
Weight modifier for nearby towns. | |
static const byte | LWM_INTOWN = 8 |
Weight modifier for in-town links. | |
static const byte | LWM_IND_ANY = 2 |
Default weight modifier for industries. | |
static const byte | LWM_IND_NEARBY = 3 |
Weight modifier for nearby industries. | |
static const byte | LWM_IND_PRODUCING = 4 |
Weight modifier for producing industries. | |
static const uint | MAX_EXTRA_LINKS = 2 |
Number of extra links allowed. | |
static const uint | MAX_IND_STOCKPILE = 1000 |
Maximum stockpile to consider for industry link weight. | |
static const uint | BASE_TOWN_LINKS = 0 |
Index into _settings_game.economy.cargodest.base_town_links for normal cargo. | |
static const uint | BASE_TOWN_LINKS_SYMM = 1 |
Index into _settings_game.economy.cargodest.base_town_links for symmteric cargos. | |
static const uint | BASE_IND_LINKS = 0 |
Index into _settings_game.economy.cargodest.base_ind_links for normal cargo. | |
static const uint | BASE_IND_LINKS_TOWN = 1 |
Index into _settings_game.economy.cargodest.base_ind_links for town cargos. | |
static const uint | BASE_IND_LINKS_SYMM = 2 |
Index into _settings_game.economy.cargodest.base_ind_links for symmetric cargos. | |
static const uint | BIG_TOWN_POP_MAIL = 0 |
Index into _settings_game.economy.cargodest.big_town_pop for mail. | |
static const uint | BIG_TOWN_POP_PAX = 1 |
Index into _settings_game.economy.cargodest.big_town_pop for passengers. | |
static const uint | SCALE_TOWN = 0 |
Index into _settings_game.economy.cargodest.pop_scale_town/weight_scale_town for normal cargo. | |
static const uint | SCALE_TOWN_BIG = 1 |
Index into _settings_game.economy.cargodest.pop_scale_town/weight_scale_town for normal cargo of big towns. | |
static const uint | SCALE_TOWN_PAX = 2 |
Index into _settings_game.economy.cargodest.pop_scale_town/weight_scale_town for passengers. | |
static const uint | SCALE_TOWN_BIG_PAX = 3 |
Index into _settings_game.economy.cargodest.pop_scale_town/weight_scale_town for passengers of big towns. | |
static const uint | CARGO_SCALE_IND = 0 |
Index into _settings_game.economy.cargodest.cargo_scale_ind for normal cargo. | |
static const uint | CARGO_SCALE_IND_TOWN = 1 |
Index into _settings_game.economy.cargodest.cargo_scale_ind for town cargos. | |
static const uint | MIN_WEIGHT_TOWN = 0 |
Index into _settings_game.economy.cargodest.min_weight_town for normal cargo. | |
static const uint | MIN_WEIGHT_TOWN_PAX = 1 |
Index into _settings_game.economy.cargodest.min_weight_town for passengers. | |
static const uint | WEIGHT_SCALE_IND_PROD = 0 |
Index into _settings_game.economy.cargodest.weight_scale_ind for produced cargo. | |
static const uint | WEIGHT_SCALE_IND_PILE = 1 |
Index into _settings_game.economy.cargodest.weight_scale_ind for stockpiled cargo. | |
RouteLinkPool | _routelink_pool ("RouteLink") |
Implementation of cargo destinations.
Definition in file cargodest.cpp.
void AddMissingIndustryLinks | ( | Industry * | ind | ) |
Make sure an industry has at least one incoming link for each accepted cargo.
Definition at line 505 of file cargodest.cpp.
References Industry::accepts_cargo, CargoSourceSink::AcceptsCargo(), SmallVector< T, S >::Append(), CargoSourceSink::cargo_links, FindSupplySource(), INVALID_CARGO, IsSymmetricCargo(), SmallVector< T, S >::Length(), lengthof, LWM_IND_ANY, MAX_EXTRA_LINKS, CargoSourceSink::num_incoming_links, CargoSourceSink::num_links_expected, and Industry::SuppliesCargo().
Referenced by UpdateCargoLinks().
void AgeRouteLinks | ( | Station * | st | ) |
Age and expire route links of a station.
Definition at line 1176 of file cargodest.cpp.
References _settings_game, EconomySettings::cargodest, GameSettings::economy, Station::goods, CargodestSettings::max_route_age, and GoodsEntry::routes.
static void CreateNewLinks | ( | CargoSourceSink * | source, | |
TileIndex | source_xy, | |||
CargoID | cid, | |||
uint | chance_a, | |||
uint | chance_b, | |||
const uint8 | town_chance[], | |||
TownID | skip_town, | |||
IndustryID | skip_ind | |||
) | [static] |
Create missing cargo links for a source.
Definition at line 383 of file cargodest.cpp.
References CargoSourceSink::AcceptsCargo(), SmallVector< T, S >::Append(), CargoSourceSink::cargo_links, Chance16(), FindIndustryDestination(), FindTownDestination(), IsSymmetricCargo(), SmallVector< T, S >::Length(), LWM_ANYWHERE, MAX_EXTRA_LINKS, CargoSourceSink::num_incoming_links, CargoSourceSink::num_links_expected, RemoveLowestLink(), and CargoSourceSink::SuppliesCargo().
Referenced by UpdateCargoLinks().
static bool EnumAcceptingIndustry | ( | const Industry * | ind, | |
void * | data | |||
) | [static] |
Enumerate all industries accepting a specific cargo.
Definition at line 802 of file cargodest.cpp.
References Industry::AcceptsCargo().
Referenced by MoveCargoWithDestinationToStationWorker().
static bool EnumAcceptingTown | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate all towns accepting a specific cargo.
Definition at line 796 of file cargodest.cpp.
References Town::AcceptsCargo().
Referenced by MoveCargoWithDestinationToStationWorker().
static bool EnumAnyDest | ( | const CargoSourceSink * | dest, | |
EnumRandomData * | erd | |||
) | [static] |
Common helper for town/industry enumeration.
Definition at line 155 of file cargodest.cpp.
References CargoSourceSink::cargo_links, CargoSourceSink::HasLinkTo(), SmallVector< T, S >::Length(), MAX_EXTRA_LINKS, and CargoSourceSink::num_links_expected.
Referenced by EnumAnyIndustry(), and EnumAnyTown().
static bool EnumAnyIndustry | ( | const Industry * | ind, | |
void * | data | |||
) | [static] |
Enumerate any industry not already a destination and accepting a specific cargo.
Definition at line 194 of file cargodest.cpp.
References Industry::AcceptsCargo(), and EnumAnyDest().
Referenced by EnumNearbyIndustry(), EnumProducingIndustry(), and FindIndustryDestination().
static bool EnumAnySupplier | ( | const T * | css, | |
void * | data | |||
) | [inline, static] |
Enumerate cargo sources supplying a specific cargo.
Definition at line 215 of file cargodest.cpp.
Referenced by EnumNearbySupplier(), and FindSupplySource().
static bool EnumAnyTown | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate any town not already a destination and accepting a specific cargo.
Definition at line 167 of file cargodest.cpp.
References Town::AcceptsCargo(), and EnumAnyDest().
Referenced by EnumBigTown(), EnumCity(), EnumNearbyTown(), and FindTownDestination().
static bool EnumBigTown | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate towns with a big population.
Definition at line 180 of file cargodest.cpp.
References _settings_game, CargodestSettings::big_town_pop, BIG_TOWN_POP_MAIL, BIG_TOWN_POP_PAX, EconomySettings::cargodest, GameSettings::economy, EnumAnyTown(), IsPassengerCargo(), and TransportedCargoStat::old_max.
Referenced by FindTownDestination().
static bool EnumCity | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate cities.
Definition at line 174 of file cargodest.cpp.
References EnumAnyTown().
Referenced by FindTownDestination().
static bool EnumNearbyIndustry | ( | const Industry * | ind, | |
void * | data | |||
) | [static] |
Enumerate nearby industries.
Definition at line 201 of file cargodest.cpp.
References EnumAnyIndustry(), and IsIndustryNearby().
Referenced by FindIndustryDestination().
static bool EnumNearbySupplier | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate nearby cargo sources supplying a specific cargo.
Definition at line 228 of file cargodest.cpp.
References EnumAnySupplier(), and IsTownNearby().
static bool EnumNearbySupplier | ( | const Industry * | ind, | |
void * | data | |||
) | [static] |
Enumerate nearby cargo sources supplying a specific cargo.
Definition at line 221 of file cargodest.cpp.
References EnumAnySupplier(), and IsIndustryNearby().
Referenced by FindSupplySource().
static bool EnumNearbyTown | ( | const Town * | t, | |
void * | data | |||
) | [static] |
Enumerate nearby towns.
Definition at line 187 of file cargodest.cpp.
References EnumAnyTown(), and IsTownNearby().
Referenced by FindTownDestination().
static bool EnumProducingIndustry | ( | const Industry * | ind, | |
void * | data | |||
) | [static] |
Enumerate industries that are producing cargo.
Definition at line 208 of file cargodest.cpp.
References CT_INVALID, EnumAnyIndustry(), and Industry::produced_cargo.
Referenced by FindIndustryDestination().
static CargoSourceSink* FindIndustryDestination | ( | byte & | weight_mod, | |
CargoSourceSink * | source, | |||
TileIndex | source_xy, | |||
CargoID | cid, | |||
IndustryID | skip = INVALID_INDUSTRY | |||
) | [static] |
Find an industry as a destination.
Definition at line 265 of file cargodest.cpp.
References _settings_game, EconomySettings::cargodest, GameSettings::economy, EnumAnyIndustry(), EnumNearbyIndustry(), EnumProducingIndustry(), Industry::GetRandom(), CargodestSettings::ind_chances, IsSymmetricCargo(), lastof, lengthof, LWM_ANYWHERE, LWM_IND_ANY, LWM_IND_NEARBY, and LWM_IND_PRODUCING.
Referenced by CreateNewLinks().
RouteLink* FindRouteLinkForCargo | ( | Station * | st, | |
CargoID | cid, | |||
const CargoPacket * | cp, | |||
StationID * | next_unload, | |||
OrderID | order, | |||
bool * | found | |||
) |
Get the current best route link for a cargo packet at a station.
st | Station the route starts at. | |
cid | Cargo type. | |
cp | Cargo packet with destination information. | |
order | Incoming order of the cargo packet. | |
[out] | found | Set to true if a route was found. |
Definition at line 964 of file cargodest.cpp.
References SmallVector< T, S >::Append(), CargoPacket::DestinationID(), CargoPacket::DestinationType(), CargoPacket::DestinationXY(), CargoPacket::Flags(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), INVALID_SOURCE, ST_INDUSTRY, BaseStation::xy, and YapfChooseRouteLink().
Referenced by CargoList< Tinst >::MoveTo(), and StationCargoList::UpdateCargoNextHop().
static CargoSourceSink* FindSupplySource | ( | Industry * | dest, | |
CargoID | cid | |||
) | [static] |
Find a supply for a cargo type.
Definition at line 294 of file cargodest.cpp.
References Chance16(), EnumAnySupplier(), EnumNearbySupplier(), Town::GetRandom(), Industry::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::location, and TileArea::tile.
Referenced by AddMissingIndustryLinks().
static CargoSourceSink* FindTownDestination | ( | byte & | weight_mod, | |
CargoSourceSink * | source, | |||
TileIndex | source_xy, | |||
CargoID | cid, | |||
const uint8 | destclass_chance[4], | |||
TownID | skip = INVALID_TOWN | |||
) | [static] |
Find a town as a destination.
Definition at line 236 of file cargodest.cpp.
References EnumAnyTown(), EnumBigTown(), EnumCity(), EnumNearbyTown(), Town::GetRandom(), IsSymmetricCargo(), lengthof, LWM_ANYWHERE, LWM_TONY_ANY, LWM_TONY_BIG, LWM_TONY_CITY, and LWM_TONY_NEARBY.
Referenced by CreateNewLinks().
void InvalidateOrderRouteLinks | ( | OrderID | order | ) |
Remove all route links referencing an order.
order | The order being removed. |
Definition at line 1157 of file cargodest.cpp.
References Station::goods, and GoodsEntry::routes.
Referenced by CmdModifyOrder(), and Order::PostDestructor().
void InvalidateStationRouteLinks | ( | Station * | station | ) |
Remove all route links to and from a station.
station | Station being removed. |
Definition at line 1125 of file cargodest.cpp.
References Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, and GoodsEntry::routes.
Referenced by Station::~Station().
Test whether a tiles is near an industry.
ind | The industry. | |
ti | The tile to test. |
Definition at line 149 of file cargodest.cpp.
References _settings_game, EconomySettings::cargodest, GameSettings::economy, CargodestSettings::ind_nearby_dist, IsNearby(), Industry::location, and TileArea::tile.
Referenced by EnumNearbyIndustry(), and EnumNearbySupplier().
Test whether two tiles are nearby with map-size scaling.
t1 | First tile. | |
t2 | Second tile. | |
dist_square | Allowed squared distance between the tiles. |
Definition at line 124 of file cargodest.cpp.
References DistanceSquare(), and ScaleByMapSize1D().
Referenced by IsIndustryNearby(), and IsTownNearby().
static bool IsPassengerCargo | ( | CargoID | cid | ) | [static] |
Is this a passenger cargo.
Definition at line 102 of file cargodest.cpp.
References CargoSpec::Get(), TE_PASSENGERS, and CargoSpec::town_effect.
Referenced by EnumBigTown(), Town::GetDestinationWeight(), and UpdateExpectedLinks().
Test whether a tiles is near a town.
t | The town. | |
ti | The tile to test. |
Definition at line 138 of file cargodest.cpp.
References _settings_game, EconomySettings::cargodest, GameSettings::economy, IsNearby(), and CargodestSettings::town_nearby_dist.
Referenced by EnumNearbySupplier(), and EnumNearbyTown().
bool MoveCargoWithDestinationToStation | ( | CargoID | cid, | |
uint * | amount, | |||
SourceType | source_type, | |||
SourceID | source_id, | |||
const StationList * | all_stations, | |||
TileIndex | src_tile | |||
) |
Move cargo to a station with destination information.
cid | Cargo type. | |
amount[in,out] | Cargo amount, return is actually moved cargo. | |
source_type | Type of the cargo source. | |
source_id | ID of the cargo source. | |
all_stations | List of possible target stations. | |
src_tile | Source tile. |
Definition at line 927 of file cargodest.cpp.
References CargoHasDestinations(), MoveCargoWithDestinationToStationWorker(), and ST_INDUSTRY.
bool MoveCargoWithDestinationToStationWorker | ( | CargoID | cid, | |
uint * | amount, | |||
SourceType | source_type, | |||
SourceID | source_id, | |||
const StationList * | all_stations, | |||
TileIndex | src_tile | |||
) |
Move a single packet of cargo to a station with destination information.
cid | Cargo type. | |
amount[in,out] | Cargo amount, return is actually moved cargo. | |
source_type | Type of the cargo source. | |
source_id | ID of the cargo source. | |
all_stations | List of possible target stations. | |
src_tile | Source tile. |
Definition at line 817 of file cargodest.cpp.
References _settings_game, CargoLink::amount, CargoSourceSink::cargo_links, EconomySettings::cargodest, CargoLink::dest, DistanceSquare(), GameSettings::economy, SmallVector< T, S >::End(), EnumAcceptingIndustry(), EnumAcceptingTown(), SmallVector< T, S >::Find(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), CargoSourceSink::GetID(), Industry::GetRandom(), Town::GetRandom(), CargoSourceSink::GetRandomLink(), StationFinder::GetStations(), CargoSourceSink::GetTileForDestination(), CargoSourceSink::GetType(), Station::goods, INVALID_ORDER, IsSymmetricCargo(), SmallVector< T, S >::Length(), LWM_ANYWHERE, CargodestSettings::max_route_penalty, TransportedCargoStat::new_act, TransportedCargoStat::new_max, ST_HEADQUARTERS, ST_INDUSTRY, ST_TOWN, TileArea::tile, and YapfChooseRouteLink().
Referenced by MoveCargoWithDestinationToStation().
void PrefillRouteLinks | ( | const Vehicle * | v | ) |
Pre-fill the route links from the orders of a vehicle.
v | The vehicle to get the orders from. |
Definition at line 1070 of file cargodest.cpp.
References _settings_game, CargoDestinationsDisabled(), DistanceManhattan(), Vehicle::FirstShared(), SpecializedStation< Station, false >::Get(), Order::GetDestination(), Vehicle::GetDisplayMaxSpeed(), OrderList::GetFirstOrder(), Order::GetNonStopType(), OrderList::GetNumOrders(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Order::IsRefit(), Order::IsType(), Vehicle::list, Order::next, Vehicle::NextShared(), ONSF_NO_STOP_AT_DESTINATION_STATION, Vehicle::orders, VehicleSettings::plane_speed, TILE_SIZE, BaseVehicle::type, UpdateVehicleRouteLinks(), VEH_AIRCRAFT, GameSettings::vehicle, and BaseStation::xy.
Referenced by AfterLoadGame(), CmdBuildVehicle(), CmdCloneOrder(), CmdModifyOrder(), CmdMoveRailVehicle(), CmdRefitVehicle(), DeleteOrder(), InsertOrder(), and NormaliseTrainHead().
void RebuildCargoLinkCounts | ( | ) |
Rebuild the cached count of incoming cargo links.
Definition at line 691 of file cargodest.cpp.
References SmallVector< T, S >::Begin(), CargoSourceSink::cargo_links, SmallVector< T, S >::End(), lengthof, MemSetT(), and CargoSourceSink::num_incoming_links.
Referenced by InitializeWindowsAndCaches().
static void RemoveInvalidLinks | ( | CargoSourceSink * | css | ) | [static] |
Remove invalid links from a cargo source/sink.
Definition at line 425 of file cargodest.cpp.
References SmallVector< T, S >::Begin(), CargoSourceSink::cargo_links, CargoSourceSink::cargo_links_weight, SmallVector< T, S >::Clear(), SmallVector< T, S >::End(), SmallVector< T, S >::Erase(), NUM_CARGO, and CargoSourceSink::SuppliesCargo().
Referenced by UpdateCargoLinks().
static void RemoveLowestLink | ( | CargoSourceSink * | source, | |
CargoID | cid | |||
) | [static] |
Remove the link with the lowest weight from a cargo source.
The reverse link is removed as well if the cargo has symmetric demand.
source | Remove the link from this cargo source. | |
cid | Cargo type of the link to remove. |
Definition at line 356 of file cargodest.cpp.
References SmallVector< T, S >::Begin(), CargoSourceSink::cargo_links, CargoLink::dest, SmallVector< T, S >::End(), SmallVector< T, S >::Erase(), SmallVector< T, S >::Find(), CargoSourceSink::HasLinkTo(), IsSymmetricCargo(), LWM_ANYWHERE, and CargoSourceSink::num_incoming_links.
Referenced by CreateNewLinks().
void UpdateCargoLinks | ( | ) |
Update the demand links of all towns and industries.
Definition at line 716 of file cargodest.cpp.
References AddMissingIndustryLinks(), CargoDestinationsDisabled(), InvalidateWindowClassesData(), RemoveInvalidLinks(), UpdateCargoLinks(), UpdateExpectedLinks(), and UpdateLinkWeights().
void UpdateCargoLinks | ( | Industry * | ind | ) |
Update the demand links.
Definition at line 550 of file cargodest.cpp.
References _settings_game, EconomySettings::cargodest, CargoHasDestinations(), CreateNewLinks(), GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_CARGO, IsTownCargo(), lengthof, Industry::location, Industry::produced_cargo, TileArea::tile, and CargodestSettings::town_chances_town.
void UpdateCargoLinks | ( | Town * | t | ) |
Update the demand links.
Definition at line 536 of file cargodest.cpp.
References _settings_game, Town::cargo_produced, EconomySettings::cargodest, CargoHasDestinations(), CreateNewLinks(), GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsTownCargo(), CargodestSettings::town_chances_city, and CargodestSettings::town_chances_town.
Referenced by _GenerateWorld(), AfterLoadGame(), OnNewMonth(), and UpdateCargoLinks().
void UpdateExpectedLinks | ( | Industry * | ind | ) |
Updated the desired link count for each cargo.
Definition at line 480 of file cargodest.cpp.
References _settings_game, Industry::average_production, BASE_IND_LINKS, CargodestSettings::base_ind_links, BASE_IND_LINKS_SYMM, BASE_IND_LINKS_TOWN, CARGO_SCALE_IND, CargodestSettings::cargo_scale_ind, CARGO_SCALE_IND_TOWN, EconomySettings::cargodest, CargoHasDestinations(), ClampToU16(), CargoSourceSink::CreateSpecialLinks(), GameSettings::economy, INVALID_CARGO, IsSymmetricCargo(), IsTownCargo(), lengthof, CargoSourceSink::num_links_expected, and Industry::produced_cargo.
void UpdateExpectedLinks | ( | Town * | t | ) |
Updated the desired link count for each cargo.
Definition at line 450 of file cargodest.cpp.
References _settings_game, BASE_TOWN_LINKS, CargodestSettings::base_town_links, BASE_TOWN_LINKS_SYMM, CargodestSettings::big_town_pop, BIG_TOWN_POP_MAIL, BIG_TOWN_POP_PAX, CargoSourceSink::cargo_links, Town::cargo_produced, EconomySettings::cargodest, CargoHasDestinations(), CargodestSettings::city_town_links, ClampToU16(), Town::CreateSpecialLinks(), CargoLink::dest, GameSettings::economy, SmallVector< T, S >::Get(), IsPassengerCargo(), IsSymmetricCargo(), SmallVector< T, S >::Length(), min(), CargoSourceSink::num_links_expected, TransportedCargoStat::old_max, CargodestSettings::pop_scale_town, SCALE_TOWN, SCALE_TOWN_BIG, SCALE_TOWN_BIG_PAX, and SCALE_TOWN_PAX.
Referenced by UpdateCargoLinks().
void UpdateLinkWeights | ( | CargoSourceSink * | css | ) |
Recalculate the link weights.
Definition at line 634 of file cargodest.cpp.
References _settings_game, CargoLink::amount, SmallVector< T, S >::Begin(), CargoSourceSink::cargo_links, CargoSourceSink::cargo_links_weight, EconomySettings::cargodest, GameSettings::economy, SmallVector< T, S >::End(), SmallVector< T, S >::Length(), TransportedCargoStat::NewMonth(), NUM_CARGO, CargodestSettings::random_dest_chance, and CargoLink::weight.
void UpdateLinkWeights | ( | Town * | t | ) |
Recalculate the link weights.
Definition at line 602 of file cargodest.cpp.
References _settings_game, CargoLink::amount, SmallVector< T, S >::Begin(), CargoSourceSink::cargo_links, CargoSourceSink::cargo_links_weight, EconomySettings::cargodest, CargoLink::dest, GameSettings::economy, SmallVector< T, S >::End(), SmallVector< T, S >::Get(), SmallVector< T, S >::Length(), min(), TransportedCargoStat::NewMonth(), NUM_CARGO, CargodestSettings::random_dest_chance, and CargoLink::weight.
Referenced by UpdateCargoLinks().
Update route links after a vehicle has arrived at a station.
v | The vehicle. | |
arrived_at | The station the vehicle arrived at. |
Definition at line 1038 of file cargodest.cpp.
References VehicleCache::cached_cargo_mask, CargoHasDestinations(), Vehicle::current_order, SpecializedStation< Station, false >::Get(), Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_ORDER, Vehicle::last_order_id, Vehicle::last_station_loaded, GoodsEntry::routes, Vehicle::travel_time, UpdateVehicleRouteLinks(), and Vehicle::vcache.
void UpdateVehicleRouteLinks | ( | const Vehicle * | v, | |
uint32 | cargos, | |||
bool | clear_others, | |||
Station * | from, | |||
OrderID | from_oid, | |||
StationID | to_id, | |||
OrderID | to_oid, | |||
uint32 | travel_time | |||
) |
Update or create a single route link for a specific vehicle and cargo.
v | The vehicle. | |
cargos | Create links for the cargo types whose bit is set. | |
clear_others | Should route links for cargo types nor carried be cleared? | |
from | Originating station. | |
from_oid | Originating order. | |
to_id | Destination station ID. | |
to_oid | Destination order. | |
travel_time | Travel time for the route. |
Definition at line 1001 of file cargodest.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_routelink_pool >::CanAllocateItem(), CargoHasDestinations(), Station::goods, HasBit(), Vehicle::owner, GoodsEntry::routes, and BaseVehicle::type.
Referenced by Vehicle::BeginLoading(), PrefillRouteLinks(), and UpdateVehicleRouteLinks().