Beispiel #1
0
        public Program()
        {
            // Load state if state was saved previously.
            int savedState;

            if (int.TryParse(Storage, out savedState))
            {
                state = (State)savedState;
            }
            else
            {
                state = State.WaitingForPayload;
            }

            // Find all needed blocks.
            blocks = new ExpectedBlocks(GridTerminalSystem);
            blocks.FindBlock <IMyTextPanel>(CRANE_ARM_STATUS_PANEL);
            blocks.FindBlock <IMyPistonBase>(CRANE_ARM_PISTON);
            blocks.FindBlock <IMyMotorStator>(CRANE_ARM_ROTOR);
            blocks.FindBlocks <IMyThrust>(CRANE_ARM_THRUSTER, 6);
            blocks.FindBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR, 3);
            blocks.FindBlocks <IMyPistonBase>(CRANE_LIFT_PISTON, 2);

            // Initialize other utility classes.
            thrustControl                = new ThrustControl(blocks);
            payloadPickupStateMachine    = new PayloadPickupStateMachine(blocks);
            payloadTransportStateMachine = new PayloadTransportStateMachine(blocks, thrustControl);
            craneArmResetStateMachine    = new CraneArmResetStateMachine(blocks, thrustControl);

            // Start update loop.
            Runtime.UpdateFrequency |= UpdateFrequency.Update1;
        }
Beispiel #2
0
    /**
     *  Store a reference to the GridTerminalSystem, identify the controller and initialize
     *  the features, if they are enabled / runnable
     */
    public void init(IMyGridTerminalSystem gridTerminalSystem)
    {
        // Get references to the GridTerminalSystem and the (preferred) control seat
        registry.gridTerminalSystem = gridTerminalSystem;
        registry.controller         = identifyController(gridTerminalSystem, config.preferredControllerName);

        // Get references to the ship's thrusters, grouped by direction
        registry.thrusters = ThrustControl.identifyThrusters(registry);

        // Get references to the ship's gyros
        registry.gyros = GyroControl.identifyGyros(registry);

        // Initialize the log
        log.init(gridTerminalSystem);

        // Initialize the sensors
        sensors.init(registry);

        // Initialize the controls
        controls.init(registry);

        // Log the controller name
        log.info("Controller: " + registry.controller.CustomName);

        // Initialize the features
        features.ForEach(wrappedFeature => {
            if (shouldRunFeature(wrappedFeature))
            {
                log.info("Initializing feature [" + wrappedFeature.feature.getName() + "]");
                wrappedFeature.feature.init(registry, log, controls, sensors, config);
                wrappedFeature.nameUCase = wrappedFeature.feature.getName().ToUpper();
            }
        });
    }
Beispiel #3
0
 public void init(FlightAssistantRegistry registry, Log log, FlightAssistantControls controls, Sensors sensors, FlightAssistantConfig config)
 {
     this.config        = config;
     this.sensors       = sensors;
     this.thrustControl = controls.thrustControl;
     this.gyroControl   = controls.gyroControl;
     this.registry      = registry;
     this.log           = log;
 }
Beispiel #4
0
 // Use this for initialization
 void Start()
 {
     thrustControl        = GameObject.FindObjectOfType <ThrustControl>();
     cameraPinchZoom      = GameObject.FindObjectOfType <CameraPinchZoom>();
     accelerometerControl = GameObject.FindObjectOfType <AccelerometerControl>();
     rope     = GameObject.FindGameObjectWithTag("Rope");
     player   = GameObject.FindGameObjectWithTag("Player");
     playArea = GameObject.FindGameObjectWithTag("Play Area");
 }
Beispiel #5
0
    public void init(FlightAssistantRegistry registry, Log log, FlightAssistantControls controls, Sensors sensors, FlightAssistantConfig config)
    {
        this.config        = config;
        this.sensors       = sensors;
        this.thrustControl = controls.thrustControl;
        this.registry      = registry;
        this.log           = log;

        this.cruisingSpeed = config.cruiseControlDefaultCruisingSpeed;
    }
Beispiel #6
0
    void Update()
    {
        if (currentNode != null)
        {
            float throttle  = 0f;
            var   thrustDir = new Vector2();
            if (Input.GetKey(KeyCode.W))
            {
                throttle    = 1f;
                thrustDir.y = 1f;
            }
            if (Input.GetKey(KeyCode.S))
            {
                throttle    = 1f;
                thrustDir.y = -1f;
            }
            if (Input.GetKey(KeyCode.A))
            {
                throttle    = 1f;
                thrustDir.x = -1f;
            }
            if (Input.GetKey(KeyCode.D))
            {
                throttle    = 1f;
                thrustDir.x = 1f;
            }
            var thrustControl = new ThrustControl()
            {
                Dir      = thrustDir.normalized,
                Throttle = throttle
            };
            currentNode.SendMessage("SetThrust", thrustControl);

            if (Input.GetKeyDown(KeyCode.F))
            {
                currentNode.SendMessage("ToggleFlightAssist");
            }

            Vector2 aimDir = MouseManager.WorldPosition - currentNode.Position2;
            aimDis  = aimDir.magnitude;
            aimDir /= aimDis;

            aimDis = Mathf.Min(aimDis, MaxAimDis);

            CrossHair.Position = currentNode.Position + (Vector3)(aimDir * aimDis);

            currentNode.SendMessage("RotateToDir", aimDir);
        }

        DebugText.Add($"desiredThurst: {desiredThurst}");
    }
Beispiel #7
0
    public void SetThrust(ThrustControl thrustControl)
    {
        this.desiredThrust = thrustControl;

        float maxInfluence = Vector2.Dot(thrustControl.Dir * thrustControl.Throttle, -NozzleDir);

        if (maxInfluence > 0f)
        {
            Throttle = maxInfluence;
        }
        else
        {
            Throttle = 0f;
        }
    }
Beispiel #8
0
 public PayloadTransportStateMachine(ExpectedBlocks blocks, ThrustControl thrustControl)
 {
     craneArmRotor      = blocks.GetBlock <IMyMotorStator>(CRANE_ARM_ROTOR);
     craneLiftPistons   = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON);
     this.thrustControl = thrustControl;
 }
Beispiel #9
0
 public CraneArmResetStateMachine(ExpectedBlocks blocks, ThrustControl thrustControl)
 {
     craneLiftPistons   = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON);
     this.thrustControl = thrustControl;
 }