summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-08-20 21:22:37 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-08-20 21:22:37 +0000
commit5e017b80008ca2e75d80de8a346bf91a6ce6364d (patch)
treed8389fc815525ca4bd6e7ff254aca6bbbd89d251 /src/vehicle.cpp
parent5c0b766ed95bd2d5557e1fa05dfc199ced5a18bf (diff)
downloadopenttd-5e017b80008ca2e75d80de8a346bf91a6ce6364d.tar.xz
(svn r25737) -Codechange: move inner workings of RefreshNextHopsStats into separate function
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp84
1 files changed, 45 insertions, 39 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 9dc2e8844..8dab81559 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2124,48 +2124,27 @@ void Vehicle::ResetRefitCaps()
}
/**
- * Simulated cargo type and capacity for prediction of future links.
- */
-struct RefitDesc {
- CargoID cargo; ///< Cargo type the vehicle will be carrying.
- uint16 capacity; ///< Capacity the vehicle will have.
- uint16 remaining; ///< Capacity remaining from before the previous refit.
- RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
- cargo(cargo), capacity(capacity), remaining(remaining) {}
-};
-
-typedef std::list<RefitDesc> RefitList;
-typedef std::map<CargoID, uint> CapacitiesMap;
-
-/**
* Predict a vehicle's course from its current state and refresh all links it
* will visit.
- */
-void Vehicle::RefreshNextHopsStats()
+ * @param capacities Current added capacities per cargo ID in the consist.
+ * @param refit_capacities Current state of capacity remaining from previous
+ * refits versus overall capacity per vehicle in the consist.
+ * @param first Order that was checked first in the overall run. If this is
+ * encountered again the refreshing is considered finished.
+ * @param cur Last stop where the consist could interact with cargo.
+ * @param next Next order to be checked.
+ * @param hops Number of hops already used up. If more than two times the
+ * number of orders in the list have been checked refreshing is stopped.
+ * @param was_refit If the consist was refit since the last stop where it could
+ * interact with cargo.
+ * @param has_cargo If the consist could leave the last stop where it could
+ * interact with cargo carrying cargo
+ * (i.e. not an "unload all" + "no loading" order).
+ */
+void Vehicle::RefreshNextHopsStats(CapacitiesMap &capacities,
+ RefitList &refit_capacities, const Order *first, const Order *cur,
+ const Order *next, uint hops, bool was_refit, bool has_cargo)
{
- /* Assemble list of capacities and set last loading stations to 0. */
- CapacitiesMap capacities;
- RefitList refit_capacities;
- for (Vehicle *v = this; v != NULL; v = v->Next()) {
- refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
- if (v->refit_cap > 0) capacities[v->cargo_type] += v->refit_cap;
- }
-
- /* If orders were deleted while loading, we're done here.*/
- if (this->orders.list == NULL) return;
-
- const Order *first = this->GetOrder(this->cur_implicit_order_index);
-
- /* Make sure the first order is a useful order. */
- first = this->orders.list->GetNextDecisionNode(first, 0);
- if (first == NULL) return;
-
- const Order *cur = first;
- const Order *next = first;
- bool has_cargo = this->last_loading_station != INVALID_STATION;
- bool was_refit = false;
- uint hops = 0;
-
while (next != NULL) {
/* If the refit cargo is CT_AUTO_REFIT, we're optimistic and assume the
@@ -2276,6 +2255,33 @@ void Vehicle::RefreshNextHopsStats()
}
/**
+ * Predict a vehicle's course from its current state and refresh all links it
+ * will visit.
+ */
+void Vehicle::RefreshNextHopsStats()
+{
+ /* Assemble list of capacities and set last loading stations to 0. */
+ CapacitiesMap capacities;
+ RefitList refit_capacities;
+ for (Vehicle *v = this; v != NULL; v = v->Next()) {
+ refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
+ if (v->refit_cap > 0) capacities[v->cargo_type] += v->refit_cap;
+ }
+
+ /* If orders were deleted while loading, we're done here.*/
+ if (this->orders.list == NULL) return;
+
+ const Order *first = this->GetOrder(this->cur_implicit_order_index);
+
+ /* Make sure the first order is a useful order. */
+ first = this->orders.list->GetNextDecisionNode(first, 0);
+ if (first == NULL) return;
+
+ this->RefreshNextHopsStats(capacities, refit_capacities, first, first,
+ first, 0, false, this->last_loading_station != INVALID_STATION);
+}
+
+/**
* Handle the loading of the vehicle; when not it skips through dummy
* orders and does nothing in all other cases.
* @param mode is the non-first call for this vehicle in this tick?