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

#define mort_hp 15

int time,i;
int unit;
int timedeath[2]={1,1};
int tp_x[2]=  {2120, 271};
int tp_y[2]=  {241, 1365};
int tp_map[2]={1,   3};
int tp_dir[2]={160, 128};
int tp_no=2,tp_in=-1,tp_go=0;//if tp_go!=0 then Flagman(0) отъехал от входного телепортера
int mort_x=246,mort_y=244,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=4,music2=4,music3=4,music4=4);
  }

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

  if(Action(Flagman(0),act_askitem,V_ARTEFACT1,0))
    iff(SizeTo(Flagman(0),tp_x[1],tp_y[1])<30 && GetObject(V_TELEPORT,tp_x[1],tp_y[1]))
    {
      Create(V_TP_EFFECT,tp_x[1],tp_y[1],10);
      Win();
      Action(Flagman(0),act_destroy,0,0);
    }
//  iff(SizeTo(Flagman(0),tp_x[tp_in],tp_y[tp_in])>40) tp_go=1;
  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; }
/*    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]);
    }*/
  }
  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);
      }
  }
}
