/*********************************************************************//**
*	\brief Hrac.
*	Implementace objektu hrace.
*	
*	\author Michal Jirous
*	\date 23.04.2009
*	\file player.h
**********************************************************************/

#ifndef __PLAYER_H_
#define __PLAYER_H_

#include "ent_creatures.h"
#include "war_storage.h"

const float PLAYER_WEIGHT = 80.0f;


const float PLAYER_HEIGHT =	72.0f;
const float PLAYER_HEIGHT_DUCKED = 36.0f;
const float PLAYER_DUCK_DISTANCE = PLAYER_HEIGHT / 20.0f;
#define DUCK_SPEED PLAYER_HEIGHT/20
const float PLAYER_FALL_DAMAGE_SPEED_LIMIT = 20.0f;

struct bullet
{
	alg::Point start;
	alg::Vector movement;
	int damage;
};

const float DEFAULT_ENERGY = 100.0f;
const float ENERGY_REGENERATION_RATIO = 0.1f;

const int DEFAULT_HEALTH = 100;
const int DEFAULT_OXYGEN = 100;

const int CRITICAL_OXYGEN = 25;
const int CRITICAL_HEALTH = 25;

#include "ent_func_ladder.h"

#include "general_sounds.h"

#define STEP_TIME	400
class CPlayer : public Creatures
{
	SoundElement m_MovementSound;
	Uint32 m_StepDelayTime;

	Uint32 m_uiUpdateTime;
	int m_iWaterDamage;

	int m_iOxygen;
	float m_fEnergy;
	void processDuck();
	
	void initSounds();
	void clearSounds();
	time_t stepTime;

	Uint32 m_StepSoundEnergy;
	Uint32 m_uiStepSoundStartTime;

	void copyCollModelToBrush();
	virtual void removeOldBackEvents();
public:

	Uint32 getTotalBackTimeSecondsAvaiable();
	void setEnergy( float e ) { m_fEnergy = getFromRange( e, 0.0f, DEFAULT_ENERGY); }
	float getEnergy()	{return m_fEnergy; }
	void consumeEnergy( float energy )	{ m_fEnergy = std::max( 0.0f, m_fEnergy - energy ); }
	virtual void updateForces();
	virtual void prepareForCollision();
	BasicWeapon *getCurrentWeapon();
	WarStorage AmmoAndWeapons;
	//bool m_bLadderJumpOut;

	virtual void updateBackTime();

	/*===========================================
	*	LADDER PARAMETERS - for Player only
	*==========================================*/
	bool m_bPosibleLadderDownMovement;
	float m_fLastLadderDistance;
	FuncLadder *m_pLadder;
	alg::Vector m_vecLastLadderNormal;
	bool m_bIsOnLadder;
	/*==========================================*/
public:
	void jump();
	
	void heal( int value );
	void addEnergy( float value )	{ setEnergy( m_fEnergy + value ); }

	bool m_bJumpoutOfWater;

	virtual void onAttack( const AttackInfo &attackInfo );

	void unloadSource();



	
	void setOxygen( int oxy )	{ m_iOxygen = std::max( 0, std::min( 100, oxy));	}
	void takeDamage( int dmg );



	virtual void compile();
	int getOxygen()	{ return m_iOxygen; }

	
	bool isJumping;
	int m_iJumpTime, m_iJumpStep;
	float m_fJumpPart;


	void update( float seconds );

	CPlayer();
	~CPlayer();
	void drawPlayer(alg::LinkedPoint &p);	//rekurzivni draw funkce

	Vector jump(float fHeight, int move, float gravityDifference);
	virtual void acceptVector(const alg::Vector &v);
	virtual void teleport( const alg::Vector &v, bool interpolation = true );
	virtual void restart();
virtual void goBackInTime();
virtual void die();
	void setStairsMovement( alg::Vector &stairsMoveVector );
	alg::Vector m_vecStairsMoveVector, m_vecStairsPart;
	int m_iStairsTimes, m_iStarsAlreadyTimes;
	bool isOnStairs;
	int m_iIsDucking;
	alg::Vector m_vecMove;
	void duck(int value);
	int m_iDuckOffset, m_iUpFromDuckOffset, m_iDuckUpSpeed;
};



#endif
