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

#define mort_hp 15

int time,i;
int unit,tp=0,repair_create=0;
int timedeath[3]={1,1,1};
int tp_x[3]=  {437, 2046,1926};
int tp_y[3]=  {160,  372, 196};
int tp_map[3]={1,   3};
int tp_dir[3]={96, 128};
int tp_no=1,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера
int mort_x=1210,mort_y=791,mort_timer,mort_fight=0;

main()
{
  iff(1)
  {
    SetVid(199,VID_CHILD+15,-320);SetVid(74,VID_CHILD+15,320);
    SetVid(19,VID_CHILD+2,319);SetVid(19,VID_CHILD+4,319);SetVid(19,VID_CHILD+5,319);
    SetVid(24,VID_CHILD+2,319);SetVid(24,VID_CHILD+4,319);SetVid(24,VID_CHILD+5,319);
    SetVid(33,VID_CHILD+2,319);SetVid(33,VID_CHILD+4,319);SetVid(33,VID_CHILD+5,319);
    SetVid(43,VID_CHILD+2,319);SetVid(43,VID_CHILD+4,319);SetVid(43,VID_CHILD+5,319);
    SetVid(79,VID_CHILD+2,319);SetVid(79,VID_CHILD+4,319);SetVid(79,VID_CHILD+5,319);
    SetVid(81,VID_CHILD+2,319);SetVid(81,VID_CHILD+4,319);SetVid(81,VID_CHILD+5,319);
    SetVid(132,VID_CHILD+2,319);SetVid(132,VID_CHILD+4,319);SetVid(132,VID_CHILD+5,319);
    SetVid(138,VID_CHILD+2,319);SetVid(138,VID_CHILD+4,319);SetVid(138,VID_CHILD+5,319);
    SetVid(143,VID_CHILD+2,319);SetVid(143,VID_CHILD+4,319);SetVid(143,VID_CHILD+5,319);
    SetVid(140,VID_CHILD+15,319);SetVid(221,VID_CHILD+15,319);SetVid(314,VID_CHILD+15,319);
    SetVid(348,VID_CHILD+15,319);SetVid(350,VID_CHILD+15,319);SetVid(237,VID_CHILD+14,60);
    SetGamma(gamma=2166);
/*    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;
//  if(GetKey()=='m') Create(V_METEORITRAIN,GetX(Flagman(0))-200+Random(400),GetY(Flagman(0))-150+Random(300),1000);
  iff(1)
  {
    if(opt_detail) SetWind(25,200);//сила, направление
    MaxUnit(V_FLYBUSH,10);
    time=GetTime();//timedeath=timedeath2=0;
    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);
    mort_timer=GetTime();
    SetVid(V_M_MORTIRA,VID_MAXHP,0);
    PlayMusic(music1=5,music2=5,music3=5,music4=5);
  }

  if((GetTime()-time)>10000)
  {
    time=GetTime();Create(V_FLYBUSH,0,Random(900),80);
  }

  iff(!GetObject(12,1566,590))//if destroy storage then surprase
    Create(V_M_MINE,1566,590,0);
  iff(!GetObject(V_M_MORTIRA,mort_x,mort_y))
    { tp_no=3;timedeath[1]=GetTime();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);
    }
  if(tp)//teleport kassandra to tp0 from tp1
    if((GetTime()-startnextmap)>400)
    {
      tp=0;Action(Flagman(0),act_changecoor,tp_x[0],tp_y[0]);
    } else;
  else if(SizeTo(Flagman(0),423,1407)<30)
  {
    tp=1;startnextmap=GetTime();
    Create(V_TP_EFFECT,423,1407,10);Effect(eff_bnuke);
  }
  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==2) Effect(eff_bnuke);
        if(i && !repair_create)
        {
          Create(V_TP_EFFECT,tp_x[i],tp_y[i],40);repair_create=1;
          Action(Create(V_M_REPAIR,tp_x[i],tp_y[i],10),act_attack,GetObject(339,mort_x,mort_y),0);
        }
      }
/*    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]);
    }*/
  }
  iff(SizeTo(Flagman(0),372,664)<80)
  {
    Create(V_M_MINE,276,504,0);Create(V_M_MINE,540,776,0);
  }
  iff(SizeTo(Flagman(0),1884,392)<80)
  {
    Create(V_M_MINE,2004,328,0);Create(V_M_MINE,1764,472,0);
  }
  if(unit=GetObject(V_M_MORTIRA,mort_x,mort_y))
  {
    if(Action(unit,act_getaction,0,0)==act_close) SetVid(V_M_MORTIRA,VID_MAXHP,0);
    if((GetTime()-mort_timer)>18000)
    {
      mort_timer=GetTime();mort_fight=0;PlaySFX(39);
      Create(211,GetX(Flagman(0))-100+Random(200),GetY(Flagman(0))-60+Random(120),500);
    } else if((GetTime()-mort_timer)>15000)
      if(Action(unit,act_getaction,0,0)==act_stand && !mort_fight)
      {
        mort_fight=1;
        SetVid(V_M_MORTIRA,VID_MAXHP,mort_hp);
        AddCommand(unit,act_open,0,0);AddCommand(unit,act_salut,0,0);AddCommand(unit,act_close,0,0);
      }
  }
}
