public override void OnPlace(BaseLayerItem item) { if (item is BaseDuct d) { Tier = d.Tier; switch (Tier) { case DuctTier.Basic: Speed = 20; break; case DuctTier.Advanced: Speed = 12; break; case DuctTier.Elite: Speed = 5; break; } } List <RoutedNetwork> networks = GetNeighbors().Select(duct => duct.Network).Distinct().ToList(); RoutedNetwork network = new RoutedNetwork { Tiles = networks.SelectMany(routedNetwork => routedNetwork.Tiles).Concat(this).ToList(), NetworkItems = networks.SelectMany(routedNetwork => routedNetwork.NetworkItems).ToList() }; foreach (Duct duct in network.Tiles) { RoutedNetwork.Networks.Remove(duct.Network); duct.Network = network; } foreach (Duct duct in network.Tiles) { if ((duct.frame & 1) != 0 && (duct.frame & 16) != 0 && (duct.frame & 4) == 0 && (duct.frame & 64) == 0) { duct.isNode = false; } else if ((duct.frame & 1) == 0 && (duct.frame & 16) == 0 && (duct.frame & 4) != 0 && (duct.frame & 64) != 0) { duct.isNode = false; } else { duct.isNode = true; } } }
public override void Load(List <TagCompound> list) { data.Clear(); RoutedNetwork.Networks.Clear(); foreach (TagCompound compound in list) { RoutedNetwork network = new RoutedNetwork(); network.Load(compound); } foreach (Duct duct in data.Values) { duct.UpdateFrame(); } }
public override void OnRemove() { if (Network.Tiles.Count == 1) { RoutedNetwork.Networks.Remove(Network); } else if (GetNeighbors().Count() == 1) { Network.Tiles.Remove(this); foreach (Duct duct in Network.Tiles) { if ((duct.frame & 1) != 0 && (duct.frame & 16) != 0 && (duct.frame & 4) == 0 && (duct.frame & 64) == 0) { duct.isNode = false; } else if ((duct.frame & 1) == 0 && (duct.frame & 16) == 0 && (duct.frame & 4) != 0 && (duct.frame & 64) != 0) { duct.isNode = false; } else { duct.isNode = true; } } } else { List <Point16> visited = new List <Point16>(); List <List <Point16> > newNetworks = new List <List <Point16> >(); foreach (Duct 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); Network.CheckPaths(); } else { for (int i = 0; i < newNetworks.Count; i++) { RoutedNetwork network = new RoutedNetwork { Tiles = newNetworks[i].Select(position => Layer[position]).ToList(), NetworkItems = newNetworks[i].Select(position => Layer[position].Network).Distinct().SelectMany(routedNetwork => routedNetwork.NetworkItems).ToList() }; network.CheckPaths(); foreach (Duct duct in network.Tiles) { duct.Network.NetworkItems.Clear(); RoutedNetwork.Networks.Remove(duct.Network); duct.Network = network; if ((duct.frame & 1) != 0 && (duct.frame & 16) != 0 && (duct.frame & 4) == 0 && (duct.frame & 64) == 0) { duct.isNode = false; } else if ((duct.frame & 1) == 0 && (duct.frame & 16) == 0 && (duct.frame & 4) != 0 && (duct.frame & 64) != 0) { duct.isNode = false; } else { duct.isNode = true; } } } } } }