Jump to content

How do I modify .cfg files?


Connor.io

Recommended Posts

Alright, so I am just wondering how to edit the .cfg files of a jet engine. More specifically, I am trying to modify the stock R.A.P.I.E.R engine to increase the maximum speed and altitude it can function at, such as allowing the engine to work at up to Mach 6.5 to 7, with the max altitude being increased to 35-45 km. Any tips?

Link to comment
Share on other sites

Hi, @Connor.io

It's not that hard, but it's not plain easy neither. :) 

First things first, instead of directly editing Stock files - what would play havoc later with crafts you download from Kerbal-X, or anything else you had done before - it's better to create new parts using the original as templates, and then changing the later. This will keep your game's integrity, preventing nasty accidents as times passes and you forget about what you changed.

So your best tool is a thingy called Module Manager. Everybody and the kitchen's sink have it installed nowadays, so installing it is a no-brainer.

Then you  need to find a place on your GameData to store your custom patches, without risking something else overwritting or deleting things - what would also ruin your savegames and crafts. I like to use <KSP_ROOT>/GameData/__LOCAL for this, as Explorer and Finder makes it very easy to find it by sorting files by name. To keep things more organised, let's create a directory inside that, like "MyFancyParts". Of course, you can use any directory you want, what I'm doing here are suggestions - but historically, people following these suggestions have way less problems on missing parts out of the blue as time goes by. :)

The first task is to open the R.A.P.I.E.R config file to give it a good look. Open it in read/only mode just to be on the safe side, you will find it on <KSP_ROOT>/GameData/Squad/Parts/Engine/rapierEngine/rapierEngine.cfg. Don't worry about not understanding what you are reading, because it will take some time until you learn enough - I'm modding KSP¹ for near half its existence, and I'm still learning (and making lots of mistakes in the process!).

We will create this thing gradually, so you can understand all the steps.

Now, create a file (like <KSP_ROOT>/GameData/__LOCAL/MyFancyParts/RapierSuper.cfg) and type:

+PART[RAPIER]:FINAL
{
	@name = #$name$-super
	@author = #$author$, Connor.io
	@title = #$title$ Super
	@manufacturer = Connor.IO Manufacturing under license from #$manufacturer$
	@description = #$description$. Super variant with improved performance.
}

The code above will tell MM to take the whole PART called RAPIER (see the original file for reference!) and copy it on a new node on the prefab (the place in memory where the config files are loaded), and then edit the atribute name to be the original value appended by "-super".  Same for the remaining attributes, note that you can "inject" new data at any place, no only at the end of the original string!

Right now we just created the new copy with some information changed to help you to differentiate it from the original on the game. Now we need to make it behave differently too!!!

On the RAPIER config, you will find two MODULE sections with name ModuleEnginesFX .  This is where you define engines, and when your engine has more than one mode (like the RAPIER); you use one for each mode. In this case, we want to mangle with the ModuleEnginesFX module with engineID = AirBreathing:

+PART[RAPIER]:FINAL
{
	@name = #$name$-super
	@author = #$author$, Connor.io
	@title = #$title$ Super
	@manufacturer = Connor.IO Manufacturing under license from #$manufacturer$
	@description = #$description$. Super variant with improved performance.
	
	@MODULE[ModuleEnginesFX]:HAS[#engineID[AirBreathing]]
	{
	}
}

So we already solved half the problem: we carbon-copied a new part, and we now know how to edit one of the engine modes. So we need to understand how an air breathing engine works - we can't change what we don't know. Our changes will be inside the { } thingies on the MODULE section.

An airbreathing engine gives you propulson in exchange of LiquidFuel and IntakeAir in a precise misture (the proportion may vary from engine to engine). So every airbreathing engine needs an Air Intake to fetch IntakeAir for it. But Air Intakes also have limitations, and so these limitations pile up with the engine's own ones.

Let's first work on the engine and, if it's not enough, later we will try something on an Air Intake.

For engines, we have two constraints - atmospheric curve and velocity curve. The atmospheric curve describes how the engine behaves as you get higher, where the air pressure is smaller, while the velocity curve does the same compared to the current airspeed. Engines are usually trimmed to be optimal on a specific high and speed.

The Velocity Curve is called velCurve on the engine's node, and the original values are:

		velCurve
		{
			key = 0 1 0 0.08333334
			key = 0.2 0.98 0.42074 0.42074
			key = 0.7 1.8 2.290406 2.290406
			key = 1.4 4.00 3.887193 3.887193
			key = 3.75 8.5 0 0
			key = 4.5 7.3 -2.831749 -2.831749
			key = 5.5 3 -5.260566 -5.260566
			key = 6 0 -0.02420209 0
		}

And the meaning follows:

  1. first value is the velocity in Mach for the point you are describing .
  2. second value is the normalize value of the engine performance (1 = 100%) at that velocity
  3. the two last values are for configuring the "curve", so you have nice curves instead of ramps on the calculation (something like bezier). We will just reuse whatever we have.

You want the engine to be useable at Mach 7, so we will replace the velCurve as follows:

+PART[RAPIER]:FINAL
{
	@name = #$name$-super
	@author = #$author$, Connor.io
	@title = #$title$ Super
	@manufacturer = Connor.IO Manufacturing under license from #$manufacturer$
	@description = #$description$. Super variant with improved performance.
	
	@MODULE[ModuleEnginesFX]:HAS[#engineID[AirBreathing]]
	{
		!velCurve,* { }
		&velCurve
		{
			key = 0 1 0 0.08333334
			key = 0.2 0.98 0.42074 0.42074
			key = 0.7 1.8 2.290406 2.290406
			key = 1.4 4.00 3.887193 3.887193
			key = 4.75 8.5 0 0
			key = 6.5 7.3 -2.831749 -2.831749
			key = 7.5 3 -5.260566 -5.260566
			key = 8 0 -0.02420209 0
		}
	}
}

This piece of code will delete the original velCurve and replace it with a new one. See the new values I added, this engine will work acceptably until Mach 7.5, and then will flame out at Mach 8.

Now we need to work on the atmospheric curve, atmCurve. Follows the original:

		atmCurve
		{
			// higher thrust at altitude than even TRJ
			key = 0 0 0 0
			key = 0.018 0.09 7.914787 7.914787
			key = 0.08 0.3 1.051923 1.051923
			key = 0.35 0.5 0.3927226 0.3927226
			key = 1 1 1.055097 0
		}
  1. first value is the atmospheric pressure normalised, where 0 = space and 1 = Kerbin's sea level.
    1. Exactly what altitude is 0 dependes of the Body, EVE is 90Km while Kerbin is 70Km.
    2. EVE at sea level has a "key" value of 5.
    3. Additionally, this values are not linear so halving the key will not means double the altitude! Check this graph for reference:
      1. 800px-(updated)_Comparison_of_the_atmosp
  2. second value is the normalised value of the engine performance (1 = 100%) at that pressure
  3. the two last values are for configuring the "curve", so you have nice curves instead of ramps on the calculation (something like bezier). We will just reuse whatever we have.

This will be a trial and error process, because properly calculating these values are a bit boring. :) So let's half some values to allow the RAPIER Super to work higher, and if you find it's too much, you can edit the values to be a bit higher until you are satisfied. Rememeber, 0 is space and 1 is Kerbin's sea level, so to allow the engine to fly higher we need to change the lower keys - except the key 0, as there's no possible way for a airbreathing engine to work on vaccum!

So we get:

+PART[RAPIER]:FINAL
{
	@name = #$name$-super
	@author = #$author$, Connor.io
	@title = #$title$ Super
	@manufacturer = Connor.IO Manufacturing under license from #$manufacturer$
	@description = #$description$. Super variant with improved performance.
	
	@MODULE[ModuleEnginesFX]:HAS[#engineID[AirBreathing]]
	{
		!velCurve,* { }
		&velCurve
		{
			key = 0 1 0 0.08333334
			key = 0.2 0.98 0.42074 0.42074
			key = 0.7 1.8 2.290406 2.290406
			key = 1.4 4.00 3.887193 3.887193
			key = 4.75 8.5 0 0
			key = 6.5 7.3 -2.831749 -2.831749
			key = 7.5 3 -5.260566 -5.260566
			key = 8 0 -0.02420209 0
		}
		!atmCurve,* { }
		&atmCurve
		{
			key = 0 0 0 0
			key = 0.009 0.09 7.914787 7.914787
			key = 0.04 0.3 1.051923 1.051923
			key = 0.35 0.5 0.3927226 0.3927226
			key = 1 1 1.055097 0
		}
	}
}

The values you will need to trim are the second and third "keys" (compare them with the original!) from top to bottom.

I think this will give you a new RAPIER engine that should behave like you want. However, I wrote that at my lunch, away from my game machine, so I didn't tested it. I will check it tonight for any mistakes - but if you test it before me and it works, please advise! :) 

Edited by Lisias
Grammars... (Sigh)
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...