public bool ShouldAvoid(FlockMovement boid) { if (boid == null) { return(false); } return(boid.FlockIndex != m_flockIndex); }
private void FindNeighboursForBoid(FlockMovement boid, bool onlyTraverseAffiliates) { // Clear the boids by proximity. m_boidsByProximity.Clear(); m_proximitiesConsidered = 0; // If flagged as such, traverse through our neighbour's neighbours only. if (onlyTraverseAffiliates) { for (int i = 0; i < boid.Neighbours.Length; i++) { // Only do proximity checks if we have a neighbour at all. if (boid.Neighbours[i] == null) { continue; } // Loop through the neighbour's neighbours. for (int j = 0; j < boid.Neighbours[i].Neighbours.Length; j++) { AddBoidByProximity(ref m_boidsByProximity, boid.Neighbours[i].Neighbours[j], boid); } } } else // Otherwise go through all boids (initial setup requires this). { for (int i = 0; i < m_boids.Count; i++) { AddBoidByProximity(ref m_boidsByProximity, m_boids[i], boid); } } // Find the first NEIGHBOUR_COUNT amount of boids. //Debug.Log("Boid #"+boid.FlockIndex+" has the following proximities:"); foreach (float dist in m_boidsByProximity.Keys) { //Debug.Log("\t" + dist + " units to " + m_boidsByProximity[dist].name); boid.SetNeighbour(m_proximitiesConsidered, m_boidsByProximity[dist]); m_proximitiesConsidered++; if (m_proximitiesConsidered == FlockMovement.NEIGHBOUR_COUNT) { break; } } // Clear the other slots if we didn't find NEIGHBOUR_COUNT. if (m_proximitiesConsidered < FlockMovement.NEIGHBOUR_COUNT) { boid.ClearNeighboursStartingFrom(m_proximitiesConsidered); } }
private void AddBoidByProximity(ref SortedDictionary<float, FlockMovement> dictionary, FlockMovement candidate, FlockMovement proximityTo) { // Check if we should do a proximity check at all. if (candidate == null || proximityTo == null || !candidate.ShouldAvoid(proximityTo)) { return; } // Otherwise add the boid to the sorted collection. m_tempBoidProximity = (candidate.CachedTransform.position - proximityTo.CachedTransform.position).sqrMagnitude; if (!dictionary.ContainsKey(m_tempBoidProximity)) { dictionary.Add(m_tempBoidProximity, candidate); } }
public void SetNeighbour(int index, FlockMovement boid) { m_neighbours[index] = boid; }
public void Land(FlockMovement boid) { m_isOccupied = true; }
private void AddBoidByProximity(ref SortedDictionary <float, FlockMovement> dictionary, FlockMovement candidate, FlockMovement proximityTo) { // Check if we should do a proximity check at all. if (candidate == null || proximityTo == null || !candidate.ShouldAvoid(proximityTo)) { return; } // Otherwise add the boid to the sorted collection. m_tempBoidProximity = (candidate.CachedTransform.position - proximityTo.CachedTransform.position).sqrMagnitude; if (!dictionary.ContainsKey(m_tempBoidProximity)) { dictionary.Add(m_tempBoidProximity, candidate); } }
public bool ShouldAvoid(FlockMovement boid) { if (boid == null) { return false; } return boid.FlockIndex != m_flockIndex; }