private void UpdateTarget() { activeTarget = FlightGlobals.fetch.VesselTarget; if (activeTarget != null) { targetDisplacement = activeTarget.GetTransform().position - vessel.GetTransform().position; targetDirection = targetDisplacement.normalized; targetRelativeVelocity = vessel.obt_velocity - activeTarget.GetObtVelocity(); targetCmpSpeed = -1.0; targetDockingTransform = null; if (activeTarget is Vessel) { targetType = ((activeTarget as Vessel).vesselType == VesselType.SpaceObject) ? TargetType.Asteroid : TargetType.Vessel; } else if (activeTarget is CelestialBody) { targetType = TargetType.CelestialBody; } else if (activeTarget is ModuleDockingNode) { targetType = TargetType.DockingPort; targetDockingTransform = (activeTarget as ModuleDockingNode).GetTransform(); } else if (activeTarget is PositionTarget) { targetType = TargetType.PositionTarget; } else { Utility.LogError(this, "UpdateTarget() - unable to classify target {0}", activeTarget.GetType().Name); targetType = TargetType.None; } if (targetType == TargetType.Vessel || targetType == TargetType.DockingPort) { UpdateTargetDockingPorts(); } targetName = activeTarget.GetName(); targetOrbit = activeTarget.GetOrbit(); } else { targetCmpSpeed = 0.0; targetType = TargetType.None; targetDisplacement = Vector3.zero; targetRelativeVelocity = Vector3d.zero; targetDirection = forward; targetDockingTransform = null; targetName = string.Empty; targetOrbit = null; if (targetDockingPorts.Length > 0) { targetDockingPorts = new ModuleDockingNode[0]; } } approachSolver.ResetComputation(); }
public void UpdateCoordinates(CelestialBody body) { if (target == null) { return; } Name = target.GetName(); switch (TargetInfo.targetType) { case ProtoTargetInfo.Type.Vessel: var v = target as Vessel; if (v == null) { break; } set_coordinates(v); return; case ProtoTargetInfo.Type.PartModule: var m = target as PartModule; if (m == null || m.vessel == null) { break; } set_coordinates(m.vessel); return; case ProtoTargetInfo.Type.Part: // There may be ITargetable Part derivatives in some mods // ReSharper disable once SuspiciousTypeConversion.Global var p = target as Part; if (p == null || p.vessel == null) { // ProtoTargetInfo.FindTarget() may return a Vessel when the Type == Part goto case ProtoTargetInfo.Type.Vessel; } set_coordinates(p.vessel); return; case ProtoTargetInfo.Type.Generic: var t = target.GetTransform(); if (t == null) { break; } var position = t.position; set_coordinates(body.GetLatitude(position), body.GetLongitude(position), body.GetAltitude(position)); return; } TargetInfo.targetType = ProtoTargetInfo.Type.Null; target = null; Valid = false; }
public string findNameForOrbit(Orbit orbit, ITargetable start) { if (start.GetOrbit() == orbit || start.GetOrbit() == null) { return(start.GetName()); } else { return(findNameForOrbit(orbit, start.GetOrbit().referenceBody)); } }
public void UpdateCoordinates(CelestialBody body) { if (target == null) { return; } Name = target.GetName(); switch (TargetInfo.targetType) { case ProtoTargetInfo.Type.Vessel: var v = target as Vessel; if (v == null) { break; } set_coordinates(v); return; case ProtoTargetInfo.Type.PartModule: var m = target as PartModule; if (m == null || m.vessel == null) { break; } set_coordinates(m.vessel); return; case ProtoTargetInfo.Type.Part: var p = target as Part; if (p == null || p.vessel == null) { break; } set_coordinates(p.vessel); return; case ProtoTargetInfo.Type.Generic: var t = target.GetTransform(); if (t == null) { break; } set_coordinates(body.GetLatitude(t.position), body.GetLongitude(t.position)); return; // case ProtoTargetInfo.Type.CelestialBody: default: break; } TargetInfo.targetType = ProtoTargetInfo.Type.Null; Name += " last location"; target = null; }
private void OnActiveTargetChange(ITargetable activeTarget) { Logger.debug("Active target changed from {0} to {1}..", this.activeTarget != null ? this.activeTarget.GetName() : "None", activeTarget.GetName()); foreach (ITargetObserver observer in targetObserverList) { observer.OnActiveTargetChange(activeTarget); } this.activeTarget = activeTarget; }
public static void LogTargetInfo(ITargetable target) { var method = typeof(OrbitRenderer).GetMethod("GetOrbitColour", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); Color orbitColor2 = (Color)method.Invoke(target.GetOrbitDriver().Renderer, new object[0]); Logger.Debug("Target name: " + target.GetName()); Logger.Debug("Target orbit color 1: " + target.GetOrbitDriver().Renderer.orbitColor); Logger.Debug("Target orbit color 2: " + orbitColor2); Logger.Debug("Target in vessel list: " + FlightGlobals.Vessels.Contains(target.GetVessel())); Logger.Debug("Target same orbit renderer: " + (target.GetOrbitDriver().Renderer == target.GetVessel().orbitRenderer)); Logger.Debug("Target orbit renderer mode: " + target.GetOrbitDriver().Renderer.drawMode); Logger.Debug("Target isActive: " + target.GetOrbitDriver().Renderer.isActive); Logger.Debug("Target isFocused: " + target.GetOrbitDriver().Renderer.isFocused); Logger.Debug("Target orbit driver draw: " + target.GetOrbitDriver().drawOrbit); Logger.Debug("Target orbit driver update mode: " + target.GetOrbitDriver().updateMode); Logger.Debug("Target orbit driver last mode: " + target.GetOrbitDriver().lastMode); Logger.Debug("Target orbit driver color: " + target.GetOrbitDriver().orbitColor); Logger.Debug("Target has conic renderer: " + (target.GetVessel().patchedConicRenderer != null)); }
public WayPoint(ITargetable t) : this() { target = t; TargetInfo = new ProtoTargetInfo(t); Name = t.GetName(); }
/// <summary> /// Wrapper around CelestialBody.theName to support other targets as well. /// </summary> /// <param name="target">Body or vessel to check</param> /// <returns> /// Name of target, including gender markers /// (Historically, this checked CelestialBody.theName, which included a lower case /// version of some names such as "the Mun". This was removed in the localization /// update, and now we only have "The Mun" regardless of where in the sentence /// the string will be used. This has been reported on the bug tracker: /// http://bugs.kerbalspaceprogram.com/issues/14314 ) /// </returns> public static string TheName(ITargetable target) { return(target?.GetDisplayName() ?? target?.GetName() ?? "NULL"); }
/// <summary> /// Draws the target information when selected. /// </summary> private void DrawTarget(SectionModule section) { ITargetable target = FlightGlobals.fetch.VesselTarget; this.ResizeRequested = true; if (GUILayout.Button("Go Back to Target Selection", this.ButtonStyle, GUILayout.Width(this.ContentWidth))) { FlightGlobals.fetch.SetVesselTarget(null); } if (target != null) { var act = FlightGlobals.ActiveVessel; if (!(target is CelestialBody) && GUILayout.Button("Switch to Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth))) { FlightEngineerCore.SwitchToVessel(target.GetVessel(), act); } bool focusable = (target is CelestialBody || target is global::Vessel); if (focusable) { MapObject targMo = null; if (target is global::Vessel) { targMo = ((global::Vessel)(target)).mapObject; } else { targMo = ((CelestialBody)(target)).MapObject; } bool shouldFocus = targMo != null && (targMo != PlanetariumCamera.fetch.target || !MapView.MapIsEnabled); if (shouldFocus && GUILayout.Button("Focus Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth))) { wasMapview = MapView.MapIsEnabled; MapView.EnterMapView(); PlanetariumCamera.fetch.SetTarget(targMo); } } bool switchBack = PlanetariumCamera.fetch.target != act.mapObject; if (switchBack && MapView.MapIsEnabled && GUILayout.Button("Focus Vessel", this.ButtonStyle, GUILayout.Width(this.ContentWidth))) { if (!wasMapview) { MapView.ExitMapView(); } PlanetariumCamera.fetch.SetTarget(act.mapObject); } if (FlightCamera.fetch.mode != FlightCamera.Modes.LOCKED && !MapView.MapIsEnabled && GUILayout.Button("Look at Target", this.ButtonStyle, GUILayout.Width(this.ContentWidth))) { var pcam = PlanetariumCamera.fetch; var fcam = FlightCamera.fetch; Vector3 from = new Vector3(); if (target is global::Vessel && ((global::Vessel)target).LandedOrSplashed) { from = ((global::Vessel)target).GetWorldPos3D(); } else { //I don't think it's possible to target the sun so this should always work but who knows. if (target.GetOrbit() != null) { from = target.GetOrbit().getTruePositionAtUT(Planetarium.GetUniversalTime()); } } Vector3 to = FlightGlobals.fetch.activeVessel.GetWorldPos3D(); // float pdist = pcam.Distance; float fdist = fcam.Distance; Vector3 n = (from - to).normalized; if (!n.IsInvalid()) { // pcam.SetCamCoordsFromPosition(n * -pdist); //this does weird stuff fcam.SetCamCoordsFromPosition(n * -fdist); } Debug.Log(" target " + from); Debug.Log(" vessel " + to); Debug.Log(" distance " + fdist + " " + fcam.Distance); } GUILayout.Space(3f); this.DrawLine("Selected Target", target.GetName(), section.IsHud); if (RendezvousProcessor.sourceDisplay != null) { if (RendezvousProcessor.landedSamePlanet || RendezvousProcessor.overrideANDN) { this.DrawLine("Ref Orbit", "Landed on " + FlightGlobals.fetch.activeVessel.GetOrbit().referenceBody.GetName(), section.IsHud); } else { this.DrawLine("Ref Orbit", RendezvousProcessor.sourceDisplay, section.IsHud); } } if (RendezvousProcessor.targetDisplay != null) { if (RendezvousProcessor.landedSamePlanet || RendezvousProcessor.overrideANDNRev) { this.DrawLine("Target Orbit", "Landed on " + target.GetOrbit().referenceBody.GetName(), section.IsHud); } else { this.DrawLine("Target Orbit", RendezvousProcessor.targetDisplay, section.IsHud); } } } }
/// <summary> /// Wrapper around CelestialBody.theName to support other targets as well. /// </summary> /// <param name="target">Body or vessel to check</param> /// <returns> /// Name of target, possibly with "the" in front /// </returns> public static string TheName(ITargetable target) { CelestialBody b = target as CelestialBody; return(b?.theName ?? target?.GetName() ?? "NULL"); }