// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Trainer.cpp
// Function: Trainer::ReadRcgFile()
bool Trainer::ReadRcgFile() {
  // TODO 读取之前的PlayMode
  string line;
  const char *buf = 0;
  ifstream fin(mTrainRcg);
  int time = 0, n_read = 0;

  const int begin_time = mTrainTime - mInitialTime;
  const int end_time = mTrainTime;

  ServerPlayMode server_playmode = SPM_PlayOn;

  while (1) {
    vector<PlayerState> ps;
    pair<Vector, Vector> bs;

    bool read = false;

    while (getline(fin, line)) {
      read = true;
      if (!line.compare(0, 5, "(show")) {
        if (sscanf(line.c_str(), "(show %d %n", &time, &n_read) != 1) {
          PRINT_ERROR("error time info:" << line);
          return false;
        }

        if (time >= begin_time) {
          buf = line.c_str();
          buf += n_read;
          break;
        }
      } else if (line.compare(0, 10, "(playmode ") == 0) {
        int time = 0;
        char pm_string[32];

        if (std::sscanf(line.c_str(), " (playmode %d %31[^)] ) ", &time,
                        pm_string) != 2) {
          std::cerr << "error: "
                    << "Illegal playmode line. \"" << line << "\"" << std::endl;
          return false;
        }

        server_playmode =
            ServerPlayModeMap::instance().GetServerPlayMode(pm_string);
      }
    }

    if (!read) {
      break;
    }

    mServerPlayModeList.push_back(server_playmode);

    float bx, by, bvx, bvy;

    if (buf == 0) //没有找到对应周期
    {
      return false;
    }

    {
      if (sscanf(buf, " ((b) %f %f %f %f) %n", &bx, &by, &bvx, &bvy, &n_read) !=
          4) {
        PRINT_ERROR("error ball info:" << line);
        return false;
      }
      buf += n_read;
      bs.first = Vector(bx, by);
      bs.second = Vector(bvx, bvy);
      bs.second /= 0.94;
      bs.first -= bs.second; //这是因为Server接到后会模拟一周期
    }

    // players
    char side;
    short unum;
    short type;
    int state;
    float x, y, vx, vy, body, neck;
    for (int i = 0; i < ServerParam::TEAM_SIZE * 2; ++i) {
      if (*buf == '\0' || *buf == ')')
        break;

      if (sscanf(buf, " ((%c %hd) %hd %x %f %f %f %f %f %f %n", &side, &unum,
                 &type, &state, &x, &y, &vx, &vy, &body, &neck,
                 &n_read) != 10) {
        PRINT_ERROR("error player info:" << buf);
        return false;
      }
      buf += n_read;

      int idx = unum - 1;
      if (side == 'r')
        idx += ServerParam::TEAM_SIZE;
      if (idx < 0 || ServerParam::TEAM_SIZE * 2 <= idx) {
        PRINT_ERROR("error player info:" << buf);
        return false;
      }

      if (side == 'r')
        unum = -unum;

      //对球员的微调安排在开场前，而不是建立前，因为牵涉到Server发来的异构
      ps.push_back(
          Trainer::PlayerState(unum, Vector(x, y), Vector(vx, vy), body, type));

      while (strncmp(buf, "((", 2)) {
        buf++;
        if (*buf == '\0')
          break;
      }
    }

    if (ps.size() == 22) {
      mPlayerStatesList.push_back(ps);
      mBallStateList.push_back(bs);
    }

    if (time >= end_time) {
      break;
    }
  }

  Assert(mPlayerStatesList.size() == mBallStateList.size());
  Assert(mPlayerStatesList.size() == mServerPlayModeList.size());

  return !mPlayerStatesList.empty();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %rbx
movb $0x0, (%rax)
leaq 0xa0(%rdi), %rsi
leaq -0x368(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x9920
leaq -0x3c(%rbp), %rax
andl $0x0, (%rax)
leaq -0x30(%rbp), %rax
andl $0x0, (%rax)
movl 0x98(%rbx), %eax
movl %eax, -0x64(%rbp)
subl 0x138(%rbx), %eax
movl %eax, -0x70(%rbp)
leaq -0x48(%rbp), %rax
movl $0x3, (%rax)
leaq 0x178(%rbx), %rax
movq %rax, -0xd0(%rbp)
leaq 0x1539b(%rip), %rax     # 0x59f38
movl (%rax), %eax
movq %rax, -0xc8(%rbp)
addl %eax, %eax
leaq 0x120(%rbx), %rcx
movq %rcx, -0xc0(%rbp)
movq %rbx, -0xb0(%rbp)
leaq 0x160(%rbx), %rcx
movq %rcx, -0xb8(%rbp)
testl %eax, %eax
movl $0x0, %ecx
movl %eax, -0x68(%rbp)
cmovgl %eax, %ecx
movl %ecx, -0x6c(%rbp)
xorpd %xmm0, %xmm0
leaq -0xa8(%rbp), %r15
xorl %ebx, %ebx
andq $0x0, -0x50(%rbp)
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, -0xf0(%rbp)
movapd %xmm0, -0x100(%rbp)
xorl %r14d, %r14d
leaq -0x368(%rbp), %rdi
movq %r15, %rsi
callq 0x9110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x44d09
movq %r15, %rdi
xorl %esi, %esi
pushq $0x5
popq %rdx
leaq 0x162d3(%rip), %rcx     # 0x5af08
callq 0x9660
testl %eax, %eax
je 0x44cc7
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
leaq 0x13d89(%rip), %rcx     # 0x589da
callq 0x9660
movb $0x1, %r14b
testl %eax, %eax
jne 0x44c05
andl $0x0, -0x38(%rbp)
movq -0xa8(%rbp), %rdi
leaq 0x162bc(%rip), %rsi     # 0x5af2b
leaq -0x38(%rbp), %rdx
leaq -0x140(%rbp), %rcx
xorl %eax, %eax
callq 0x94a0
cmpl $0x2, %eax
jne 0x45089
callq 0x47724
movq %rax, %r13
leaq -0x160(%rbp), %r12
movq %r12, %rdi
leaq -0x140(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x10e4a
movq %r13, %rdi
movq %r12, %rsi
callq 0x484ba
movl %eax, -0x48(%rbp)
movq %r12, %rdi
callq 0x9240
jmp 0x44c05
movq -0xa8(%rbp), %rdi
leaq 0x16239(%rip), %rsi     # 0x5af0e
leaq -0x3c(%rbp), %rdx
leaq -0x30(%rbp), %rcx
xorl %eax, %eax
callq 0x94a0
cmpl $0x1, %eax
jne 0x44f5c
movb $0x1, %r14b
movl -0x70(%rbp), %eax
cmpl %eax, -0x3c(%rbp)
jl 0x44c05
movslq -0x30(%rbp), %rbx
addq -0xa8(%rbp), %rbx
jmp 0x44d13
testb $0x1, %r14b
je 0x45171
movq -0xd0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x45e70
testq %rbx, %rbx
movq -0xc8(%rbp), %r14
je 0x4516c
subq $0x8, %rsp
movq %rbx, %rdi
leaq 0x16224(%rip), %rsi     # 0x5af65
leaq -0x160(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x44(%rbp), %r8
leaq -0x88(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
callq 0x94a0
popq %rcx
popq %rdx
cmpl $0x4, %eax
jne 0x45108
movslq -0x30(%rbp), %rax
cvtss2sd -0x160(%rbp), %xmm0
cvtss2sd -0x38(%rbp), %xmm1
cvtss2sd -0x44(%rbp), %xmm2
addq %rax, %rbx
cvtss2sd -0x88(%rbp), %xmm3
movsd 0x150b0(%rip), %xmm4    # 0x59e48
divsd %xmm4, %xmm2
movsd %xmm2, -0xf0(%rbp)
divsd %xmm4, %xmm3
movsd %xmm3, -0xe8(%rbp)
subsd %xmm2, %xmm0
movsd %xmm0, -0x100(%rbp)
subsd %xmm3, %xmm1
movsd %xmm1, -0xf8(%rbp)
xorl %r13d, %r13d
cmpl -0x6c(%rbp), %r13d
je 0x44f09
movzbl (%rbx), %eax
testl %eax, %eax
je 0x44f09
cmpl $0x29, %eax
je 0x44f09
subq $0x8, %rsp
movq %rbx, %rdi
leaq 0x16195(%rip), %rsi     # 0x5af8c
leaq -0x29(%rbp), %rdx
leaq -0x32(%rbp), %rcx
leaq -0x3e(%rbp), %r8
leaq -0xd8(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
leaq -0xd4(%rbp), %r10
pushq %r10
leaq -0x74(%rbp), %r10
pushq %r10
leaq -0x78(%rbp), %r10
pushq %r10
leaq -0x7c(%rbp), %r10
pushq %r10
leaq -0x80(%rbp), %r10
pushq %r10
leaq -0x84(%rbp), %r10
pushq %r10
callq 0x94a0
addq $0x40, %rsp
cmpl $0xa, %eax
jne 0x44fc5
movslq -0x30(%rbp), %rax
addq %rax, %rbx
movswl -0x32(%rbp), %eax
movb -0x29(%rbp), %cl
cmpb $0x72, %cl
movl $0x0, %edx
cmovel %r14d, %edx
addl %eax, %edx
decl %edx
js 0x45027
cmpl %edx, -0x68(%rbp)
jle 0x45027
cmpb $0x72, %cl
jne 0x44e87
negl %eax
movw %ax, -0x32(%rbp)
cwtl
cvtss2sd -0x84(%rbp), %xmm0
cvtss2sd -0x80(%rbp), %xmm1
cvtss2sd -0x7c(%rbp), %xmm2
cvtss2sd -0x78(%rbp), %xmm3
cvtss2sd -0x74(%rbp), %xmm4
movswl -0x3e(%rbp), %ecx
movl %eax, -0x140(%rbp)
movsd %xmm0, -0x138(%rbp)
movsd %xmm1, -0x130(%rbp)
movsd %xmm2, -0x128(%rbp)
movsd %xmm3, -0x120(%rbp)
movsd %xmm4, -0x118(%rbp)
movl %ecx, -0x110(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x46732
movb (%rbx), %al
cmpb $0x28, %al
jne 0x44ef7
cmpb $0x28, 0x1(%rbx)
je 0x44f01
movb 0x1(%rbx), %al
incq %rbx
testb %al, %al
jne 0x44eed
incl %r13d
jmp 0x44dcb
movq -0x58(%rbp), %rax
subq -0x60(%rbp), %rax
cmpq $0x4d0, %rax            # imm = 0x4D0
jne 0x44f3c
movq -0xc0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x45e96
movq -0xb8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x45ed2
movl -0x3c(%rbp), %r14d
leaq -0x60(%rbp), %rdi
callq 0x46594
cmpl -0x64(%rbp), %r14d
xorpd %xmm0, %xmm0
jl 0x44be8
jmp 0x4517a
movq 0x3208d(%rip), %rdi     # 0x76ff0
leaq 0x15e50(%rip), %rsi     # 0x5adba
callq 0x94b0
leaq 0x161fc(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x9890
leaq 0x1448d(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x15f79(%rip), %rsi     # 0x5af1a
movq %rax, %rdi
callq 0x94b0
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x9430
movq %rax, %rdi
callq 0x99e8
jmp 0x450d1
movq 0x32024(%rip), %rdi     # 0x76ff0
leaq 0x15de7(%rip), %rsi     # 0x5adba
callq 0x94b0
leaq 0x16193(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x244, %esi            # imm = 0x244
callq 0x9890
leaq 0x14424(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x15fa9(%rip), %rsi     # 0x5afb3
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
jmp 0x45087
movq 0x31fc2(%rip), %rdi     # 0x76ff0
leaq 0x15d85(%rip), %rsi     # 0x5adba
callq 0x94b0
leaq 0x16131(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x24d, %esi            # imm = 0x24D
callq 0x9890
leaq 0x143c2(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x15f47(%rip), %rsi     # 0x5afb3
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
jmp 0x450d1
movq 0x31f60(%rip), %rdi     # 0x76ff0
leaq 0x15ead(%rip), %rsi     # 0x5af44
callq 0x94b0
leaq 0x15ea9(%rip), %rsi     # 0x5af4c
movq %rax, %rdi
callq 0x94b0
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x9430
leaq 0x15ea2(%rip), %rsi     # 0x5af63
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
leaq -0x60(%rbp), %rdi
callq 0x46594
xorl %ebx, %ebx
leaq -0x368(%rbp), %rdi
callq 0x9180
leaq -0xa8(%rbp), %rdi
callq 0x9240
movl %ebx, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x31ee1(%rip), %rdi     # 0x76ff0
leaq 0x15ca4(%rip), %rsi     # 0x5adba
callq 0x94b0
leaq 0x16050(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x22d, %esi            # imm = 0x22D
callq 0x9890
leaq 0x142e1(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x15e2e(%rip), %rsi     # 0x5af7b
movq %rax, %rdi
callq 0x94b0
leaq -0xa8(%rbp), %rsi
movq %rax, %rdi
callq 0x9430
movq %rax, %rdi
callq 0x99e8
jmp 0x450d1
leaq -0x60(%rbp), %rdi
callq 0x46594
movq -0xb0(%rbp), %rcx
movq 0x120(%rcx), %rax
cmpq 0x128(%rcx), %rax
setne %bl
jmp 0x450dc
jmp 0x451c1
jmp 0x451c1
jmp 0x451c1
movq %rax, %rbx
jmp 0x451d9
jmp 0x451c1
jmp 0x451c1
jmp 0x451c1
jmp 0x451c1
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x9240
jmp 0x451c4
jmp 0x451c1
jmp 0x451c1
jmp 0x451c1
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x46594
leaq -0x368(%rbp), %rdi
callq 0x9180
leaq -0xa8(%rbp), %rdi
callq 0x9240
movq %rbx, %rdi
callq 0x98b0
nop