#define UTIL_BOSS_H aaa
//----------------------------------------------------------------------------
//  @brief
//        this file include procedures for working with hp-bar of bosses
//        currently provide usability for only one boss per map

//  @ingroup
    
//  2005Jul21 created. Zmanovsky Peter.
//  (C) 2005    Sigma-Team
//-----------------------------------------------------------------------------


#define BOSS_DAMAGE_GAMMA		0x0E4040
#define BOSS_GAMMA_TIME1		50
#define BOSS_GAMMA_TIME2		50

//------------------------------------------------------------------------------------------
static int BossHealthBar = 0;
static int Boss = 0;
//
static int StartGammaTime = 0;

//------------------------------------------------------------------------------------------
SetBossGamma( int iBoss, int iPercent, int BegGamma, int EndGamma )
{
	SetVidData( GetUnitVid(iBoss), VID_GAMMA+Action(iBoss,ACT_GET_ARMY),
											 CountGamma(BegGamma,EndGamma,iPercent*255/1000) );
}


//------------------------------------------------------------------------------------------
BossTact( int iVid, int RealMaxHp )
{
	//find boss
	if( !Boss )
	{
        if ( LevelNumber < 0 )//сурвайв
        {
        	Boss = FindNearestSprite( GETSPRITE_VID_FLAG+850, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
            if ( !Boss ) Boss = FindNearestSprite( GETSPRITE_VID_FLAG+853, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
        	if ( !Boss ) Boss = FindNearestSprite( GETSPRITE_VID_FLAG+856, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
        	if ( !Boss ) Boss = FindNearestSprite( GETSPRITE_VID_FLAG+860, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
        	if ( !Boss ) Boss = FindNearestSprite( GETSPRITE_VID_FLAG+863, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
        	if ( !Boss ) Boss = FindNearestSprite( GETSPRITE_VID_FLAG+866, GetX(Flagman(0)), GetY(Flagman(0)), 6000 );
        }
    	else
        	Boss = FindNearestSprite( GETSPRITE_VID_FLAG+iVid, GetX(Flagman(0)), GetY(Flagman(0)), 2000 );
	}

    //BossHealthBar is released sometimes (after pressing tab)
    if( Boss && !BossHealthBar && gbState_Bar )
        BossHealthBar = CreateSprite(931, ScreenX() / 2 , 50, 0, 0 );

    if( BossHealthBar )
    {
        if( Boss )
        {
            int val, maxhp, hp;
            hp = Action( Boss, ACT_GET_HP );
            if( hp < 0 )
                hp = 0;
			if( RealMaxHp )
            	maxhp = RealMaxHp;
			else
				maxhp = GetVidData( GetUnitVid(Boss), VID_MAXHP );
			//
            val = 0;
            if( hp && maxhp )
                val = 255 - 255 * hp / maxhp;
            if( val > 250 )		//250 - standard HACK
                val = 250;
            Action( BossHealthBar, ACT_CHANGE_DIRECTION, val );
            if( !hp )
            {
                Destroy( BossHealthBar );
                BossHealthBar = 0;
            }
        }
        else
        {
            Destroy( BossHealthBar );
            BossHealthBar = 0;
        }
    }

    //
    if( StartGammaTime )
    {
    	int iDelta;
    	iDelta = GetTime() - StartGammaTime;
    	//
    	if( iDelta < BOSS_GAMMA_TIME1 )
    		SetBossGamma( Boss, iDelta * 1000 / BOSS_GAMMA_TIME1, 0, BOSS_DAMAGE_GAMMA );
		else
    	if( iDelta < BOSS_GAMMA_TIME1 + BOSS_GAMMA_TIME2 )
    		SetBossGamma( Boss, (iDelta-BOSS_GAMMA_TIME1) * 1000 / BOSS_GAMMA_TIME2, BOSS_DAMAGE_GAMMA, 0 );
		else
		{
			StartGammaTime = 0;
			SetBossGamma( Boss, 0, 0, 0 );
		}
    		
    }
    //
    //if( GetKey() == 'o' )
    //	StartGammaTime = GetTime();	
    //
    iff(giBossKillTime && GetTime() - giBossKillTime > 5000)
    {
    	Win();
    }
}


/*F1510_7(int unit)
{
	if( !StartGammaTime )
		StartGammaTime = GetTime();	
}
*/


//------------------------------------------------------------------------------------------
F2150_15(int unit)
{
	CreateItems(unit);
	giBossKillTime = GetTime();
}
F2150_16(int unit) { F2150_15(unit); }

