A discrete-domain approach to three-phase hysteresis in porous media