AvionicsSystems icon indicating copy to clipboard operation
AvionicsSystems copied to clipboard

Add support for uncrewed vessels (e.g. ProbeControlRoom)

Open sovetskysoyuz opened this issue 3 years ago • 5 comments

Several important parts of MASFlightComputer and MASVesselComputer only run during the FixedUpdate if vesselCrewed is true. This blocks compatibility with the Probe Control Room IVA, which is inherently used on uncrewed vessels.

Beyond the big FixedUpdate blocks, there are a few other functions (onVesselChange, onVesselWasModified, onVesselDestroy, onVesselCreate, onVesselCrewWasModified) that also only run on crewed vessels.

Other parts of MAS may assume that a vessel is crewed and throw exceptions for an uncrewed vessel - I already found that FindCurrentKerbal() in MASFlightComputer doesn't like it if there are no kerbals to find, and anything else that calls IVACameraActiveKerbal without checking if the vessel is uncrewed would have the same issue.

Recompiling the current MAS source-code with the crew-count checks removed, and some protection on IVACameraActiveKerbal calls to avoid NREs, produces a plugin that seems to work fine with the current version of Probe Control Room on KSP 1.11.1. I haven't tried to make these changes conditional on whether PCR is installed, since I always play with it and don't mind having these changes be permanent for my own installation, but such a condition would remove any performance impact for MAS users who don't use Probe Control Room.

Edit: a few other patches that I've made on my local copy - FYI since some of these took a while for me to tease out:

  • The functions in MASComponentAudioPlayer that use audioSource.mute should mute if the currentCameraMode is neither IVA nor Internal (since Probe Control Room uses Internal, not IVA, camera). This allows props to play sounds like alarm tones in Probe Control Room without being muted.
  • For an uncrewed vessel, the pod's referenceTransform is RemoteCommand, not Self; UpdateDockingNode should check for both of these when deciding whether to set shipFlightNumber = referencePart.launchID. This change allows MAS props to properly set the own-vessel reference part (since otherwise none of the conditions in UpdateDockingNode will be satisfied, because IVA camera mode isn't active).
  • MAS encounters problems when a new Probe Control Room vessel is created in-flight (e.g. through undocking or decoupling). The new vessel's first call to UpdateAttitude() fails with a NRE, followed by a bunch of other NREs, and this results in the MAS IVA initializing incompletely. From what I can figure out, the issue is related to PCR's StartIVA() method using SetReferencePart() to set a placeholder part that it spawns as the reference part, but it creates the part as private. This causes MAS to choke when it looks up the reference part for the new vessel. I am able to eliminate the NRE by adding a call to UpdateReferenceTransform() at the beginning of UpdateAttitude, and modifying UpdateReferenceTransform() so that it sets the root part as the reference part if it encounters a null reference part. There's probably a more efficient way to do this.

sovetskysoyuz avatar Jan 31 '21 22:01 sovetskysoyuz