public bool ShouldAvoid(FlockMovement boid)
 {
     if (boid == null)
     {
         return(false);
     }
     return(boid.FlockIndex != m_flockIndex);
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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;
 }
Beispiel #5
0
 public void Land(FlockMovement boid)
 {
     m_isOccupied = true;
 }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
 public void Land(FlockMovement boid)
 {
     m_isOccupied = true;
 }
Beispiel #9
0
 public bool ShouldAvoid(FlockMovement boid)
 {
     if (boid == null)
     {
         return false;
     }
     return boid.FlockIndex != m_flockIndex;
 }
Beispiel #10
0
 public void SetNeighbour(int index, FlockMovement boid)
 {
     m_neighbours[index] = boid;
 }