summaryrefslogtreecommitdiff
path: root/src/train.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-22 22:22:46 +0000
committerrubidium <rubidium@openttd.org>2009-05-22 22:22:46 +0000
commit80e94b9bb15f846189e98f1f457afe2b96ba2b58 (patch)
treeb623c3e1cc75771986452340a138bd3ac60d4cbc /src/train.h
parent7a37220881c995f317bf5bd0f3077fa6c9e9d098 (diff)
downloadopenttd-80e94b9bb15f846189e98f1f457afe2b96ba2b58.tar.xz
(svn r16391) -Codechange: use Train instead of Vehicle where appropriate.
Diffstat (limited to 'src/train.h')
-rw-r--r--src/train.h147
1 files changed, 79 insertions, 68 deletions
diff --git a/src/train.h b/src/train.h
index 4fa431d90..86c8c8a21 100644
--- a/src/train.h
+++ b/src/train.h
@@ -9,6 +9,7 @@
#include "core/bitmath_func.hpp"
#include "vehicle_base.h"
+struct Train;
/** enum to handle train subtypes
* Do not access it directly unless you have to. Use the access functions below
@@ -202,12 +203,81 @@ static inline bool EngineHasArticPart(const Vehicle *v)
return (v->Next() != NULL && IsArticulatedPart(v->Next()));
}
+/** Tell if we are dealing with the rear end of a multiheaded engine.
+ * @param v Vehicle.
+ * @return True if the engine is the rear part of a dualheaded engine.
+ */
+static inline bool IsRearDualheaded(const Vehicle *v)
+{
+ assert(v->type == VEH_TRAIN);
+ return (IsMultiheaded(v) && !IsTrainEngine(v));
+}
+
+void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
+void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
+
+byte FreightWagonMult(CargoID cargo);
+
+int CheckTrainInDepot(const Train *v, bool needs_to_be_stopped);
+int CheckTrainStoppedInDepot(const Train *v);
+void UpdateTrainAcceleration(Train *v);
+void CheckTrainsLengths();
+
+void FreeTrainTrackReservation(const Train *v, TileIndex origin = INVALID_TILE, Trackdir orig_td = INVALID_TRACKDIR);
+bool TryPathReserve(Train *v, bool mark_as_stuck = false, bool first_tile_okay = false);
+
+int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length);
+
+void TrainConsistChanged(Train *v, bool same_length);
+void TrainPowerChanged(Train *v);
+Money GetTrainRunningCost(const Train *v);
+
+/**
+ * This class 'wraps' Vehicle; you do not actually instantiate this class.
+ * You create a Vehicle using AllocateVehicle, so it is added to the pool
+ * and you reinitialize that to a Train using:
+ * v = new (v) Train();
+ *
+ * As side-effect the vehicle type is set correctly.
+ */
+struct Train : public Vehicle {
+ /** Initializes the Vehicle to a train */
+ Train() { this->type = VEH_TRAIN; }
+
+ /** We want to 'destruct' the right class. */
+ virtual ~Train() { this->PreDestructor(); }
+
+ const char *GetTypeString() const { return "train"; }
+ void MarkDirty();
+ void UpdateDeltaXY(Direction direction);
+ ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
+ void PlayLeaveStationSound() const;
+ bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
+ SpriteID GetImage(Direction direction) const;
+ int GetDisplaySpeed() const { return this->u.rail.last_speed; }
+ int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed; }
+ Money GetRunningCost() const;
+ bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
+ bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
+ bool Tick();
+ void OnNewDay();
+ Trackdir GetVehicleTrackdir() const;
+ TileIndex GetOrderStationLocation(StationID station);
+ bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
+ Train *First() { return (Train *)this->Vehicle::First(); }
+ Train *First() const { return (Train *)this->Vehicle::First(); }
+ Train *Next() { return (Train *)this->Vehicle::Next(); }
+ Train *Next() const { return (Train *)this->Vehicle::Next(); }
+ Train *Previous() { return (Train *)this->Vehicle::Previous(); }
+ Train *Previous() const { return (Train *)this->Vehicle::Previous(); }
+};
+
/**
* Get the next part of a multi-part engine.
* Will only work on a multi-part engine (EngineHasArticPart(v) == true),
* Result is undefined for normal engine.
*/
-static inline Vehicle *GetNextArticPart(const Vehicle *v)
+static inline Train *GetNextArticPart(const Train *v)
{
assert(EngineHasArticPart(v));
return v->Next();
@@ -217,28 +287,18 @@ static inline Vehicle *GetNextArticPart(const Vehicle *v)
* @param v Vehicle.
* @return Last part of the engine.
*/
-static inline Vehicle *GetLastEnginePart(Vehicle *v)
+static inline Train *GetLastEnginePart(Train *v)
{
assert(v->type == VEH_TRAIN);
while (EngineHasArticPart(v)) v = GetNextArticPart(v);
return v;
}
-/** Tell if we are dealing with the rear end of a multiheaded engine.
- * @param v Vehicle.
- * @return True if the engine is the rear part of a dualheaded engine.
- */
-static inline bool IsRearDualheaded(const Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- return (IsMultiheaded(v) && !IsTrainEngine(v));
-}
-
/** Get the next real (non-articulated part) vehicle in the consist.
* @param v Vehicle.
* @return Next vehicle in the consist.
*/
-static inline Vehicle *GetNextVehicle(const Vehicle *v)
+static inline Train *GetNextVehicle(const Train *v)
{
assert(v->type == VEH_TRAIN);
while (EngineHasArticPart(v)) v = GetNextArticPart(v);
@@ -251,11 +311,11 @@ static inline Vehicle *GetNextVehicle(const Vehicle *v)
* @param w Vehicle.
* @return Previous vehicle in the consist.
*/
-static inline Vehicle *GetPrevVehicle(const Vehicle *w)
+static inline Train *GetPrevVehicle(const Train *w)
{
assert(w->type == VEH_TRAIN);
- Vehicle *v = w->Previous();
+ Train *v = w->Previous();
while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
return v;
@@ -265,10 +325,10 @@ static inline Vehicle *GetPrevVehicle(const Vehicle *w)
* @param v Vehicle.
* @return Next vehicle in the consist.
*/
-static inline Vehicle *GetNextUnit(const Vehicle *v)
+static inline Train *GetNextUnit(const Train *v)
{
assert(v->type == VEH_TRAIN);
- Vehicle *w = GetNextVehicle(v);
+ Train *w = GetNextVehicle(v);
if (w != NULL && IsRearDualheaded(w)) w = GetNextVehicle(w);
return w;
@@ -278,62 +338,13 @@ static inline Vehicle *GetNextUnit(const Vehicle *v)
* @param v Vehicle.
* @return Previous vehicle in the consist.
*/
-static inline Vehicle *GetPrevUnit(const Vehicle *v)
+static inline Train *GetPrevUnit(const Train *v)
{
assert(v->type == VEH_TRAIN);
- Vehicle *w = GetPrevVehicle(v);
+ Train *w = GetPrevVehicle(v);
if (w != NULL && IsRearDualheaded(w)) w = GetPrevVehicle(w);
return w;
}
-void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
-void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
-
-byte FreightWagonMult(CargoID cargo);
-
-int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
-int CheckTrainStoppedInDepot(const Vehicle *v);
-void UpdateTrainAcceleration(Vehicle *v);
-void CheckTrainsLengths();
-
-void FreeTrainTrackReservation(const Vehicle *v, TileIndex origin = INVALID_TILE, Trackdir orig_td = INVALID_TRACKDIR);
-bool TryPathReserve(Vehicle *v, bool mark_as_stuck = false, bool first_tile_okay = false);
-
-int GetTrainStopLocation(StationID station_id, TileIndex tile, const Vehicle *v, int *station_ahead, int *station_length);
-
-/**
- * This class 'wraps' Vehicle; you do not actually instantiate this class.
- * You create a Vehicle using AllocateVehicle, so it is added to the pool
- * and you reinitialize that to a Train using:
- * v = new (v) Train();
- *
- * As side-effect the vehicle type is set correctly.
- */
-struct Train : public Vehicle {
- /** Initializes the Vehicle to a train */
- Train() { this->type = VEH_TRAIN; }
-
- /** We want to 'destruct' the right class. */
- virtual ~Train() { this->PreDestructor(); }
-
- const char *GetTypeString() const { return "train"; }
- void MarkDirty();
- void UpdateDeltaXY(Direction direction);
- ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
- void PlayLeaveStationSound() const;
- bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
- SpriteID GetImage(Direction direction) const;
- int GetDisplaySpeed() const { return this->u.rail.last_speed; }
- int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed; }
- Money GetRunningCost() const;
- bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
- bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
- bool Tick();
- void OnNewDay();
- Trackdir GetVehicleTrackdir() const;
- TileIndex GetOrderStationLocation(StationID station);
- bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
-};
-
#endif /* TRAIN_H */