Overview
This guide goes over three things:1. A pseudo-mathematical process to significantly improve region density and diversity2: A very basic guide to general region terminology that will soon be replaced by another guide from yours truly3. An explanation with examples of how to use subregions.
Intro
If you are looking for an introduction for regions, this is not the guide for you. Here is a significantly better guide for learning basic region functionality.
Regions have always given me a huge amount of trouble because there isn’t really a good formula for how to make them, and every guide online that I’ve found so far explains them by saying “just play with the values and see what happens.”
This has led to a lot of really frustrated modding sessions where the rest of the mod is basically finished, but the regions aren’t right and the whole thing looks off. Honestly ship diversity in campaign is probably one of the most overlooked but REALLY important parts of a mod that make a significant impact on replayability.
The aim of this guide (as mentioned in the title) is primarily to discuss the fleets and fleetCount sections of the regions file to attain the best possible ship diversity as well as understanding subregions.
This guide comes with a VERY barebones regions syntax explanation that should be used as a refresher rather than a learning tool. Some of the information found within it is outdated. To reiterate before you go on, if you are new to regions then this link will take you to a better guide for you.
Setup
Ideally, a regions file should be one of the last things you add to a mod. The perfect regions file primarily spawns in the most ships possible from your fleetPallete, but also has to fit in the small gap between empty and overbearing.
An easy way to avoid doing all of the following is to just make a ton of really big “unique” sections and then play with the unique fraction until you get something that looks good.
Unfortunately, this isn’t possible for a lot of more complicated factions that may want to use unique specifically for bigger ships or planetoids to list some examples. In this case you are going to have to write an actual regions file, and unless you want your entire beautiful mod to end up looking half-assed in campaign, you are going to actually have to put in some work.
The setup for the regions process ironically starts by not touching regions at all. The first thing you want to do is to make a list of the p costs of each ship in your fleetPallete. Personally, the fastest way to do this for me is to open sandbox and list the values on a sheet of paper before transferring them to excel.
All you need to do in sandbox is:
- type “cl” to clear the sandbox
- type in “fleetp ” followed by your faction id
- press 2 and click a ship. the mode in 2 will select the entire ship as an entity rather than any individual blocks (image below)
- with the ship selected, press 3. this will actually select the ship and it will tell you the combined p cost of every block in the ship (image below)
Once you have these written down on paper, it’s time to fire up everyone’s favorite modding tool: microsoft excel (google sheets is an ok alternative but you’re going to have to look up the commands).
Excel Stuff (part 1)
If you are interested in making the best possible regions file, this section is for you. Each faction has a different p distribution, so this will be a how-to-excel guide and not me telling you how your faction will work. NOTE: if you are using google sheets, this should all still be possible, but I don’t know the commands for it so you will have to look them up on your own.
If you read through the last section, you should have this already done. It’s a list of p costs for each of your ships. I threw in a little title and a number so it would be easier to tell what is going on, but the important thing is that its a list of ship costs (if you have a duplicate, put the number twice). I put my costs in column G, which is a completely arbitrary decision, but make sure to REMEMBER WHERE YOUR INFORMATION IS.
The next thing to do is to calculate an average and standard deviation of the data you have given. The nice thing about excel is that you actually don’t have to do math because the formulas do everything for you. Another cool thing about excel is that if you are writing an equation and click on a box, the program will automatically write the coordinates of the box you pressed in the equation.
- =AVERAGE(Φx:Φy)
- This is the average equation. replace Φ with the column your cost column is, and x and y are the first and last row where there are numbers. The colon is just a range that tells the program to look in every value between/including the two given ones. In my specific case, I had my information in the column G from rows 2-16, so I wrote =AVERAGE(G2:G16)
- =STDEV.S(Φx:Φy)
- This is the standard deviation equation. It has the same format except you put STDEV.S in front. The .S just means you are only working with numbers and does the same thing as the (now obsolete) STDEV function.
Once you have your two values, you can set up a parameter for the function. This is just defining the range that the graph will show, so obviously your minimum is going to be 0 and your maximum is going to be around your maximum ship cost. You could just plug in the maximum ship cost for your max value, but for a tiny bit more accuracy we are going to use another equation using the average and standard deviation.
- =average+3*standard_deviation
- In this equation you are obviously going to want to replace the written values with the ones you have. This is the actual equation people use when solving for any type of bell curve, so using 3 as a multiplier is important to get the full possible range that is going to include your highest ship cost.
- Here is the equation I used (top right corner for cell P5):
The last thing this part will cover is the step size. You now have a high and a low, and all you are missing is how big of a “step” you are going to take each time the function crunches numbers. As a general rule of thumb, a smaller step size means a nicer looking graph and this is basically how integrals work, but also longer loading times and for our purpose there isn’t really a reason to have more than 20 steps. The graph will look seamless anyways.
Because your low is 0, your step size will just be your “high” value divided by whatever step size you want. Mine ended up being around 4000
- NOTE: because factions have smaller or bigger ships, the step size and high value can either be REALLY small or REALLY big. The high and step value I have shown for demonstration are not benchmarks.
Excel Stuff (part 2)
Here is where the graphing comes in. We are going to generate a bell curve that gives us the deviation of the ships in the mod. This is a way to visualize how powerful the ships in the mod are so that the regions file can reflect it to get maximum diversity.
To make the graph, you are going to have two columns next to each other.
The first one (the x axis) is going to symbolize ship costs. This one is easy to make. The first value is 0. The next value is the value below plus the step we found in the previous chapter.
- In this example, I am adding the step ($L$11) to the previous value (N11)
- The reason I write $L$11 instead of just L11 is because excel has a neat feature where if you select a box and drag the bottom right corner down, the affected cells will fill up with copies of the formula in the original box, except that any movement is translated (N11 becomes N12 in box N13 and so forth). Using the $ character locks that specific parameter which allows us to drag an equation and have a constant value ($L$11 stays as $L$11 in N12, N13, and so on).
- To finish this column, we are going to drag the box down the amount of steps you chose. In my case it was 20 steps, so I pulled it down 19 boxes to make 19 new cells. The 20th cell should have your high value in it.
The other column (y axis) is going to be a really complicated equation that gives us a number which correlates to how many ship p values are “close” to the number given in the equation.
Basically just write “=NORM.DIST(NΦ,avg,deviation,FALSE)” in the column next to your first one and drag down. In this case, Φ is the same as the column to the left of it. Remember to use the $trick when inputting your average and deviation. These are the same values we got way at the beginning of part 1. Below is my example:
–Now, the last thing we have left to do is plot the points for some visual feedback. You are going to want to select both columns of data and go to the insert tab. With your two columns selected, select the scatter chart dropdown, and select “scatter with smooth lines.”
–Your graph should look something like this at the end of this process. Your x and y axis values will be different, and the peak will probably be somewhere else, but the important part is that there is a bell curve. This will be used as a visual guide to create the regions file. If you look closely, your average value should be the top of the curve.
Fleet Diversity (regions file)
If you need to brush up on fleetCount and fleets read the last chapter first for a refresher.
The first thing you want to do is set fleetCount={1,2}. This will probably change later, but it’s an important step to knowing how you want your regions to progress.
Step 2 is to deconstruct your graph. I will not be using percentage values the conventional way from left to right because the 0.0 of a regions file is in the direct center of the region.
The first thing to do it mentally take a note of how the regions are distributed. The easiest way to do this is to annotate in region fractions. I happened to have very nice numbers.
The first thing to notice is that as the region gets closer to the center, the bigger the ships get. The 0.0 is even a bit above the maximum ship size to better increase the chance of a big ship spawning in the center of your region though. There are still a few problems with this concept though. For one, 60% of the region space is allocated to a pretty small amount of ships comparatively. If you look farther than that, the only ships that can really spawn in the middle 20% are the huge ones. Also, the p allocated to the outer ring is 0, so nothing will spawn there. This is an overkill region and it could work well in your favor if you are lucky, but chances are you won’t get any small ships to spawn.
The next idea is similar, but it plays with some values.
In this image, the setup is basically the same, except that a 0.7 and 0.9 have been added. This still has a bit of the overkill and 1=0 problem, but its a tiny bit better because there are more definitions for the trailing part of the bell curve which means the computer has more attempts to spawn in mid-range ships.
Finally, there is the best option.
This design does a few things. First of all, it addresses the overkill problem by moving the 0.2 value to where the 0.4 value was. Now there is barely any useless space allocated to big ships.
The other thing is that the 1.0 value has been added back as a generously rounded up value of the smallest ship. Ideally the 2-3 smallest ships will fit into this category and can be ignored by the rest of the regions file.
The main bulk from 0.8 to 0.2 has been allocated to mid-range ships now which is also where there are the most physical ships being built. There’s a big jump before the curve, but the important part is that there is a three-part small separation starting on the top of the bell curve that enables a lot of the mid-range ships that usually get overwhelmed by big/small ships to come out and shine.
Finally, the 0.0 has been moved to 1.5*whatever the value of 0.1 (or the previous 0.0) is. This adds in an additional chance for the biggest ships in the fleet to spawn without much region allocation penalty.
At this point, your code should look something like this (of course your code will have different values, but it should follow the same model). Take note of how the fleets section matches the graph.
fleets={
{id, { {0, 150000}, {0.1, 100000}, {0.2, 60000}, {0.4, 40000}, {0.5, 30000}, {0.6, 20000}, {0.8, 10000},{1, 1000} }},
},
fleetCount={1, 2},
Once you are here, proportions need to be upkept. All there is left to do is go into the game and load a fresh region. Most likely, this region will feel sparse. That’s fine, because that’s what fleetCount is for. If you feel that the regions are a bit empty, just multiply the top fleetCount digit and all the fleets p costs by a certain number and make the bottom fleetCount digit one lower than the top. As an example, here I multiplied by 2 (notice that fleet fraction does not change).
fleets={
{id, { {0, 300000}, {0.1, 200000}, {0.2, 120000}, {0.4, 80000}, {0.5, 60000}, {0.6, 40000}, {0.8, 20000},{1, 2000} }},
},
fleetCount={3, 4},
Sidenote: your top fleetCount value most likely won’t go above 6 and really SHOULDN’T go above 8. If that’s happening, the most likely cause is that your regions are way too big. Try to keep them below 2 at the absolute highest. Alternatively you could just have like a REALLY weird ship p distribution.
Regions 101 (outdated and for quick format remembering only)
This is slightly outdated in terms of functionality of syntax, but it is correctly defined and can be used as a guide to remember how the syntax looks.
Subregions
So what if you want multiple unique spawns that are independent of each other? Or if you want two regions to spawn, but you want one to somehow be different than the other? This is where subregions come in. The basic concept is creating multiple regions in a single regions.lua file. Attached below is an un-annotated example for a random faction (222) that I will analyze.
NOTE: MAKE SURE TO HAVE DIFFERENT IDENT= FOR EACH SUBREGION
In this example, there are two subregions. The file itself is still called “regions.lua”, but notice that the two regions (ident 22201 starting on line 3 and 22202 starting on line 20) are both encapsulated in a subregions={}. If I wanted to add more subregions, I would simply add another region block inside some brackets {} and most likely give it the ident=22203.
The inside of each subregion (lines 3-18 and 20-34) follow the same exact guidelines as the previously shown regions file in the “regions 101” portion of the guide. In this specific example, I have chosen to have only unique spawns, and overall very similar stats. Both regions have the same color, position, radius, and asteroid densities.
The main difference here is that the first region only happens once and only spawns one ship named “222_ship1” while the second region happens 3 times, and each time spawns two ships named “222_ship2”.
If I wanted to, I could add regular fleets and fortresses to these regions without penalty. If I was feeling extra funky, I could make one regions.lua with the information for multiple different factions at once. Overall, most cases can just be done without subregions, but it can definitely be helpful for gimmicky factions.
Nested Regions
It is also possible to have subregions within subregions. Currently the format looks something like this:
The most simple way to explain this is imagining the outer region as a galaxy, and the inner region as a regular region. Note that the inner region overlaps the outer region.
In this situation, the galaxy is defined by the black circle and your “outer” region is the blue. It is defined with respect to the galaxy, so if you give it radius={0.1,0.15} or position={0.5,1} then it will be between 10-15% of the galaxy radius and in the outer half of the total galactic radius.
The red “inner” region, however, is defined with respect to the “outer” region. This means that if it is given radius=0.8 and position=0, it will be centered in the middle of the blue “outer” region and have a radius that is 80% the length of the blue “outer” region.
An example of a complete nested region is given below. In this example I am spawning in a bigger region with faction 28, and then spawning a smaller circle of faction 29 inside it. This will produce only one region on the map, because the color is the same, but when encountering this region, a player will see the faction 29 completely surrounded by faction 28 every time. Note that the earlier fleet method has been abridged for ease of reading.
Closing Remarks
This is a significantly more in depth region guide than most beginning modders most likely want. It is filled with information that I have to double-check occasionally, and the regions 101 is very glossed over. If you still need it, here is the guide that goes over each part of a very basic regions.lua file in depth with no mention of bell curves or subregions. Until then, this guide should still have all the information you need to understand any region possible to make in this game.
Cheers!