void OnCollisionStay(Collision collision) { // force any vessels landed on the pad to share the same situation // works around a bug in KSP that sometimes glitches the landed // vessel to not-landed Part p = FlightGlobals.GetPartUpwardsCached(collision.collider.gameObject); if (p != null) { if (vessel.LandedOrSplashed) { p.vessel.Landed = vessel.Landed; p.vessel.Splashed = vessel.Splashed; p.vessel.SetLandedAt(vessel.landedAt, null, vessel.displaylandedAt); } } }
Part FindContactParts() { if (part.packed) { return(null); } can_dock = true; contacts.Clear(); var num_grapples = grapple_transforms.Count; var parts = new List <Part>(); for (int i = 0; i < num_grapples; i++) { var grapple = grapple_transforms[i]; RaycastHit hit; if (Physics.Raycast(grapple.position, grapple.forward * GrappleRange, out hit, GrappleRange, LayerUtil.DefaultEquivalent)) { var sqr_range = (grapple.position - hit.point).sqrMagnitude; if (sqr_range < GrappleRangeSqr) { parts.Add(FlightGlobals.GetPartUpwardsCached(hit.transform.gameObject)); } var contact = new Contact { ori = grapple, point = hit.point, good = sqr_range < DockRangeSqr }; can_dock &= contact.good; contacts.Add(contact); } } var p = (parts.Count == num_grapples && new HashSet <Part>(parts).Count == 1 ? parts[0] : null); if (p != null && p.vessel.isEVA) { p = null; } can_dock &= p != null; return(p); }
public override void deployEvent() { IScalarModule scalar = null; float deployLimit = 0; RaycastHit hit; if (_raySource != null && Physics.Raycast(_raySource.position, _raySource.forward, out hit, 1f, LayerUtil.DefaultEquivalent)) { if (hit.collider != null) { bool primary = false; bool secondary = false; if (hit.collider.gameObject.name == "PrimaryDoorCollider") { primary = true; } else if (hit.collider.gameObject.name == "SecondaryDoorCollider") { secondary = true; } if (primary || secondary) { Part p = FlightGlobals.GetPartUpwardsCached(hit.collider.gameObject);// Part.GetComponentUpwards<Part>(hit.collider.gameObject); if (p != null) { PartModule USAnimate = null; for (int i = p.Modules.Count - 1; i >= 0; i--) { if (p.Modules[i].moduleName == "USAnimateGeneric") { USAnimate = p.Modules[i]; if (USAnimate is IScalarModule) { scalar = USAnimate as IScalarModule; } break; } } if (USAnimate != null) { BaseEvent doorEvent = null; BaseField doorLimit = null; if (primary) { doorEvent = USAnimate.Events["toggleEventPrimary"]; doorLimit = USAnimate.Fields["primaryDeployLimit"]; } else if (secondary) { doorEvent = USAnimate.Events["toggleEventSecondary"]; doorLimit = USAnimate.Fields["secondaryDeployLimit"]; } if (doorLimit != null) { deployLimit = doorLimit.GetValue <float>(USAnimate) * 0.01f; } else { deployLimit = 1; } if (doorEvent != null) { if (doorEvent.active && doorEvent.guiActive) { doorEvent.Invoke(); StartCoroutine(WaitForBayDoors(scalar, deployLimit)); } else { base.deployEvent(); } } else { base.deployEvent(); } } else { base.deployEvent(); } } else { base.deployEvent(); } } else { var ownColliders = part.GetComponentsInChildren <Collider>(); bool flag = false; for (int i = ownColliders.Length - 1; i >= 0; i--) { if (hit.collider == ownColliders[i]) { flag = true; break; } } if (flag) { base.deployEvent(); } else { ScreenMessages.PostScreenMessage( string.Format( "<b><color=orange>Obstruction detected preventing {0} from being deployed.</color></b>" , part.partInfo.title) , 5f, ScreenMessageStyle.UPPER_CENTER); } } } } else { base.deployEvent(); } }
private IEnumerator deployEvent() { if (USTwoScience) { RaycastHit hit; if (_raySource != null && Physics.Raycast(_raySource.position, _raySource.forward, out hit, 1f, LayerUtil.DefaultEquivalent)) { if (hit.collider != null) { bool primary = false; bool secondary = false; if (hit.collider.gameObject.name == "PrimaryDoorCollider") { primary = true; } else if (hit.collider.gameObject.name == "SecondaryDoorCollider") { secondary = true; } if (primary || secondary) { Part p = FlightGlobals.GetPartUpwardsCached(hit.collider.gameObject);// Part.GetComponentUpwards<Part>(hit.collider.gameObject); if (p != null) { IScalarModule scalar = null; float deployLimit = 1; PartModule USAnimate = null; for (int i = p.Modules.Count - 1; i >= 0; i--) { if (p.Modules[i].moduleName == "USAnimateGeneric") { USAnimate = p.Modules[i]; if (USAnimate is IScalarModule) { scalar = USAnimate as IScalarModule; } break; } } if (USAnimate != null && scalar != null) { BaseEvent doorEvent = null; BaseField doorLimit = null; if (primary) { doorEvent = USAnimate.Events["toggleEventPrimary"]; doorLimit = USAnimate.Fields["primaryDeployLimit"]; } else if (secondary) { doorEvent = USAnimate.Events["toggleEventSecondary"]; doorLimit = USAnimate.Fields["secondaryDeployLimit"]; } if (doorLimit != null) { deployLimit = doorLimit.GetValue <float>(USAnimate) * 0.01f; } if (doorEvent != null) { if (doorEvent.active && doorEvent.guiActive) { doorEvent.Invoke(); DMUtils.Logging("Door Invoked"); while (scalar.GetScalar < deployLimit) { yield return(null); } } } } } } else { var ownColliders = part.GetComponentsInChildren <Collider>(); bool flag = false; for (int i = ownColliders.Length - 1; i >= 0; i--) { if (hit.collider == ownColliders[i]) { flag = true; break; } } if (!flag) { ScreenMessages.PostScreenMessage( string.Format( "<b><color=orange>Obstruction detected preventing {0} from being deployed.</color></b>" , part.partInfo.title) , 5f, ScreenMessageStyle.UPPER_CENTER); yield break; } } } } } IsDeployed = true; animator(1f, 0f, Anim, animationName); if (USScience) { animator(1f, 0f, USAnim, USBayAnimation); } yield return(new WaitForSeconds(Anim[animationName].length)); fullyDeployed = true; }