Ok, I can't use the trick I was thinking of for fuel-based units, but I have thought of another way.
Every turn, onBeginPlayerTurn if Player not isHuman, we walk the list of units.
For each unit which is fuel based and has less then half it's fuel tank, we do the following:
1) Patch up it's fuel tank--If it has 0 (and the out of fuel bit isn't set), we give it it's move in fuel. If it has < then it's move but more then 0, we give it it's move + 1 in fuel.
2) We find the nearest source of fuel (this is hard, given terrain issues)
3) We find a square it canMoveInto within its move range on the path to the fuel.
4) We setXY() the unit to that location
5) We finishMove() the unit
6) setAI to None (just in case)
7) We test for refueling by hand, if it's in the same square as a refueling unit (carrier for instance), we refuel it automatically
8) When it gets refueled, we reset it's ai to Unknown, which I am guessing is used by the engine to mark a unit which needs a new role assigned to it.
This gives the computer some advantages when it comes to it's fuel units, but nothing that major, IMO. The hard part is dealing with different travel modes and finding the shortest path to the nearest fuel depot. Totally solvable, just a lot of work. The second hardest problem is the moving target issue--carriers (or other supply units) can move, making predictive movement problematic. Easiest solution is just to put in a flag "rendezvous" or some such, ref count, say, so that when a unit comes in to rendezvous with a supply unit, it tags that unit so it won't move (and we just finishMove() it every turn at the start of the turn.
Best solution I have so far to the fuel-based units & computer player issues.
Every turn, onBeginPlayerTurn if Player not isHuman, we walk the list of units.
For each unit which is fuel based and has less then half it's fuel tank, we do the following:
1) Patch up it's fuel tank--If it has 0 (and the out of fuel bit isn't set), we give it it's move in fuel. If it has < then it's move but more then 0, we give it it's move + 1 in fuel.
2) We find the nearest source of fuel (this is hard, given terrain issues)
3) We find a square it canMoveInto within its move range on the path to the fuel.
4) We setXY() the unit to that location
5) We finishMove() the unit
6) setAI to None (just in case)
7) We test for refueling by hand, if it's in the same square as a refueling unit (carrier for instance), we refuel it automatically
8) When it gets refueled, we reset it's ai to Unknown, which I am guessing is used by the engine to mark a unit which needs a new role assigned to it.
This gives the computer some advantages when it comes to it's fuel units, but nothing that major, IMO. The hard part is dealing with different travel modes and finding the shortest path to the nearest fuel depot. Totally solvable, just a lot of work. The second hardest problem is the moving target issue--carriers (or other supply units) can move, making predictive movement problematic. Easiest solution is just to put in a flag "rendezvous" or some such, ref count, say, so that when a unit comes in to rendezvous with a supply unit, it tags that unit so it won't move (and we just finishMove() it every turn at the start of the turn.
Best solution I have so far to the fuel-based units & computer player issues.