Combined effects of trapped energetic ions and resistive layer damping on the stability of the resistive wall mode