/*
	Rogue Trader.
	Copyright (c) 2007, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef PLAYERHUMAN_H
#define PLAYERHUMAN_H

//##############################################################################
// C Includes
//##############################################################################

#include <cstdlib>
#include <cstring>

//##############################################################################
// Forward references
//##############################################################################

class GLWindow;
class GameScene;
class Game;

//##############################################################################
// Base class: cannot be forward referenced
//##############################################################################

#include "Player.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   PlayerHuman
// Purpose:      Class for a human player. Does the movement of the ship and
//               controller input for a human player.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class PlayerHuman : public Player
{

  public:

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Constructor:

        PlayerHuman
        (
            const char * name           ,   // player name
            GameObjectHook * hookShip   ,   // hook to ship player will control
            double credits              ,   // credits the player will start with
            Game * game                     // game the player belongs to
        );

        // Destructor:

        ~PlayerHuman();

        // Do the player's move: takes the last frame time in seconds as a paramter

        void makeMove( float frameTime );

        // Return the current target object for the player's ship

        inline GameObject * getTarget(){ return target; }

        // Get one of the players cameras following its ship:

        inline Camera * getCamera()
        {
            // Return camera requested. make sure its in bounds though:

            return cameras[ cameraAngle & 7 ];
        }

        // Tells if the player has selected the first person view:

        inline bool inFirstPersonMode(){ return cameraAngle == 0; }

        // Gives the name of the player:

        inline const char * getName(){ return name; }

        // Gives the number of kills the player has got:

        inline unsigned getNumKills(){ return numKills; }

        // Set the number of player kills:

        inline void setNumKills( unsigned kills ){ this->numKills = kills; }

        // Set the name of the player:

        void setName( const char * name );

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

  private:

        //----------------------------------------------------------------------
        // Constants:
        //----------------------------------------------------------------------

        static const float KEYBOARD_ACCELERATION;   // Rate at which the players target can be changed speed per second using the keyboard
        static const float KEYBOARD_SENSITIVITY;    // affects how much the keyboard turns the ship. higher values mean more turning.
        static const float MOUSE_SENSITIVITY;       // determines how rotation occurs from mouse movement
        static const float TURN_SMOOTHING;          // determines how much to smooth rotational movement
        static const float CAM_DIST;                // distance of the camera from the players ship. external views only.

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Update the ships position with all the cameras: makes all of the cameras follow the ship

        void updateCameras();

        //----------------------------------------------------------------------
        // Variables:
        //----------------------------------------------------------------------

        // Current amount to rotate player ship by. In radians and per second.

        float rotationX;
        float rotationY;

        // The mouse position before the player started dragging and rotating view with RMB

        int mouseBeforeDragX;
        int mouseBeforeDragY;

        // Were these mouse and keyboard buttons pressed last time the player made its move ?

        bool rightMouseHeld;
        bool middleMouseHeld;
        bool deleteKeyHeld;
        bool backspaceKeyHeld;

        // The current target for the players ship:

        GameObject * target;

        // Player cameras: 8 in total following the players ship

        Camera * cameras[8];

        // Current camera angle to view the players ship from:

        unsigned cameraAngle;

        // Name of the player:

        char * name;

        // Number of kills the player has got:

        unsigned numKills;

        // Game the player belongs to

        Game * game;
};

//##############################################################################
// C++ includes
//##############################################################################

#include "GLWindow.h"
#include "GameScene.h"
#include "Game.h"

#endif // ifndef PLAYERHUMAN_H
