Exemple #1
0
 public void ApplyFillPatterns()
 {
     FilledRegions.Clear();
     while (iterateFillPatternsRegionCount < Regions.Count)
     {
         IterateFillPattern();
     }
     return;
 }
    public void IterateFillPattern()
    {
        if (DoneFillPatterns)
        {
            return;
        }

        //Get the current node.
        PositionalNode n = NeedToApply.Current;

        //If it is a junction, ignore it for now.
        //FilledRegions covering junctions/tunnels will be
        //   added after fill patterns are applied to rooms.
        if (NodeStates[n] == NodeState.TunnelJunction)
        {
            DoneFillPatterns = !NeedToApply.MoveNext();
            return;
        }

        //Get the best fill pattern for it and apply it if one exists.
        FillPattern  p = Settings.MostSuitable(NodeAreas[n]);
        FilledRegion tempF;

        if (p != null)
        {
            FillData.BeingFilled = NodeAreas[n];
            tempF = p.Apply(FillData);
            //If the area has no team spawns, add one at the top.
            if (tempF.PotentialSpawns[Spawns.Team].Count == 0 && tempF.Covering.Width + 1 >= 4)
            {
                tempF.PotentialSpawns[Spawns.Team].Add(new Region(tempF.Covering.Left, tempF.Covering.Top, tempF.Covering.Width, 0));
            }
            FilledRegions.Add(tempF);
        }
        else
        {
            FilledRegions.Add(new NoRegion(NodeAreas[n]));
        }

        //Continue the iteration.
        DoneFillPatterns = !NeedToApply.MoveNext();
    }
    //Making FilledRegions for tunnels.
    public void AfterFillPatterns()
    {
        //First, see if there are enough team base spawns just going by the rooms.
        //If there are, then we won't use any team spawns in tunnels.

        const int maxNumbTeams = 8;
        int       teamSpawns   = 0;

        foreach (FilledRegion f in FilledRegions)
        {
            teamSpawns += f.PotentialSpawns[Spawns.Team].Count;
        }
        bool enoughSpawns = teamSpawns >= maxNumbTeams;

        //Find all tunnel regions and make a FilledRegion for them.

        TunnelRegion  temp;
        List <Region> rooms = new List <Region>();

        foreach (PositionalNode key in NodeAreas.Keys)
        {
            if (NodeStates[key] == NodeState.Room)
            {
                rooms.Add(NodeAreas[key]);
            }
        }
        foreach (Region r in Regions)
        {
            if (!rooms.Contains(r))
            {
                temp = new TunnelRegion(r, Map);
                if (enoughSpawns)
                {
                    temp.PotentialSpawns[Spawns.Team].Clear();
                }

                FilledRegions.Add(temp);
            }
        }
    }
Exemple #4
0
    public void IterateFillPattern()
    {
        //Already done?
        if (iterateFillPatternsRegionCount >= Regions.Count)
        {
            return;
        }

        //Run an iteration.

        FilledRegion temp;
        Region       r = Regions[iterateFillPatternsRegionCount];

        iterateFillPatternsRegionCount++;

        //Pick a random applicable pattern (assuming one exists) and apply it.
        FillPattern p = Settings.MostSuitable(r);

        if (p != null)
        {
            //Clear the space, and apply the pattern.
            FillData.BeingFilled = r;
            FillData.FillRegion(false, r);
            temp = p.Apply(FillData);

            //If the filled region is blank, replace it with a BlankRegion.
            bool blank = true;
            for (int i = temp.Covering.Left; i <= temp.Covering.Right; ++i)
            {
                for (int j = temp.Covering.Top; j <= temp.Covering.Bottom; ++j)
                {
                    if (FillData.GetMapAt(new Location(i, j)))
                    {
                        blank = false;
                        break;
                    }
                }
                if (!blank)
                {
                    break;
                }
            }
            if (blank)
            {
                temp = new BlankRegion(temp.Covering);
            }

            //Now add it.
            FilledRegions.Add(temp);
            Region r2;

            //Make sure the spawn points are all valid.
            foreach (Spawns s in FilledRegions[FilledRegions.Count - 1].PotentialSpawns.Keys)
            {
                for (int i = 0; i < FilledRegions[FilledRegions.Count - 1].PotentialSpawns[s].Count; ++i)
                {
                    r2 = FilledRegions[FilledRegions.Count - 1].PotentialSpawns[s][i];

                    if (r2.Width < 0 || r2.Height < 0)
                    {
                        FilledRegions[FilledRegions.Count - 1].PotentialSpawns[s].RemoveAt(i--);
                    }
                }
            }
        }
        //If no regions fit, add a "NoRegion".
        else
        {
            FilledRegions.Add(new NoRegion(r));
        }
    }