Exemplo n.º 1
0
        public IEnumerator <bool> Init()
        {
            iniSerializer = new INISerializer("DroneControl");
            iniSerializer.AddValue("controllerName", x => x, "Controller");

            if (Me.CustomData == "")
            {
                string temp = Me.CustomData;
                iniSerializer.FirstSerialization(ref temp);
                Me.CustomData = temp;
            }
            else
            {
                iniSerializer.DeSerialize(Me.CustomData);
            }
            yield return(true);

            time = new IngameTime();
            GTS  = new GridTerminalSystemUtils(Me, GridTerminalSystem);
            yield return(true);

            controller = GTS.GetBlockWithNameOnGrid(controllerName) as IMyShipController;
            yield return(true);

            entityTracking = new EntityTracking_Module(GTS, controller, null, EntityTracking_Module.refExpSettings.Turret);
            autoPilot      = new AutoPilot(GTS, controller, time, entityTracking);
            yield return(true);

            comms   = new InterGridComms(IGC, time, Me);
            comms.P = this;
            yield return(true);

            RegisterCommands();
            loaded = true;
        }
Exemplo n.º 2
0
            public RotorTurretGroup(IMyBlockGroup turretGroup, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
            {
                var rotors = new List <IMyMotorStator>();

                turretGroup.GetBlocksOfType(rotors);

                Setup(rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag);
            }
            public AdvGyroControl(PID_Controller.PIDSettings pidSettings, IngameTime ingameTime)
            {
                yawPid   = new PID_Controller(pidSettings);
                pitchPid = new PID_Controller(pidSettings);
                rollPid  = new PID_Controller(pidSettings);

                this.ingameTime = ingameTime;
            }
Exemplo n.º 4
0
        public Program()
        {
            time              = new IngameTime();
            droneManagement   = new DroneManagement(time, IGC);
            droneManagement.P = this;

            Runtime.UpdateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update100;
        }
Exemplo n.º 5
0
            public AdvThrustControl(IMyShipController controller, List <IMyThrust> thrusters, IngameTime ingameTime)
            {
                this.controller = controller;
                this.ingameTime = ingameTime;

                SortThrustersByDirection(thrusters, controller);
                CountThrustersPerDirection();
            }
Exemplo n.º 6
0
        public IEnumerator <bool> Init()
        {
            cannonSettings = new INISerializer("CannonSettings");
            cannonSettings.AddValue("referenceName", x => x, "RCReference");
            cannonSettings.AddValue("speedCap", x => double.Parse(x), 104.38);
            cannonSettings.AddValue("launchVelocity", x => double.Parse(x), 100.0);
            cannonSettings.AddValue("sourceRotorTName", x => x, "[OrbitalCannonBase]_[Azimuth]");
            cannonSettings.AddValue("elevationTag", x => x, "[Elevation]");
            cannonSettings.AddValue("timerName", x => x, "CannonTimer");


            if (Me.CustomData == "")
            {
                string temp = Me.CustomData;
                cannonSettings.FirstSerialization(ref temp);
                Me.CustomData = temp;
            }
            else
            {
                cannonSettings.DeSerialize(Me.CustomData);
            }
            yield return(true);

            ingameTime = new IngameTime();
            GTSUtils   = new GridTerminalSystemUtils(Me, GridTerminalSystem);

            yield return(true);

            IMyShipController reference   = GridTerminalSystem.GetBlockWithName((string)cannonSettings.GetValue("referenceName")) as IMyShipController;
            IMyMotorStator    sourceRotor = GridTerminalSystem.GetBlockWithName((string)cannonSettings.GetValue("sourceRotorTName")) as IMyMotorStator;
            IMyTimerBlock     timer       = GridTerminalSystem.GetBlockWithName((string)cannonSettings.GetValue("timerName")) as IMyTimerBlock;

            Echo($"Getting blocks status:...\nreference: {reference != null}\nsourceRotor: {sourceRotor != null}");

            if (reference == null || sourceRotor == null)
            {
                throw new Exception("cant get blocks!");
            }

            yield return(true);

            targeter = new Targeter
                       (
                (double)cannonSettings.GetValue("speedCap"),
                (double)cannonSettings.GetValue("launchVelocity"),
                reference
                       );
            targeter.directionFoundCallback += TargetCalculatedCallback;

            yield return(true);

            cannon       = Cannon.CreateCannon(sourceRotor, GTSUtils, ingameTime, reference, (string)cannonSettings.GetValue("sourceRotorTName"), (string)cannonSettings.GetValue("elevationTag"));
            cannon.Timer = timer;
            yield return(true);

            Echo("Initialized!");
            initialized = true;
        }
Exemplo n.º 7
0
            public InterGridComms(IMyIntergridCommunicationSystem comms, IngameTime time, IMyProgrammableBlock me)
            {
                commands       = new Dictionary <string, Action <object> >();
                keepaliveChann = comms.RegisterBroadcastListener("ServerKeepAlive");

                this.comms = comms;
                this.time  = time;
                this.me    = me;
            }
Exemplo n.º 8
0
            public DroneManagement(IngameTime time, IMyIntergridCommunicationSystem comms)
            {
                dronesByPosition = new PositionOctree <Drone>();
                drones           = new Dictionary <long, Drone>();
                commands         = new Dictionary <string, Action <object> >();

                this.time  = time;
                this.comms = comms;
            }
Exemplo n.º 9
0
            public PhysicsTargeting(IMyShipController control, IngameTime ingameTime, double maxProjectileVel, double targetTimeout = 2.5)
            {
                this.targetTimeout    = targetTimeout;
                this.control          = control;
                this.maxProjectileVel = maxProjectileVel;
                this.keepRunning      = true;
                this.ingameTime       = ingameTime;

                internalScheduler = new Scheduler();
            }
Exemplo n.º 10
0
            public void Setup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
            {
                this.deadzoneProvider = deadzoneProvider;
                this.ingameTime       = ingameTime;

                List <IMyMotorStator> elevation = rotors.Where(x => x.CustomName.Contains(elevationTag)).ToList();
                IMyMotorStator        azimuth   = rotors.First(x => x.CustomName.Contains(azimuthTag));

                defaultDir = azimuth.WorldMatrix.Forward;

                List <IMyMotorStator> cannonBases = Select(elevation);

                List <RotorControl.RotorReferencePair> elevationPairs = new List <RotorControl.RotorReferencePair>();

                for (int i = 0; i < elevation.Count; i++)
                {
                    elevationPairs.Add(new RotorControl.RotorReferencePair {
                        rotor = elevation[i], reference = cannonBases[i]
                    });
                }

                RotorControl.RotorReferencePair azimuthPair = new RotorControl.RotorReferencePair {
                    rotor = azimuth, reference = cannonBases[0]
                };

                rotorControl          = new RotorControl(azimuthPair, elevationPairs);
                rotorControl.onTarget = OnTarget;

                #region configuration
                turretConfig = new INISerializer("TurretConfig");

                turretConfig.AddValue("azimuthMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("elevationMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("salvoSize", x => int.Parse(x), 3);
                turretConfig.AddValue("salvoTimeout", x => double.Parse(x), 2.5);

                if (rotorControl.azimuth.rotor.CustomData == "")
                {
                    string temp = rotorControl.azimuth.rotor.CustomData;
                    turretConfig.FirstSerialization(ref temp);
                    rotorControl.azimuth.rotor.CustomData = temp;
                }
                else
                {
                    turretConfig.DeSerialize(rotorControl.azimuth.rotor.CustomData);
                }
                #endregion

                foreach (var cannonbase in cannonBases)
                {
                    var launcher = new RotorLauncher(cannonbase, ingameTime, salvoTimeout);
                    launchers.Add(launcher);
                }
            }
            public void Setup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag, GridTerminalSystemUtils GTS)
            {
                this.deadzoneProvider = deadzoneProvider;
                this.ingameTime       = ingameTime;

                List <IMyMotorStator> elevation = rotors.Where(x => x.CustomName.Contains(elevationTag)).ToList();
                IMyMotorStator        azimuth   = rotors.First(x => x.CustomName.Contains(azimuthTag));

                defaultDir = azimuth.WorldMatrix.Forward;

                #region configuration
                turretConfig = new INISerializer("TurretConfig");

                turretConfig.AddValue("azimuthMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("elevationMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("referenceName", x => x, "TurretReference");

                if (azimuth.CustomData == "")
                {
                    string temp = azimuth.CustomData;
                    turretConfig.FirstSerialization(ref temp);
                    azimuth.CustomData = temp;
                }
                else
                {
                    turretConfig.DeSerialize(azimuth.CustomData);
                }
                #endregion

                IMyTerminalBlock cannonref = GTS.GridTerminalSystem.GetBlockWithName(referenceName);

                if (cannonref == null)
                {
                    throw new Exception($"referenceName ({referenceName}) resolves to NULL!");
                }

                List <RotorControl.RotorReferencePair> elevationPairs = new List <RotorControl.RotorReferencePair>();
                for (int i = 0; i < elevation.Count; i++)
                {
                    elevationPairs.Add(new RotorControl.RotorReferencePair {
                        rotor = elevation[i], reference = cannonref
                    });
                }

                RotorControl.RotorReferencePair azimuthPair = new RotorControl.RotorReferencePair {
                    rotor = azimuth, reference = cannonref
                };

                rotorControl            = new RotorControl(azimuthPair, elevationPairs);
                rotorControl.onTarget  += OnTarget;
                rotorControl.useForward = true;
            }
Exemplo n.º 12
0
            public RotorLauncher(IMyMotorStator baseRotor, IngameTime ingameTime, double timeoutS)
            {
                this.ingameTime = ingameTime;
                this.timeoutS   = timeoutS;

                var currentrotor = baseRotor;

                while (currentrotor != null)
                {
                    propellingRotors.Add(currentrotor);

                    currentrotor = Selector(currentrotor.TopGrid);
                }

                launchRotor = propellingRotors[propellingRotors.Count - 1];
            }
            public void Setup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
            {
                this.deadzoneProvider = deadzoneProvider;
                this.ingameTime       = ingameTime;

                List <IMyMotorStator> elevation = rotors.Where(x => x.CustomName.Contains(elevationTag)).ToList();
                IMyMotorStator        azimuth   = rotors.First(x => x.CustomName.Contains(azimuthTag));

                defaultDir = azimuth.WorldMatrix.Forward;

                List <IMyUserControllableGun> gatlingGunsList = new List <IMyUserControllableGun>();

                List <RotorControl.RotorReferencePair> elevationPairs = Select(elevation, gatlingGunsList);

                RotorControl.RotorReferencePair azimuthPair = new RotorControl.RotorReferencePair {
                    rotor = azimuth, reference = gatlingGunsList[0]
                };

                gatlingGuns = new IMyUserControllableGun[gatlingGunsList.Count];
                for (int i = 0; i < gatlingGunsList.Count; i++)
                {
                    gatlingGuns[i] = gatlingGunsList[i];
                }
                gatlingGunsList = null;

                rotorControl            = new RotorControl(azimuthPair, elevationPairs);
                rotorControl.onTarget   = OnTarget;
                rotorControl.useForward = true;

                #region configuration
                turretConfig = new INISerializer("TurretConfig");

                turretConfig.AddValue("azimuthMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("elevationMultiplier", x => double.Parse(x), -1.0);

                if (rotorControl.azimuth.rotor.CustomData == "")
                {
                    string temp = rotorControl.azimuth.rotor.CustomData;
                    turretConfig.FirstSerialization(ref temp);
                    rotorControl.azimuth.rotor.CustomData = temp;
                }
                else
                {
                    turretConfig.DeSerialize(rotorControl.azimuth.rotor.CustomData);
                }
                #endregion
            }
Exemplo n.º 14
0
        public Program()
        {
            #region serializer
            nameSerializer = new INISerializer("Config");

            nameSerializer.AddValue("rotorTurretGroupTag", x => x, "[HaE RotorTurret]");
            nameSerializer.AddValue("gatlingTurretGroupTag", x => x, "[HaE GatlingTurret]");
            nameSerializer.AddValue("missileTurretGroupTag", x => x, "[HaE MissileTurret]");
            nameSerializer.AddValue("azimuthTag", x => x, "[Azimuth]");
            nameSerializer.AddValue("elevationTag", x => x, "[Elevation]");
            nameSerializer.AddValue("controllerName", x => x, "Controller");
            nameSerializer.AddValue("groupType", x => x, "Any");
            nameSerializer.AddValue("lcdStatusTag", x => x, "[GridcannonStatus]");
            nameSerializer.AddValue("maxProjectileVel", x => double.Parse(x), 104.45);
            nameSerializer.AddValue("maxActiveRotorGunVel", x => double.Parse(x), 30.0);
            nameSerializer.AddValue("maxGatlingBulletVel", x => double.Parse(x), 400.0);
            nameSerializer.AddValue("maxMissileAccel", x => double.Parse(x), 600.0);
            nameSerializer.AddValue("maxMissileVel", x => double.Parse(x), 200.0);
            nameSerializer.AddValue("maxGatlingBulletVel", x => double.Parse(x), 400.0);
            nameSerializer.AddValue("enableAutoDeadzoning", x => bool.Parse(x), true);

            if (Me.CustomData == "")
            {
                string temp = Me.CustomData;
                nameSerializer.FirstSerialization(ref temp);
                Me.CustomData = temp;
            }
            else
            {
                nameSerializer.DeSerialize(Me.CustomData);
            }
            #endregion

            GTSUtils                 = new GridTerminalSystemUtils(Me, GridTerminalSystem);
            mainScheduler            = new Scheduler();
            ingameTime               = new IngameTime();
            rotorTurretGroups        = new List <RotorTurretGroup>();
            missileTurretGroups      = new List <MissileTurretGroup>();
            gatlingTurretGroups      = new List <GatlingTurretGroup>();
            deadzoneProvider         = new DeadzoneProvider(GTSUtils);
            deadzoneProvider.Enabled = enableAutoDeadzoning;

            mainScheduler.AddTask(Init());

            Runtime.UpdateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update10 | UpdateFrequency.Update100;
        }
            public Autopilot_Module(GridTerminalSystemUtils GTS, IMyShipController controller, IngameTime ingameTime,
                                    PID_Controller.PIDSettings gyroPidSettings, PID_Controller.PIDSettings thrustPidSettings,
                                    EntityTracking_Module trackingModule)
            {
                GTS.GridTerminalSystem.GetBlocksOfType(allThrusters);
                GTS.GridTerminalSystem.GetBlocksOfType(gyros);

                this.controller = controller;
                this.ingameTime = ingameTime;

                thrustPidController = new PID_Controller(thrustPidSettings);

                gyroControl        = new AdvGyroControl(gyroPidSettings, ingameTime);
                thrustControl      = new AdvThrustControl(controller, allThrusters, ingameTime);
                collisionAvoidance = new CollisionAvoidance(controller, trackingModule, 10, 10);
                trackingModule.onEntityDetected += collisionAvoidance.OnEntityDetected;
            }
Exemplo n.º 16
0
            public static Cannon CreateCannon
            (
                IMyMotorStator sourceRotor, GridTerminalSystemUtils GTS,
                IngameTime ingameTime, IMyShipController control,
                string azimuthTag, string elevationTag
            )
            {
                List <IMyMotorStator> rotors     = new List <IMyMotorStator>();
                List <IMyMotorStator> cache      = new List <IMyMotorStator>();
                List <IMyMotorStator> prevTop    = new List <IMyMotorStator>();
                List <IMyMotorStator> currentTop = new List <IMyMotorStator>();

                DeadzoneProvider deadzoneProvider = new DeadzoneProvider(GTS);

                rotors.Add(sourceRotor);
                prevTop.AddRange(rotors);

                while (prevTop.Count > 0)
                {
                    foreach (var rotor in prevTop)
                    {
                        cache.Clear();
                        rotor.TopGrid?.GetCubesOfType(GTS.GridTerminalSystem, cache);
                        currentTop.AddRange(cache);
                    }

                    rotors.AddRange(currentTop);

                    prevTop.Clear();
                    prevTop.AddRange(currentTop);
                    currentTop.Clear();
                }

                var turretGroup = new RotorTurretGroup(rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag, GTS);

                turretGroup.TargetDirection(ref Vector3D.Zero);
                turretGroup.defaultDir = control.WorldMatrix.Forward;

                if (turretGroup.CheckGroupStatus() != TurretGroupUtils.TurretGroupStatus.MajorDMG)
                {
                    return(new Cannon(turretGroup, deadzoneProvider, control));
                }

                return(null);
            }
Exemplo n.º 17
0
        public void SubConstructor()
        {
            //DEBUG ATTACHMENTS
            P = this;

            //Timing
            Runtime.UpdateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update100;
            ingameTime = new IngameTime();

            //Generic Inits
            gridTerminalSystemUtils = new GridTerminalSystemUtils(Me, GridTerminalSystem);
            reference       = GridTerminalSystem.GetBlockWithName(REFERENCENAME) as IMyShipController;
            targetingCamera = GridTerminalSystem.GetBlockWithName(TARGETCAMNAME) as IMyCameraBlock;
            textOut         = GridTerminalSystem.GetBlockWithName(TEXTOUTNAME) as IMyTextPanel;
            monoOut         = GridTerminalSystem.GetBlockWithName(MonoLCDName) as IMyTextPanel;

            //Module Inits
            //entityTracking = new EntityTracking_Module(gridTerminalSystemUtils, reference, targetingCamera);
            //autopilotModule = new Autopilot_Module(gridTerminalSystemUtils, reference, ingameTime, gyroPidSettings, thrustPidSettings, entityTracking);
            scheduler  = new Scheduler();
            drawingLib = new MonospaceDrawingLib(175, 175, Color.Black);
            drawingLib.onRenderDone = OnRenderDone;
            drawingLib.AddRenderTask(drawingLib.Generate(), OnRenderDone);
        }
            public Autopilot_Module(GridTerminalSystemUtils GTS, IMyShipController controller, IngameTime ingameTime,
                                    EntityTracking_Module trackingModule)
            {
                GTS.GridTerminalSystem.GetBlocksOfType(allThrusters);
                GTS.GridTerminalSystem.GetBlocksOfType(gyros);

                this.controller = controller;
                this.ingameTime = ingameTime;

                thrustControl      = new AdvThrustControl(controller, allThrusters, ingameTime);
                collisionAvoidance = new CollisionAvoidance(controller, trackingModule, 10, 10);
                trackingModule.onEntityDetected += collisionAvoidance.OnEntityDetected;

                PID_Controller.PIDSettings onePid = new PID_Controller.PIDSettings
                {
                    PGain          = 1,
                    DerivativeGain = 0,
                    IntegralGain   = 0,
                };

                thrustPidController = new PID_Controller(onePid);

                gyroControl = new AdvGyroControl(onePid, ingameTime);
            }
            public RotorLauncher(IMyMotorStator baseRotor, IngameTime ingameTime, double timeoutS)
            {
                var propellingRotors = new List <IMyMotorStator>();

                this.ingameTime = ingameTime;
                this.timeoutS   = timeoutS;

                var currentrotor = baseRotor;

                while (currentrotor != null)
                {
                    propellingRotors.Add(currentrotor);

                    currentrotor = Selector(currentrotor.TopGrid);
                }

                launchRotor          = propellingRotors[propellingRotors.Count - 1];
                propellingRotorArray = new IMyMotorStator[propellingRotors.Count];
                for (int i = 0; i < propellingRotors.Count; i++)
                {
                    propellingRotorArray[i] = propellingRotors[i];
                }
                propellingRotors = null;
            }
 public MissileTurretGroup(GridTerminalSystemUtils GTS, List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
 {
     Setup(GTS, rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag);
 }
Exemplo n.º 21
0
 public Cannon(List <IMyMotorStator> rotors, IMyShipController reference, IngameTime ingameTime, GridTerminalSystemUtils GTSUtils, string azimuthTag, string elevationTag)
 {
     this.reference   = reference;
     deadzoneProvider = new DeadzoneProvider(GTSUtils);
     rotorTurretGroup = new RotorTurretGroup(rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag, GTSUtils);
 }
Exemplo n.º 22
0
 public LapData(IMyShipController controller, IngameTime ingameTime)
 {
     this.controller = controller;
     this.ingameTime = ingameTime;
 }
Exemplo n.º 23
0
 public AutoPilot(GridTerminalSystemUtils GTS, IMyShipController controller, IngameTime time,
                  PID_Controller.PIDSettings gyroPidSettings, PID_Controller.PIDSettings thrustPidSettings,
                  EntityTracking_Module entityTracking)
 {
     autopilotModule = new Autopilot_Module(GTS, controller, time, gyroPidSettings, thrustPidSettings, entityTracking);
 }
            public Autopilot_Module(GridTerminalSystemUtils GTS, IMyShipController controller, IngameTime ingameTime,
                                    PID_Controller.PIDSettings gyroPidSettings, PID_Controller.PIDSettings thrustPidSettings,
                                    EntityTracking_Module trackingModule) : this(GTS, controller, ingameTime, trackingModule)
            {
                thrustPidController = new PID_Controller(thrustPidSettings);

                gyroControl = new AdvGyroControl(gyroPidSettings, ingameTime);
            }
 public RotorTurretGroup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag, GridTerminalSystemUtils GTS)
 {
     Setup(rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag, GTS);
 }
            public MissileTurretGroup(GridTerminalSystemUtils GTS, IMyBlockGroup turretGroup, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
            {
                var rotors = new List <IMyMotorStator>();

                turretGroup.GetBlocksOfType(rotors);

                Setup(GTS, rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag);
            }
Exemplo n.º 27
0
 public AutoPilot(GridTerminalSystemUtils GTS, IMyShipController controller, IngameTime time, EntityTracking_Module entityTracking)
 {
     autopilotModule = new Autopilot_Module(GTS, controller, time, entityTracking);
 }
Exemplo n.º 28
0
 public RotorTurretGroup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
 {
     Setup(rotors, ingameTime, deadzoneProvider, azimuthTag, elevationTag);
 }
Exemplo n.º 29
0
    private int CurYear()
    {
        IngameTime time = GetCurTime();

        return(time.year);
    }
            public AdvancedSimTargeting(ProjectileInfo projectileInfo, MyDetectedEntityInfo target, IMyShipController control, IngameTime ingameTime, double tolerance, bool continuous, double speedlimit = 100, double timescale = 1)
            {
                this.tolerance  = tolerance;
                this.continuous = continuous;
                this.target     = target;
                this.speedlimit = speedlimit;
                this.timescale  = timescale;
                this.control    = control;

                this.projectileInfo = projectileInfo;
                targetInfo          = new TargetInfo(target, timescale);
                tolerance           = target.BoundingBox.Size.Length();
            }