Jump to content

Possible to Save Ship from Persistence File?


Recommended Posts

Claw, I asked this in the mod request thread, but I don't think you saw it so I'll ask it again here. Do you mind if I take a look at your source and repurpose it for use in Kerbal Construction Time? I had a similar thing working in 0.25 that got broken in 0.90 and your method seems to solve the issues I was having. I need a similar functionality to recover ships back into vessel storage directly. Thankfully I don't feel the need to reset EVERYTHING, but I had a couple things I reset back to "default" values when I was testing in 0.25.

It sure isn't the nicest way of handling things, and isn't comprehensive at all, but here's what I had for "sanitizing" the ship's ConfigNode:


private ConfigNode SanitizeShipNode(ConfigNode node)
{
//PART, MODULE -> clean experiments, repack chutes, disable engines
foreach(ConfigNode part in node.GetNodes("PART"))
{
foreach(ConfigNode module in part.GetNodes("MODULE"))
{
string name = module.GetValue("name");
if (name == "ModuleEngines")
{
module.SetValue("staged", "False");
module.SetValue("flameout", "False");
module.SetValue("EngineIgnited", "False");
module.SetValue("engineShutdown", "False");
module.SetValue("currentThrottle", "0");
module.SetValue("manuallyOverridden", "False");
}
else if (name == "ModuleEnginesFX")
{
module.SetValue("staged", "False");
module.SetValue("flameout", "False");
module.SetValue("EngineIgnited", "False");
module.SetValue("engineShutdown", "False");
module.SetValue("currentThrottle", "0");
module.SetValue("manuallyOverridden", "False");
}
else if (name == "ModuleScienceExperiment")
{
module.SetValue("Deployed", "False");
module.SetValue("Inoperable", "False");
module.RemoveNodes("ScienceData");
}
else if (name == "ModuleScienceContainer")
{
module.RemoveNodes("ScienceData");
}
else if (name == "ModuleParachute")
{
module.SetValue("staged", "False");
module.SetValue("persistentState", "STOWED");
}
}
}
return node;
}

Link to comment
Share on other sites

Claw, I asked this in the mod request thread, but I don't think you saw it so I'll ask it again here. Do you mind if I take a look at your source and repurpose it for use in Kerbal Construction Time?

No, sorry. I did not see that request. And my add-ons fall under this license: https://creativecommons.org/licenses/by-nc-sa/4.0/ Which basically says you can copy/use/modify/build on it so long as you give some credit, is for non-commercial use, and that you follow similar sharing rules.

And I appreciate you asking. :D Feel free to take what you need. I will be working on it more today actually, so possibly some updates to follow soon-ish.

Cheers,

~Claw

Edited by Claw
Link to comment
Share on other sites

Updated my utility. One thing left to fix: handling ships that have docked in flight.

Strictly speaking, you don't need to bother with that; just recover the entire ship and let the user split it manually; yay for the re-root tool :D.

Of course, it would be convenient if you could do it automatically, and successfully.

Link to comment
Share on other sites

Well, the main issue there is that docked nodes in flight are handled differently to normal editor node connections. Plus there's a possibility that multi-docked ports or dockings that result in loop constructions could cause issues.

Link to comment
Share on other sites

Strictly speaking, you don't need to bother with that...

It's not a root problem but an internal book keeping problem. The tree structure of KSP is an expectation of all of the things that interact with a given ship. The problem with docking ports is that they create a small rift in how the ship is stored, because the linkages are created in a slightly different way when docked than when you have two things physically stuck together. That's good news because accidentally creating circular loops shouldn't be a problem, but that also means I have to do a few other things to get the ports hooked together in a way that the editor can handle.

The other good news is that even if I didn't fix the way it handles docking ports, you can still rescue a ship that has docking ports and open it in the editor without it crashing KSP. It would just require the user to manually edit the .craft file to manually restore some missing links. Also, as an added side benefit, it will likely lead in to me working on a fix for the "can't dock / undock" bug that's been around for a while. But that's starting to get way off topic. :P

I also built some "factory restore" code that will put the ship back into a fully reset state (as requested). I haven't turned it on yet though because it will be destructive to a wide variety of mods. So I'm waiting until if/when I get around to making a GUI so that I can have that as a toggle option.

Cheers,

~Claw

Link to comment
Share on other sites

For the defaults module settings, would opening the appropriate .cfg file be an option. Run the code so when it gets to a module tag in a part open the corresponding .cfg file and get the default values, over write the lines in the sfs/craft file, and keep on going?

That's how I would do it. At a quick glance this is just going through every line of the file correct? Easy enough to save the partname as a temp variable and if module is encountered open the cfg file get that info and write it. While I've not done python or c, I have done this exact thing in VB and php.

Link to comment
Share on other sites

It's not a root problem but an internal book keeping problem. The tree structure of KSP is an expectation of all of the things that interact with a given ship. The problem with docking ports is that they create a small rift in how the ship is stored, because the linkages are created in a slightly different way when docked than when you have two things physically stuck together.

Ah, okay. Hmm... multi-docked ships seem like they would be quite a bit harder to deal with unless the "first" docking node is treated specially somehow; how do you identify which link should be kept, and which should be removed? Or for that matter, identify multi-docking in general? It's not really enough to just go one/two level/s up/down the tree from the docking port and examine the parts given some of the crazy contraptions people have built :(.

Link to comment
Share on other sites

For the defaults module settings, would opening the appropriate .cfg file be an option. Run the code so when it gets to a module tag in a part open the corresponding .cfg file and get the default values, over write the lines in the sfs/craft file, and keep on going?

Well, you could approach the problem in a multitude of ways to reset the parts. For the current setup, the add-on only resets things that cause the editor to fail. There is also a piece of code in there (not active yet) that resets each part to the same state it would be in if you had just selected it out of the editor list. It actually seems to work very well in the testing I've done so far, but it will be very incompatible for certain mods which is why I am waiting till I can make it a toggle option.

You could probably also read the .cfg files and load things that way. I did not choose that route because sometimes what's listed in the .cfg files isn't all of the startup parameters for a given module. I did not confirm that by actually investigating the .cfg files, but I was afraid that method would be prone to error, and chose a different way. So I'm not saying it can't be done that way, I simply didn't look...So it might be perfectly valid.

The mod compatibility problem that I'm actually referring to is that with mod parts, resetting everything to "factory" state (however you choose to do that) can be disastrous. Take for instance, Procedural Wings. PWings (to my understanding) stores values for wing shape and parameters in the part module. So if I were to reset the part module to a "brand new" state (as if you just pulled it off the parts list), any work done with PWings would be completely destroyed.

Ah, okay. Hmm... multi-docked ships seem like they would be quite a bit harder to deal with unless the "first" docking node is treated specially somehow...

Actually, it does treat the first docking port differently. I haven't inspected a lot of multi-docked structures directly at the savefile level, but enough to know they are different. This is one of those things that I anticipate will be reasonably easy...but it may also turn out to be a nightmare. :P

Cheers,

~Claw

Link to comment
Share on other sites

It's actually included on my bug fix & utilities page, which is rapidly becoming unwieldy. http://forum.kerbalspaceprogram.com/threads/97285 Technically it's still "Add-on Development", but I will likely keep the utilities all together to help manage my time (as you hinted).

I suppose I should update my signature to reflect those additions. :P

Cheers,

~Claw

Link to comment
Share on other sites

:D :D :D

she made orbit with a heavy+ cargo! and ooh boy what a first successful run it was...

zUvbL7N.png

QW5A65e.png

mz5egie.png

Space Shuttle Intrepid made heavy plus cargo delivery to 172km. Second run made it to 182km. Landed her at KSC. Then I ripped out everything in the cargo bay leaving the bare floor making her as light as possible, and turned her around back to orbit only by reducing the fuel amounts in the external tank and lower liquid boosters (solids are nearly impossible at this time to lift heavy+ cargo - I should know - I spent 12 hours fighting it lol)! Success!!! A newb-friendly shuttle (hopefully) capable of simple empty flights to space, to capable of anything you can fit into the Mk 3 cargo bay without tweaking anything but fuel amounts! This thing is powerful. Easy. And beautiful. She's a dream to fly. The pictures don't do it justice. :D :D :D

She can also return abort to KSC with any cargo, including the heavy+ you see above. Pics and vid later for that piece of engineering sweetness.

275 parts empty. 304 parts with the heavy+ cargo. :) Not bad. I hope to reduce part count further once I tweak it further. After tweaks, and a video run, she'll be ready to publish.

Claw,

Publish your addin as a separate thread. People need to know this exists!

Link to comment
Share on other sites

:D :D :D

she made orbit with a heavy+ cargo! and ooh boy what a first successful run it was...

Thank you for the pictures. That kind of feedback makes my effort feel worth while. :D

Sadly this comes too late to save my SSTO shuttle (I made a new one and a new KSP is out now), but one million internets to Claw anyway!

Sorry... :( If only I knew how to mod back then.

Cheers,

~Claw

Link to comment
Share on other sites

Tweakable 3 made heavy+ delivery at 200k last night comfortably. Removed fuel lines and redid tank. 20 less parts! Needs slight vertical adjustment to find balance sweetspot between empty and full cargo. Booster tweaks up next.

Space Shuttle Claw (Intrepid Class) after 200k heavy+ delivery.

NYAZ17Jh.jpg

Edited by inigma
Link to comment
Share on other sites

As promised. Released! I'll have to link this thread back to the OP on Monday. But for now, Claw and Starwhip are credited with rescuing this craft from its otherwise untimely end.

Thank you guys. Your work was well worth it.

Thread link and craft file:

http://forum.kerbalspaceprogram.com/threads/108219-STS-1-Space-Shuttle-%28NASA-Replica-Easy-to-Load-Fly%29-Full-O-Y-Tanks-to-Orbit-VIDEO-CRAFT

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 2 months later...
  • 9 months later...

I hate to necro this thread, but I see no better option...Does anyone have a version of this tool that works in 1.0.5? Whenever I try to use it now, it throws a "MissingMethodException: Method not found: ConfigNode.SetValue" error (I assume this was broken in the 1.0 update).

Thanks in advance.

Link to comment
Share on other sites

  • 3 months later...
On 4/7/2016 at 1:19 AM, Three1415 said:

I hate to necro this thread, but I see no better option...Does anyone have a version of this tool that works in 1.0.5? Whenever I try to use it now, it throws a "MissingMethodException: Method not found: ConfigNode.SetValue" error (I assume this was broken in the 1.0 update).

Thanks in advance.

At the risk of nechroing again, yes!  I have a tool that extracts all ships from any save (.sfs) file and wraps them in a .zip archive.

http://www.Kerbaltek.com/craftkitchen
(bottom of the page)

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...