I spent a week writing logic and testing and I finally got it!
How it works ....
First of all, I had to change the impassable terrain from 100 to 300 (I'll explain later).
Next, add more conditions for my modified PlaceUnit() function, as follows ;
(1) Search for a valid, unoccupied road tile, recorded as x2/y2.
- Since I have at least one road axis enabled in Amaris' map logic, it's bound to find one (roads are plentiful)
(2) Add the unit to the x2/y2 location... "AddUnit()".
(3) Run a "GetRouteCost()" from x2/y2 to the proposed x/y placement tile.
(4) If cost < 300, and cost != -1, then it's a good placement barring other conditions.
(5) If step #4 fails, search outwards to a predefined distance (which is half the mapheight value).
(6) If step #5 fails, then look for roadtiles using same procedure as step #4.
The reason why I had to do a "double-check" with (cost<300 @ cost!=-1) is because I felt that the "GetRouteCost" cheats and will find a route and not return a -1. Since the impassable terrain tile cost is 300, the "< 300" check ensures it doesn't pass through those tiles, and if it does, the cost will exceed 300 instantly. Using 300 also allows it to place it anywhere on the current map (generally the cost will be less than 200, but 300 ensured that) ... Using 100 wouldn't work, hence the reason why I boosted it to 300.
Overall, it works great! ... Game run after game run it's fool proof (or shall I say idiot proof).
Now I can wrap up the QuickBattles and release them soon.
Rob

