mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-19 19:49:30 +01:00
(svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it.
This commit is contained in:
parent
3999dbe7f7
commit
7b92d9efe4
@ -453,10 +453,7 @@ struct DepotWindow : Window {
|
|||||||
if (x < 0) break;
|
if (x < 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if an articulated part was selected, find its parent */
|
d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
|
||||||
while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
|
|
||||||
|
|
||||||
d->wagon = v;
|
|
||||||
|
|
||||||
return MODE_DRAG_VEHICLE;
|
return MODE_DRAG_VEHICLE;
|
||||||
}
|
}
|
||||||
|
22
src/train.h
22
src/train.h
@ -273,6 +273,28 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
|
|||||||
return this->Next();
|
return this->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the last part of a multi-part engine.
|
* Get the last part of a multi-part engine.
|
||||||
* @return Last part of the engine.
|
* @return Last part of the engine.
|
||||||
|
@ -1105,9 +1105,9 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if an articulated part is being handled, deal with its parent vehicle */
|
/* if an articulated part is being handled, deal with its parent vehicle */
|
||||||
while (src->IsArticulatedPart()) src = src->Previous();
|
src = src->GetFirstEnginePart();
|
||||||
if (dst != NULL) {
|
if (dst != NULL) {
|
||||||
while (dst->IsArticulatedPart()) dst = dst->Previous();
|
dst = dst->GetFirstEnginePart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* don't move the same vehicle.. */
|
/* don't move the same vehicle.. */
|
||||||
@ -1445,7 +1445,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
|
|
||||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
while (v->IsArticulatedPart()) v = v->Previous();
|
v = v->GetFirstEnginePart();
|
||||||
Train *first = v->First();
|
Train *first = v->First();
|
||||||
|
|
||||||
/* make sure the vehicle is stopped in the depot */
|
/* make sure the vehicle is stopped in the depot */
|
||||||
|
Loading…
Reference in New Issue
Block a user