// File: /workspace/github_cpp_makefile_star2_O1/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 0x635ff
movq %rdi, %rbx
xorl %r15d, %r15d
movq (%rax,%r15,8), %r12
callq 0x450ba
movsd 0x5c60(%rax), %xmm0
movsd %xmm0, 0x168(%r12)
movl 0x11c(%r12), %eax
cmpl 0x14(%rbx), %eax
jne 0x631f5
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r14d
callq 0x4a75c
movl 0x3238(%rax), %r13d
callq 0x4a75c
imull 0x3240(%rax), %r13d
cmpl %r13d, %r14d
jg 0x631f5
callq 0x4a75c
movl 0x3238(%rax), %r13d
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r14d
callq 0x4a75c
movq %rax, %rcx
movl %r14d, %eax
cltd
idivl 0x3238(%rcx)
subl %edx, %r13d
movsd 0x78(%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x450ba
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 0x4a75c
movsd -0x40(%rbp), %xmm0
divsd 0x3130(%rax), %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %r13d
jg 0x631f5
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, %rdx     # imm = 0x2128
movl 0x11c(%r12), %esi
leal -0x1(%rsi), %edi
testl %esi, %esi
movl %esi, %ecx
notl %ecx
cmovgl %edi, %ecx
leaq 0xa8(%rax,%rdx), %rdi
leaq 0x10d0(%rax,%rdx), %r14
cmovgq %rdi, %r14
cmpl 0x14(%rbx), %esi
je 0x635c4
cmpb $0x1, 0x112(%r12)
jne 0x632e5
movslq %ecx, %rax
imulq $0x178, %rax, %rax      # imm = 0x178
addq %rax, %r14
cmpb $0x1, 0x112(%r14)
jne 0x632e5
xorpd %xmm2, %xmm2
cmpl $0x0, 0x40(%r12)
jne 0x6336a
cmpl $0x0, 0x40(%r14)
jne 0x6336a
movsd 0x58(%r12), %xmm1
movsd 0x30(%r14), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x38(%r14), %xmm1
movsd 0x30(%r12), %xmm0
subsd %xmm2, %xmm0
movsd 0x38(%r12), %xmm2
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
ucomisd 0x7db3(%rip), %xmm0     # 0x6b090
jb 0x6332a
sqrtsd %xmm0, %xmm0
jmp 0x6332f
callq 0x4a75c
movsd 0x3048(%rax), %xmm0
movsd %xmm0, 0x78(%r12)
callq 0x450ba
movsd 0x7d52(%rip), %xmm0     # 0x6b058
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3058(%rax,%rcx), %xmm1
jmp 0x6353f
callq 0x93c0
movapd %xmm0, -0x40(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r12), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3030(%rax,%rcx), %xmm0
mulsd 0x80(%r14), %xmm0
movapd -0x40(%rbp), %xmm2
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 0x7ce8(%rip), %xmm0     # 0x6b080
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
subsd %xmm1, %xmm3
movsd %xmm3, -0x30(%rbp)
callq 0x4a75c
movsd 0x3438(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x633f5
callq 0x4a75c
movsd -0x48(%rbp), %xmm0
ucomisd 0x3068(%rax), %xmm0
jbe 0x633f5
callq 0x4a75c
movsd -0x48(%rbp), %xmm0
subsd 0x3070(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x4a75c
movsd 0x3430(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x6344a
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r14), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x40(%rbp), %xmm0
ucomisd 0x3060(%rax,%rcx), %xmm0
jbe 0x6344a
callq 0x4a75c
movsd -0x40(%rbp), %xmm0
subsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x4a75c
movsd -0x30(%rbp), %xmm0
ucomisd 0x3440(%rax), %xmm0
jb 0x634a0
movsd 0x7bf2(%rip), %xmm0     # 0x6b058
movsd -0x40(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x634a0
movsd %xmm1, -0x40(%rbp)
callq 0x4a75c
movsd 0x7bd5(%rip), %xmm0     # 0x6b058
movsd -0x40(%rbp), %xmm1
addsd 0x30a0(%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
ucomisd %xmm0, %xmm1
jbe 0x634a0
movsd %xmm0, -0x40(%rbp)
callq 0x450ba
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 0x4a75c
movsd -0x30(%rbp), %xmm0
ucomisd 0x3048(%rax), %xmm0
jbe 0x634f3
callq 0x4a75c
movsd 0x3048(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movsd 0x3438(%rax), %xmm0
addsd 0x8223(%rip), %xmm0     # 0x6b730
ucomisd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm0
jbe 0x6352e
callq 0x4a75c
movsd 0x3438(%rax), %xmm0
addsd 0x8202(%rip), %xmm0     # 0x6b730
movsd %xmm0, 0x78(%r12)
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd %xmm1, 0x80(%r12)
movsd %xmm0, 0x90(%r12)
cmpl $0x0, 0x11c(%r12)
jle 0x635c4
cmpl $0x0, 0xe8(%r12)
jne 0x635c4
movsd 0xe0(%r12), %xmm0
movsd 0x7ae5(%rip), %xmm1     # 0x6b060
ucomisd %xmm0, %xmm1
jbe 0x635eb
addsd 0x7ae7(%rip), %xmm0     # 0x6b070
movsd 0x7acf(%rip), %xmm1     # 0x6b060
ucomisd %xmm0, %xmm1
ja 0x63581
andpd 0x7a71(%rip), %xmm0     # 0x6b010
ucomisd 0x9239(%rip), %xmm0     # 0x6c7e0
jbe 0x635c4
callq 0x450ba
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 0x63115
jmp 0x635ff
ucomisd 0x7a55(%rip), %xmm0     # 0x6b048
jb 0x63597
addsd 0x7a6b(%rip), %xmm0     # 0x6b068
jmp 0x635eb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq