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

int time,new_monster=0;
int unit,i,tp=0;//if tp!=0 then начинать телепортацию в позицию tp
int timedeath[4]={1,1,1,0};
int tp_x[4]=  {1105, 624,1558,1100};
int tp_y[4]=  { 162,1270,1263,1261};
int tp_map[4]={3,   4,   4,   4};
int tp_dir[4]={128, 128, 128, 128};
int tp_no=3,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);
    SetGamma(gamma=1877);
/*    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=8,music2=9,music3=8,music4=9);
  }

  iff(SizeTo(Flagman(0),1848,320)<150)
  {
    Action(GetObject(103,1848,320),act_destroy,0,0);
    Create(V_M_MINE,1848,320,0);
  }
  iff(!GetObject(318,318,398))//коммуникационный центр
  {
    Action(GetObject(V_M_AUTOTURREL,607,315),act_clearcom,0,0);
    Action(GetObject(V_M_AUTOTURREL,596,553),act_clearcom,0,0);
    Action(GetObject(V_M_AUTOTURREL,1584,453),act_clearcom,0,0);
    Action(GetObject(V_M_AUTOTURREL,1594,677),act_clearcom,0,0);
  }
  iff(!GetObject(V_M_AUTOTURREL,tp_x[3],tp_y[3]))
  {
    Action(GetObject(195,tp_x[3],tp_y[3]),act_destroy,0,0);
    tp_no=4;//РОЖАТЬ телепорт на смерть подложки башни
  }
  iff(SizeTo(Flagman(0),tp_x[3],tp_y[3])<30 && GetObject(V_TELEPORT,tp_x[3],tp_y[3]))
  {
    Create(V_TP_EFFECT,tp_x[3],tp_y[3],10);
    Win();
    Action(Flagman(0),act_destroy,0,0);
  }
  iff(Action(Flagman(0),act_askitem,V_ARTEFACT1,0) && SizeTo(Flagman(0),1099,1130)<200)
    Action(GetObject(167,1099,1130),act_destroy,0,0);//gate destroy
  if(tp)
    if((GetTime()-startnextmap)>400)
    {
      Action(Flagman(0),act_changecoor,tp_x[0],tp_y[0]);Create(V_TP_EFFECT,tp_x[0],tp_y[0],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>0 && i<3)
      {
        tp=i;startnextmap=GetTime();
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);Effect(eff_bnuke);
      }
    }
}
