I think if your city is attacked and gates are open, all your troops fall under the command of your mayor. His attributes are what are factored in.