public Region(Vector2i coords, int fieldsInLine, bool load)
        {
            Coords       = coords;
            FieldsInLine = fieldsInLine;

            RegionBorder = new RegionBorder(new Vector2f(coords.X * 64 * fieldsInLine + (64 * (fieldsInLine / 2)) - 32, coords.Y * 64 * fieldsInLine + (64 * (fieldsInLine / 2)) - 32), new Vector2f(64 * fieldsInLine, 64 * fieldsInLine), TextureManager.Instance.GetTexture("border", "region"));

            if (load)
            {
                Load();
            }
        }
        public void Dispose()
        {
            if (Loaded)
            {
                Fields.ForEach(field => field.Dispose());
                Fields.Clear();

                Enemies.ToList().ForEach(enemy => enemy?.Dispose());
                Enemies.Clear();

                RegionBorder?.Dispose();
                Player?.Dispose();

                Player       = null;
                Activity     = null;
                RegionBorder = null;
                MessageBus.Instance.Unregister(MessageType.PawnDeath, OnPawnDeath);
            }
        }
        /// <summary>
        /// This assumes edges are in order.
        /// </summary>
        private void CreateNoisyEdges()
        {
            if (id == 96)
            {
                Debug.Log("paws plx");
            }
            regionBorders = new List <RegionBorder>();
            List <VEdge> vEdges      = polygon.GetVoronoiEdges();
            VEdge        currentEdge = vEdges[0];
            VEdge        lastEdge    = vEdges[vEdges.Count - 1];

            if (!currentEdge.SharesCorner(lastEdge, out Corner sharedCorner))
            {
                Debug.LogError("Edges are not in order in region " + id);
            }
            else
            {
                if (sharedCorner != currentEdge.start)
                {
                    currentEdge.ReverseEndPoints();
                }
                if (sharedCorner != lastEdge.end)
                {
                    lastEdge.ReverseEndPoints();
                }
            }

            for (int i = 0; i < vEdges.Count; ++i)
            {
                if (i > 0)
                {
                    currentEdge = vEdges[i];
                    lastEdge    = vEdges[i - 1];
                    if (!currentEdge.SharesCorner(lastEdge, out sharedCorner))
                    {
                        Debug.LogError("Edges are not in order in region " + id);
                    }
                    else
                    {
                        if (sharedCorner != currentEdge.start)
                        {
                            currentEdge.ReverseEndPoints();
                        }

                        if (sharedCorner != lastEdge.end)
                        {
                            lastEdge.ReverseEndPoints();
                        }
                    }
                }

                RegionBorder border = new RegionBorder(currentEdge, Instantiate(borderRenderer, borders));
                regionBorders.Add(border);
            }

            RegionBorder lastBorder  = regionBorders[regionBorders.Count - 1];
            RegionBorder firstBorder = regionBorders[0];

            if (!lastBorder.edge.SharesCorner(firstBorder.edge, out sharedCorner))
            {
                Debug.LogError("MAJOR ERROR: Edges are not in order in region " + id);
            }
            else
            {
                if (sharedCorner != lastBorder.edge.end || sharedCorner != firstBorder.edge.start)
                {
                    Debug.LogError("Last and first edges do not line up in region " + id + " edge " + lastBorder.edge.id);
                }
            }
        }
 private void DetermineRegionNeighbors()
 {
     foreach (Region region in base.Context.Regions.Values)
     {
         List <Frontier> list = new List <Frontier>();
         foreach (District district in region.Districts)
         {
             foreach (HexPos hexPos in district)
             {
                 foreach (HexPos hexPos2 in base.Context.Grid.Adjacents(hexPos))
                 {
                     int      key       = base.Context.DistrictData[hexPos2.Row, hexPos2.Column];
                     District district2 = base.Context.Districts[key];
                     if (district2 != null)
                     {
                         Region neighborRegion = district2.MotherRegion;
                         if (neighborRegion != null && region.Id != neighborRegion.Id)
                         {
                             if (!district.Neighbours.Contains(district2))
                             {
                                 district.Neighbours.Add(base.Context.Districts[key]);
                             }
                             RegionBorder regionBorder;
                             if (region.Borders.ContainsKey(neighborRegion))
                             {
                                 regionBorder = region.Borders[neighborRegion];
                             }
                             else
                             {
                                 regionBorder = new RegionBorder(region, neighborRegion);
                                 region.Borders.Add(neighborRegion, regionBorder);
                             }
                             if (!regionBorder.Contains(hexPos))
                             {
                                 regionBorder.Add(hexPos);
                             }
                             Frontier frontier = list.FirstOrDefault((Frontier tmpFront) => tmpFront.Neighbour == neighborRegion.Id);
                             if (frontier == null)
                             {
                                 frontier = new Frontier
                                 {
                                     Neighbour = neighborRegion.Id,
                                     Points    = new List <Frontier.Point>()
                                 };
                                 list.Add(frontier);
                             }
                             bool flag = false;
                             for (int i = 0; i < frontier.Points.Count; i++)
                             {
                                 if (frontier.Points[i].Hex == hexPos)
                                 {
                                     flag = true;
                                 }
                             }
                             if (!flag)
                             {
                                 frontier.Points.Add(new Frontier.Point
                                 {
                                     From = (int)neighborRegion.Id,
                                     Hex  = hexPos
                                 });
                             }
                         }
                     }
                 }
             }
         }
         region.Frontiers = list.ToArray();
         if (region.Neighbours.Count == 1)
         {
             base.ReportTmx("?NestedRegion");
         }
     }
 }