//jumper(moroz)
#include "maps\header.ini"

int time,timewin=0;
int unit,i,flag;
int timedeath[8]={1,1,1,1,0,0};
int tp_x[8]=  {150 ,5838,3846,4206, 1642,1737,1819,1758};
int tp_y[8]=  {612 ,116, 372 , 372, 115 ,115, 115, 636 };
int tp_map[8]={0,   2};
int tp_dir[8]={32,  0};
int tp_no=4,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера
int tp=0;

main()
{
  iff(1)
  {
    SetVid(199,VID_CHILD+15,-322);SetVid(74,VID_CHILD+15,322);
    SetVid(19,VID_CHILD+2,321);SetVid(19,VID_CHILD+4,321);SetVid(19,VID_CHILD+5,321);
    SetVid(24,VID_CHILD+2,321);SetVid(24,VID_CHILD+4,321);SetVid(24,VID_CHILD+5,321);
    SetVid(33,VID_CHILD+2,321);SetVid(33,VID_CHILD+4,321);SetVid(33,VID_CHILD+5,321);
    SetVid(43,VID_CHILD+2,321);SetVid(43,VID_CHILD+4,321);SetVid(43,VID_CHILD+5,321);
    SetVid(79,VID_CHILD+2,321);SetVid(79,VID_CHILD+4,321);SetVid(79,VID_CHILD+5,321);
    SetVid(81,VID_CHILD+2,321);SetVid(81,VID_CHILD+4,321);SetVid(81,VID_CHILD+5,321);
    SetVid(132,VID_CHILD+2,321);SetVid(132,VID_CHILD+4,321);SetVid(132,VID_CHILD+5,321);
    SetVid(138,VID_CHILD+2,321);SetVid(138,VID_CHILD+4,321);SetVid(138,VID_CHILD+5,321);
    SetVid(143,VID_CHILD+2,321);SetVid(143,VID_CHILD+4,321);SetVid(143,VID_CHILD+5,321);
    SetVid(140,VID_CHILD+15,321);SetVid(221,VID_CHILD+15,321);SetVid(314,VID_CHILD+15,321);
    SetVid(348,VID_CHILD+15,321);SetVid(350,VID_CHILD+15,321);SetVid(237,VID_CHILD+14,367);
    gammamenu=64;
/*    for(i=0;i<tp_no;i++) if(old_n_map==tp_map[i]) tp_in=i;
    if(tp_in<0)
      for(i=tp_no-1;i>=0;i--) if( map&(1<<(tp_map[i]-1)) ) tp_in=i;*/
    if(tp_in<0) tp_in=0;
    SetPosition(tp_x[tp_in],tp_y[tp_in]);
    MaxUnit(V_M_CHOPPER,4);
  }
  if(Tact()) return;
  iff(1)
  {
    if(opt_detail) SetWind(25,200);//сила, направление
    time=GetTime();
    flag=Random(10)+1;
    PlayMusic(music1=5,music2=5,music3=5,music4=5);
    for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
    {
      if(Random(1))
        if(GetUnitVid(unit)==V_M_PLASMATANK) Action(unit,act_damage,10,0);
        else if(GetUnitVid(unit)==V_M_GUNTANK) Action(unit,act_damage,20,0);
      if( GetUnitVid(unit)==V_M_PLASMATANK || GetUnitVid(unit)==V_M_GUNTANK)
        if(flag)
          if(!(flag=flag-1)) Action(unit,act_additem,V_ARTEFACT1,0);
    }
    SetFlagman(0,Create(kassandra,tp_x[tp_in],tp_y[tp_in],0));
    Action(Flagman(0),act_changeaction,act_stand,tp_dir[tp_in]);
  }
  if((GetTime()-time)>60000)
  {
    time=GetTime();
    if(!Random(10)) { Create(V_METEORITRAIN,150+Random(2000),100+Random(500),1000);PlaySFX(39); }
  }
  if(tp)
    if((GetTime()-startnextmap)>400)
    {
      if(tp==2) { Action(Flagman(0),act_changecoor,tp_x[3],tp_y[3]);Create(V_TP_EFFECT,tp_x[3],tp_y[3],10); }
      tp=0;
    } else;
  else
  for(i=0;i<tp_no;i++)
  {
    if(!GetObject(V_TELEPORT,tp_x[i],tp_y[i]))
      if(!timedeath[i]) timedeath[i]=GetTime();
      else if((GetTime()-timedeath[i])>4000)
        { Create(V_TELEPORT,tp_x[i],tp_y[i],0);timedeath[i]=0; } else;
    else if(SizeTo(Flagman(0),tp_x[i],tp_y[i])<30 && i==2)
      if(Action(Flagman(0),act_deleteitem,V_ARTEFACT1,0))
      {
        tp=i;startnextmap=GetTime();
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);Effect(eff_bnuke);
      }
/*    iff( SizeTo(Flagman(0),tp_x[i],tp_y[i])<30 && tp_go )
    {
      Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);NextNMap(tp_map[i]);
    }*/
  }
//  for(unit=FirstUnit(1,u_avia);unit;unit=NextUnit())
//    if(GetUnitVid(unit)==45) Action(unit,act_setarmy,3,0);//придать ракетам армию 3
  for(i=4;i<8;i++)
    if(!GetObject(V_M_MISSILETURREL,tp_x[i],tp_y[i]))
      if(!timedeath[i]) timedeath[i]=GetTime();
      else if((GetTime()-timedeath[i])>4000)
      {
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],20);
        Action(GetObject(197,tp_x[i],tp_y[i]),act_destroy,0,0);
        unit=Create(V_M_MISSILETURREL,tp_x[i],tp_y[i],0);timedeath[i]=0;
        if(i<7) Action(unit,act_setarmy,0,0);
//        if(i>6) Action(unit,act_attack,GetObject(V_M_MISSILETURREL,tp_x[5],tp_y[5]),0);
//        if(i>6) Action(unit,act_attack,GetObject(268,1600,229),0);
      }
  if(SizeTo(Flagman(0),tp_x[1],tp_y[1])<30 && GetObject(V_TELEPORT,tp_x[1],tp_y[1]))
    iff(Action(Flagman(0),act_askitem,V_ARTEFACT1,0))
    {
      Create(V_TP_EFFECT,tp_x[1],tp_y[1],10);
      Win();
      Action(Flagman(0),act_destroy,0,0);
    }
}