
#pragma once

#include "MW4.hpp"
#include "Sensor.hpp"
#include "hudcomp.hpp"
#include "weapon.hpp"

namespace MechWarrior4
{
	const int MAX_HUD_DAMAGE_ZONE = 11;

	const int MAX_HUD_DAMAGE_LEVEL = 6;

	class HUDDamage : public HUDComponent
	{
	protected:

		typedef HUDComponent inherited;
		int m_DamageValues[MAX_HUD_DAMAGE_ZONE+1];
		Scalar m_ArmorValues[MAX_HUD_DAMAGE_ZONE+1];
		DWORD m_DamageColors[MAX_HUD_DAMAGE_LEVEL];

		HUDText *m_RearText;
		Stuff::Time m_DamageFlashTime,m_HitFlashTime;
		bool m_DamageFlash;
		int m_HitFlashCount[MAX_HUD_DAMAGE_ZONE+1];
		int m_MechID;
		bool m_ArmorMode;

		void DrawImplementation(void);

	public:
		HUDDamage();
		~HUDDamage();
		virtual void Update (Stuff::Time till);
		virtual void Reset (void);
		void SetVehicle(Vehicle *vehicle);

		void DamageValue (int values[MAX_HUD_DAMAGE_ZONE+1]);
		void ArmorValue (Scalar values[MAX_HUD_DAMAGE_ZONE+1],bool firstpass);
		void ToggleMode (void)
		{ m_ArmorMode = !m_ArmorMode; 
		  VehicleInterface::GetInstance()->hudDamageMode = m_ArmorMode;
		}
	};

	class HUDTargetDamage : public HUDComponent
	{
	protected:
		struct WeaponData {
			int m_TextureID;
			int m_PartLoc;
			WeaponData (int p1,int p3)
			{
				m_TextureID = p1;
				m_PartLoc = p3;
			}
		};
		typedef HUDComponent inherited;
		void DrawImplementation(void);
		bool m_ArmorMode;

		Stuff::SlotOf <Entity *> m_TargetVehicle;
		stlport::vector<WeaponData> m_Weapons;
		
		HUDText *m_TargetName;
		HUDText *m_TargetRangeText;
		int m_TargetAlignment;
		Stuff::Scalar m_TargetTonnage;
		int m_DamageValues[MAX_HUD_DAMAGE_ZONE+1];
		Scalar m_ArmorValues[MAX_HUD_DAMAGE_ZONE+1];
		DWORD m_DamageColors[MAX_HUD_DAMAGE_LEVEL];
		Stuff::Time m_DamageFlashTime,m_HitFlashTime;
		bool m_DamageFlash;
		int m_HitFlashCount[MAX_HUD_DAMAGE_ZONE+1];
		int m_TargetMechID;
		bool m_ShowData;
		bool m_LastMechMode;
		//sanghoon begin
	public:
		char hsh_targetname[64];
		char hsh_targetrange[64];
		//sanghoon end

	public:
		HUDTargetDamage();
		~HUDTargetDamage();
		virtual void Update (Stuff::Time till);
		virtual void Reset (void);
//		void DamageValue (int values[MAX_HUD_DAMAGE_ZONE]);
//		void ArmorValue (Scalar values[MAX_HUD_DAMAGE_ZONE],bool firstpass);
		bool ToggleMode (void);
		bool ShowCamera (void)
		{ return ((!m_ArmorMode) && m_Visible);  }
		void Target (Entity *veh);
		void TargetName (char *name)
		{
            m_TargetName->UpdateText (name);
			//sanghoon begin
			strncpy(hsh_targetname,name,sizeof(hsh_targetname));
			hsh_targetname[sizeof(hsh_targetname)-1]=0;
			//sanghoon end
        }
		void TargetRange (Stuff::Scalar value)
		{ 
			char text[50];
			int temp = (int) value;
			sprintf (text,"%dm",temp);
			m_TargetRangeText->UpdateText (text); 
			//sanghoon begin
			strncpy(hsh_targetrange,text,sizeof(hsh_targetrange));
			hsh_targetrange[sizeof(hsh_targetrange)-1]=0;
			//sanghoon end
		}
		void TargetTonnage (Stuff::Scalar value);
		void TargetAlignment (int value)
		{ m_TargetAlignment = value; }
		void ReticuleTarget (Entity *veh)
		{
			if (veh && !m_ShowData)
			{
				if (veh == m_TargetVehicle.GetCurrent ())
					m_ShowData = true;
			}
		}
	};
}

