Exemplo n.º 1
0
        private Vector3?DetectDecoys()
        {
            var bBox = new BoundingBox(GetPosition() - new Vector3(.5f * MyDecoyFlareConstants.DECOY_ATTRACT_RADIUS),
                                       GetPosition() + new Vector3(.5f * MyDecoyFlareConstants.DECOY_ATTRACT_RADIUS));
            Vector3?result   = null;
            var     elements = MyEntities.GetElementsInBox(ref bBox);

            foreach (var rbElement in elements)
            {
                var rigidBody = rbElement.GetRigidBody();
                if (rigidBody == null)
                {
                    continue;
                }

                var decoy = ((MyPhysicsBody)rigidBody.m_UserData).Entity as MyDecoyFlare;
                if (decoy == null)
                {
                    continue;
                }

                //if (MyFactions.GetFactionsRelation(this.OwnerEntity.Faction, decoy.OwnerEntity.Faction) != MyFactionRelationEnum.Enemy)
                //    continue; // only attracts enemy missiles

                var decoyDistanceSquared = (decoy.GetPosition() - this.GetPosition()).LengthSquared();
                if (decoyDistanceSquared < MyDecoyFlareConstants.DECOY_ATTRACT_RADIUS * MyDecoyFlareConstants.DECOY_ATTRACT_RADIUS)
                {
                    result = decoy.GetPosition();
                    break;
                }
            }
            elements.Clear();
            return(result);
        }
        /// <summary>
        /// Writes all surrounding blocks around the given one with the given size.
        /// </summary>
        private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks)
        {
            outBlocks.Clear();

            BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);

            if (block.FatBlock != null)
            {
                aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox;
                aabb.Translate(block.Position * block.CubeGrid.GridSize);
            }

            aabb = aabb.Transform(block.CubeGrid.WorldMatrix);
            aabb.Inflate(0.125);

            List <MyEntity> boxOverlapList = new List <MyEntity>();

            MyEntities.GetElementsInBox(ref aabb, boxOverlapList);

            for (int i = 0; i < boxOverlapList.Count; i++)
            {
                var otherBlock = boxOverlapList[i] as MyCubeBlock;
                if (otherBlock != null && otherBlock.CubeGrid.IsStatic && otherBlock.CubeGrid.EnableSmallToLargeConnections && otherBlock.SlimBlock != block && otherBlock.CubeGrid != block.CubeGrid &&
                    otherBlock.CubeGrid.GridSizeEnum == cubeSizeEnum && !(otherBlock is MyCompoundCubeBlock) && !(otherBlock is MyFracturedBlock))
                {
                    outBlocks.Add(otherBlock);
                }
            }

            boxOverlapList.Clear();
        }
Exemplo n.º 3
0
        private static void CheckNeighbourStaticGridsAfterVoxelChanged(MyVoxelBase.OperationType type, MyVoxelBase voxelMap, MyShape shape)
        {
            // Check static grids around (possible change to dynamic)
            if (Sync.IsServer && MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL && MyFakes.ENABLE_BLOCKS_IN_VOXELS_TEST && MyStructuralIntegrity.Enabled)
            {
                BoundingBoxD cutOutBox = shape.GetWorldBoundaries();
                cutOutBox.Inflate(0.25);

                List <MyEntity> boxOverlapList = new List <MyEntity>();
                MyEntities.GetElementsInBox(ref cutOutBox, boxOverlapList);

                foreach (var entity in boxOverlapList)
                {
                    var grid = entity as MyCubeGrid;
                    if (grid != null && grid.IsStatic)
                    {
                        if (grid.Physics != null && grid.Physics.Shape != null)
                        {
                            grid.Physics.Shape.RecalculateConnectionsToWorld(grid.GetBlocks());
                        }

                        if (type == MyVoxelBase.OperationType.Cut)
                        {
                            grid.TestDynamic = true;
                        }
                    }
                }

                boxOverlapList.Clear();
            }
        }
Exemplo n.º 4
0
        List <IMyEntity> IMyEntities.GetElementsInBox(ref VRageMath.BoundingBoxD boundingBox)
        {
            m_entityList.Clear();
            MyEntities.GetElementsInBox(ref boundingBox, m_entityList);
            var result = new List <IMyEntity>(m_entityList.Count);

            foreach (var entity in m_entityList)
            {
                result.Add(entity);
            }
            return(result);
        }
Exemplo n.º 5
0
        private static void FindObjectsInDetectingArea()
        {
            // find max detector's range
            float range = Math.Max(DefaultRadarRange, MyHudConstants.RADAR_JAMMER_RANGE);

            Debug.Assert(m_objectsInDetectingArea.Count == 0);
            BoundingSphere sphereToDetecting = new BoundingSphere(GetRadarPosition(), range);
            BoundingBox    radarBoundingBox  = BoundingBoxHelper.InitialBox;

            BoundingBoxHelper.AddSphere(ref sphereToDetecting, ref radarBoundingBox);
            MyEntities.GetElementsInBox(ref radarBoundingBox, m_objectsInDetectingArea);
        }
Exemplo n.º 6
0
        protected void CutOutFromVoxel(MyVoxelMap voxelMap, ref BoundingSphere bigSphereForTunnel)
        {
            if (!IsDummy)
            {
                if (MyMultiplayerGameplay.IsRunning)
                {
                    MyMultiplayerGameplay.Static.CutOut(voxelMap, ref bigSphereForTunnel);
                }

                //remove decals
                MyDecals.HideTrianglesAfterExplosion(voxelMap, ref bigSphereForTunnel);

                //cut off
                MyVoxelGenerator.CutOutSphereFast(voxelMap, bigSphereForTunnel);


                if (MySession.Is25DSector)
                {
                    //  Create debris rocks thrown from the explosion
                    MyExplosionDebrisVoxel.CreateExplosionDebris(ref bigSphereForTunnel, 1, CommonLIB.AppCode.Networking.MyMwcVoxelMaterialsEnum.Ice_01, MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip.GroupMask, voxelMap);

                    BoundingBox boundingBox = BoundingBoxHelper.InitialBox;
                    BoundingBoxHelper.AddSphere(ref bigSphereForTunnel, ref boundingBox);

                    // we need local list because this method can be called from inside of the loop

                    var elements = MyEntities.GetElementsInBox(ref boundingBox);
                    foreach (var el in elements)
                    {
                        MyEntity entity = ((MinerWars.AppCode.Game.Physics.MyPhysicsBody)el.GetRigidBody().m_UserData).Entity;
                        MyExplosionDebrisVoxel debris = entity as MyExplosionDebrisVoxel;

                        if (debris == null)
                        {
                            continue;
                        }

                        Vector3 awayDirection = debris.GetPosition() - bigSphereForTunnel.Center;

                        debris.Physics.AddForce(
                            MinerWars.AppCode.Game.Physics.MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE,
                            awayDirection * MyExplosionsConstants.EXPLOSION_FORCE_RADIUS_MULTIPLIER * 100000,
                            bigSphereForTunnel.Center,
                            MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomVector3Normalized() * 10000);
                    }

                    elements.Clear();
                }

                PlayVoxelCutCue();
            }
        }
        /// <summary>
        /// Writes all surrounding blocks around the given one with the given size.
        /// </summary>
        private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks)
        {
            outBlocks.Clear();

            BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);

            if (block.FatBlock != null)
            {
                var aabbCenter = aabb.Center;
                aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox;
                Matrix m;
                block.FatBlock.Orientation.GetMatrix(out m);
                aabb = aabb.TransformFast(m);
                aabb.Translate(aabbCenter);
            }

            aabb = aabb.TransformFast(block.CubeGrid.WorldMatrix);
            aabb.Inflate(0.125);

            List <MyEntity> boxOverlapList = new List <MyEntity>();

            MyEntities.GetElementsInBox(ref aabb, boxOverlapList);

            for (int i = 0; i < boxOverlapList.Count; i++)
            {
                var otherBlock = boxOverlapList[i] as MyCubeBlock;
                if (otherBlock != null && otherBlock.SlimBlock != block &&
                    otherBlock.CubeGrid.IsStatic && otherBlock.CubeGrid.EnableSmallToLargeConnections && otherBlock.CubeGrid.SmallToLargeConnectionsInitialized &&
                    otherBlock.CubeGrid != block.CubeGrid && otherBlock.CubeGrid.GridSizeEnum == cubeSizeEnum && !(otherBlock is MyFracturedBlock) &&
                    !(otherBlock.Components.Has <MyFractureComponentBase>()))
                {
                    var compound = otherBlock as MyCompoundCubeBlock;
                    if (compound != null)
                    {
                        foreach (var blockInCompound in compound.GetBlocks())
                        {
                            if (blockInCompound != block && !(blockInCompound.FatBlock.Components.Has <MyFractureComponentBase>()))
                            {
                                outBlocks.Add(blockInCompound.FatBlock);
                            }
                        }
                    }
                    else
                    {
                        outBlocks.Add(otherBlock);
                    }
                }
            }

            boxOverlapList.Clear();
        }
        /// <summary>
        /// Writes all surrounding blocks around the given one with the given size.
        /// </summary>
        private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks)
        {
            outBlocks.Clear();

            BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);

            if (block.FatBlock != null)
            {
                aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox;
                aabb.Translate(block.Position * block.CubeGrid.GridSize);
            }

            aabb = aabb.Transform(block.CubeGrid.WorldMatrix);
            aabb.Inflate(0.125);

            List <MyEntity> boxOverlapList = new List <MyEntity>();

            MyEntities.GetElementsInBox(ref aabb, boxOverlapList);

            for (int i = 0; i < boxOverlapList.Count; i++)
            {
                var otherGrid = boxOverlapList[i] as MyCubeGrid;
                if (otherGrid != null)
                {
                    foreach (var gridBlock in otherGrid.CubeBlocks)
                    {
                        if (IsValidForConnection(gridBlock.FatBlock, block, cubeSizeEnum))
                        {
                            if (!IsCompoundAndProcessed(gridBlock.FatBlock, block, outBlocks))
                            {
                                outBlocks.Add(gridBlock.FatBlock);
                            }
                        }
                    }
                }
                else
                {
                    var otherBlock = boxOverlapList[i] as MyCubeBlock;
                    if (IsValidForConnection(otherBlock, block, cubeSizeEnum))
                    {
                        if (!IsCompoundAndProcessed(otherBlock, block, outBlocks))
                        {
                            outBlocks.Add(otherBlock);
                        }
                    }
                }
            }

            boxOverlapList.Clear();
        }
Exemplo n.º 9
0
        private static void OnVoxelChanged(MyVoxelBase.OperationType type, MyVoxelBase voxelMap, MyShape shape)
        {
            if (Sync.IsServer)
            {
                BoundingBoxD cutOutBox = shape.GetWorldBoundaries();
                cutOutBox.Inflate(0.25);

                MyEntities.GetElementsInBox(ref cutOutBox, m_overlapList);
                // Check static grids around (possible change to dynamic)
                if (/*MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL &&*/ MyFakes.ENABLE_BLOCKS_IN_VOXELS_TEST && MyStructuralIntegrity.Enabled)
                {
                    foreach (var entity in m_overlapList)
                    {
                        var grid = entity as MyCubeGrid;
                        if (grid != null && grid.IsStatic)
                        {
                            if (grid.Physics != null && grid.Physics.Shape != null)
                            {
                                grid.Physics.Shape.RecalculateConnectionsToWorld(grid.GetBlocks());
                            }

                            if (type == MyVoxelBase.OperationType.Cut)
                            {
                                grid.TestDynamic = true;
                            }
                        }
                    }
                }
            }
            var      voxelPhysics = voxelMap as MyVoxelPhysics;
            MyPlanet planet       = voxelPhysics != null ? voxelPhysics.Parent : voxelMap as MyPlanet;

            if (planet != null)
            {
                var planetEnvironment = planet.Components.Get <MyPlanetEnvironmentComponent>();
                if (planetEnvironment != null)
                {
                    var sectors = planetEnvironment.GetSectorsInRange(shape);
                    if (sectors != null)
                    {
                        foreach (var sector in sectors)
                        {
                            sector.DisableItemsInShape(shape);
                        }
                    }
                }
            }
            m_overlapList.Clear();
        }
Exemplo n.º 10
0
        private static void OnVoxelChanged(MyVoxelBase.OperationType type, MyVoxelBase voxelMap, MyShape shape)
        {
            if (!Sync.IsServer)
            {
                return;
            }
            BoundingBoxD cutOutBox = shape.GetWorldBoundaries();

            cutOutBox.Inflate(0.25);

            MyEntities.GetElementsInBox(ref cutOutBox, m_overlapList);
            // Check static grids around (possible change to dynamic)
            if (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL && MyFakes.ENABLE_BLOCKS_IN_VOXELS_TEST && MyStructuralIntegrity.Enabled)
            {
                foreach (var entity in m_overlapList)
                {
                    var grid = entity as MyCubeGrid;
                    if (grid != null && grid.IsStatic)
                    {
                        if (grid.Physics != null && grid.Physics.Shape != null)
                        {
                            grid.Physics.Shape.RecalculateConnectionsToWorld(grid.GetBlocks());
                        }

                        if (type == MyVoxelBase.OperationType.Cut)
                        {
                            grid.TestDynamic = true;
                        }
                    }
                }
            }
            var      voxelPhysics = voxelMap as MyVoxelPhysics;
            MyPlanet planet       = voxelPhysics != null ? voxelPhysics.Parent : voxelMap as MyPlanet;

            if (planet != null)
            {
                var center = cutOutBox.Center;
                foreach (var environment in planet.GetEnvironmentItemsAtPosition(ref center))
                {
                    environment.RemoveItemsAroundPoint(cutOutBox.Center, cutOutBox.HalfExtents.Max());
                }
            }
            m_overlapList.Clear();
        }
Exemplo n.º 11
0
 static bool CanPlaceInArea(OperationType type, MyShape Shape)
 {
     if (type == OperationType.Fill)
     {
         m_foundElements.Clear();
         BoundingBoxD box = Shape.GetWorldBoundaries();
         MyEntities.GetElementsInBox(ref box, m_foundElements);
         foreach (var entity in m_foundElements)
         {
             if (IsForbiddenEntity(entity))
             {
                 if (entity.PositionComp.WorldAABB.Intersects(box))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 12
0
 static bool CanPlaceInArea(OperationType type, MyShape Shape)
 {
     if (type == OperationType.Fill)
     {
         m_foundElements.Clear();
         BoundingBoxD box = Shape.GetWorldBoundaries();
         MyEntities.GetElementsInBox(ref box, m_foundElements);
         foreach (var entity in m_foundElements)
         {
             if (IsForbiddenEntity(entity))
             {
                 if (entity.PositionComp.WorldAABB.Intersects(box))
                 {
                     MyHud.Notifications.Add(MyNotificationSingletons.CopyPasteAsteoridObstructed);
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
        private MyCubeGrid DetectTouchingGrid(MySlimBlock block)
        {
            if (MyCubeBuilder.Static.DynamicMode)
            {
                return(null);
            }

            if (block == null)
            {
                return(null);
            }

            if (block.FatBlock is MyCompoundCubeBlock)
            {
                foreach (var blockInCompound in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
                {
                    MyCubeGrid touchingGrid = DetectTouchingGrid(blockInCompound);
                    if (touchingGrid != null)
                    {
                        return(touchingGrid);
                    }
                }

                return(null);
            }

            ProfilerShort.Begin("MultiBlockClipboard: DetectMerge");

            float        gridSize = block.CubeGrid.GridSize;
            BoundingBoxD aabb;

            block.GetWorldBoundingBox(out aabb);
            // Inflate by half cube, so it will intersect for sure when there's anything
            aabb.Inflate(gridSize / 2);

            m_tmpNearEntities.Clear();
            MyEntities.GetElementsInBox(ref aabb, m_tmpNearEntities);

            var mountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio);

            try
            {
                for (int i = 0; i < m_tmpNearEntities.Count; i++)
                {
                    var grid = m_tmpNearEntities[i] as MyCubeGrid;
                    if (grid != null && grid != block.CubeGrid && grid.Physics != null && grid.Physics.Enabled && grid.IsStatic && grid.GridSizeEnum == block.CubeGrid.GridSizeEnum)
                    {
                        Vector3I gridOffset = grid.WorldToGridInteger(m_pastePosition);
                        if (!grid.CanMergeCubes(block.CubeGrid, gridOffset))
                        {
                            continue;
                        }

                        MatrixI transform = grid.CalculateMergeTransform(block.CubeGrid, gridOffset);
                        Base6Directions.Direction forward        = transform.GetDirection(block.Orientation.Forward);
                        Base6Directions.Direction up             = transform.GetDirection(block.Orientation.Up);
                        MyBlockOrientation        newOrientation = new MyBlockOrientation(forward, up);
                        Quaternion newRotation;
                        newOrientation.GetQuaternion(out newRotation);
                        Vector3I newPosition = Vector3I.Transform(block.Position, transform);

                        if (!MyCubeGrid.CheckConnectivity(grid, block.BlockDefinition, mountPoints, ref newRotation, ref newPosition))
                        {
                            continue;
                        }

                        return(grid);
                    }
                }
            }
            finally
            {
                m_tmpNearEntities.Clear();
                ProfilerShort.End();
            }

            return(null);
        }
        /// <summary>
        /// Writes all surrounding blocks around the given one with the given size.
        /// </summary>
        private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MySlimBlock> outBlocks)
        {
            outBlocks.Clear();

            BoundingBoxD aabbForNeighbors = new BoundingBoxD(block.Min * block.CubeGrid.GridSize, block.Max * block.CubeGrid.GridSize);
            BoundingBoxD aabb             = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);

            if (block.FatBlock != null)
            {
                var aabbCenter = aabb.Center;
                aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox;
                Matrix m;
                block.FatBlock.Orientation.GetMatrix(out m);
                aabb = aabb.TransformFast(m);
                aabb.Translate(aabbCenter);
            }

            aabb.Inflate(0.125);
            var aabbWorld = aabb.TransformFast(block.CubeGrid.WorldMatrix);

            List <MyEntity> boxOverlapList = new List <MyEntity>();

            MyEntities.GetElementsInBox(ref aabbWorld, boxOverlapList);

            for (int i = 0; i < boxOverlapList.Count; i++)
            {
                var cubeGrid = boxOverlapList[i] as MyCubeGrid;
                if (cubeGrid != null)
                {
                    if (cubeGrid.IsStatic && cubeGrid != block.CubeGrid && cubeGrid.EnableSmallToLargeConnections && cubeGrid.SmallToLargeConnectionsInitialized &&
                        cubeGrid.GridSizeEnum == cubeSizeEnum)
                    {
                        Debug.Assert(m_tmpSlimBlocksList.Count == 0);
                        m_tmpSlimBlocksList.Clear();
                        cubeGrid.GetBlocksIntersectingOBB(aabb, block.CubeGrid.WorldMatrix, m_tmpSlimBlocksList);

                        CheckNeighborBlocks(block, aabbForNeighbors, cubeGrid, m_tmpSlimBlocksList);

                        foreach (var slimBlock in m_tmpSlimBlocksList)
                        {
                            if (slimBlock.FatBlock != null)
                            {
                                if (slimBlock.FatBlock is MyFracturedBlock)
                                {
                                    continue;
                                }

                                if (slimBlock.FatBlock.Components.Has <MyFractureComponentBase>())
                                {
                                    continue;
                                }

                                if (slimBlock.FatBlock is MyCompoundCubeBlock)
                                {
                                    foreach (var blockInCompound in (slimBlock.FatBlock as MyCompoundCubeBlock).GetBlocks())
                                    {
                                        if (!(blockInCompound.FatBlock.Components.Has <MyFractureComponentBase>()))
                                        {
                                            outBlocks.Add(blockInCompound);
                                        }
                                    }
                                }
                                else
                                {
                                    outBlocks.Add(slimBlock);
                                }
                            }
                            else
                            {
                                outBlocks.Add(slimBlock);
                            }
                        }

                        m_tmpSlimBlocksList.Clear();
                    }
                }
            }

            boxOverlapList.Clear();
        }
Exemplo n.º 15
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                MyRender.GetRenderProfiler().StartProfilingBlock("MyCannonShot.UpdateBeforeSimulation");

                if (this.WorldMatrix.Translation != m_previousPosition)
                {
                    MyLine line = new MyLine(this.WorldMatrix.Translation, m_previousPosition);
                    MyDangerZones.Instance.Notify(line, OwnerEntity);
                }

                //  Kill this missile
                if (m_isExploded && !m_wasPenetration)
                {
                    //  Create explosion
                    MyExplosion newExplosion = MyExplosions.AddExplosion();
                    if (newExplosion != null)
                    {
                        float           radius          = MyMwcUtils.GetRandomFloat(m_ammoProperties.ExplosionRadius - 2, m_ammoProperties.ExplosionRadius + 2);
                        BoundingSphere  explosionSphere = new BoundingSphere((m_collisionPoint.HasValue ? m_collisionPoint.Value : GetPosition()), radius);
                        MyExplosionInfo info            = new MyExplosionInfo(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, explosionSphere, m_explosionType, true)
                        {
                            GroupMask            = Physics.GroupMask,
                            CascadeLevel         = CascadedExplosionLevel,
                            HitEntity            = m_collidedEntity,
                            OwnerEntity          = this.OwnerEntity,
                            Direction            = WorldMatrix.Forward,
                            ParticleScale        = 1.5f,
                            VoxelExplosionCenter = explosionSphere.Center + radius * WorldMatrix.Forward * 0.6f,
                        };
                        info.CreateParticleEffect = !m_hasExplosion;
                        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());
                    }

                    MarkForClose();

                    return;
                }

                base.UpdateBeforeSimulation();

                //  Chech timeout and max distance
                if ((m_elapsedMiliseconds > MyCannonConstants.SHOT_TIMEOUT) || (Vector3.Distance(this.WorldMatrix.Translation, m_origin) >= m_ammoProperties.MaxTrajectory))
                {
                    MarkForClose();
                    return;
                }



                Matrix orientation = GetWorldRotation();

                //  Update thruster cue/sound
                MyAudio.UpdateCuePosition(m_thrusterCue, this.WorldMatrix.Translation, orientation.Forward, orientation.Up, this.Physics.LinearVelocity);

                Vector3 pos = this.WorldMatrix.Translation;

                if (m_penetratedVoxelMap == null)
                {
                    if (m_smokeEffect != null)
                    {
                        m_smokeEffect.WorldMatrix = WorldMatrix;
                    }
                }

                /*
                 * if (m_wasPenetration)
                 * {
                 * //  Create explosion
                 * MyExplosion newExplosion = MyExplosions.AddExplosion();
                 * if (newExplosion != null)
                 * {
                 * float radius = MyMwcUtils.GetRandomFloat(1, 2);
                 * float particleScale = 2.2f; // must be large enough to cover the hole
                 * newExplosion.StartWithPositionOffset(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, m_explosionType, m_penetrationOrigin - WorldMatrix.Forward * 2, radius, MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadedExplosionLevel, particleScale: particleScale, hitEntity: m_collidedEntity, ownerEntity: m_ownerEntity);
                 * }
                 * m_wasPenetration = false;
                 * m_hasExplosion = true;
                 * }        */

                if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive)
                {
                    //  Look for small ships in shots's proximity
                    BoundingSphere boundingSphere = new BoundingSphere(GetPosition(), MyCannonShotConstants.PROXIMITY_DETECTION_RADIUS);
                    BoundingBox    boundingBox    = new BoundingBox();
                    BoundingBox.CreateFromSphere(ref boundingSphere, out boundingBox);

                    var elements = MyEntities.GetElementsInBox(ref boundingBox);
                    for (int i = 0; i < elements.Count; i++)
                    {
                        var rigidBody = (MyPhysicsBody)elements[i].GetRigidBody().m_UserData;
                        var entity    = rigidBody.Entity;


                        if (!(entity is MinerWars.AppCode.Game.Entities.MySmallShip))
                        {
                            continue;
                        }
                        if (entity == OwnerEntity)
                        {
                            continue;
                        }
                        if (entity == this)
                        {
                            continue;
                        }

                        Explode(entity);
                        break;
                    }
                    elements.Clear();
                }

                /*
                 * if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster)
                 * {
                 *  m_cuttingSphere.Center = GetPosition();
                 *
                 *  //  We found voxel so lets make tunel into it
                 *  MyPhysObjectBase collisionResult = MyEntities.GetIntersectionWithSphere(ref m_cuttingSphere, this, (MySmallShip)Parent);
                 *  if (collisionResult is MyVoxelMap)
                 *  {
                 *      MyVoxelMap voxelMap = collisionResult as MyVoxelMap;
                 *      if (m_penetratedVoxelMap == null)
                 *      {
                 *          m_penetratedVoxelMap = voxelMap;
                 *          m_penetrationOrigin = GetPosition();
                 *      }
                 *
                 *      Game.Voxels.MyVoxelGenerator.CutOutSphereFast(voxelMap, m_cuttingSphere);
                 *  }
                 * } */
                /*
                 * if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster)
                 * {
                 * if (m_penetratedVoxelMap != null)
                 * {
                 * //MyCannonShotConstants.BUSTER_PENETRATION_LENGTH
                 * float busterPenetrationLength = m_ammoProperties.ExplosionRadius * 0.75f;
                 * if (Vector3.Distance(m_penetrationOrigin, GetPosition()) >= busterPenetrationLength)
                 * {
                 *    m_collisionPoint = GetPosition(); //We want to explode inside voxel, not on collision point
                 *    Explode(m_penetratedVoxelMap);
                 * }
                 * }
                 * }    */
            }
            finally
            {
                MyRender.GetRenderProfiler().EndProfilingBlock();
            }
        }
Exemplo n.º 16
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (m_state == MyCurrentState.ACTIVATED)
            {
                if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeSearchedForTarget) > MyMineSmartConstants.INTERVAL_TO_SEARCH_FOR_ENEMY_IN_MILISECONDS)
                {
                    m_lastTimeSearchedForTarget = MyMinerGame.TotalGamePlayTimeInMilliseconds;

                    //  Look for small ships in mine's proximity
                    BoundingSphere boundingSphere = new BoundingSphere(GetPosition(), m_ammoProperties.MaxTrajectory);
                    BoundingBox    boundingBox;
                    BoundingBox.CreateFromSphere(ref boundingSphere, out boundingBox);

                    MySmallShip newTarget = null;

                    var elements = MyEntities.GetElementsInBox(ref boundingBox);
                    for (int i = 0; i < elements.Count; i++)
                    {
                        var rigidBody = (MyPhysicsBody)elements[i].GetRigidBody().m_UserData;
                        var entity    = rigidBody.Entity;

                        if (entity is MySmallShip && MyFactions.GetFactionsRelation(Faction, entity.Faction) == MyFactionRelationEnum.Enemy)
                        {
                            float dist = Vector3.Distance(entity.GetPosition(), GetPosition());
                            if (dist <= m_ammoProperties.MaxTrajectory)
                            {
                                newTarget = (MySmallShip)entity;
                                break;
                            }
                        }
                    }
                    elements.Clear();

                    //  If not target found at all
                    if (newTarget == null)
                    {
                        m_currentTarget = null;
                    }

                    //  We assign new target only if we do not have any previous (that's a protection agains possible jumping over targets if more targets in proximity)
                    if (m_currentTarget == null)
                    {
                        m_currentTarget = newTarget;
                    }
                }

                //  There is some enemy so lets go to him and explode
                if (m_currentTarget != null)
                {
                    //  Move towards the target
                    Vector3 engineForce = MyMwcUtils.Normalize(m_currentTarget.GetPosition() - GetPosition()) * m_ammoProperties.InitialSpeed;
                    engineForce *= MyMineSmartConstants.CHASE_SPEED_MULTIPLIER;
                    this.Physics.AddForce(
                        MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE,
                        engineForce,
                        GetPosition(),
                        Vector3.Zero);

                    StartMovingCue();
                }
                else
                {
                    StopMovingCue();
                }

                UpdateMovingCue();
            }
        }