Beispiel #1
0
        public override void OnKill()
        {
            if (Network.Tiles.Count == 1)
            {
                GelumNetwork.Networks.Remove(Network);
            }
            else if (GetNeighbors().Count() == 1)
            {
                Network.Tiles.Remove(this);
            }
            else
            {
                List <Point16>         visited     = new List <Point16>();
                List <List <Point16> > newNetworks = new List <List <Point16> >();

                foreach (BaseGelumTE duct in GetNeighbors())
                {
                    if (visited.Contains(duct.Position))
                    {
                        continue;
                    }

                    visited.Add(duct.Position);

                    List <Point16> p = new List <Point16> {
                        Position, duct.Position
                    };
                    GetNeighborsRecursive(duct, p);
                    visited.AddRange(p);

                    p.Remove(Position);
                    newNetworks.Add(p);
                }

                if (newNetworks.Count <= 1)
                {
                    Network.Tiles.Remove(this);
                }
                else
                {
                    for (int i = 0; i < newNetworks.Count; i++)
                    {
                        GelumNetwork network = new GelumNetwork
                        {
                            Tiles = newNetworks[i].Select(position => ByPosition[position] as BaseGelumTE).ToList()
                        };
                        foreach (BaseGelumTE duct in network.Tiles)
                        {
                            GelumNetwork.Networks.Remove(duct.Network);
                            duct.Network = network;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public override void OnPlace()
        {
            List <GelumNetwork> networks = GetNeighbors().Select(duct => duct.Network).Distinct().ToList();
            GelumNetwork        network  = new GelumNetwork
            {
                Tiles = networks.SelectMany(routedNetwork => routedNetwork.Tiles).Concat(this).ToList()
            };

            foreach (BaseGelumTE duct in network.Tiles)
            {
                GelumNetwork.Networks.Remove(duct.Network);
                duct.Network = network;
            }
        }