示例#1
0
        public static CombinationTable.Combination FindPossibleCombination(Rail.JunctionPiece Piece, Body Entity)
        {
            if (Entity is RailEntity)
            {
                var baseJunction        = (Entity as RailEntity).GetPiece();
                var basePiece           = Rail.RailLibrary.GetRailPiece(baseJunction.RailPiece);
                var relativeOrientation = Rail.OrientationHelper.Relative(baseJunction.Orientation, Piece.Orientation);

                if (basePiece.Name == Piece.RailPiece && relativeOrientation == PieceOrientation.North)
                {
                    return new CombinationTable.Combination
                           {
                               Result = basePiece.Name,
                               ResultRelativeOrientation = PieceOrientation.North
                           }
                }
                ;

                var matchingCombination = RailLibrary.CombinationTable.FindCombination(
                    basePiece.Name, Piece.RailPiece, relativeOrientation);
                return(matchingCombination);
            }

            return(null);
        }
示例#2
0
        public static bool CanPlace(WorldManager World, RailEntity PreviewEntity)
        {
            // Todo: Make sure this uses BuildObjectTool.IsValidPlacement to enforce building rules.

            var junctionPiece  = PreviewEntity.GetPiece();
            var actualPosition = PreviewEntity.GetContainingVoxel();

            if (!actualPosition.IsValid)
            {
                return(false);
            }
            if (!actualPosition.IsEmpty)
            {
                return(false);
            }

            if (actualPosition.Coordinate.Y == 0)
            {
                return(false);                                  // ???
            }
            var voxelUnder = VoxelHelpers.GetVoxelBelow(actualPosition);

            if (voxelUnder.IsEmpty)
            {
                return(false);
            }
            var box = actualPosition.GetBoundingBox().Expand(-0.2f);

            foreach (var entity in World.EnumerateIntersectingObjects(box, CollisionType.Static))
            {
                if ((entity as GameComponent).IsDead)
                {
                    continue;
                }

                if (Object.ReferenceEquals(entity, PreviewEntity))
                {
                    continue;
                }
                if (Object.ReferenceEquals(entity.GetRoot(), PreviewEntity.GetRoot()))
                {
                    continue;
                }
                if (entity is GenericVoxelListener)
                {
                    continue;
                }
                if (entity is WorkPile)
                {
                    continue;
                }
                if (entity is Health)
                {
                    continue;
                }
                if (entity is CraftDetails)
                {
                    continue;
                }
                if (entity is SimpleSprite)
                {
                    continue;
                }

                if (FindPossibleCombination(junctionPiece, entity).HasValue(out var possibleCombination))
                {
                    var combinedPiece = new Rail.JunctionPiece
                    {
                        RailPiece   = possibleCombination.Result,
                        Orientation = Rail.OrientationHelper.Rotate((entity as RailEntity).GetPiece().Orientation, (int)possibleCombination.ResultRelativeOrientation),
                    };

                    PreviewEntity.UpdatePiece(combinedPiece, PreviewEntity.GetContainingVoxel());
                    return(true);
                }

                if (Debugger.Switches.DrawToolDebugInfo)
                {
                    Drawer3D.DrawBox(box, Color.Yellow, 0.2f, false);
                }

                World.UserInterface.ShowTooltip(String.Format("Can't place {0}. Entity in the way: {1}", junctionPiece.RailPiece, entity.ToString()));
                return(false);
            }

            return(true);
        }
示例#3
0
        public static MaybeNull <CombinationTable.Combination> FindPossibleCombination(Rail.JunctionPiece Piece, GameComponent Entity)
        {
            if (Entity is RailEntity)
            {
                var baseJunction = (Entity as RailEntity).GetPiece();
                if (Library.GetRailPiece(baseJunction.RailPiece).HasValue(out var basePiece))
                {
                    var relativeOrientation = Rail.OrientationHelper.Relative(baseJunction.Orientation, Piece.Orientation);

                    if (basePiece.Name == Piece.RailPiece && relativeOrientation == PieceOrientation.North)
                    {
                        return new CombinationTable.Combination
                               {
                                   Result = basePiece.Name,
                                   ResultRelativeOrientation = PieceOrientation.North
                               }
                    }
                    ;

                    var matchingCombination = Library.FindRailCombination(basePiece.Name, Piece.RailPiece, relativeOrientation);
                    return(matchingCombination);
                }
            }

            return(null);
        }
示例#4
0
        public static bool CanPlace(GameMaster Player, RailEntity PreviewEntity)
        {
            // Todo: Make sure this uses BuildObjectTool.IsValidPlacement to enforce building rules.

            var junctionPiece  = PreviewEntity.GetPiece();
            var actualPosition = PreviewEntity.GetContainingVoxel();

            if (!actualPosition.IsValid)
            {
                return(false);
            }
            if (!actualPosition.IsEmpty)
            {
                return(false);
            }

            if (actualPosition.Coordinate.Y == 0)
            {
                return(false);                                  // ???
            }
            var local      = actualPosition.Coordinate.GetLocalVoxelCoordinate();
            var voxelUnder = new VoxelHandle(actualPosition.Chunk, new LocalVoxelCoordinate(local.X, local.Y - 1, local.Z));

            if (voxelUnder.IsEmpty)
            {
                return(false);
            }

            foreach (var entity in Player.World.EnumerateIntersectingObjects(actualPosition.GetBoundingBox().Expand(-0.2f), CollisionType.Static))
            {
                if ((entity as GameComponent).IsDead)
                {
                    continue;
                }

                if (Object.ReferenceEquals(entity, PreviewEntity))
                {
                    continue;
                }
                if (entity is GenericVoxelListener)
                {
                    continue;
                }
                if (entity is WorkPile)
                {
                    continue;
                }

                var possibleCombination = FindPossibleCombination(junctionPiece, entity);
                if (possibleCombination != null)
                {
                    var combinedPiece = new Rail.JunctionPiece
                    {
                        RailPiece   = possibleCombination.Result,
                        Orientation = Rail.OrientationHelper.Rotate((entity as RailEntity).GetPiece().Orientation, (int)possibleCombination.ResultRelativeOrientation),
                    };

                    PreviewEntity.UpdatePiece(combinedPiece, PreviewEntity.GetContainingVoxel());
                    return(true);
                }

                if (Debugger.Switches.DrawBoundingBoxes)
                {
                    Drawer3D.DrawBox(entity.GetBoundingBox(), Color.Yellow, 0.1f, false);
                    Player.World.ShowTooltip(String.Format("Can't place {0}. Entity in the way: {1}", junctionPiece.RailPiece, entity.ToString()));
                }

                return(false);
            }

            return(true);
        }