AI work

I’ve started working on the new/enhanced AI. The primary goal is to give the AI the ability remember more than one task, as you can probably guess, the old AI could only remember one. This lead to a few problems mainly being that the AI was very inflexible, and that whatever task I gave it had to be complete in and of itself.

First up the inflexibility – say for example the player orders one of his/her ships to attack a object that is 1000 distance units away, but while the ship is flying towards that object it is attacked. Because the old AI only remembers one task at a time if the AI responded to the attacker it would forget the original order, because I want to give the player the ability of absolute command over ships in their arsenal, this meant that I had to tell the AI to ignore any attacker (the turret’s would defend the ship, but the ship itself wouldn’t respond) under these conditions (where the player directly orders a ship to perform an action, the ship would ignore everything else around it and try to do that action). But! If the AI can remember more than one thing, it can respond to things – in this example defend itself, and then afterwards continue onto the target that the player commanded it to. So giving the AI some memory is of clear benefit here.

The second issue is that the tasks had to be complete in and of themselves – this is actually an internal coding thing, so technically invisible to the player, however having each task be complete in itself means that AI tasks are prone to bugs, they are hard to save (for saving/loading), and that they are hard to add. So the new state of the AI is that it will be built up of small and reusable tasks that form larger ones.

For example this is how I stared coding what I called in code “AI Nodes”:
Idle node – set ship speed to 0
Wait node – use idle node until a timer expires
Turn to position mode – turn ship towards a specified point in space
Go to position node – use the turn to position node, and set the ship speed so that it can travel to the position
Go to object node – use the go to position node and update the position based on the go to object’s position
Follow object node – use the go to object node, when within distance of the follow object switch to the idle node.
Formation follow object node – like the follow object node, but instead of idling when near use the turn to position node to align with the followed ship, with some speed matching.

As you can see the go to position node uses the turn to position node. This very simple example shows how I can create more complex behaviors, eventually giving me the ability to set complex tasks, that are easy to arrange and create. For example: go to position abc, destroy this ship, pick up that object, and then return to position xyz. This could be useful for pirate raids, for civilian traffic, for trading ships, for scripted events, for boss battles, for cutscenes and other story elements – anything really.

The very very flight basics are in, what I’m currently working on now is the gravity drive changes for the AI and player controlled ships. All along I’ve been planning on not having the standard “warp” or “hyperspace” type mechanism in this project, instead what I call a “gravity drive” – a method of traveling at a high rate of speed, but not the boring already seen mechanics, instead ships can use the gravity drive to pull themselves (or as I like to think of it fall towards) large objects, making them choke points and giving them strategic value. These objects will be asteroid bases, large rocks, and potentially special “gravity field generating” stations and even maybe some special ships. So the player can either use standard engines to travel to a position, or can use the gravity drive to hop along from nearby large object to nearby large object until they get to their destination. So it basically calls for some basic distance comparison based mapping, which I’ve coded in tonight.

Next up more logic, the pull mechanism of the gravity drive, and better obstacle avoidance, then off to combat, and then off to intelligent node selection/addition/removal/management.