Ids of celestial bodies in the persistent.sfs file
I'm currently making a tourist planner for KSP which reads in the persistent.sfs which tourist want to do what on which planet . Here's a preview.
The problem is that although science has the whole body name, tourist contracts use a targetBody
to tell which planet
For example here is a tourist contract in the savefile
PARAM
{
name = KerbalTourParameter
state = Incomplete
disableOnStateChange = False
allowPartialFailure = True
values = 219375,0,0,0,0
kerbalName = Ludves Kerman
kerbalGender = Male
PARAM
{
name = KerbalDestinationParameter
state = Incomplete
values = 24375,0,0,0,0
targetBody = 5
targetType = Orbit
kerbalName = Ludves Kerman
}
PARAM
{
name = KerbalDestinationParameter
state = Incomplete
values = 24375,0,0,0,0
targetBody = 0
targetType = Orbit
kerbalName = Ludves Kerman
}
PARAM
{
name = KerbalDestinationParameter
state = Incomplete
values = 24375,0,0,0,0
targetBody = 2
targetType = Flyby
kerbalName = Ludves Kerman
}
}
(as you can see on my screenshot, Ludves wants to Orbit the Sun (0), Orbit Eve (5) and flyby the Mun (2))
And here is a science found
Science
{
id = mysteryGoo@KerbinSrfLandedLaunchPad
title = Observation de la glairine™ mystérieuse d’Aire de lancement
dsc = 1
scv = 0.0122894989
sbv = 0.300000012
sci = 3.85207105
cap = 3.9000001
}
- Do you know where I can find the IDs of all bodies in KSP instead of just doing every single mission?
- Are they the same between each save game?
For the moment I have found :
Sun : 0
Kerbin : 1
Mun : 2
Minmus : 3
Duna : 6 (you see the number begin to become unsorted...)
Ike : 7
Eve : 5
Thanks!
At least one way to observe this numbering in-game is to press Alt+F12 to open the cheat menu, select the "Set Orbit" pane and scroll through the list of available celestial bodies. They seem to be presented in exactly the order given by the numbers you list, i.e. Sun → Kerbin → Mun → Minmus → etc.
I believe the numbering itself comes from the order in which the bodies are stored internally in the FlightGlobals.Bodies
list (and I suspect it historically more or less reflects the order in which the various bodies were added to the game during its development). If you're writing a mod, you should be able to access a celestial body by its ID number simply by using the number as an index into this list. Conversely, every CelestialBody
object has a FlightGlobalsIndex
property that gives its index in the list.
I'm not sure if there's any convenient way to obtain this numbering directly from a save file. For a stock KSP install, it should always be the same so you could just hardcode it, but mods that add new celestial bodies e.g. via Kopernicus can presumably mix it up.
A reddit user sent a probe to all bodies and used the REF
line of the orbit caracteristics:
0 - Sun
4 - Moho
5 - Eve
13 - Gilly
1 - Kerbin
2 - Mun
3 - Minmus
6 - Duna
7 - Ike
15 - Dres
8 - Jool
9 - Laythe
10 - Vall
12 - Tylo
11 - Bop
14 - Pol
16 - Eeloo
- The values match those I have already found
- It was a fresh new game
So the IDs are the same between saves