Changeset - r4198:d1c27397be1a
[Not reviewed]
master
0 1 0
Darkvater - 18 years ago 2006-07-30 22:55:17
darkvater@openttd.org
(svn r5665) - Codechange: check pointers against NULL, coding style, tabulation; nothing serious.
1 file changed with 11 insertions and 14 deletions:
0 comments (0 inline, 0 general)
train_cmd.c
Show inline comments
 
@@ -955,14 +955,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
	src = GetVehicle(s);
 

	
 
	if (src->type != VEH_Train) return CMD_ERROR;
 

	
 
	// if nothing is selected as destination, try and find a matching vehicle to drag to.
 
	if (d == INVALID_VEHICLE) {
 
		dst = NULL;
 
		if (!IsTrainEngine(src)) dst = FindGoodVehiclePos(src);
 
		dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src);
 
	} else {
 
		dst = GetVehicle(d);
 
	}
 

	
 
	// if an articulated part is being handled, deal with its parent vehicle
 
	while (IsArticulatedPart(src)) src = GetPrevVehicleInChain(src);
 
@@ -1006,20 +1005,19 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
		Vehicle *u, *engine = NULL;
 

	
 
		for (u = dst_head; u != NULL; u = u->next) {
 
			if (IsTrainEngine(u) && IsMultiheaded(u) && u->u.rail.other_multiheaded_part != NULL) {
 
				engine = u;
 
			}
 
				if (engine != NULL && engine->u.rail.other_multiheaded_part == u) {
 
					engine = NULL;
 
				}
 
				if (u == dst) {
 
					if (engine != NULL) dst = engine->u.rail.other_multiheaded_part;
 
					break;
 
				}
 

	
 
			if (engine != NULL && engine->u.rail.other_multiheaded_part == u) {
 
				engine = NULL;
 
			}
 
			if (u == dst) {
 
				if (engine != NULL) dst = engine->u.rail.other_multiheaded_part;
 
				break;
 
			}
 
		}
 
	}
 

	
 
	if (IsMultiheaded(src) && !IsTrainEngine(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
 
@@ -1108,14 +1106,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
				GetLastEnginePart(v)->next = NULL;
 
			} else {
 
				src_head = NULL;
 
			}
 
		} else {
 
			// if moving within the same chain, dont use dst_head as it may get invalidated
 
			if (src_head == dst_head)
 
				dst_head = NULL;
 
			if (src_head == dst_head) dst_head = NULL;
 
			// unlink single wagon from linked list
 
			src_head = UnlinkWagon(src, src_head);
 
			GetLastEnginePart(src)->next = NULL;
 
		}
 

	
 
		if (dst == NULL) {
 
@@ -1185,13 +1182,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
		 * we can't loop forever here because next time we reach this line we will have a front engine */
 
		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
 
			CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1);
 
			src_head = NULL;	// don't do anything more to this train since the new call will do it
 
		}
 

	
 
		if (src_head) {
 
		if (src_head != NULL) {
 
			NormaliseTrainConsist(src_head);
 
			TrainConsistChanged(src_head);
 
			if (IsFrontEngine(src_head)) {
 
				UpdateTrainAcceleration(src_head);
 
				InvalidateWindow(WC_VEHICLE_DETAILS, src_head->index);
 
				/* Update the refit button and window */
 
@@ -1199,13 +1196,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, src_head->index, 12);
 
			}
 
			/* Update the depot window */
 
			InvalidateWindow(WC_VEHICLE_DEPOT, src_head->tile);
 
		};
 

	
 
		if (dst_head) {
 
		if (dst_head != NULL) {
 
			NormaliseTrainConsist(dst_head);
 
			TrainConsistChanged(dst_head);
 
			if (IsFrontEngine(dst_head)) {
 
				UpdateTrainAcceleration(dst_head);
 
				InvalidateWindow(WC_VEHICLE_DETAILS, dst_head->index);
 
				/* Update the refit button and window */
0 comments (0 inline, 0 general)