Model Predictive Control with Environment Adaptation for Legged Locomotion