//	GamePlay.h - The main gameplay state.
//  ----------------------------------------------------------------------------
//	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 GamePlay_H_
#define GamePlay_H_

#include "Prole.h"
#include "GameState.h"
#include "Capitalist.h"

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

class Debilitation;
class PlayerBehaviour;

///	The main gameplay state.
class GamePlay : public GameState
{
  public:
	///	Constructor.
	GamePlay(Application *app);
	///	Destructor.
	~GamePlay();

	///	Draws the text.
	void draw(Drawer *d);

	///	Called when a key down event is received.
	void keyDown(const SDL_keysym& keyPressed);
	///	Called when a key up event is received.
	void keyUp(const SDL_keysym& keyPressed);

	///	Drops a blob.
	void mouseDown(int button, int posX, int posY);
	///	Moves the cursor.
	void mouseMove(int posX, int posY);

	///	This state's name.
	const std::string getName() const {return "GamePlay";};

	///	Adds a debilitation wave.
	void addWave(int x, int y, float val);

	///	Adds a revolutionary connection.
	void addRevolConnection(Prole *p1, Prole *p2);
	///	Removes a revolutionary connection.
	void removeRevolConnection(Prole *p1, Prole *p2);

	///	Returns the Proles in this world.
	Prole *getProles() {return proles;};
	///	Returns the Capitalists in this world.
	Capitalist *getCapitalists() {return capitalists;};

	///	Kills the player, starts them over.
	void killPlayer();

	///	Some constants.
	enum
	{
		NumCapitalists = 6,
		NumProles = 128
	};
  private:
	///	Helper method.  Calculates Prole-Capitalist collisions.
	void capitalistCollisions();
	///	Helper method.  Generates worldPositions.
	void generateWorlds();

	///	The background image.
	uint32_t background;
	///	The endgame image.
	uint32_t possibleWorlds;
	///	The 'world' images.
	uint32_t worlds[12];
	///	The help text.
	uint32_t helpText1;
	///	The help text.
	uint32_t helpText2;

	///	Represents a blob.
	struct Blob
	{
		uint32_t image;
		int x;
		int y;
	};

	///	The blobs on the screen.
	std::vector<Blob> blobs;

	///	The links between revolutionaries.
	struct RevolConnection
	{
		Prole *p1;
		Prole *p2;
	};
	///	The links between revolutionaries.
	std::vector<RevolConnection> revolConnections;

	///	The capitalists.
	Capitalist capitalists[NumCapitalists];
	///	The proles.
	Prole proles[NumProles];
	///	The currently-active debilitation waves.
	std::vector<Debilitation *> debilitations;
	///	The player-controlled Prole.
	PlayerBehaviour *player;
	///	Used to draw lines highlighting the player when they're born.
	float playerLines;

	///	Used to fade in the end game screen.
	float endGame;

	///	Used to draw the 'world' fragments in the background.
	struct World
	{
		uint32_t image;
		int x;
		int y;
		float fade;
	};
	///	The positions where 'world' fragments may be drawn.
	std::vector<World> possiblePositions;
	///	The positions where 'world' fragments *are* drawn.
	std::vector<World> worldPositions;
	///	Which world image we're on.
	int whichWorld;

	///	Used to fade out the help text.
	float helpFade1;
	///	Used to fade out the help text.
	float helpFade2;
};

#endif
