In regicide, data.garrisonEmergency is not reset when retreating a hero to a base when the hero couldn't find a place to garrison. It seems the best (only?) way to do this is to check for distance, but these calls could be expensive.
After this, there should be checks for "exposed" heroes to retreat to the second closest base if they can't garrison, as if a hurt hero is overwhelmed with enemies when it has already retreated it will not move anywhere. This will important for D104.