From 1f28e232c3e3da4f11ddc7d12d3618c489c32625 Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 13 Apr 2010 19:10:08 +0000 Subject: (svn r19621) -Codechange: Remove direct usage of magic 'p1's in build vehicle commands. --- src/train_cmd.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/train_cmd.cpp') diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 00c5d3a91..67600098e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -688,10 +688,11 @@ static void AddRearEngineToMultiheadedTrain(Train *v) */ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { + EngineID eid = GB(p1, 0, 16); /* Check if the engine-type is valid (for the company) */ - if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE); + if (!IsEngineBuildable(eid, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE); - const Engine *e = Engine::Get(p1); + const Engine *e = Engine::Get(eid); const RailVehicleInfo *rvi = &e->u.rail; CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); @@ -705,11 +706,11 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, if (!IsRailDepotTile(tile)) return CMD_ERROR; if (!IsTileOwner(tile, _current_company)) return CMD_ERROR; - if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); + if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(eid, tile, flags); uint num_vehicles = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + - CountArticulatedParts(p1, false); + CountArticulatedParts(eid, false); /* Check if depot and new engine uses the same kind of tracks * * We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ @@ -747,7 +748,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, v->value = value.GetCost(); v->last_station_visited = INVALID_STATION; - v->engine_type = p1; + v->engine_type = eid; v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback v->reliability = e->reliability; @@ -792,7 +793,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window } - Company::Get(_current_company)->num_engines[p1]++; + Company::Get(_current_company)->num_engines[eid]++; CheckConsistencyOfArticulatedVehicle(v); } -- cgit v1.2.3-54-g00ecf