// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::UpdateSelfInfo()
void WorldStateUpdater::UpdateSelfInfo() {

  SelfState().SetIsAlive(true);
  SelfState().UpdateIsSensed(true); // “真正”的自己

  //=============================更新自己的sense========================
  UpdateSelfSense();
  /*
          //==========================according to speed of this cycle estimate
     position of this cycle======================= if
     (mpObserver->GetPlayerMoveTime() != mpObserver->CurrentTime())
          {
                  Vector vel = SelfState().GetVel();

                  if (mpObserver->Sense().IsCollideWithBall() ||
     mpObserver->Sense().IsCollideWithPlayer() ||
     mpObserver->Sense().IsCollideWithPost())
                  {
                          //when collided ,velocity should be changed to normal;
                          vel /= -0.1;
                  }

                  Vector last_pos =
     mpWorldState->GetHistory(1)->Teammate(GetSelfUnum()).GetPos();
                  SelfState().UpdatePos(last_pos + vel /
     ServerParam::instance().ballDecay() , SelfState().GetPosDelay()
     ,SelfState().GetPosConf());
          }
  */

  //到此为止自己的身体角度和脖子角度更新对了
  //计算公式见USTC_Material 第七章
  // playerVel = polar2vector(speedValue, neckGlobalAngle + speedAngle)
  Vector vec = Polar2Vector(mpObserver->Sense().GetSpeed(),
                            mpObserver->Sense().GetSpeedDir() +
                                GetSelf().GetNeckGlobalDir());
  SelfState().UpdateVel(vec);

  //用自己更新后的速度预测自己的位置,比之前的预测准.见08
  if (!mpObserver->Sense().IsCollideWithBall() &&
      !mpObserver->Sense().IsCollideWithPlayer() &&
      mpObserver->GetPlayerMoveTime() != mpObserver->CurrentTime()) {
    const Vector &pre_pos =
        mpWorldState->GetHistory(1)->GetTeammate(mSelfUnum).GetPos();
    double conf =
        mpWorldState->GetHistory(1)->GetTeammate(mSelfUnum).GetPosConf();

    if (conf > PlayerParam::instance().minValidConf()) {

      Vector pos = pre_pos + vec / SelfState().GetPlayerDecay();
      SelfState().UpdatePos(pos, SelfState().GetPosDelay(),
                            SelfState().GetPosConf());
    }
  }

  //评估自己位置误差
  //,目前最大问题是server移人,而人不知.目前处理是如果dropball以及playmode模式改变是将位置eps加到极大
  if (mpWorldState->GetPlayModeTime() == mpWorldState->CurrentTime() ||
      mpWorldState->IsBallDropped()) {
    SelfState().UpdatePosEps(10000);
  }

  //===============================更新自己的视觉======================
  if (mpObserver->IsNewSight()) {
    //更新自己的头部和身体角度
    double neck_globe_angle = 0.0;

    if (ComputeSelfDir(neck_globe_angle)) {
      //计算公式见USTC_Material 第七章
      // bodyGlobalAngle = neckGlobalAngle – head_angle
      if (mSightDelay <= HistoryState::HISTORY_SIZE) {
        const PlayerState &player =
            mpWorldState->GetHistory(mSightDelay)->GetTeammate(mSelfUnum);
        SelfState().UpdateBodyDir(neck_globe_angle - player.GetNeckDir(),
                                  mSightDelay, mPlayerConf);
      } else {
        PRINT_ERROR("mSightDelay too big!!" << mSightDelay);
        SelfState().UpdateBodyDir(neck_globe_angle - SelfState().GetNeckDir(),
                                  mSightDelay, mPlayerConf);
      }
    }

    if (mSightDelay == 0) {
      //修正自己的速度 当且仅当不出现视觉延迟时.
      Vector vec = Polar2Vector(mpObserver->Sense().GetSpeed(),
                                mpObserver->Sense().GetSpeedDir() +
                                    GetSelf().GetNeckGlobalDir());
      SelfState().UpdateVel(vec);
    }

    //更新自己的位置
    Vector pos;
    double eps = 0;
    if (ComputeSelfPos(pos, eps)) {
      if (eps > SelfState().GetPosEps()) {
        //根据统计值,x,y单个分量差值大于1基本不存在 因此取1
        if (pos.Dist2(SelfState().GetPos()) < 1) {
          pos = SelfState().GetPos();
          eps = SelfState().GetPosEps();
        }

      } else if (eps == SelfState().GetPosEps()) {
        if (pos.Dist2(SelfState().GetPos()) < 1) {
          pos = (pos + SelfState().GetPos()) / 2;
        }
      }

      SelfState().UpdatePos(pos, mSightDelay, mPlayerConf);
      SelfState().UpdatePosEps(eps);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xbc740
movq %rax, %rdi
movl $0x1, %esi
callq 0x288a0
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
movl $0x1, %esi
callq 0x7d1d0
movq -0xd8(%rbp), %rdi
callq 0xb5150
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbce60
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xe8(%rbp)
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbce80
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xe0(%rbp)
callq 0xbcea0
movq %rax, %rdi
callq 0xa95b0
movq -0xe8(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x112c0
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
callq 0xbc740
movq %rax, %rdi
leaq -0x18(%rbp), %rsi
xorl %edx, %edx
movsd 0x11fac(%rip), %xmm0    # 0xc1010
callq 0x142a0
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbcec0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xc9(%rbp)
jne 0xaf0ec
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbcee0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xc9(%rbp)
jne 0xaf0ec
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0xbcf00
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x28(%rbp)
movq (%rax), %rdi
callq 0x11a70
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x175f0
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0xaf0fb
jmp 0xaf254
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0xab550
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
addq $0x14, %rsi
callq 0x12520
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0xab550
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
addq $0x14, %rsi
callq 0x12520
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1d930
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0x1d950
movsd -0xf0(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xaf252
movq -0xd8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq %rax, -0x108(%rbp)
callq 0xbc740
movq %rax, %rdi
callq 0x11740
movsd (%rax), %xmm0
leaq -0x18(%rbp), %rdi
callq 0x1eef0
movq -0x108(%rbp), %rdi
movsd %xmm0, -0x58(%rbp)
movsd %xmm1, -0x50(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x11360
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
callq 0xbc740
movq -0xd8(%rbp), %rdi
movq %rax, -0x100(%rbp)
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1ddd0
movq -0xd8(%rbp), %rdi
movl %eax, -0xf4(%rbp)
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1d930
movq -0x100(%rbp), %rdi
movl -0xf4(%rbp), %edx
movsd (%rax), %xmm0
leaq -0x48(%rbp), %rsi
callq 0x142f0
jmp 0xaf254
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x253d0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x110(%rbp)
movq 0x8(%rax), %rdi
callq 0x12100
movq -0x110(%rbp), %rdi
movq %rax, %rsi
callq 0x120a0
testb $0x1, %al
jne 0xaf2a7
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xbcf20
testb $0x1, %al
jne 0xaf2a7
jmp 0xaf2c7
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
movsd 0x13c1e(%rip), %xmm0    # 0xc2ee0
callq 0xbc830
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0x28a50
testb $0x1, %al
jne 0xaf2df
jmp 0xaf781
movq -0xd8(%rbp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0xb5780
testb $0x1, %al
jne 0xaf300
jmp 0xaf463
movq -0xd8(%rbp), %rax
cmpl $0xa, 0x28(%rax)
jg 0xaf393
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rdi
movl 0x28(%rax), %esi
callq 0xab550
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
addq $0x14, %rsi
callq 0x12520
movq -0xd8(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0xbc740
movq %rax, -0x120(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movq -0x68(%rbp), %rdi
callq 0x118d0
movq -0xd8(%rbp), %rax
movq -0x120(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x118(%rbp), %xmm0
subsd %xmm1, %xmm0
movl 0x28(%rax), %esi
movsd 0x18(%rax), %xmm1
callq 0x77ef0
jmp 0xaf461
jmp 0xaf395
movq 0x4ec54(%rip), %rdi     # 0xfdff0
leaq 0x165a5(%rip), %rsi     # 0xc5948
callq 0xa5a0
movq %rax, %rdi
leaq 0x15e9f(%rip), %rsi     # 0xc5251
callq 0xa5a0
movq %rax, %rdi
movl $0x2f1, %esi            # imm = 0x2F1
callq 0xaa40
movq %rax, %rdi
leaq 0x14191(%rip), %rsi     # 0xc355f
callq 0xa5a0
movq %rax, %rdi
leaq 0x16581(%rip), %rsi     # 0xc595e
callq 0xa5a0
movq %rax, %rdi
movq -0xd8(%rbp), %rax
movl 0x28(%rax), %esi
callq 0xaa40
movq %rax, %rdi
movq 0x4ebb2(%rip), %rsi     # 0xfdfb0
callq 0xa630
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq -0xd8(%rbp), %rdi
movq %rax, -0x130(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
callq 0xbc740
movq %rax, %rdi
callq 0x118d0
movq -0xd8(%rbp), %rax
movq -0x130(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x128(%rbp), %xmm0
subsd %xmm1, %xmm0
movl 0x28(%rax), %esi
movsd 0x18(%rax), %xmm1
callq 0x77ef0
jmp 0xaf463
movq -0xd8(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xaf51c
movq -0xd8(%rbp), %rax
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbce60
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x140(%rbp)
movq (%rax), %rdi
callq 0x119d0
movq %rax, %rdi
callq 0xbce80
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
callq 0xbcea0
movq %rax, %rdi
callq 0xa95b0
movq -0x140(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x138(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x112c0
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x78(%rbp)
movsd %xmm1, -0x70(%rbp)
callq 0xbc740
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
xorl %edx, %edx
movsd 0x11af9(%rip), %xmm0    # 0xc1010
callq 0x142a0
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x11a10
movq -0xd8(%rbp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
leaq -0x90(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0xb59a0
testb $0x1, %al
jne 0xaf57a
jmp 0xaf77f
movq -0xd8(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0xbcf40
movsd -0x148(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xaf642
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x49040
movaps %xmm0, %xmm1
movsd 0x11a2a(%rip), %xmm0    # 0xc1010
ucomisd %xmm1, %xmm0
jbe 0xaf63d
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xd8(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0xbcf40
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0xaf735
movq -0xd8(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0xbcf40
movsd -0x150(%rbp), %xmm0
ucomisd (%rax), %xmm0
jne 0xaf733
jp 0xaf733
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x49040
movaps %xmm0, %xmm1
movsd 0x1195c(%rip), %xmm0    # 0xc1010
ucomisd %xmm1, %xmm0
jbe 0xaf731
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x11360
movsd %xmm0, -0xc8(%rbp)
movsd %xmm1, -0xc0(%rbp)
leaq -0xc8(%rbp), %rdi
movsd 0x11db0(%rip), %xmm0    # 0xc14b0
callq 0x1eef0
movsd %xmm0, -0xb8(%rbp)
movsd %xmm1, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xaf733
jmp 0xaf735
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
movq -0xd8(%rbp), %rax
movl 0x28(%rax), %edx
movsd 0x18(%rax), %xmm0
leaq -0x90(%rbp), %rsi
callq 0x142f0
movq -0xd8(%rbp), %rdi
callq 0xbc740
movq %rax, %rdi
addq $0x8, %rdi
movsd -0xa8(%rbp), %xmm0
callq 0xbc830
jmp 0xaf781
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw (%rax,%rax)