Game Design, Programming and running a one-man games business…

Fixing the AI orders (again)

Some cunning GSB players noticed that the orders were not working correctly in terms of attacking certain classes of ship. If you deleted the ‘attack fighters’ order, the desired behaviour was that the ship ignored fighters until there were only fighters left.

This bit of code was broken and basically needed re-doing. Now you might think it’s an easy algorithm that goes like this:

Go through each intact enemy ship
Pick the optimum one out of the classes we should shoot at
If you still have no target...
Go through each intact enemy ship
Pick the optimum one ignoring class.

Leaving aside the inefficiency of parsing the 300 enemy ships twice each time, this isn’t as simple as it looks, because a lot of the time a ship will fail to find a target within range. Thats because all of the ships its ordered to fight are across the map. Ideally the ship trundles over and shoots them. So the criteria for actually picking a target differs from the criteria for establishing whether or not there are any valid targets. Plus, the idea that once all the frigates and cruisers are dead, that EVERY TIME I look for a target I have to do a dummy run through with invalid orders is just untidy and slooow slooow…

So I ended up coding a convoluted complex system which (as convoluted complex systems often are) is way faster than that. Basically Fleets keep track of if they have any ships of each class. Whenever new ships show up (survival mode) or a ship dies, the fleet recalculates that data. if the data has changed, it tells each intact ship in the fleet. Those ships then compare this against their orders, and deduce whether or not the orders still stand. If they don’t, they tell all their turret AI’s to ignore class-based orders from now on. This involves practically no overhead during a  typical target-acquisition call (which are very frequent)

That took a lot longer to code, debug and test than it did to type here :D

In other news, I fixed some dodgy server-side code that prevented challenges being deleted. I’m amazed more people did not whine at me that the ‘delete’ button on a challenge basically did sod all. It now works :D


6 thoughts on Fixing the AI orders (again)

  1. Speaking of fighters…

    Is there a way to have fighters Escort and break off to attack when there are no more opposing fighters left? I’d love for them to go attack rather than circling my fleet.

  2. why don’t you make a bool that switches off when there are no more frigates and cruisers, and check it before running trough all the ships?
    like

    if (AreThereStillBaddies == 1)
    {
    if (FindNrBaddies() > 0 )
    {
    FindNearestAndGoKillIt();
    }
    else
    {
    AreThereStillBaddies = 0
    }
    }

  3. I’m not sure I agree that the correct course of action is to trundle over to the desired target and start shooting. I think you should trundle over, but if transit time > weapon recharge time, by all means fire at whatever’s available en-route!

  4. Paul makes a great point. I would also exempt short range and point defense weapons from this rule set.

  5. I think navigation decision trees should be relatively separate from firing control decisions. By that I mean that a ship should automatically be moving in ways that minimize risk to the ship (such as staying away from heavily damaged ships about to blow, backing off from incoming ships to maintain optimum weapons range, etc).

    Firing control on the other hand should always be looking to maximize the use of the weapons at any given moment. Fast weapons targeting fighters, beams targeting whatever they can penetrate and anti shield weapons targeting whatever the primary target is that is close by that needs it’s shields broken. No Ship should be wasting beams on shields they can’t pierce. Maybe the first time, yes.. but after that, you close range for your shield piercers and in the meantime take out that escort frigate.

    In this case there are a couple overlaps: navigation needs to know what optimum weapons range is and targeting needs to be able to tell navigation that they need to close because they can’t pierce the primary target’s shields with beams.

Comments are currently closed.