ship_cmd.c
changeset 3954 7b51d0046efb
parent 3948 a09379beffd5
child 3955 b96f96b31403
equal deleted inserted replaced
3953:e64bbd8598e2 3954:7b51d0046efb
  1028 /** Refits a ship to the specified cargo type.
  1028 /** Refits a ship to the specified cargo type.
  1029  * @param tile unused
  1029  * @param tile unused
  1030  * @param p1 vehicle ID of the ship to refit
  1030  * @param p1 vehicle ID of the ship to refit
  1031  * @param p2 various bitstuffed elements
  1031  * @param p2 various bitstuffed elements
  1032  * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
  1032  * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
       
  1033  * - p2 = (bit 8-15) - the new cargo subtype to refit to
  1033  */
  1034  */
  1034 int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1035 int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1035 {
  1036 {
  1036 	Vehicle *v;
  1037 	Vehicle *v;
  1037 	int32 cost;
  1038 	int32 cost;
  1038 	CargoID new_cid = p2 & 0xFF; //gets the cargo number
  1039 	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
       
  1040 	byte new_subtype = GB(p2, 8, 8);
  1039 
  1041 
  1040 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
  1042 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
  1041 
  1043 
  1042 	v = GetVehicle(p1);
  1044 	v = GetVehicle(p1);
  1043 
  1045 
  1059 	}
  1061 	}
  1060 
  1062 
  1061 	if (flags & DC_EXEC) {
  1063 	if (flags & DC_EXEC) {
  1062 		v->cargo_count = 0;
  1064 		v->cargo_count = 0;
  1063 		v->cargo_type = new_cid;
  1065 		v->cargo_type = new_cid;
       
  1066 		v->cargo_subtype = new_subtype;
  1064 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
  1067 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
       
  1068 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
       
  1069 		RebuildVehicleLists();
  1065 	}
  1070 	}
  1066 
  1071 
  1067 	return cost;
  1072 	return cost;
  1068 
  1073 
  1069 }
  1074 }