Autodesign and AI Ship Variety

A place for discussion of making game modifications.
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Autodesign and AI Ship Variety

Post by harpy eagle »

So lately autodesign has has been on my mind.

I mentioned in another thread that the AI never seems to use heavy weapons, even when they research them.

This is because the AI always uses 'balanced' autogeneration, which usually puts medium weapons into heavy hardpoints. It's a valid option, since I believe you get twice the shots so putting a medium weapon there actually often provides a higher damage output, with less range of course.

It would be nice though if the AI created designs for both configurations. Then the navy composition code could build some mixture of them based on whatever criteria it uses.

I've also noticed that the auto design also never uses anti-missiles. I discovered this was due to the auto design configurations, and modified it a little so that if the anti-missiles are available, it may design with a mix of direct-PD and anti-missiles. I figure a mix is good because they complement each other: direct-fire PD can autofire so is good for close-in when you need that reaction fire, while the longer range of anti-missiles means that it is great for providing cover to other ships, and much more easily creates overlapping missile denial zones.

This means that the AI can now build ships with anti-missiles.

For example, when auto-designing an ashdar escort cruiser with rapid-fire and anti-missile techs researched,

Vanilla: https://imgur.com/a/ARVi9u0

Modded: https://imgur.com/a/ob9fts4

I also tweaked siege autogeneration so that, like balanced, it includes some point defense, as missile fleets do benefit from having PD, especially against other missile fleets.

In the process I also fixed a bug in the part ordering code that was causing nested mixed_goals to not work.

NOTE: this mod is in a bit of a weird place as of r22256. There is some additional work I need to do in order to make the AI fully use the new designs in this mod. However using this mod should still work without any errors.

Updated: 02/05/2018
Attachments
AIShipDesignsMod (e1e779f).zip
(226.94 KiB) Downloaded 828 times
Last edited by harpy eagle on Wed May 02, 2018 3:54 pm, edited 9 times in total.
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Autodesign and AI Ship Variety

Post by zolobolo »

Thanks for the mod, will try it out in the next game right away

Also noticed two things:
1. You have mentioned that AI did not use heavy weapons before but I have seen them use Railguns a couple of times - maybe when they got this tech from derelict colonies early?
2. Orthin also do not use Shield Capacitors for Busbar hard-points - can you have them utilize those via this mod? Though this would not automatically mean that they will utilize them in combat, hope the vanilla AI will pick up on them once they are there :)
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Autodesign and AI Ship Variety

Post by zolobolo »

Error during a design process
Attachments
Designs.rar
(221.4 KiB) Downloaded 756 times
Design.png
Design.png (61.76 KiB) Viewed 25093 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

zolobolo wrote:1. You have mentioned that AI did not use heavy weapons before but I have seen them use Railguns a couple of times - maybe when they got this tech from derelict colonies early?
I guess I was oversimplifying things. The AI never uses heavy lasers or heavy drivers since those weapons do less damage than their medium counterparts in exchange for greater range.

There are three autodesign presets in the game, one that prioritizes damage (while mixing in PD), one that prioritizes PD, and one that prioritizes range.

Since the AI only ever uses the first one, weapons that trade damage for increased range are never used.

My aim is to allow the AI to use the other autodesign presets. Since they don't prioritize for damage as strongly, the AI will use them less, but should still mix some of them into it's fleet composition for variety.

I think the reason you saw railguns was that, being a late game tech, they do enough damage for the vanilla autodesign to include them.
zolobolo wrote:2. Orthin also do not use Shield Capacitors for Busbar hard-points - can you have them utilize those via this mod? Though this would not automatically mean that they will utilize them in combat, hope the vanilla AI will pick up on them once they are there :)
Yes that should be possible.
zolobolo wrote:Error during a design process
It's still unfinished ;) Though I did fix that bug.

The core logic is pretty much finished, aside from the special case of handling cloaking devices.

I need to go through every ship hull in the game and define which loadout presets are valid for them (so that the AI doesn't build battlecruisers with only PD, for example). That will take a bit of time.

EDIT: In case it was a little confusing, by "loadout presents" I am defining tables that look something like this:

Code: Select all

theme_loadouts 'Hawk' {
  config_loadout 'Destroyer' { 'balanced', 'escort' },
  config_loadout 'Light Cruiser' { 'balanced', 'standoff' },
  config_loadout 'Missile Cruiser' { 'standoff' },
  config_loadout 'Escort Cruiser' { 'balanced', 'escort', 'standoff'},
  config_loadout 'Military Transport' { 'balanced', 'escort' },

  config_loadout 'Heavy Cruiser' { 'balanced', 'standoff' },
  config_loadout 'Battlecruiser' { 'balanced', 'standoff' },
  
  --for carriers, escort is all interceptors, siege is all bombers, balanced is a mix
  config_loadout 'Escort Carrier' { 'escort', 'standoff' },
  config_loadout 'Light Carrier' { 'balanced', 'escort', 'standoff' }, 
  config_loadout 'Fleet Carrier' { 'balanced' },
  
  config_loadout 'Fleet Base' { 'standoff' },
  config_loadout 'Star Base' { 'standoff' },
}

theme_loadouts 'Star' {
  config_loadout 'Armed Merchant' { 'escort' },
  config_loadout 'Military Transport' { 'balanced', 'escort' },
}

theme_loadouts 'Blade' {
  config_loadout 'Destroyer' { 'escort' },
  config_loadout 'Light Cruiser' { 'balanced', 'standoff' },
}
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Autodesign and AI Ship Variety

Post by zolobolo »

harpy eagle wrote:The AI never uses heavy lasers or heavy drivers since those weapons do less damage than their medium counterparts in exchange for greater range.
Yes that was my assumption as well. When getting Railgun early on due to salvaged derelict colony tech, it is the logical decision to equip due to damage output vs early game tech

Overall, the concept looks great, and you will seem to have a great deal of flexibility in assigning possible roles to ships as well as creating new roles if necessary

Do all ships of all races fall then into one of the above general category of destroyer, Light Cruiser...etc?
What about faction specific one such as Frigates in case of Yoral?
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

zolobolo wrote:Do all ships of all races fall then into one of the above general category of destroyer, Light Cruiser...etc?
What about faction specific one such as Frigates in case of Yoral?
Each ship hull type (drawer/config combination, in the code) can be specified individually. I need to go through each one and make sure the loadouts I've chosen make sense.
CapnDarwin
Posts: 14
Joined: Wed Apr 04, 2018 5:29 pm

Re: Autodesign and AI Ship Variety

Post by CapnDarwin »

Another great mod! Thanks for the hard work.
nathanebht
Posts: 120
Joined: Sat Oct 21, 2017 2:48 pm

Re: Autodesign and AI Ship Variety

Post by nathanebht »

Thanks for creating the mod! I'd suggest having the AI prioritize medium weapons over PD defense weapons. Medium are more versatile.

Heavy over medium. The AI hardly ever utilizes heavy weapons and the extra range works better in many situations.

Anti-missile added only if there is extra defense slots. For example, if there are 2 light slots then the 2nd is anti-missiles. If there are only 2 medium slots then one medium and one pd or anti-missile. If you can have an AI compare it's missile tech versus weapon tech, then you could add some extra logic.

The tactical combat AI mod seems to make missiles much less useful. Perhaps, not have them used on ships except in their dedicated slots?
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

nathanebht wrote:Heavy over medium. The AI hardly ever utilizes heavy weapons and the extra range works better in many situations.
The range is especially useful for slower ships. But in many cases putting a medium weapon in a heavy mount does result in more raw damage, so I don't want to discount it completely.
nathanebht wrote:The tactical combat AI mod seems to make missiles much less useful. Perhaps, not have them used on ships except in their dedicated slots?
I'm considering that for 'balanced' designs. It is kind of inefficient to have a mostly beam-equipped ships and then throw in a missile weapon that launches only 2 missiles. I can do this now because part of the goal with this mod is to make the AI have dedicated missile designs that it can choose from.

So if the AI decides to go with missiles for a ship, it will go very heavily with the missiles, or not.

Anyways... while looking through the auto-design aka Part Ordering code, I happened to spot this commented-out block:

Code: Select all

            -- also check to see if this part+1mod combo is better than the current
            -- best option
            --[[
            if part_name~=name
              for mod in rpairs | part.unlocked_mods?            
                if compare_fun(  mount, part, mod,
                                best.mount, best.part, best.mod )
                  cleartable(best)
                  insert( best, ..mount ,part=part, ..i, ..mod)
                end
              end
            end
            --]]
The fact that the auto-designer doesn't check any mods at all when determining the best part for a mount kind of bothered me. It means that when determining the value of a part we just have to assume that any unlocked mods can and will be added. Otherwise you run into really tricky situations where a part that is actually better with a mod added isn't considered because it happens to be worse without the mod. So I decided to take a shot at implementing it.

But... wow, what a rabbit hole that turned out to be. Things almost came together except for a couple of issues causing the AI to make strange choices.

Figuring out how the auto-designer worked wasn't too hard, but tracing the source of an issue meant working my way through layers upon layers of closures with only print statements in hand. I did manage to sort out most of the issues in the end. It still seems to ignore some of the preferences I give it for heavy turrets, so I still have some work to do. EDIT: Aha, fixed. I noticed it was only affecting the Gremak, turns out to be related to how I was generating new raider (i.e. cloaking field equipped) designs.

However, I think the ability to actually compare weapon mods when ordering parts will come in handy, and I fixed a few bugs along the way, like a missing entry in a mount type alias table, and some contradictory logic, so I guess it was worth it.

Edit: And as mentioned, I also create new preference sets for empires that have distortion field technology. In vanilla, there was only one hardcoded 'raider' preference set that autogenerated ships with cloaking fields. Now I can take any preference set and modify it, so any empire that gets access to distortion field technology will start using cloaking fields.
User avatar
sven
Site Admin
Posts: 1621
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Autodesign and AI Ship Variety

Post by sven »

harpy eagle wrote: Figuring out how the auto-designer worked wasn't too hard, but tracing the source of an issue meant working my way through layers upon layers of closures with only print statements in hand. I did manage to sort out most of the issues in the end. It still seems to ignore some of the preferences I give it for heavy turrets, so I still have some work to do. EDIT: Aha, fixed. I noticed it was only affecting the Gremak, turns out to be related to how I was generating new raider (i.e. cloaking field equipped) designs.

However, I think the ability to actually compare weapon mods when ordering parts will come in handy, and I fixed a few bugs along the way, like a missing entry in a mount type alias table, and some contradictory logic, so I guess it was worth it.
Yeah, there are a few places in the Lua codebase where I really wish I had access to a step-by-step interactive debugger, and the autodesign core logic is one of them. Dibyendu Majumdar has a nice open source Visual Studio plugin for interactive debugging of his Lua 5.3 dialect. One of these days, I may fork it to make an SiS-compatible Lua debugger. But... a VS debugger plugin is of those projects that, while it would be both fun and useful, just never seems quite high-priority enough to justify the time investment.
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

Okay! I think this is in a playable state now. I've attached a download to the OP.

There's a small patch to the strategic AI mod that you'll need in order for the AI fully make use of this. There's a bit of a complication since Sven just released an improvement to how the AI picks it's strategies, and I'd like to see about making this mod compatible with that.

In the meantime, I've attached a version of the economy AI mod that has been updated to make use of the new AI designs to the OP of this thread. There's also a mod pack archive that contains the latest research paths mod as well.
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

Some important notes:

This mod works by adding a multiple designs for each hull type, but only when a new design becomes available. Therefore you need to start a new game for this mod to work properly.

It generates designs for AI controlled empires only, so that players don't have a bunch of designs appearing out of nowhere. If you enable the ai_dev in the developer options menu though, it will do this for all empires, even ones that are player controlled.

So if you plan on playing with this mod while having the AI control your empire, you should enable ai_dev before you start your new game.

Because the strategic AI mod causes the AI to vary it's designs, the AI should start building a mixture of different loadouts for each hull type, although designs with the most raw firepower will be more prevalent.

I'm going to see about integrating with sven's new fleet composition code.
User avatar
sven
Site Admin
Posts: 1621
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Autodesign and AI Ship Variety

Post by sven »

harpy eagle wrote:I'm going to see about integrating with sven's new fleet composition code.
I think these mods/patches should be pretty naturally complementary. If we wanted to get really fancy with it, I'd guess the the warship_classification() code could probably be extended to read a design hint out of ship.source_design, creating a hook that would allow fleet templates to reward using multiple different designs based on the same hull; but that's probably overkill. I might just start by adjusting the chosen PartOrdering function based on the hull type and ai_state.strategy_cards.... A very short simple diff could get a lot of mileage here, I think. (And you don't necessarily need a PD, long range, and bombard version of a heavy cruiser, if your navy already has a mix of missile cruisers, heavy cruisers, and escort cruisers.)
zolobolo
Posts: 1544
Joined: Fri Nov 25, 2016 3:49 pm

Re: Autodesign and AI Ship Variety

Post by zolobolo »

If possible please swap the extra reactor of the Yoral Frigate to something else like reinforced bulkhead or shield

Same for Gremak Exploration Cruiser - that one has two scanners
Attachments
Seeing Double.png
Seeing Double.png (743.93 KiB) Viewed 25018 times
User avatar
harpy eagle
Posts: 296
Joined: Sat Mar 10, 2018 3:25 am

Re: Autodesign and AI Ship Variety

Post by harpy eagle »

zolobolo wrote:If possible please swap the extra reactor of the Yoral Frigate to something else like reinforced bulkhead or shield

Same for Gremak Exploration Cruiser - that one has two scanners
Youch, that would be a bug.
Post Reply