mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r16718) -Codechange: make IsFreeWagon() member of Train
This commit is contained in:
parent
adc5363202
commit
ecfaa0564d
|
@ -20,7 +20,7 @@
|
|||
/* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
|
||||
return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::IsFreeWagon(v)));
|
||||
return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
|
||||
}
|
||||
|
||||
/* static */ int32 AIVehicle::GetNumWagons(VehicleID vehicle_id)
|
||||
|
|
|
@ -368,7 +368,7 @@ void SetTrainGroupID(Train *v, GroupID new_g)
|
|||
*/
|
||||
void UpdateTrainGroupID(Train *v)
|
||||
{
|
||||
assert(v->IsFrontEngine() || IsFreeWagon(v));
|
||||
assert(v->IsFrontEngine() || v->IsFreeWagon());
|
||||
|
||||
GroupID new_g = v->IsFrontEngine() ? v->group_id : (GroupID)DEFAULT_GROUP;
|
||||
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||
|
|
|
@ -135,7 +135,7 @@ static int MapOldSubType(const Vehicle *v)
|
|||
switch (v->type) {
|
||||
case VEH_TRAIN:
|
||||
if (IsTrainEngine(v)) return 0;
|
||||
if (IsFreeWagon(v)) return 4;
|
||||
if (Train::From(v)->IsFreeWagon()) return 4;
|
||||
return 2;
|
||||
case VEH_ROAD:
|
||||
case VEH_SHIP: return 0;
|
||||
|
|
|
@ -985,7 +985,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
FOR_ALL_TRAINS(v) {
|
||||
if (v->IsFrontEngine() || IsFreeWagon(v)) TrainConsistChanged(v, true);
|
||||
if (v->IsFrontEngine() || v->IsFreeWagon()) TrainConsistChanged(v, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ void ConnectMultiheadedTrains()
|
|||
}
|
||||
|
||||
FOR_ALL_TRAINS(v) {
|
||||
if (v->IsFrontEngine() || IsFreeWagon(v)) {
|
||||
if (v->IsFrontEngine() || v->IsFreeWagon()) {
|
||||
/* Two ways to associate multiheaded parts to each other:
|
||||
* sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>..
|
||||
* bracket-matching: Free vehicle chains shall be arranged to look like ..<..<..>..<..>..>..
|
||||
|
|
11
src/train.h
11
src/train.h
|
@ -327,11 +327,16 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
|
|||
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
||||
|
||||
/**
|
||||
* Check if a vehicle is front engine
|
||||
* @param v vehicle to check
|
||||
* @return Returns true if vehicle is a front engine
|
||||
* Check if train is a front engine
|
||||
* @return Returns true if train is a front engine
|
||||
*/
|
||||
FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, TS_FRONT); }
|
||||
|
||||
/**
|
||||
* 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); }
|
||||
};
|
||||
|
||||
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
|
||||
|
|
|
@ -217,7 +217,7 @@ void TrainConsistChanged(Train *v, bool same_length)
|
|||
{
|
||||
uint16 max_speed = UINT16_MAX;
|
||||
|
||||
assert(v->IsFrontEngine() || IsFreeWagon(v));
|
||||
assert(v->IsFrontEngine() || v->IsFreeWagon());
|
||||
|
||||
const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type);
|
||||
EngineID first_engine = v->IsFrontEngine() ? v->engine_type : INVALID_ENGINE;
|
||||
|
@ -752,7 +752,7 @@ static void NormalizeTrainVehInDepot(const Train *u)
|
|||
{
|
||||
const Train *v;
|
||||
FOR_ALL_TRAINS(v) {
|
||||
if (IsFreeWagon(v) && v->tile == u->tile &&
|
||||
if (v->IsFreeWagon() && v->tile == u->tile &&
|
||||
v->track == TRACK_BIT_DEPOT) {
|
||||
if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
|
||||
CMD_MOVE_RAIL_VEHICLE)))
|
||||
|
@ -1030,7 +1030,7 @@ static void AddWagonToConsist(Train *v, Train *dest)
|
|||
*/
|
||||
static void NormaliseTrainConsist(Train *v)
|
||||
{
|
||||
if (IsFreeWagon(v)) return;
|
||||
if (v->IsFreeWagon()) return;
|
||||
|
||||
assert(v->IsFrontEngine());
|
||||
|
||||
|
@ -4459,7 +4459,7 @@ bool Train::Tick()
|
|||
if (!TrainLocoHandler(this, false)) return false;
|
||||
|
||||
return TrainLocoHandler(this, true);
|
||||
} else if (IsFreeWagon(this) && (this->vehstatus & VS_CRASHED)) {
|
||||
} else if (this->IsFreeWagon() && (this->vehstatus & VS_CRASHED)) {
|
||||
/* Delete flooded standalone wagon chain */
|
||||
if (++this->crash_anim_pos >= 4400) {
|
||||
delete this;
|
||||
|
|
|
@ -27,14 +27,16 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
|
|||
if (v->tile != tile) continue;
|
||||
|
||||
switch (type) {
|
||||
case VEH_TRAIN:
|
||||
if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
|
||||
if (Train::From(v)->track != TRACK_BIT_DEPOT) continue;
|
||||
if (wagons != NULL && IsFreeWagon(v->First())) {
|
||||
if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
|
||||
case VEH_TRAIN: {
|
||||
const Train *t = Train::From(v);
|
||||
if (IsArticulatedPart(t) || IsRearDualheaded(t)) continue;
|
||||
if (t->track != TRACK_BIT_DEPOT) continue;
|
||||
if (wagons != NULL && t->First()->IsFreeWagon()) {
|
||||
if (individual_wagons || t->IsFreeWagon()) *wagons->Append() = t;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (!v->IsInDepot()) continue;
|
||||
|
|
Loading…
Reference in New Issue