// File: /workspace/github_cpp_makefile_star2_O2/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 %rdi, %rbx
xorl %r12d, %r12d
movl %r12d, %r12d
movq 0x8(%rbx), %rcx
movq 0x20f8(%rcx), %rax
movq 0x2100(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x514b4
movq (%rax,%r12,8), %r14
callq 0x38d94
movsd 0x5c60(%rax), %xmm0
movsd %xmm0, 0x168(%r14)
movl 0x11c(%r14), %eax
cmpl 0x14(%rbx), %eax
jne 0x51191
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r15d
callq 0x3db2c
movl 0x3238(%rax), %r13d
callq 0x3db2c
imull 0x3240(%rax), %r13d
cmpl %r13d, %r15d
jg 0x51191
callq 0x3db2c
movl 0x3238(%rax), %r13d
movq 0x8(%rbx), %rax
movl 0x10(%rax), %r15d
callq 0x3db2c
movq %rax, %rcx
movl %r15d, %eax
cltd
idivl 0x3238(%rcx)
subl %edx, %r13d
movsd 0x78(%r14), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r14, %rdi
callq 0xcf86
movsd -0x40(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x3db2c
movsd -0x40(%rbp), %xmm0
divsd 0x3130(%rax), %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %r13d
jg 0x51191
andq $0x0, 0x168(%r14)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rsi
movl 0x14b90(%rsi), %eax
addl $0x9, %eax
cltd
pushq $0xa
popq %rcx
idivl %ecx
movslq %edx, %rax
imulq $0x2128, %rax, %rcx     # imm = 0x2128
addq %rsi, %rcx
movl 0x11c(%r14), %eax
testl %eax, %eax
jle 0x511d7
leal -0x1(%rax), %edx
imulq $0x178, %rdx, %rdx      # imm = 0x178
leaq (%rcx,%rdx), %r15
addq $0xa8, %r15
jmp 0x511f0
movl %eax, %edx
notl %edx
movslq %edx, %rdx
imulq $0x178, %rdx, %rdx      # imm = 0x178
leaq (%rcx,%rdx), %r15
addq $0x10d0, %r15           # imm = 0x10D0
cmpl 0x14(%rbx), %eax
je 0x514ac
cmpb $0x1, 0x112(%r14)
jne 0x5142c
cmpb $0x1, 0x112(%r15)
jne 0x5142c
xorpd %xmm2, %xmm2
cmpl $0x0, 0x40(%r14)
jne 0x51284
cmpl $0x0, 0x40(%r15)
jne 0x51284
movsd 0x58(%r14), %xmm0
movsd 0x30(%r15), %xmm1
mulsd %xmm0, %xmm1
mulsd 0x38(%r15), %xmm0
movsd 0x30(%r14), %xmm2
subsd %xmm1, %xmm2
movsd 0x38(%r14), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
sqrtsd %xmm2, %xmm0
movapd %xmm0, -0x40(%rbp)
movq %r14, %rdi
callq 0xd2d2
movapd -0x40(%rbp), %xmm2
movsd (%rax), %xmm0
mulsd 0x80(%r15), %xmm0
divsd %xmm0, %xmm2
movsd 0x90(%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x78(%r15), %xmm3
movsd 0x80(%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
movapd %xmm2, %xmm0
mulsd 0x5da6(%rip), %xmm0     # 0x57058
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
subsd %xmm1, %xmm3
movsd %xmm3, -0x30(%rbp)
callq 0x3db2c
movsd 0x3438(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x5130f
callq 0x3db2c
movsd -0x48(%rbp), %xmm0
ucomisd 0x3068(%rax), %xmm0
jbe 0x5130f
callq 0x3db2c
movsd -0x48(%rbp), %xmm0
subsd 0x3070(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x3db2c
movsd 0x3430(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x5134d
movq %r15, %rdi
callq 0x1cd6e
movsd -0x40(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x5134d
callq 0x3db2c
movsd -0x40(%rbp), %xmm0
subsd 0x3090(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x3db2c
movsd -0x30(%rbp), %xmm0
ucomisd 0x3440(%rax), %xmm0
jb 0x513a3
movsd 0x5cdf(%rip), %xmm0     # 0x57048
movsd -0x40(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x513a3
movsd %xmm1, -0x40(%rbp)
callq 0x3db2c
movsd 0x5cc2(%rip), %xmm0     # 0x57048
movsd -0x40(%rbp), %xmm1
addsd 0x30a0(%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
ucomisd %xmm0, %xmm1
jbe 0x513a3
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
callq 0x1cd18
movsd (%rax), %xmm0
mulsd -0x48(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
movsd -0x30(%rbp), %xmm0
ucomisd 0x3048(%rax), %xmm0
jbe 0x513df
callq 0x3db2c
movsd 0x3048(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
movsd 0x3438(%rax), %xmm0
addsd 0x630f(%rip), %xmm0     # 0x57708
ucomisd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm0
jbe 0x5141a
callq 0x3db2c
movsd 0x3438(%rax), %xmm0
addsd 0x62ee(%rip), %xmm0     # 0x57708
movsd %xmm0, 0x78(%r14)
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
jmp 0x51453
callq 0x3db2c
movsd 0x3048(%rax), %xmm0
movsd %xmm0, 0x78(%r14)
movq %r14, %rdi
callq 0x1cda2
movsd 0x5bf9(%rip), %xmm0     # 0x57048
movsd (%rax), %xmm1
movsd %xmm1, 0x80(%r14)
movsd %xmm0, 0x90(%r14)
cmpl $0x0, 0x11c(%r14)
jle 0x514ac
cmpl $0x0, 0xe8(%r14)
jne 0x514ac
movq %r14, %rdi
callq 0x3ad8e
andpd 0x5b87(%rip), %xmm0     # 0x57010
ucomisd 0x730f(%rip), %xmm0     # 0x587a0
jbe 0x514ac
callq 0x38d94
movsd 0x78(%r14), %xmm0
minsd 0x5c88(%rax), %xmm0
movsd %xmm0, 0x78(%r14)
incl %r12d
jmp 0x510af
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop