The score for buying army now scales with the cost of that army.
The cost of the units that need to be disbanded in order to hire the new units is subtracted from the army-hiring-score so the AI will prefer hiring armies where the amount of troops to disband is low or non-existent.
Fixed a bug that also disbanded troops when there still were free slots available.
The AI is now a lot more likely to buy a hero early on when that hero's army is worth more than half the cost of the hero, regardless of other circumstances.
Instead of skipping the defense of other towns entirely when hiring a hero was considered as a way of defending, now only hiring the same hero twice will be avoided.
Fixed an issue that made AI consider unpurchased troops as reinforcements for their armies which caused AI to visit cities over and over without actually doing anything there.
Buying units is handled by BuyArmyBehavior.
AI will now also garrison a hero as defender if the town to be defended has troops as long as the hero can merge their own troops with the town.
AI will no longer just dismiss existing troops in a town if a hero trying to garrison there can merge with it.
Reduced the amount of circumstances under which the AI dismisses heroes. Among others to prevent a loop through all passes where it repeatedly hires and dismisses heroes.
Modified how to score what hero to hire to make it more likely to rehire fled heroes with high levels when the army-gain from the hero would be rather insignificant.
Fixed crash caused by mistakenly assuming that "pos" is the position of a hero on the map and not its bottom-right-corner that can be outside of the map.
The StayAtTown-behavior now always creates tasks for all heroes to go and stay at a town. It will be treated differently than going to a town for mana in the sense that it is only considered at the lowest priority-tier. So it will only happen when the AI doesn't find anything else to do. It should resolve one of the two main-reasons for losing weak heros.
The hunter-gather-priority-tier now goes strictly by distance for all taks that are considered above 0 in value.
Don't hire a hero in a town where another hero is currently defending against a threat. This would mean one of them has to stay outside and be exposed.
A town will no longer communitcate that it doesn't need defenses, when it currently has a garrisioned hero. Because otherwise the garrisoned hero would just leave and let the town undefended.
Reworked recruit-behavior to be a bit more conservative and avoid recruiting-sprees. Stuff like buying several heros in a row because the next one is always slightly better than the last but using up the whole starting-bank for that.