예제 #1
0
    private void RecalculateConnections()
    {
        RegionConnectionManager.Remove(this);
        _connections = new HashSet <Connection>();
        blackList    = new HashSet <Vector2>();

        foreach (Vector2 position in _ownedPositions)
        {
            for (int i = 0; i < _directions.Count; i++)
            {
                if (!_ownedPositions.Contains(position + _directions[i]) && IsValid(position + _directions[i]))
                {
                    CreateConnection(position, _directions[i]);
                }
            }
        }

        RegionConnectionManager.Add(this);
    }
    public static void SetDirty(Vector2 position)
    {
        position = position.ToCellPosition();

        if (_dirtyCells.Contains(position) || !_regionPositions.ContainsKey(position))
        {
            return;
        }

        Region region = _regionPositions[position];

        RegionConnectionManager.Remove(region);
        _regions.Remove(region);

        foreach (Vector2 ownedPos in region.OwnedPositions)
        {
            _regionPositions.Remove(ownedPos);
            _dirtyCells.Add(ownedPos);
        }
    }
    private static void ExecuteFullRegeneration()
    {
        foreach (Region region in _regions)
        {
            RegionConnectionManager.Remove(region);
        }

        _dirtyCells      = new List <Vector2>();
        _regionPositions = new Dictionary <Vector2, Region>();
        _regions         = new HashSet <Region>();

        for (int x = 0; x < MapData.MAPSIZE; x++)
        {
            for (int y = 0; y < MapData.MAPSIZE; y++)
            {
                Vector2 pos = new Vector2(x, y);

                if (!Contains(pos) && IsValid(pos))
                {
                    Create(pos);
                }
            }
        }
    }