This is the Alpha release of a public-code, fairly feature-complete AI that works with Vanilla. It largely replaces all of Vanilla's AI systems under the hood at this point, including some support for System AIs that call Vanilla's System AIs. While this AI isn't perfect, it substantially improves the performance of Starsector in large battles.

It's Alpha, and there are a few bells-and-whistles that don't work or are in need of improvement, but I think it's finally ready for some public testing and comment.

Historically, this AI is an extension of and refinement of the AI I originally wrote for Vacuum, with a lot of improvements and support for Vanilla features I didn't have in Vacuum (in particular, friendly fire being a thing).

This mod provides:

1. A common framework for developing new mods for StarSector that is mainly public code, except where StarSector's API is utilized.I.E.: the code comes with the mod and yes, you can feel free to modify it and redistribute it, so long as you're using it within StarSector. You may also include specialized builds for specific modded ships, in your mods, etc., if you're that ambitious. Feel free to study how it works if you want to develop practical game AIs, too, but please don't just copy-pasta the core of it into a commercial game, thanks.2. A fairly well-documented codebase for building new AIs to handle various behaviors in Vanilla without having to reinvent too many wheels.3. An AI that, while imperfect (see Caveats, below) will give most players a reasonably-good game challenge and better performance in large battles.4. Very fast performance; the AI and its sub-components are fairly well-optimized, if not perfectly so.5. AI support for auto-fire weapons that is pretty lean and mean, using the structural optimizations in the base AI.6. AI support for most, but not all, Missiles (see Caveats), using the structural optimizations in the base AI.7. AI support for most, but not all, Drones (see Caveats), using the structural optimizations in the base AI.8. AI support for all of the Vanilla Systems, using the structural optimizations in the base AI.9. Supports modded Systems that have an AI script defined in the .system file.10. Unless Alex does something radical to how ModPlugins work or how fundamental calls to Global work, it's pretty future-proof, so we can use this as a base for future work on this area of SS modding.11. Now supports "blacklisting" of specific hull ids; hulls blacklisted will not use the AI for the ship, the ship's weapons or Systems.

Structure

Each weapon on Autofire, ship on Auto-Pilot and guided missiles / drones (with a few exceptions, see Caveats, below) is assigned an AI via data.scripts.SS_AI_ModPlugin. This is fairly well-documented code, explaining how and why different AIs get assigned to different things, etc.

Once the AIs are assigned, depending on the AI, different things happen, obviously, but:

The AIs all use a common data system; this is part of what makes the AI very fast, by reducing search scopes, etc. This is located in data.scripts.plugins.ShipThreatPlugin.

The AIs call some common methods that are useful and that I (gradually) have cut out duplicates of, etc. to de-clutter the source.

Each ship AI instance calls a number of methods in various classes outside the main class. This was done mainly to de-clutter the main ship AI class so that it's easier to read.

Auto-fire AIs operate completely independently of Ship AIs; this is by design.

System AIs operate completely independently of Ship AIs; this is by design.

Caveats / Mea Culpa

1. The AI doesn't currently support the Avoid command and is, in general, a little weaker in terms of supporting Command Point commands than it should be. You'll see that this is somewhat less-necessary than it is in Vanilla, however; the current (crude) threat-management system does a pretty good job of keeping Frigates from attacking far-more-powerful enemies, for example.2. The AI's support for Omni Shields is pretty basic atm, and rather easily exploited.3. MIRV missiles aren't supported at all atm, due to being unable to get the data I needed from the SS engine atm. Alex says there will be a fix for that, probably not until the next major SS update, though.4. Drones that use a strict formation aren't supported at all because of other engine-side info I need but can't get (easily / quickly).5. The Phase Cloak AI is pretty lame right now. I think it'll have to wait until I re-write my threat system.6. There are probably a bunch of other little problems, goofs, extraneous / inelegant code sections and areas where my documentation fell a little short of ideal. The threat system is very inefficient and inelegant atm and there are some ugly kludges in places where we'll almost certainly have some proper JSON support later on, like missile engine-ignition timers, etc., where I couldn't be bothered this round. Please don't hate on me, I've been Rather Busy for the last year and a half and have only just now had a period of something like free time to get this thing finally ported out of Vacuum, fixed up and moderately polished so that it's something moderately like Ready.7. If you think X sucks, fix it, document how the fix works... and send me a fix. Eventually you'll be able to just fork this, when I think it's ready for Git access, but until then, treat this work in the spirit it was given to you.8. The AI probably has some major ways to exploit it that I don't know about, because I couldn't test every possible squirrel case or weird tactic that could break it. That's OK; we can learn from these things. Just let me know how you exploited it, so that we can all discuss fixes.9. If you want to write a System AI that makes use of the structural improvements that make the base AI fast, that's non-trivial; we can talk about that later on, if this proves to be a popular project and we all want to use this. Right now, just leave your System AIs alone and they'll Just Work, so long as they don't need AI Flags set.

Lastly... I don't think there are any crash bugs left, but if there's anything I've learned from SS modding, it's that a public release inevitably means that Nature will provide the millionth monkey, hah.

Pretty excited to break into this at a later date to see if I can write a few AIs for a couple things I want to bring to my mod! At the very least I want to test the difference that this AI has over vanilla! Cool stuff Xenoargh!

System AIs operate completely independently of Ship AIs; this is by design. Alex's system of AI Flags is not currently supported; modded System AIs that depend on Flags will fail or will operate in weird ways. Perhaps later I'll support this, as it's a reasonably-good method to communicate efficiently and it'd make modded AIs that expect that work, but very few do atm.

Note that this will break some II/SS+/Templar/THI/Exigency system AIs and degrade most of them. AI flags are a good forward-facing way to cheaply add checks for things that are generally quite difficult to calculate, and ultimately match what the AI is already doing. It is absolutely worth supporting.

You might want to amend your statement from "few" to "most".

Also, if you haven't done this already, I SERIOUSLY suggest implementing this mod as two parts; one, a vanilla AI replacer; two, a library. Being able to use your AI as a framework for specific AIs to put on exceptional ships, is valuable to many developers who would rather NOT replace the vanilla AI on most ships.

I'll see about the AI Flags when I'm done rewriting the threat code, add support for Avoid, add a few more methods to move things out of the main state machine, etc. These are higher priorities atm.

I wasn't aware that AI Flags had finally started to get used- the last time I looked at that, hardly anybody was bothering. Supporting them in a reasonably-good fashion is non-trivial but it's probably not too much work and won't slow the code down much if it's done sensibly.

It's already basically ready as a library; see how it's broken down into method toolsets. The ship AI basically calls methods for most of the heavy stuff at this point and will probably become entirely based on that model, so that it's really clean and generating new behavior for <specific activity> is largely just writing / altering the method for <specific activity>, rather than digging through the entire state machine.

There are a few things where it's not doing that yet (for example the Command interpreter) but it's the direction it's going.

It'd need some minor structural changes so that it'd be efficient in that use case, however; the baseline is primarily designed to replace the Vanilla AI wholesale and that's my primary interest, frankly.

Alpha 2; improved threat-management system for better speed and possible future improvements; Omni shield management is a little more solid. Please let me know how well it's playing atm.

Next step is to make the core of the ShipThreatPlugin work for mods that merely want to run a single AI instance but keep the core efficiency of the AI and not have to reinvent wheels, rather than replacing the entire Vanilla AI; I'll set up a way to do that that is convenient to coders who just want to work on specific AI behaviors, etc.

Then I'll work on the Command interpretation a bit more, so that that is reasonably tight before looking at AI Flags. I will probably take a brief break before I get to that, however, to get another prototype project to the point of alpha, as it's something that rather needs doing.

The load on the ship AI pretty much disappeared and we're back to PDAI being the "cpu hog" of the collection, at < 1% of total cycles used on average during combat. Still looking at what should be done to facilitate individual AIs; probably the best method's the simplest, an instanceof check that prevents data collection and all of the distance checks if a root ship isn't an instance of StandardShipAI or a class that implements it. Same with weapon AIs, etc., since they're dependent on that data to function. There may be some order-of-operations issues there; will have to check it out.

I'm pausing before working on that problem (and then getting on to AI Flags support, Command interpretation, etc.) to get another project done; it's something that should be pretty quick to get to an alpha state, though.

I'm aware that the current AI has some obvious flaws, but I think it'll do for some testing and feedback (i.e., let me know where it's still horribly bad, etc.).

Oh my goood I've been waiting for this. The way that fights and escort groups prioritize remaining in formation over everything else and won't, if their escort target is harassing an enemy target because it's a close support ship and its target is an assault/strike vessel they just sit there next to it uselessly until the enemy is within range to target the close support ship instead of recognizing that the enemy is within engaging-distance of the ship they're supposed to be escorting and essentially being switched to engage the enemy until the ship they're escorting disengages, and now there's hope of that being fixed and I can stop bugging Alex about stuff that would probably require a massive reworking of the entire combat system!

The behavior you've just described doesn't happen with this AI, generally speaking; at worst, your escorts will hang back from heavy engagements because they're scared of the enemy's total strength in an area.

I'm still working on my other little project atm, so I'm still not done splitting this out into a library / utility mod and the active part yet. I'd like to get more feedback about how it's working for people before I do that, too, to make sure there aren't any really major issues remaining.

That doesn't happen with this AI, no, although right now it certainly still has some unsolved problems

Among other things, after getting detailed feedback from a local SS player here who was kind enough to test:

1. Escort command is fixed; ships will now actually perform Escort more-or-less correctly and will do a better job when given specific attack orders.2. The bug reported with Burn Drive is fixed.3. Autofire AI no longer wastes shots on Hulks.

When I'm sure that Escort works well-enough to be considered a real improvement, I'll release Alpha 4.

Future Plans:

I still need to do some work on the Threat Assessment part of the AI; among other issues, the AI's still having some problems with deciding which enemy / missile to point shields at a little too often and it's having some specific issues with being a missile-boat, and I am going to try and get it to correctly weight ships that have targeted it, vs. ships that are merely close.

I also need to get the AI to raise shields if it thinks it's going to collide with a friendly ship (mainly this is causing some issues during early parts of a battle / mission) and I need to work on certain types of missile-launcher AI situations; basically, when to Harpoon-spam, when to use Reapers. Right now both things are pretty bare-bones; if the AI thinks it can hit, it fires; it's not very picky about it. I'd also like to work on having the AI attempt to do some deliberate alpha-strike and Soft Flux management stuff.

I have written a "broadside" AI, too, although it's still basically bare-bones functional; it can be activated via a Hull Mod. It essentially gives the AI a different movement pattern, where it attempts to circle its main target at maximum range, rather than getting close. It works pretty well for ships designed for that pattern. Eventually I'll also have some Hull Mods that tell the base AI to do some other things, like avoid combat where possible (for LRM boats and carriers) and other stuff like that, where the default behaviors aren't ideal.

I'd like to hear more detailed feedback about the current issues with Alpha 3, though; my objective is to get this fixed up to a "good enough" stage reasonably quickly, so that I can get to breaking the mod up into the library-code-side (for modders) and the player-code-side (i.e., a good base AI with some cool behaviors / tweakable behaviors).