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

int time;
int unit,i;
int missile_tur=0;//1 - if all missile turrels is dead
int timedeath[4]={1,1,1,0};
int tp_x[4]=  {272, 247 ,3170,174};
int tp_y[4]=  {3227,309, 1712,158};
int tp_map[4]={4,   5,   9,   10};
int tp_dir[4]={32,  64,  192, 192};
int tp_no=1,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);MaxUnit(V_M_CHOPPER,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=2,music2=2,music3=2,music4=2);
  }
  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);
  }
  iff(SizeTo(Flagman(0),2712,2389)<100 ||
      SizeTo(Flagman(0),2555,2270)<50 ||
      SizeTo(Flagman(0),2878,2487)<50 )
  {
    Action(unit=GetObject(V_MEDIC,2555,2270),act_destroy,0,0);if(unit) Create(V_M_MINE,2555,2270,0);
    Action(unit=GetObject(V_MEDIC,2615,2239),act_destroy,0,0);if(unit) Create(V_M_MINE,2615,2239,0);
    Action(unit=GetObject(V_MEDIC,2681,2219),act_destroy,0,0);if(unit) Create(V_M_MINE,2681,2219,0);
    Action(unit=GetObject(V_MEDIC,2762,2215),act_destroy,0,0);if(unit) Create(V_M_MINE,2762,2215,0);
    Action(unit=GetObject(V_MEDIC,2845,2231),act_destroy,0,0);if(unit) Create(V_M_MINE,2845,2231,0);
    Action(unit=GetObject(V_MEDIC,2900,2275),act_destroy,0,0);if(unit) Create(V_M_MINE,2900,2275,0);
    Action(unit=GetObject(V_MEDIC,2925,2324),act_destroy,0,0);if(unit) Create(V_M_MINE,2925,2324,0);
    Action(unit=GetObject(V_MEDIC,2931,2383),act_destroy,0,0);if(unit) Create(V_M_MINE,2931,2383,0);
    Action(unit=GetObject(V_MEDIC,2915,2448),act_destroy,0,0);if(unit) Create(V_M_MINE,2915,2448,0);
    Action(unit=GetObject(V_MEDIC,2878,2487),act_destroy,0,0);if(unit) Create(V_M_MINE,2878,2487,0);
  }
  if(!missile_tur)
  {
    for(unit=FirstUnit(1,u_monster);unit;unit=NextUnit())
      if(GetUnitVid(unit)==V_M_MISSILETURREL) break;
    if(unit)
    {
      Action(GetObject(V_M_CHOPPER,195,2052),act_setarmy,0,0);
      Action(GetObject(V_M_CHOPPER,3099,3104),act_setarmy,0,0);
      Action(GetObject(V_M_CHOPPER,3176,265),act_setarmy,0,0);
    } else
    {
      missile_tur=1;
      Action(GetObject(V_M_AIRPORT,195,2052),act_setbehave,3,0);
      Action(GetObject(V_M_AIRPORT,3099,3104),act_setbehave,3,0);
      Action(GetObject(V_M_AIRPORT,3176,265),act_setbehave,3,0);
      Action(GetObject(V_M_AIRPORT,195,2052),act_setbuildtime,23,0);
      Action(GetObject(V_M_AIRPORT,3099,3104),act_setbuildtime,23,0);
      Action(GetObject(V_M_AIRPORT,3176,265),act_setbuildtime,23,0);
    }
  }
  iff(missile_tur && !GetObject(V_M_AIRPORT,195,2052) && !GetObject(V_M_AIRPORT,3099,3104) && !GetObject(V_M_AIRPORT,3176,265))
  {
    tp_no=3;timedeath[1]=timedeath[2]=GetTime();
  }
  for(i=1;i<3;i++)
    iff(SizeTo(Flagman(0),tp_x[i],tp_y[i])<30 && GetObject(V_TELEPORT,tp_x[i],tp_y[i]))
    {
      Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);
      Win();
      Action(Flagman(0),act_destroy,0,0);
    }
  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;if(i) 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]);
    }*/
  }
}
