// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::MaintainPlayerStamina()
void WorldStateUpdater::MaintainPlayerStamina() {
  for (unsigned int i = 0; i < mpWorldState->GetPlayerList().size(); ++i) {
    PlayerState *player = mpWorldState->GetPlayerList()[i];

    // 更新所有球员的mMinStamina
    player->UpdateMinStamina(PlayerParam::instance().MinStamina());
    if (player->GetUnum() == mSelfUnum && // 暂时只考虑自己
        mpWorldState->CurrentTime().T() <=
            ServerParam::instance().halfTime() *
                ServerParam::instance().nrNormalHalfs()) // 常规时间
    {
      const int reserve_cycle =
          ServerParam::instance().halfTime() -
          mpWorldState->CurrentTime().T() %
              ServerParam::instance().halfTime(); // 这个半场还剩多少周期
      const int cycle_buffer =
          (int)((player->GetStamina() + player->GetExtraStamina()) /
                ServerParam::instance().maxPower());
      if (reserve_cycle <=
          cycle_buffer) // 近似认为每个半场的最后若干周期可以不考虑体力
      {
        player->UpdateMinStamina(0.0);
      }
    }

    const PlayerState *last_cycle_player =
        &mpWorldState->GetHistory(1)->GetPlayer(player->GetUnum());
    if (player->GetUnum() == mSelfUnum)
      continue;
    if (player->IsAlive() && last_cycle_player->IsAlive()) {
      double power = 0.0; //认为没有dash

      if (player->GetVelDelay() == 0 &&
          last_cycle_player->GetVelDelay() ==
              0) { //一次确定的dash -- 暂时不考虑侧dash
        double acc = (player->GetVel() -
                      last_cycle_player->GetVel() * player->GetDecay())
                         .Mod();
        power =
            acc / (player->GetDashPowerRate() * last_cycle_player->GetEffort());
      }

      double stamina = last_cycle_player->GetStamina();
      double recovery = last_cycle_player->GetRecovery();
      double effort = last_cycle_player->GetEffort();

      stamina -= (power > 0.0) ? power : -2.0 * power;
      if (stamina <= ServerParam::instance().recoverDecStamina() &&
          recovery > ServerParam::instance().recoverMin())
        recovery -= ServerParam::instance().recoverDec();
      if (stamina <= ServerParam::instance().effortDecStamina() &&
          effort > last_cycle_player->GetEffortMin())
        effort -= ServerParam::instance().effortDec();
      if (stamina >= ServerParam::instance().effortIncStamina() &&
          effort < 1.0) {
        effort += ServerParam::instance().effortInc();
        if (effort > 1.0) {
          effort = 1.0;
        }
      }
      stamina += recovery * last_cycle_player->GetStaminaIncMax();
      if (stamina > ServerParam::instance().staminaMax()) {
        stamina = ServerParam::instance().staminaMax();
      }
      // tracer stamina may error, give the min stamina
      if (stamina < ServerParam::instance().recoverDecStamina() + 100) {
        stamina = ServerParam::instance().recoverDecStamina() + 100;
      }

      player->UpdateStamina(stamina);
      player->UpdateEffort(effort);
      player->UpdateRecovery(recovery);
    } else {
      player->UpdateStamina(ServerParam::instance().staminaMax());
      player->UpdateEffort(player->GetEffortMax());
      player->UpdateRecovery(1.0);
    }

    if (player->GetUnum() > 0) {
      if (player->GetArmPointDelay() == 0 &&
          fabs(player->GetArmPointDir()) >
              MAX_POINT_DIR + 30.0) { //队友因为没体力point
        //				std::cout << "#" << SelfState().GetUnum() << "
        //see @" << mpWorldState->CurrentTime() << ": teammate " <<
        //player->GetUnum() << " point dir 180" << std::endl;
        //	if(mIsZeroStamina[player->GetUnum()])
        //		player->UpdateStamina(0.0);
        //	else
        //		if(!mIsZeroStamina[player->GetUnum()]&&fabs(player->GetStamina())<FLOAT_EPS)
        //			player->UpdateStamina(PlayerParam::instance().LowStaminaPointThr());
        //		else
        player->UpdateStamina(Min(PlayerParam::instance().LowStaminaPointThr(),
                                  player->GetStamina()));
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdi), %rcx
movq 0x20f8(%rcx), %rax
cmpq %rax, 0x2100(%rcx)
je 0x6165c
movq %rdi, %rbx
xorl %r15d, %r15d
movq (%rax,%r15,8), %r12
callq 0x43dce
movsd 0x5c60(%rax), %xmm0
movsd %xmm0, 0x168(%r12)
movl 0x11c(%r12), %eax
cmpl 0x14(%rbx), %eax
jne 0x61255
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r14d
callq 0x49360
movl 0x3238(%rax), %r13d
callq 0x49360
imull 0x3240(%rax), %r13d
cmpl %r13d, %r14d
jg 0x61255
callq 0x49360
movl 0x3238(%rax), %r13d
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r14d
callq 0x49360
movq %rax, %rcx
movl %r14d, %eax
cltd
idivl 0x3238(%rcx)
subl %edx, %r13d
movsd 0x78(%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x40(%rbp), %xmm0
addsd 0x3050(%rax,%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd -0x40(%rbp), %xmm0
divsd 0x3130(%rax), %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %r13d
jg 0x61255
movq $0x0, 0x168(%r12)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x14b90(%rax), %ecx
addl $0x9, %ecx
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %ecx
movslq %ecx, %rcx
imulq $0x2128, %rcx, %rcx     # imm = 0x2128
addq %rax, %rcx
movl 0x11c(%r12), %eax
testl %eax, %eax
jle 0x612b4
leal -0x1(%rax), %edx
imulq $0x178, %rdx, %rdx      # imm = 0x178
leaq (%rcx,%rdx), %r14
addq $0xa8, %r14
jmp 0x612cd
movl %eax, %edx
notl %edx
movslq %edx, %rdx
imulq $0x178, %rdx, %rdx      # imm = 0x178
leaq (%rcx,%rdx), %r14
addq $0x10d0, %r14           # imm = 0x10D0
cmpl 0x14(%rbx), %eax
je 0x61621
cmpb $0x1, 0x112(%r12)
jne 0x6155c
cmpb $0x1, 0x112(%r14)
jne 0x6155c
xorpd %xmm2, %xmm2
cmpl $0x0, 0x40(%r12)
jne 0x61385
cmpl $0x0, 0x40(%r14)
jne 0x61385
movsd 0x58(%r12), %xmm0
movsd 0x30(%r14), %xmm1
mulsd %xmm0, %xmm1
mulsd 0x38(%r14), %xmm0
movsd 0x30(%r12), %xmm2
subsd %xmm1, %xmm2
movsd 0x38(%r12), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0x43dce
movapd -0x40(%rbp), %xmm2
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3030(%rax,%rcx), %xmm0
mulsd 0x80(%r14), %xmm0
divsd %xmm0, %xmm2
movsd 0x90(%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x78(%r14), %xmm3
movsd 0x80(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
movapd %xmm2, %xmm0
mulsd 0x7ccd(%rip), %xmm0     # 0x69080
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
subsd %xmm1, %xmm3
movsd %xmm3, -0x30(%rbp)
callq 0x49360
movsd 0x3438(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x61410
callq 0x49360
movsd -0x48(%rbp), %xmm0
ucomisd 0x3068(%rax), %xmm0
jbe 0x61410
callq 0x49360
movsd -0x48(%rbp), %xmm0
subsd 0x3070(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x49360
movsd 0x3430(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x61465
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x40(%rbp), %xmm0
ucomisd 0x3060(%rax,%rcx), %xmm0
jbe 0x61465
callq 0x49360
movsd -0x40(%rbp), %xmm0
subsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x49360
movsd -0x30(%rbp), %xmm0
ucomisd 0x3440(%rax), %xmm0
jb 0x614bb
movsd 0x7bd7(%rip), %xmm0     # 0x69058
movsd -0x40(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x614bb
movsd %xmm1, -0x40(%rbp)
callq 0x49360
movsd 0x7bba(%rip), %xmm0     # 0x69058
movsd -0x40(%rbp), %xmm1
addsd 0x30a0(%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
ucomisd %xmm0, %xmm1
jbe 0x614bb
movsd %xmm0, -0x40(%rbp)
callq 0x43dce
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3018(%rax,%rcx), %xmm0
mulsd -0x48(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movsd -0x30(%rbp), %xmm0
ucomisd 0x3048(%rax), %xmm0
jbe 0x6150e
callq 0x49360
movsd 0x3048(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movsd 0x3438(%rax), %xmm0
addsd 0x8208(%rip), %xmm0     # 0x69730
ucomisd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm0
jbe 0x61549
callq 0x49360
movsd 0x3438(%rax), %xmm0
addsd 0x81e7(%rip), %xmm0     # 0x69730
movsd %xmm0, 0x78(%r12)
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
jmp 0x6159c
callq 0x49360
movsd 0x3048(%rax), %xmm0
movsd %xmm0, 0x78(%r12)
callq 0x43dce
movsd 0x7adb(%rip), %xmm0     # 0x69058
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3058(%rax,%rcx), %xmm1
movsd %xmm1, 0x80(%r12)
movsd %xmm0, 0x90(%r12)
cmpl $0x0, 0x11c(%r12)
jle 0x61621
cmpl $0x0, 0xe8(%r12)
jne 0x61621
movsd 0xe0(%r12), %xmm0
movsd 0x7a88(%rip), %xmm1     # 0x69060
ucomisd %xmm0, %xmm1
jbe 0x61648
addsd 0x7a8a(%rip), %xmm0     # 0x69070
movsd 0x7a72(%rip), %xmm1     # 0x69060
ucomisd %xmm0, %xmm1
ja 0x615de
andpd 0x7a14(%rip), %xmm0     # 0x69010
ucomisd 0x91cc(%rip), %xmm0     # 0x6a7d0
jbe 0x61621
callq 0x43dce
movsd 0x78(%r12), %xmm0
minsd 0x5c88(%rax), %xmm0
movsd %xmm0, 0x78(%r12)
incl %r15d
movq 0x8(%rbx), %rcx
movq 0x20f8(%rcx), %rax
movq 0x2100(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x61175
jmp 0x6165c
ucomisd 0x79f8(%rip), %xmm0     # 0x69048
jb 0x615f4
addsd 0x7a0e(%rip), %xmm0     # 0x69068
jmp 0x61648
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop