magico13

[1.4] StageRecovery - Recover Funds+ from Dropped Stages - v1.8.0 (March 11, 2018)

Recommended Posts

Working with 0.24.1?

I haven't gotten a chance to test it yet, but there shouldn't be any reason for it not to. Most of the changes in 0.24.1 are pretty minor and shouldn't affect this code at all. With that said, if anyone is experiencing issues in 0.24.1 that weren't in 0.24.0, please let me know.

Share this post


Link to post
Share on other sites

Great mod! Serious urge to download.

Also you know what would be awesome? If this is possible to implement, could there be two sliders in the options menu that would change this mod? One slider could be for the funds returned upon recovery, going from 10% to 100% of the returns you would get from recovering a normal vessel. The other slider could be for the minimum parachute speed required to land, going from 12m/s to 2m/s.

Share this post


Link to post
Share on other sites
Great mod! Serious urge to download.

Also you know what would be awesome? If this is possible to implement, could there be two sliders in the options menu that would change this mod? One slider could be for the funds returned upon recovery, going from 10% to 100% of the returns you would get from recovering a normal vessel. The other slider could be for the minimum parachute speed required to land, going from 12m/s to 2m/s.

I am working on an update right now which adds one of the two features, just not as a slider (hmm, a slider is a good idea rather than a text box, so I may see how easy it is to use a slider instead). That option is just the funds returned percentage. I want to go back through the code that actually checks the drag to mass and calculate it as a velocity rather than a drag to mass ratio, then allow people to set what they want the velocity to be. I just haven't gotten a chance to do that yet, so maybe I'll try to get that in before I release the update I'm working on.

Additionally, if someone would be willing to provide a toolbar icon, in both 32x32 and 24x24 variants, it would be greatly appreciated! My artistic skills are... well... non-existent so otherwise you guys will be stuck with this:

Hideous_Icon.png

Share this post


Link to post
Share on other sites

New version uploaded. Biggest changes:

In-game settings menu. Only accessible in space center with the stock toolbar (Blizzy's toolbar will be added later). From this you can change the recovery percentage, the cutoff velocity (how slow you have to go), and any other settings.

EXPERIMENTAL Deadly Reentry support. If DR is installed and the vessel is going faster than the DR Max Speed then every 1% faster it is going than the speed, there is a 2% chance of it burning up. Heatshields reduce this chance by the percentage they are not used (a full heatshield reduces the chance by 100%, a used up heat shield reduces it by 0%). The default speed is 2km/s. If you go 3km/s then there is a 100% chance of burning up. A full heatshield will reduce this to 0%. Going 4km/s will cause you to burn up even with a full heatshield (200% without one, 100% with).

It isn't precise or even that realistic, but if you want realistic Deadly Reentry support you should just follow the stage down manually :P

Edit: Forgot to mention, you can disable the Deadly Reentry support by setting the DR Max Velocity to 0 in the settings menu.

Edited by magico13

Share this post


Link to post
Share on other sites

First off, I would like to say thank you to both you and Vendan for making these two mods. I installed both your mod and Vendan's mod in addition to the 30 something mods I currently have installed. Neither worked. So I was able to troubleshoot it down to Realchutes and either StageRecovery or DebRefun conflicting with each other.

Here are two logs:

https://www.dropbox.com/s/zki0wwoi13zwx2m/SR_output_log.txt

https://www.dropbox.com/s/cidmopskjdtgcem/SR_output_log1.txt

The first one I had all my mods installed with the exception of realchutes. Worked perfect as expected. Second file is running with realchutes and I did not receive any recovery notifications. I did receive a destroyed notification on one attempt, but didn't grab the log.

This is the exception I see in log1


Vessel Untitled Space Craft Debris was on-rails at 0.0 atm pressure and was destroyed.

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)


InvalidOperationException: Operation is not valid due to the current state of the object
at System.Linq.Enumerable.Single[Type] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 at
System.Linq.Enumerable.SingleOrDefault[Type] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0 at
StageRecovery.StageRecovery.VesselDestroyEvent (.Vessel v) [0x00000] in <filename unknown>:0 at EventData`1[Vessel].Fire (.Vessel data) [0x00000] in <filename
unknown>:0 at Vessel.OnDestroy () [0x00000] in <filename unknown>:0

(Filename: Line: -1)

Sorry for the trouble and thanks in advance for taking a look into it.

Share this post


Link to post
Share on other sites

Somehow it appears you have real chute installed twice. That may not be the only issue, but it's probably contributing to the problem. In the first log it is only installed once, but it definitely is running twice in the second log. Double check that you didn't accidentally put a second one somewhere (perhaps accidentally copied into another mod's folder?) then try again and let me know if you've still got the issue. If yes, then please send me the logs again and I'll see what I can do.

Checking deeper into the logs, the second realchute appears to be in GameData/RealChute/ModuleManager/Plugins/. Just looks like a botched real chute install, so hopefully it's as simple as fixing that :)

Edited by magico13

Share this post


Link to post
Share on other sites

Yup, that fixed it. Now I feel like a complete noob. Don't know how that ended up in there as I use JSGME to put it in there.. Thanks for the help!

Share this post


Link to post
Share on other sites
Yup, that fixed it. Now I feel like a complete noob. Don't know how that ended up in there as I use JSGME to put it in there.. Thanks for the help!

No worries, at least it was something simple!

In other news:

New update posted! The most major change is the implementation of a Variable Recovery Rate model (though you can switch back to the flat rate model previously used). I wasn't really planning on adding this because it's pretty similar to how DebRefund works, but this issue on github was opened and so I decided to implement it my way (but leave the flat rate option available, you can switch in the settings menu). That link also includes a fairly detailed explanation of how the model works.

The Variable Recovery Rate model has two cutoff velocities, a low and a high. If the velocity is below the low cutoff you get 100% of stock recovery, if it's above the high cutoff you get 0% (and the recovery failure event is fired). In between the cutoffs the recovery rate follows a quadratic formula which I refer to as the "Recovery Curve". The default Recovery Curve (6 m/s low, 12 m/s high) is presented below.

Additionally, Blizzy's toolbar is now supported for accessing the settings menu and the API was updated.

If you use KCT along with this then there is now the fun feature of recovered parts now being too damaged beyond repair to be added to the part inventory (but funds are still returned), conceivably the first major interaction between the two mods (additionally, KCT doesn't have a variable recovery rate or Deadly Reentry support).

Edit: Also forgot to mention, but this now (should) support KSP-AVC for version checking. If you want version checking for this mod (and many others), please check that out here: http://forum.kerbalspaceprogram.com/threads/79745-0-24-2-KSP-AVC-Add-on-Version-Checker-Plugin-1-0-4-KSP-AVC-Online

vIZdSuk.png

Edited by magico13

Share this post


Link to post
Share on other sites

Found an interesting interaction with Tweakscale and the two part recovery mods I've seen, DebRefund and StageRecovery. The SRB's are causing a negative amount of funds to be recovered. For the larger boosters you could actually end up recovering a negative amount.

When I commented out the RT-10 from the Squad_TweakScale.cfg it recovered with positive value. Not sure if this is a TweakScale bug or one for the other mods, but I'm going to post this in those their respective threads since I've seen a few folks running into this issue.

Share this post


Link to post
Share on other sites
Found an interesting interaction with Tweakscale and the two part recovery mods I've seen, DebRefund and StageRecovery. The SRB's are causing a negative amount of funds to be recovered. For the larger boosters you could actually end up recovering a negative amount.

When I commented out the RT-10 from the Squad_TweakScale.cfg it recovered with positive value. Not sure if this is a TweakScale bug or one for the other mods, but I'm going to post this in those their respective threads since I've seen a few folks running into this issue.

The way to check if it's tweakscale is to take one of the SRBs that are having the issue, place only it in the VAB and remove all the fuel. If the cost goes negative with tweakscale installed and not stock, then it's definitely something caused by tweakscale. I thought I had averted that issue by making it so the minimum return would be 0 (thus it couldn't go negative) but I apparently forgot to do the check at one crucial point. I will add that in now, but it only works around the issue, it doesn't fix the issue with the booster costs being incorrect in the first place.

Edit: I should have just implemented the workaround. I didn't change the version number or download link though, so you will need to redownload. Not worth the trouble of changing the version number for such a minor edit.

Edit 2: There was a brief period of time where I had forgotten to use "+=" and instead had used "=". I have since fixed that. If you managed to download between the last edit and this one (a few minutes) then you will have incorrect returns. Please redownload. Sorry about that :/

Edited by magico13

Share this post


Link to post
Share on other sites

Um... I broke something:

66WPYgJ.png

If I just go to the launchpad and immediately hit recover vessel, the stock recovery refunds the correct prices. Could another mod be interfering somehow?

Share this post


Link to post
Share on other sites
Um... I broke something:

Not your fault, definitely mine. I was returning 100 instead of 1 when the velocity was below the low cutoff, so everything was multiplied by 100. Should be fixed now, thank you! That's what I get for not testing every combination.

I should probably reword the damage percentage as it's less the percent damaged and more the percent undamaged, or the percent returned based on speed. Marked down for next version.

Share this post


Link to post
Share on other sites

I have a bug using this with with 24.2 - I am getting ridiculous quantities of money back for recovery of a stage? I know Elon Musk says re-usability is the key to affordability but this is silly :P

QMxuiVV.png

I am using other addons and plugins so there may be a conflict. I can test in an inert setup if required.

EDIT: Doh! Too late :P

Glad you fixed it, it is a really handy mod!

Share this post


Link to post
Share on other sites

Just wanted to take a moment to say thank you for developing this plugin. I love it! It integrates well with the new career system. I'm playing on "hard" difficulty by using a custom ScienceDefs.cfg (about 1/3 stock science points) and a custom tech tree. This plugin helps recover some of the much-needed money. It, along with the entire "money" system in Career mode, has forced me to carefully plan my rocket designs so that the majority of reusable stages are dropped while still able to have a return trajectory to Kerbin, rather than simply using brute force builds and dropping stages in orbit. So thanks again!

One feature I would like to see: The ability to ignore destroyed SRB's. I don't attempt to recover used SRB's, so I get spammed with red envelopes whenever I launch a rocket. Not a big deal, and if it would be a pain, don't bother.

Share this post


Link to post
Share on other sites

One feature I would like to see: The ability to ignore destroyed SRB's. I don't attempt to recover used SRB's, so I get spammed with red envelopes whenever I launch a rocket. Not a big deal, and if it would be a pain, don't bother.

Thank you for your gratitude :) As for the feature request, I'm not too sure of how easily I can implement that (I can fairly easily make a blacklist of parts so that if a stage has any of them then no messages would be shown, but I don't know of a user-friendly way of having people add things to the black list...). In the meantime, you can disable failed recovery messages in the settings menu (space center scene, if using Blizzy's toolbar you'll have to enable the button) if you don't really need them. Then at least you won't be spammed by the messages. Additionally, I may alleviate the issue some in the future as I'd like to try to consolidate all the recovery messages for a launch into one message, instead of one per stage. I just haven't figured out the best way of grouping the messages together yet.

Share this post


Link to post
Share on other sites

Magico you have my permission to grab the rocket assisted auto landing from mce 23.5 version.

Code

With this and the other auto recycle no point in adding it to mc2.

Edited by malkuth

Share this post


Link to post
Share on other sites
Magico you have my permission to grab the rocket assisted auto landing from mce 23.5 version.

With this and the other auto recycle no point in adding it to mc2.

Thank you! I was actually considering asking you if I could use that! By the way, SR has an API so if MC2 needs access to anything regarding SR's recovery it's quite easy to access (just register a method to either the Success or Failure events, KCT does it in the KCT_Events class). If you need anything at all, please don't hesitate to ask. Working with you in the past has always been a pleasure.

Share this post


Link to post
Share on other sites
Thank you! I was actually considering asking you if I could use that! By the way, SR has an API so if MC2 needs access to anything regarding SR's recovery it's quite easy to access (just register a method to either the Success or Failure events, KCT does it in the KCT_Events class). If you need anything at all, please don't hesitate to ask. Working with you in the past has always been a pleasure.

No problem. I'll check it out.

Ya I had a real bummer today, little nasty bug made it into mc2 contract that's bugging me. Had to disable 2 contracts in mean time. On my work weekend and no time to address issue until Tuesday. :(. Stuff like that bums me out. And I forgot to update my github for last few versions so can't study the code on work breaks to see what's wrong.

Edited by malkuth

Share this post


Link to post
Share on other sites

@Magico: I know you're checking to see if parachutes have been attached to dropped stages. Is there any way you can think of that your code could mess up the game's parachute code? I've never had parachute failures until I installed this mod. Now I get them about 50% of the time. The parachute will vanish before my ship hits the ground. Usually about 50 meters up, but I've had them vanish as high as 250 meters up. Not that I'm 100% convinced it's this mod, because at the same time I added this, I added about 6 others. However, I don't think any of those mods affect parachutes in any way. I'm using Interstallar, Firespitter, Infernal Robotics, and a few others like Toolbar and MechJeb.

Share this post


Link to post
Share on other sites
@Magico: I know you're checking to see if parachutes have been attached to dropped stages. Is there any way you can think of that your code could mess up the game's parachute code?

I highly doubt it's anything I'm doing, since this code only comes into play when something is destroyed by being unloaded in the atmosphere. And all I do with parachutes then is read the value of a couple numbers on the specific parachute, I certainly don't change anything on it. It also doesn't do anything with the active vessel, only the unloaded inactive ones.

That behavior will happen when your vertical velocity becomes positive in stock KSP (not with RealChute though), so maybe that's related? Otherwise I've not seen that before. I'm willing to take a look at an output_log.txt file (from the KSP_Data folder) from a play session after the problem occurred if you want me to.

Share this post


Link to post
Share on other sites
Not your fault, definitely mine. I was returning 100 instead of 1 when the velocity was below the low cutoff, so everything was multiplied by 100. Should be fixed now, thank you! That's what I get for not testing every combination.

I should probably reword the damage percentage as it's less the percent damaged and more the percent undamaged, or the percent returned based on speed. Marked down for next version.

Awesome, thanks for the great mod and support!

Share this post


Link to post
Share on other sites

That's OK. It was more than likely some other mod, my playstyle at those particular moments, or something else I'm not thinking of. After paying more careful attention to parachute deployment, vertical velocity, and not using "time warp" while in parachute descent, I haven't had any more issues.

Share this post


Link to post
Share on other sites

Found an instance where I failed to get a refund. Perhaps it was because the stage actually survived and wasn't deleted in the normal way?

I had a big stage with 4 radial parachutes attached. I dropped the stage just before I finished my circularization burn. In other words, the dropped stage had an apoapsis of 80k and a periapsis of about 35k. This put it on an "aerobrake" re-entry. I noticed after the first time I dropped the stage that I didn't get a refund, so I reverted to launch and when I dropped the stage, I pressed the bracket key to switch my view from my main rocket to the dropped debris. I followed it all the way to the ground and it did indeed land safely. Of course when I clicked "recover" I didn't get any summary or money back. I then re-launched a third time and when I dropped the stage I was able to keep it in view until it passed about 90km away from me as it droped back into the atmosphere. Waited about 15 minutes and no message, no refund.

this code only comes into play when something is destroyed by being unloaded in the atmosphere

Is this the issue then? The game is obviously deleting the object (especially since I have Settings to zero lingering debris). But since it was dropped in space and only then fell into the atmosphere, I think the game must be using a different mechanic to delete it, that your plugin doesn't detect.

Share this post


Link to post
Share on other sites

If you check the debris Targa after you circularize with your main craft on the map view it won't disappear unless you get within (then beyond) loading distance while it is in the atmosphere. If the debris has any periapsis at all while it's not the active vehicle it'll go on rails around its orbit like if Kerbin had no atmosphere. Best bet with that stage is to add retro-rockets to push it into a suborbital trajectory.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.