#include "maps\export.lgc"
#include "maps\table.lgc"
//#include "maps\common.lgc"

#ifndef COMMON_DEFS_H
    #include "maps\common_defs.lgc"
#endif

int    StartSlide   = 0;// время начала показа слайд шоу
int    StartPicture = 0;// время начала показа картинки
int    NoPicture    = 0;// номер показываемой картинки
int    Picture      = 0;// ссылка на саму показываемую в данный момент картинку
string NextMap      = "";
bool gbFromMainMenu = false;

//------------------------------------------------------------------------------------------
HideSlideButtons(bool bHide)
{
	int act = ANI_MENUSTAND;
	if(bHide)
		act = ANI_MENUDISABLE;
	//
	int spr, vid;
	for( spr = FirstSprite(); spr ;spr = NextSprite() )
	{
		vid = GetUnitVid(spr);
		//
		if(vid == 758)
		{
			Action(spr, act);
			Action(spr, ACT_SET_INVISIBLE, bHide);
		}
		//
		//if(gbFromMainMenu && vid == 706 && GetDirection(spr) == 175)
		//{
		//	Action(spr, ACT_CHANGE_DIRECTION, 53);
		//}
	}
}


//------------------------------------------------------------------------------------------
main()
{
  iff( 1 )
  {
    SetCursor(CURSOR_NORMAL);
//    SetReg( GetDefaultRegPath(),"NewRecord",999 );
//    SetCursor(CURSOR_OFF);
//    SetSoundVolume( GetReg(GetDefaultRegPath(),"SoundVolume","100") );
//    SetMusicVolume( GetReg(GetDefaultRegPath(),"MusicVolume","100") );
    StartSlide = StartPicture = GetTime();
    //Effect(EFF_FADE_OUT,0);
    //
    if(GetGlobValI("SlideFromMainMenu",0) != 0)
    {
    	SetGlobValI("SlideFromMainMenu",0);
    	gbFromMainMenu = true;
    }
    //
    MenuLoad("maps\\slide.men");
    HideSlideButtons(true);
    Picture = MenuFind(771);
  }

  if( GetEffectState(EFF_FADE) > 45 || GetEffectState(EFF_FADE_OUT) > 45 || GetEffectState(EFF_ALPHAAPPEAR) > 45 )
  {
    if( NextMap=="exit" )
      Exit();
    else if( NextMap=="buy" )
    {
      Exec(GetString("strings","BuyCommand"));
      Exit();
    }
    else if( NextMap!="" )
      Load(NextMap);
    else //if( GetUnitVid(Picture)!=951+NoPicture )
    {
      if( NoPicture>=3 )
        NoPicture = 0;
      //Destroy( Picture );
      //Picture = CreateSprite(951+NoPicture,ScreenX()/2,ScreenY()/2,0);
      int dir = Call_ii(EXT_GetAbsDir, 771, NoPicture);
      if(Picture)
        Action(Picture, ACT_CHANGE_DIRECTION, dir);
    }
  }

  int sprTime = MenuFind(734);
  if(sprTime)
  {
  	int dir = (GetTime() - StartSlide)/1000;
  	if(dir < 0 )
  		dir = 0;
	if(dir > 9)
		dir = 9;
	dir = Call_ii(EXT_GetAbsDir, 734, dir);
	Action(sprTime, ACT_CHANGE_DIRECTION, dir);
  }
  iff( (GetTime() - StartSlide) > 10000 )
  {
    HideSlideButtons(false);
    Destroy(sprTime);
    sprTime = 0;
  }

  if( GetEffectState(EFF_FADE) < 0 )
  {
    if( (GetTime() - StartPicture) > 3100 )
    {
      StartPicture = GetTime();
      Effect(EFF_ALPHAAPPEAR,0);
      NoPicture++;
    }
    if( GetKey() || (GetInputState()&(INPUT_LCLICK|INPUT_RCLICK)) )
    {
      StartPicture = GetTime()+60000;
      Effect(EFF_ALPHAAPPEAR,0);
      NoPicture++;
    }
  }
	if( MenuLClick() )
	{
		if( MenuNVidUnderCursor()==758 )
		{
			Effect(EFF_FADE,0);
			if(GetDirection(MenuLClick())==0)
				NextMap = "exit";
			else
				NextMap = "maps\\mainmenu.map";

		}
		else if(MenuNVidUnderCursor()==733)
		{
			Effect(EFF_FADE,0);
			NextMap = "buy";
		}
	}
}
