src/train_cmd.cpp
changeset 9628 981ba3800c35
parent 9515 ff5c2a07215b
child 9699 33ebfa8216ca
equal deleted inserted replaced
9627:3497448171a8 9628:981ba3800c35
   683 
   683 
   684 /** Build a railroad vehicle.
   684 /** Build a railroad vehicle.
   685  * @param tile tile of the depot where rail-vehicle is built
   685  * @param tile tile of the depot where rail-vehicle is built
   686  * @param flags type of operation
   686  * @param flags type of operation
   687  * @param p1 engine type id
   687  * @param p1 engine type id
   688  * @param p2 bit 0 when set, the train will get number 0, otherwise it will get a free number
   688  * @param p2 bit 1 prevents any free cars from being added to the train
   689  *           bit 1 prevents any free cars from being added to the train
       
   690  */
   689  */
   691 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   690 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   692 {
   691 {
   693 	/* Check if the engine-type is valid (for the player) */
   692 	/* Check if the engine-type is valid (for the player) */
   694 	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
   693 	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
   723 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   722 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   724 		}
   723 		}
   725 
   724 
   726 		Vehicle *v = vl[0];
   725 		Vehicle *v = vl[0];
   727 
   726 
   728 		UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
   727 		UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
   729 		if (unit_num > _settings_game.vehicle.max_trains)
   728 		if (unit_num > _settings_game.vehicle.max_trains)
   730 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   729 			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
   731 
   730 
   732 		if (flags & DC_EXEC) {
   731 		if (flags & DC_EXEC) {
   733 			DiagDirection dir = GetRailDepotDirection(tile);
   732 			DiagDirection dir = GetRailDepotDirection(tile);
   796 			}
   795 			}
   797 
   796 
   798 			TrainConsistChanged(v);
   797 			TrainConsistChanged(v);
   799 			UpdateTrainGroupID(v);
   798 			UpdateTrainGroupID(v);
   800 
   799 
   801 			if (!HasBit(p2, 1)) { // check if the cars should be added to the new vehicle
   800 			if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle
   802 				NormalizeTrainVehInDepot(v);
   801 				NormalizeTrainVehInDepot(v);
   803 			}
   802 			}
   804 
   803 
   805 			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   804 			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   806 			InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
   805 			InvalidateWindowClassesData(WC_TRAINS_LIST, 0);