예제 #1
0
 public ZoneKey(MapEventZone zone)
 {
     if (zone == null)
     {
         throw new ArgumentNullException(nameof(zone));
     }
     Global      = zone.Global;
     Unk1        = zone.Unk1;
     Trigger     = zone.Trigger;
     Chain       = zone.Chain;
     DummyNumber = 0;
     Node        = zone.Node;
 }
예제 #2
0
    public static IList <(ZoneKey, Geometry.Polygon)> BuildZones(BaseMapData map)
    {
        if (map == null)
        {
            throw new ArgumentNullException(nameof(map));
        }

        // Render zones to a grid
        var zoneMap = new MapEventZone[map.Width * map.Height];

        Array.Copy(map.Zones, zoneMap, zoneMap.Length);

        var regions = new List <(ZoneKey key, IList <(int, int)> region)>();

        for (int index = 0; index < zoneMap.Length; index++)
        {
            var current = zoneMap[index];
            if (current == null)
            {
                continue;
            }

            FillZone(regions, zoneMap, map.Width, current, index);
        }

        RemoveVoids(regions);

        var edgeSets = regions.Select(x => (x.key, FindRegionEdges(x.region))).ToList();

        // zoneMap should be empty now
        ApiUtil.Assert(zoneMap.All(x => x == null));

        // Stitch edges together
        for (int i = 0; i < edgeSets.Count; i++)
        {
            edgeSets[i] = (edgeSets[i].Item1, MergeEdges(edgeSets[i].Item2));
        }

        // Follow edges clockwise to build poly
        return(edgeSets
               .SelectMany(x =>
                           BuildPolygonsFromSortedEdges(x.Item2)
                           .Select(y => (x.Item1, y)))
               .ToList());
    }