// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movslq 0x14(%rdi), %rax
movq 0x8(%rdi), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
movb $0x1, %dl
movb %dl, 0x42(%rax,%rcx)
movb %dl, 0xa6(%rax,%rcx)
callq 0x517ec
movq (%rbx), %r14
movsd 0x148(%r14), %xmm0
movsd %xmm0, -0x20(%rbp)
addq $0x140, %r14            # imm = 0x140
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
movq $-0xd0, %r15
addq %r15, %rdi
callq 0x4bef2
addsd -0x20(%rbp), %xmm0
leaq -0x30(%rbp), %rsi
movsd %xmm0, (%rsi)
movq %r14, %rdi
callq 0xd15b
leaq -0x50(%rbp), %rsi
movsd %xmm0, (%rsi)
movsd %xmm1, 0x8(%rsi)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
addq %r15, %rdi
movsd 0x8831(%rip), %xmm0     # 0x57048
xorl %edx, %edx
callq 0xdde8
movq (%rbx), %rax
cmpb $0x0, 0x1b2(%rax)
jne 0x4e923
cmpb $0x0, 0x1b1(%rax)
jne 0x4e923
movq 0x5688(%rax), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
cmpl %edx, 0x10(%rax)
jne 0x4e857
cmpl %ecx, 0xc(%rax)
je 0x4e923
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rcx
movl 0x14b90(%rcx), %eax
addl $0x9, %eax
pushq $0xa
popq %rsi
cltd
idivl %esi
movslq %edx, %rax
imulq $0x2128, %rax, %r14     # imm = 0x2128
addq %rcx, %r14
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %r15      # imm = 0x178
movsd -0xb0(%r15,%r14), %xmm0
movsd %xmm0, -0x20(%rbp)
callq 0x38d94
movsd -0x20(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x4e923
addq %r14, %r15
addq $-0xc8, %r15
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
movq $-0xd0, %r14
addq %r14, %rdi
callq 0xd344
movsd (%rax), %xmm0
leaq -0x50(%rbp), %rdi
callq 0x218ee
addsd (%r15), %xmm0
addsd 0x8(%r15), %xmm1
leaq -0x30(%rbp), %rsi
movsd %xmm0, (%rsi)
movsd %xmm1, 0x8(%rsi)
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
addq %rcx, %r14
addq %rax, %r14
movl -0xb8(%rax,%rcx), %edx
movsd -0xb0(%rax,%rcx), %xmm0
movq %r14, %rdi
callq 0xde1c
movq 0x8(%rbx), %rax
movl 0x28(%rax), %ecx
cmpl 0x14(%rax), %ecx
jne 0x4e937
movl 0x10(%rax), %ecx
cmpl %ecx, 0x24(%rax)
je 0x4e93d
cmpb $0x1, 0x2c(%rax)
jne 0x4e95a
movslq 0x14(%rbx), %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
movabsq $0x40c3880000000000, %rdx # imm = 0x40C3880000000000
movq %rdx, -0xa8(%rax,%rcx)
movq (%rbx), %rax
cmpb $0x1, 0x3382(%rax)
jne 0x4ec05
leaq -0x40(%rbp), %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x51b30
testb %al, %al
je 0x4ea5b
movl 0x28(%rbx), %esi
cmpl $0xa, %esi
jg 0x4e9ad
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x4c81e
movslq 0x14(%rbx), %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
addq %rcx, %r14
addq $-0xd0, %r14
jmp 0x4ea27
movq 0x2863c(%rip), %rdi     # 0x76ff0
leaq 0xce4d(%rip), %rsi      # 0x5b808
callq 0x94b0
leaq 0xc7ab(%rip), %rsi      # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x2f1, %esi            # imm = 0x2F1
callq 0x9890
leaq 0xaa3c(%rip), %rsi      # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0xce2c(%rip), %rsi      # 0x5b81e
movq %rax, %rdi
callq 0x94b0
movl 0x28(%rbx), %esi
movq %rax, %rdi
callq 0x9890
movq %rax, %rdi
callq 0x99e8
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%rax,%rcx), %r14
addq $-0xd0, %r14
leaq (%rax,%rcx), %rdi
addq $-0x38, %rdi
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
callq 0xd40e
movsd -0x20(%rbp), %xmm2
subsd %xmm0, %xmm2
movl 0x28(%rbx), %esi
movsd 0x18(%rbx), %xmm1
movq %r14, %rdi
movapd %xmm2, %xmm0
callq 0x382a6
cmpl $0x0, 0x28(%rbx)
jne 0x4eada
movq (%rbx), %r14
movsd 0x148(%r14), %xmm0
movsd %xmm0, -0x20(%rbp)
addq $0x140, %r14            # imm = 0x140
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
movq $-0xd0, %r15
addq %r15, %rdi
callq 0x4bef2
addsd -0x20(%rbp), %xmm0
leaq -0x38(%rbp), %rsi
movsd %xmm0, (%rsi)
movq %r14, %rdi
callq 0xd15b
leaq -0x30(%rbp), %rsi
movsd %xmm0, (%rsi)
movsd %xmm1, 0x8(%rsi)
movslq 0x14(%rbx), %rax
imulq $0x178, %rax, %rdi      # imm = 0x178
addq 0x8(%rbx), %rdi
addq %r15, %rdi
movsd 0x8575(%rip), %xmm0     # 0x57048
xorl %edx, %edx
callq 0xdde8
xorpd %xmm0, %xmm0
leaq -0x30(%rbp), %rsi
movapd %xmm0, (%rsi)
leaq -0x38(%rbp), %rdx
andq $0x0, (%rdx)
movq %rbx, %rdi
callq 0x51c20
testb %al, %al
je 0x4ec05
movsd -0x38(%rbp), %xmm6
movslq 0x14(%rbx), %rcx
movq 0x8(%rbx), %rax
imulq $0x178, %rcx, %rcx      # imm = 0x178
leaq (%rcx,%rax), %rdi
addq $-0xd0, %rdi
movsd 0x28(%rdi), %xmm0
ucomisd %xmm0, %xmm6
jbe 0x4eb6e
movsd -0x30(%rbp), %xmm1
subsd 0x8(%rdi), %xmm1
movsd -0x28(%rbp), %xmm2
subsd 0x10(%rdi), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
movsd 0x84f8(%rip), %xmm2     # 0x57048
ucomisd %xmm1, %xmm2
jbe 0x4ebd2
addq %rcx, %rax
addq $-0xc8, %rax
movupd (%rax), %xmm1
movapd %xmm1, -0x30(%rbp)
movapd %xmm0, %xmm6
jmp 0x4ebd2
jne 0x4ebd2
jp 0x4ebd2
movsd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movsd 0x8(%rdi), %xmm3
movsd 0x10(%rdi), %xmm2
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
movapd %xmm1, %xmm5
subsd %xmm2, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
movsd 0x849e(%rip), %xmm5     # 0x57048
ucomisd %xmm4, %xmm5
jbe 0x4ebd2
addsd %xmm3, %xmm0
addsd %xmm2, %xmm1
movsd 0x8c88(%rip), %xmm2     # 0x57848
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x28(%rbp)
movsd %xmm6, -0x20(%rbp)
movl 0x28(%rbx), %edx
movsd 0x18(%rbx), %xmm0
leaq -0x30(%rbp), %rsi
callq 0xde1c
movslq 0x14(%rbx), %rax
movq 0x8(%rbx), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0xa8(%rcx,%rax)
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq