Пример #1
0
 public static void Main()
 {
     var connection = new KRPC.Client.Connection (address: IPAddress.Parse ("10.0.2.2"));
     var vessel = connection.SpaceCenter ().ActiveVessel;
     KRPC.Client.Tuple<double,double,double,double> q = vessel.Flight ().Rotation;
     Console.WriteLine (q.Item1 + "," + q.Item2 + "," + q.Item3 + "," + q.Item4);
 }
Пример #2
0
    public static void Main()
    {
        var connection = new KRPC.Client.Connection();
        var vessel     = connection.SpaceCenter().ActiveVessel;

        KRPC.Client.Tuple <double, double, double> v = vessel.Flight().Prograde;
        Console.WriteLine(v.Item1 + "," + v.Item2 + "," + v.Item3);
    }
Пример #3
0
 public static void Main()
 {
     var connection = new KRPC.Client.Connection (name: "Kerbal Alarm Clock Example", address: IPAddress.Parse ("10.0.2.2"));
     var kac = connection.KerbalAlarmClock ();
     var alarm = kac.CreateAlarm (AlarmType.Raw, "My New Alarm", connection.SpaceCenter ().UT + 10);
     alarm.Notes = "10 seconds have now passed since the alarm was created.";
     alarm.Action = AlarmAction.MessageOnly;
 }
Пример #4
0
    public static void Main()
    {
        var connection = new KRPC.Client.Connection();
        var vessel     = connection.SpaceCenter().ActiveVessel;

        KRPC.Client.Tuple <double, double, double, double> q = vessel.Flight().Rotation;
        Console.WriteLine(q.Item1 + "," + q.Item2 + "," + q.Item3 + "," + q.Item4);
    }
Пример #5
0
    public static void Main()
    {
        var connection = new KRPC.Client.Connection(name: "Kerbal Alarm Clock Example");
        var kac        = connection.KerbalAlarmClock();
        var alarm      = kac.CreateAlarm(AlarmType.Raw, "My New Alarm", connection.SpaceCenter().UT + 10);

        alarm.Notes  = "10 seconds have now passed since the alarm was created.";
        alarm.Action = AlarmAction.MessageOnly;
    }
Пример #6
0
 public static void Main()
 {
     var connection = new KRPC.Client.Connection (address: IPAddress.Parse ("10.0.2.2"));
     var vessel = connection.SpaceCenter ().ActiveVessel;
     var root = vessel.Parts.Root;
     var stack = new Stack<KRPC.Client.Tuple<Part,int>> ();
     stack.Push (new KRPC.Client.Tuple<Part,int> (root, 0));
     while (stack.Count > 0) {
         var item = stack.Pop ();
         Part part = item.Item1;
         int depth = item.Item2;
         Console.WriteLine (new String (' ', depth) + part.Title);
         foreach (var child in part.Children)
             stack.Push (new KRPC.Client.Tuple<Part,int> (child, depth + 1));
     }
 }
Пример #7
0
    public static void Main()
    {
        var connection = new KRPC.Client.Connection();
        var vessel     = connection.SpaceCenter().ActiveVessel;
        var root       = vessel.Parts.Root;
        var stack      = new Stack <KRPC.Client.Tuple <Part, int> > ();

        stack.Push(new KRPC.Client.Tuple <Part, int> (root, 0));
        while (stack.Count > 0)
        {
            var  item  = stack.Pop();
            Part part  = item.Item1;
            int  depth = item.Item2;
            Console.WriteLine(new String(' ', depth) + part.Title);
            foreach (var child in part.Children)
            {
                stack.Push(new KRPC.Client.Tuple <Part, int> (child, depth + 1));
            }
        }
    }
Пример #8
0
        private void addStream(DataType type)
        {
            // Some much used variables
            spaceCenter = connection.SpaceCenter();

            vessel          = connection.SpaceCenter().ActiveVessel;
            control         = connection.SpaceCenter().ActiveVessel.Control;
            orbit           = connection.SpaceCenter().ActiveVessel.Orbit;
            resources       = connection.SpaceCenter().ActiveVessel.Resources;
            resources_stage = connection.SpaceCenter().ActiveVessel.ResourcesInDecoupleStage(stage, false);

            inertialRefFrame = orbit.Body.NonRotatingReferenceFrame;
            surfaceRefFrame  = vessel.SurfaceReferenceFrame;
            mapRefFrame      = orbit.Body.ReferenceFrame;

            inertFlight = connection.SpaceCenter().ActiveVessel.Flight(inertialRefFrame);
            flight      = connection.SpaceCenter().ActiveVessel.Flight(surfaceRefFrame);
            mapFlight   = connection.SpaceCenter().ActiveVessel.Flight(mapRefFrame);


            Kstream stream;

            switch (type)
            {
            ///// BODY DATA /////
            case DataType.body_radius:
                stream = new floatStream(connection.AddStream(() => orbit.Body.EquatorialRadius));
                break;

            case DataType.body_gravityParameter:
                stream = new floatStream(connection.AddStream(() => orbit.Body.GravitationalParameter));
                break;

            case DataType.body_rotSpeed:
                stream = new floatStream(connection.AddStream(() => orbit.Body.RotationalSpeed));
                break;

            case DataType.body_name:
                stream = new stringStream(connection.AddStream(() => orbit.Body.Name));
                break;

            case DataType.body_mass:
                stream = new floatStream(connection.AddStream(() => orbit.Body.Mass));
                break;

            case DataType.body_rotPeriod:
                stream = new floatStream(connection.AddStream(() => orbit.Body.RotationalPeriod));
                break;

            case DataType.body_nonRotatingReferenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => orbit.Body.NonRotatingReferenceFrame));
                break;

            ///// CONTROL DATA /////

            case DataType.control_SAS:
                stream = new boolStream(connection.AddStream(() => control.SAS));
                break;

            case DataType.control_SASmode:
                stream = new sasModeStream(connection.AddStream(() => control.SASMode));
                break;

            case DataType.control_RCS:
                stream = new boolStream(connection.AddStream(() => control.RCS));
                break;

            case DataType.control_gear:
                stream = new boolStream(connection.AddStream(() => control.Gear));
                break;

            case DataType.control_brakes:
                stream = new boolStream(connection.AddStream(() => control.Brakes));
                break;

            case DataType.control_lights:
                stream = new boolStream(connection.AddStream(() => control.Lights));
                break;

            case DataType.control_abort:
                stream = new boolStream(connection.AddStream(() => control.Abort));
                break;

            case DataType.control_actionGroup0:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(0)));
                break;

            case DataType.control_actionGroup1:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(1)));
                break;

            case DataType.control_actionGroup2:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(2)));
                break;

            case DataType.control_actionGroup3:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(3)));
                break;

            case DataType.control_actionGroup4:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(4)));
                break;

            case DataType.control_actionGroup5:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(5)));
                break;

            case DataType.control_actionGroup6:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(6)));
                break;

            case DataType.control_actionGroup7:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(7)));
                break;

            case DataType.control_actionGroup8:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(8)));
                break;

            case DataType.control_actionGroup9:
                stream = new boolStream(connection.AddStream(() => control.GetActionGroup(9)));
                break;

            case DataType.control_throttle:
                stream = new floatStream(connection.AddStream(() => control.Throttle));
                break;

            case DataType.control_currentStage:
                stream = new intStream(connection.AddStream(() => control.CurrentStage));
                break;

            case DataType.control_nodes:
                stream = new IListNodeStream(connection.AddStream(() => control.Nodes));
                break;

            ///// FLIGHT DATA /////

            case DataType.flight_gForce:
                stream = new floatStream(connection.AddStream(() => flight.GForce));
                break;

            case DataType.flight_angleOfAttack:
                stream = new floatStream(connection.AddStream(() => flight.AngleOfAttack));
                break;

            case DataType.flight_meanAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.MeanAltitude));
                break;

            case DataType.flight_surfaceAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.SurfaceAltitude));
                break;

            case DataType.flight_bedrockAltitude:
                stream = new doubleStream(connection.AddStream(() => flight.BedrockAltitude));
                break;

            case DataType.flight_elevation:
                stream = new doubleStream(connection.AddStream(() => flight.Elevation));
                break;

            case DataType.flight_latitude:
                stream = new doubleStream(connection.AddStream(() => flight.Latitude));
                break;

            case DataType.flight_longitude:
                stream = new doubleStream(connection.AddStream(() => flight.Longitude));
                break;

            case DataType.flight_map_latitude:
                stream = new doubleStream(connection.AddStream(() => mapFlight.Latitude));
                break;

            case DataType.flight_map_longitude:
                stream = new doubleStream(connection.AddStream(() => mapFlight.Longitude));
                break;

            case DataType.flight_velocity:
                stream = new tuple3Stream(connection.AddStream(() => flight.Velocity));
                break;

            case DataType.flight_speed:
                stream = new doubleStream(connection.AddStream(() => flight.Speed));
                break;

            case DataType.flight_horizontalSpeed:
                stream = new doubleStream(connection.AddStream(() => flight.HorizontalSpeed));
                break;

            case DataType.flight_verticalSpeed:
                stream = new doubleStream(connection.AddStream(() => flight.VerticalSpeed));
                break;

            case DataType.flight_centerOfMass:
                stream = new tuple3Stream(connection.AddStream(() => flight.CenterOfMass));
                break;

            case DataType.flight_rotation:
                stream = new tuple4Stream(connection.AddStream(() => flight.Rotation));
                break;

            case DataType.flight_direction:
                stream = new tuple3Stream(connection.AddStream(() => flight.Direction));
                break;

            case DataType.flight_pitch:
                stream = new floatStream(connection.AddStream(() => flight.Pitch));
                break;

            case DataType.flight_heading:
                stream = new floatStream(connection.AddStream(() => flight.Heading));
                break;

            case DataType.flight_roll:
                stream = new floatStream(connection.AddStream(() => flight.Roll));
                break;

            case DataType.flight_atmosphereDensity:
                stream = new floatStream(connection.AddStream(() => flight.AtmosphereDensity));
                break;

            case DataType.flight_dynamicPressure:
                stream = new floatStream(connection.AddStream(() => flight.DynamicPressure));
                break;

            case DataType.flight_staticPressure:
                stream = new floatStream(connection.AddStream(() => flight.StaticPressure));
                break;

            case DataType.flight_prograde:
                stream = new tuple3Stream(connection.AddStream(() => flight.Prograde));
                break;

            case DataType.flight_retrograde:
                stream = new tuple3Stream(connection.AddStream(() => flight.Retrograde));
                break;

            case DataType.flight_radial:
                stream = new tuple3Stream(connection.AddStream(() => flight.Radial));
                break;

            case DataType.flight_antiRadial:
                stream = new tuple3Stream(connection.AddStream(() => flight.AntiRadial));
                break;

            case DataType.flight_normal:
                stream = new tuple3Stream(connection.AddStream(() => flight.Normal));
                break;

            case DataType.flight_antiNormal:
                stream = new tuple3Stream(connection.AddStream(() => flight.AntiNormal));
                break;


            ///// INERTIAL FLIGHT DATA /////

            case DataType.flight_inertial_roll:
                stream = new floatStream(connection.AddStream(() => inertFlight.Roll));
                break;

            case DataType.flight_inertial_pitch:
                stream = new floatStream(connection.AddStream(() => inertFlight.Pitch));
                break;

            case DataType.flight_inertial_yaw:
                stream = new floatStream(connection.AddStream(() => inertFlight.Heading));
                break;

            case DataType.flight_inertial_direction:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Direction));
                break;

            case DataType.flight_inertial_rotation:
                stream = new tuple4Stream(connection.AddStream(() => inertFlight.Rotation));
                break;

            case DataType.flight_inertial_velocity:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Velocity));
                break;

            case DataType.flight_inertial_prograde:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Prograde));
                break;

            case DataType.flight_inertial_retrograde:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Retrograde));
                break;

            case DataType.flight_inertial_radial:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Radial));
                break;

            case DataType.flight_inertial_antiRadial:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.AntiRadial));
                break;

            case DataType.flight_inertial_normal:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.Normal));
                break;

            case DataType.flight_inertial_antiNormal:
                stream = new tuple3Stream(connection.AddStream(() => inertFlight.AntiNormal));
                break;


            ///// ORBIT DATA /////

            case DataType.orbit_apoapsisAltitude:
                stream = new doubleStream(connection.AddStream(() => orbit.ApoapsisAltitude));
                break;

            case DataType.orbit_apoapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.Apoapsis));
                break;

            case DataType.orbit_periapsisAltitude:
                stream = new doubleStream(connection.AddStream(() => orbit.PeriapsisAltitude));
                break;

            case DataType.orbit_periapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.Periapsis));
                break;

            case DataType.orbit_radius:
                stream = new doubleStream(connection.AddStream(() => orbit.Radius));
                break;

            case DataType.orbit_speed:
                stream = new doubleStream(connection.AddStream(() => orbit.Speed));
                break;

            case DataType.orbit_celestialBody:
                stream = new celestialBodyStream(connection.AddStream(() => orbit.Body));
                break;

            case DataType.orbit_semiMajorAxis:
                stream = new doubleStream(connection.AddStream(() => orbit.SemiMajorAxis));
                break;

            case DataType.orbit_semiMinorAxis:
                stream = new doubleStream(connection.AddStream(() => orbit.SemiMinorAxis));
                break;

            case DataType.orbit_argumentOfPeriapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.ArgumentOfPeriapsis));
                break;

            case DataType.orbit_longitudeOfAscendingNode:
                stream = new doubleStream(connection.AddStream(() => orbit.LongitudeOfAscendingNode));
                break;

            case DataType.orbit_eccentricity:
                stream = new doubleStream(connection.AddStream(() => orbit.Eccentricity));
                break;

            case DataType.orbit_inclination:
                stream = new doubleStream(connection.AddStream(() => orbit.Inclination));
                break;

            case DataType.orbit_trueAnomaly:
                stream = new doubleStream(connection.AddStream(() => orbit.TrueAnomaly));
                break;

            case DataType.orbit_timeToApoapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToApoapsis));
                break;

            case DataType.orbit_timeToPeriapsis:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToPeriapsis));
                break;

            case DataType.orbit_period:
                stream = new doubleStream(connection.AddStream(() => orbit.Period));
                break;

            case DataType.orbit_timeToSOIChange:
                stream = new doubleStream(connection.AddStream(() => orbit.TimeToSOIChange));
                break;



            ///// RESOURCE DATA /////

            case DataType.resource_total_max_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources.Max("ElectricCharge")));
                break;

            case DataType.resource_total_amount_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources.Amount("ElectricCharge")));
                break;

            case DataType.resource_stage_max_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("ElectricCharge")));
                break;

            case DataType.resource_stage_amount_electricCharge:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("ElectricCharge")));
                break;


            case DataType.resource_total_max_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources.Max("MonoPropellant")));
                break;

            case DataType.resource_total_amount_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources.Amount("MonoPropellant")));
                break;

            case DataType.resource_stage_max_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("MonoPropellant")));
                break;

            case DataType.resource_stage_amount_monoPropellant:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("MonoPropellant")));
                break;


            case DataType.resource_total_max_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources.Max("LiquidFuel")));
                break;

            case DataType.resource_total_amount_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources.Amount("LiquidFuel")));
                break;

            case DataType.resource_stage_max_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("LiquidFuel")));
                break;

            case DataType.resource_stage_amount_liquidFuel:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("LiquidFuel")));
                break;


            case DataType.resource_stage_max_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources_stage.Max("Oxidizer")));
                break;

            case DataType.resource_stage_amount_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources_stage.Amount("Oxidizer")));
                break;

            case DataType.resource_total_max_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources.Max("Oxidizer")));
                break;

            case DataType.resource_total_amount_oxidizer:
                stream = new floatStream(connection.AddStream(() => resources.Amount("Oxidizer")));
                break;


            ///// SPACECENTER DATA /////
            case DataType.spacecenter_universial_time:
                stream = new doubleStream(connection.AddStream(() => spaceCenter.UT));
                break;


            ///// VESSEL DATA /////
            case DataType.vessel_MET:
                stream = new doubleStream(connection.AddStream(() => vessel.MET));
                break;

            case DataType.vessel_type:
                stream = new vesselTypeStream(connection.AddStream(() => vessel.Type));
                break;

            case DataType.vessel_mass:
                stream = new floatStream(connection.AddStream(() => vessel.Mass));
                break;

            case DataType.vessel_dryMass:
                stream = new floatStream(connection.AddStream(() => vessel.DryMass));
                break;

            case DataType.vessel_position:
                stream = new tuple3Stream(connection.AddStream(() => vessel.Position(vessel.Orbit.Body.NonRotatingReferenceFrame)));
                break;

            case DataType.vessel_velocity:
                stream = new tuple3Stream(connection.AddStream(() => vessel.Velocity(vessel.Orbit.Body.NonRotatingReferenceFrame)));
                break;

            case DataType.vessel_parts:
                stream = new vesselPartsStream(connection.AddStream(() => vessel.Parts));
                break;

            case DataType.vessel_referenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => vessel.ReferenceFrame));
                break;

            case DataType.vessel_orbit:
                stream = new OrbitStream(connection.AddStream(() => vessel.Orbit));
                break;

            case DataType.vessel_autoPilot:
                stream = new AutoPilotStream(connection.AddStream(() => vessel.AutoPilot));
                break;

            case DataType.vessel_surfaceReferenceFrame:
                stream = new referenceFrameStream(connection.AddStream(() => vessel.SurfaceReferenceFrame));
                break;


            default:
                throw (new Exception("DataType: " + type.ToString() + " not supported"));
            }

            // Safety check if type already exists in streams
            if (!streams.ContainsKey(type))
            {
                streams.Add(type, stream);
            }
        }
        public void SetConnectionAndStartPolling(KRPC.Client.Connection connection)
        {
            _connection = connection;
            _spaceCenter = _connection.SpaceCenter();

            _shouldPoll = true;
            _pollingThread = new Thread(Poll);
            _pollingThread.Start();
            ConnectedAndViewsVisbilityChanged();
        }