Ejemplo n.º 1
0
        void Main(string arg)
        {
            if (initcounter > 0)
            {
                Init();
                return;
            }

            bool dampeners = designator.DampenersOverride;

            Vector3D v_lin = GetShipVelocity(controller);
            Vector3D v_ang = GetShipAngularVelocity(controller);

            Vector3D gravity = GetGravity(controller);

            Vector3D input_lin = new Vector3D(0, 0, 0);
            Vector3D input_ang = new Vector3D(0, 0, 0);

            foreach (IMyShipController cockpit in Cockpits)
            {
                input_lin += cockpit.MoveIndicator;
                Vector2 input_mouse = cockpit.RotationIndicator / -10;
                input_ang += new Vector3D(input_mouse.X, input_mouse.Y, -cockpit.RollIndicator);
            }

            float azimuth   = GetAngle(r_azimuth);
            float elevation = GetAngle(r_elevation);

            double v_az = input_ang.Y * 0.4 - (v_ang.Y + (Math.Sin(azimuth) * v_ang.X + Math.Cos(azimuth) * v_ang.Z) * Math.Tan(elevation));
            double v_el = input_ang.X * 0.4 + (v_ang.Z * Math.Sin(azimuth) - v_ang.X * Math.Cos(azimuth));

            r_azimuth.TargetVelocityRad   = Convert.ToSingle(v_az);
            r_elevation.TargetVelocityRad = Convert.ToSingle(v_el);

            if ((Math.Abs(Math.Sin(azimuth)) + 0.2) * Math.Abs(elevation) > 1.3)
            {
                input_ang.Z -= Math.Sin(azimuth) * elevation;
            }


            Gyroscopes.SetRotation(GyroFactor * Convert.ToSingle(input_lin.Y), GyroFactor * Convert.ToSingle(input_lin.X), GyroFactor * Convert.ToSingle(input_ang.Z));


            for (int j = 0; j < TForward.Count; j++)
            {
                TForward[j].SetValue <float>("Override", Convert.ToSingle(input_lin.Z) * -100);
            }
            for (int j = 0; j < TBackward.Count; j++)
            {
                TBackward[j].SetValue <float>("Override", Convert.ToSingle(input_lin.Z) * 100);
            }
            Vector3D target = designator.GetPosition() + designator.WorldMatrix.Forward * 400;

            foreach (IMyLargeTurretBase turret in Designators)
            {
                if (turret.HasTarget)
                {
                    targetList.Add(turret.GetTargetedEntity());
                }
            }


            targetList.tick();

            Vector3D velocity = Vector3D.Zero;



            if (targetList.Count() > 0)
            {
                target   = targetList.ReturnTargetPosition();
                velocity = targetList.ReturnTargetVelocity();
            }


            foreach (Turret turret in Turrets)
            {
                turret.Target(target, velocity, this, targetList.Count() > 0);
            }


            Echo("Number of Targets found: " + Convert.ToString(targetList.Count()));
        }