Changeset - r13924:f0296916bae7
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2009-12-11 22:23:48
rubidium@openttd.org
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
1 file changed with 12 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -702,25 +702,12 @@ static CommandCost CmdBuildRailWagon(Eng
 
	/* Allow for the wagon and the articulated parts */
 
	if (!Vehicle::CanAllocateItem(num_vehicles)) {
 
		return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *u = NULL;
 

	
 
		Train *w;
 
		FOR_ALL_TRAINS(w) {
 
			/* do not connect new wagon with crashed/flooded consists */
 
			if (w->tile == tile && w->IsFreeWagon() &&
 
					w->engine_type == engine &&
 
					!(w->vehstatus & VS_CRASHED)) {
 
				u = w->Last();
 
				break;
 
			}
 
		}
 

	
 
		Train *v = new Train();
 
		v->spritenum = rvi->image_index;
 

	
 
		v->engine_type = engine;
 
		v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
 

	
 
@@ -739,18 +726,14 @@ static CommandCost CmdBuildRailWagon(Eng
 
		v->track = TRACK_BIT_DEPOT;
 
		v->vehstatus = VS_HIDDEN | VS_DEFPAL;
 

	
 
//		v->subtype = 0;
 
		v->SetWagon();
 

	
 
		if (u != NULL) {
 
			u->SetNext(v);
 
		} else {
 
			v->SetFreeWagon();
 
			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
		}
 

	
 
		v->cargo_type = e->GetDefaultCargoType();
 
//		v->cargo_subtype = 0;
 
		v->cargo_cap = rvi->capacity;
 
		v->value = value.GetCost();
 
//		v->day_counter = 0;
 
@@ -775,12 +758,24 @@ static CommandCost CmdBuildRailWagon(Eng
 
		if (IsLocalCompany()) {
 
			InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window
 
		}
 
		Company::Get(_current_company)->num_engines[engine]++;
 

	
 
		CheckConsistencyOfArticulatedVehicle(v);
 

	
 
		/* Try to connect the vehicle to one of free chains of wagons. */
 
		Train *w;
 
		FOR_ALL_TRAINS(w) {
 
			/* do not connect new wagon with crashed/flooded consists */
 
			if (w->tile == tile && w->IsFreeWagon() &&
 
					w->engine_type == engine &&
 
					!(w->vehstatus & VS_CRASHED)) {
 
				DoCommand(0, v->index | (w->Last()->index << 16), 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	return value;
 
}
 

	
 
/** Move all free vehicles in the depot to the train */
0 comments (0 inline, 0 general)