예제 #1
0
        /// <summary>
        /// Load the course info from the current map.
        /// </summary>
        public void LoadFromMap()
        {
            Host.AssertServer();

            Holes.Clear();
            foreach (var hole in Entity.All.OfType <HoleSpawn>())
            {
                var goal = Entity.All.OfType <HoleGoal>().Where(x => x.Hole == hole.Number).First();

                if (goal == null)
                {
                    Log.Error($"No ball goal found for [Hole {hole.Number}]");
                    continue;
                }

                Log.Info($"Hole ({hole.Number}) - {hole.Name}");

                // todo: sort this list

                Holes.Add(new HoleInfo()
                {
                    Number = hole.Number,
                    // Name = hole.Name,
                    Par           = hole.Par,
                    SpawnPosition = hole.Position,
                    SpawnAngles   = hole.WorldAng,
                    // GoalPosition = goal.Position,
                    // Bounds = Entity.All.OfType<HoleBounds>().Where(x => x.Hole == hole.Number).ToList()
                });
            }
        }
예제 #2
0
        public void GenerateHolesR()
        {
            if (Holes.Count == 5)
            {
                return;
            }

            int x = r.Next(50, 700);
            int y = r.Next(50, 350);

            bool touch = false;

            foreach (Hole d in Holes)
            {
                touch = d.Colliding(new Hole(new Point(x, y)));

                if (touch)
                {
                    break;
                }
            }

            if (!touch)
            {
                Holes.Add(new Hole(new Point(x, y)));
            }
            GenerateHolesR();
        }
예제 #3
0
파일: Polygon2f.cs 프로젝트: andybak/CGAL
        public void AddHole(Polygon2f hole)
        {
            if (hole.HasHoles)
            {
                throw new  NotImplementedException("Hole with holes not implemented.");
            }

            if (Holes == null)
            {
                Holes = new List <Polygon2f>();
            }

            Holes.Add(hole);
        }
예제 #4
0
    private void SplitHorizontalAt(Stack <Region> regionsToSplit, Region beingSplitted, int splitY)
    {
        //Get the number of holes.
        int holes = Settings.HolesInLine(beingSplitted.Width + 1);

        if (holes < 1)
        {
            holes = 1;
        }
        if (holes >= beingSplitted.Width + 1)
        {
            Regions.Add(beingSplitted);
            return;
        }

        //First make the line.
        for (int i = beingSplitted.Left; i <= beingSplitted.Right; ++i)
        {
            Map[i, splitY] = true;
        }
        //Make sure the line isn't blocking a hole at the edge of the region.
        if (beingSplitted.Left > 0 && (!Map[beingSplitted.Left - 1, splitY] || Holes.Contains(new Location(beingSplitted.Left - 1, splitY))))
        {
            Map[beingSplitted.Left, splitY] = false;
            Holes.Add(new Location(beingSplitted.Left, splitY));
        }
        if (beingSplitted.Right < Map.GetLength(1) - 1 && (!Map[beingSplitted.Right + 1, splitY] || Holes.Contains(new Location(beingSplitted.Right + 1, splitY))))
        {
            Map[beingSplitted.Right, splitY] = false;
            Holes.Add(new Location(beingSplitted.Right, splitY));
        }
        //Now make holes.

        //Get the possible cells to put a hole in.
        List <int> cellXs = new List <int>(beingSplitted.Width + 1);

        for (int i = 0; i < beingSplitted.Width + 1; ++i)
        {
            cellXs.Add(i + beingSplitted.Left);
        }

        //Randomly pick from them.
        int randomIndex;

        for (int i = 0; i < holes; ++i)
        {
            randomIndex = MathF.R.Next(0, cellXs.Count);

            Map[cellXs[randomIndex], splitY] = false;
            Holes.Add(new Location(cellXs[randomIndex], splitY));

            cellXs.RemoveAt(randomIndex);
        }

        //Now split the region into two regions (assuming both regions are large enough). Move the regions around a bit to make sure the line we just made is not part of the regions.
        Region one = new Region(beingSplitted.TopLeft, new Location {
            X = beingSplitted.Right, Y = splitY - 1
        });
        Region two = new Region(new Location {
            X = beingSplitted.Left, Y = splitY + 1
        }, beingSplitted.BottomRight);

        if (one.Width >= 0 && one.Height >= 0 && one.Left >= 0 && one.Right < Map.GetLength(0) && one.Top >= 0 && one.Bottom < Map.GetLength(1))
        {
            regionsToSplit.Push(one);
        }
        if (two.Width >= 0 && two.Height >= 0 && two.Left >= 0 && two.Right < Map.GetLength(0) && two.Top >= 0 && two.Bottom < Map.GetLength(1))
        {
            regionsToSplit.Push(two);
        }
    }
예제 #5
0
 public virtual void AddHole(Hole hole)
 {
     hole.Courseconfiguration = this;
     Holes.Add(hole);
 }
예제 #6
0
 public void AddHole(int contourId)
 {
     Holes.Add(contourId);
 }
예제 #7
0
    private void FillTunnels()
    {
        //Go through all nodes and make tunnels,
        //  with special edge tunnels around the perimeter (if the level wraps around).
        Location lastNodePos = (Settings.TunnelLength + MaxRoomSize) * (Settings.NumberOfNodes - new Location(1, 1));
        Location topLeft, nextTopLeft;
        Region   beingCleared;

        foreach (PositionalNode n in NodeStates.Keys)//Graph.AllNodes(new PositionalNode(new float[2] { 1.0f, 1.0f }, 0)))
        {
            //Fill in the tunnel to the right and down from this cell.

            //Down.
            if (n.Coordinate[1] < lastNodePos.Y)
            {
                topLeft = new Location(VerticalTunnelX((int)n.Coordinate[0]), NodeAreas[n].Bottom);
                if (NodeStates[n] == NodeState.Room)
                {
                    topLeft = topLeft.Below;
                }
                nextTopLeft = NodeAreas[new PositionalNode(new float[2] {
                    n.Coordinate[0], n.Coordinate[1] + MaxRoomSize.Y + Settings.TunnelLength.Y
                }, 0)].TopLeft;

                beingCleared = new Region(topLeft, new Location(topLeft.X + Settings.TunnelThickness.Y - 1, nextTopLeft.Y - 1));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int x = beingCleared.Left; x <= beingCleared.Right; ++x)
                {
                    Holes.Add(new Location(x, beingCleared.Top));
                    Holes.Add(new Location(x, beingCleared.Bottom));
                }
            }
            //Right.
            if (n.Coordinate[0] < lastNodePos.X)
            {
                topLeft     = new Location(NodeAreas[n].Right, HorizontalTunnelY((int)n.Coordinate[1])).Right;
                nextTopLeft = NodeAreas[new PositionalNode(new float[2] {
                    n.Coordinate[0] + MaxRoomSize.X + Settings.TunnelLength.X, n.Coordinate[1]
                }, 0)].TopLeft;

                beingCleared = new Region(topLeft, new Location(nextTopLeft.X - 1, topLeft.Y + Settings.TunnelThickness.X - 1));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int y = beingCleared.Top; y <= beingCleared.Bottom; ++y)
                {
                    Holes.Add(new Location(beingCleared.Left, y));
                    Holes.Add(new Location(beingCleared.Right, y));
                }
            }

            //Border cases.

            //Left border.
            if (Settings.WrapAroundX && n.Coordinate[0] == 1.0f)
            {
                topLeft     = new Location(0, HorizontalTunnelY((int)n.Coordinate[1]));
                nextTopLeft = NodeAreas[n].TopLeft.Left;

                beingCleared = new Region(topLeft, new Location(nextTopLeft.X, topLeft.Y + Settings.TunnelThickness.X - 1));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int y = beingCleared.Top; y <= beingCleared.Bottom; ++y)
                {
                    Holes.Add(new Location(beingCleared.Right, y));
                }
            }
            //Top border.
            if (Settings.WrapAroundY && n.Coordinate[1] == 1.0f)
            {
                topLeft     = new Location(VerticalTunnelX((int)n.Coordinate[0]), 0);
                nextTopLeft = NodeAreas[n].TopLeft.Above;

                beingCleared = new Region(topLeft, new Location(topLeft.X + Settings.TunnelThickness.Y - 1, nextTopLeft.Y));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int x = beingCleared.Left; x <= beingCleared.Right; ++x)
                {
                    Holes.Add(new Location(x, beingCleared.Bottom));
                }
            }
            //Right border.
            if (Settings.WrapAroundX && n.Coordinate[0] == lastNodePos.X + 1)
            {
                topLeft = new Location(NodeAreas[n].Right, HorizontalTunnelY((int)n.Coordinate[1])).Right;

                beingCleared = new Region(topLeft, new Location(Map.GetLength(0) - 1, topLeft.Y + Settings.TunnelThickness.X - 1));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int y = beingCleared.Top; y <= beingCleared.Bottom; ++y)
                {
                    Holes.Add(new Location(beingCleared.Left, y));
                }
            }
            //Bottom border.
            if (Settings.WrapAroundY && n.Coordinate[1] == lastNodePos.Y + 1)
            {
                topLeft = new Location(VerticalTunnelX((int)n.Coordinate[0]), NodeAreas[n].Bottom).Below;

                beingCleared = new Region(topLeft, new Location(topLeft.X + Settings.TunnelThickness.Y - 1, Map.GetLength(1) - 1));
                FillData.FillRegion(false, beingCleared);
                Regions.Add(beingCleared);

                for (int x = beingCleared.Left; x <= beingCleared.Right; ++x)
                {
                    Holes.Add(new Location(x, beingCleared.Top));
                }
            }
        }
    }