//	Prole.h - The prole class.
//  ----------------------------------------------------------------------------
//	This file is part of 'The Future Will Only Be Dystopian if Capitalism
//	Remains Undefeated', a game.
//	Copyright (C) 2009  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#ifndef PROLE_H_
#define PROLE_H_

#include <vector>
#include <stdint.h>

class Prole;
class Drawer;
class GamePlay;

//------------------------------------------------------------------------------
///	Base class for all the possible Prole behaviours.
class ProleBehaviour
{
  public:
	///	Constructor.
	ProleBehaviour() {};
	///	Destructor.
	virtual ~ProleBehaviour() {};

	///	Gets the Prole to act (move, revolutionise, etc.).
	virtual void act(Prole *p, GamePlay *gp) = 0;
};

//------------------------------------------------------------------------------
///	The prole class.
class Prole
{
  public:
	///	Constructor.
	Prole();
	///	Destructor.
	~Prole();

	///	Sets the Prole's behaviour.
	void setBehaviour(ProleBehaviour *b);

	///	Gets the Prole to move.
	void move(GamePlay *gp);
	///	Gets the Prole to bounce off a Capitalist.
	void bounceFrom(float x, float y);

	///	Draws the Prole.
	void draw(Drawer *d);
	///	Triggers a flash.
	void triggerFlash();

	///	Sets the Prole's position.
	void setPosition(float x, float y);
	///	Sets the Prole's direction.
	void setDirection(float x, float y);
	///	Returns the Prole's position.
	float getX() const {return xPos;};
	///	Returns the Prole's position.
	float getY() const {return yPos;};
	///	Returns the Prole's direction.
	float getDirX() const {return xDir;};
	///	Returns the Prole's direction.
	float getDirY() const {return yDir;};

	///	Turns a Prole revolutionary.
	void setRevolutionary(bool val);
	///	Returns whether or not this Prole is a revolutionary.
	bool getRevolutionary() const {return revolutionary;};

	///	Sets the Prole's colour.
	void setColour(float r, float g, float b);
	///	Sets whether the Prole should fade as it loses its life.
	void setLifeFade(bool val);
	///	Sets whether to do a motion blur trail for the Prole.
	void setTrail(bool val);

	///	Resets the Prole's life, moves them to a new position.
	void resetLife(GamePlay *gp);
	///	Reduces the Prole's life, returns true if they have died.
	bool reduceLife(float val);
	///	Returns the Prole's life.
	float getLife() const {return life;};
	///	Sets the Prole's strength.
	void setStrength(float val);

	///	Tries to convince the Prole to become a revolutionary.
	void convince(Prole *p, GamePlay *gp);
	///	Makes the Prole go back to worker behaviour.
	void backToWorker(GamePlay *gp);
	///	Removes a neighbour.
	void removeNeighbour(Prole *p);
	///	Returns this Prole's revolutionary neighbours.
	std::vector<Prole *>& getNeighbours() {return neighbours;};
  private:
	///	The Prole's image.
	static uint32_t image;
	///	The star puff image.
	static uint32_t starPuff;

	///	The Prole's behaviour.
	ProleBehaviour *behaviour;

	///	The Prole's position.
	float xPos;
	///	The Prole's position.
	float yPos;
	///	The Prole's direction.
	float xDir;
	///	The Prole's direction.
	float yDir;

	///	Used to bounce away from a Capitalist.
	int bounceCount;

	///	Whether or not the Prole is revolutionary.
	bool revolutionary;
	///	How convinced this Prole is about becoming a revolutionary.
	float revolConvinced;

	///	The size of the motion blur trail.
	enum
	{
		TrailSize = 8
	};

	///	The Prole's colour.
	float red;
	///	The Prole's colour.
	float green;
	///	The Prole's colour.
	float blue;
	///	Whether the Prole should fade as it loses its life.
	bool lifeFade;
	///	Whether the Prole should have a motion blur trail.
	bool trail;
	///	Used to draw the trail.
	float trailX[TrailSize];
	///	Used to draw the trail.
	float trailY[TrailSize];

	///	Links to this Prole's revolutionary neighbours.
	std::vector<Prole *> neighbours;

	///	The Prole's life.
	float life;
	///	How strong this Prole is (lower numbers == stronger).
	float strength;
	///	When a new Prole is born (resetLife()), we draw an expanding star.
	float starSize;

	///	Used to make the prole 'flash'.
	float flash;
};

#endif
