Пример #1
0
        private bool IsBeingWelded()
        {
            if (MySession.Static == null)
            {
                return(false);
            }
            if (MySession.Static.ControlledEntity == null)
            {
                return(false);
            }
            MyCharacter entity = MySession.Static.ControlledEntity.Entity as MyCharacter;

            if (entity == null)
            {
                return(false);
            }
            MyEngineerToolBase currentWeapon = entity.CurrentWeapon as MyEngineerToolBase;

            if (currentWeapon == null)
            {
                return(false);
            }
            MyCubeGrid  targetGrid = currentWeapon.GetTargetGrid();
            MyCubeBlock objB       = this.Entity as MyCubeBlock;

            if (((targetGrid == null) || ((objB == null) || !ReferenceEquals(targetGrid, objB.CubeGrid))) || !currentWeapon.HasHitBlock)
            {
                return(false);
            }
            MySlimBlock cubeBlock = targetGrid.GetCubeBlock(currentWeapon.TargetCube);

            return((cubeBlock != null) ? (ReferenceEquals(cubeBlock.FatBlock, objB) && currentWeapon.IsShooting) : false);
        }
Пример #2
0
        private void DamageGrid(FlameInfo flameInfo, LineD l, MyCubeGrid grid)
        {
            HkSphereShape sph       = new HkSphereShape(flameInfo.Radius * BlockDefinition.FlameDamageLengthScale);
            var           transform = MatrixD.CreateWorld(l.From, Vector3.Forward, Vector3.Up);
            var           hit       = MyPhysics.CastShapeReturnPoint(l.To, sph, ref transform, (int)MyPhysics.CollisionLayers.DefaultCollisionLayer, 0.05f);

            sph.Base.RemoveReference();

            if (hit.HasValue)
            {
                //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                MyPhysics.CastRay(hit.Value - l.Direction * 0.1f, hit.Value + l.Direction * 0.1f, m_gridRayCastLst, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer);
                if (m_gridRayCastLst.Count == 0 || m_gridRayCastLst[0].HkHitInfo.GetHitEntity() != grid)    //If you found something other than the targeted grid do nothing
                {
                    m_gridRayCastLst.Clear();
                    return;
                }

                Vector3D offsetHit = hit.Value + l.Direction * 0.1;
                m_gridRayCastLst.Clear();
                var block = grid.GetCubeBlock(grid.WorldToGridInteger(offsetHit));
                //if (block != this.SlimBlock)
                {
                    //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                    var invWorld = grid.PositionComp.WorldMatrixNormalizedInv;
                    var gridPos  = Vector3D.Transform(offsetHit, invWorld);
                    var gridDir  = Vector3D.TransformNormal(l.Direction, invWorld);
                    if (block != null)
                    {
                        //We dont want to damage thruster itself
                        //We dont want smallship thruster to damage heavy armors because of landing
                        if (block.FatBlock != this && (CubeGrid.GridSizeEnum == MyCubeSize.Large || block.BlockDefinition.DeformationRatio > 0.25))
                        {
                            block.DoDamage(30 * BlockDefinition.FlameDamage, MyDamageType.Environment, attackerId: EntityId);
                        }
                    }

                    if (block == null || block.FatBlock != this)
                    {
                        var areaPlanar   = 0.5f * flameInfo.Radius * CubeGrid.GridSize;
                        var areaVertical = 0.5f * CubeGrid.GridSize;

                        grid.Physics.ApplyDeformation(BlockDefinition.FlameDamage, areaPlanar, areaVertical, gridPos, gridDir, MyDamageType.Environment, CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.1f : 0, attackerId: EntityId);
                    }
                }
            }
        }
Пример #3
0
        private void DamageGrid(FlameInfo flameInfo, LineD l, MyCubeGrid grid)
        {
            HkSphereShape sph       = new HkSphereShape(flameInfo.Radius * m_thrustDefinition.FlameDamageLengthScale);
            var           transform = MatrixD.CreateWorld(l.From, Vector3.Forward, Vector3.Up);
            var           hit       = MyPhysics.CastShapeReturnPoint(l.To, sph, ref transform, (int)MyPhysics.DefaultCollisionLayer, 0.05f);

            sph.Base.RemoveReference();

            if (hit.HasValue)
            {
                //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                MyPhysics.CastRay(hit.Value - l.Direction * 0.1f, hit.Value + l.Direction * 0.1f, m_gridRayCastLst, MyPhysics.ObjectDetectionCollisionLayer);
                if ((m_gridRayCastLst.Count == 0 || m_gridRayCastLst[0].HkHitInfo.Body.GetEntity() != grid) && grid == CubeGrid)
                {
                    m_gridRayCastLst.Clear();
                    return;
                }
                m_gridRayCastLst.Clear();
                var block = grid.GetCubeBlock(grid.WorldToGridInteger(hit.Value));
                //if (block != this.SlimBlock)
                {
                    //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                    var invWorld = grid.PositionComp.GetWorldMatrixNormalizedInv();
                    var gridPos  = Vector3D.Transform(hit.Value, invWorld);
                    var gridDir  = Vector3D.TransformNormal(l.Direction, invWorld);
                    if (block != null)
                    {
                        if (block.FatBlock != this && (CubeGrid.GridSizeEnum == MyCubeSize.Large || block.BlockDefinition.DeformationRatio > 0.25))
                        {
                            block.DoDamage(30 * m_thrustDefinition.FlameDamage, MyDamageType.Environment, attackerId: EntityId);
                        }
                    }
                    var areaPlanar   = 0.5f * flameInfo.Radius * CubeGrid.GridSize;
                    var areaVertical = 0.5f * CubeGrid.GridSize;

                    grid.Physics.ApplyDeformation(m_thrustDefinition.FlameDamage, areaPlanar, areaVertical, gridPos, gridDir, MyDamageType.Environment, CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.1f : 0, attackerId: EntityId);
                }
            }
        }
Пример #4
0
        public Vector3 GetDefinitionOffsetWithNeighbours(Vector3I cubePos, Vector3I bonePos, MyCubeGrid grid)
        {
            Vector3I boneOffset = GetCubeBoneOffset(cubePos, bonePos);

            if (m_tempAffectedCubes == null)
            {
                m_tempAffectedCubes = new List <Vector3I>();
            }

            m_tempAffectedCubes.Clear();
            GetAffectedCubes(cubePos, boneOffset, m_tempAffectedCubes, grid);

            Vector3 offset        = Vector3.Zero;
            int     affectedCount = 0;

            foreach (var cube in m_tempAffectedCubes)
            {
                var cubeBlock = grid.GetCubeBlock(cube);
                if (cubeBlock != null && cubeBlock.BlockDefinition.Skeleton != null)
                {
                    Vector3I currentBoneOffset = GetCubeBoneOffset(cube, bonePos);

                    var defOffset = GetDefinitionOffset(cubeBlock, currentBoneOffset);
                    if (defOffset != null)
                    {
                        offset += defOffset.Value;
                        affectedCount++;
                    }
                }
            }

            if (affectedCount == 0)
            {
                return(offset);
            }
            return(offset / affectedCount);
        }
Пример #5
0
        private void DamageGrid(FlameInfo flameInfo, LineD l, MyCubeGrid grid)
        {
            HkSphereShape sph = new HkSphereShape(flameInfo.Radius * BlockDefinition.FlameDamageLengthScale);
            var transform = MatrixD.CreateWorld(l.From, Vector3.Forward, Vector3.Up);
            var hit = MyPhysics.CastShapeReturnPoint(l.To, sph, ref transform, (int)MyPhysics.DefaultCollisionLayer, 0.05f);

            sph.Base.RemoveReference();

            if (hit.HasValue)
            {
                //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                MyPhysics.CastRay(hit.Value - l.Direction * 0.1f, hit.Value + l.Direction * 0.1f, m_gridRayCastLst, MyPhysics.ObjectDetectionCollisionLayer);
                if ((m_gridRayCastLst.Count == 0 || m_gridRayCastLst[0].HkHitInfo.GetHitEntity() != grid) && grid == CubeGrid)
                {
                    m_gridRayCastLst.Clear();
                    return;
                }
                m_gridRayCastLst.Clear();
                var block = grid.GetCubeBlock(grid.WorldToGridInteger(hit.Value));
                //if (block != this.SlimBlock)
                {
                    //MyRenderProxy.DebugDrawSphere(hit.Value, 0.1f, Color.Green.ToVector3(), 1, true);
                    var invWorld = grid.PositionComp.GetWorldMatrixNormalizedInv();
                    var gridPos = Vector3D.Transform(hit.Value, invWorld);
                    var gridDir = Vector3D.TransformNormal(l.Direction, invWorld);
                    if (block != null)
                        if (block.FatBlock != this && (CubeGrid.GridSizeEnum == MyCubeSize.Large || block.BlockDefinition.DeformationRatio > 0.25))
                        {
                            block.DoDamage(30 * BlockDefinition.FlameDamage, MyDamageType.Environment, attackerId: EntityId);
                        }
                    var areaPlanar = 0.5f * flameInfo.Radius * CubeGrid.GridSize;
                    var areaVertical = 0.5f * CubeGrid.GridSize;

                    grid.Physics.ApplyDeformation(BlockDefinition.FlameDamage, areaPlanar, areaVertical, gridPos, gridDir, MyDamageType.Environment, CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.1f : 0, attackerId: EntityId);
                }
            }
        }
Пример #6
0
        protected virtual void InitSubBlocks()
        {
            if (!MyFakes.ENABLE_SUBBLOCKS)
            {
                return;
            }

            if (m_subBlocksInitialized)
            {
                return;
            }

            //  if (!Sync.IsServer)
            //    return;

            try
            {
                MyCubeBlockDefinition subBlockDefinition;
                MatrixD subBlockMatrix;
                Vector3 dummyPosition;

                var finalModel = Sandbox.Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model);
                foreach (var dummy in finalModel.Dummies)
                {
                    if (!MyCubeBlock.GetSubBlockDataFromDummy(BlockDefinition, dummy.Key, dummy.Value, true, out subBlockDefinition, out subBlockMatrix, out dummyPosition))
                    {
                        continue;
                    }

                    string dummyName = dummy.Key.Substring(DUMMY_SUBBLOCK_ID.Length);

                    MySlimBlock        subblock = null;
                    MyCubeGrid         subgrid  = null;
                    MySubBlockLoadInfo subBlockLoadInfo;
                    if (m_subBlockIds.TryGetValue(dummyName, out subBlockLoadInfo))
                    {
                        MyEntity entity;
                        if (MyEntities.TryGetEntityById(subBlockLoadInfo.GridId, out entity))
                        {
                            subgrid = entity as MyCubeGrid;
                            if (subgrid != null)
                            {
                                subblock = subgrid.GetCubeBlock(subBlockLoadInfo.SubBlockPosition);
                                Debug.Assert(subblock != null, "Cannot find subblock in subgrid!");
                                if (subblock == null)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                Debug.Assert(false, "Loaded entity is not grid!");
                                continue;
                            }
                        }
                        else
                        {
                            Debug.Assert(false, "Cannot load subgrid!");
                            continue;
                        }
                    }

                    if (!m_subBlocksLoaded)
                    {
                        if (subgrid == null)
                        {
                            Debug.Assert(!subBlockMatrix.IsMirrored());
                            Matrix subGridWorldMatrix = subBlockMatrix * PositionComp.LocalMatrix * CubeGrid.WorldMatrix;

                            //TODO: Try to find better way how to sync entity ID of subblocks..
                            subgrid = MyCubeBuilder.SpawnDynamicGrid(subBlockDefinition, subGridWorldMatrix, EntityId + SubBlocks.Count + 1);
                            if (subgrid != null)
                            {
                                subblock = subgrid.GetCubeBlock(Vector3I.Zero);
                            }
                        }

                        if (subgrid == null)
                        {
                            Debug.Assert(false, "SubGrid has not been set!");
                            continue;
                        }

                        if (subblock == null || subblock.FatBlock == null)
                        {
                            Debug.Assert(false, "Fatblock cannot be null for subblocks!");
                            continue;
                        }
                    }

                    if (subblock != null)
                    {
                        SubBlocks.Add(dummyName, subblock);
                        subblock.FatBlock.SubBlockName = dummyName;
                        subblock.FatBlock.OwnerBlock   = SlimBlock;
                        subblock.FatBlock.OnClosing   += SubBlock_OnClosing;
                        Debug.Assert(SlimBlock != null);
                    }
                }
            }
            finally
            {
                m_subBlockIds.Clear();

                m_subBlocksInitialized = true;
            }
        }
Пример #7
0
        public Vector3 GetDefinitionOffsetWithNeighbours(Vector3I cubePos, Vector3I bonePos, MyCubeGrid grid)
        {
            Vector3I boneOffset = GetCubeBoneOffset(cubePos, bonePos);

            if (m_tempAffectedCubes == null)
            {
                m_tempAffectedCubes = new List<Vector3I>();
            }

            m_tempAffectedCubes.Clear();
            GetAffectedCubes(cubePos, boneOffset, m_tempAffectedCubes, grid);

            Vector3 offset = Vector3.Zero;
            int affectedCount = 0;
            foreach (var cube in m_tempAffectedCubes)
            {
                var cubeBlock = grid.GetCubeBlock(cube);
                if (cubeBlock != null && cubeBlock.BlockDefinition.Skeleton != null)
                {
                    Vector3I currentBoneOffset = GetCubeBoneOffset(cube, bonePos);

                    var defOffset = GetDefinitionOffset(cubeBlock, currentBoneOffset);
                    if (defOffset != null)
                    {
                        offset += defOffset.Value;
                        affectedCount++;
                    }
                }
            }

            if (affectedCount == 0)
            {
                return offset;
            }
            return offset / affectedCount;
        }
Пример #8
0
        public static void AfterStaticGridSpawn(MyCubeGrid grid)
        {
            Debug.Assert(grid.IsStatic);

            MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
            if (block != null)
            {
                MyCubeGrid mainGrid = grid.DetectMerge(block);
                if (mainGrid == null)
                    mainGrid = grid;
                mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(block));

                if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
                {
                    MyCubeGridSmallToLargeConnection.Static.CheckBlockSmallToLargeConnect(block);
                }
            }
            else
                Debug.Fail("Block not created");
        }
        public void OnWorldPosChanged(ref MatrixD newTransform)
        {

            MatrixD worldPos = newTransform;
            m_caster.OnWorldPositionChanged(ref worldPos);

            var entitiesInRange = this.m_caster.EntitiesInRange;
            float closestDistance = float.MaxValue;
            MyEntity closestEntity = null;

            if (!m_isPointOfRefSet)
                m_pointOfReference = worldPos.Translation;

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
               // int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    float distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_pointOfReference);

                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            closestEntity = entity.Entity;
                            this.m_distanceToHitSq = distanceSq;
                            this.m_hitPosition = entity.DetectionPoint;

                            closestDistance = distanceSq;
                        }
                    }
                 //   ++i;
                }
            }

            this.m_hitCubeGrid = closestEntity as MyCubeGrid;
            this.m_hitBlock = null;
            this.m_hitDestroaybleObj = closestEntity as IMyDestroyableObject;
            this.m_hitFloatingObject = closestEntity as MyFloatingObject;
            this.m_hitCharacter = closestEntity as MyCharacter;

            if (m_hitCubeGrid != null)
            {
                var invWorld = m_hitCubeGrid.PositionComp.WorldMatrixNormalizedInv;
                var gridLocalPos = Vector3D.Transform(this.m_hitPosition, invWorld);
                Vector3I blockPos;
                m_hitCubeGrid.FixTargetCube(out blockPos, gridLocalPos / m_hitCubeGrid.GridSize);
                m_hitBlock = m_hitCubeGrid.GetCubeBlock(blockPos);

            }

            
        }
Пример #10
0
        public static void AfterGridBuild(MyEntity builder, MyCubeGrid grid)
        {
            if (grid != null)
            {
                MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
                if (block != null)
                {
                    if (grid.IsStatic)
                    {
                        MyCubeGrid mainGrid = grid.DetectMerge(block);
                        if (mainGrid == null)
                            mainGrid = grid;
                        mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(block));

                        if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
                        {
                            MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block);
                        }
                    }

                    if (Sync.IsServer)
                    {
                        MyCubeBuilder.BuildComponent.AfterGridCreated(grid, builder);
                    }
                }
                else
                    Debug.Fail("Block not created");
            }
        }
Пример #11
0
        protected virtual bool TryDrillBlocks(MyCubeGrid grid, Vector3 worldPoint, bool onlyCheck)
        {
            var invWorld = grid.PositionComp.GetWorldMatrixNormalizedInv();
            var gridLocalPosCenter = Vector3.Transform(m_sensor.Center, invWorld);
            var gridLocalPos = Vector3.Transform(m_sensor.FrontPoint, invWorld);
            var gridLocalTarget = Vector3.Transform(worldPoint, invWorld);

            var gridSpacePos = Vector3I.Round(gridLocalPos / grid.GridSize);
            var block = grid.GetCubeBlock(gridSpacePos);

            bool createDebris = false;
            if (!onlyCheck)
            {
                if (block != null && block is IMyDestroyableObject && block.CubeGrid.BlocksDestructionEnabled)
                {
                    var destroyable = (block as IMyDestroyableObject);
                    destroyable.DoDamage(60, MyDamageType.Drill, Sync.IsServer);
                    createDebris = grid.Physics.ApplyDeformation(0.25f, 1.5f, 2f, gridLocalTarget, Vector3.Normalize(gridLocalPos - gridLocalPosCenter), MyDamageType.Drill);
                }
            }

            m_target = createDebris ? null : block;

            bool success = false;
            if (block != null)
            {
                if (createDebris)
                {
                    BoundingSphereD bsphere = m_cutOut.Sphere;
                    BoundingBoxD aabb = BoundingBoxD.CreateFromSphere(bsphere);
                    MyDebris.Static.CreateExplosionDebris(ref bsphere, block.CubeGrid, ref aabb, 0.3f);
                }

                success = true;
            }

            return success;
        }
Пример #12
0
        /// <summary>
        /// Writes multiblocks (compound block and block ID) to outMultiBlocks collection with the same multiblockId.
        /// </summary>
        public static void GetBlocksInMultiBlock(MyCubeGrid grid, Vector3I minPosition, Vector3I maxPosition, MyMultiBlockDefinition multiBlockDefinition, int multiBlockId,
            HashSet<Tuple<MySlimBlock, ushort?>> outMultiBlocks)
        {
            Debug.Assert(multiBlockId != 0);
            if (multiBlockId == 0)
                return;

            Vector3I cube = minPosition;
            for (Vector3I.RangeIterator it = new Vector3I.RangeIterator(ref minPosition, ref maxPosition); it.IsValid(); it.GetNext(out cube))
            {
                MySlimBlock slimBlock = grid.GetCubeBlock(cube);
                if (slimBlock == null)
                    continue;

                MyCompoundCubeBlock compound = slimBlock.FatBlock as MyCompoundCubeBlock;

                if (compound != null)
                {
                    m_tmpSlimBlocks.Clear();

                    foreach (var blockInCompound in compound.GetBlocks(m_tmpSlimBlocks))
                    {
                        if (blockInCompound.MultiBlockDefinition == multiBlockDefinition && blockInCompound.MultiBlockId == multiBlockId)
                        {
                            ushort? blockInCompoundId = compound.GetBlockId(blockInCompound);
                            outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, blockInCompoundId));
                        }
                    }

                    m_tmpSlimBlocks.Clear();
                }
                else
                {
                    MyFracturedBlock fracturedBlock = slimBlock.FatBlock as MyFracturedBlock;
                    if (fracturedBlock != null)
                    {
                        if (fracturedBlock.IsMultiBlockPart(multiBlockDefinition.Id, multiBlockId))
                            outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null));
                    }
                    else
                    {
                        if (slimBlock.MultiBlockDefinition == multiBlockDefinition && slimBlock.MultiBlockId == multiBlockId)
                            outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null));
                    }
                }
            }
        }
Пример #13
0
        protected virtual bool TryDrillBlocks(MyCubeGrid grid, Vector3 worldPoint, bool onlyCheck, out MyStringHash blockMaterial)
        {
            var invWorld = grid.PositionComp.WorldMatrixNormalizedInv;
            var gridLocalPosCenter = Vector3.Transform(m_sensor.Center, invWorld);
            var gridLocalPos = Vector3.Transform(m_sensor.FrontPoint, invWorld);
            var gridLocalTarget = Vector3.Transform(worldPoint, invWorld);

            var gridSpacePos = Vector3I.Round(gridLocalPos / grid.GridSize);
            var block = grid.GetCubeBlock(gridSpacePos);

            if (block != null)
            {
                if (block.BlockDefinition.PhysicalMaterial.Id.SubtypeId == MyStringHash.NullOrEmpty)
                    blockMaterial = m_metalMaterial;
                else
                    blockMaterial = block.BlockDefinition.PhysicalMaterial.Id.SubtypeId;
            }
            else
                blockMaterial = MyStringHash.NullOrEmpty;

            int createDebris = 0;
            if (!onlyCheck)
            {
                if (block != null && block is IMyDestroyableObject && block.CubeGrid.BlocksDestructionEnabled)
                {
                    var destroyable = (block as IMyDestroyableObject);
                    destroyable.DoDamage(60, MyDamageType.Drill, Sync.IsServer, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
                    createDebris = grid.Physics.ApplyDeformation(0.25f, 1.5f, 2f, gridLocalTarget, Vector3.Normalize(gridLocalPos - gridLocalPosCenter), MyDamageType.Drill, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
                }
            }

            m_target = createDebris != 0 ? null : block;

            bool success = false;
            if (block != null)
            {
                if (createDebris != 0)
                {
                    BoundingSphereD bsphere = m_cutOut.Sphere;
                    BoundingBoxD aabb = BoundingBoxD.CreateFromSphere(bsphere);
                    MyDebris.Static.CreateExplosionDebris(ref bsphere, block.CubeGrid, ref aabb, 0.3f);
                }

                success = true;
            }

            return success;
        }
Пример #14
0
        protected static void AfterGridBuild(MyEntity builder, MyCubeGrid grid, bool instantBuild)
        {
            if (grid != null)
            {
                MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
                if (block != null)
                {
                    if (grid.IsStatic)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        MySlimBlock blockInCompound = compoundBlock != null && compoundBlock.GetBlocksCount() > 0 ? compoundBlock.GetBlocks()[0] : null;

                        MyCubeGrid mainGrid = grid.DetectMerge(block);
                        if (mainGrid == null)
                            mainGrid = grid;

                        MySlimBlock mainBlock = block;
                        if (blockInCompound != null)
                        {
                            Debug.Assert(blockInCompound.CubeGrid == mainGrid);
                            mainBlock = mainGrid.GetCubeBlock(blockInCompound.Position);
                        }

                        mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(mainBlock));

                        if (MyCubeGridSmallToLargeConnection.Static != null)
                        {
                            if (Sync.IsServer && !MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block) && grid.GridSizeEnum == MyCubeSize.Small)
                                block.CubeGrid.TestDynamic = true;
                        }
                    }

                    if (Sync.IsServer)
                    {
                        MyCubeBuilder.BuildComponent.AfterSuccessfulBuild(builder, instantBuild);
                    }

                    if (block.FatBlock != null)
                        block.FatBlock.OnBuildSuccess(builder.EntityId);
                }
                else
                    Debug.Fail("Block not created");

                
            }
        }
Пример #15
0
        public static void AfterGridBuild(MyEntity builder, MyCubeGrid grid)
        {
            if (grid != null)
            {
                MySlimBlock block = grid.GetCubeBlock(Vector3I.Zero);
                if (block != null)
                {
                    if (grid.IsStatic)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        MySlimBlock blockInCompound = compoundBlock != null && compoundBlock.GetBlocksCount() > 0 ? compoundBlock.GetBlocks()[0] : null;

                        MyCubeGrid mainGrid = grid.DetectMerge(block);
                        if (mainGrid == null)
                            mainGrid = grid;

                        MySlimBlock mainBlock = block;
                        if (blockInCompound != null)
                        {
                            Debug.Assert(blockInCompound.CubeGrid == mainGrid);
                            mainBlock = mainGrid.GetCubeBlock(blockInCompound.Position);
                        }

                        mainGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(mainBlock));

                        if (MyFakes.ENABLE_SMALL_BLOCK_TO_LARGE_STATIC_CONNECTIONS)
                        {
                            if (!MyCubeGridSmallToLargeConnection.Static.AddBlockSmallToLargeConnection(block) && grid.GridSizeEnum == MyCubeSize.Small)
                                block.CubeGrid.TestDynamic = true;
                        }
                    }

                    if (Sync.IsServer)
                    {
                        MyCubeBuilder.BuildComponent.AfterGridCreated(grid, builder);
                    }
                }
                else
                    Debug.Fail("Block not created");
            }
        }