2005-11-18 23:41:03 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file train.h Base for the train class. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2005-11-18 23:41:03 +00:00
|
|
|
#ifndef TRAIN_H
|
|
|
|
#define TRAIN_H
|
|
|
|
|
2010-01-16 22:30:04 +00:00
|
|
|
#include "newgrf_engine.h"
|
|
|
|
#include "cargotype.h"
|
|
|
|
#include "rail.h"
|
|
|
|
#include "engine_base.h"
|
|
|
|
#include "rail_map.h"
|
2010-03-06 12:41:18 +00:00
|
|
|
#include "ground_vehicle.hpp"
|
2005-11-18 23:41:03 +00:00
|
|
|
|
2009-05-22 22:22:46 +00:00
|
|
|
struct Train;
|
2005-11-18 23:41:03 +00:00
|
|
|
|
2009-05-22 22:33:05 +00:00
|
|
|
enum VehicleRailFlags {
|
|
|
|
VRF_REVERSING = 0,
|
|
|
|
|
|
|
|
/* used to store if a wagon is powered or not */
|
|
|
|
VRF_POWEREDWAGON = 3,
|
|
|
|
|
|
|
|
/* used to reverse the visible direction of the vehicle */
|
|
|
|
VRF_REVERSE_DIRECTION = 4,
|
|
|
|
|
|
|
|
/* used to mark train as lost because PF can't find the route */
|
|
|
|
VRF_NO_PATH_TO_DESTINATION = 5,
|
|
|
|
|
|
|
|
/* used to mark that electric train engine is allowed to run on normal rail */
|
|
|
|
VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6,
|
|
|
|
|
|
|
|
/* used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only) */
|
|
|
|
VRF_TOGGLE_REVERSE = 7,
|
|
|
|
|
|
|
|
/* used to mark a train that can't get a path reservation */
|
|
|
|
VRF_TRAIN_STUCK = 8,
|
2010-07-09 14:14:17 +00:00
|
|
|
|
|
|
|
/* used to mark a train that is just leaving a station */
|
|
|
|
VRF_LEAVING_STATION = 9,
|
2009-05-22 22:33:05 +00:00
|
|
|
};
|
|
|
|
|
2010-06-21 17:35:27 +00:00
|
|
|
/** Modes for ignoring signals. */
|
|
|
|
enum TrainForceProceeding {
|
|
|
|
TFP_NONE = 0, ///< Normal operation.
|
|
|
|
TFP_STUCK = 1, ///< Proceed till next signal, but ignore being stuck till then. This includes force leaving depots.
|
|
|
|
TFP_SIGNAL = 2, ///< Ignore next signal, after the signal ignore being stucked.
|
|
|
|
};
|
|
|
|
typedef SimpleTinyEnumT<TrainForceProceeding, byte> TrainForceProceedingByte;
|
|
|
|
|
2009-05-22 22:22:46 +00:00
|
|
|
byte FreightWagonMult(CargoID cargo);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-05-22 22:55:41 +00:00
|
|
|
/** Variables that are cached to improve performance and such */
|
2010-03-06 12:42:53 +00:00
|
|
|
struct TrainCache {
|
2009-05-22 22:55:41 +00:00
|
|
|
/* Cached wagon override spritegroup */
|
|
|
|
const struct SpriteGroup *cached_override;
|
|
|
|
|
|
|
|
uint16 last_speed; // NOSAVE: only used in UI
|
|
|
|
|
|
|
|
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
|
2010-01-30 10:41:15 +00:00
|
|
|
uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
|
|
|
|
uint8 cached_veh_length; ///< length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
|
|
|
|
bool cached_tilt; ///< train can tilt; feature provides a bonus in curves
|
2009-05-22 22:55:41 +00:00
|
|
|
|
2009-06-01 13:14:56 +00:00
|
|
|
/* cached max. speed / acceleration data */
|
|
|
|
uint16 cached_max_speed; ///< max speed of the consist. (minimum of the max speed of all vehicles in the consist)
|
|
|
|
int cached_max_curve_speed; ///< max consist speed limited by curves
|
|
|
|
|
2009-05-22 22:55:41 +00:00
|
|
|
/**
|
|
|
|
* Position/type of visual effect.
|
|
|
|
* bit 0 - 3 = position of effect relative to vehicle. (0 = front, 8 = centre, 15 = rear)
|
|
|
|
* bit 4 - 5 = type of effect. (0 = default for engine class, 1 = steam, 2 = diesel, 3 = electric)
|
|
|
|
* bit 6 = disable visual effect.
|
|
|
|
* bit 7 = disable powered wagons.
|
|
|
|
*/
|
|
|
|
byte cached_vis_effect;
|
|
|
|
byte user_def_data;
|
|
|
|
|
2009-10-04 04:57:01 +00:00
|
|
|
EngineID first_engine; ///< cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
|
2009-05-22 22:55:41 +00:00
|
|
|
};
|
|
|
|
|
2009-05-22 22:22:46 +00:00
|
|
|
/**
|
2009-05-26 23:24:34 +00:00
|
|
|
* 'Train' is either a loco or a wagon.
|
2009-05-22 22:22:46 +00:00
|
|
|
*/
|
2010-03-06 12:41:18 +00:00
|
|
|
struct Train : public GroundVehicle<Train, VEH_TRAIN> {
|
2009-05-22 22:55:41 +00:00
|
|
|
TrainCache tcache;
|
|
|
|
|
2009-05-22 22:33:05 +00:00
|
|
|
/* Link between the two ends of a multiheaded engine */
|
|
|
|
Train *other_multiheaded_part;
|
|
|
|
|
|
|
|
uint16 crash_anim_pos;
|
|
|
|
|
|
|
|
uint16 flags;
|
|
|
|
TrackBitsByte track;
|
2010-06-21 17:35:27 +00:00
|
|
|
TrainForceProceedingByte force_proceed;
|
2009-05-22 22:33:05 +00:00
|
|
|
RailTypeByte railtype;
|
|
|
|
RailTypes compatible_railtypes;
|
|
|
|
|
2010-01-09 14:43:08 +00:00
|
|
|
/** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */
|
|
|
|
uint16 wait_counter;
|
|
|
|
|
2009-06-02 19:12:28 +00:00
|
|
|
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
|
2010-03-06 12:41:18 +00:00
|
|
|
Train() : GroundVehicle<Train, VEH_TRAIN>() {}
|
2009-05-22 22:22:46 +00:00
|
|
|
/** We want to 'destruct' the right class. */
|
|
|
|
virtual ~Train() { this->PreDestructor(); }
|
|
|
|
|
2010-03-06 12:44:30 +00:00
|
|
|
friend struct GroundVehicle<Train, VEH_TRAIN>; // GroundVehicle needs to use the acceleration functions defined at Train.
|
|
|
|
|
2009-05-22 22:22:46 +00:00
|
|
|
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;
|
2009-07-01 22:22:01 +00:00
|
|
|
bool IsPrimaryVehicle() const { return this->IsFrontEngine(); }
|
2009-05-22 22:22:46 +00:00
|
|
|
SpriteID GetImage(Direction direction) const;
|
2009-05-22 22:55:41 +00:00
|
|
|
int GetDisplaySpeed() const { return this->tcache.last_speed; }
|
|
|
|
int GetDisplayMaxSpeed() const { return this->tcache.cached_max_speed; }
|
2009-05-22 22:22:46 +00:00
|
|
|
Money GetRunningCost() const;
|
2009-07-17 22:00:13 +00:00
|
|
|
int GetDisplayImageWidth(Point *offset = NULL) const;
|
2009-12-13 17:13:20 +00:00
|
|
|
bool IsInDepot() const;
|
|
|
|
bool IsStoppedInDepot() const;
|
2009-05-22 22:22:46 +00:00
|
|
|
bool Tick();
|
|
|
|
void OnNewDay();
|
2009-12-04 20:29:46 +00:00
|
|
|
uint Crash(bool flooded = false);
|
2009-05-22 22:22:46 +00:00
|
|
|
Trackdir GetVehicleTrackdir() const;
|
|
|
|
TileIndex GetOrderStationLocation(StationID station);
|
|
|
|
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
2009-07-01 22:22:01 +00:00
|
|
|
|
2009-07-17 13:54:06 +00:00
|
|
|
void ReserveTrackUnderConsist() const;
|
2010-01-15 18:23:52 +00:00
|
|
|
|
|
|
|
int GetCurveSpeedLimit() const;
|
|
|
|
|
|
|
|
void ConsistChanged(bool same_length);
|
|
|
|
|
2010-08-15 19:59:48 +00:00
|
|
|
void RailtypeChanged();
|
|
|
|
|
2010-01-16 22:16:28 +00:00
|
|
|
int UpdateSpeed();
|
|
|
|
|
2010-01-15 18:23:52 +00:00
|
|
|
void UpdateAcceleration();
|
2009-07-02 12:10:39 +00:00
|
|
|
|
2010-01-16 22:30:04 +00:00
|
|
|
int GetCurrentMaxSpeed() const;
|
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* enum to handle train subtypes
|
|
|
|
* Do not access it directly unless you have to. Use the access functions below
|
|
|
|
* This is an enum to tell what bit to access as it is a bitmask
|
|
|
|
*/
|
|
|
|
enum TrainSubtype {
|
|
|
|
TS_FRONT = 0, ///< Leading engine of a train
|
|
|
|
TS_ARTICULATED_PART = 1, ///< Articulated part of an engine
|
|
|
|
TS_WAGON = 2, ///< Wagon
|
|
|
|
TS_ENGINE = 3, ///< Engine, that can be front engine, but might be placed behind another engine
|
|
|
|
TS_FREE_WAGON = 4, ///< First in a wagon chain (in depot)
|
|
|
|
TS_MULTIHEADED = 5, ///< Engine is multiheaded
|
|
|
|
};
|
|
|
|
|
2009-07-02 00:17:27 +00:00
|
|
|
/**
|
|
|
|
* Set front engine state
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, TS_FRONT); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the front engine state
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, TS_FRONT); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a vehicle to be an articulated part
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, TS_ARTICULATED_PART); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a vehicle from being an articulated part
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, TS_ARTICULATED_PART); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a vehicle to be a wagon
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetWagon() { SetBit(this->subtype, TS_WAGON); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear wagon property
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearWagon() { ClrBit(this->subtype, TS_WAGON); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set engine status
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetEngine() { SetBit(this->subtype, TS_ENGINE); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear engine status
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearEngine() { ClrBit(this->subtype, TS_ENGINE); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set if a vehicle is a free wagon
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, TS_FREE_WAGON); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a vehicle from being a free wagon
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, TS_FREE_WAGON); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set if a vehicle is a multiheaded engine
|
|
|
|
*/
|
|
|
|
FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, TS_MULTIHEADED); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear multiheaded engine property
|
|
|
|
*/
|
|
|
|
FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, TS_MULTIHEADED); }
|
|
|
|
|
|
|
|
|
2009-07-01 22:22:01 +00:00
|
|
|
/**
|
2009-07-01 23:49:13 +00:00
|
|
|
* Check if train is a front engine
|
|
|
|
* @return Returns true if train is a front engine
|
2009-07-01 22:22:01 +00:00
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, TS_FRONT); }
|
2009-07-01 23:49:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if train is a free wagon (got no engine in front of it)
|
|
|
|
* @return Returns true if train is a free wagon
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsFreeWagon() const { return HasBit(this->subtype, TS_FREE_WAGON); }
|
2009-07-01 23:57:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a vehicle is an engine (can be first in a train)
|
|
|
|
* @return Returns true if vehicle is an engine
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsEngine() const { return HasBit(this->subtype, TS_ENGINE); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a train is a wagon
|
|
|
|
* @return Returns true if vehicle is a wagon
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsWagon() const { return HasBit(this->subtype, TS_WAGON); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if train is a multiheaded engine
|
|
|
|
* @return Returns true if vehicle is a multiheaded engine
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsMultiheaded() const { return HasBit(this->subtype, TS_MULTIHEADED); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell if we are dealing with the rear end of a multiheaded engine.
|
|
|
|
* @return True if the engine is the rear part of a dualheaded engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsRearDualheaded() const { return this->IsMultiheaded() && !this->IsEngine(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if train is an articulated part of an engine
|
|
|
|
* @return Returns true if train is an articulated part
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsArticulatedPart() const { return HasBit(this->subtype, TS_ARTICULATED_PART); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an engine has an articulated part.
|
|
|
|
* @return True if the engine has an articulated part.
|
|
|
|
*/
|
2009-07-02 09:06:15 +00:00
|
|
|
FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
|
2009-07-01 23:57:20 +00:00
|
|
|
|
2009-05-22 22:22:46 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* Get the next part of a multi-part engine.
|
|
|
|
* Will only work on a multi-part engine (this->EngineHasArticPart() == true),
|
|
|
|
* Result is undefined for normal engine.
|
|
|
|
* @return next part of articulated engine
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetNextArticPart() const
|
|
|
|
{
|
|
|
|
assert(this->HasArticulatedPart());
|
|
|
|
return this->Next();
|
|
|
|
}
|
2009-05-26 22:10:13 +00:00
|
|
|
|
2009-07-19 19:17:41 +00:00
|
|
|
/**
|
|
|
|
* Get the first part of a multi-part engine.
|
|
|
|
* @return First part of the engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetFirstEnginePart()
|
|
|
|
{
|
|
|
|
Train *v = this;
|
|
|
|
while (v->IsArticulatedPart()) v = v->Previous();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first part of a multi-part engine.
|
|
|
|
* @return First part of the engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE const Train *GetFirstEnginePart() const
|
|
|
|
{
|
|
|
|
const Train *v = this;
|
|
|
|
while (v->IsArticulatedPart()) v = v->Previous();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* Get the last part of a multi-part engine.
|
|
|
|
* @return Last part of the engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetLastEnginePart()
|
|
|
|
{
|
|
|
|
Train *v = this;
|
|
|
|
while (v->HasArticulatedPart()) v = v->GetNextArticPart();
|
|
|
|
return v;
|
|
|
|
}
|
2006-08-26 14:22:54 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* Get the next real (non-articulated part) vehicle in the consist.
|
|
|
|
* @return Next vehicle in the consist.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetNextVehicle() const
|
|
|
|
{
|
|
|
|
const Train *v = this;
|
|
|
|
while (v->HasArticulatedPart()) v = v->GetNextArticPart();
|
2006-08-26 14:22:54 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/* v now contains the last artic part in the engine */
|
|
|
|
return v->Next();
|
|
|
|
}
|
2008-08-16 14:02:20 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* Get the previous real (non-articulated part) vehicle in the consist.
|
|
|
|
* @return Previous vehicle in the consist.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetPrevVehicle() const
|
|
|
|
{
|
|
|
|
Train *v = this->Previous();
|
|
|
|
while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
|
2008-08-16 14:02:20 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
return v;
|
|
|
|
}
|
2007-09-05 10:33:42 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
/**
|
|
|
|
* Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
|
|
|
|
* @return Next vehicle in the consist.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetNextUnit() const
|
|
|
|
{
|
|
|
|
Train *v = this->GetNextVehicle();
|
|
|
|
if (v != NULL && v->IsRearDualheaded()) v = v->GetNextVehicle();
|
2007-09-05 10:33:42 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
|
|
|
|
* @return Previous vehicle in the consist.
|
|
|
|
*/
|
|
|
|
FORCEINLINE Train *GetPrevUnit()
|
|
|
|
{
|
|
|
|
Train *v = this->GetPrevVehicle();
|
|
|
|
if (v != NULL && v->IsRearDualheaded()) v = v->GetPrevVehicle();
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
2010-01-16 22:30:04 +00:00
|
|
|
|
|
|
|
|
2010-02-10 21:06:05 +00:00
|
|
|
protected: // These functions should not be called outside acceleration code.
|
2010-01-16 22:30:04 +00:00
|
|
|
|
2010-08-15 19:59:48 +00:00
|
|
|
void UpdateVisualEffect(bool allow_power_change);
|
2010-08-15 19:53:53 +00:00
|
|
|
|
2010-01-16 22:30:04 +00:00
|
|
|
/**
|
|
|
|
* 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() && HasPowerOnRail(this->railtype, GetRailType(this->tile))) {
|
|
|
|
uint16 power = GetVehicleProperty(this, PROP_TRAIN_POWER, RailVehInfo(this->engine_type)->power);
|
|
|
|
/* Halve power for multiheaded parts */
|
|
|
|
if (this->IsMultiheaded()) power /= 2;
|
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a value if this articulated part is powered.
|
|
|
|
* @return Power value from the articulated part in HP, or zero if it is not powered.
|
|
|
|
*/
|
|
|
|
FORCEINLINE uint16 GetPoweredPartPower(const Train *head) const
|
|
|
|
{
|
2010-08-15 18:35:57 +00:00
|
|
|
/* For powered wagons the engine defines the type of engine (i.e. railtype) */
|
|
|
|
if (HasBit(this->flags, VRF_POWEREDWAGON) && HasPowerOnRail(head->railtype, GetRailType(this->tile))) {
|
2010-01-16 22:30:04 +00:00
|
|
|
return RailVehInfo(this->tcache.first_engine)->pow_wag_power;
|
|
|
|
}
|
|
|
|
|
|
|
|
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() * FreightWagonMult(this->cargo_type)) / 16;
|
|
|
|
|
|
|
|
/* Vehicle weight is not added for articulated parts. */
|
|
|
|
if (!this->IsArticulatedPart()) {
|
|
|
|
weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Powered wagons have extra weight added. */
|
|
|
|
if (HasBit(this->flags, VRF_POWEREDWAGON)) {
|
|
|
|
weight += RailVehInfo(this->tcache.first_engine)->pow_wag_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 GetVehicleProperty(this, PROP_TRAIN_TRACTIVE_EFFORT, RailVehInfo(this->engine_type)->tractive_effort);
|
|
|
|
}
|
|
|
|
|
2010-08-02 14:49:23 +00:00
|
|
|
/**
|
|
|
|
* Gets the area used for calculating air drag.
|
|
|
|
* @return Area of the engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE byte GetAirDragArea() const
|
|
|
|
{
|
|
|
|
return 120;
|
|
|
|
}
|
|
|
|
|
2010-08-02 14:52:51 +00:00
|
|
|
/**
|
|
|
|
* Gets the air drag coefficient of this vehicle.
|
|
|
|
* @return Air drag value from the engine.
|
|
|
|
*/
|
|
|
|
FORCEINLINE byte GetAirDrag() const
|
|
|
|
{
|
|
|
|
return RailVehInfo(this->engine_type)->air_drag;
|
|
|
|
}
|
|
|
|
|
2010-01-16 22:30:04 +00:00
|
|
|
/**
|
|
|
|
* Checks the current acceleration status of this vehicle.
|
|
|
|
* @return Acceleration status.
|
|
|
|
*/
|
2010-01-17 23:03:43 +00:00
|
|
|
FORCEINLINE AccelStatus GetAccelerationStatus() const
|
2010-01-16 22:30:04 +00:00
|
|
|
{
|
2010-01-17 23:03:43 +00:00
|
|
|
return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
|
2010-01-16 22:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the current speed of this vehicle.
|
|
|
|
* @return Current speed in mph.
|
|
|
|
*/
|
|
|
|
FORCEINLINE uint16 GetCurrentSpeed() const
|
|
|
|
{
|
|
|
|
return this->cur_speed * 10 / 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rolling friction coefficient of this vehicle.
|
|
|
|
* @return Rolling friction coefficient in [1e-3].
|
|
|
|
*/
|
|
|
|
FORCEINLINE uint32 GetRollingFriction() const
|
|
|
|
{
|
|
|
|
return 35;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows to know the acceleration type of a vehicle.
|
|
|
|
* @return Acceleration type of the vehicle.
|
|
|
|
*/
|
|
|
|
FORCEINLINE int GetAccelerationType() const
|
|
|
|
{
|
|
|
|
return GetRailTypeInfo(this->railtype)->acceleration_type;
|
|
|
|
}
|
2010-01-28 20:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the slope steepness used by this vehicle.
|
|
|
|
* @return Slope steepness used by the vehicle.
|
|
|
|
*/
|
|
|
|
FORCEINLINE uint32 GetSlopeSteepness() const
|
|
|
|
{
|
|
|
|
return 20 * _settings_game.vehicle.train_slope_steepness; // 1% slope * slope steepness
|
|
|
|
}
|
2010-03-06 12:27:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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->tcache.cached_max_speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum speed allowed by the track for this vehicle.
|
|
|
|
* @return Maximum speed allowed.
|
|
|
|
*/
|
|
|
|
FORCEINLINE uint16 GetMaxTrackSpeed() const
|
|
|
|
{
|
|
|
|
return GetRailTypeInfo(GetRailType(this->tile))->max_speed;
|
|
|
|
}
|
2010-03-06 12:52:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the vehicle is at a tile that can be sloped.
|
|
|
|
* @return True if the tile can be sloped.
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool TileMayHaveSlopedTrack() const
|
|
|
|
{
|
|
|
|
/* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. */
|
|
|
|
return this->track == TRACK_BIT_X || this->track == TRACK_BIT_Y;
|
|
|
|
}
|
2009-07-02 12:10:39 +00:00
|
|
|
};
|
2008-08-16 14:02:20 +00:00
|
|
|
|
2009-07-02 12:10:39 +00:00
|
|
|
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
|
2008-08-16 14:02:20 +00:00
|
|
|
|
2005-11-18 23:41:03 +00:00
|
|
|
#endif /* TRAIN_H */
|