//Slaughter (12)
#include "maps\header.ini"

int time;
int unit,i,birth,tp[4]={0,0,0,0};//if tp!=0 then начинать телепортацию в позицию tp
int timedeath[17]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                         //w21  w43  el
int tp_x[17]=  {1200,1374,1374,1038,1038,1932,2031,309 ,416 ,1992,2136,240 ,144 ,144 ,2112,718 };
int tp_y[17]=  {1200,1060,1348,1348,1060,234 ,347 ,2050,2084,2160,2080,160 ,272 ,176 ,2176,2305};
int tp_map[5]={3,   4,   4,   4,   4};
//int tp_dir[5]={0,   128, 128, 128, 0};
int kas_x[5]={0,2094,2142,318 ,126};//место куда телепортируют кассандру
int kas_y[5]={0,212 ,2180,2148,128};
int birth_x[8]={1182,1782,1998,1854,1206,630 ,438 ,630};
int birth_y[8]={388 ,692 ,1204,1732,1924,1636,1172,628};

NetCreatePlayer()
{
  weapon[n_flagman*4]=V_FLAGMANHEAD12;weapon[1+n_flagman*4]=0;weapon[2+n_flagman*4]=0;weapon[3+n_flagman*4]=0;kassandra=V_TRANSMISSION1;
  birth=Random(7);
  while( unit=AskPlace(kassandra,birth_x[birth],birth_y[birth],0) )
    if(GetUnitVid(unit)==V_TRANSMISSION1 || GetUnitVid(unit)==V_TRANSMISSION2 || GetUnitVid(unit)==V_TRANSMISSION3)
      if(birth<7) birth++;else birth=0;
    else Action(unit,act_death,0,0);
  SetFlagman(n_flagman,Create(kassandra,birth_x[birth],birth_y[birth],0));
  Action(Flagman(n_flagman),act_setarmy,n_flagman,0);
  Action(Flagman(n_flagman),act_changeaction,act_stand,0/*tp_dir[n_flagman]*/);
  Create(V_TP_EFFECT,birth_x[birth],birth_y[birth],10);
  if(GetNetInfo(NET_NUMPLAYER)==n_flagman) SetPosition(birth_x[birth],birth_y[birth]);
  Action(Flagman(n_flagman),act_setstate,(n_flagman<<12)+Action(Flagman(n_flagman),act_getstate,0,0),0);
  Action(Flagman(n_flagman),act_changeweapon,weapon[n_flagman*4],0);
  net_birth[n_flagman]=0;
}

main()
{
  iff(1)
  {
    if(opt_detail) SetWind(25,200);//сила, направление
    MaxUnit(V_FLYBUSH,10);
    time=GetTime();
    for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++) NetCreatePlayer();
    PlayMusic(music1=2,music2=2,music3=2,music4=2);
  }
  if(NetTact()) return;
  if((GetTime()-time)>10000)
  {
    time=GetTime();Create(V_FLYBUSH,0,Random(400),80);
    if(!Random(4)) Create(V_METEORITRAIN,150+Random(450),100+Random(340),1000);
  }
  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],50);
        else if(i<11) Create(V_AMMO2,tp_x[i],tp_y[i],50);
        else Create(V_AMMO2+2,tp_x[i],tp_y[i],50);
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],40);timedeath[i]=0;
      } else;
    else
      if(i<9) if(!GetObject(V_MEDIC,tp_x[i],tp_y[i] )) timedeath[i]=GetTime();else;
      else if(i<11) if(!GetObject(V_AMMO2,tp_x[i],tp_y[i])) timedeath[i]=GetTime();else;
      else if(!GetObject(V_AMMO2+2,tp_x[i],tp_y[i])) timedeath[i]=GetTime();
  for(i=13;i<16;i++)
    if(timedeath[i])
      if((GetTime()-timedeath[i])>40000)
      {
        if(i==14) Create(V_UPGRADE12+2,tp_x[i],tp_y[i],50);//w21
        else if(i==13) Create(V_UPGRADE12+8,tp_x[i],tp_y[i],50);//w41
        else Create(103,tp_x[i],tp_y[i],50);//extra life
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],40);timedeath[i]=0;
      } else;
    else
      if(i==14) if(!GetObject(V_UPGRADE12+2,tp_x[i],tp_y[i] )) timedeath[i]=GetTime();else;
      else if(i==13) if(!GetObject(V_UPGRADE12+8,tp_x[i],tp_y[i] )) timedeath[i]=GetTime();else;
      else if(!GetObject(103,tp_x[i],tp_y[i])) timedeath[i]=GetTime();//extra life
    if(timedeath[15])
      if((GetTime()-timedeath[15])>200000)
      {
        Create(103,tp_x[15],tp_y[15],50);//extra life
        Create(V_TP_EFFECT,tp_x[15],tp_y[15],40);timedeath[15]=0;
      } else;
    else if(!GetObject(103,tp_x[15],tp_y[15])) timedeath[15]=GetTime();//extra life
  for(n_flagman=0;n_flagman<GetNetInfo(NET_NOPLAYER);n_flagman++)
    if(Flagman(n_flagman))
    {
      if(tp[n_flagman])
        if((GetTime()-startnextmap)>400)
        {
          while(unit=AskPlace(kassandra,kas_x[tp[n_flagman]],kas_y[tp[n_flagman]],0))
            Action(unit,act_death,0,0);
          Action(Flagman(n_flagman),act_changecoor,kas_x[tp[n_flagman]],kas_y[tp[n_flagman]]);
          Create(V_TP_EFFECT,kas_x[tp[n_flagman]],kas_y[tp[n_flagman]],10);
          tp[n_flagman]=0;
        } else;
      else
        for(i=0;i<5;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(n_flagman),tp_x[i],tp_y[i])<30 && i)
          {
            tp[n_flagman]=i;startnextmap=GetTime();
            Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);Effect(eff_bnuke);
          }
        }
    } else //if player is die
    {
      if(net_birth[n_flagman])
        if( (GetTime()-net_birth[n_flagman])>3000 )
          NetCreatePlayer();
    }
}
