private bool LinkTo(KASModuleStrut tgtModule, bool checkCondition = true,
bool setJointOrDock = true)
{
//Check condition if needed
if (checkCondition) {
if (!CheckLink(this.strutTransform, tgtModule.strutTransform, true)) {
ScreenMessages.PostScreenMessage("Max angle or length reached, cannot link!",
5, ScreenMessageStyle.UPPER_CENTER);
return false;
}
if (tgtModule == this) {
ScreenMessages.PostScreenMessage(
string.Format("{0} cannot be linked to itself!", part.partInfo.title),
5, ScreenMessageStyle.UPPER_CENTER);
return false;
}
if (tgtModule.type != this.type) {
ScreenMessages.PostScreenMessage(
string.Format("{0} cannot be linked to {1} because they are not compatible!",
part.partInfo.title, tgtModule.part.partInfo.title),
5, ScreenMessageStyle.UPPER_CENTER);
return false;
}
if (tgtModule.vessel != vessel && !allowDock) {
ScreenMessages.PostScreenMessage(
string.Format("{0} cannot be linked to another vessel!", part.partInfo.title),
5, ScreenMessageStyle.UPPER_CENTER);
return false;
}
}
// Load tube renderer in this module
this.StopEvaLink();
this.strutRenderer.tgtNode = tgtModule.strutTransform;
this.strutRenderer.shaderName = "Diffuse";
this.strutRenderer.color = Color.white;
this.strutRenderer.color.a = 1f;
this.strutRenderer.Load();
// Set references for the current module
this.Events["ContextMenuUnlink"].guiActiveUnfocused = true;
this.Events["ContextMenuLink"].guiActiveUnfocused = false;
this.linkedStrutModule = tgtModule;
this.linked = true;
// Set references for the target module
tgtModule.linkedStrutModule = this;
tgtModule.Events["ContextMenuUnlink"].guiActiveUnfocused = true;
tgtModule.Events["ContextMenuLink"].guiActiveUnfocused = false;
tgtModule.linked = true;
tgtStrutPartID = tgtModule.part.flightID.ToString();
tgtStrutVesselID = tgtModule.part.vessel.id.ToString();
KAS_Shared.InvalidateContextMenu(this.part);
KAS_Shared.InvalidateContextMenu(tgtModule.part);
if (setJointOrDock) {
// Create joint or dock part
if (tgtModule.vessel == vessel) {
if (tgtModule.part.parent != part && part.parent != tgtModule.part) {
KAS_Shared.DebugLog("LinkTo(Strut) Parts are from the same vessel but are not connected,"
+ " setting joint...");
if (part.parent && tgtModule.part.parent) {
KAS_Shared.DebugLog("LinkTo(Strut) Set joint on struts parents");
AttachFixed(part.parent, tgtModule.part.parent, breakForce);
} else {
KAS_Shared.DebugLog("LinkTo(Strut) Set joint on struts");
AttachFixed(part, tgtModule.part, breakForce);
}
}
} else {
KAS_Shared.DebugLog("LinkTo(Strut) Parts are from a different vessel, docking...");
AttachDocked(tgtModule);
}
} else {
KAS_Shared.DebugLog("LinkTo(Strut) setJointOrDock = false, ignoring dock and creating joint");
}
// Connect fuel flow when appropriate
bool both_attached =
this.part.srfAttachNode.attachedPart && tgtModule.part.srfAttachNode.attachedPart;
this.Events["ContextMenuTogglePump"].active = this.allowPumpFuel && both_attached;
if (this.pumpFuel) {
this.StartPump(checkCondition);
}
tgtModule.Events["ContextMenuTogglePump"].active = tgtModule.allowPumpFuel && both_attached;
if (tgtModule.pumpFuel) {
tgtModule.StartPump(checkCondition);
}
return true;
}