I noticed that even if it's decided to keep the gate closed it will still save the rainbow and the ballista. This wastes a lot of food. If the gate isn't going to open then it only needs to save resources.

Even when the gates are open it saves all the ballista. Can we get a variable to define the most ballista it should save. Say, maxballs and default it to 5k ?

I noticed that even if there is not enough food to send the transports with the ballista, it will still try. It should send the transports alone and only send enough to carry the resources in the city.

If there are warehouses in the town it still tries to save all the resources before it saves the gold. It should calculate the capacity of the warehouses and consider it before loading the transports.

It always leaves 10k gold in the city when it saves the resources. This is a dead give away for a bot. It should only leave gold when it can not balance the cost of heroes with the tax rate. And it should be able to balance the cost vs tax up until very low loyalty by dropping production and raising tax to 85% for a few mins.