KGB,
Having lower gold means cheaper heroes but it means less chance to get them.
That's not true. When I didn't know the hero algorithm, I found myself for example in situation that I had four heroes (and would like to get one more). I tried to keep my gold over 1500. It seemed to me that since it is more than max hero price, I had a reasonable chance to get one in few turns. Later I found that the probability was exactly the same as if I had 400 gold - in which case I would have some good production instead and wouldn't get expensive offers the new hero wouldn't be worth. So not knowing the exact numbers and thinking more gold = better was definitely not good...
Having the max price lowered and possibility of adding level for sparse gold definitely helps a lot with this.
I'd much rather have 950 gold and be sure of a hero than have only 650 and get one 50% of the time regardless of whether or not I paid 200 more gold for my hero.
I don't say it's not worth to raise your money anyway in this case, I just don't see the reason for making some special rule which makes heroes cheaper for somebody who hasn't enough gold to pay for them...
Allowing players to instantly place their heroes anywhere for gold isn't a good idea. What will happen is that when you start offering L2+ heros + allies players will be placing those right on the front lines and using them to attack. Getting a L3 hero + allies is going to just be impossible to guard against and games would turn on that. The 2 turn portal time at least prevents that issue.
I see as much bigger problem than choosing the city the fact that the high level hero appears from nowhere. For example, if you are ready for attack in forest, and the opponent gets L3 offer, he buys a ranger and attacks you with 20 leadership (not mentioning possible allies), which completely turns the outcome of the battle for the other side...
One more thing for the posted code:
if ($turn > 6 && $turn < 13)
{
// 33% chans för lvl 2 hero
$herolevel = mt_rand(1,3);
if ($herolevel == 3)
{
$herolevel = 2;
}
This is 2/3 probability for L2 hero, not L1, isn't it?