Esempio n. 1
0
        //  This mine collides with something after which it must explode
        public override void Explode()
        {
            MyExplosion newExplosion = MyExplosions.AddExplosion();

            if (newExplosion != null)
            {
                newExplosion.Start(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, MyExplosionTypeEnum.FLASH_EXPLOSION, new BoundingSphere(GetPosition(), m_ammoProperties.ExplosionRadius), MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadedExplosionLevel, ownerEntity: OwnerEntity, particleScale: 0.001f);
            }

            bool isBotFlashBomb = OwnerEntity as MySmallShipBot != null;

            //If ship is another player, add flash to his view
            BoundingSphere flashSphere = new BoundingSphere(GetPosition(), MyFlashBombConstants.FLASH_RADIUS);

            m_targetEntities.Clear();
            MyEntities.GetIntersectionWithSphere(ref flashSphere, this, null, true, false, ref m_targetEntities);
            foreach (MyEntity ob in m_targetEntities)
            {
                if (ob is MySmallShip)
                {
                    if (MyEnemyTargeting.CanSee(this, ob) == null)
                    {
                        Vector3 bombPosition = GetPosition();
                        if (ob == MySession.PlayerShip)
                        {
                            if (MyCamera.IsInFrustum(ref bombPosition))
                            {
                                MyFlashes.MakeFlash();
                            }
                        }
                        else if (!isBotFlashBomb && ob is MySmallShipBot)  //If this flashbomb is from bot, dont flash bots
                        {
                            //If it is bot, make him panic
                            MySmallShipBot bot = ob as MySmallShipBot;
                            bot.Flash();
                        }
                    }
                }
            }

            MarkForClose();
        }
Esempio n. 2
0
        public override bool StartShooting()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyLargeShipMissileLauncherBarrel::StartShooting");

            LastShotId = null;

            int missileShotInterval = 0;

            MyLargeShipGunBase.GetMissileAmmoParams(GetAmmoType(), ref missileShotInterval);
            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileShotInterval)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                return(false);
            }

            m_burstFinish = false;
            while (!m_burstFinish)
            {
                if (!base.StartShooting())
                {
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    return(false);
                }

                if (m_groupMask == null)
                {
                    MyPhysics.physicsSystem.GetRigidBodyModule().GetGroupMaskManager().GetGroupMask(ref m_groupMask);
                }

                MyEntity target = ((MyLargeShipGunBase)Parent).GetTarget();

                List <MyModelDummy> muzzles = GetMuzzleFlashMatrix();
                m_activeMuzzle = --m_burstToFire;

                Matrix  worldMatrix         = WorldMatrix;
                Vector3 muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix);


                if (IsControlledByPlayer())
                {
                    //target = MySession.PlayerShip.TargetEntity as MySmallShip;
                    target = MyEnemyTargeting.SwitchNextTarget(true);
                }

                if (target != null || IsControlledByPlayer())
                {
                    MySoundCue?shootingSound = GetWeaponBase().UnifiedWeaponCueGet(MySoundCuesEnum.WepMissileLaunch3d);
                    if (shootingSound == null || !shootingSound.Value.IsPlaying)
                    {
                        GetWeaponBase().UnifiedWeaponCueSet(Audio.MySoundCuesEnum.WepMissileLaunch3d,
                                                            MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero));
                        //MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero);
                    }

                    Vector3 deviateVector = GetDeviatedVector(MyAmmoConstants.GetAmmoProperties(GetAmmoType()));

                    var missile = MyMissiles.Add(GetAmmoType(), muzzleFlashPosition + 2 * WorldMatrix.Forward, WorldMatrix.Forward * 2.0f, deviateVector, Vector3.Zero, this, target, SearchingDistance, isLightWeight: true);
                    if (missile.GuidedInMultiplayer)
                    {
                        missile.EntityId = MyEntityIdentifier.AllocateId();
                        MyEntityIdentifier.AddEntityWithId(missile);
                        LastShotId = missile.EntityId;
                    }
                }


                if (m_burstToFire <= 0)
                {
                    m_burstFireTime_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_burstToFire      = m_burstFireCount;
                    m_burstFinish      = true;
                }
                if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_burstFireTime_ms) > m_burstFireTimeLoadingIntervalConst_ms)
                {
                    m_burstFinish = false;
                }

                if (!IsControlledByPlayer())
                {
                    m_burstFinish = true;
                }
            }

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Updates resource.
        /// </summary>
        public override void UpdateBeforeSimulation()
        {
            try
            {
                MyRender.GetRenderProfiler().StartProfilingBlock("MyMissile.UpdateBeforeSimulation");

                //Large ship weapons wont make bots curious
                if ((!(OwnerEntity is MyLargeShipMissileLauncherBarrel)) && MyMwcUtils.HasValidLength(this.WorldMatrix.Translation - m_previousPosition))
                {
                    MyLine line = new MyLine(this.WorldMatrix.Translation, m_previousPosition);
                    MyDangerZones.Instance.Notify(line, OwnerEntity);
                }

                if (m_isExploded)
                {
                    //  Create explosion
                    MyExplosion newExplosion = MyExplosions.AddExplosion();
                    if (newExplosion != null)
                    {
                        float radius = m_ammoProperties.ExplosionRadius;

                        // Explicitly on Marek's request (ticket 4740)
                        bool amplifyRadius = m_collidedEntity != null?MyFactions.GetFactionsRelation(m_collidedEntity.Faction, Faction) != MyFactionRelationEnum.Friend : false;

                        if (amplifyRadius)
                        {
                            radius *= 2;
                        }

                        BoundingSphere explosionSphere = new BoundingSphere(m_collisionPoint.HasValue ? m_collisionPoint.Value : GetPosition(), radius);

                        //  Call main explosion starter
                        MyExplosionInfo info = new MyExplosionInfo()
                        {
                            PlayerDamage            = m_ammoProperties.HealthDamage,
                            Damage                  = m_ammoProperties.ShipDamage,
                            EmpDamage               = m_ammoProperties.EMPDamage,
                            ExplosionType           = m_explosionType,
                            ExplosionSphere         = explosionSphere,
                            LifespanMiliseconds     = MyExplosionsConstants.EXPLOSION_LIFESPAN,
                            ExplosionForceDirection = MyExplosionForceDirection.EXPLOSION,
                            GroupMask               = Physics.GroupMask,
                            CascadeLevel            = CascadedExplosionLevel,
                            HitEntity               = m_collidedEntity,
                            ParticleScale           = 1.5f,
                            OwnerEntity             = this.OwnerEntity,
                            Direction               = WorldMatrix.Forward,
                            VoxelExplosionCenter    = explosionSphere.Center + m_ammoProperties.ExplosionRadius * WorldMatrix.Forward * 0.5f,
                            ExplosionFlags          = MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT,
                            VoxelCutoutScale        = amplifyRadius ? 0.5f : 1.0f,
                            PlaySound               = true,
                        };

                        newExplosion.Start(ref info);
                    }

                    if (m_collidedEntity != null && !m_collidedEntity.IsExploded())
                    {
                        m_collidedEntity.Physics.AddForce(
                            MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE,
                            WorldMatrix.Forward * MyMissileConstants.HIT_STRENGTH_IMPULSE,
                            GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 2,
                            MyMissileConstants.HIT_STRENGTH_IMPULSE * MyMwcUtils.GetRandomVector3Normalized());
                        m_collidedEntity.OnClose -= m_collidedEntity_OnClose;
                    }

                    MarkForClose();

                    return;
                }

                bool firstTargetting = m_elapsedMiliseconds == 0;

                base.UpdateBeforeSimulation();

                m_missileTargetUpdate += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;

                if (m_missileTargetUpdate >= MyGuidedMissileConstants.MISSILE_TARGET_UPDATE_INTERVAL_IN_MS || firstTargetting)
                {
                    m_missileTargetUpdate = 0;

                    switch (m_missileType)
                    {
                    case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection:
                    {
                        MySmallShip targetShip = m_targetEntity as MySmallShip;
                        if (targetShip != null && targetShip.IsRadarJammed())
                        {
                            m_targetEntity = null;
                        }
                    }
                    break;

                    case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection:
                    {
                        m_targetEntities.Clear();

                        Matrix proj = Matrix.CreateOrthographic(MyGuidedMissileConstants.ENGINE_GUIDED_MISSILE_RADIUS, MyGuidedMissileConstants.ENGINE_GUIDED_MISSILE_RADIUS, 0, 1000);
                        Matrix view = Matrix.CreateLookAt(GetPosition(), GetPosition() + WorldMatrix.Forward, WorldMatrix.Up);
                        m_visualFrustum.Matrix = view * proj;

                        MyEntities.GetAllIntersectionWithBoundingFrustum(ref m_visualFrustum, m_targetEntities);

                        if (m_targetEntities.Contains(m_targetEntity))
                        {
                            break;
                        }

                        MyEntity target = null;
                        float    closestToMissileDirection = float.MaxValue;

                        foreach (MyEntity entity in m_targetEntities)
                        {
                            if (CanTarget(entity))
                            {
                                MySmallShip targetShip = entity as MySmallShip;
                                if (targetShip != null)
                                {
                                    if ((targetShip.IsEngineTurnedOff()))
                                    {
                                        continue;
                                    }
                                }

                                Vector3 targetPos     = entity.GetPosition();
                                Vector3 missilePos    = this.GetPosition();
                                Vector3 missilePosEnd = this.GetPosition() + this.WorldMatrix.Forward * 10000;
                                Vector3 closestPos    = MyUtils.GetClosestPointOnLine(ref missilePos, ref missilePosEnd, ref targetPos);

                                float distance = Vector3.Distance(closestPos, targetPos);
                                if (distance < closestToMissileDirection)
                                {
                                    closestToMissileDirection = distance;
                                    target = entity;
                                }
                            }
                        }

                        UpdateTarget(target);
                    }
                    break;

                    case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection:
                    {
                        Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(MyGuidedMissileConstants.VISUAL_GUIDED_MISSILE_FOV), 1, 10, MyGuidedMissileConstants.VISUAL_GUIDED_MISSILE_RANGE);
                        m_visualFrustum.Matrix = Matrix.Invert(WorldMatrix) * projectionMatrix;

                        m_targetEntities.Clear();
                        MyEntities.GetAllIntersectionWithBoundingFrustum(ref m_visualFrustum, m_targetEntities);
                        int testsLimit = 8;

                        if (m_targetEntities.Contains(m_targetEntity))
                        {
                            break;
                        }

                        MyEntity target = null;         //looks better if missile gets "lost"

                        float closestToMissileDirection = float.MaxValue;

                        foreach (MyEntity entity in m_targetEntities)
                        {
                            if (!CanTarget(entity))
                            {
                                continue;
                            }

                            if (testsLimit-- == 0)
                            {
                                break;
                            }

                            if (MyEnemyTargeting.CanSee(this, entity) == null)
                            {
                                Vector3 targetPos     = entity.GetPosition();
                                Vector3 missilePos    = this.GetPosition();
                                Vector3 missilePosEnd = this.GetPosition() + this.WorldMatrix.Forward * 10000;
                                Vector3 closestPos    = MyUtils.GetClosestPointOnLine(ref missilePos, ref missilePosEnd, ref targetPos);

                                float distance = Vector3.Distance(closestPos, targetPos);
                                if (distance < closestToMissileDirection)
                                {
                                    closestToMissileDirection = distance;
                                    target = entity;
                                }
                            }
                        }

                        UpdateTarget(target);
                    }
                    break;
                    }
                }

                if ((m_initTime - m_elapsedMiliseconds) > 0)
                {   //simulating missile launch and engine ignition
                    MyEntity owner = OwnerEntity;
                    if (owner != null)
                    {
                        Vector3 transformedInitDir = Vector3.TransformNormal(m_initDir, owner.WorldMatrix); //
                        Vector3 initialVelocity    = Vector3.Zero;
                        if (owner.Physics != null)
                        {
                            initialVelocity = owner.Physics.LinearVelocity;
                        }
                        Physics.LinearVelocity = transformedInitDir * m_ammoProperties.InitialSpeed + initialVelocity;
                    }
                }
                else
                {
                    //  This will help blend "initial velocity" and "thrust velocity" so at the beginning missile is powered by initiatal velocity only, but later
                    float velocityBlend = MathHelper.Clamp((float)(m_elapsedMiliseconds - m_initTime) / m_blendVelocities, 0, 1);

                    if (velocityBlend == 1.0f)
                    {
                        m_actualSpeed = m_ammoProperties.DesiredSpeed;
                    }
                    else
                    {
                        float    initialSpeed = 0.0f;
                        MyEntity owner        = OwnerEntity;
                        if (owner != null)
                        {
                            if (owner.Physics != null)
                            {
                                initialSpeed = owner.Physics.LinearVelocity.Length();
                            }
                        }

                        m_actualSpeed = velocityBlend * m_ammoProperties.DesiredSpeed + ((1.0f - velocityBlend) * (m_ammoProperties.InitialSpeed + initialSpeed));

                        if (m_missileType != MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic && m_smokeEffect == null)
                        {
                            // if (MyCamera.GetDistanceWithFOV(GetPosition()) < 150)
                            {
                                /*
                                 * MyParticleEffect startEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_MissileStart);
                                 * startEffect.WorldMatrix = WorldMatrix;
                                 */
                                m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Missile);
                                m_smokeEffect.WorldMatrix = WorldMatrix;
                                m_smokeEffect.AutoDelete  = false;
                            }
                        }
                    }

                    m_desiredVelocity = GetDesiredVelocity(m_targetEntity);

                    Physics.LinearVelocity = m_desiredVelocity * m_actualSpeed * 1.0f;
                }

                Physics.AngularVelocity = Vector3.Zero;

                if ((m_elapsedMiliseconds > m_missileTimeout) || (Vector3.Distance(GetPosition(), m_origin) >= m_maxTrajectory))
                {
                    Explode();
                    return;
                }


                if (m_smokeEffect != null)
                {
                    Matrix smokeMatrix = Matrix.CreateWorld(WorldMatrix.Translation - 0.5f * WorldMatrix.Forward, WorldMatrix.Forward, WorldMatrix.Up);
                    m_smokeEffect.WorldMatrix = smokeMatrix;
                }

                if (m_targetEntity != null)
                {
                    if (m_targetEntity.Physics != null)
                    {
                        m_targetVelocity = m_targetEntity.Physics.LinearVelocity;
                    }
                    else
                    {
                        m_targetVelocity = Vector3.Zero;
                    }
                }
            }
            finally
            {
                MyRender.GetRenderProfiler().EndProfilingBlock();
            }
        }