The cognitive mechanisms of complex planning