Changeset - r12440:97b7db79722d
[Not reviewed]
master
0 3 0
frosch - 15 years ago 2009-07-19 19:17:41
frosch@openttd.org
(svn r16884) -Codechange: Add Train::GetFirstEnginePart() and use it.
3 files changed with 26 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -453,10 +453,7 @@ struct DepotWindow : Window {
 
					if (x < 0) break;
 
				}
 

	
 
				/* if an articulated part was selected, find its parent */
 
				while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
 

	
 
				d->wagon = v;
 
				d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
 

	
 
				return MODE_DRAG_VEHICLE;
 
			}
src/train.h
Show inline comments
 
@@ -274,6 +274,28 @@ struct Train : public SpecializedVehicle
 
	}
 

	
 
	/**
 
	 * 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.
 
	 * @return Last part of the engine.
 
	 */
src/train_cmd.cpp
Show inline comments
 
@@ -1105,9 +1105,9 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
	}
 

	
 
	/* if an articulated part is being handled, deal with its parent vehicle */
 
	while (src->IsArticulatedPart()) src = src->Previous();
 
	src = src->GetFirstEnginePart();
 
	if (dst != NULL) {
 
		while (dst->IsArticulatedPart()) dst = dst->Previous();
 
		dst = dst->GetFirstEnginePart();
 
	}
 

	
 
	/* don't move the same vehicle.. */
 
@@ -1445,7 +1445,7 @@ CommandCost CmdSellRailWagon(TileIndex t
 

	
 
	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();
 

	
 
	/* make sure the vehicle is stopped in the depot */
0 comments (0 inline, 0 general)