/////////////////////////////////////////////////////////////////////
// Flock.h: interface for the Flock class.
//   A flock contains a list of boids
//   The Flock is not responsible for deleting dynamically
//   allocated boids
// Joel Gompert
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FLOCK_H__AB70E4E2_1566_4EF1_8991_00EB8A769A65__INCLUDED_)
#define AFX_FLOCK_H__AB70E4E2_1566_4EF1_8991_00EB8A769A65__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <list>
using namespace std;

#include "Entity.h"
#include "Mesh.h"
#include "Boid.h"

class Boid;

class Flock : public AbstractEntity
{
public:
	///////////////////////////////
	// Constructors and destructors
	///////////////////////////////
	Flock(Vector2D goal);
	virtual ~Flock();

	// a helper function to release the memory of all the boids in the flock
	void cleanup();

	/////////////////////
	// flocking functions
	/////////////////////
	void Update(float elapsed_time); // updates all members of the flock

	//////////////////////////
	// miscellaneous functions
	//////////////////////////

	void AddTo(Boid* boid); // adds a boid to the flock
	int GetCount() const {return members.size();} // get number of boids in the flock
	void RemoveFrom(Boid* boid); // removes a boid from the flock and releases the boid's memory

	Vector2D ave2Pos(int team); // gives the average 2D position of the flock
	D3DXVECTOR3 ave3Pos(int team); // returns the average 3D position of the flock
	Vector2D aveVel(int team);
	float aveYaw(int team);
	float avePitch(int team);

	///////////////////////////////////////////////////////
	// functions required for PhysicalEntity
	unsigned int GetAction(float TimeStep, Msg** SentMsgs);
	unsigned int SendMsg(Msg* RecievedMsg, Msg** SentMsgs);
	///////////////////////////////////////////////////////

	////////////////////////////////////////////////////////
	// Temporary addition for calculating energy expediture
	float aveEnergy();
	////////////////////////////////////////////////////////

	friend Boid;

	Vector2D team_goals[2];
private:
	
	list<Boid *> members; // the members of the flock
};

#endif // !defined(AFX_FLOCK_H__AB70E4E2_1566_4EF1_8991_00EB8A769A65__INCLUDED_)
