mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r16894) -Codechange: Add [Specialised]Vehicle::Last().
This commit is contained in:
parent
e3752f3ef8
commit
d5a4c89365
@ -151,7 +151,7 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh
|
||||
if (v == wagon) return;
|
||||
|
||||
if (wagon == NULL) {
|
||||
if (head != NULL) wagon = GetLastVehicleInChain(head);
|
||||
if (head != NULL) wagon = head->Last();
|
||||
} else {
|
||||
wagon = wagon->Previous();
|
||||
if (wagon == NULL) return;
|
||||
|
@ -704,7 +704,7 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
|
||||
if (w->tile == tile && w->IsFreeWagon() &&
|
||||
w->engine_type == engine &&
|
||||
!(w->vehstatus & VS_CRASHED)) {
|
||||
u = GetLastVehicleInChain(w);
|
||||
u = w->Last();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1829,7 +1829,7 @@ static void AdvanceWagonsBeforeSwap(Train *v)
|
||||
{
|
||||
Train *base = v;
|
||||
Train *first = base; // first vehicle to move
|
||||
Train *last = Train::From(GetLastVehicleInChain(v)); // last vehicle to move
|
||||
Train *last = v->Last(); // last vehicle to move
|
||||
uint length = CountVehiclesInChain(v);
|
||||
|
||||
while (length > 2) {
|
||||
@ -1878,7 +1878,7 @@ static void AdvanceWagonsAfterSwap(Train *v)
|
||||
|
||||
Train *base = v;
|
||||
Train *first = base; // first vehicle to move
|
||||
Train *last = Train::From(GetLastVehicleInChain(v)); // last vehicle to move
|
||||
Train *last = v->Last(); // last vehicle to move
|
||||
uint length = CountVehiclesInChain(v);
|
||||
|
||||
/* we have to make sure all wagons that leave a depot because of train reversing are moved coorectly
|
||||
@ -2219,7 +2219,7 @@ static TrainFindDepotData FindClosestTrainDepot(Train *v, int max_distance)
|
||||
} break;
|
||||
|
||||
case VPF_NPF: { // NPF
|
||||
const Vehicle *last = GetLastVehicleInChain(v);
|
||||
const Vehicle *last = v->Last();
|
||||
Trackdir trackdir = v->GetVehicleTrackdir();
|
||||
Trackdir trackdir_rev = ReverseTrackdir(last->GetVehicleTrackdir());
|
||||
|
||||
@ -3225,7 +3225,7 @@ static bool CheckReverseTrain(Train *v)
|
||||
case VPF_NPF: { // NPF
|
||||
NPFFindStationOrTileData fstd;
|
||||
NPFFoundTargetData ftd;
|
||||
Vehicle *last = GetLastVehicleInChain(v);
|
||||
Vehicle *last = v->Last();
|
||||
|
||||
NPFFillWithOrderData(&fstd, v);
|
||||
|
||||
|
@ -35,7 +35,7 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||
|
||||
/* if we found a loco, */
|
||||
if (found != NULL) {
|
||||
found = GetLastVehicleInChain(found);
|
||||
found = found->Last();
|
||||
/* put the new wagon at the end of the loco. */
|
||||
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, CMD_MOVE_RAIL_VEHICLE);
|
||||
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
|
||||
|
@ -453,18 +453,6 @@ void InitializeVehicles()
|
||||
ResetVehiclePosHash();
|
||||
}
|
||||
|
||||
Vehicle *GetLastVehicleInChain(Vehicle *v)
|
||||
{
|
||||
while (v->Next() != NULL) v = v->Next();
|
||||
return v;
|
||||
}
|
||||
|
||||
const Vehicle *GetLastVehicleInChain(const Vehicle *v)
|
||||
{
|
||||
while (v->Next() != NULL) v = v->Next();
|
||||
return v;
|
||||
}
|
||||
|
||||
uint CountVehiclesInChain(const Vehicle *v)
|
||||
{
|
||||
uint count = 0;
|
||||
|
@ -366,6 +366,27 @@ public:
|
||||
*/
|
||||
inline Vehicle *First() const { return this->first; }
|
||||
|
||||
/**
|
||||
* Get the last vehicle of this vehicle chain.
|
||||
* @return the last vehicle of the chain.
|
||||
*/
|
||||
inline Vehicle *Last()
|
||||
{
|
||||
Vehicle *v = this;
|
||||
while (v->Next() != NULL) v = v->Next();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last vehicle of this vehicle chain.
|
||||
* @return the last vehicle of the chain.
|
||||
*/
|
||||
inline const Vehicle *Last() const
|
||||
{
|
||||
const Vehicle *v = this;
|
||||
while (v->Next() != NULL) v = v->Next();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first order of the vehicles order list.
|
||||
@ -537,6 +558,18 @@ struct SpecializedVehicle : public Vehicle {
|
||||
*/
|
||||
FORCEINLINE T *First() const { return (T *)this->Vehicle::First(); }
|
||||
|
||||
/**
|
||||
* Get the last vehicle in the chain
|
||||
* @return last vehicle in the chain
|
||||
*/
|
||||
FORCEINLINE T *Last() { return (T *)this->Vehicle::Last(); }
|
||||
|
||||
/**
|
||||
* Get the last vehicle in the chain
|
||||
* @return last vehicle in the chain
|
||||
*/
|
||||
FORCEINLINE const T *Last() const { return (const T *)this->Vehicle::Last(); }
|
||||
|
||||
/**
|
||||
* Get next vehicle in the chain
|
||||
* @return next vehicle in the chain
|
||||
|
@ -23,8 +23,6 @@
|
||||
typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
||||
|
||||
void VehicleServiceInDepot(Vehicle *v);
|
||||
Vehicle *GetLastVehicleInChain(Vehicle *v);
|
||||
const Vehicle *GetLastVehicleInChain(const Vehicle *v);
|
||||
uint CountVehiclesInChain(const Vehicle *v);
|
||||
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
|
@ -537,8 +537,7 @@ Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
|
||||
bool YapfCheckReverseTrain(const Vehicle *vt)
|
||||
{
|
||||
const Train *v = Train::From(vt);
|
||||
/* last wagon */
|
||||
const Train *last_veh = Train::From(GetLastVehicleInChain(v));
|
||||
const Train *last_veh = v->Last();
|
||||
|
||||
/* get trackdirs of both ends */
|
||||
Trackdir td = v->GetVehicleTrackdir();
|
||||
@ -600,7 +599,7 @@ bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reve
|
||||
*depot_tile = INVALID_TILE;
|
||||
*reversed = false;
|
||||
|
||||
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
||||
const Vehicle *last_veh = v->Last();
|
||||
|
||||
PBSTileInfo origin = FollowTrainReservation(Train::From(v));
|
||||
TileIndex last_tile = last_veh->tile;
|
||||
|
Loading…
Reference in New Issue
Block a user