Multiple versions of ships depending on gamerule

I’ve been working on something like this for the last few months. There are issues:

  1. There’s no way to communicate game rule flag states to SHIP files, build and research, AI, etc. You have to create a separate version of each SHIP per combination of game rule flag states.
  2. If you create multiple versions of each SHIP file, the AI will fail because many ship names are hardcoded in each race’s “ai_build.lua” script. You cannot communicate the game rule states to this file either AFAIK.

Meh. So much time wasted.

You are probally right with 1)

With 2) its possible to add ships by there class (defined in classdef.lua in the ai files) and be-gone with hardcoded ship names (engine works out if its currently available to the race or not).

For example

-- for ai_build
if (s_militaryStrength > 25*sg_moreEnemies) then
	ShipDemandAddByClass(ePlatform, -2)

-- eplatform looks like this
squadclass[ePlatform] = {

This will reduce research demand for all relevant platform ships in the table if you outnumber the enemy by a-lot (some voo-doo magic behind the scenes decides if the race has the ships available to them as the table contains ships from all factions, but if so it adds demand to it)

1 Like

Are there equivalents for the NumSquadrons and NumSquadronsQ functions that work with these classes?

“ai_build.lua” uses them over and over again.

Can I create custom classes?


Is the -2 in ShipDemandAddByClass(ePlatform, -2) a relative value compared to some other number?

Don’t know for a fact but id guess NumSquadronsFamily() and NumSquadronsFamilyQ

Yes you can create custom classes, up to 7 more (from 24 to 31, unsure if you can use 32 so maybe 8)

Here are the values of the default ones however (for example eScout is essentially just the number 4, but defined engine-side)


So in classdef.lua on line 348-352 it would looks like this

eUselessShips = eMaxCount
eBattleCruiser = eMaxCount + 1
sg_maxClasses = eBattleCruiser+1
eDestroyer = eMaxCount + 2
sg_maxClasses = eDestroyer  + 1

Whoever made this was feeling very confused at the time and made it ugly as possible, but if you wanted to add classes and tidy it up, you would want it too look like this

eUselessShips = eMaxCount -- (22)
eBattleCruiser = eUselessShips + 1 -- (23)
eDestroyer = eBattleCruiser + 1 -- (24)
eCustomClassExample1 = eDestroyer  + 1 --(25)
eCustomClassExample2 = eCustomClassExample1 + 1 -- (26)
eCustomClassExample3 = eCustomClassExample2 + 1 -- (27)
sg_maxClasses = eCustomClassExample3 + 1 -- (28)

-- then add your tables with your list of ships

squadclass[eCustomClassExample1] = {

squadclass[eCustomClassExample2] = {

squadclass[eCustomClassExample3] = {

Essentially the function in ai_build is ran every 2 seconds by each race, and so somewhere else in the code you might usually add 1 demand to platform but, as in my example, if your army is huge we are then lowering demand for that research as it’s not that important to research that anymore. -2 is essentially just lowering its demand by 2 from whatever its demand is (ie if its 100, it becomes 98).

Hope this helps and I haven’t over-explained it too much!

I found out NumSquadrons and NumSquadronsQ will crash with an error if the ship is not mentioned in either the build script or research script. Is it possible to create build items that don’t work and are invisible and the AI will ignore? (Just curious. It won’t fix my actual problem.)

If this is the case for a race, just remove the NumSquadrons and whatever depends on the result in that race’s ai_build.lua. All races ai_build.lua’s are independent of each other.

For example if a race in question has no shipyards, there’s no point adding fake demand for shipyards (and the functions crashes anyway as you say if you haven’t defined a races shipyard).

I mistyped here, I meant to say demand for the ship - not research demand (that’s defined somewhere else)

It’s only two ships from among all four races, so it might be easier just to temporarily create dummy build script entries for them. Eventually I will need to find or devise replacements for NumSquadrons and NumSquadronsQ.

Hi. You could make a whole separate race folder using the configuration filter that would only work with the selected game type so that you could change out all of the AI and build files.

That is interesting, but I still don’t understand how filters work. For instance, where do you set them and where do you get them. Some members tried to explain them to me before. A thorough tutorial would help, but everyone who needs to seems to understand them already. :frowning:

unpack Star Trek Continuum 2310 and you’ll see how to do it. This might not be exactly right but:

There’s a file ‘configfilters.lua’ in the scripts folder where you can set which filters are included or excluded. This applies to the whole mod so you can include and exclude game types.

Then you go to the scripts\rules folder to set the filters for each game type. There’s a setting for maps and races that are included in that game type.

Then go to scripts\races to set the filters extensions in the race.lua files. So here you could make duplicates of the races to set everything up separately. Like Taiidan_a for one game type and Taiidan_b for another game type.

Sorry, I need custom races for game rules, not game types. (Actually, each combination of four different game rules, for a total of 16.) Is this possible?

(I edited the thread title to clear up any confusion.)

ah okay, yeah that should be possible too:

Look how the game rules for strikecraft only or carriers only are set up. They’re referenced in the gamerules lua to a file in \leveldata\multiplayer\lib. From there they either grant or restrict a list of research items in the file: \scripts\races\racename\deathmatch\props\gbx.lua

You could use this to start a specific research tree for that game mode.

So all 4 research trees in the same research.lua but with different starting research items to keep them all completely separate.

You’d have the problem of the different ship variants all showing up as greyed out in the build menu, but you could either make different build ships variants for each game type with different build families, or there was a thread on how to get ships out of the build tree completely based on a script in the main rule here:

This is what I’m already doing, but since all the ships belong to the same race the AI doesn’t know that there may be four (or more) versions of a resource controller, for instance, and is unable to build the correct one. (Or see more than just one.)

Ah ok. Maybe you could set up the AI to build acc. to classes instead of the kSPACESHIP entries?

Then add a bunch of new classes in classdef?

I wonder if you could separate the AIs in AIbuild with the IsResearchDone function?

or maybe with:

if (Player_HasResearch(playerIndex, “Reseach that sets race type”) then

Those functions are outside the AI scope (according to the wiki).

If I find replacements for the NumSquadrons and NumSquadronsQ functions then yes I can do this. One problem is that if you feed these functions a ship that doesn’t exist you get a crash. Otherwise I could just write a wrapper that feeds the function multiple ships one at a time, and who cares about the ones that don’t exist?

I was told there’s an hardcoded upper limit on the number of classes you can define or you (presumably) get a crash.

Sorry, by ‘crash’ I don’t mean CTD. It’s just the script that bugs out repeatedly.

Yeah, that’s a pickle…

But wouldn’t the set up be the same if you separated all of the races out instead of making it one of the game options? Like: Hiigaran Kith S`Jet, Outer Rim Hiigarans, Hiigaran Separatists, Hiigaran Attack Force Fury (or something like that haha)

Then the player could set up the game the same way, but all of the script folders would be separate.

My ships vary only slightly. Right now I would need 16 versions of HGN, VGR, KUS and TAI. If I add another gamerule then I will need 32. With my luck I likely will encounter a hardcoded race limit.