Three-phase flow is a key to many EOR techniques such as Water Alternating Gas (WAG) injection. Predicting oil recovery during three-phase EOR in carbonates requires a sound understanding of the fundamental flow physics in mixed- to oil-wet rocks to derive physically robust flow functions, i.e. relative permeability and capillary pressure. In this work we use pore-network modelling, a reliable and physically-based simulation tool, to predict the flow functions. We have developed a new pore-scale network model for rocks with variable wettability, from mixed to oil-wet. It comprises a constrained set of parameters that mimic the wetting state of a reservoir. Unlike other models, it combines three main features: (1) A novel thermodynamic criterion for formation and collapse of oil layers. The new model hence captures wetting film and layer flow of oil adequately, which affects the oil relative permeability at low oil saturation and leads to accurate prediction of residual oil. (2) Multiple displacement chains, where injection of one phase at the inlet triggers a chain of interface displacements throughout the network. This allows accurate modeling of the mobilization of many disconnected phase clusters that arise during higher order (WAG) floods. (3) The model takes realistic 3D pore-networks extracted from pore-space reconstruction methods and CT images as input, preserving both topology and pore shape of the rock. We validated our network model by comparing 2D network simulations with published data from WAG floods in oil-wet micromodels. This demonstrates the importance of film and layer flow for the continuity of the various phases during subsequent WAG cycles and for the residual oil saturations. A sensitivity analysis has been carried out with the full 3D model to predict three-phase relative permeabilities and residual oil saturations for WAG cycles under various wetting conditions with different flood end-points.