mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
This commit is contained in:
parent
1028e2dc91
commit
7cdf6d1cbe
@ -202,7 +202,7 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost)
|
|||||||
/* Get the vehicle in front of the one we move out */
|
/* Get the vehicle in front of the one we move out */
|
||||||
Vehicle *front = old_v->Previous();
|
Vehicle *front = old_v->Previous();
|
||||||
/* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
|
/* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
|
||||||
if (IsMultiheaded(front) && !IsTrainEngine(front)) front = front->Previous();
|
if (IsRearDualheaded(front)) front = front->Previous();
|
||||||
/* Now we move the old one out of the train */
|
/* Now we move the old one out of the train */
|
||||||
DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
|
DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
|
||||||
/* Add the new vehicle */
|
/* Add the new vehicle */
|
||||||
@ -250,7 +250,7 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost)
|
|||||||
|
|
||||||
if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v)) {
|
if (old_v->type == VEH_TRAIN && IsFrontEngine(old_v)) {
|
||||||
Vehicle *next_veh = GetNextVehicle(old_v);
|
Vehicle *next_veh = GetNextVehicle(old_v);
|
||||||
if (IsMultiheaded(next_veh) && !IsTrainEngine(next_veh)) next_veh = next_veh->Next(); // don't try to move the rear multiheaded engine
|
if (IsRearDualheaded(next_veh)) next_veh = next_veh->Next(); // don't try to move the rear multiheaded engine
|
||||||
if (next_veh != NULL) {
|
if (next_veh != NULL) {
|
||||||
/* Verify that the wagons can be placed on the engine in question.
|
/* Verify that the wagons can be placed on the engine in question.
|
||||||
* This is done by building an engine, test if the wagons can be added and then sell the test engine. */
|
* This is done by building an engine, test if the wagons can be added and then sell the test engine. */
|
||||||
@ -337,7 +337,7 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
|
|||||||
cost = CommandCost();
|
cost = CommandCost();
|
||||||
w = v;
|
w = v;
|
||||||
do {
|
do {
|
||||||
if (w->type == VEH_TRAIN && IsMultiheaded(w) && !IsTrainEngine(w)) {
|
if (w->type == VEH_TRAIN && IsRearDualheaded(w)) {
|
||||||
/* we build the rear ends of multiheaded trains with the front ones */
|
/* we build the rear ends of multiheaded trains with the front ones */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
10
src/train.h
10
src/train.h
@ -225,6 +225,16 @@ static inline Vehicle *GetLastEnginePart(Vehicle *v)
|
|||||||
return 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.
|
/** Get the next real (non-articulated part) vehicle in the consist.
|
||||||
* @param v Vehicle.
|
* @param v Vehicle.
|
||||||
* @return Next vehicle in the consist.
|
* @return Next vehicle in the consist.
|
||||||
|
@ -798,7 +798,7 @@ int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped)
|
|||||||
* engines with more articulated parts than before works correctly.
|
* engines with more articulated parts than before works correctly.
|
||||||
*
|
*
|
||||||
* Also skip counting rear ends of multiheaded engines */
|
* Also skip counting rear ends of multiheaded engines */
|
||||||
if (!IsArticulatedPart(v) && !(!IsTrainEngine(v) && IsMultiheaded(v))) count++;
|
if (!IsArticulatedPart(v) && !IsRearDualheaded(v)) count++;
|
||||||
if (v->u.rail.track != TRACK_BIT_DEPOT || v->tile != tile ||
|
if (v->u.rail.track != TRACK_BIT_DEPOT || v->tile != tile ||
|
||||||
(IsFrontEngine(v) && needs_to_be_stopped && !(v->vehstatus & VS_STOPPED))) {
|
(IsFrontEngine(v) && needs_to_be_stopped && !(v->vehstatus & VS_STOPPED))) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -953,7 +953,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||||||
dst_head = NULL;
|
dst_head = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMultiheaded(src) && !IsTrainEngine(src)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
|
if (IsRearDualheaded(src)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
|
||||||
|
|
||||||
/* when moving all wagons, we can't have the same src_head and dst_head */
|
/* when moving all wagons, we can't have the same src_head and dst_head */
|
||||||
if (HASBIT(p2, 0) && src_head == dst_head) return CommandCost();
|
if (HASBIT(p2, 0) && src_head == dst_head) return CommandCost();
|
||||||
@ -1221,7 +1221,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED);
|
return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMultiheaded(v) && !IsTrainEngine(v)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
|
if (IsRearDualheaded(v)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (v == first && IsFrontEngine(first)) {
|
if (v == first && IsFrontEngine(first)) {
|
||||||
|
@ -500,7 +500,7 @@ bool IsEngineCountable(const Vehicle *v)
|
|||||||
case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors
|
case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
return !IsArticulatedPart(v) && // tenders and other articulated parts
|
return !IsArticulatedPart(v) && // tenders and other articulated parts
|
||||||
(!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines
|
!IsRearDualheaded(v); // rear parts of multiheaded engines
|
||||||
case VEH_ROAD: return IsRoadVehFront(v);
|
case VEH_ROAD: return IsRoadVehFront(v);
|
||||||
case VEH_SHIP: return true;
|
case VEH_SHIP: return true;
|
||||||
default: return false; // Only count player buildable vehicles
|
default: return false; // Only count player buildable vehicles
|
||||||
@ -1733,7 +1733,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
v = v_front;
|
v = v_front;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (v->type == VEH_TRAIN && IsMultiheaded(v) && !IsTrainEngine(v)) {
|
if (v->type == VEH_TRAIN && IsRearDualheaded(v)) {
|
||||||
/* we build the rear ends of multiheaded trains with the front ones */
|
/* we build the rear ends of multiheaded trains with the front ones */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user