Carbonate reservoirs have structural heterogeneities (triple porosity: pore-vug-fracture) and are mixed-to oil-wet. The interplay of structural and wettability heterogeneities impacts the sweep efficiency and oil recovery. The choice of an IOR or EOR process and the prediction of oil recovery requires a sound understanding of the fundamental controls on fluid flow in mixed-to oil-wet carbonate rocks and physically robust flow functions, i.e. relative permeability and capillary pressure functions. Obtaining these flow functions is a challenging task, especially when three fluid phases coexist. In this work we use pore-network modelling, a reliable and physically-based simulation tool, to predict three-phase flow functions. We have developed a new pore-scale network model for rocks with variable wettability. Unlike other models, this model comprises a novel thermodynamic criterion for formation and collapse of oil layers. The new model hence captures film/layer flow of oil adequately which impacts the oil relative permeability at low oil saturation and hence the accurate prediction of residual oil. Pore-networks extracted from pore-space reconstruction methods and CT images have been used as input for our simulations and the model comprises a constrained set of parameters that can be tuned to mimic the wetting state of a given reservoir. We have validated our model with available experimental data for a range of wettabilities. A sensitivity analysis has been carried out to investigate the dependency of relative permeabilities on layer collapse and film/layer flow under various wetting conditions. Additionally, WAG injection has been simulated with different lengths of so-called multi-displacement chains and different flood end-points. The flow functions generated by our model can be passed to the next scales (upscaling) to predict the oil recovery at the reservoir scale and we demonstrate this using a proof-of-concept study.