protected void AttachDocked(KASModuleAttachCore otherAttachModule, Vessel forceDominant = null)
{
// Don't overwrite vesselInfo on redundant calls
if (part.vessel == otherAttachModule.part.vessel
&& attachMode.Docked && dockedAttachModule == otherAttachModule
&& otherAttachModule.attachMode.Docked && otherAttachModule.dockedAttachModule == this
&& vesselInfo != null && otherAttachModule.vesselInfo != null) {
KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing to do at all");
return;
}
// Save vessel Info
vesselInfo = new DockedVesselInfo();
vesselInfo.name = vessel.vesselName;
vesselInfo.vesselType = vessel.vesselType;
vesselInfo.rootPartUId = vessel.rootPart.flightID;
dockedAttachModule = otherAttachModule;
dockedPartID = otherAttachModule.part.flightID.ToString();
otherAttachModule.vesselInfo = new DockedVesselInfo();
otherAttachModule.vesselInfo.name = otherAttachModule.vessel.vesselName;
otherAttachModule.vesselInfo.vesselType = otherAttachModule.vessel.vesselType;
otherAttachModule.vesselInfo.rootPartUId = otherAttachModule.vessel.rootPart.flightID;
otherAttachModule.dockedAttachModule = this;
otherAttachModule.dockedPartID = part.flightID.ToString();
// Set reference
attachMode.Docked = true;
otherAttachModule.attachMode.Docked = true;
// Stop if already docked
if (otherAttachModule.part.parent == part || part.parent == otherAttachModule.part) {
KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing more to do");
return;
}
// This results in a somewhat wrong state, but it's better to not make it even more wrong.
if (otherAttachModule.part.vessel == part.vessel) {
KAS_Shared.DebugWarning("DockTo(Core) BUG: Parts belong to the same vessel, doing nothing");
return;
}
// Reset vessels position and rotation for returning all parts to their original position and
// rotation before coupling
vessel.SetPosition(vessel.transform.position, true);
vessel.SetRotation(vessel.transform.rotation);
otherAttachModule.vessel.SetPosition(otherAttachModule.vessel.transform.position, true);
otherAttachModule.vessel.SetRotation(otherAttachModule.vessel.transform.rotation);
// Couple depending of mass
Vessel dominantVessel = GetDominantVessel(this.vessel, otherAttachModule.vessel);
if (forceDominant == this.vessel || forceDominant == otherAttachModule.vessel) {
dominantVessel = forceDominant;
}
KAS_Shared.DebugLog(string.Format("DockTo(Core) Master vessel is {0}",
dominantVessel.vesselName));
if (dominantVessel == this.vessel) {
KAS_Shared.DebugLog(string.Format("DockTo(Core) Docking {0} from {1} with {2} from {3}",
otherAttachModule.part.partInfo.title,
otherAttachModule.vessel.vesselName,
part.partInfo.title,
vessel.vesselName));
if (FlightGlobals.ActiveVessel == otherAttachModule.part.vessel) {
KAS_Shared.DebugLog(string.Format("DockTo(Core) Switching focus to {0}",
this.part.vessel.vesselName));
FlightGlobals.ForceSetActiveVessel(this.part.vessel);
FlightInputHandler.ResumeVesselCtrlState(this.part.vessel);
}
otherAttachModule.part.Couple(this.part);
} else {
KAS_Shared.DebugLog(string.Format("DockTo(Core) Docking {0} from {1} with {2} from {3}",
part.partInfo.title,
vessel.vesselName,
otherAttachModule.part.partInfo.title,
otherAttachModule.vessel.vesselName));
if (FlightGlobals.ActiveVessel == part.vessel) {
KAS_Shared.DebugLog(string.Format("DockTo(Core) Switching focus to {0}",
otherAttachModule.part.vessel.vesselName));
FlightGlobals.ForceSetActiveVessel(otherAttachModule.part.vessel);
FlightInputHandler.ResumeVesselCtrlState(otherAttachModule.part.vessel);
}
part.Couple(otherAttachModule.part);
}
GameEvents.onVesselWasModified.Fire(this.part.vessel);
}