equal
deleted
inserted
replaced
656 } |
656 } |
657 |
657 |
658 /** Build a railroad vehicle. |
658 /** Build a railroad vehicle. |
659 * @param x,y tile coordinates (depot) where rail-vehicle is built |
659 * @param x,y tile coordinates (depot) where rail-vehicle is built |
660 * @param p1 engine type id |
660 * @param p1 engine type id |
661 * @param p2 bit 0 build only one engine, even if it is a dualheaded engine. |
661 * @param p2 bit 0 prevents any free cars from being added to the train |
662 p2 bit 1 prevents any free cars from being added to the train |
|
663 */ |
662 */ |
664 int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
663 int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
665 { |
664 { |
666 const RailVehicleInfo *rvi; |
665 const RailVehicleInfo *rvi; |
667 int value; |
666 int value; |
691 |
690 |
692 if (rvi->flags & RVI_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
691 if (rvi->flags & RVI_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
693 |
692 |
694 value = EstimateTrainCost(rvi); |
693 value = EstimateTrainCost(rvi); |
695 |
694 |
696 //make sure we only pay for half a dualheaded engine if we only requested half of it |
695 num_vehicles = (rvi->flags & RVI_MULTIHEAD) ? 2 : 1; |
697 if (rvi->flags&RVI_MULTIHEAD && HASBIT(p2,0)) |
|
698 value /= 2; |
|
699 |
|
700 num_vehicles = (rvi->flags & RVI_MULTIHEAD && !HASBIT(p2, 0)) ? 2 : 1; |
|
701 num_vehicles += CountArticulatedParts(rvi, p1); |
696 num_vehicles += CountArticulatedParts(rvi, p1); |
702 |
697 |
703 if (!(flags & DC_QUERY_COST)) { |
698 if (!(flags & DC_QUERY_COST)) { |
704 Vehicle *vl[12]; // Allow for upto 10 artic parts and dual-heads |
699 Vehicle *vl[12]; // Allow for upto 10 artic parts and dual-heads |
705 if (!AllocateVehicles(vl, num_vehicles) || IsOrderPoolFull()) |
700 if (!AllocateVehicles(vl, num_vehicles) || IsOrderPoolFull()) |
759 v->u.rail.shortest_platform[0] = 255; |
754 v->u.rail.shortest_platform[0] = 255; |
760 v->u.rail.shortest_platform[1] = 0; |
755 v->u.rail.shortest_platform[1] = 0; |
761 |
756 |
762 VehiclePositionChanged(v); |
757 VehiclePositionChanged(v); |
763 |
758 |
764 if (rvi->flags & RVI_MULTIHEAD && !HASBIT(p2, 0)) { |
759 if (rvi->flags & RVI_MULTIHEAD) { |
765 SetMultiheaded(v); |
760 SetMultiheaded(v); |
766 AddRearEngineToMultiheadedTrain(vl[0], vl[1], true); |
761 AddRearEngineToMultiheadedTrain(vl[0], vl[1], true); |
767 /* Now we need to link the front and rear engines together |
762 /* Now we need to link the front and rear engines together |
768 * other_multiheaded_part is the pointer that links to the other half of the engine |
763 * other_multiheaded_part is the pointer that links to the other half of the engine |
769 * vl[0] is the front and vl[1] is the rear |
764 * vl[0] is the front and vl[1] is the rear |
775 } |
770 } |
776 |
771 |
777 TrainConsistChanged(v); |
772 TrainConsistChanged(v); |
778 UpdateTrainAcceleration(v); |
773 UpdateTrainAcceleration(v); |
779 |
774 |
780 if (!HASBIT(p2, 1)) { // check if the cars should be added to the new vehicle |
775 if (!HASBIT(p2, 0)) { // check if the cars should be added to the new vehicle |
781 NormalizeTrainVehInDepot(v); |
776 NormalizeTrainVehInDepot(v); |
782 } |
777 } |
783 |
778 |
784 InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
779 InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
785 RebuildVehicleLists(); |
780 RebuildVehicleLists(); |