public float GetBearing(Vessel vessel) { return(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), GetHeadingFromVessel(vessel))); }
public static BodyTarget CreateOrGetExisting(string bodyName, SharedObjects shared) { return(CreateOrGetExisting(VesselUtils.GetBodyByName(bodyName), shared)); }
public BoundsValue GetBoundsValue() { Direction myFacing = VesselUtils.GetFacing(Vessel); Quaternion inverseMyFacing = myFacing.Rotation.Inverse(); Vector rootOrigin = Parts[0].GetPosition(); Bounds unionBounds = new Bounds(); for (int pNum = 0; pNum < Parts.Count; ++pNum) { PartValue p = Parts[pNum]; Vector partOriginOffsetInVesselBounds = p.GetPosition() - rootOrigin; Bounds b = p.GetBoundsValue().GetUnityBounds(); Vector partCenter = new Vector(b.center); // Just like the logic for the part needing all 8 corners of the mesh's bounds, // this needs all 8 corners of the part bounds: for (int signX = -1; signX <= 1; signX += 2) { for (int signY = -1; signY <= 1; signY += 2) { for (int signZ = -1; signZ <= 1; signZ += 2) { Vector corner = partCenter + new Vector(signX * b.extents.x, signY * b.extents.y, signZ * b.extents.z); Vector worldCorner = partOriginOffsetInVesselBounds + p.GetFacing() * corner; Vector3 vesselCorner = inverseMyFacing * worldCorner.ToVector3(); unionBounds.Encapsulate(vesselCorner); } } } } Vector min = new Vector(unionBounds.min); Vector max = new Vector(unionBounds.max); // The above operation is expensive and should force the CPU to do a WAIT 0: Shared.Cpu.YieldProgram(new YieldFinishedNextTick()); return(new BoundsValue(min, max, delegate { return Parts[0].GetPosition(); }, delegate { return VesselUtils.GetFacing(Vessel); }, Shared)); }
public VesselVelocity(Vessel v) { orbitVelocity = new Vector(v.obt_velocity); surfaceVelocity = new Vector(v.srf_velocity); velocityHeading = VesselUtils.GetVelocityHeading(v); }
public override void AddTo(SharedObjects shared) { shared.BindingMgr.AddGetter("CORE", () => new Core((kOSProcessor)shared.Processor, shared)); shared.BindingMgr.AddSetter("TARGET", val => { if (shared.Vessel != FlightGlobals.ActiveVessel) { throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("TARGET can only be set for the Active Vessel"); } var targetable = val as IKOSTargetable; if (targetable != null) { VesselUtils.SetTarget(targetable, shared.Vessel); return; } if (!string.IsNullOrEmpty(val.ToString().Trim())) { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body, shared.Vessel); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), shared.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel, shared.Vessel); return; } } //Target not found, if we have a target we clear it VesselUtils.UnsetTarget(); }); shared.BindingMgr.AddGetter("TARGET", () => { if (shared.Vessel != FlightGlobals.ActiveVessel) { throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("TARGET can only be returned for the Active Vessel"); } var currentTarget = FlightGlobals.fetch.VesselTarget; var vessel = currentTarget as Vessel; if (vessel != null) { return(new VesselTarget(vessel, shared)); } var body = currentTarget as CelestialBody; if (body != null) { return(new BodyTarget(body, shared)); } var dockingNode = currentTarget as ModuleDockingNode; if (dockingNode != null) { return(new DockingPortValue(dockingNode, shared)); } throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("No TARGET is selected"); }); shared.BindingMgr.AddGetter("HASTARGET", () => { if (shared.Vessel != FlightGlobals.ActiveVessel) { return(false); } // the ship has a target if the object does not equal null. return(FlightGlobals.fetch.VesselTarget != null); }); }
public override Vector GetNorthVector() { return(new Vector(VesselUtils.GetNorthVector(Vessel))); }
void IFlightControlParameter.UpdateAutopilot(FlightCtrlState c) { if (!Enabled) { return; } if (!(controlShared.Vessel.horizontalSrfSpeed > 0.1f)) { return; } if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(controlShared.Vessel), VesselUtils.GetVelocityHeading(controlShared.Vessel))) <= 90) { c.wheelSteer = Mathf.Clamp(Value / -10, -1, 1); } else { c.wheelSteer = -Mathf.Clamp(Value / -10, -1, 1); } }
private void WheelSteer(FlightCtrlState c) { if (!Enabled) { return; } float bearing = 0; if (value is VesselTarget) { bearing = VesselUtils.GetTargetBearing(control.Vessel, ((VesselTarget)value).Vessel); } else if (value is GeoCoordinates) { bearing = (float)((GeoCoordinates)value).GetBearing(); } else { try { double doubleValue = Convert.ToDouble(value); if (Utils.IsValidNumber(doubleValue)) { bearing = (float)(Math.Round(doubleValue) - Mathf.Round(FlightGlobals.ship_heading)); if (bearing < -180) { bearing += 360; // i.e. 359 degrees to the left is really 1 degree to the right. } else if (bearing > 180) { bearing -= 360; // i.e. 359 degrees to the right is really 1 degree to the left } } } catch (InvalidCastException) // Note, very few types actually fail Convert.ToDouble(), so it's hard to get this to occur. { // perform the "unlock" so this message won't spew every FixedUpdate: Enabled = false; ClearValue(); throw new KOSWrongControlValueTypeException( "WHEELSTEER", value.GetType().Name, "Vessel, LATLNG, or Number (compass heading)"); } } if (!(control.Vessel.horizontalSrfSpeed > 0.1f)) { return; } if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(control.Vessel), VesselUtils.GetVelocityHeading(control.Vessel))) <= 90) { c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1); } else { c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1); } }
public BodyTarget(string name, SharedObjects shareObj) : this(VesselUtils.GetBodyByName(name), shareObj) { BodyInitializeSuffixes(); }
public override void Evaluate() { switch (RegexMatch.Groups[1].Value.ToUpper()) { case "BODIES": StdOut(""); StdOut("Name Distance"); StdOut("-------------------------------------"); foreach (var body in FlightGlobals.fetch.bodies) { StdOut(body.bodyName.PadLeft(14) + " " + Vector3d.Distance(body.position, Vessel.GetWorldPos3D())); } StdOut(""); break; case "TARGETS": StdOut(""); StdOut("Vessel Name Distance"); StdOut("-------------------------------------"); var commRange = VesselUtils.GetCommRange(Vessel); foreach (var vessel in FlightGlobals.Vessels) { if (vessel == Vessel) { continue; } var vT = new VesselTarget(vessel, this); if (RemoteTechHook.Instance != null) { if (RemoteTechHook.Instance.GetSignalDelayToSatellite(Vessel.id, vessel.id) != Double.PositiveInfinity) { StdOut(vT.Vessel.vesselName.PadRight(24) + " " + vT.GetDistance().ToString("0.0").PadLeft(8)); } } else { if (vT.IsInRange(commRange)) { StdOut(vT.Vessel.vesselName.PadRight(24) + " " + vT.GetDistance().ToString("0.0").PadLeft(8)); } } } StdOut(""); break; case "RESOURCES": StdOut(""); StdOut("Stage Resource Name Amount"); StdOut("------------------------------------------------"); foreach (var part in Vessel.Parts) { foreach (PartResource resource in part.Resources) { StdOut(part.inverseStage.ToString(CultureInfo.InvariantCulture) + " " + resource.resourceName.PadRight(20) + " " + resource.amount.ToString("0.00").PadLeft(8)); } } break; case "PARTS": StdOut("------------------------------------------------"); foreach (var part in Vessel.Parts) { StdOut(part.ConstructID + " " + part.partInfo.name); } break; case "ENGINES": StdOut("------------------------------------------------"); foreach (var part in VesselUtils.GetListOfActivatedEngines(Vessel)) { foreach (PartModule module in part.Modules) { if (!(module is ModuleEngines)) { continue; } var engineMod = (ModuleEngines)module; StdOut(part.uid + " " + part.inverseStage.ToString(CultureInfo.InvariantCulture) + " " + engineMod.moduleName); } } break; case "SENSORS": StdOut(""); StdOut("Part Name Sensor Type"); StdOut("------------------------------------------------"); foreach (var part in Vessel.Parts) { foreach (PartModule module in part.Modules) { var sensor = module as ModuleEnviroSensor; if (sensor == null) { continue; } if (part.partInfo.name.Length > 37) { StdOut(part.partInfo.title.PadRight(34) + "... " + sensor.sensorType); } else { StdOut(part.partInfo.title.PadRight(37) + " " + sensor.sensorType); } } } break; } State = ExecutionState.DONE; }
private static bool CheckCommRange(Vessel vessel) { return(VesselUtils.GetDistanceToHome(vessel) < VesselUtils.GetCommRange(vessel)); }
public double GetMaxThrustAt(double atmPressure) { return(VesselUtils.GetMaxThrust(Vessel, atmPressure)); }
public override void AddTo(SharedObjects shared) { sharedObj = shared; shared.BindingMgr.AddGetter("CORE", () => new Core((kOSProcessor)shared.Processor, shared)); shared.BindingMgr.AddGetter("SHIP", () => ship); // These are now considered shortcuts to SHIP:suffix foreach (var scName in VesselTarget.ShortCuttableShipSuffixes) { shared.BindingMgr.AddGetter(scName, () => VesselShortcutGetter(scName)); } shared.BindingMgr.AddSetter("TARGET", val => { if (shared.Vessel != FlightGlobals.ActiveVessel) { throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("TARGET can only be set for the Active Vessel"); } var targetable = val as IKOSTargetable; if (targetable != null) { VesselUtils.SetTarget(targetable, shared.Vessel); return; } if (!string.IsNullOrEmpty(val.ToString().Trim())) { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body, shared.Vessel); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), shared.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel, shared.Vessel); return; } } //Target not found, if we have a target we clear it VesselUtils.UnsetTarget(); }); shared.BindingMgr.AddGetter("TARGET", () => { var target = (shared.Vessel == FlightGlobals.ActiveVessel) ? FlightGlobals.fetch.VesselTarget : shared.Vessel.targetObject; var vessel = target as Vessel; if (vessel != null) { return(VesselTarget.CreateOrGetExisting(vessel, shared)); } var body = target as CelestialBody; if (body != null) { return(BodyTarget.CreateOrGetExisting(body, shared)); } var dockingNode = target as ModuleDockingNode; if (dockingNode != null) { return(VesselTarget.CreateOrGetExisting(dockingNode.vessel, shared)[dockingNode.part]); } throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("No TARGET is selected"); }); shared.BindingMgr.AddGetter("HASTARGET", () => { // the ship has a target if the object does not equal null. return((shared.Vessel == FlightGlobals.ActiveVessel ? FlightGlobals.fetch.VesselTarget : shared.Vessel.targetObject) != null); }); }
public override object GetSuffix(string suffixName) { switch (suffixName) { case "CONTROL": return(FlightControlManager.GetControllerByVessel(Vessel)); case "DIRECTION": var vector = (Vessel.GetWorldPos3D() - context.Vessel.GetWorldPos3D()); return(new Direction(vector, false)); case "DISTANCE": return((float)GetDistance()); case "BEARING": return(VesselUtils.GetTargetBearing(context.Vessel, Vessel)); case "HEADING": return(VesselUtils.GetTargetHeading(context.Vessel, Vessel)); case "PROGRADE": return(GetPrograde()); case "RETROGRADE": return(GetRetrograde()); case "MAXTHRUST": return(VesselUtils.GetMaxThrust(Vessel)); case "VELOCITY": return(new VesselVelocity(Vessel)); case "GEOPOSITION": return(new GeoCoordinates(Vessel)); case "LATITUDE": return(VesselUtils.GetVesselLattitude(Vessel)); case "LONGITUDE": return(VesselUtils.GetVesselLongitude(Vessel)); case "FACING": return(GetFacing()); case "UP": return(new Direction(Vessel.upAxis, false)); case "NORTH": return(new Direction(VesselUtils.GetNorthVector(Vessel), false)); case "BODY": return(new BodyTarget(Vessel.mainBody, Vessel)); case "ANGULARMOMENTUM": return(new Direction(Vessel.angularMomentum, true)); case "ANGULARVEL": return(new Direction(Vessel.angularVelocity, true)); case "MASS": return(Vessel.GetTotalMass()); case "VERTICALSPEED": return(Vessel.verticalSpeed); case "SURFACESPEED": return(Vessel.horizontalSrfSpeed); case "AIRSPEED": return ((Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.GetWorldPos3D())) .magnitude); //the velocity of the vessel relative to the air); case "VESSELNAME": return(Vessel.vesselName); case "ALTITUDE": return(Vessel.altitude); case "APOAPSIS": return(Vessel.orbit.ApA); case "PERIAPSIS": return(Vessel.orbit.PeA); case "SENSORS": return(new VesselSensors(Vessel)); case "TERMVELOCITY": return(VesselUtils.GetTerminalVelocity(Vessel)); case "LOADED": return(Vessel.loaded); case "OBT": return(new OrbitInfo(Vessel.orbit, Vessel)); } // Is this a resource? double dblValue; if (VesselUtils.TryGetResource(Vessel, suffixName, out dblValue)) { return(dblValue); } return(base.GetSuffix(suffixName)); }
public BodyTarget(string name, SharedObjects shareObj) : this(VesselUtils.GetBodyByName(name), shareObj) { }
public BodyTarget(string name, Vessel vessel) : this(VesselUtils.GetBodyByName(name), vessel) { }
public override object GetSuffix(string suffixName) { switch (suffixName) { case "CONTROL": return(FlightControlManager.GetControllerByVessel(Vessel)); case "BEARING": return(VesselUtils.GetTargetBearing(CurrentVessel, Vessel)); case "HEADING": return(VesselUtils.GetTargetHeading(CurrentVessel, Vessel)); case "MAXTHRUST": return(VesselUtils.GetMaxThrust(Vessel)); case "FACING": return(GetFacing()); case "ANGULARMOMENTUM": return(new Direction(Vessel.angularMomentum, true)); case "ANGULARVEL": return(new Direction(Vessel.angularVelocity, true)); case "MASS": return(Vessel.GetTotalMass()); case "VERTICALSPEED": return(Vessel.verticalSpeed); case "SURFACESPEED": return(Vessel.horizontalSrfSpeed); case "AIRSPEED": return ((Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.GetWorldPos3D())) .magnitude); //the velocity of the vessel relative to the air); //DEPRICATED VESSELNAME case "VESSELNAME": case "SHIPNAME": return(Vessel.vesselName); // Although there is an implementation of lat/long/alt in Orbitible, // it's better to use the methods for vessels that are faster if they're // available: case "LATITUDE": return(VesselUtils.GetVesselLattitude(Vessel)); case "LONGITUDE": return(VesselUtils.GetVesselLongitude(Vessel)); case "ALTITUDE": return(Vessel.altitude); case "SENSORS": return(new VesselSensors(Vessel)); case "TERMVELOCITY": return(VesselUtils.GetTerminalVelocity(Vessel)); case "LOADED": return(Vessel.loaded); } // Is this a resource? double dblValue; if (VesselUtils.TryGetResource(Vessel, suffixName, out dblValue)) { return(dblValue); } return(base.GetSuffix(suffixName)); }
public CelestialBody GetBody() { return(CachedBody ?? (CachedBody = VesselUtils.GetBodyByName(WrappedWaypoint.celestialName))); }
/// <summary> /// The bearing from the current CPU vessel to the surface spot with the /// given lat/long coords, relative to the current CPU vessel's heading. /// </summary> /// <returns> bearing </returns> public double GetBearing() { return(VesselUtils.AngleDelta(VesselUtils.GetHeading(Shared.Vessel), (float)GetHeadingFrom())); }
/// <summary> /// Annoyingly, KSP returns vessel.angularVelociy in a frame of reference /// relative to the ship facing instead of the universe facing. This would be /// wonderful if that was their philosophy everywhere, but it's not - its just a /// weird exception for this one case. This transforms it back into raw universe /// axes again: /// </summary> /// <param name="angularVelFromKSP">the value KSP is returning for angular velocity</param> /// <returns>altered velocity in the new reference frame</returns> private Vector RawAngularVelFromRelative(Vector3 angularVelFromKSP) { return(new Vector(VesselUtils.GetFacing(Vessel).Rotation * new Vector3d(angularVelFromKSP.x, -angularVelFromKSP.z, angularVelFromKSP.y))); }
public override void AddTo(SharedObjects shared) { shared.BindingMgr.AddSetter("SAS", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, (bool)val)); shared.BindingMgr.AddSetter("GEAR", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, (bool)val)); shared.BindingMgr.AddSetter("LEGS", val => VesselUtils.LandingLegsCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("CHUTES", val => VesselUtils.DeployParachutes(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("CHUTESSAFE", val => VesselUtils.DeployParachutesSafe(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("LIGHTS", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Light, (bool)val)); shared.BindingMgr.AddSetter("PANELS", val => VesselUtils.SolarPanelCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("RADIATORS", val => VesselUtils.RadiatorCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("LADDERS", val => VesselUtils.LadderCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("LEGS", val => VesselUtils.LandingLegsCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("BAYS", val => VesselUtils.BayCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("DEPLOYDRILLS", val => VesselUtils.DrillDeployCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("DRILLS", val => VesselUtils.DrillCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("FUELCELLS", val => VesselUtils.FuelCellCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("ISRU", val => VesselUtils.ISRUCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("INTAKES", val => VesselUtils.IntakeCtrl(shared.Vessel, (bool)val)); shared.BindingMgr.AddSetter("BRAKES", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, (bool)val)); shared.BindingMgr.AddSetter("RCS", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, (bool)val)); shared.BindingMgr.AddSetter("ABORT", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Abort, (bool)val)); shared.BindingMgr.AddSetter("AG1", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom01, (bool)val)); shared.BindingMgr.AddSetter("AG2", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom02, (bool)val)); shared.BindingMgr.AddSetter("AG3", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom03, (bool)val)); shared.BindingMgr.AddSetter("AG4", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom04, (bool)val)); shared.BindingMgr.AddSetter("AG5", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom05, (bool)val)); shared.BindingMgr.AddSetter("AG6", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom06, (bool)val)); shared.BindingMgr.AddSetter("AG7", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom07, (bool)val)); shared.BindingMgr.AddSetter("AG8", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom08, (bool)val)); shared.BindingMgr.AddSetter("AG9", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom09, (bool)val)); shared.BindingMgr.AddSetter("AG10", val => shared.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom10, (bool)val)); shared.BindingMgr.AddGetter("SAS", () => shared.Vessel.ActionGroups[KSPActionGroup.SAS]); shared.BindingMgr.AddGetter("GEAR", () => shared.Vessel.ActionGroups[KSPActionGroup.Gear]); shared.BindingMgr.AddGetter("LEGS", () => VesselUtils.GetLandingLegStatus(shared.Vessel)); shared.BindingMgr.AddGetter("CHUTES", () => VesselUtils.GetChuteStatus(shared.Vessel)); shared.BindingMgr.AddGetter("CHUTESSAFE", () => VesselUtils.GetChuteSafeStatus(shared.Vessel)); shared.BindingMgr.AddGetter("LIGHTS", () => shared.Vessel.ActionGroups[KSPActionGroup.Light]); shared.BindingMgr.AddGetter("PANELS", () => VesselUtils.GetSolarPanelStatus(shared.Vessel)); shared.BindingMgr.AddGetter("RADIATORS", () => VesselUtils.GetRadiatorStatus(shared.Vessel)); shared.BindingMgr.AddGetter("LADDERS", () => VesselUtils.GetLadderStatus(shared.Vessel)); shared.BindingMgr.AddGetter("BAYS", () => VesselUtils.GetBayStatus(shared.Vessel)); shared.BindingMgr.AddGetter("DEPLOYDRILLS", () => VesselUtils.GetDrillDeployStatus(shared.Vessel)); shared.BindingMgr.AddGetter("DRILLS", () => VesselUtils.GetDrillStatus(shared.Vessel)); shared.BindingMgr.AddGetter("FUELCELLS", () => VesselUtils.GetFuelCellStatus(shared.Vessel)); shared.BindingMgr.AddGetter("ISRU", () => VesselUtils.GetISRUStatus(shared.Vessel)); shared.BindingMgr.AddGetter("INTAKES", () => VesselUtils.GetIntakeStatus(shared.Vessel)); shared.BindingMgr.AddGetter("BRAKES", () => shared.Vessel.ActionGroups[KSPActionGroup.Brakes]); shared.BindingMgr.AddGetter("RCS", () => shared.Vessel.ActionGroups[KSPActionGroup.RCS]); shared.BindingMgr.AddGetter("ABORT", () => shared.Vessel.ActionGroups[KSPActionGroup.Abort]); shared.BindingMgr.AddGetter("AG1", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom01]); shared.BindingMgr.AddGetter("AG2", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom02]); shared.BindingMgr.AddGetter("AG3", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom03]); shared.BindingMgr.AddGetter("AG4", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom04]); shared.BindingMgr.AddGetter("AG5", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom05]); shared.BindingMgr.AddGetter("AG6", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom06]); shared.BindingMgr.AddGetter("AG7", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom07]); shared.BindingMgr.AddGetter("AG8", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom08]); shared.BindingMgr.AddGetter("AG9", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom09]); shared.BindingMgr.AddGetter("AG10", () => shared.Vessel.ActionGroups[KSPActionGroup.Custom10]); }
private void InitializeSuffixes() { AddSuffix("PARTSNAMED", new OneArgsSuffix <ListValue, StringValue>(GetPartsNamed)); AddSuffix("PARTSNAMEDPATTERN", new OneArgsSuffix <ListValue, StringValue>(GetPartsNamedPattern)); AddSuffix("PARTSTITLED", new OneArgsSuffix <ListValue, StringValue>(GetPartsTitled)); AddSuffix("PARTSTITLEDPATTERN", new OneArgsSuffix <ListValue, StringValue>(GetPartsTitledPattern)); AddSuffix("PARTSDUBBED", new OneArgsSuffix <ListValue, StringValue>(GetPartsDubbed)); AddSuffix("PARTSDUBBEDPATTERN", new OneArgsSuffix <ListValue, StringValue>(GetPartsDubbedPattern)); AddSuffix("MODULESNAMED", new OneArgsSuffix <ListValue, StringValue>(GetModulesNamed)); AddSuffix("PARTSINGROUP", new OneArgsSuffix <ListValue, StringValue>(GetPartsInGroup)); AddSuffix("MODULESINGROUP", new OneArgsSuffix <ListValue, StringValue>(GetModulesInGroup)); AddSuffix("PARTSTAGGED", new OneArgsSuffix <ListValue, StringValue>(GetPartsTagged)); AddSuffix("PARTSTAGGEDPATTERN", new OneArgsSuffix <ListValue, StringValue>(GetPartsTaggedPattern)); AddSuffix("ALLTAGGEDPARTS", new NoArgsSuffix <ListValue>(GetAllTaggedParts)); AddSuffix("PARTS", new NoArgsSuffix <ListValue <PartValue> >(() => Parts)); AddSuffix("DOCKINGPORTS", new NoArgsSuffix <ListValue <DockingPortValue> >(() => DockingPorts)); AddSuffix(new string[] { "DECOUPLERS", "SEPARATORS" }, new NoArgsSuffix <ListValue <DecouplerValue> >(() => Decouplers)); AddSuffix("ELEMENTS", new NoArgsSuffix <ListValue>(() => Vessel.PartList("elements", Shared))); AddSuffix("CONTROL", new Suffix <FlightControl>(GetFlightControl)); AddSuffix("BEARING", new Suffix <ScalarValue>(() => VesselUtils.GetTargetBearing(CurrentVessel, Vessel))); AddSuffix("HEADING", new Suffix <ScalarValue>(() => VesselUtils.GetTargetHeading(CurrentVessel, Vessel))); AddSuffix("AVAILABLETHRUST", new Suffix <ScalarValue>(() => VesselUtils.GetAvailableThrust(Vessel))); AddSuffix("AVAILABLETHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetAvailableThrustAt)); AddSuffix("MAXTHRUST", new Suffix <ScalarValue>(() => VesselUtils.GetMaxThrust(Vessel))); AddSuffix("MAXTHRUSTAT", new OneArgsSuffix <ScalarValue, ScalarValue>(GetMaxThrustAt)); AddSuffix("FACING", new Suffix <Direction>(() => VesselUtils.GetFacing(Vessel))); AddSuffix("BOUNDS", new Suffix <BoundsValue>(() => GetBoundsValue())); AddSuffix("ANGULARMOMENTUM", new Suffix <Vector>(() => new Vector(Vessel.angularMomentum))); AddSuffix("ANGULARVEL", new Suffix <Vector>(() => RawAngularVelFromRelative(Vessel.angularVelocity))); AddSuffix("MASS", new Suffix <ScalarValue>(() => Vessel.GetTotalMass())); AddSuffix("VERTICALSPEED", new Suffix <ScalarValue>(() => Vessel.verticalSpeed)); AddSuffix("GROUNDSPEED", new Suffix <ScalarValue>(GetHorizontalSrfSpeed)); AddSuffix("SURFACESPEED", new Suffix <ScalarValue>(() => { throw new KOSObsoletionException("0.18.0", "SURFACESPEED", "GROUNDSPEED", ""); })); AddSuffix("AIRSPEED", new Suffix <ScalarValue>(() => (Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.CoMD)).magnitude, "the velocity of the vessel relative to the air")); AddSuffix(new[] { "SHIPNAME", "NAME" }, new SetSuffix <StringValue>(() => Vessel.vesselName, RenameVessel, "The KSP name for a craft, cannot be empty")); AddSuffix("TYPE", new SetSuffix <StringValue>(() => Vessel.vesselType.ToString(), RetypeVessel, "The Ship's KSP type (e.g. rover, base, probe)")); AddSuffix("SENSORS", new Suffix <VesselSensors>(() => new VesselSensors(Vessel))); AddSuffix("TERMVELOCITY", new Suffix <ScalarValue>(() => { throw new KOSAtmosphereObsoletionException("17.2", "TERMVELOCITY", "<None>", string.Empty); })); AddSuffix(new[] { "DYNAMICPRESSURE", "Q" }, new Suffix <ScalarValue>(() => Vessel.dynamicPressurekPa * ConstantValue.KpaToAtm, "Dynamic Pressure in Atmospheres")); AddSuffix("LOADED", new Suffix <BooleanValue>(() => Vessel.loaded)); AddSuffix("UNPACKED", new Suffix <BooleanValue>(() => !Vessel.packed)); AddSuffix("ROOTPART", new Suffix <PartValue>(() => Root)); AddSuffix("CONTROLPART", new Suffix <PartValue>(() => PartValueFactory.Construct(GetControlPart(), Shared))); AddSuffix("DRYMASS", new Suffix <ScalarValue>(() => Vessel.GetDryMass(), "The Ship's mass when empty")); AddSuffix("WETMASS", new Suffix <ScalarValue>(() => Vessel.GetWetMass(), "The Ship's mass when full")); AddSuffix("RESOURCES", new Suffix <ListValue <AggregateResourceValue> >(() => AggregateResourceValue.FromVessel(Vessel, Shared), "The Aggregate resources from every part on the craft")); AddSuffix("LOADDISTANCE", new Suffix <LoadDistanceValue>(() => new LoadDistanceValue(Vessel))); AddSuffix("ISDEAD", new NoArgsSuffix <BooleanValue>(() => (Vessel == null || Vessel.state == Vessel.State.DEAD))); AddSuffix("STATUS", new Suffix <StringValue>(() => Vessel.situation.ToString())); //// Although there is an implementation of lat/long/alt in Orbitible, //// it's better to use the methods for vessels that are faster if they're //// available: AddSuffix("LATITUDE", new Suffix <ScalarValue>(() => VesselUtils.GetVesselLatitude(Vessel))); AddSuffix("LONGITUDE", new Suffix <ScalarValue>(() => VesselUtils.GetVesselLongitude(Vessel))); AddSuffix("ALTITUDE", new Suffix <ScalarValue>(() => Vessel.altitude)); AddSuffix("CREW", new NoArgsSuffix <ListValue>(GetCrew)); AddSuffix("CREWCAPACITY", new NoArgsSuffix <ScalarValue>(GetCrewCapacity)); AddSuffix("CONNECTION", new NoArgsSuffix <VesselConnection>(() => new VesselConnection(Vessel, Shared))); AddSuffix("MESSAGES", new NoArgsSuffix <MessageQueueStructure>(() => GetMessages())); AddSuffix("STARTTRACKING", new NoArgsVoidSuffix(StartTracking)); AddSuffix("SOICHANGEWATCHERS", new NoArgsSuffix <UniqueSetValue <UserDelegate> >(() => Shared.DispatchManager.CurrentDispatcher.GetSOIChangeNotifyees(Vessel))); }
private void WheelSteer(FlightCtrlState c) { if (!Enabled) { return; } float bearing = 0; if (value is VesselTarget) { bearing = VesselUtils.GetTargetBearing(control.Vessel, ((VesselTarget)value).Vessel); } else if (value is GeoCoordinates) { bearing = (float)((GeoCoordinates)value).GetBearing(); } else if (value is double) { double doubleValue = Convert.ToDouble(value); if (Utils.IsValidNumber(doubleValue)) { bearing = (float)(Math.Round(doubleValue) - Mathf.Round(FlightGlobals.ship_heading)); } } if (!(control.Vessel.horizontalSrfSpeed > 0.1f)) { return; } if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(control.Vessel), VesselUtils.GetVelocityHeading(control.Vessel))) <= 90) { c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1); } else { c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1); } }
public ScalarValue GetMaxThrustAt(ScalarValue atmPressure) { return(VesselUtils.GetMaxThrust(Vessel, atmPressure)); }
private object GetResourceOfCurrentStage(string resourceName) { var activeEngines = VesselUtils.GetListOfActivatedEngines(vessel); return(Utils.ProspectForResource(resourceName, activeEngines)); }