Exemple #1
0
        private bool TestPlacement()
        {
            MyCubeGrid grid;
            MyGridPlacementSettings gridPlacementSettings;
            BoundingBoxD            xd;
            bool flag3;
            MyGridPlacementSettings settings4;
            bool flag1;
            bool flag = true;

            base.m_touchingGrids.Clear();
            int num = 0;

            goto TR_0047;
TR_000F:
            xd = grid.PositionComp.LocalAABB;
            MatrixD worldMatrixNormalizedInv = grid.PositionComp.WorldMatrixNormalizedInv;

            if (MySector.MainCamera != null)
            {
                Vector3D point = Vector3D.Transform(MySector.MainCamera.Position, worldMatrixNormalizedInv);
                flag = flag && (xd.Contains(point) != ContainmentType.Contains);
            }
            if (flag)
            {
                m_tmpCollisionPoints.Clear();
                MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints);
                using (List <Vector3D> .Enumerator enumerator3 = m_tmpCollisionPoints.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        Vector3D point = Vector3D.Transform(enumerator3.Current, worldMatrixNormalizedInv);
                        flag = flag && (xd.Contains(point) != ContainmentType.Contains);
                        if (!flag)
                        {
                            break;
                        }
                    }
                }
            }
            num++;
            goto TR_0047;
TR_001D:
            flag &= flag3;
            base.m_touchingGrids[num] = this.DetectTouchingGrid();
            goto TR_000F;
TR_0033:
            settings4 = base.m_settings.GetGridPlacementSettings(grid.GridSizeEnum, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode);
            flag      = flag && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings4, grid.PositionComp.LocalAABB, false, null, true, true);
            goto TR_000F;
TR_0047:
            while (true)
            {
                if (num >= base.PreviewGrids.Count)
                {
                    return(flag);
                }
                grid = base.PreviewGrids[num];
                if (!Sandbox.Game.Entities.MyEntities.IsInsideWorld(grid.PositionComp.GetPosition()))
                {
                    return(false);
                }
                gridPlacementSettings = base.m_settings.GetGridPlacementSettings(grid.GridSizeEnum);
                base.m_touchingGrids.Add(null);
                if ((MySession.Static.SurvivalMode && !MyBlockBuilderBase.SpectatorIsBuilding) && !MySession.Static.CreativeToolsEnabled(Sync.MyId))
                {
                    if ((num == 0) && MyBlockBuilderBase.CameraControllerSpectator)
                    {
                        base.m_visible = false;
                        return(false);
                    }
                    if (((num == 0) && !MyCubeBuilder.Static.DynamicMode) && !MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref grid.PositionComp.WorldMatrixNormalizedInv, grid.PositionComp.LocalAABB, grid.GridSize, MyBlockBuilderBase.IntersectionDistance))
                    {
                        base.m_visible = false;
                        return(false);
                    }
                    if (!flag)
                    {
                        return(false);
                    }
                }
                if (!MyCubeBuilder.Static.DynamicMode)
                {
                    if (num != 0)
                    {
                        break;
                    }
                    if (!(base.m_hitEntity is MyCubeGrid))
                    {
                        break;
                    }
                    if (!base.IsSnapped)
                    {
                        break;
                    }
                    MyCubeGrid hitEntity = base.m_hitEntity as MyCubeGrid;
                    MyGridPlacementSettings gridPlacementSettings = base.m_settings.GetGridPlacementSettings(hitEntity.GridSizeEnum, hitEntity.IsStatic);
                    flag = ((hitEntity.GridSizeEnum != MyCubeSize.Large) || (grid.GridSizeEnum != MyCubeSize.Small)) ? (flag && base.TestGridPlacementOnGrid(grid, ref gridPlacementSettings, hitEntity)) : (flag && flag1);
                    base.m_touchingGrids.Clear();
                    base.m_touchingGrids.Add(hitEntity);
                }
                else
                {
                    MyGridPlacementSettings settings2 = (grid.GridSizeEnum == MyCubeSize.Large) ? base.m_settings.LargeGrid : base.m_settings.SmallGrid;
                    bool flag2 = false;
                    foreach (MySlimBlock block in grid.GetBlocks())
                    {
                        Vector3      min       = ((Vector3)(block.Min * base.PreviewGrids[num].GridSize)) - (Vector3.Half * base.PreviewGrids[num].GridSize);
                        Vector3      max       = (block.Max * base.PreviewGrids[num].GridSize) + (Vector3.Half * base.PreviewGrids[num].GridSize);
                        BoundingBoxD localAabb = new BoundingBoxD(min, max);
                        if (!flag2)
                        {
                            flag2 = TestVoxelPlacement(block, ref gridPlacementSettings, true);
                        }
                        flag = flag && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings2, localAabb, true, null, false, true);
                        if (!flag)
                        {
                            break;
                        }
                    }
                    flag &= flag2;
                }
                goto TR_000F;
            }
            if (num != 0)
            {
                goto TR_0033;
            }
            else if (!(base.m_hitEntity is MyVoxelMap))
            {
                goto TR_0033;
            }
            else
            {
                flag3 = false;
                using (HashSet <MySlimBlock> .Enumerator enumerator = grid.CubeBlocks.GetEnumerator())
                {
                    do
                    {
                        while (true)
                        {
                            if (enumerator.MoveNext())
                            {
                                MySlimBlock block3;
                                bool        flag4;
                                MySlimBlock current = enumerator.Current;
                                if (current.FatBlock is MyCompoundCubeBlock)
                                {
                                    using (List <MySlimBlock> .Enumerator enumerator2 = (current.FatBlock as MyCompoundCubeBlock).GetBlocks().GetEnumerator())
                                    {
                                        while (enumerator2.MoveNext())
                                        {
                                            if (!flag3)
                                            {
                                                flag1 = MyCubeGrid.TestPlacementArea(grid, ref gridPlacementSettings, grid.PositionComp.LocalAABB, false, null);
                                                flag3 = TestVoxelPlacement(block3, ref gridPlacementSettings, false);
                                            }
                                            flag = flag && flag4;
                                            if (!flag)
                                            {
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (!flag3)
                                {
                                    flag4 = TestBlockPlacementArea(block3, ref gridPlacementSettings, false, false);
                                    flag3 = TestVoxelPlacement(current, ref gridPlacementSettings, false);
                                }
                                flag = flag && TestBlockPlacementArea(current, ref gridPlacementSettings, false, false);
                            }
                            else
                            {
                                goto TR_001D;
                            }
                            break;
                        }
                    }while (flag);
                }
            }
            goto TR_001D;
        }
        private bool TestPlacement()
        {
            bool retval = true;

            for (int i = 0; i < PreviewGrids.Count; ++i)
            {
                var grid     = PreviewGrids[i];
                var settings = m_settings.GetGridPlacementSettings(grid);

                if (MySession.Static.SurvivalMode && !MyCubeBuilder.DeveloperSpectatorIsBuilding)
                {
                    if (i == 0 && MyCubeBuilder.CameraControllerSpectator)
                    {
                        m_visible = false;
                        return(false);
                    }

                    if (i == 0 && !MyCubeBuilder.Static.DynamicMode)
                    {
                        MatrixD invMatrix = grid.PositionComp.WorldMatrixNormalizedInv;
                        if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref invMatrix, (BoundingBoxD)grid.PositionComp.LocalAABB, grid.GridSize, MyCubeBuilder.Static.IntersectionDistance))
                        {
                            m_visible = false;
                            return(false);
                        }
                    }

                    if (!MySession.Static.SimpleSurvival && MySession.ControlledEntity is MyCharacter)
                    {
                        foreach (var block in grid.GetBlocks())
                        {
                            retval &= (MySession.ControlledEntity as MyCharacter).CanStartConstruction(block.BlockDefinition);
                            if (!retval)
                            {
                                break;
                            }
                        }
                    }

                    if (i == 0 && MySession.Static.SimpleSurvival)
                    {
                        retval = retval && MyCubeBuilder.Static.CanBuildBlockSurvivalTime();
                    }

                    if (!retval)
                    {
                        return(false);
                    }
                }

                if (MyCubeBuilder.Static.DynamicMode)
                {
                    if (!m_dynamicBuildAllowed)
                    {
                        var settingsLocal = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.PastingSettings.LargeGrid : MyPerGameSettings.PastingSettings.SmallGrid;

                        foreach (var block in grid.GetBlocks())
                        {
                            Vector3      minLocal  = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                            Vector3      maxLocal  = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                            BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal);
                            retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, aabbLocal, true);
                        }
                    }
                }
                else if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions)
                {
                    var hitGrid = m_hitEntity as MyCubeGrid;

                    bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small;

                    if (smallOnLargeGrid)
                    {
                        retval = retval && MyCubeGrid.TestPlacementArea(grid, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, false /*, hitGrid*/);
                    }
                    else
                    {
                        retval = retval && TestGridPlacementOnGrid(grid, ref settings, hitGrid);
                    }
                }
                else if (i == 0 && m_hitEntity is MyVoxelMap)
                {
                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock is MyCompoundCubeBlock)
                        {
                            MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                            foreach (var blockInCompound in compoundBlock.GetBlocks())
                            {
                                retval = retval && TestBlockPlacementArea(blockInCompound, ref settings, false);
                                if (!retval)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            retval = retval && TestBlockPlacementArea(block, ref settings, false);
                        }

                        if (!retval)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var settingsLocal = m_settings.GetGridPlacementSettings(grid, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode);
                    retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, (BoundingBoxD)grid.PositionComp.LocalAABB, false);
                }

                BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB;
                MatrixD      invGridWorlMatrix = grid.PositionComp.GetWorldMatrixNormalizedInv();

                // Character collisions.
                if (MySector.MainCamera != null)
                {
                    Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix);
                    retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains;
                }

                if (retval)
                {
                    m_tmpCollisionPoints.Clear();
                    MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints);
                    foreach (var pt in m_tmpCollisionPoints)
                    {
                        Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix);
                        retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains;
                        if (!retval)
                        {
                            break;
                        }
                    }
                }
            }

            return(retval);
        }
        private new bool TestPlacement()
        {
            bool retval = true;

            m_touchingGrids.Clear();

            for (int i = 0; i < PreviewGrids.Count; ++i)
            {
                var grid     = PreviewGrids[i];
                var settings = m_settings.GetGridPlacementSettings(grid.GridSizeEnum);

                m_touchingGrids.Add(null);

                if (MySession.Static.SurvivalMode && !MyCubeBuilder.SpectatorIsBuilding && !MySession.Static.IsAdminModeEnabled(Sync.MyId))
                {
                    if (i == 0 && MyCubeBuilder.CameraControllerSpectator)
                    {
                        m_visible = false;
                        return(false);
                    }

                    if (i == 0 && !MyCubeBuilder.Static.DynamicMode)
                    {
                        MatrixD invMatrix = grid.PositionComp.WorldMatrixNormalizedInv;
                        if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref invMatrix, (BoundingBoxD)grid.PositionComp.LocalAABB, grid.GridSize, MyCubeBuilder.IntersectionDistance))
                        {
                            m_visible = false;
                            return(false);
                        }
                    }

                    /*if (!MySession.Static.SimpleSurvival && MySession.Static.ControlledEntity is MyCharacter)
                     * {
                     *  foreach (var block in grid.GetBlocks())
                     *  {
                     *      retval &= (MySession.Static.ControlledEntity as MyCharacter).CanStartConstruction(block.BlockDefinition);
                     *      if (!retval)
                     *          break;
                     *  }
                     * }
                     *
                     * if (i == 0 && MySession.Static.SimpleSurvival)
                     * {
                     *  retval = retval && MyCubeBuilder.Static.CanBuildBlockSurvivalTime();
                     * }*/

                    if (!retval)
                    {
                        return(false);
                    }
                }

                if (MyCubeBuilder.Static.DynamicMode)
                {
                    // if (!m_dynamicBuildAllowed)
                    //  {
                    var settingsLocal = grid.GridSizeEnum == MyCubeSize.Large ? m_settings.LargeGrid :
                                        m_settings.SmallGrid;
                    bool anyBlockVoxelHit = false;
                    foreach (var block in grid.GetBlocks())
                    {
                        Vector3      minLocal  = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                        Vector3      maxLocal  = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                        BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal);
                        if (!anyBlockVoxelHit)
                        {
                            anyBlockVoxelHit = TestVoxelPlacement(block, ref settings, true);
                        }
                        retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, aabbLocal, true, testVoxel: false);
                        if (!retval)
                        {
                            break;
                        }
                    }

                    retval = retval && anyBlockVoxelHit;
                    // }
                }
                else if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped /* && SnapMode == SnapMode.Base6Directions*/)
                {
                    var hitGrid       = m_hitEntity as MyCubeGrid;
                    var settingsLocal = m_settings.GetGridPlacementSettings(hitGrid.GridSizeEnum, hitGrid.IsStatic);

                    bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small;

                    if (smallOnLargeGrid)
                    {
                        retval = retval && MyCubeGrid.TestPlacementArea(grid, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, false);
                    }
                    else
                    {
                        retval = retval && TestGridPlacementOnGrid(grid, ref settingsLocal, hitGrid);
                    }

                    m_touchingGrids.Clear();
                    m_touchingGrids.Add(hitGrid);
                }
                else if (i == 0 && m_hitEntity is MyVoxelMap)
                {
                    bool anyBlockVoxelHit = false;
                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock is MyCompoundCubeBlock)
                        {
                            MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                            foreach (var blockInCompound in compoundBlock.GetBlocks())
                            {
                                if (!anyBlockVoxelHit)
                                {
                                    anyBlockVoxelHit = TestVoxelPlacement(blockInCompound, ref settings, false);
                                }
                                retval = retval && TestBlockPlacementArea(blockInCompound, ref settings, false, false);
                                if (!retval)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (!anyBlockVoxelHit)
                            {
                                anyBlockVoxelHit = TestVoxelPlacement(block, ref settings, false);
                            }
                            retval = retval && TestBlockPlacementArea(block, ref settings, false, false);
                        }

                        if (!retval)
                        {
                            break;
                        }
                    }

                    retval = retval && anyBlockVoxelHit;

                    Debug.Assert(i == 0);
                    m_touchingGrids[i] = DetectTouchingGrid();
                }
                else
                {
                    var settingsLocal = m_settings.GetGridPlacementSettings(grid.GridSizeEnum, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode);
                    retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, (BoundingBoxD)grid.PositionComp.LocalAABB, false);
                }

                BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB;
                MatrixD      invGridWorlMatrix = grid.PositionComp.WorldMatrixNormalizedInv;

                // Character collisions.
                if (MySector.MainCamera != null)
                {
                    Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix);
                    retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains;
                }

                if (retval)
                {
                    m_tmpCollisionPoints.Clear();
                    MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints);
                    foreach (var pt in m_tmpCollisionPoints)
                    {
                        Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix);
                        retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains;
                        if (!retval)
                        {
                            break;
                        }
                    }
                }
            }

            return(retval);
        }