// File: 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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x80(%rbp), %rax
movl -0xc(%rbp), %ecx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rdi
callq 0x81040
movq %rax, %rdi
callq 0x81170
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0xb4a88
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x81040
movq %rax, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x81190
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0x12c00
movq -0x90(%rbp), %rdi
movsd (%rax), %xmm0
callq 0xbe5c0
movq -0x18(%rbp), %rdi
callq 0x1b470
movq -0x80(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0xb457e
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12100
movq %rax, %rdi
callq 0x13040
movl %eax, -0x94(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0xbd040
movl %eax, -0x98(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0xbd060
movl -0x98(%rbp), %ecx
movl %eax, %edx
movl -0x94(%rbp), %eax
imull %edx, %ecx
cmpl %ecx, %eax
jg 0xb457e
callq 0x855e0
movq %rax, %rdi
callq 0xbd040
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, -0xac(%rbp)
movq 0x8(%rax), %rdi
callq 0x12100
movq %rax, %rdi
callq 0x13040
movl %eax, -0xb0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0xbd040
movl %eax, %ecx
movl -0xb0(%rbp), %eax
cltd
idivl %ecx
movl -0xac(%rbp), %eax
subl %edx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10cd0
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10cf0
movsd -0xa8(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x10f10
movsd -0xa0(%rbp), %xmm0
divsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xb457c
movq -0x18(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xbe5c0
jmp 0xb457e
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0xab550
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1b470
movq -0xb8(%rbp), %rdi
movl %eax, -0x2c(%rbp)
leaq -0x2c(%rbp), %rsi
callq 0x23eb0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1b470
movq -0x80(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0xb45ce
jmp 0xb4a7a
movq -0x18(%rbp), %rdi
callq 0x23f20
testb $0x1, %al
jne 0xb45e0
jmp 0xb4994
movq -0x28(%rbp), %rdi
callq 0x23f20
testb $0x1, %al
jne 0xb45f2
jmp 0xb4994
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x28a30
cmpl $0x0, %eax
jne 0xb46d0
movq -0x28(%rbp), %rdi
callq 0x28a30
cmpl $0x0, %eax
jne 0xb46d0
movq -0x18(%rbp), %rdi
callq 0x10a80
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a80
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1d690
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x13320
movq -0xd0(%rbp), %rdi
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x11670
movsd (%rax), %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11650
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm0
mulsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10cd0
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32a80
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x28(%rbp), %rdi
callq 0x11650
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb4723
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
jmp 0xb4738
movsd 0xc8ed(%rip), %xmm0     # 0xc1018
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0xe0(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b30
movsd -0xe8(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0xb47c1
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b50
movsd -0xf0(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xb47c1
callq 0x855e0
movq %rax, %rdi
callq 0x32b70
movsd (%rax), %xmm1
movsd -0x70(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b90
movsd -0xf8(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0xb4830
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32bb0
movsd -0x100(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xb4830
callq 0x855e0
movq %rax, %rdi
callq 0x32bf0
movsd (%rax), %xmm1
movsd -0x78(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32c10
movsd -0x108(%rbp), %xmm0
ucomisd (%rax), %xmm0
jb 0xb48a4
movsd 0xc7b0(%rip), %xmm0     # 0xc1010
ucomisd -0x78(%rbp), %xmm0
jbe 0xb48a4
callq 0x855e0
movq %rax, %rdi
callq 0x88ae0
movsd (%rax), %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd 0xc781(%rip), %xmm1     # 0xc1010
ucomisd %xmm1, %xmm0
jbe 0xb48a2
movsd 0xc773(%rip), %xmm0     # 0xc1010
movsd %xmm0, -0x78(%rbp)
jmp 0xb48a4
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movq -0x28(%rbp), %rdi
callq 0x328b0
movsd -0x118(%rbp), %xmm0
movsd (%rax), %xmm2
movsd -0x68(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x110(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32930
movsd -0x110(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xb4916
callq 0x855e0
movq %rax, %rdi
callq 0x32930
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32b30
movsd -0x120(%rbp), %xmm1
movsd 0xcd98(%rip), %xmm0     # 0xc16d8
addsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xb4968
callq 0x855e0
movq %rax, %rdi
callq 0x32b30
movsd 0xcd79(%rip), %xmm0     # 0xc16d8
addsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
callq 0x77fd0
movq -0x18(%rbp), %rdi
movsd -0x78(%rbp), %xmm0
callq 0x77ff0
movq -0x18(%rbp), %rdi
movsd -0x70(%rbp), %xmm0
callq 0x78010
jmp 0xb49f1
movq -0x18(%rbp), %rax
movq %rax, -0x130(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x32930
movq -0x130(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x77fd0
movq -0x18(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
callq 0x32c30
movq -0x128(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x77ff0
movq -0x18(%rbp), %rdi
movsd 0xc624(%rip), %xmm0     # 0xc1010
callq 0x78010
movq -0x18(%rbp), %rdi
callq 0x1b470
cmpl $0x0, %eax
jle 0xb4a78
movq -0x18(%rbp), %rdi
callq 0x7d440
cmpl $0x0, %eax
jne 0xb4a76
movq -0x18(%rbp), %rdi
callq 0x7d400
movaps 0xc643(%rip), %xmm1     # 0xc1060
pand %xmm1, %xmm0
movsd 0xdcd7(%rip), %xmm1     # 0xc2700
ucomisd %xmm1, %xmm0
jbe 0xb4a76
movq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0xbe5e0
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10cd0
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x12a60
movq -0x138(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x77fd0
jmp 0xb4a78
jmp 0xb4a7a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xb43de
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)