# FlockingClassDefinitions.py 
# Define the basic classes 'Bird' and 'Flock' 

# Import Modules
from numpy import *
from Scientific.Geometry import *

# Define the class 'Bird'

# The class Bird consists of a string-form bird label i.e. 'b7', the maximum velocity (MV),
# maximum acceleration (MA), & sightrange as floating point numbers, and the current position of the bird
# (p_current), position at the last timestep (p_last) and current velocity (v_current) as Vectors [x,y,0], 
# and finally a list of neighbors in string form i.e. ['b1','b9','b4'].

# we define the following functions for the class Bird:

# (1) Standard Initialization
# (2) Standard Representation (gives label)
# (3) fulldisplay which lists all attributes

class Bird:
    
     def __init__(self, label, MV, MA, sightrange, p_current, p_last, v_current, neighbors): 
         self.label = label
         self.MV = MV
         self.MA = MA
         self.sightrange = sightrange
         self.p_current = p_current
         self.p_last = p_last
         self.v_current = v_current
         self.neighbors = neighbors

     def __repr__(self):
        return self.label	    


     def fulldisplay(self):
         print 'label = ', self.label
         print 'max velocity = ', self.MV
         print 'max acceleration = ', self.MA
         print 'sightrange = ', self.sightrange
         print 'p_current = ', self.p_current
         print 'p_last = ', self.p_last
         print 'v_current = ',self.v_current
         print 'neighbors = ',self.neighbors 

         
# Define the class 'Flock'

# The class Flock consists of a label (i.e 'Penguins'), a list of birds in the flock 
# i.e. [b1,b2, ... bn], and the location, previous location, & velocity of the CM of the flock as Vectors [x,y,0]. 

# we define the following functions for the class Flock:

# (1) Standard Initialization
# (2) Standard Representation (gives label)
# (3) fulldisplay which lists all flock attributes

class Flock:
      
      def __init__(self,label,ListOfBirds,CM_current, CM_last, Avg_Velocity_current):
         self.label = label
         self.ListOfBirds = ListOfBirds
         self.CM_current = CM_current
         self.CM_last = CM_last
         self.Avg_Velocity_current = Avg_Velocity_current

      def __repr__(self):
         return self.label 
         

      def fulldisplay(self):
         print 'label = ', self.label
         print 'list of birds in flock = ', self.ListOfBirds
         print 'location of CM = ', self.CM_current
         print 'previous location of CM = ', self.CM_last
         print 'average velocity = ',self.Avg_Velocity_current
                 
          


# Notes: (1) Although the system is two dimensional, we must store the velocities and positions as 3D vectors
#            with a z-component = 0, in order to use vector functionslike dot products. 
#            -- at least it wasn't working for me otherwise.

#        (2) There is a good bit of extra overhead here. The display functions are not used later on, and we don't actually 
#            keep track of the CM of the flock or it's velocity with the simulation. These are reconstructed later from
#            the data that is written to a textfile, in the data analysis section. These definitions were originally created
#            before I had fully figured out how everything was going stick together, and it was easier simply to keep 
#            them as they were than go back and modify everything. They were also helpful for me in learning about how
#            to work with and define 'objects'. 




    


