#include "maps\survive_birth.lgc"
#include "maps\monsters.lgc"


  

F850_14(int unit) { Action(unit,ACT_ADD_ITEM,262); }
F853_14(int unit) { Action(unit,ACT_ADD_ITEM,264); }
F856_14(int unit) { Action(unit,ACT_ADD_ITEM,268); }
F860_14(int unit) { Action(unit,ACT_ADD_ITEM,267); }
F863_14(int unit) { Action(unit,ACT_ADD_ITEM,269); }
F866_14(int unit) { Action(unit,ACT_ADD_ITEM,260); }


InitSurviveGame()
{
  int i;

//  SetScrollType(SCROLL_FLAGMAN_IN_CENTER);

  // т√ёЄрты хЄё  фы  тёхї VID ё weapon==31 LIFETIME
  PlayerItem[7]=0;//ъюышўхёЄтю цшчэхщ є шуЁюър т ёєЁтрщтх 0
  SetVidData(302,VID_LIFETIME,20000);

  for( i = 0; i < sizeof(MonstersVid)/4; i++ )
  {
    SetVidData(MonstersVid[i],VID_DETECTRANGE,2000);
//    SetVidData(MonstersVid[i],VID_SPEED,(GetVidData(MonstersVid[i],VID_SPEED)*7)/10);
  }
}

SurviveGameTact()
{
  static int prev_time=0, prev_shift=-1;
  static int arrowed_unit=0;
  int        shift,i,x,y,delta_speed,dir,unit;
  if( (GetTime()-prev_time)>100 )
  {
    prev_time = GetTime();
    shift = ((GetTime()-StartGameTime)/30000)*MONSTERS_VID_COUNT;
    if( shift > 39*MONSTERS_VID_COUNT )
      shift = 39*MONSTERS_VID_COUNT;
    if( shift!=prev_shift )
    {
      prev_shift = shift;
      for( i = 0; i < sizeof(MonstersVid)/4; i++ )
      {
        delta_speed = (GetVidData(MonstersVid[i],VID_SPEED)*MonsterSpeedPercent[shift/MONSTERS_VID_COUNT])/100;
        SetVidData(MonstersVid[i],VID_SPEED,GetVidData(MonstersVid[i],VID_SPEED) + delta_speed);
      }
    }
    for( i = 0; i < MONSTERS_VID_COUNT; i++ )
      if( MonsterBirthP[shift+i] )
      {
        if( !Random( 600/MonsterBirthP[shift+i] - 1 ) ||
            (MonsterBirthP[shift+i]==1 && ((GetTime()-StartGameTime)%30000) > 15000) )//если в этой минуте должен был родится 1 монстр и не родился за 55 секунд то рожаем
        {
          do
          {
            x=Random(3);
            if     ( x==0 ) { x=-50;                y=Random(MapSizeY()); }
            else if( x==1 ) { x=MapSizeX()+50;      y=Random(MapSizeY()); }
            else if( x==2 ) { x=Random(MapSizeX()); y=-50;                }
            else            { x=Random(MapSizeX()); y=MapSizeY()+50;      }
          } while( CanPlace(MonstersVid[i],x,y,0) );
//          Action( CreateSprite((4+i/3)*10+(i%3)*3,x,y,0), ACT_ATTACK,Flagman(0),0);
          unit = CreateSprite(MonstersVid[i],x,y,0);
          Action( unit, ACT_ATTACK,Flagman(0),0);
          if( IsBossVid( MonstersVid[i] ) )
            arrowed_unit = unit;
          if( MonsterBirthP[shift+i] == 1 )
            MonsterBirthP[shift+i] = 0;
        }
      }
    if( Flagman(0) )
    {
      if( arrowed_unit )
      {
        if( !ArrowHint )
          ArrowHint = CreateSprite(786,GetX(Flagman(0)),GetY(Flagman(0)),GetZ(Flagman(0)));
      }
      else if( ArrowHint )
      {
        Destroy(ArrowHint);
        ArrowHint = 0;
      }
    }
  }
  if( ArrowHint )
    if( arrowed_unit )
    {
      dir = DirectionTo(Flagman(0),GetX(arrowed_unit),GetY(arrowed_unit));
      Action(ArrowHint,ACT_CHANGE_DIRECTION,dir);
//        Action(ArrowHint,ACT_CHANGE_COOR,GetX(Flagman(0)),GetY(Flagman(0)),GetZ(Flagman(0))+11);
      Action(ArrowHint,ACT_CHANGE_COOR,GetX(Flagman(0))+Sin(dir)/25,GetY(Flagman(0))-Cos(dir)/25,GetZ(Flagman(0)));
    }
}
