public bool RemoveFromGraph() { if (IsRoot) { Graph.Root = HasNeighbors ? this[0] : (_cannotVisitNeighbors.Length > 0 ? _cannotVisitNeighbors[0] : null); if (Graph.Root == null) { Graph.Root = this; return(false); } } if (this == Graph.LastAddedNode) { Graph.LastAddedNode = HasNeighbors ? this[0] : (_cannotVisitNeighbors.Length > 0 ? _cannotVisitNeighbors[0] : null); } --Graph.Size; ++Graph._removedNodes; for (int i = 0; i < _neighbors.Length; ++i) { MyLib.ArrayRemoveOne(ref this[i]._cannotVisitNeighbors, this); } for (int i = 0; i < _cannotVisitNeighbors.Length; ++i) { _cannotVisitNeighbors[i].RemoveNeighbor(this); } _neighbors = null; _cannotVisitNeighbors = null; return(true); }
public void CheckAndFixTeams() { MyLib.ArrayRemoveDuplicates(ref _enemyTeams); MyLib.ArrayRemoveDuplicates(ref _alliedTeams); MyLib.ArrayRemoveDuplicates(ref _neutralTeams); MyLib.ArrayRemoveOne(ref _enemyTeams, this); MyLib.ArrayRemoveOne(ref _neutralTeams, this); int index = _alliedTeams.FindIndex(this); if (index == -1) { MyLib.ArrayInsert(ref _alliedTeams, this, 0); } else { _alliedTeams[index] = _alliedTeams[0]; _alliedTeams[0] = this; } }
public bool AddNeighbor(Node newNeighbor, float dist = 1f) { if (!CanBeNeighbor(newNeighbor)) { return(false); } if (dist != 1f) { MyLib.ExpandArray(ref _neighbors, new NeighborAndDistance(newNeighbor, dist)); Graph.CostedConnections = true; } else { MyLib.ExpandArray(ref _neighbors, new NeighborAndDistance(newNeighbor, 1f)); } MyLib.ArrayRemoveOne(ref _cannotVisitNeighbors, newNeighbor); if (!newNeighbor.IsNeighboringTo(this)) { MyLib.ExpandArray(ref newNeighbor._cannotVisitNeighbors, this); } return(true); }
private bool AddNeighbor(Node newNeighbor, bool addCannotVisit, float dist = 1f) { if (addCannotVisit) { return(AddNeighbor(newNeighbor, dist)); } if (!CanBeNeighbor(newNeighbor)) { return(false); } if (dist != 1f) { MyLib.ExpandArray(ref _neighbors, new NeighborAndDistance(newNeighbor, dist)); Graph.CostedConnections = true; } else { MyLib.ExpandArray(ref _neighbors, new NeighborAndDistance(newNeighbor, 1f)); } MyLib.ArrayRemoveOne(ref _cannotVisitNeighbors, newNeighbor); return(true); }
public void RemoveNeighbor(Node exNeighbor) { MyLib.ArrayRemoveOne(ref _neighbors, x => x.Neighbor == exNeighbor); MyLib.ArrayRemoveOne(ref exNeighbor._cannotVisitNeighbors, this); }
public void RemoveRenderer(SpriteRenderer renderer) { MyLib.ArrayRemoveOne(ref _images, x => x.Renderer == renderer); }