public void PlugHead(KASModulePort portModule, PlugState plugMode, bool fromSave = false,
bool fireSound = true, bool alreadyDocked = false)
{
if (plugMode == PlugState.Locked || plugMode == PlugState.Deployed) {
return;
}
if (!alreadyDocked && !fromSave) {
if (portModule.strutConnected()) {
ScreenMessages.PostScreenMessage(
string.Format("{0} is already used !", portModule.part.partInfo.title),
5, ScreenMessageStyle.UPPER_CENTER);
return;
}
if (portModule.plugged) {
ScreenMessages.PostScreenMessage(
string.Format("{0} is already used !", portModule.part.partInfo.title),
5, ScreenMessageStyle.UPPER_CENTER);
return;
}
if (this.part.vessel == portModule.part.vessel) {
plugMode = PlugState.PlugUndocked;
}
}
if (!cableJoint) {
Deploy();
}
DropHead();
if (plugMode == PlugState.PlugUndocked) {
KAS_Shared.DebugLog("PlugHead(Winch) - Plug using undocked mode");
headState = PlugState.PlugUndocked;
if (fireSound) {
AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(portModule.plugSndPath),
portModule.part.transform.position);
}
}
if (plugMode == PlugState.PlugDocked) {
KAS_Shared.DebugLog("PlugHead(Winch) - Plug using docked mode");
// This should be safe even if already connected
AttachDocked(portModule);
// Set attached part
portModule.part.FindAttachNode(portModule.attachNode).attachedPart = this.part;
this.part.FindAttachNode(connectedPortNodeName).attachedPart = portModule.part;
// Remove joints between connector and winch
KAS_Shared.RemoveAttachJointBetween(this.part, portModule.part);
headState = PlugState.PlugDocked;
if (fireSound) {
AudioSource.PlayClipAtPoint(
GameDatabase.Instance.GetAudioClip(portModule.plugDockedSndPath),
portModule.part.transform.position);
}
// Kerbal Joint Reinforcement compatibility
GameEvents.onPartUndock.Fire(portModule.part);
}
KAS_Shared.DebugLog("PlugHead(Winch) - Moving head...");
headTransform.rotation =
Quaternion.FromToRotation(headPortNode.forward, -portModule.portNode.forward)
* headTransform.rotation;
headTransform.position =
headTransform.position - (headPortNode.position - portModule.portNode.position);
SetHeadToPhysic(false);
SetCableJointConnectedBody(portModule.part.rb);
headTransform.parent = portModule.part.transform;
cableJointLength = cableRealLenght + 0.01f;
// Set variables
connectedPortInfo.module = portModule;
connectedPortInfo.module.plugged = true;
portModule.winchConnected = this;
}