//Slaughter
#include "maps\header.ini"

int time,new_monster=0;
int unit,i,tp=0;//if tp!=0 then начинать телепортацию в позицию tp
int timedeath[13]={1,0,0,0,0,0,0,0,0,0,0,0,0};
int tp_x[13]=  {1200,1374,1374,1038,1038,1932,2031,309 ,416 ,2049,2135,158 ,230 };
int tp_y[13]=  {1200,1060,1348,1348,1060,234 ,347 ,2050,2084,2162,2090,268 ,193 };
int tp_map[5]={3,   4,   4,   4,   4};
int tp_dir[5]={0,   128, 128, 128, 0};
int tp_no=5,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера

main()
{
  iff(1)
  {
    SetVid(199,VID_CHILD+15,-200);SetVid(74,VID_CHILD+15,200);
    SetVid(19,VID_CHILD+2,116);SetVid(19,VID_CHILD+4,116);SetVid(19,VID_CHILD+5,116);
    SetVid(24,VID_CHILD+2,116);SetVid(24,VID_CHILD+4,116);SetVid(24,VID_CHILD+5,116);
    SetVid(33,VID_CHILD+2,116);SetVid(33,VID_CHILD+4,116);SetVid(33,VID_CHILD+5,116);
    SetVid(43,VID_CHILD+2,116);SetVid(43,VID_CHILD+4,116);SetVid(43,VID_CHILD+5,116);
    SetVid(79,VID_CHILD+2,116);SetVid(79,VID_CHILD+4,116);SetVid(79,VID_CHILD+5,116);
    SetVid(81,VID_CHILD+2,116);SetVid(81,VID_CHILD+4,116);SetVid(81,VID_CHILD+5,116);
    SetVid(132,VID_CHILD+2,116);SetVid(132,VID_CHILD+4,116);SetVid(132,VID_CHILD+5,116);
    SetVid(138,VID_CHILD+2,116);SetVid(138,VID_CHILD+4,116);SetVid(138,VID_CHILD+5,116);
    SetVid(143,VID_CHILD+2,116);SetVid(143,VID_CHILD+4,116);SetVid(143,VID_CHILD+5,116);
    SetVid(140,VID_CHILD+15,116);SetVid(221,VID_CHILD+15,116);SetVid(314,VID_CHILD+15,116);
    SetVid(348,VID_CHILD+15,116);SetVid(350,VID_CHILD+15,116);SetVid(237,VID_CHILD+14,60);
/*    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]);
  }
  if(Tact()) return;
  iff(1)
  {
    if(opt_detail) SetWind(25,200);//сила, направление
    MaxUnit(V_FLYBUSH,10);
    time=GetTime();
    SetFlagman(0,Create(kassandra,tp_x[tp_in],tp_y[tp_in],0));
    Action(Flagman(0),act_changeaction,act_stand,tp_dir[tp_in]);
    Create(V_TP_EFFECT,tp_x[tp_in],tp_y[tp_in],10);
    PlayMusic(music1=3,music2=4,music3=3,music4=4);
  }
  if((GetTime()-time)>10000)
  {
    time=GetTime();Create(V_FLYBUSH,0,Random(400),80);
    if(!Random(4)) { PlaySFX(39);Create(V_METEORITRAIN,150+Random(450),100+Random(340),1000); }
  }
  if(!new_monster)
  {
    for(i=FirstUnit(1,u_monster);i;i=NextUnit())
      if(GetUnitVid(i)==V_M_LASERTANK) new_monster=1;
    if(!new_monster) new_monster=GetTime();
    else new_monster=0;
  } else
  {
    if( (GetTime()-new_monster)>12000 )
    {
      new_monster=0;
      Action(GetObject(V_TELEPORT,1182,388 ),act_destroy,0,0);Create(V_TP_EFFECT,1182,388 ,10);
      Action(GetObject(V_TELEPORT,1542,468 ),act_destroy,0,0);Create(V_TP_EFFECT,1542,468 ,10);
      Action(GetObject(V_TELEPORT,1782,692 ),act_destroy,0,0);Create(V_TP_EFFECT,1782,692 ,10);
      Action(GetObject(V_TELEPORT,1926,932),act_destroy,0,0);Create(V_TP_EFFECT,1926,932,10);
      Action(GetObject(V_TELEPORT,1998,1204),act_destroy,0,0);Create(V_TP_EFFECT,1998,1204,10);
      Action(GetObject(V_TELEPORT,1974,1492),act_destroy,0,0);Create(V_TP_EFFECT,1974,1492,10);
      Action(GetObject(V_TELEPORT,1854,1732),act_destroy,0,0);Create(V_TP_EFFECT,1854,1732,10);
      Action(GetObject(V_TELEPORT,1614,1892),act_destroy,0,0);Create(V_TP_EFFECT,1614,1892,10);
      Action(GetObject(V_TELEPORT,1206,1924),act_destroy,0,0);Create(V_TP_EFFECT,1206,1924,10);
      Action(GetObject(V_TELEPORT,894 ,1828),act_destroy,0,0);Create(V_TP_EFFECT,894 ,1828,10);
      Action(GetObject(V_TELEPORT,630 ,1636),act_destroy,0,0);Create(V_TP_EFFECT,630 ,1636,10);
      Action(GetObject(V_TELEPORT,510 ,1428),act_destroy,0,0);Create(V_TP_EFFECT,510 ,1428,10);
      Action(GetObject(V_TELEPORT,438 ,1172),act_destroy,0,0);Create(V_TP_EFFECT,438 ,1172,10);
      Action(GetObject(V_TELEPORT,510 ,884 ),act_destroy,0,0);Create(V_TP_EFFECT,510 ,884 ,10);
      Action(GetObject(V_TELEPORT,630 ,628 ),act_destroy,0,0);Create(V_TP_EFFECT,630 ,628 ,10);
      Action(GetObject(V_TELEPORT,846 ,468 ),act_destroy,0,0);Create(V_TP_EFFECT,846 ,468 ,10);
    } else if((GetTime()-new_monster)>2700)
      if(!GetObject(V_TELEPORT,1182,388))
      {
        Create(V_TELEPORT,1182,388 ,0);i=Create(V_M_LASERTANK,1182,388 ,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1542,468 ,0);i=Create(V_M_LASERTANK,1542,468 ,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1782,692 ,0);i=Create(V_M_LASERTANK,1782,692 ,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1926,932,0);i=Create(V_M_LASERTANK,1926,932,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1998,1204,0);i=Create(V_M_LASERTANK,1998,1204,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1974,1492,0);i=Create(V_M_LASERTANK,1974,1492,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1854,1732,0);i=Create(V_M_LASERTANK,1854,1732,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1614,1892,0);i=Create(V_M_LASERTANK,1614,1892,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,1206,1924,0);i=Create(V_M_LASERTANK,1206,1924,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,894 ,1828,0);i=Create(V_M_LASERTANK,894 ,1828,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,630 ,1636,0);i=Create(V_M_LASERTANK,630 ,1636,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,510 ,1428,0);i=Create(V_M_LASERTANK,510 ,1428,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,438 ,1172,0);i=Create(V_M_LASERTANK,438 ,1172,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,510 ,884 ,0);i=Create(V_M_LASERTANK,510 ,884 ,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,630 ,628 ,0);i=Create(V_M_LASERTANK,630 ,628 ,0);
        if(!Random(2)) Action(i,act_additem,V_MEDIC,0);
        Create(V_TELEPORT,846 ,468 ,0);i=Create(V_M_LASERTANK,846 ,468 ,0);
      } else;
    else if((GetTime()-new_monster)>2000) { Effect(eff_bnuke);PlaySFX(18); }
    iff(SizeTo(Flagman(0),1182,388 )<30 && GetObject(V_TELEPORT,1182,388)) { Create(V_TP_EFFECT,1182,388 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1542,468 )<30 && GetObject(V_TELEPORT,1542,468)) { Create(V_TP_EFFECT,1542,468 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1782,692 )<30 && GetObject(V_TELEPORT,1782,692)) { Create(V_TP_EFFECT,1782,692 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1926,932)<30 && GetObject(V_TELEPORT,1926,932))  { Create(V_TP_EFFECT,1926,932,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1998,1204)<30 && GetObject(V_TELEPORT,1998,1204)) { Create(V_TP_EFFECT,1998,1204,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1974,1492)<30 && GetObject(V_TELEPORT,1974,1492)) { Create(V_TP_EFFECT,1974,1492,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1854,1732)<30 && GetObject(V_TELEPORT,1854,1732)) { Create(V_TP_EFFECT,1854,1732,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1614,1892)<30 && GetObject(V_TELEPORT,1614,1892)) { Create(V_TP_EFFECT,1614,1892,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),1206,1924)<30 && GetObject(V_TELEPORT,1206,1924)) { Create(V_TP_EFFECT,1206,1924,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),894 ,1828)<30 && GetObject(V_TELEPORT,894,1828)) { Create(V_TP_EFFECT,894 ,1828,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),630 ,1636)<30 && GetObject(V_TELEPORT,630,1636)) { Create(V_TP_EFFECT,630 ,1636,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),510 ,1428)<30 && GetObject(V_TELEPORT,510,1428)) { Create(V_TP_EFFECT,510 ,1428,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),438 ,1172)<30 && GetObject(V_TELEPORT,438,1172)) { Create(V_TP_EFFECT,438 ,1172,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),510 ,884 )<30 && GetObject(V_TELEPORT,510,884)) { Create(V_TP_EFFECT,510 ,884 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),630 ,628 )<30 && GetObject(V_TELEPORT,630,628)) { Create(V_TP_EFFECT,630 ,628 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
    iff(SizeTo(Flagman(0),846 ,468 )<30 && GetObject(V_TELEPORT,846,468)) { Create(V_TP_EFFECT,846 ,468 ,10);Win();Action(Flagman(0),act_destroy,0,0); }
  }
//  iff(SizeTo(Flagman(0),tp_x[tp_in],tp_y[tp_in])>40) tp_go=1;
  if(tp)
    if((GetTime()-startnextmap)>400)
    {
      if(tp==1) { Action(Flagman(0),act_changecoor,2094,212);Create(V_TP_EFFECT,2094,212,10); }
      if(tp==2) { Action(Flagman(0),act_changecoor,2142,2180);Create(V_TP_EFFECT,2142,2180,10); }
      if(tp==3) { Action(Flagman(0),act_changecoor,318,2148);Create(V_TP_EFFECT,318,2148,10); }
      if(tp==4) { Action(Flagman(0),act_changecoor,126,128);Create(V_TP_EFFECT,126,128,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)
      {
        tp=i;startnextmap=GetTime();
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);Effect(eff_bnuke);
      }
    }
  for(i=5;i<13;i++)
    if(timedeath[i])
      if((GetTime()-timedeath[i])>20000)
      {
        if(i<9) Create(V_MEDIC,tp_x[i],tp_y[i],0);
        else Create(V_AMMO2,tp_x[i],tp_y[i],0);
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);timedeath[i]=0;
      } else;
    else
      if(i<9)
        if(!GetObject(V_MEDIC,tp_x[i],tp_y[i] )) timedeath[i]=GetTime();else;
      else if(!GetObject(V_AMMO2,tp_x[i],tp_y[i])) timedeath[i]=GetTime();
}
