Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Presets: Internals

magico13 edited this page Jul 12, 2015 · 1 revision

Preset System Structure

So you've read the Presets page and want to know a bit more about how the system works, it's quirks, and the Preset files themselves. Perhaps you're a mod author who wants to incorporate KCT into your systems, or perhaps you just want to make some fun Presets to share with others and want to make sure you've played around with everything you can. Well, here's all the "behind the scenes" info you need. For this, we won't be using the in-game GUI. Just a text editor and a file explorer.

Structure of a Preset File

Below I provide an example of the standard structure of a Preset file. You can use this as a base to make your own Presets without touching the GUI. You'll quickly see there are 4 parts: a header-like structure and 3 nodes corresponding to the 3 Preset-specific sections of the Settings GUI.

The Header contains the options presented in the GUI for saving a new Preset, and an additional "allowDeletion = true/false" element. This cannot be altered in the GUI and is what controls whether or not a new Preset can be made with the same shortName. It does not prevent actual deletion of the file!

The three nodes (KCT_Preset_General, KCT_Preset_Time, and KCT_Preset_Formula) correspond pretty clearly to the three sections of the Settings GUI, so I won't cover them again here. They also correspond exactly to the classes that contain that information in the KCT_PresetManager.cs file.

KCT_Preset
{
	name = Default
	shortName = default
	description = The Default KCT Settings
	author = magico13 (KCT)
	allowDeletion = False	
	career = True
	science = True
	sandbox = True
	KCT_Preset_General
	{
		Enabled = True
		BuildTimes = True
		ReconditioningTimes = True
		TechUnlockTimes = True
		KSCUpgradeTimes = True
		Simulations = True
		SimulationCosts = True
		RequireVisitsForSimulations = True
		TechUpgrades = True
		StartingPoints = 15,15,45
	}
	KCT_Preset_Time
	{
		OverallMultiplier = 1
		BuildEffect = 1
		InventoryEffect = 100
		ReconditioningEffect = 1728
		MaxReconditioning = 345600
		RolloutReconSplit = 0.25
	}
	KCT_Preset_Formula
	{
		NodeFormula = 2^([N]+1) / 86400
		UpgradeFundsFormula = min(2^([N]+4) * 1000, 1024000)
		UpgradeScienceFormula = min(2^([N]+2) * 1.0, 512)
		ResearchFormula = [N]*0.5/86400
		EffectivePartFormula = min([C]/([I] + ([B]*([U]+1))), [C])
		ProceduralPartFormula = (([C]-[A]) + ([A]*10/max([I],1))) / max([B]*([U]+1),1)
		BPFormula = ([E]^(1/2))*2000*[O]
		KSCUpgradeFormula = ([C]^(1/2))*1000*[O]
		ReconditioningFormula = min([M]*[O]*[E], [X])
		BuildRateFormula = (([I]+1)*0.05*[N] + max(0.1-[I], 0))*sign(2*[L]-[I]+1)
		SimCostFormula = max([C]/50000 * ([PM]/[KM]) * ([S]/10 + 1) * ([A]/10 + 1) * ([L]^0.5) * 100, 1000)
		KerbinSimCostFormula = max([C]/50000 * ([L]^0.5) * 10, 100)
		UpgradeResetFormula = 2*([N]+1)
		InventorySaleFormula = ([V]+[P] / 10000)^(0.5)
	}
}

Shipping KCT Presets with Other Mods

KCT can automatically detect and load Presets in folders other than the default GameData/KerbalConstructionTime/KCT_Presets folder. All you must do is create a KCT_Presets folder under your mod folder and include your Preset files there. For example:

GameData/YourMod/KCT_Presets/MyPreset.cfg

There must be only one directory level between GameData and KCT_Presets, so you can't create a GameData/KCT_Presets folder or a GameData/MyMod/PluginData/KCT_Presets folder as KCT will not find these. Presets in other folders are loaded AFTER the ones in the KerbalConstructionTime folder, which you can use to your advantage (see below).

Preset Exclusivity and Overriding

There can be only one Preset with a given shortName loaded at a time. If a Preset is loaded later that has the same shortName as an already loaded Preset the older, already loaded Preset is discarded and the new one is used. Since Presets in the KerbalConstructionTime folder are loaded first, any Presets located in any other folder can override these Presets. So you could ship a default.cfg that overrides the KCT default.cfg. This is set up this way to make things more configurable for modders. IF THIS IS USED INAPPROPRIATELY THE ORDERING WILL BE REVERSED. Don't make me take away this privilege by intentionally screwing up peoples saves, or I will reverse the ordering and make it so the first Preset found is used instead.