summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-11 22:23:48 +0000
committerrubidium <rubidium@openttd.org>2009-12-11 22:23:48 +0000
commit9ae24229561e3016c19dd980cd49ea525282bf90 (patch)
tree5b35ab47e8c78367b1494441ad17d3dd952deb2f /src
parentb09431263183701036e5b3f579e87ddcdeab4c43 (diff)
downloadopenttd-9ae24229561e3016c19dd980cd49ea525282bf90.tar.xz
(svn r18466) -Codechange: use CmdMoveRailWagon to attach a just build wagon to a chain
Diffstat (limited to 'src')
-rw-r--r--src/train_cmd.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 61efbae2b..cbeeb3f76 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -705,19 +705,6 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
}
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;
@@ -742,12 +729,8 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
// v->subtype = 0;
v->SetWagon();
- if (u != NULL) {
- u->SetNext(v);
- } else {
- v->SetFreeWagon();
- InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
- }
+ v->SetFreeWagon();
+ InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
v->cargo_type = e->GetDefaultCargoType();
// v->cargo_subtype = 0;
@@ -778,6 +761,18 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
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;