Beispiel #1
0
 public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
 {
     base.Init(objectBuilder, cubeGrid);
     if (CubeGrid.GridSizeEnum == MyCubeSize.Large)
     {
         IDLE_SOUND.Init("ToolLrgGrindIdle");
         METAL_SOUND.Init("ToolLrgGrindMetal");
     }
     m_rotationSpeed = 0.0f;
 }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            if (CubeGrid.GridSizeEnum == MyCubeSize.Large)
            {
                IDLE_SOUND.Init("ToolLrgGrindIdle");
                METAL_SOUND.Init("ToolLrgGrindMetal");
            }
            m_rotationSpeed = 0.0f;

            HeatUpFrames = MyShipGrinderConstants.GRINDER_HEATUP_FRAMES;
        }
Beispiel #3
0
 void SelectionChanged()
 {
     if (!MySandboxGame.IsDedicated)
     {
         m_soundPair.Init(m_cueId);
         var soundData = MyAudio.Static.GetCue(m_cueId);
         if (soundData != null)
         {
             IsLoopable = soundData.Loopable;
         }
     }
     m_loopableTimeSlider.UpdateVisual();
     m_playButton.UpdateVisual();
     m_stopButton.UpdateVisual();
 }
        internal void SetupSounds(double distanceFromCameraSqr)
        {
            FiringSoundState = System.FiringSound;

            if (!AmmoDef.Const.IsBeamWeapon && AmmoDef.Const.AmmoTravelSound)
            {
                HasTravelSound = true;
                TravelSound.Init(AmmoDef.AmmoAudio.TravelSound, false);
            }
            else
            {
                HasTravelSound = false;
            }

            if (AmmoDef.Const.HitSound)
            {
                var hitSoundChance = AmmoDef.AmmoAudio.HitPlayChance;
                HitSoundActive = (hitSoundChance >= 1 || hitSoundChance >= MyUtils.GetRandomDouble(0.0f, 1f));
                if (HitSoundActive)
                {
                    HitSound.Init(AmmoDef.AmmoAudio.HitSound, false);
                }
            }

            if (!IsShrapnel && FiringSoundState == WeaponSystem.FiringSoundState.PerShot && distanceFromCameraSqr < System.FiringSoundDistSqr)
            {
                StartSoundActived = true;
                FireSound.Init(System.Values.HardPoint.Audio.FiringSound, false);
                FireEmitter.SetPosition(Origin);
                FireEmitter.Entity = FiringWeapon.MyCube;
            }

            if (StartSoundActived)
            {
                StartSoundActived = false;
                FireEmitter.PlaySound(FireSound, true);
            }
        }
Beispiel #5
0
        public void SelectSound(MyStringId cueId, bool sync)
        {
            if (sync)
            {
                SyncObject.SendSelectSoundRequest(cueId);
            }
            else
            {
                CueId = cueId;

                if (!MySandboxGame.IsDedicated)
                {
                    m_soundPair.Init(cueId);
                    var soundData = MyAudio.Static.GetCue(cueId);
                    if (soundData != null)
                    {
                        IsLoopable = soundData.Loopable;
                    }
                }

                RaisePropertiesChanged();
            }
        }
Beispiel #6
0
        public void SelectSound(MyCueId cueId, bool sync)
        {
            if (sync)
            {
                SyncObject.SendSelectSoundRequest(cueId);
            }
            else
            {
                CueId = cueId;

                if (!MySandboxGame.IsDedicated)
                {
                    m_soundPair.Init(cueId);
                    var soundData = MyAudio.Static.GetCue(cueId);
                    if (soundData != null)
                    {
                        IsLoopable = soundData.Loopable;
                    }
                }
                m_loopableTimeSlider.UpdateVisual();
                m_playButton.UpdateVisual();
                m_stopButton.UpdateVisual();
            }
        }
Beispiel #7
0
        private PlatformState GetParts(WeaponComponent comp)
        {
            for (int i = 0; i < Structure.MuzzlePartNames.Length; i++)
            {
                _orderToCreate.Add(i);
            }

            if (Structure.PrimaryWeapon > 0)
            {
                var tmpPos = _orderToCreate[Structure.PrimaryWeapon];
                _orderToCreate[tmpPos] = _orderToCreate[0];
                _orderToCreate[0]      = tmpPos;
            }

            Parts.CheckSubparts();

            foreach (var i in _orderToCreate)
            {
                var          muzzlePartHash = Structure.MuzzlePartNames[i];
                WeaponSystem system;
                if (!Structure.WeaponSystems.TryGetValue(muzzlePartHash, out system))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid weapon system, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                var muzzlePartName = muzzlePartHash.String != "Designator" ? muzzlePartHash.String : system.ElevationPartName.String;

                MyEntity muzzlePartEntity;
                if (!Parts.NameToEntity.TryGetValue(muzzlePartName, out muzzlePartEntity))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid barrelPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }
                foreach (var part in Parts.NameToEntity)
                {
                    part.Value.OnClose += comp.SubpartClosed;
                    break;
                }

                //compatability with old configs of converted turrets
                var azimuthPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.AzimuthPartName.String) ? "MissileTurretBase1" : system.AzimuthPartName.String : system.AzimuthPartName.String;

                var elevationPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.ElevationPartName.String) ? "MissileTurretBarrels" : system.ElevationPartName.String : system.ElevationPartName.String;

                MyEntity azimuthPart = null;
                if (!Parts.NameToEntity.TryGetValue(azimuthPartName, out azimuthPart))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Weapon: {system.WeaponName} Invalid azimuthPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                MyEntity elevationPart = null;
                if (!Parts.NameToEntity.TryGetValue(elevationPartName, out elevationPart))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid elevationPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                azimuthPart.NeedsWorldMatrix   = true;
                elevationPart.NeedsWorldMatrix = true;

                var weapon = Weapons[i] = new Weapon(muzzlePartEntity, system, i, comp, Parts, elevationPart, azimuthPart, azimuthPartName, elevationPartName);

                SetupUi(weapon);

                if (!comp.Debug && weapon.System.Values.HardPoint.Other.Debug)
                {
                    comp.Debug = true;
                }

                if (weapon.System.Values.HardPoint.Ai.TurretController)
                {
                    if (weapon.System.Values.HardPoint.Ai.PrimaryTracking && comp.TrackingWeapon == null)
                    {
                        comp.TrackingWeapon = weapon;
                    }

                    if (weapon.AvCapable && weapon.System.HardPointRotationSound)
                    {
                        RotationSound.Init(weapon.System.Values.HardPoint.Audio.HardPointRotationSound, false);
                    }
                }
            }
            _orderToCreate.Clear();

            CompileTurret(comp);

            State = PlatformState.Inited;

            return(State);
        }
        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;
        }
        private PlatformState GetParts(WeaponComponent comp)
        {
            Parts.CheckSubparts();
            for (int i = 0; i < Structure.MuzzlePartNames.Length; i++)
            {
                var muzzlePartHash = Structure.MuzzlePartNames[i];
                var barrelCount    = Structure.WeaponSystems[muzzlePartHash].Barrels.Length;

                WeaponSystem system;
                if (!Structure.WeaponSystems.TryGetValue(muzzlePartHash, out system))
                {
                    Log.Line($"Invalid weapon system, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                var wepAnimationSet = comp.Session.CreateWeaponAnimationSet(system, Parts);

                var muzzlePartName = muzzlePartHash.String != "Designator" ? muzzlePartHash.String : system.ElevationPartName.String;


                MyEntity muzzlePartEntity;
                if (!Parts.NameToEntity.TryGetValue(muzzlePartName, out muzzlePartEntity))
                {
                    Log.Line($"Invalid barrelPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }
                foreach (var part in Parts.NameToEntity)
                {
                    part.Value.OnClose += comp.SubpartClosed;
                    break;
                }

                //compatability with old configs of converted turrets
                var azimuthPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.AzimuthPartName.String) ? "MissileTurretBase1" : system.AzimuthPartName.String : system.AzimuthPartName.String;

                var elevationPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.ElevationPartName.String) ? "MissileTurretBarrels" : system.ElevationPartName.String : system.ElevationPartName.String;

                MyEntity azimuthPart = null;
                if (!Parts.NameToEntity.TryGetValue(azimuthPartName, out azimuthPart))
                {
                    Log.Line($"Invalid azimuthPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                MyEntity elevationPart = null;
                if (!Parts.NameToEntity.TryGetValue(elevationPartName, out elevationPart))
                {
                    Log.Line($"Invalid elevationPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                foreach (var triggerSet in wepAnimationSet)
                {
                    for (int j = 0; j < triggerSet.Value.Length; j++)
                    {
                        comp.AllAnimations.Add(triggerSet.Value[j]);
                    }
                }

                Weapons[i] = new Weapon(muzzlePartEntity, system, i, comp, wepAnimationSet)
                {
                    Muzzles     = new Muzzle[barrelCount],
                    Dummies     = new Dummy[barrelCount],
                    AzimuthPart = new PartInfo {
                        Entity = azimuthPart
                    },
                    ElevationPart = new PartInfo {
                        Entity = elevationPart
                    },
                    AzimuthOnBase = azimuthPart.Parent == comp.MyCube,
                    AiOnlyWeapon  = comp.BaseType != Turret || (azimuthPartName != "MissileTurretBase1" && elevationPartName != "MissileTurretBarrels" && azimuthPartName != "InteriorTurretBase1" && elevationPartName != "InteriorTurretBase2" && azimuthPartName != "GatlingTurretBase1" && elevationPartName != "GatlingTurretBase2")
                };

                var weapon = Weapons[i];
                SetupUi(weapon);

                if (!comp.Debug && weapon.System.Values.HardPoint.Other.Debug)
                {
                    comp.Debug = true;
                }

                if (weapon.System.Values.HardPoint.Ai.TurretController)
                {
                    if (weapon.System.Values.HardPoint.Ai.PrimaryTracking && comp.TrackingWeapon == null)
                    {
                        comp.TrackingWeapon = weapon;
                    }

                    if (weapon.AvCapable && weapon.System.HardPointRotationSound)
                    {
                        RotationSound.Init(weapon.System.Values.HardPoint.Audio.HardPointRotationSound, false);
                    }
                }
            }
            CompileTurret(comp);

            State = PlatformState.Inited;

            return(State);
        }