12 #include "../stdafx.h" 13 #include "../core/bitmath_func.hpp" 14 #include "../station_func.h" 15 #include "../engine_base.h" 16 #include "../vehicle_func.h" 20 #include "../safeguards.h" 35 if (first == NULL)
return;
38 LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading);
50 if (this->from < other.
from) {
52 }
else if (this->from > other.
from) {
55 if (this->to < other.
to) {
57 }
else if (this->to > other.
to) {
72 vehicle(vehicle), seen_hops(seen_hops),
cargo(
CT_INVALID), allow_merge(allow_merge),
73 is_full_loading(is_full_loading)
78 for (
Vehicle *v = this->vehicle; v != NULL; v = v->
Next()) {
80 if (v->refit_cap > 0) {
82 this->
capacities[v->cargo_type] += v->refit_cap;
94 this->
cargo = refit_cargo;
96 bool any_refit =
false;
99 if (!
HasBit(e->info.refit_mask, this->cargo)) {
106 CargoID temp_cid = v->cargo_type;
107 byte temp_subtype = v->cargo_subtype;
108 v->cargo_type = this->
cargo;
111 uint16 mail_capacity = 0;
115 v->cargo_type = temp_cid;
116 v->cargo_subtype = temp_subtype;
119 if (this->
cargo != refit_it->cargo && refit_it->remaining > 0) {
120 this->
capacities[refit_it->cargo] -= refit_it->remaining;
121 refit_it->remaining = 0;
122 }
else if (amount < refit_it->remaining) {
123 this->
capacities[refit_it->cargo] -= refit_it->remaining - amount;
124 refit_it->remaining = amount;
126 refit_it->capacity = amount;
127 refit_it->cargo = this->
cargo;
133 if (mail_capacity < refit_it->remaining) {
134 this->
capacities[refit_it->cargo] -= refit_it->remaining - mail_capacity;
135 refit_it->remaining = mail_capacity;
137 refit_it->capacity = mail_capacity;
150 if (it->remaining == it->capacity)
continue;
151 this->
capacities[it->cargo] += it->capacity - it->remaining;
152 it->remaining = it->capacity;
177 if (next->
IsType(OT_CONDITIONAL)) {
207 if (st != NULL && next_station != INVALID_STATION && next_station != st->
index) {
212 if (cargo_quantity == 0)
continue;
231 this->vehicle->orders.list->GetTotalDuration() >
263 while (next != NULL) {
291 if (next == NULL)
break;
303 if (!next->
IsType(OT_GOTO_STATION) && !next->
IsType(OT_IMPLICIT))
continue;
311 if (cur->
IsType(OT_GOTO_STATION) || cur->
IsType(OT_IMPLICIT)) {
CargoID cargo
Cargo the consist is probably carrying or CT_INVALID if unknown.
Definition of link refreshing utility.
OrderID from
Last order where vehicle could interact with cargo or absolute first order.
Consist had a chance to load since the last refit and the refit capacities can be reset...
void RefreshStats(const Order *cur, const Order *next)
Refresh link stats for the given pair of orders.
static Titem * Get(size_t index)
Returns Titem with given index.
CargoID cargo
Cargo given in last refit order.
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
bool is_full_loading
If the vehicle is full loading.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Ticks GetTotalDuration() const
Gets the known duration of the vehicles orders, timetabled or not.
OrderList * list
Pointer to the order list for this vehicle.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
uint32 current_order_time
How many ticks have passed since this order started.
Tindex index
Index of this pool item.
StationID last_station_visited
The last station we stopped at.
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
const Order * GetNextDecisionNode(const Order *next, uint hops) const
Get the next order which will make the given vehicle stop at a station or refit at a depot or evaluat...
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Consist could leave the last stop where it could interact with cargo carrying cargo (i...
Order * GetOrderAt(int index) const
Get a certain order of the order chain.
bool IsAutoRefit() const
Is this order a auto-refit order.
Vehicle * vehicle
Vehicle for which the links should be refreshed.
uint capacities[NUM_CARGO]
Current added capacities per cargo ID in the consist.
LinkGraphID link_graph
Link graph this station belongs to.
bool IsRefit() const
Is this order a refit order.
bool operator<(const Hop &other) const
Comparison operator to allow hops to be used in a std::set.
bool IsType(OrderType type) const
Check whether this order is of the given type.
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
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.
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
OrderID to
Next order to be processed.
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
HopSet * seen_hops
Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Re...
const Order * PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
Predict the next order the vehicle will execute and resolve conditionals by recursion and return next...
Currently doing an autorefit loop. Ignore the first autorefit order.
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
void RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
A hop the refresh algorithm might evaluate.
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity=NULL) const
Determines capacity of a given vehicle from scratch.
const Order * GetNext(const Order *curr) const
Get the order after the given one or the first one, if the given one is the last one.
Maximal number of cargo types in a game.
EdgeUpdateMode
Special modes for updating links.
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
DestinationID GetDestination() const
Gets the destination of this order.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Vehicle * Next() const
Get the next vehicle of this vehicle.
bool HandleRefit(CargoID refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
int32 Ticks
The type to store ticks in.
There was a conditional jump. Try to use the given next order when looking for a new one...
Declaration of link graph classes used for cargo distribution.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or NULL when it doesn't exists.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
byte CargoID
Cargo slots to indicate a cargo type within a game.
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
Simulated cargo type and capacity for prediction of future links.
static Station * Get(size_t index)
Gets station with given index.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Consist was refit since the last stop where it could interact with cargo.
Utility to refresh links a consist will visit.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.