#define grapple_init
{
  grappleTimer = 0;
  grappled = false;
  mousePressed = false;
  grappleDir = 0;
  grappleX = 0;
  grappleY = 0;
  grappleOriginX = 0;
  grappleOriginY = 0;
  grappleSpeed = argument0;
}
#define grapple_shoot
{
  if (mouse_check_button(mb_left)){
    if (grappleTimer*grappleSpeed < argument0){
      if (!mousePressed){
        grappleOriginX = self.x;
        grappleOriginY = self.y;
        grappleDir = degtorad(point_direction(self.x,self.y,mouse_x,mouse_y));
        grappled = false;
        grappleTimer = 0;
      }
      else if (grappled){
        motion_add(point_direction(self.x,self.y,grappleX,grappleY),power(1.1,point_distance(self.x,self.y,grappleX,grappleY)/1000+argument2/5));
        //grappleDir = point_direction(self.x,self.y,grappleX,grappleY);
      }
      else {
        grappleTimer += 1;
      }
      for (g = 0; g < grappleSpeed; g += 1){
        if (position_meeting(grappleOriginX+(grappleTimer*grappleSpeed+grappleSpeed)*cos(grappleDir),grappleOriginY-(grappleTimer*grappleSpeed+grappleSpeed)*sin(grappleDir),argument1)){
          grappled = true;
          grappleX = grappleOriginX+(grappleTimer*grappleSpeed+grappleSpeed)*cos(grappleDir);
          grappleY = grappleOriginY-(grappleTimer*grappleSpeed+grappleSpeed)*sin(grappleDir);
        }
        else {
          grappled = false;
        }
      }
    }
    else {
      grappleOriginX = self.x;
      grappleOriginY = self.y;
      grappleDir = degtorad(point_direction(self.x,self.y,mouse_x,mouse_y));
      grappleTimer = 0;
    }
    mousePressed = true;
  }
  else{
    mousePressed = false;
  }
}

#define grapple_target
{
  if (mouse_check_button(mb_right)){
    if (grappleTimer*grappleSpeed < argument0){
      if (!mousePressedR){
        targetID = instance_nearest(mouse_x,mouse_y,argument3);
        grappleOriginX = self.x;
        grappleOriginY = self.y;
        grappleDir = degtorad(point_direction(self.x,self.y,targetID.x,targetID.y));
        grappled = false;
        grappleTimer = 0;
      }
      else if (grappled){
        motion_add(point_direction(self.x,self.y,grappleX,grappleY),power(1.1,point_distance(self.x,self.y,grappleX,grappleY)/1000+argument2/5));
        //grappleDir = point_direction(self.x,self.y,grappleX,grappleY);
      }
      else {
        grappleTimer += 1;
      }
      for (g = 0; g < grappleSpeed; g += 1){
        if (position_meeting(grappleOriginX+(grappleTimer*grappleSpeed+grappleSpeed)*cos(grappleDir),grappleOriginY-(grappleTimer*grappleSpeed+grappleSpeed)*sin(grappleDir),argument1)){
          grappled = true;
          grappleX = grappleOriginX+(grappleTimer*grappleSpeed+grappleSpeed)*cos(grappleDir);
          grappleY = grappleOriginY-(grappleTimer*grappleSpeed+grappleSpeed)*sin(grappleDir);
        }
        else {
          grappled = false;
        }
      }
    }
    else {
      grappleOriginX = self.x;
      grappleOriginY = self.y;
      grappleDir = degtorad(point_direction(self.x,self.y,targetID.x,targetID.y));
      grappleTimer = 0;
    }
    mousePressedR = true;
  }
  else {
    mousePressedR = false;
  }
}
#define grapple_draw
{
  pen_size = argument0;
  pen_color = argument1;
  __pen_size = pen_size;
  __pen_color = pen_color;
  draw_set_color(pen_color)
  if (mouse_check_button(mb_left) ||mouse_check_button(mb_right)){
    if (!grappled){
      draw_line(self.x,self.y,grappleOriginX+(grappleTimer*grappleSpeed+grappleSpeed)*cos(grappleDir),grappleOriginY-(grappleTimer*grappleSpeed+grappleSpeed)*sin(grappleDir));
    }
    else {
      draw_line(self.x,self.y,grappleX,grappleY);
    }
  }
  pen_size = __pen_size;
  pen_color = __pen_color;
}

