Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void RemoveCableFromNetwork(Cable removedCable)
- {
- if (GameManager.GameState != GameState.None)
- {
- CableNetwork oldCableNetwork = removedCable.CableNetwork;
- Queue<Cable> checkedCable = new Queue<Cable>(); // leave this empty to optimize the search below... if the first cable finds a neighbor, no sense checking.
- // start with the removed cables neighbors and we'll recurse from there keeping these as hard barriers
- foreach(Cable neighbor in removedCable.ConnectedCables())
- {
- if (!checkedCable.Contains(neighbor))
- {
- checkedCable.Enqueue(neighbor);
- CableNetwork newCableNetwork = new CableNetwork(neighbor);
- Queue<Cable> cableQueue = new Queue<Cable>(neighbor);
- // start with that and add all the neighbors as we walk through.
- while(cableQueue.Count > 0)
- {
- Cable thisCable = cableQueue.Dequeue();
- foreach (Cable thatCableNeighbor in thisCable.ConnectedCables())
- {
- if (thatCableNeighbor != removedCable && !checkedCable.Contains(thatCableNeighbor) && !newCableNetwork.CableList.Contains(thatCableNeighbor))
- {
- newCableNetwork.AddCable(thatCableNeighbor);
- oldCableNetwork.RemoveCable(thatCableNeighbor);
- checkedCable.Enqueue(thatCableNeighbor);
- cableQueue.Enqueue(thatCableNeighbor);
- }
- }
- foreach (Device device in thisCable.ConnectedDevices())
- {
- oldCableNetwork.RemoveDevice(thisCable, device);
- }
- }
- }
- }
- if (CableNetwork.OnNetworkChanged != null)
- {
- CableNetwork.OnNetworkChanged();
- }
- // Is this needed?
- // foreach (Device device in removedCable.ConnectedDevices())
- // {
- // oldCableNetwork.RemoveDevice(thisCable, device);
- // }
- oldCableNetwork.RemoveCable(removedCable);
- }
- }
Add Comment
Please, Sign In to add comment