summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-06-21 16:17:47 +0000
committertruelight <truelight@openttd.org>2007-06-21 16:17:47 +0000
commit56eb1738ee6de39367047a3cd0f20011560eb393 (patch)
tree9a8cf5e86397687ed30d3da2567447b1d843509d /src/vehicle.cpp
parent2792019b78fbfd10702b93a2d570562397cf8cb2 (diff)
downloadopenttd-56eb1738ee6de39367047a3cd0f20011560eb393.tar.xz
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index c00c3fe4a..53bdfdf51 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -229,6 +229,7 @@ void AfterLoadVehicles()
FOR_ALL_VEHICLES(v) {
v->UpdateDeltaXY(v->direction);
+ v->fill_percent_te_id = INVALID_TE_ID;
v->first = NULL;
if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE;
if (v->type == VEH_ROAD) v->u.road.first_engine = INVALID_ENGINE;
@@ -296,6 +297,7 @@ static Vehicle *InitializeVehicle(Vehicle *v)
v->depot_list = NULL;
v->random_bits = 0;
v->group_id = DEFAULT_GROUP;
+ v->fill_percent_te_id = INVALID_TE_ID;
return v;
}
@@ -2263,6 +2265,29 @@ bool IsVehicleInDepot(const Vehicle *v)
return false;
}
+/**
+ * Calculates how full a vehicle is.
+ * @param v The Vehicle to check. For trains, use the first engine.
+ * @return A percentage of how full the Vehicle is.
+ */
+uint8 CalcPercentVehicleFilled(Vehicle *v)
+{
+ int count = 0;
+ int max = 0;
+
+ /* Count up max and used */
+ for (; v != NULL; v = v->next) {
+ count += v->cargo_count;
+ max += v->cargo_cap;
+ }
+
+ /* Train without capacity */
+ if (max == 0) return 100;
+
+ /* Return the percentage */
+ return (count * 100) / max;
+}
+
void VehicleEnterDepot(Vehicle *v)
{
switch (v->type) {
@@ -3107,6 +3132,9 @@ void Vehicle::LeaveStation()
current_order.flags = 0;
GetStation(this->last_station_visited)->loading_vehicles.remove(this);
+ HideFillingPercent(this->fill_percent_te_id);
+ this->fill_percent_te_id = INVALID_TE_ID;
+
UpdateVehicleTimetable(this, false);
}