// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/Kicker.cpp
// Function: Kicker::KickBall(Agent&, Vector const&, double, KickMode, int*, bool)
bool Kicker::KickBall(Agent &agent, const Vector &target, double speed_out,
                      KickMode mode, int *cycle_left, bool is_shoot) {
  UpdateKickData(agent);

  double speed_buf = 0.0;
  switch (mode) {
  case KM_Hard:
    speed_buf = 0.04;
    break;
  case KM_Quick:
    speed_buf = 0.08; // 要快速踢出去，速度小一点也没关系
    break;
  default:
    speed_buf = 0.06;
    break;
  }

  double speed[] = {0.0, 0.0, 0.0, 0.0, ServerParam::instance().ballSpeedMax()};
  int kick_cycle = 1;
  double kick_speed = speed_out;

  for (int i = 1; i <= 4; ++i) {
    speed[i] = GetMaxSpeed(agent, target, i);

    if (speed[i] < 0.01) // 能产生的速度太小，不考虑
    {
      continue;
    }
    if (speed[i] + speed_buf > speed_out) {
      kick_cycle = i;
      kick_speed = Min(speed_out, speed[i]);
      break;
    }
  }

  if (cycle_left != 0) {
    *cycle_left = kick_cycle - 1;
  }

  bool rt = KickBall(
      agent, target, kick_speed, kick_cycle,
      is_shoot); // 花kick_cycle周期踢球，目标点为target，出球速度为SpeedOut
  return rt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %r9b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
movq -0x10(%rbp), %rsi
callq 0x50020
movq $0x0, -0x40(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x8c(%rbp)
subl $0x1, %eax
je 0x54254
jmp 0x54247
movl -0x8c(%rbp), %eax
subl $0x2, %eax
je 0x54263
jmp 0x54272
movsd 0x6e01c(%rip), %xmm0    # 0xc2278
movsd %xmm0, -0x40(%rbp)
jmp 0x5427f
movsd 0x6d92d(%rip), %xmm0    # 0xc1b98
movsd %xmm0, -0x40(%rbp)
jmp 0x5427f
movsd 0x6e496(%rip), %xmm0    # 0xc2710
movsd %xmm0, -0x40(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0xa310
callq 0x855e0
movq %rax, %rdi
callq 0x23d60
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x1, -0x74(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movl $0x1, -0x84(%rbp)
cmpl $0x4, -0x84(%rbp)
jg 0x54374
movq -0x98(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x84(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x51150
movslq -0x84(%rbp), %rax
movsd %xmm0, -0x70(%rbp,%rax,8)
movslq -0x84(%rbp), %rax
movsd 0x6d3c4(%rip), %xmm0    # 0xc16d0
ucomisd -0x70(%rbp,%rax,8), %xmm0
jbe 0x54316
jmp 0x54360
movslq -0x84(%rbp), %rax
movsd -0x70(%rbp,%rax,8), %xmm0
addsd -0x40(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x5435e
movl -0x84(%rbp), %eax
movl %eax, -0x74(%rbp)
movslq -0x84(%rbp), %rax
leaq -0x70(%rbp), %rsi
shlq $0x3, %rax
addq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x12a60
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x54374
jmp 0x54360
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x542c0
cmpq $0x0, -0x30(%rbp)
je 0x54387
movl -0x74(%rbp), %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x98(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x80(%rbp), %xmm0
movl -0x74(%rbp), %ecx
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %r8d
callq 0x52060
andb $0x1, %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)