summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ground_vehicle.cpp3
-rw-r--r--src/roadveh.h137
-rw-r--r--src/saveload/vehicle_sl.cpp1
3 files changed, 138 insertions, 3 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp
index 92c135ee5..419d9483b 100644
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -11,6 +11,7 @@
#include "stdafx.h"
#include "train.h"
+#include "roadveh.h"
#include "ground_vehicle.hpp"
#include "window_type.h"
#include "vehicle_gui.h"
@@ -148,3 +149,5 @@ int GroundVehicle<T, Type>::GetAcceleration() const
/* Instantiation for Train */
template struct GroundVehicle<Train, VEH_TRAIN>;
+/* Instantiation for RoadVehicle */
+template struct GroundVehicle<RoadVehicle, VEH_ROAD>;
diff --git a/src/roadveh.h b/src/roadveh.h
index da01854cc..33866b065 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -12,8 +12,11 @@
#ifndef ROADVEH_H
#define ROADVEH_H
-#include "vehicle_base.h"
#include "road_type.h"
+#include "ground_vehicle.hpp"
+#include "engine_base.h"
+#include "cargotype.h"
+#include "road_map.h"
struct RoadVehicle;
@@ -89,7 +92,7 @@ struct RoadVehicleCache {
/**
* Buses, trucks and trams belong to this class.
*/
-struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
+struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> {
RoadVehicleCache rcache; ///< Cache of often used calculated values
byte state; ///< @see RoadVehicleStates
byte frame;
@@ -103,10 +106,12 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
RoadTypes compatible_roadtypes;
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
- RoadVehicle() : SpecializedVehicle<RoadVehicle, VEH_ROAD>() {}
+ RoadVehicle() : GroundVehicle<RoadVehicle, VEH_ROAD>() {}
/** We want to 'destruct' the right class. */
virtual ~RoadVehicle() { this->PreDestructor(); }
+ friend struct GroundVehicle<RoadVehicle, VEH_ROAD>; // GroundVehicle needs to use the acceleration functions defined at RoadVehicle.
+
const char *GetTypeString() const { return "road vehicle"; }
void MarkDirty();
void UpdateDeltaXY(Direction direction);
@@ -155,6 +160,132 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
* @return True if the engine has an articulated part.
*/
FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
+
+protected: // These functions should not be called outside acceleration code.
+
+ /**
+ * Allows to know the power value that this vehicle will use.
+ * @return Power value from the engine in HP, or zero if the vehicle is not powered.
+ */
+ FORCEINLINE uint16 GetPower() const
+ {
+ /* Power is not added for articulated parts */
+ if (!this->IsArticulatedPart()) {
+ return 10 * RoadVehInfo(this->engine_type)->power; // Road vehicle power is in units of 10 HP.
+ }
+ return 0;
+ }
+
+ /**
+ * Returns a value if this articulated part is powered.
+ * @return Zero, because road vehicles don't have powered parts.
+ */
+ FORCEINLINE uint16 GetPoweredPartPower(const RoadVehicle *head) const
+ {
+ return 0;
+ }
+
+ /**
+ * Allows to know the weight value that this vehicle will use.
+ * @return Weight value from the engine in tonnes.
+ */
+ FORCEINLINE uint16 GetWeight() const
+ {
+ uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count()) / 16;
+
+ /* Vehicle weight is not added for articulated parts. */
+ if (!this->IsArticulatedPart()) {
+ weight += RoadVehInfo(this->engine_type)->weight / 4; // Road vehicle weight is in units of 1/4 t.
+ }
+
+ return weight;
+ }
+
+ /**
+ * Allows to know the tractive effort value that this vehicle will use.
+ * @return Tractive effort value from the engine.
+ */
+ FORCEINLINE byte GetTractiveEffort() const
+ {
+ return RoadVehInfo(this->engine_type)->tractive_effort;
+ }
+
+ /**
+ * Checks the current acceleration status of this vehicle.
+ * @return Acceleration status.
+ */
+ FORCEINLINE AccelStatus GetAccelerationStatus() const
+ {
+ return (this->vehstatus & VS_STOPPED) ? AS_BRAKE : AS_ACCEL;
+ }
+
+ /**
+ * Calculates the current speed of this vehicle.
+ * @return Current speed in mph.
+ */
+ FORCEINLINE uint16 GetCurrentSpeed() const
+ {
+ return this->cur_speed * 10 / 32;
+ }
+
+ /**
+ * Returns the rolling friction coefficient of this vehicle.
+ * @return Rolling friction coefficient in [1e-3].
+ */
+ FORCEINLINE uint32 GetRollingFriction() const
+ {
+ /* Trams have a slightly greater friction coefficient than trains. The rest of road vehicles have bigger values. */
+ return (this->roadtype == ROADTYPE_TRAM) ? 50 : 75;
+ }
+
+ /**
+ * Allows to know the acceleration type of a vehicle.
+ * @return Zero, road vehicles always use a normal acceleration method.
+ */
+ FORCEINLINE int GetAccelerationType() const
+ {
+ return 0;
+ }
+
+ /**
+ * Returns the slope steepness used by this vehicle.
+ * @return Slope steepness used by the vehicle.
+ */
+ FORCEINLINE uint32 GetSlopeSteepness() const
+ {
+ /* Road vehicles use by default a steeper slope than trains. */
+ return 20 * 7; // 1% slope * slope steepness
+ }
+
+ /**
+ * Gets the maximum speed of the vehicle, ignoring the limitations of the kind of track the vehicle is on.
+ * @return Maximum speed of the vehicle.
+ */
+ FORCEINLINE uint16 GetInitialMaxSpeed() const
+ {
+ return this->max_speed;
+ }
+
+ /**
+ * Gets the maximum speed allowed by the track for this vehicle.
+ * @return Since roads don't limit road vehicle speed, it returns always zero.
+ */
+ FORCEINLINE uint16 GetMaxTrackSpeed() const
+ {
+ return 0;
+ }
+
+ /**
+ * Checks if the vehicle is at a tile that can be sloped.
+ * @return True if the tile can be sloped.
+ */
+ FORCEINLINE bool TileMayHaveSlopedTrack() const
+ {
+ if (!IsNormalRoadTile(this->tile)) return false;
+ RoadBits cur_road = GetAllRoadBits(this->tile);
+ /* Any road that isn't ROAD_X or ROAD_Y cannot be sloped. */
+ return cur_road == ROAD_X || cur_road == ROAD_Y;
+ }
};
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 15782f524..5c02573c1 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -563,6 +563,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
SLE_CONDNULL(2, 6, 68),
+ SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, 139, SL_MAX_VERSION),
SLE_CONDNULL(4, 69, 130),
SLE_CONDNULL(2, 6, 130),
/* reserve extra space in savegame here. (currently 16 bytes) */