Пример #1
0
            private bool justMove(motorBase motor)
            {
                TimeSpan ts = befTime - nowTime;

                double ang = (motor.Angle - motor.BefAngle);

                double diffAngle = motor.TargetAngle - motor.Angle;

                double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds;

                if (diffAngle > rad)
                {
                    motor.MyMotor.TargetVelocityRPM = motor.TargetRPM;
                }
                else
                {
                    motor.MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2));
                }

                motor.BefAngle = motor.Angle;

                if ((motor.Angle - motor.TargetAngle) < 0.5)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #2
0
            private bool justMove(motorBase motor)
            {
                TimeSpan ts = befTime - nowTime;

                double ang = (MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.befRadian));

                double diffAngle = MathHelperD.ToDegrees(motor.targetRadians) - MathHelperD.ToDegrees(motor.motorRadian);

                double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds;

                if (diffAngle > rad)
                {
                    motor.MyMotor.TargetVelocityRPM = motor.targetRPM;
                }
                else
                {
                    motor.MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2));
                }

                motor.befRadian = motor.motorRadian;

                if ((MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.targetRadians)) < 0.5)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        internal Matrix CreateRotation(double x, double y, double z)
        {
            var rotation = MatrixD.Zero;

            if (x > 0 || x < 0)
            {
                rotation = MatrixD.CreateRotationX(MathHelperD.ToRadians(x));
            }

            if (y > 0 || y < 0)
            {
                if (x > 0 || x < 0)
                {
                    rotation *= MatrixD.CreateRotationY(MathHelperD.ToRadians(y));
                }
                else
                {
                    rotation = MatrixD.CreateRotationY(MathHelperD.ToRadians(y));
                }
            }

            if (z > 0 || z < 0)
            {
                if (x > 0 || x < 0 || y > 0 || y < 0)
                {
                    rotation *= MatrixD.CreateRotationZ(MathHelperD.ToRadians(z));
                }
                else
                {
                    rotation = MatrixD.CreateRotationZ(MathHelperD.ToRadians(z));
                }
            }

            return(rotation);
        }
Пример #4
0
            private bool fastMove(motorBase motor)
            {
                TimeSpan ts = befTime - DateTime.UtcNow;

                //double ang = (motor.Angle - motor.BefAngle);

                double diffAngle = motor.TargetAngle - motor.Angle;

                double rad = MathHelperD.ToRadians(diffAngle) / (-0.03);

                // motor.MyMotor.TargetVelocityRad = -(float)(rad / 5);

                if (TargetRPM < Math.Abs(rad * 9.549))
                {
                    MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? TargetRPM : -TargetRPM;
                }
                else
                {
                    motor.MyMotor.TargetVelocityRad = -(float)(rad / 2);
                }


                befTime        = DateTime.UtcNow;
                motor.BefAngle = motor.Angle;

                if (Math.Abs(motor.Angle - motor.TargetAngle) < 0.5)
                {
                    motor.MyMotor.TargetVelocityRad = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #5
0
        Program()
        {
            _guns        = new List <IMyUserControllableGun>();
            _controllers = new List <IMyRemoteControl>();
            GridTerminalSystem.GetBlocksOfType(_guns);
            GridTerminalSystem.GetBlocksOfType(_controllers);
            _currentControl = _controllers.FirstOrDefault(c => c.IsFunctional);

            if (_currentControl == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(Storage))
            {
                if (!Vector3D.TryParse(Storage, out _origin))
                {
                    _origin = _currentControl.GetPosition();
                }
            }
            else
            {
                _origin = _currentControl.GetPosition();
                Storage = _origin.ToString();
            }

            _weaponAngle = Math.Cos(MathHelperD.ToRadians(WEAPON_ANGLE_LIMIT));
        }
Пример #6
0
            private bool fastMove(motorBase motor)
            {
                TimeSpan ts = befTime - DateTime.UtcNow;

                double diffAngle = MathHelperD.ToDegrees(motor.targetRadians) - MathHelperD.ToDegrees(motor.motorRadian);

                double rad = MathHelperD.ToRadians(diffAngle) / (-0.03);

                if (targetRPM < Math.Abs(rad * 9.549))
                {
                    MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? targetRPM : -targetRPM;
                }
                else
                {
                    motor.MyMotor.TargetVelocityRad = -(float)(rad / 2);
                }



                befTime         = DateTime.UtcNow;
                motor.befRadian = motor.motorRadian;

                if (Math.Abs(MathHelperD.ToDegrees(motor.motorRadian) - MathHelperD.ToDegrees(motor.targetRadians)) < 0.5)
                {
                    motor.MyMotor.TargetVelocityRad = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #7
0
            private bool fastMove()
            {
                TimeSpan ts = befTime - DateTime.UtcNow;

                //double ang = (motor.Angle - motor.BefAngle);

                double diffAngle = DataEntity.GetTargetAngle() - MathHelperD.ToDegrees(MyMotor.Angle);

                double rad = MathHelperD.ToRadians(diffAngle) / (-0.03);


                if (DataEntity.GetVelocity() < Math.Abs(rad * 9.549))
                {
                    MyMotor.TargetVelocityRPM = MathHelperD.ToDegrees(rad) < 0 ? DataEntity.GetVelocity() : -DataEntity.GetVelocity();
                }
                else
                {
                    MyMotor.TargetVelocityRad = -(float)(rad / 2);
                }


                befTime        = DateTime.UtcNow;
                BefAngleDegree = MathHelperD.ToDegrees(MyMotor.Angle);

                if (Math.Abs(MathHelperD.ToDegrees(MyMotor.Angle) - DataEntity.GetTargetAngle()) < 1)
                {
                    MyMotor.TargetVelocityRad = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #8
0
            private bool justMove()
            {
                TimeSpan ts = befTime - nowTime;


                double ang = (MathHelperD.ToDegrees(MyMotor.Angle) - BefAngleDegree);

                double diffAngle = DataEntity.GetTargetAngle() - (MathHelperD.ToDegrees(MyMotor.Angle));

                double rad = MathHelperD.ToRadians(diffAngle) / ts.TotalSeconds;

                if (diffAngle > rad)
                {
                    MyMotor.TargetVelocityRPM = DataEntity.GetVelocity();
                }
                else
                {
                    MyMotor.TargetVelocityRPM = (float)(diffAngle / (Math.PI * 2));
                }

                BefAngleDegree = MathHelperD.ToDegrees(MyMotor.Angle);

                if ((MathHelperD.ToDegrees(MyMotor.Angle) - DataEntity.GetTargetAngle()) < 0.5)
                {
                    MyMotor.TargetVelocityRad = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #9
0
            private bool fastMove(motorBase motor)
            {
                TimeSpan ts = befTime - DateTime.UtcNow;

                //double ang = (motor.Angle - motor.BefAngle);

                double diffAngle = motor.TargetAngle - motor.Angle;

                double rad = MathHelperD.ToRadians(diffAngle) / (-0.02);

                motor.MyMotor.TargetVelocityRad = -(float)(rad / 5);

                befTime        = DateTime.UtcNow;
                motor.BefAngle = motor.Angle;

                if (Math.Abs(motor.Angle - motor.TargetAngle) < 0.5)
                {
                    motor.MyMotor.TargetVelocityRad = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #10
0
        private Vector3D GetSmartLosPosition(int i, ref Dummy.DummyInfo info, int degrees)
        {
            double   angle   = MathHelperD.ToRadians(degrees);
            var      perpDir = Vector3D.CalculatePerpendicularVector(info.Direction);
            Vector3D up;

            Vector3D.Normalize(ref perpDir, out up);
            Vector3D right;

            Vector3D.Cross(ref info.Direction, ref up, out right);
            var offset = Math.Tan(angle); // angle better be in radians

            var destPos = info.Position;

            switch (i)
            {
            case 0:
                return(destPos + (info.Direction * Comp.Ai.GridVolume.Radius));

            case 1:
                return(destPos + ((info.Direction + up * offset) * Comp.Ai.GridVolume.Radius));

            case 2:
                return(destPos + ((info.Direction - up * offset) * Comp.Ai.GridVolume.Radius));

            case 3:
                return(destPos + ((info.Direction + right * offset) * Comp.Ai.GridVolume.Radius));

            case 4:
                return(destPos + ((info.Direction - right * offset) * Comp.Ai.GridVolume.Radius));
            }

            return(Vector3D.Zero);
        }
Пример #11
0
            public motorBase(IMyMotorStator moter, bool reverseFlg, float targetAngle, float targetRpm)
            {
                MyMotor         = moter;
                MyMotor_reverse = reverseFlg;
                targetRadians   = MathHelperD.ToRadians(targetAngle);
                targetRPM       = targetRpm;

                nowTime = DateTime.UtcNow;
                befTime = DateTime.UtcNow;
            }
Пример #12
0
            public void Main()
            {
                string[] str = MyMotor.CustomData.Split(',');

                if (str.Length < 3)
                {
                    finishFlg = false;
                    return;
                }


                float buff = float.Parse(str[1]);

                targetRadians = MyMotor_reverse ? MathHelperD.ToRadians(-buff) : MathHelperD.ToRadians(buff);
                targetRPM     = float.Parse(str[2]);

                nowTime = DateTime.UtcNow;

                finishFlg = fastMove(this);
            }
Пример #13
0
        internal void InitTracking()
        {
            RotationSpeed  = System.AzStep;
            ElevationSpeed = System.ElStep;
            var minAz         = System.MinAzimuth;
            var maxAz         = System.MaxAzimuth;
            var minEl         = System.MinElevation;
            var maxEl         = System.MaxElevation;
            var toleranceRads = MathHelperD.ToRadians(System.Values.HardPoint.AimingTolerance);

            MinElevationRadians = MinElToleranceRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(minEl));
            MaxElevationRadians = MaxElToleranceRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(maxEl));

            MinAzimuthRadians = MinAzToleranceRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(minAz));
            MaxAzimuthRadians = MaxAzToleranceRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(maxAz));

            if (System.TurretMovement == WeaponSystem.TurretType.AzimuthOnly || System.Values.HardPoint.AddToleranceToTracking)
            {
                MinElToleranceRadians -= toleranceRads;
                MaxElToleranceRadians += toleranceRads;
            }
            else if (System.TurretMovement == WeaponSystem.TurretType.ElevationOnly || System.Values.HardPoint.AddToleranceToTracking)
            {
                MinAzToleranceRadians -= toleranceRads;
                MaxAzToleranceRadians += toleranceRads;
            }

            if (MinElToleranceRadians > MaxElToleranceRadians)
            {
                MinElToleranceRadians -= 6.283185f;
            }

            if (MinAzToleranceRadians > MaxAzToleranceRadians)
            {
                MinAzToleranceRadians -= 6.283185f;
            }

            var dummyInfo = Dummies[MiddleMuzzleIndex];

            MuzzleDistToBarrelCenter = Vector3D.Distance(dummyInfo.Info.Position, dummyInfo.Entity.PositionComp.WorldAABB.Center);
        }
Пример #14
0
        internal void InitTracking()
        {
            RotationSpeed  = System.AzStep;
            ElevationSpeed = System.ElStep;
            var minAz = System.MinAzimuth;
            var maxAz = System.MaxAzimuth;
            var minEl = System.MinElevation;
            var maxEl = System.MaxElevation;

            MinElevationRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(minEl));
            MaxElevationRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(maxEl));

            var toleranceRads = MathHelperD.ToRadians(System.Values.HardPoint.AimingTolerance);

            if (MinElevationRadians > MaxElevationRadians)
            {
                MinElevationRadians -= 6.283185f;
            }
            MinAzimuthRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(minAz));
            MaxAzimuthRadians = MathHelperD.ToRadians(MathFuncs.NormalizeAngle(maxAz));

            if (System.TurretMovement == WeaponSystem.TurretType.AzimuthOnly)
            {
                MinElevationRadians -= toleranceRads;
                MaxElevationRadians += toleranceRads;
            }
            else if (System.TurretMovement == WeaponSystem.TurretType.ElevationOnly)
            {
                MinAzimuthRadians -= toleranceRads;
                MaxAzimuthRadians += toleranceRads;
            }

            if (MinAzimuthRadians > MaxAzimuthRadians)
            {
                MinAzimuthRadians -= 6.283185f;
            }
        }
Пример #15
0
        internal Weapon(MyEntity entity, WeaponSystem system, int weaponId, WeaponComponent comp, RecursiveSubparts parts, MyEntity elevationPart, MyEntity azimuthPart, string azimuthPartName, string elevationPartName)
        {
            System            = system;
            Comp              = comp;
            WeaponCreatedTick = System.Session.Tick;

            AnimationsSet = comp.Session.CreateWeaponAnimationSet(system, parts);
            foreach (var set in AnimationsSet)
            {
                foreach (var pa in set.Value)
                {
                    comp.AllAnimations.Add(pa);
                    AnimationLookup.Add(pa.AnimationId, pa);
                }
            }

            ParticleEvents = comp.Session.CreateWeaponParticleEvents(system, parts);

            MyStringHash subtype;

            if (comp.MyCube.DefinitionId.HasValue && comp.Session.VanillaIds.TryGetValue(comp.MyCube.DefinitionId.Value, out subtype))
            {
                if (subtype.String.Contains("Gatling"))
                {
                    _numModelBarrels = 6;
                }
                else
                {
                    _numModelBarrels = System.Barrels.Length;
                }
            }
            else
            {
                _numModelBarrels = System.Barrels.Length;
            }


            bool hitParticle = false;

            foreach (var ammoType in System.AmmoTypes)
            {
                var c = ammoType.AmmoDef.Const;
                if (c.EnergyAmmo)
                {
                    CanUseEnergyAmmo = true;
                }
                if (c.IsHybrid)
                {
                    CanUseHybridAmmo = true;
                }
                if (c.MustCharge)
                {
                    CanUseChargeAmmo = true;
                }
                if (c.IsBeamWeapon)
                {
                    CanUseBeams = true;
                }
                if (c.HitParticle)
                {
                    hitParticle = true;
                }
            }

            comp.HasEnergyWeapon = comp.HasEnergyWeapon || CanUseEnergyAmmo || CanUseHybridAmmo;

            AvCapable = System.HasBarrelShootAv && !Comp.Session.DedicatedServer || hitParticle;

            if (AvCapable && system.FiringSound == WeaponSystem.FiringSoundState.WhenDone)
            {
                FiringEmitter = System.Session.Emitters.Count > 0 ? System.Session.Emitters.Pop() : new MyEntity3DSoundEmitter(null, false, 1f);
                FiringEmitter.CanPlayLoopSounds = true;
                FiringEmitter.Entity            = Comp.MyCube;
                FiringSound = System.FireWhenDonePairs.Count > 0 ? System.FireWhenDonePairs.Pop() : new MySoundPair(System.Values.HardPoint.Audio.FiringSound, false);
            }

            if (AvCapable && system.PreFireSound)
            {
                PreFiringEmitter = System.Session.Emitters.Count > 0 ? System.Session.Emitters.Pop() : new MyEntity3DSoundEmitter(null, false, 1f);
                PreFiringEmitter.CanPlayLoopSounds = true;

                PreFiringEmitter.Entity = Comp.MyCube;
                PreFiringSound          = System.PreFirePairs.Count > 0 ? System.PreFirePairs.Pop() : new MySoundPair(System.Values.HardPoint.Audio.PreFiringSound, false);
            }

            if (AvCapable && system.WeaponReloadSound)
            {
                ReloadEmitter = System.Session.Emitters.Count > 0 ? System.Session.Emitters.Pop() : new MyEntity3DSoundEmitter(null, false, 1f);
                ReloadEmitter.CanPlayLoopSounds = true;

                ReloadEmitter.Entity = Comp.MyCube;
                ReloadSound          = System.ReloadPairs.Count > 0 ? System.ReloadPairs.Pop() : new MySoundPair(System.Values.HardPoint.Audio.ReloadSound, false);
            }

            if (AvCapable && system.BarrelRotationSound)
            {
                RotateEmitter = System.Session.Emitters.Count > 0 ? System.Session.Emitters.Pop() : new MyEntity3DSoundEmitter(null, false, 1f);
                RotateEmitter.CanPlayLoopSounds = true;

                RotateEmitter.Entity = Comp.MyCube;
                RotateSound          = System.RotatePairs.Count > 0 ? System.RotatePairs.Pop() : new MySoundPair(System.Values.HardPoint.Audio.BarrelRotationSound, false);
            }

            if (AvCapable)
            {
                if (System.BarrelEffect1)
                {
                    BarrelEffects1 = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
                if (System.BarrelEffect2)
                {
                    BarrelEffects2 = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
                if (hitParticle && CanUseBeams)
                {
                    HitEffects = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
            }

            if (System.Armor != ArmorState.IsWeapon)
            {
                Comp.HasArmor = true;
            }

            WeaponId           = weaponId;
            PrimaryWeaponGroup = WeaponId % 2 == 0;
            IsTurret           = System.Values.HardPoint.Ai.TurretAttached;
            TurretMode         = System.Values.HardPoint.Ai.TurretController;
            TrackTarget        = System.Values.HardPoint.Ai.TrackTargets;

            if (System.Values.HardPoint.Ai.TurretController)
            {
                AiEnabled = true;
            }

            AimOffset   = System.Values.HardPoint.HardWare.Offset;
            FixedOffset = System.Values.HardPoint.HardWare.FixedOffset;

            HsRate         = System.Values.HardPoint.Loading.HeatSinkRate / 3;
            EnergyPriority = System.Values.HardPoint.Other.EnergyPriority;
            var toleranceInRadians = MathHelperD.ToRadians(System.Values.HardPoint.AimingTolerance);

            AimCone.ConeAngle = toleranceInRadians;
            AimingTolerance   = Math.Cos(toleranceInRadians);

            if (Comp.Platform.Structure.PrimaryWeapon == weaponId)
            {
                comp.TrackingWeapon = this;
            }

            if (IsTurret && !TrackTarget)
            {
                Target = comp.TrackingWeapon.Target;
            }
            else
            {
                Target = new Target(this, true);
            }

            _numOfBarrels = System.Barrels.Length;
            BeamSlot      = new uint[_numOfBarrels];
            Muzzles       = new Muzzle[_numOfBarrels];
            Dummies       = new Dummy[_numOfBarrels];
            WeaponCache   = new WeaponFrameCache(_numOfBarrels);
            NewTarget     = new Target(this);
            RayCallBack   = new ParallelRayCallBack(this);
            Acquire       = new WeaponAcquire(this);
            AzimuthPart   = new PartInfo {
                Entity = azimuthPart
            };
            ElevationPart = new PartInfo {
                Entity = elevationPart
            };
            MuzzlePart = new PartInfo {
                Entity = entity
            };
            MiddleMuzzleIndex = Muzzles.Length > 1 ? Muzzles.Length / 2 - 1 : 0;

            var burstDelay = System.Values.HardPoint.Loading.DelayAfterBurst;

            ShowBurstDelayAsReload = Comp.Session.HandlesInput && System.Values.HardPoint.Loading.ShotsInBurst > 0 && burstDelay > 30 && burstDelay >= TicksPerShot && burstDelay >= System.Values.HardPoint.Loading.ReloadTime;

            ParentIsSubpart   = azimuthPart.Parent is MyEntitySubpart;
            AzimuthInitFwdDir = azimuthPart.PositionComp.LocalMatrixRef.Forward;

            FuckMyLife();

            AiOnlyWeapon = Comp.BaseType != WeaponComponent.BlockType.Turret || (Comp.BaseType == WeaponComponent.BlockType.Turret && (azimuthPartName != "MissileTurretBase1" && elevationPartName != "MissileTurretBarrels" && azimuthPartName != "InteriorTurretBase1" && elevationPartName != "InteriorTurretBase2" && azimuthPartName != "GatlingTurretBase1" && elevationPartName != "GatlingTurretBase2"));
            UniqueId     = comp.Session.UniqueWeaponId;
            ShortLoadId  = comp.Session.ShortLoadAssigner();

            string   ejectorMatch;
            MyEntity ejectorPart;

            if (System.HasEjector && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Ejector, System.AltEjectorName, out ejectorPart, out ejectorMatch))
            {
                Ejector = new Dummy(ejectorPart, this, System.Values.Assignments.Ejector);
            }

            string   scopeMatch;
            MyEntity scopePart;

            if (System.HasScope && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Scope, System.AltScopeName, out scopePart, out scopeMatch))
            {
                Scope = new Dummy(scopePart, this, scopeMatch);
            }

            Monitors = Comp.Monitors[WeaponId];
        }
 public void SetTargetAngle(double value)
 {
     targetAngleRadian = MathHelperD.ToRadians(value);
 }
        public Weapon(MyEntity entity, WeaponSystem system, int weaponId, WeaponComponent comp, Dictionary <EventTriggers, PartAnimation[]> animationSets)
        {
            LoadId      = comp.Session.LoadAssigner();
            ShortLoadId = comp.Session.ShortLoadAssigner();
            MuzzlePart  = new PartInfo {
                Entity = entity
            };
            AnimationsSet = animationSets;

            if (AnimationsSet != null)
            {
                foreach (var set in AnimationsSet)
                {
                    for (int j = 0; j < set.Value.Length; j++)
                    {
                        var animation = set.Value[j];
                        AnimationLookup.Add(animation.AnimationId, animation);
                    }
                }
            }

            System = system;
            Comp   = comp;

            MyStringHash subtype;

            if (comp.MyCube.DefinitionId.HasValue && comp.Session.VanillaIds.TryGetValue(comp.MyCube.DefinitionId.Value, out subtype))
            {
                if (subtype.String.Contains("Gatling"))
                {
                    _numModelBarrels = 6;
                }
                else
                {
                    _numModelBarrels = System.Barrels.Length;
                }
            }
            else
            {
                _numModelBarrels = System.Barrels.Length;
            }


            bool hitParticle = false;

            foreach (var ammoType in System.WeaponAmmoTypes)
            {
                var c = ammoType.AmmoDef.Const;
                if (c.EnergyAmmo)
                {
                    CanUseEnergyAmmo = true;
                }
                if (c.IsHybrid)
                {
                    CanUseHybridAmmo = true;
                }
                if (c.MustCharge)
                {
                    CanUseChargeAmmo = true;
                }
                if (c.IsBeamWeapon)
                {
                    CanUseBeams = true;
                }
                if (c.HitParticle)
                {
                    hitParticle = true;
                }
            }

            comp.HasEnergyWeapon = comp.HasEnergyWeapon || CanUseEnergyAmmo || CanUseHybridAmmo;

            AvCapable = System.HasBarrelShootAv && !Comp.Session.DedicatedServer;

            if (AvCapable && system.FiringSound == WeaponSystem.FiringSoundState.WhenDone)
            {
                FiringEmitter = new MyEntity3DSoundEmitter(Comp.MyCube, true, 1f);
                FiringSound   = new MySoundPair();
                FiringSound.Init(System.Values.HardPoint.Audio.FiringSound);
            }

            if (AvCapable && system.PreFireSound)
            {
                PreFiringEmitter = new MyEntity3DSoundEmitter(Comp.MyCube, true, 1f);
                PreFiringSound   = new MySoundPair();
                PreFiringSound.Init(System.Values.HardPoint.Audio.PreFiringSound);
            }

            if (AvCapable && system.WeaponReloadSound)
            {
                ReloadEmitter = new MyEntity3DSoundEmitter(Comp.MyCube, true, 1f);
                ReloadSound   = new MySoundPair();
                ReloadSound.Init(System.Values.HardPoint.Audio.ReloadSound);
            }

            if (AvCapable && system.BarrelRotationSound)
            {
                RotateEmitter = new MyEntity3DSoundEmitter(Comp.MyCube, true, 1f);
                RotateSound   = new MySoundPair();
                RotateSound.Init(System.Values.HardPoint.Audio.BarrelRotationSound);
            }

            if (AvCapable)
            {
                if (System.BarrelEffect1)
                {
                    BarrelEffects1 = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
                if (System.BarrelEffect2)
                {
                    BarrelEffects2 = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
                if (hitParticle && CanUseBeams)
                {
                    HitEffects = new MyParticleEffect[System.Values.Assignments.Barrels.Length];
                }
            }

            WeaponId           = weaponId;
            PrimaryWeaponGroup = WeaponId % 2 == 0;
            IsTurret           = System.Values.HardPoint.Ai.TurretAttached;
            TurretMode         = System.Values.HardPoint.Ai.TurretController;
            TrackTarget        = System.Values.HardPoint.Ai.TrackTargets;

            if (System.Values.HardPoint.Ai.TurretController)
            {
                AiEnabled   = true;
                AimOffset   = System.Values.HardPoint.HardWare.Offset;
                FixedOffset = System.Values.HardPoint.HardWare.FixedOffset;
            }

            HsRate         = System.Values.HardPoint.Loading.HeatSinkRate / 3;
            EnergyPriority = System.Values.HardPoint.Other.EnergyPriority;
            var toleranceInRadians = MathHelperD.ToRadians(System.Values.HardPoint.AimingTolerance);

            AimCone.ConeAngle = toleranceInRadians;
            AimingTolerance   = Math.Cos(toleranceInRadians);



            _numOfBarrels    = System.Barrels.Length;
            BeamSlot         = new uint[_numOfBarrels];
            Target           = new Target(comp.MyCube);
            NewTarget        = new Target(comp.MyCube);
            WeaponCache      = new WeaponFrameCache(System.Values.Assignments.Barrels.Length);
            TrackProjectiles = System.TrackProjectile;
        }