Ratcheting based on neighboring niches determines lifestyle