Exemplo n.º 1
0
 private static MyObjectBuilder_CubeBlock ProcessLargeTurretBase(MyObjectBuilder_CubeBlock block, Options options, MyCubeSize size)
 {         // LargeTurretBase
     try
     {
         MyLargeTurretBaseDefinition myLargeTurret      = (MyLargeTurretBaseDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetId());
         List <BlockSideEnum>        mountPoints        = myLargeTurret.MountPoints.Select(myMountPoint => myMountPoint.GetObjectBuilder(myMountPoint.Normal).Side).ToList();
         List <WeaponInformation>    replacementOptions = LargeGridWeaponTurretBases.FindAll(x =>
                                                                                             //x.ModName != "Vanilla" &&
                                                                                             x.SubtypeId != block.SubtypeId &&
                                                                                             x.MountPoints.Intersect(mountPoints).Any() &&
                                                                                             x.SizeX == myLargeTurret.Size.X &&
                                                                                             x.SizeY == myLargeTurret.Size.Y &&
                                                                                             x.SizeZ <= myLargeTurret.Size.Z// + 1
                                                                                             );
         if (replacementOptions.Count == 0)
         {
             return(block);
         }
         block = CreateReplacementTurretBase(replacementOptions[Core.Random.Next(0, replacementOptions.Count)], block, size, myLargeTurret);
     }
     catch (Exception e)
     {
         Core.GeneralLog.WriteToLog("WeaponSwapper-ProcessLargeTurretBase", $"Exception!\t{e}");
     }
     return(block);
 }
Exemplo n.º 2
0
        public static WeaponDefinition CreateFromKeenDefinition(MyWeaponBlockDefinition b, MyWeaponDefinition w)
        {
            if (b is MyLargeTurretBaseDefinition)
            {
                MyLargeTurretBaseDefinition lb = b as MyLargeTurretBaseDefinition;
                return(new WeaponDefinition {
                    Enabled = true,
                    SubtypeId = w.Id.SubtypeId.String,
                    DeviateShotAngle = w.DeviateShotAngle,
                    ReloadTime = w.ReloadTime,
                    ReleaseTimeAfterFire = w.ReleaseTimeAfterFire,
                    //PhysicalMaterial = w.PhysicalMaterial,
                    MuzzleFlashLifeSpan = w.MuzzleFlashLifeSpan,
                    MuzzleFlashSpriteName = "Muzzle_Flash_Large",
                    NoAmmoSound = w.NoAmmoSound.SoundId.ToString(),
                    ReloadSound = w.ReloadSound.SoundId.ToString(),
                    SecondarySound = w.SecondarySound.SoundId.ToString(),
                    NoAmmoSoundPair = w.NoAmmoSound,
                    ReloadSoundPair = w.ReloadSound,
                    SecondarySoundPair = w.SecondarySound,
                    AmmoData = WeaponAmmoDefinition.CreateFromKeenDefinition(w.WeaponAmmoDatas[0]),

                    AiEnabled = lb.AiEnabled,
                    MinElevationDegrees = lb.MinElevationDegrees,
                    MaxElevationDegrees = lb.MaxElevationDegrees,
                    MinAzimuthDegrees = lb.MinAzimuthDegrees,
                    MaxAzimuthDegrees = lb.MaxAzimuthDegrees,
                    IdleRotation = lb.IdleRotation,
                    MaxRangeMeters = lb.MaxRangeMeters,
                    RotationSpeed = lb.RotationSpeed,
                    ElevationSpeed = lb.ElevationSpeed,
                    MinFov = lb.MinFov,
                    MaxFov = lb.MaxFov,
                    AmmoPullAmount = lb.AmmoPullAmount,
                    InventoryFillFactorMin = lb.InventoryFillFactorMin,
                });
            }
            else
            {
                return(new WeaponDefinition {
                    Enabled = true,
                    SubtypeId = w.Id.SubtypeId.String,
                    DeviateShotAngle = w.DeviateShotAngle,
                    ReloadTime = w.ReloadTime,
                    ReleaseTimeAfterFire = w.ReleaseTimeAfterFire,
                    //PhysicalMaterial = w.PhysicalMaterial,
                    MuzzleFlashLifeSpan = w.MuzzleFlashLifeSpan,
                    MuzzleFlashSpriteName = "Muzzle_Flash_Large",
                    NoAmmoSound = w.NoAmmoSound.SoundId.ToString(),
                    ReloadSound = w.ReloadSound.SoundId.ToString(),
                    SecondarySound = w.SecondarySound.SoundId.ToString(),
                    NoAmmoSoundPair = w.NoAmmoSound,
                    ReloadSoundPair = w.ReloadSound,
                    SecondarySoundPair = w.SecondarySound,
                    AmmoData = WeaponAmmoDefinition.CreateFromKeenDefinition(w.WeaponAmmoDatas[0]),
                    InventoryFillFactorMin = b.InventoryFillFactorMin,
                });
            }
        }
Exemplo n.º 3
0
 public WeaponInformation(List <BlockSideEnum> mountPoints, MyCubeSize myCubeSize, int sizeX, int sizeY, int sizeZ,
                          MyStringHash subtypeId, string subtypeName, MyObjectBuilderType typeId, string modName, string id, MyWeaponBlockDefinition myWeaponBlock = null, MyLargeTurretBaseDefinition myLargeTurret = null)
 {
     MountPoints   = mountPoints;
     MyCubeSize    = myCubeSize;
     SizeX         = sizeX;
     SizeY         = sizeY;
     SizeZ         = sizeZ;
     SubtypeId     = subtypeId;
     SubtypeName   = subtypeName;
     TypeId        = typeId;
     ModName       = modName;
     Id            = id;
     MyWeaponBlock = myWeaponBlock;
     MyLargeTurret = myLargeTurret;
 }
        //True if the turret can aim at its target.
        private static bool isInFiringArk(SmartTurret turret, Vector3D targetLocation)
        {
            IMyLargeTurretBase turretBase = turret.Entity as IMyLargeTurretBase;

            if (turretBase == null)
            {
                return(false);
            }

            MyLargeTurretBaseDefinition turretDefinition = (MyDefinitionManager.Static.GetCubeBlockDefinition(turretBase.BlockDefinition) as MyLargeTurretBaseDefinition);
            int azimuthMin   = turretDefinition.MinAzimuthDegrees;
            int azimuthMax   = turretDefinition.MaxAzimuthDegrees;
            int elevationMin = turretDefinition.MinElevationDegrees;
            int elevationMax = turretDefinition.MaxElevationDegrees;

            //Get turrets world rotation.
            Matrix3x3 turretRotation = turretBase.WorldMatrix.Rotation;

            //Make a Quaternion from the world rotation and invert it so we can rotate to ther way.
            Quaternion offset = Quaternion.CreateFromRotationMatrix(turretBase.WorldMatrix);

            offset.Conjugate();
            offset.Normalize();

            //Find the direction of the target from the turret.
            Vector3 dirToTarget = targetLocation - turretBase.GetPosition();

            dirToTarget.Normalize();

            //Rotate the dirrection of the target by the Quaternion to cancel out the turrets world rotation.
            dirToTarget = Vector3.Transform(dirToTarget, offset);

            //The targets direction is now relative to the world so we can get Azimuth and Elevation.
            float azimuth;
            float elevation;

            Vector3.GetAzimuthAndElevation(dirToTarget, out azimuth, out elevation);

            //Convert Azimuth and Elevation to deg for comparason with the turrets elevation and azimuth limits.
            azimuth   = (float)(180 / Math.PI * azimuth);
            elevation = (float)(180 / Math.PI * elevation);

            return(azimuth >= azimuthMin && azimuth <= azimuthMax && elevation >= elevationMin && elevation <= elevationMax);
        }
Exemplo n.º 5
0
        private void DpsAndHeatInit(Weapon weapon, MyLargeTurretBaseDefinition ob, out double maxTrajectory)
        {
            MaxHeat += weapon.System.MaxHeat;

            weapon.RateOfFire     = (int)(weapon.System.RateOfFire * Set.Value.RofModifier);
            weapon.BarrelSpinRate = (int)(weapon.System.BarrelSpinRate * Set.Value.RofModifier);
            HeatSinkRate         += weapon.HsRate;

            if (weapon.System.HasBarrelRotation)
            {
                weapon.UpdateBarrelRotation();
            }

            if (weapon.RateOfFire < 1)
            {
                weapon.RateOfFire = 1;
            }

            weapon.SetWeaponDps();

            if (!weapon.System.DesignatorWeapon)
            {
                PeakDps      += weapon.ActiveAmmoDef.AmmoDef.Const.PeakDps;
                EffectiveDps += weapon.ActiveAmmoDef.AmmoDef.Const.EffectiveDps;
                ShotsPerSec  += weapon.ActiveAmmoDef.AmmoDef.Const.ShotsPerSec;
                BaseDps      += weapon.ActiveAmmoDef.AmmoDef.Const.BaseDps;
                AreaDps      += weapon.ActiveAmmoDef.AmmoDef.Const.AreaDps;
                DetDps       += weapon.ActiveAmmoDef.AmmoDef.Const.DetDps;
            }

            maxTrajectory = 0;
            if (weapon.ActiveAmmoDef.AmmoDef.Const.MaxTrajectory > maxTrajectory)
            {
                maxTrajectory = weapon.ActiveAmmoDef.AmmoDef.Const.MaxTrajectory;
            }

            if (weapon.TrackProjectiles)
            {
                Ai.PointDefense = true;
            }
        }
Exemplo n.º 6
0
 private static void ProcessLargeTurretBase(MyDefinitionBase myDefinition)
 {
     try
     {
         if (WeaponIgnoreList.Contains(myDefinition.Id.SubtypeId) || !myDefinition.Public)
         {
             return;
         }
         //MyCubeBlockDefinition myCubeBlock = MyDefinitionManager.Static.GetCubeBlockDefinition(myDefinition.Id);
         MyLargeTurretBaseDefinition myLargeTurret       = (MyLargeTurretBaseDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(myDefinition.Id);
         List <BlockSideEnum>        mountPoints         = myLargeTurret.MountPoints.Select(myMountPoint => myMountPoint.GetObjectBuilder(myMountPoint.Normal).Side).ToList();
         WeaponInformation           myWeaponInformation = new WeaponInformation(
             mountPoints,
             myLargeTurret.CubeSize,
             myLargeTurret.Size.X,
             myLargeTurret.Size.Y,
             myLargeTurret.Size.Z,
             myDefinition.Id.SubtypeId,
             myDefinition.Id.SubtypeName,
             myDefinition.Id.TypeId,
             myDefinition.Context?.ModName ?? "Vanilla",
             myDefinition.Id.ToString(),
             null, myLargeTurret
             );
         if (myLargeTurret.CubeSize == MyCubeSize.Large)
         {
             LargeGridWeaponTurretBases.Add(myWeaponInformation);
         }
         else
         {
             SmallGridWeaponTurretBases.Add(myWeaponInformation);
         }
         //Core.GeneralLog.WriteToLog("ProcessLargeTurretBase", myWeaponInformation.ToString());
     }
     catch (Exception e)
     {
         Core.GeneralLog.WriteToLog("ProcessLargeTurretBase", $"Exception! {e}");
     }
 }
Exemplo n.º 7
0
        public Turret(IMyCubeBlock block)
            : base(block)
        {
            // definition limits
            MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition;

            if (definition == null)
            {
                throw new NullReferenceException("definition");
            }

            minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f);
            maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees);
            minAzimuth   = MathHelper.ToRadians(definition.MinAzimuthDegrees);
            maxAzimuth   = MathHelper.ToRadians(definition.MaxAzimuthDegrees);

            Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360;

            // speeds are in rads per ms (from S.E. source)
            speedElevation = definition.ElevationSpeed * 100f / 6f;
            speedAzimuth   = definition.RotationSpeed * 100f / 6f;

            setElevation = myTurret.Elevation;
            setAzimuth   = myTurret.Azimuth;

            // subparts for turrets form a chain
            var subparts = ((MyCubeBlock)CubeBlock).Subparts;

            while (subparts.Count != 0)
            {
                m_barrel = subparts.FirstPair().Value;
                subparts = m_barrel.Subparts;
            }

            //Log.DebugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()");
            //Log.DebugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()");
        }
Exemplo n.º 8
0
        public TurretBase(IMyCubeBlock CubeBlock)
        {
            try
            {
                if (!Settings.boolSettings[Settings.BoolSetName.bAllowTurretControl])
                {
                    return;
                }

                this.myCubeBlock  = CubeBlock;
                this.myTerminal   = CubeBlock as IMyTerminalBlock;
                this.myTurretBase = CubeBlock as Ingame.IMyLargeTurretBase;
                this.myLogger     = new Logger(myCubeBlock.CubeGrid.DisplayName, "TurretBase", myCubeBlock.DisplayNameText);

                this.myCubeBlock.throwIfNull_variable("myCubeBlock");
                this.myTerminal.throwIfNull_variable("myTerminal");
                this.myTurretBase.throwIfNull_variable("myTurretBase");

                myLogger.debugLog("created for: " + myCubeBlock.DisplayNameText, "DelayedInit()");
                //EnforcedUpdate = Sandbox.Common.MyEntityUpdateEnum.EACH_FRAME; // want as many opportunities to lock main thread as possible
                if (!(myTurretBase.DisplayNameText.Contains("[") || myTurretBase.DisplayNameText.Contains("]")))
                {
                    if (myTurretBase.OwnerId.Is_ID_NPC())
                    {
                        myTurretBase.SetCustomName(myTurretBase.DisplayNameText + " " + Settings.stringSettings[Settings.StringSetName.sSmartTurretDefaultNPC]);
                    }
                    else
                    {
                        myTurretBase.SetCustomName(myTurretBase.DisplayNameText + " " + Settings.stringSettings[Settings.StringSetName.sSmartTurretDefaultPlayer]);
                    }
                }

                TurretBase_CustomNameChanged(null);
                myTerminal.CustomNameChanged += TurretBase_CustomNameChanged;
                myTerminal.OwnershipChanged  += myTerminal_OwnershipChanged;

                // definition limits
                MyLargeTurretBaseDefinition definition = MyDefinitionManager.Static.GetCubeBlockDefinition(myCubeBlock.getSlimObjectBuilder()) as MyLargeTurretBaseDefinition;

                definition.throwIfNull_variable("definition");

                minElevation = (float)Math.Max(definition.MinElevationDegrees / 180 * Math.PI, -0.6);                 // -0.6 was determined empirically
                maxElevation = (float)Math.Min(definition.MaxElevationDegrees / 180 * Math.PI, Math.PI / 2);
                minAzimuth   = (float)(definition.MinAzimuthDegrees / 180 * Math.PI);
                maxAzimuth   = (float)(definition.MaxAzimuthDegrees / 180 * Math.PI);

                myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "DelayedInit()");
                myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "DelayedInit()");

                CubeBlock.OnClosing += Close;
            }
            catch (Exception e)
            {
                if (myCubeBlock == null)
                {
                    myLogger.log("failed to initialize myCubeBlock == null, Exception:" + e, "DelayedInit()", Logger.severity.ERROR);
                }
                else
                {
                    myLogger.log("failed to initialize for " + myCubeBlock.DisplayNameText + ", Exception:" + e, "DelayedInit()", Logger.severity.WARNING);
                }
                Close(null);
                return;
            }
        }
Exemplo n.º 9
0
        private static MyObjectBuilder_CubeBlock CreateReplacementTurretBase(WeaponInformation weaponInformation, MyObjectBuilder_CubeBlock block, MyCubeSize size, MyLargeTurretBaseDefinition myLargeTurret)
        {
            MyObjectBuilder_CubeBlock myNewWeapon = MyObjectBuilderSerializer.CreateNewObject(
                weaponInformation.TypeId, weaponInformation.SubtypeName) as MyObjectBuilder_CubeBlock;

            if (myNewWeapon == null)
            {
                Core.GeneralLog.WriteToLog("CreateReplacementTurretBase", $"Replacement came up null...");
                return(block);
            }
            ((MyObjectBuilder_TurretBase)myNewWeapon).EntityId         = block.EntityId;
            ((MyObjectBuilder_TurretBase)myNewWeapon).SubtypeName      = weaponInformation.SubtypeName;
            ((MyObjectBuilder_TurretBase)myNewWeapon).IntegrityPercent = block.IntegrityPercent;
            ((MyObjectBuilder_TurretBase)myNewWeapon).BuildPercent     = block.BuildPercent;
            ((MyObjectBuilder_TurretBase)myNewWeapon).Range            = 2500;
            ((MyObjectBuilder_TurretBase)myNewWeapon).Orientation      = block.Orientation;
            ((MyObjectBuilder_TurretBase)myNewWeapon).BlockOrientation = block.BlockOrientation;
            ((MyObjectBuilder_TurretBase)myNewWeapon).ColorMaskHSV     = block.ColorMaskHSV;
            ((MyObjectBuilder_TurretBase)myNewWeapon).Min                = block.Min;
            ((MyObjectBuilder_TurretBase)myNewWeapon).ShowInTerminal     = true;
            ((MyObjectBuilder_TurretBase)myNewWeapon).ShowOnHUD          = false;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetCharacters   = ((MyObjectBuilder_TurretBase)block).TargetCharacters;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetLargeGrids   = ((MyObjectBuilder_TurretBase)block).TargetLargeGrids;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetMeteors      = ((MyObjectBuilder_TurretBase)block).TargetMeteors;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetMissiles     = ((MyObjectBuilder_TurretBase)block).TargetMissiles;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetNeutrals     = ((MyObjectBuilder_TurretBase)block).TargetNeutrals;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetSmallGrids   = ((MyObjectBuilder_TurretBase)block).TargetSmallGrids;
            ((MyObjectBuilder_TurretBase)myNewWeapon).TargetStations     = ((MyObjectBuilder_TurretBase)block).TargetStations;
            ((MyObjectBuilder_TurretBase)myNewWeapon).EnableIdleRotation = ((MyObjectBuilder_TurretBase)block).EnableIdleRotation;
            ((MyObjectBuilder_TurretBase)myNewWeapon).Enabled            = ((MyObjectBuilder_TurretBase)block).Enabled;
            ((MyObjectBuilder_TurretBase)myNewWeapon).ComponentContainer = new MyObjectBuilder_ComponentContainer()
            {
                Components = new List <MyObjectBuilder_ComponentContainer.ComponentData>()
                {
                    new MyObjectBuilder_ComponentContainer.ComponentData()
                    {
                        TypeId    = "MyInventoryBase",
                        Component = new MyObjectBuilder_Inventory()
                        {
                            InventoryFlags      = MyInventoryFlags.CanReceive,
                            RemoveEntityOnEmpty = false,
                        }
                    }
                }
            };
            return(myNewWeapon);
        }
Exemplo n.º 10
0
        private void DpsAndHeatInit(Weapon weapon, MyLargeTurretBaseDefinition ob, out double maxTrajectory)
        {
            MaxHeat += weapon.System.MaxHeat;

            weapon.RateOfFire     = (int)(weapon.System.RateOfFire * Set.Value.RofModifier);
            weapon.BarrelSpinRate = (int)(weapon.System.BarrelSpinRate * Set.Value.RofModifier);
            HeatSinkRate         += weapon.HsRate;

            if (weapon.System.HasBarrelRotation)
            {
                weapon.UpdateBarrelRotation();
            }

            if (weapon.RateOfFire < 1)
            {
                weapon.RateOfFire = 1;
            }

            weapon.SetWeaponDps();

            if (!weapon.System.DesignatorWeapon)
            {
                PeakDps     += weapon.ActiveAmmoDef.AmmoDef.Const.PeakDps;
                ShotsPerSec += weapon.ActiveAmmoDef.AmmoDef.Const.ShotsPerSec;
                BaseDps     += weapon.ActiveAmmoDef.AmmoDef.Const.BaseDps;
                AreaDps     += weapon.ActiveAmmoDef.AmmoDef.Const.AreaDps;
                DetDps      += weapon.ActiveAmmoDef.AmmoDef.Const.DetDps;
            }

            maxTrajectory = 0;
            if (weapon.ActiveAmmoDef.AmmoDef.Const.MaxTrajectory > maxTrajectory)
            {
                maxTrajectory = weapon.ActiveAmmoDef.AmmoDef.Const.MaxTrajectory;
            }

            if (weapon.TrackProjectiles)
            {
                Ai.PointDefense = true;
            }

            if (!weapon.Comp.Session.IsClient)
            {
                weapon.State.Sync.Reloading = false;
            }

            //if (!weapon.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo && !weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge)
            //Session.ComputeStorage(weapon);

            //Log.Line($"MustCharge: {weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge} CurrentAmmo: {weapon.State.Sync.CurrentAmmo} MagSize: {weapon.ActiveAmmoDef.AmmoDef.Const.MagazineSize} hybrid: {weapon.ActiveAmmoDef.AmmoDef.Const.IsHybrid} EnergyAmmo: {weapon.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo}");

            if ((!Session.IsClient || !Session.MpActive) && weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge && weapon.State.Sync.CurrentAmmo != weapon.ActiveAmmoDef.AmmoDef.Const.MagazineSize)
            {
                if (weapon.State.Sync.CurrentCharge > 0)
                {
                    State.Value.CurrentCharge -= weapon.State.Sync.CurrentCharge;
                }

                weapon.State.Sync.CurrentCharge = 0;
                weapon.State.Sync.CurrentAmmo   = 0;
                weapon.State.Sync.Reloading     = false;

                if (!Session.GameLoaded)
                {
                    Session.ChargingWeaponsToReload.Enqueue(weapon);
                }
                else
                {
                    Session.ComputeStorage(weapon);
                }
            }
            else if (!weapon.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo && weapon.State.Sync.CurrentAmmo == 0)
            {
                weapon.EventTriggerStateChanged(EventTriggers.EmptyOnGameLoad, true);
                Session.ComputeStorage(weapon);
            }
        }