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

int time;
int unit,i;
int timedeath[18]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int tp_x[18]=  {4782,4254 ,2886,2790,2502,2046,1494,990 ,630 ,438 ,366 ,486 ,702 ,1038,1494,1950,2358,2718};
int tp_y[18]=  {148 ,596  ,1508,1908,2276,2532,2628,2468,2164,1844,1508,1188,916 ,676 ,580 ,628 ,804 ,1076};
int tp_map[18]={4,   5,    9,  10};
int tp_dir[18]={160, 64, 192, 192};
int tp_no=18,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера
int tp=0;
int plasma_tank;

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);
    if(tp_in<0) tp_in=0;
    SetPosition(tp_x[tp_in],tp_y[tp_in]);
  }
  if(!Flagman(0)) SetVid(V_TELEPORT,VID_MAXHP,100);//сделать уязвимыми телепортеры
  if(Tact()) return;
  iff(1)
  {
    if(opt_detail) SetWind(25,200);//сила, направление
    SetGamma(gamma=1860);
    MaxUnit(V_M_CHOPPER,3);MaxUnit(V_M_MINE,16);MaxUnit(V_M_LASERTANK,4);
    MaxUnit(V_M_GUNTANK,4);MaxUnit(V_M_RL,4);MaxUnit(V_M_PLASMATANK,1);
    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);
    SetVid(V_TELEPORT,VID_MAXHP,0);//сделать неуязвимыми телепортеры
    PlayMusic(music1=8,music2=9,music3=8,music4=9);
  }

  if((GetTime()-time)>10000)
  {
    time=GetTime();//Create(V_FLYBUSH,0,Random(400),80);
  }
  if(SizeTo(Flagman(0),1484,1852)<150)
    iff(Action(Flagman(0),act_askitem,V_ARTEFACT1,0))
      Action(GetObject(167,1484,1852),act_destroy,0,0);//gate destroy
  if(SizeTo(Flagman(0),596,718)<150)
    iff(Action(Flagman(0),act_askitem,V_ARTEFACT1,0))
      Action(GetObject(167,596,718),act_destroy,0,0);//gate destroy
  plasma_tank=0;
  for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
  {
    if(GetUnitVid(unit)==V_M_PLASMATANK) plasma_tank=unit;
    for(i=2;i<18;i++)
      if(SizeTo(unit,tp_x[i],tp_y[i])<5 && !(Action(unit,act_getbehave,0,0)&128))
      {
        Action(unit,act_setbehave,Action(unit,act_getbehave,0,0)|128,0);
        if(!Random(2) && GetUnitVid(unit)!=V_M_MINE)
          Action(unit,act_additem,V_MEDIC,0);
        if(!Random(2) && GetUnitVid(unit)==V_M_RL)
          Action(unit,act_additem,V_AMMO2+1,0);
        if(!Random(2) && GetUnitVid(unit)==V_M_GUNTANK)
          Action(unit,act_additem,V_AMMO2,0);
        if(!Random(2) && GetUnitVid(unit)==V_M_MINER)
          Action(unit,act_additem,V_AMMO2+2,0);
      }
  }
  if(!Action(Flagman(0),act_askitem,V_ARTEFACT1,0))
    if(SizeTo(plasma_tank,596,718)<200)
      Action(GetObject(167,596,718),act_destroy,0,0);//gate destroy
    else if(!GetObject(167,596,718)) Create(167,596,718,0);//gate create
  iff(!GetObject(362,1494,1518))
  {
    SetVid(V_TELEPORT,VID_MAXHP,100);//сделать уязвимыми телепортеры
    Action(GetObject(364,1550,1524),act_death,0,0);//уничтожить ракетные башни
    Action(GetObject(364,1438,1524),act_death,0,0);//уничтожить ракетные башни
//    SetVid(V_M_CHOPPER,VID_MAXHP,0);//сделать неуязвимыми вертолеты
    Action(unit=Create(V_M_CHOPPER,1494,1518,10),act_move,0,0);
    Action(unit,act_damage,-200,0);
    Win();
  }
  iff(losemenu && win && (GetTime()-nukestart)>700)
  {
    for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
      if(GetUnitVid(unit)==363) Action(unit,act_death,0,0);
  }
  iff(losemenu && win && (GetTime()-nukestart)>1400)
  {
    for(unit=FirstUnit(1,u_monster); unit; unit=NextUnit())
      if(GetUnitVid(unit)==343) Action(unit,act_death,0,0);
  }
  if(tp)
    if((GetTime()-startnextmap)>400)
    {
      if(tp==1) { Action(Flagman(0),act_changecoor,tp_x[2],tp_y[2]);Create(V_TP_EFFECT,tp_x[2],tp_y[2],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==1)
      {
        tp=i;startnextmap=GetTime();
        Create(V_TP_EFFECT,tp_x[i],tp_y[i],10);Effect(eff_bnuke);
      }
    }
}
