public void BindTo(IBindingManager manager) { manager.AddGetter("LOADDISTANCE", cpu => Vessel.loadDistance); manager.AddSetter("LOADDISTANCE", delegate(ICPU cpu, object val) { var distance = (float)val; Vessel.loadDistance = distance; Vessel.unloadDistance = distance - 250; }); manager.AddGetter("WARP", cpu => TimeWarp.fetch.current_rate_index); manager.AddSetter("WARP", delegate(ICPU cpu, object val) { int newRate; if (int.TryParse(val.ToString(), out newRate)) { TimeWarp.SetRate(newRate, false); } }); foreach (var body in FlightGlobals.fetch.bodies) { var cBody = body; manager.AddGetter(body.name, cpu => new BodyTarget(cBody, cpu.Vessel)); } }
public void BindTo(IBindingManager manager) { manager.AddGetter("LOADDISTANCE", cpu => Vessel.loadDistance ); manager.AddSetter("LOADDISTANCE", delegate(ICPU cpu, object val) { var distance = (float) val; Vessel.loadDistance = distance; Vessel.unloadDistance = distance - 250; }); manager.AddGetter("WARP", cpu => TimeWarp.fetch.current_rate_index); manager.AddSetter("WARP", delegate(ICPU cpu, object val) { int newRate; if (int.TryParse(val.ToString(), out newRate)) { TimeWarp.SetRate(newRate, false); } }); foreach (var body in FlightGlobals.fetch.bodies) { var cBody = body; manager.AddGetter(body.name, cpu => new BodyTarget(cBody, cpu.Vessel)); } }
public void BindTo(IBindingManager manager) { #if DEBUG manager.AddGetter("TEST1", cpu => 4); manager.AddSetter("TEST1", (cpu, val) => cpu.StdOut(val.ToString())); #endif }
public LockableControl(string name, string propertyName, ICPU cpu, IBindingManager manager) { Name = name; Cpu = cpu; Vessel = cpu.Vessel; Locked = false; Value = 0; manager.AddGetter(name, c => Value); manager.AddSetter(name, delegate { }); this.propertyName = propertyName; }
public void BindTo(IBindingManager manager) { manager.AddSetter("TARGET", delegate(ICPU cpu, object val) { if (val is ITargetable) { VesselUtils.SetTarget((ITargetable) val); } else if (val is VesselTarget) { VesselUtils.SetTarget(((VesselTarget) val).Target); } else if (val is BodyTarget) { VesselUtils.SetTarget(((BodyTarget) val).Target); } else { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), cpu.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel); } } }); manager.AddGetter("TARGET", delegate(ICPU cpu) { var currentTarget = FlightGlobals.fetch.VesselTarget; if (currentTarget is Vessel) { return new VesselTarget((Vessel) currentTarget, cpu); } if (currentTarget is CelestialBody) { return new BodyTarget((CelestialBody) currentTarget, cpu.Vessel); } return null; }); }
public void BindTo(IBindingManager manager) { manager.AddSetter("TARGET", delegate(ICPU cpu, object val) { var targetable = val as IKOSTargetable; if (targetable != null) { VesselUtils.SetTarget(targetable); } else { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), cpu.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel); } } }); manager.AddGetter("TARGET", delegate(ICPU cpu) { var currentTarget = FlightGlobals.fetch.VesselTarget; var vessel = currentTarget as Vessel; if (vessel != null) { return(new VesselTarget(vessel, cpu)); } var body = currentTarget as CelestialBody; if (body != null) { return(new BodyTarget(body, cpu.Vessel)); } return(null); }); }
public void BindTo(IBindingManager manager) { manager.AddSetter("TARGET", delegate(ICPU cpu, object val) { var targetable = val as IKOSTargetable; if (targetable != null) { VesselUtils.SetTarget(targetable); } else { var body = VesselUtils.GetBodyByName(val.ToString()); if (body != null) { VesselUtils.SetTarget(body); return; } var vessel = VesselUtils.GetVesselByName(val.ToString(), cpu.Vessel); if (vessel != null) { VesselUtils.SetTarget(vessel); } } }); manager.AddGetter("TARGET", delegate(ICPU cpu) { var currentTarget = FlightGlobals.fetch.VesselTarget; var vessel = currentTarget as Vessel; if (vessel != null) { return new VesselTarget(vessel, cpu); } var body = currentTarget as CelestialBody; if (body != null) { return new BodyTarget(body, cpu.Vessel); } return null; }); }
public void BindTo(IBindingManager manager) { manager.AddGetter("ALT:APOAPSIS", cpu => cpu.Vessel.orbit.ApA); manager.AddGetter("ALT:PERIAPSIS", cpu => cpu.Vessel.orbit.PeA); manager.AddGetter("ALT:RADAR", cpu => cpu.Vessel.heightFromTerrain > 0 ? Mathf.Min(cpu.Vessel.heightFromTerrain, (float)cpu.Vessel.altitude) : (float)cpu.Vessel.altitude); manager.AddGetter("ANGULARVELOCITY", cpu => cpu.Vessel.transform.InverseTransformDirection(cpu.Vessel.rigidbody.angularVelocity)); manager.AddGetter("COMMRANGE", cpu => VesselUtils.GetCommRange(cpu.Vessel)); manager.AddGetter("ENCOUNTER", cpu => VesselUtils.TryGetEncounter(cpu.Vessel)); manager.AddGetter("ETA:APOAPSIS", cpu => cpu.Vessel.orbit.timeToAp); manager.AddGetter("ETA:PERIAPSIS", cpu => cpu.Vessel.orbit.timeToPe); manager.AddGetter("ETA:TRANSITION", cpu => cpu.Vessel.orbit.EndUT - cpu.Vessel.missionTime); manager.AddGetter("INCOMMRANGE", cpu => Convert.ToDouble(CheckCommRange(cpu.Vessel))); manager.AddGetter("MISSIONTIME", cpu => cpu.Vessel.missionTime); manager.AddGetter("OBT", cpu => new OrbitInfo(cpu.Vessel.orbit, cpu.Vessel)); manager.AddGetter("TIME", cpu => new TimeSpan(Planetarium.GetUniversalTime())); manager.AddGetter("SHIP", cpu => new VesselTarget(cpu.Vessel, cpu)); manager.AddGetter("STATUS", cpu => cpu.Vessel.situation.ToString()); manager.AddGetter("STAGE", cpu => new StageValues(cpu.Vessel)); manager.AddSetter("VESSELNAME", delegate(ICPU cpu, object value) { cpu.Vessel.vesselName = value.ToString(); }); manager.AddGetter("NEXTNODE", delegate(ICPU cpu) { var vessel = cpu.Vessel; if (vessel.patchedConicSolver.maneuverNodes.Count == 0) { throw new KOSException("No maneuver nodes present!"); } return(Node.FromExisting(vessel, vessel.patchedConicSolver.maneuverNodes[0])); }); // These are now considered shortcuts to SHIP:suffix foreach (var scName in VesselTarget.ShortCuttableShipSuffixes) { var cName = scName; manager.AddGetter(scName, cpu => new VesselTarget(cpu.Vessel, cpu).GetSuffix(cName)); } }
public void BindTo(IBindingManager manager) { manager.AddGetter("ALT:APOAPSIS", cpu => cpu.Vessel.orbit.ApA); manager.AddGetter("ALT:PERIAPSIS", cpu => cpu.Vessel.orbit.PeA); manager.AddGetter("ALT:RADAR", cpu => cpu.Vessel.heightFromTerrain > 0 ? Mathf.Min(cpu.Vessel.heightFromTerrain, (float) cpu.Vessel.altitude) : (float) cpu.Vessel.altitude); manager.AddGetter("ANGULARVELOCITY", cpu => cpu.Vessel.transform.InverseTransformDirection(cpu.Vessel.rigidbody.angularVelocity)); manager.AddGetter("COMMRANGE", cpu => VesselUtils.GetCommRange(cpu.Vessel)); manager.AddGetter("ENCOUNTER", cpu => VesselUtils.TryGetEncounter(cpu.Vessel)); manager.AddGetter("ETA:APOAPSIS", cpu => cpu.Vessel.orbit.timeToAp); manager.AddGetter("ETA:PERIAPSIS", cpu => cpu.Vessel.orbit.timeToPe); manager.AddGetter("ETA:TRANSITION", cpu => cpu.Vessel.orbit.EndUT - cpu.Vessel.missionTime); manager.AddGetter("INCOMMRANGE", cpu => Convert.ToDouble(CheckCommRange(cpu.Vessel))); manager.AddGetter("MISSIONTIME", cpu => cpu.Vessel.missionTime); manager.AddGetter("OBT", cpu => new OrbitInfo(cpu.Vessel.orbit, cpu.Vessel)); manager.AddGetter("TIME", cpu => new TimeSpan(Planetarium.GetUniversalTime())); manager.AddGetter("SHIP", cpu => new VesselTarget(cpu.Vessel, cpu)); manager.AddGetter("STATUS", cpu => cpu.Vessel.situation.ToString()); manager.AddGetter("STAGE", cpu => new StageValues(cpu.Vessel)); manager.AddSetter("VESSELNAME", delegate(ICPU cpu, object value) { cpu.Vessel.vesselName = value.ToString(); }); manager.AddGetter("NEXTNODE", delegate(ICPU cpu) { var vessel = cpu.Vessel; if (vessel.patchedConicSolver.maneuverNodes.Count == 0) { throw new KOSException("No maneuver nodes present!"); } return Node.FromExisting(vessel, vessel.patchedConicSolver.maneuverNodes[0]); }); // These are now considered shortcuts to SHIP:suffix foreach (var scName in VesselTarget.ShortCuttableShipSuffixes) { var cName = scName; manager.AddGetter(scName, cpu => new VesselTarget(cpu.Vessel, cpu).GetSuffix(cName)); } }
private void HookEvents() { binding.AddGetter(name, () => getValue()); binding.AddSetter(name, val => setValue(val)); }
private void HookEvents() { binding.AddGetter(name, () => value); binding.AddSetter(name, val => value = val); }
public void BindTo(IBindingManager manager) { manager.AddSetter("SAS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, (bool) val)); manager.AddSetter("GEAR", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, (bool) val)); manager.AddSetter("LEGS", (cpu, val) => VesselUtils.LandingLegsCtrl(cpu.Vessel, (bool) val)); manager.AddSetter("CHUTES", (cpu, val) => VesselUtils.DeployParachutes(cpu.Vessel, (bool) val)); manager.AddSetter("LIGHTS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Light, (bool) val)); manager.AddSetter("PANELS", (cpu, val) => VesselUtils.SolarPanelCtrl(cpu.Vessel, (bool) val)); manager.AddSetter("BRAKES", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, (bool) val)); manager.AddSetter("RCS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, (bool) val)); manager.AddSetter("ABORT", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Abort, (bool) val)); manager.AddSetter("AG1", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom01, (bool) val)); manager.AddSetter("AG2", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom02, (bool) val)); manager.AddSetter("AG3", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom03, (bool) val)); manager.AddSetter("AG4", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom04, (bool) val)); manager.AddSetter("AG5", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom05, (bool) val)); manager.AddSetter("AG6", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom06, (bool) val)); manager.AddSetter("AG7", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom07, (bool) val)); manager.AddSetter("AG8", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom08, (bool) val)); manager.AddSetter("AG9", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom09, (bool) val)); manager.AddSetter("AG10", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom10, (bool) val)); manager.AddGetter("SAS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.SAS]); manager.AddGetter("GEAR", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Gear]); manager.AddGetter("LEGS", cpu => VesselUtils.GetLandingLegStatus(cpu.Vessel)); manager.AddGetter("CHUTES", cpu => VesselUtils.GetChuteStatus(cpu.Vessel)); manager.AddGetter("LIGHTS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Light]); manager.AddGetter("PANELS", cpu => VesselUtils.GetSolarPanelStatus(cpu.Vessel)); manager.AddGetter("BRAKES", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Brakes]); manager.AddGetter("RCS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.RCS]); manager.AddGetter("ABORT", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Abort]); manager.AddGetter("AG1", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom01]); manager.AddGetter("AG2", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom02]); manager.AddGetter("AG3", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom03]); manager.AddGetter("AG4", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom04]); manager.AddGetter("AG5", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom05]); manager.AddGetter("AG6", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom06]); manager.AddGetter("AG7", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom07]); manager.AddGetter("AG8", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom08]); manager.AddGetter("AG9", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom09]); manager.AddGetter("AG10", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom10]); }
public void BindTo(IBindingManager manager) { manager.AddSetter("SAS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, (bool)val)); manager.AddSetter("GEAR", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, (bool)val)); manager.AddSetter("LEGS", (cpu, val) => VesselUtils.LandingLegsCtrl(cpu.Vessel, (bool)val)); manager.AddSetter("CHUTES", (cpu, val) => VesselUtils.DeployParachutes(cpu.Vessel, (bool)val)); manager.AddSetter("LIGHTS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Light, (bool)val)); manager.AddSetter("PANELS", (cpu, val) => VesselUtils.SolarPanelCtrl(cpu.Vessel, (bool)val)); manager.AddSetter("BRAKES", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, (bool)val)); manager.AddSetter("RCS", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, (bool)val)); manager.AddSetter("ABORT", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Abort, (bool)val)); manager.AddSetter("AG1", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom01, (bool)val)); manager.AddSetter("AG2", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom02, (bool)val)); manager.AddSetter("AG3", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom03, (bool)val)); manager.AddSetter("AG4", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom04, (bool)val)); manager.AddSetter("AG5", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom05, (bool)val)); manager.AddSetter("AG6", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom06, (bool)val)); manager.AddSetter("AG7", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom07, (bool)val)); manager.AddSetter("AG8", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom08, (bool)val)); manager.AddSetter("AG9", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom09, (bool)val)); manager.AddSetter("AG10", (cpu, val) => cpu.Vessel.ActionGroups.SetGroup(KSPActionGroup.Custom10, (bool)val)); manager.AddGetter("SAS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.SAS]); manager.AddGetter("GEAR", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Gear]); manager.AddGetter("LEGS", cpu => VesselUtils.GetLandingLegStatus(cpu.Vessel)); manager.AddGetter("CHUTES", cpu => VesselUtils.GetChuteStatus(cpu.Vessel)); manager.AddGetter("LIGHTS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Light]); manager.AddGetter("PANELS", cpu => VesselUtils.GetSolarPanelStatus(cpu.Vessel)); manager.AddGetter("BRAKES", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Brakes]); manager.AddGetter("RCS", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.RCS]); manager.AddGetter("ABORT", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Abort]); manager.AddGetter("AG1", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom01]); manager.AddGetter("AG2", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom02]); manager.AddGetter("AG3", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom03]); manager.AddGetter("AG4", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom04]); manager.AddGetter("AG5", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom05]); manager.AddGetter("AG6", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom06]); manager.AddGetter("AG7", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom07]); manager.AddGetter("AG8", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom08]); manager.AddGetter("AG9", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom09]); manager.AddGetter("AG10", cpu => cpu.Vessel.ActionGroups[KSPActionGroup.Custom10]); }