#define  COMMON_GAMEBAR_H aaa
//----------------------------------------------------------------------------
//  @brief
//        gamebar
//        

//  @ingroup
    
//  2006Nov14 created. Zmanovsky Peter.
//  (C) 2006    Sigma-Team
//-----------------------------------------------------------------------------



//------------------------------------------------------------------------------------------
ShowGameBarSpeed(int NewSpeed)
{
	//int i;
	//i = (NewSpeed - MIN_BALL_SPEED)/25;//STEP_BALL_SPEED;
	//
	string str;
	//str = itoa(i) + "(" + itoa(NewSpeed) + ")";
	str = itoa(NewSpeed/2);
	Action(MenuBallSpeed, ACT_SET_TEXT, &str);
	//
	int dir, dd;
	dd = NewSpeed - MIN_BALL_SPEED;
	if(dd < 0)
		dd = 0;
	//
	dir = 256 * dd / (MAX_BALL_SPEED - MIN_BALL_SPEED);
	if(dir > 242)
		dir = 242;
	if(MenuBallSpeedBar)
		Action(MenuBallSpeedBar, ACT_CHANGE_DIRECTION, dir);
}


//------------------------------------------------------------------------------------------
ShowGameBarScores()
{
	string str;
	//
	int score = giScoresLev;
	if(giStatShown)	//в статистике показываем score, кот. был перед показом статистики
		score = giScoresLevOnStatLoad;
	str = itoa(score);
	Action(MenuScores, ACT_SET_TEXT, &str);
	//
	score = gScoreTot;
	if(giStatShown)	//в статистике показываем score, кот. был перед показом статистики
		score = giScoreTotBeforeStat;
	str = itoa(score/10);
	Action(MenuScoresTotal, ACT_SET_TEXT, &str);
}


//------------------------------------------------------------------------------------------
ShowGameBarLives()
{
	string str;
	int num = NoPlayerLife;
	if(giBornLifeFxTime && NoPlayerLife > 0)
		num--;
	str = itoa(num);
	Action(MenuNoPlayerLife, ACT_SET_TEXT, &str);
	//
	int dir = num;
	if(num > MAX_LIVES_GAMEBAR)
		num = MAX_LIVES_GAMEBAR+1;
	dir = Call_ii(EXT_GetAbsDir, 474, num);
	//
	if(MenuNoPlayerLifeBar)
		Action(MenuNoPlayerLifeBar, ACT_CHANGE_DIRECTION, dir);
}


//------------------------------------------------------------------------------------------
GameBarTact()
{
	string str;
	//
   	int iTime = 0;
   	if(StartBallLevelTime)
   		iTime = (GetTime() - StartBallLevelTime) / 1000;
	iTime = GetGoldLevTime() - iTime;
	//
	int timeBarDir = 0;
	int spr = MenuFind(746);
	if(spr)
	{
		int dir = 0;
		if(iTime < 0 && GetBonusLevTime())
		{
			int perc = 100-(GetBonusLevTime() + iTime) *100 / GetBonusLevTime();
			dir = 255 * perc / 100;
			if(dir > 250)
				dir = 250;
		}
		if(iTime < 0 && dir < 8)
			dir = 8;
		//
		//Log3("aa = " + itoa(dir));
		Action(spr, ACT_CHANGE_DIRECTION, dir);
		timeBarDir = dir;
	}
	//
	if(iTime < 0)
		iTime = 0;
	str = Printf("%02d",iTime/60) + ":" + Printf("%02d",iTime%60);
	//
	//if(timeBarDir > 0 && timeBarDir < 250)
	//	str = "";
	//
	Action(MenuGameTime, ACT_SET_TEXT, &str);
	//
	ShowGameBarLives();
	//
	str = GetCrystalsStr();
	Action(MenuCrystals, ACT_SET_TEXT, &str);
	//
	int dir;
	dir = Call_ii(EXT_GetAbsDir, 480, giCrystalScore % CRYSTALS_FOR_LIFE);
	if(MenuCrystalsBar)
		Action(MenuCrystalsBar, ACT_CHANGE_DIRECTION, dir);
	//
	ShowGameBarScores();
	//
	if(gbShowDbg)
	{
		str = "LEVEL" + itoa(LevelNumber) + ". SUBLEVEL" + itoa(giSubLevelNum+1);
		if(!DbgTextCurLevel)
			DbgTextCurLevel = CreateSprite(3, ScreenX()-240, 35+5000, 5000);
		Action(DbgTextCurLevel, ACT_SET_TEXT, &str);
	}
	else
		Destroy(DbgTextCurLevel);
	//
	if(giBornLifeFxTime && GetTime() > giBornLifeFxTime)
	{
		giBornLifeFxTime = 0;
		AnimateAddLife();
	}
/*        for ( i = FirstUnit(U_UNIT); i; i = NextUnit() )
            if ( GetVidData(GetUnitVid(i), VID_CLASS) == B_BALL )
            {
                int max_speed;
                max_speed = Action(i, ACT_GET_ITEM, 1);
                i = (max_speed - MIN_BALL_SPEED)/25;//STEP_BALL_SPEED;
                str = itoa(i) + "(" + itoa(max_speed) + ")";
                Action(MenuBallSpeed, ACT_SET_TEXT, &str);
                break;
            }*/
}


//------------------------------------------------------------------------------------------
AnimateAddLife()
{
	int x = GetX(MenuNoPlayerLife);
	int y = GetY(MenuNoPlayerLife)-GetZ(MenuNoPlayerLife);
	int z = GetZ(MenuNoPlayerLife);
	//
	int dx = 10000;
	if(NoPlayerLife == 1)	dx = -38;
	else
	if(NoPlayerLife == 2)	dx = -19;
	else
	if(NoPlayerLife == 3)	dx =   0;
	else
	if(NoPlayerLife == 4)	dx =  19;
	else
	if(NoPlayerLife == 5)	dx =  38;
	else
		return;
		
	int dy = 28;
	//
	CreateSprite(760, x + dx, y + z + 1 + dy, z + 1);
}


//------------------------------------------------------------------------------------------
Animate20Crystals(bool bBornFx)
{
	CreateSprite(761, MenuCrystalsAddLifeX, MenuCrystalsAddLifeY + MenuCrystalsAddLifeZ, MenuCrystalsAddLifeZ);
	if(bBornFx)
		giBornLifeFxTime = GetTime() + ADD_LIFE_BY_CRYSTALS_DELAY;
	ShowGameBarLives();
}


//------------------------------------------------------------------------------------------
AddLife(int iType)
{
	int ret = AddLifeEx(+1);
	//
	if(iType != AL_BONUS && (ret || iType == AL_FLYSTAT))
		PlaySFX(4);
	//
	if(ret && iType != AL_FLYSTAT && iType != AL_CRYSTALS)
		AnimateAddLife();
	//
	return ret;
}

