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

int time,timewin=0;
int unit,i,flag;
int timedeath[6]={1,1,1,0,0,0};
int tp_x[6]=  {412 ,462 ,516 ,579 ,1819,1758};
int tp_y[6]=  {341 ,3172,2272,3265, 115, 636 };
int tp_map[6]={0,   2};
int tp_dir[6]={96,  0};
int tp_no=2,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера
string path;
int plasma_tank;
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;
    path=GetCommands(GetObject(V_TELEPORT,tp_x[0],tp_y[0]));
    Action(GetObject(V_TELEPORT,tp_x[0],tp_y[0]),act_destroy,0,0);
    MaxUnit(V_M_FIGHTER,2);MaxUnit(V_M_PLASMATANK,1);
/*    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);//сила, направление
    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]);
    PlayMusic(music1=2,music2=2,music3=2,music4=2);
  }
  for(unit=FirstUnit(1,u_avia); unit; unit=NextUnit())
    if(GetUnitVid(unit)==V_M_VIDEOCAMERA)
      if(Action(unit,act_getaction,0,0)==act_fight)
      {
        Action(Create(V_M_FIGHTER,0,20,60),act_attack,Action(unit,act_gettarget,0,0),0);
        Action(Create(V_M_FIGHTER,0,100,60),act_attack,Action(unit,act_gettarget,0,0),0);
      }
  plasma_tank=0;
  for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
    if(GetUnitVid(unit)==V_M_PLASMATANK) plasma_tank=unit;
  Action(plasma_tank,act_setarmy,0,0);
  if(SizeTo(plasma_tank,1659,1932)<200)
    Action(GetObject(167,1659,1932),act_destroy,0,0);//gate destroy
  else if(!GetObject(167,1659,1932)) Action(Create(167,1659,1932,0),act_changeaction,act_stand,64);//gate create
  if(SizeTo(plasma_tank,2955,441)<200)
    Action(GetObject(167,2955,441),act_destroy,0,0);//gate destroy
  else if(!GetObject(167,2955,441)) Action(Create(167,2955,441,0),act_changeaction,act_stand,64);//gate create
  if(SizeTo(plasma_tank,3363,1202)<200)
    Action(GetObject(167,3363,1202),act_destroy,0,0);//gate destroy
  else if(!GetObject(167,3363,1202)) Create(167,3363,1202,0);//gate create
  if(SizeTo(plasma_tank,3222,2883)<200)
    Action(GetObject(167,3222,2883),act_destroy,0,0);//gate destroy
  else if(!GetObject(167,3222,2883)) Create(167,3222,2883,0);//gate create
  if(SizeTo(plasma_tank,2100,3329)<200)
    Action(GetObject(167,2100,3329),act_destroy,0,0);//gate destroy
  else if(!GetObject(167,2100,3329)) Action(Create(167,2100,3329,0),act_changeaction,act_stand,64);//gate create
  if(SizeTo(plasma_tank,tp_x[1],tp_y[1])<30)
  {
    Action(plasma_tank,act_destroy,0,0);
    Create(V_TP_EFFECT,tp_x[1],tp_y[1],10);
  }

  iff(SizeTo(Flagman(0),2732,1755)<80)
  {
    Create(V_M_MINE,2738,1545,0);Create(V_M_MINE,2836,1566,0);Create(V_M_MINE,2913,1611,0);
    Create(V_M_MINE,2977,1675,0);Create(V_M_MINE,2999,1758,0);Create(V_M_MINE,2985,1835,0);
    Create(V_M_MINE,2938,1905,0);Create(V_M_MINE,2855,1962,0);Create(V_M_MINE,2745,1986,0);
    Create(V_M_MINE,2635,1977,0);Create(V_M_MINE,2547,1914,0);Create(V_M_MINE,2487,1845,0);
    Create(V_M_MINE,2475,1749,0);Create(V_M_MINE,2501,1669,0);Create(V_M_MINE,2554,1597,0);
    Create(V_M_MINE,2633,1552,0);
  }
  if(SizeTo(Flagman(0),tp_x[2],tp_y[2])<30 && !tp)
  {
    tp=2;startnextmap=GetTime();
    Create(V_TP_EFFECT,tp_x[2],tp_y[2],10);Effect(eff_bnuke);
  }
  if(tp)
    if((GetTime()-startnextmap)>400)
    {
      if(tp==2)
      {
        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)
        {
          unit=Create(V_TELEPORT,tp_x[i],tp_y[i],0);timedeath[i]=0;
          if(!i)
          {
            SetCommands(unit,path);
            Action(unit,act_setbehave,4,0);
            Action(unit,act_additem,V_M_PLASMATANK,0);
            Action(unit,act_setbuildtime,7,0);
          }
        }
  }
  iff(!GetObject(318,3735,244))//коммуникационный центр
    for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
      if(GetUnitVid(unit)==V_M_LASERTURREL)
      {
        Action(unit,act_setbehave,0,0);
        Action(unit,act_deletetarget,Flagman(0),0);
        Action(unit,act_deletetarget,plasma_tank,0);
      }
  iff(!GetObject(12,227,2042))//if destroy storage then surprase
    Create(V_M_MINE,227,2042,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);
    }
}
