Jump to content

Prevent targeted docking port from being un-targeted at 200m


Recommended Posts

The title says it all, I'm wondering if anyone can help me with this.

I've noticed that in ModuleDockingNode, the "UnsetTarget()" event has an "unfocusedRange = 200f" attribute - this might have something to do with it, but I'm not looking to modify KSP's default behavior, just disable it in particular cases.

If I procedurally "FlightGlobals.fetch.SetVesselTarget(..)" when outside of 200m, the target node is set for a split second, perhaps a frame or two, and then becomes un-selected. Thus, there's probably an event system going on here. If that was the case, I might be able to override the "UnsetTarget()" method, but I'm trying to do this purely through a MonoBehaviour (plugin), and not through a PartModule.

Any help would be greatly appreciated.

-NavyFish

Link to comment
Share on other sites

Here is something you might be able to use. It is adapted from RemoteTech, which is probably a better source. Basically if you go past 200m, you can start using the protovessel to get parts, and then revert to the real target when the target gets closer again. Not sure if its really what you need, but it might help.

private void buildFromVessel(Vessel v)

{

vessel = v;

if (v.loaded) //Treat vessels differently if loaded, or not loaded

{

foreach (Part p in v.parts)

{

foreach (PartModule m in p.Modules)

{

if (m.name.Equals("ModuleDockingNode"))

{

//Do your stuff here

}

}

}

}

else

{

//Use protovessel stuff

foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)

{

foreach (ProtoPartModuleSnapshot s in p.modules)

{

if (s.moduleName.Equals("ModuleDockingNode"))

{

ConfigNode n = new ConfigNode();

s.Save(n);

try

{

string t = n.GetValue("type", 0);

type = getType(t);

}

catch

{

//Error handling

}

//Do your stuff here

}

}

}

}

}

Link to comment
Share on other sites

Awesome, thanks for the reply. I will try that - though I thought the "loaded" flag indicated vessels were within the 2.5 km scene? My current code does something very similar to the first block you posted, but I haven't worked with Proto stuff at all. I'll have to dig around the forums to get more detail on what they are, exactly.

I've noticed that "FlightGlobals.fetch.VesselTarget" changes at 200m, if you had a docking node manually targeted - it shifts to the root part of the ship. So I think my way forward is going to be whenever the target changes, find out the vessel that belongs to the targeted part, then traverse through its list of parts and find the appropriate docking node.

Link to comment
Share on other sites

What do you know about ModuleDockingNode? This might actually be of some use in my megascale construction projects - I'm having difficulty performing what would otherwise be a textbook docking at 245m from the dockee object's root part. The docking ports don't seem to want to engage, despite being lined up perfectly and having 0 degrees angle difference. They still collide, though, which kind of confuses me.

Any insights?

Link to comment
Share on other sites

The 200m threshold is not one of loading, but of packing. You can change the packing and unpacking thresholds thusly:


OrbitPhysicsManager Manager = (OrbitPhysicsManager)GameObject.FindObjectOfType(typeof(OrbitPhysicsManager));

Manager.distantLandedPartPackThreshold = Manager.distantPartPackThreshold = 2250;
Manager.distantLandedPartUnpackThreshold = Manager.distantPartUnpackThreshold = 2000;

Of course there might be some additional limitations within ModuleDockingNode itself. That I haven't tested.

Don't overdo the range boost btw. It can cause quite some lag if you set the OrbitPhysicsManager to unpack too many parts at a time. Romfarer overdid it a bit for his Lazor plugin and it caused him nothing but grief. This code snippet is from RT1. Here I set the packing and unpacking thresholds to be just within the loading range (2500 m). I've had good experiences with this, it seems I found the sweet spot. I did however implement a toggle to turn off the range boost. I'd recommend you do the same if you choose to implement this.

Link to comment
Share on other sites

Thank you, JDP. I'm still exploring a way to achieve this effect without tweaking other parts of the game, but this is great information to have - and if I can't get another approach working, then I'm likely to use your approach.

NGTOne - I think JDP's answer would explain the problem you're having - the Docking Nodes are likely getting packed up at 200m, and thus the logic that controls their connection is disabled.

I've made a simple partless plugin incorporating his code above. You can download it here and give it a shot.

The source:


using System;
using UnityEngine;

namespace PartPackExtender
{
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class PartPackExtender : MonoBehaviour
{
public void Start()
{
OrbitPhysicsManager Manager = (OrbitPhysicsManager)GameObject.FindObjectOfType(typeof(OrbitPhysicsManager));

Manager.distantLandedPartPackThreshold = Manager.distantPartPackThreshold = 2250;
Manager.distantLandedPartUnpackThreshold = Manager.distantPartUnpackThreshold = 2000;
}
}
}

Please let us know if that fixes your problem. I can't test it out because I don't have any ships that are > 200m long! lol

Also, worth noting - it seems that the OrbitPhysicsManager has been deprecated. The meta text reads:


'Manager.distantLandedPartUnpackThreshold is obsolete. Use Vessel.distanceUnpackThreshold instead'

(and likewise for the pack threshold)

I'm not sure if the correct 'Vessel' to use would be FlightGlobals.ActiveVessel, or the Vessel you're trying to dock to - but hopefully for now the OrbitPhysicsManager is still functional.

Link to comment
Share on other sites

...

Also, worth noting - it seems that the OrbitPhysicsManager has been deprecated. The meta text reads:


'Manager.distantLandedPartUnpackThreshold is obsolete. Use Vessel.distanceUnpackThreshold instead'

(and likewise for the pack threshold)

I'm not sure if the correct 'Vessel' to use would be FlightGlobals.ActiveVessel, or the Vessel you're trying to dock to - but hopefully for now the OrbitPhysicsManager is still functional.

Great catch! It would seem that there has been a couple of extra benefits from getting Romfarer as a dev. the packing thresholds seem to be fully vessel-specific now. Which makes me very much giddy. I can get away with much larger RC ranges now. It does seem like the old method no longer will work though. Since the thresholds are now vessel specific, you'd need to modify the vessel of the targeted node.

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