import java.util.ArrayList;

import processing.core.PVector;

// Flocking
// Daniel Shiffman <http://www.shiffman.net>
// The Nature of Code, Spring 2009

// Flock class
// Does very little, simply manages the ArrayList of all the boids


public class Flock {
  ArrayList<Boid> boids; // An arraylist for all the boids

  Flock() {
    boids = new ArrayList<Boid>(); // Initialize the arraylist
  }

  void seek(PVector _l){
    for (int i = 0; i < boids.size(); i++) {
      Boid b = boids.get(i); 
      b.seek(_l);
    }
  }
  
  void arrive(PVector _l){
    for (int i = 0; i < boids.size(); i++) {
      Boid b = boids.get(i); 
      b.arrive(_l);
    }
  }
  
  void follow(FlowField _f){
    for (int i = 0; i < boids.size(); i++) {
      Boid b = boids.get(i); 
      b.follow(_f);
    }
  }
  
  void run() {
    for (int i = 0; i < boids.size(); i++) {
      Boid b = boids.get(i);  
      b.run(boids);  // Passing the entire list of boids to each boid individually
      
      if(b.dead())
        boids.remove(i);
    }
  }

  void addBoid(Boid b) {
    boids.add(b);
  }

}