546 CommandCost value(EXPENSES_NEW_VEHICLES, (GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8); |
546 CommandCost value(EXPENSES_NEW_VEHICLES, (GetEngineProperty(engine, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8); |
547 |
547 |
548 uint num_vehicles = 1 + CountArticulatedParts(engine, false); |
548 uint num_vehicles = 1 + CountArticulatedParts(engine, false); |
549 |
549 |
550 if (!(flags & DC_QUERY_COST)) { |
550 if (!(flags & DC_QUERY_COST)) { |
|
551 /* Check that the wagon can drive on the track in question */ |
|
552 if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
|
553 |
551 /* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */ |
554 /* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */ |
552 Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1)); |
555 Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1)); |
553 memset(vl, 0, sizeof(*vl) * (num_vehicles + 1)); |
556 memset(vl, 0, sizeof(*vl) * (num_vehicles + 1)); |
554 |
557 |
555 if (!Vehicle::AllocateList(vl, num_vehicles)) |
558 if (!Vehicle::AllocateList(vl, num_vehicles)) |
700 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
703 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
701 } |
704 } |
702 |
705 |
703 const RailVehicleInfo *rvi = RailVehInfo(p1); |
706 const RailVehicleInfo *rvi = RailVehInfo(p1); |
704 |
707 |
705 /* Check if depot and new engine uses the same kind of tracks */ |
|
706 /* We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ |
|
707 if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
|
708 |
|
709 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
708 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
710 |
709 |
711 CommandCost value = EstimateTrainCost(p1, rvi); |
710 CommandCost value = EstimateTrainCost(p1, rvi); |
712 |
711 |
713 uint num_vehicles = |
712 uint num_vehicles = |
714 (rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + |
713 (rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + |
715 CountArticulatedParts(p1, false); |
714 CountArticulatedParts(p1, false); |
716 |
715 |
717 if (!(flags & DC_QUERY_COST)) { |
716 if (!(flags & DC_QUERY_COST)) { |
|
717 /* Check if depot and new engine uses the same kind of tracks * |
|
718 * We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ |
|
719 if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; |
|
720 |
718 /* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */ |
721 /* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */ |
719 Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1)); |
722 Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1)); |
720 memset(vl, 0, sizeof(*vl) * (num_vehicles + 1)); |
723 memset(vl, 0, sizeof(*vl) * (num_vehicles + 1)); |
721 |
724 |
722 if (!Vehicle::AllocateList(vl, num_vehicles)) |
725 if (!Vehicle::AllocateList(vl, num_vehicles)) |