src/train_cmd.cpp
branch0.6
changeset 11150 4e3726a46a72
parent 10656 8bea44dae56f
equal deleted inserted replaced
11132:6dd6907c378d 11150:4e3726a46a72
   695 
   695 
   696 /** Build a railroad vehicle.
   696 /** Build a railroad vehicle.
   697  * @param tile tile of the depot where rail-vehicle is built
   697  * @param tile tile of the depot where rail-vehicle is built
   698  * @param flags type of operation
   698  * @param flags type of operation
   699  * @param p1 engine type id
   699  * @param p1 engine type id
   700  * @param p2 bit 0 when set, the train will get number 0, otherwise it will get a free number
   700  * @param p2 bit 1 prevents any free cars from being added to the train
   701  *           bit 1 prevents any free cars from being added to the train
       
   702  */
   701  */
   703 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   702 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   704 {
   703 {
   705 	/* Check if the engine-type is valid (for the player) */
   704 	/* Check if the engine-type is valid (for the player) */
   706 	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
   705 	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
   734 		if (!Vehicle::AllocateList(vl, num_vehicles))
   733 		if (!Vehicle::AllocateList(vl, num_vehicles))
   735 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   734 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   736 
   735 
   737 		Vehicle *v = vl[0];
   736 		Vehicle *v = vl[0];
   738 
   737 
   739 		UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
   738 		UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
   740 		if (unit_num > _patches.max_trains)
   739 		if (unit_num > _patches.max_trains)
   741 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   740 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   742 
   741 
   743 		if (flags & DC_EXEC) {
   742 		if (flags & DC_EXEC) {
   744 			DiagDirection dir = GetRailDepotDirection(tile);
   743 			DiagDirection dir = GetRailDepotDirection(tile);
   807 			}
   806 			}
   808 
   807 
   809 			TrainConsistChanged(v);
   808 			TrainConsistChanged(v);
   810 			UpdateTrainGroupID(v);
   809 			UpdateTrainGroupID(v);
   811 
   810 
   812 			if (!HasBit(p2, 1)) { // check if the cars should be added to the new vehicle
   811 			if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle
   813 				NormalizeTrainVehInDepot(v);
   812 				NormalizeTrainVehInDepot(v);
   814 			}
   813 			}
   815 
   814 
   816 			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   815 			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   817 			RebuildVehicleLists();
   816 			RebuildVehicleLists();