// File: /workspace/github_cpp_makefile_star2_O2/Worthy-Wang[P]Warcraft3-StartWar/City.cpp
// Function: warcraft::City::blueWarriorAttackFirst()
void City::blueWarriorAttackFirst()
{
    vector<WeaponPtr> &redWeaponLib = redWarrior->getWeapons();
    vector<WeaponPtr> &blueWeaponLib = blueWarrior->getWeapons();
    size_t redWeaponIndex = 0;
    size_t blueWeaponIndex = 0;
    //蓝武士先发动攻击
    while (1)
    {
        bool redWeaponFlag = false, blueWeaponFlag = false;
        bool redHpFlag = false, blueHpFlag = false;

        /****************************蓝武士*******************************/
        //查看是否有武器能使用
        for (size_t i = 0; i < blueWeaponLib.size(); i++)
            if (blueWeaponLib[i]->getDurability() > 0)
            {
                blueWeaponFlag = true;
                break;
            }
        //有武器能够使用的话进行攻击
        if (blueWeaponFlag)
        {
            while (blueWeaponLib[blueWeaponIndex]->getDurability() == 0)
                blueWeaponIndex = (blueWeaponIndex + 1) % blueWeaponLib.size();
            blueWarrior->attack(redWarrior, blueWeaponLib[blueWeaponIndex]);
            blueWeaponIndex = (blueWeaponIndex + 1) % blueWeaponLib.size();
            redHpFlag = true; //红方确定受到攻击
        }

        /****************************红武士*******************************/
        //查看是否有武器能使用
        for (size_t i = 0; i < redWeaponLib.size(); i++)
            if (redWeaponLib[i]->getDurability() > 0)
            {
                redWeaponFlag = true;
                break;
            }
        //有武器能够使用的话进行攻击
        if (redWeaponFlag)
        {
            while (0 == redWeaponLib[redWeaponIndex]->getDurability())
                redWeaponIndex = (redWeaponIndex + 1) % redWeaponLib.size();
            redWarrior->attack(blueWarrior, redWeaponLib[redWeaponIndex]);
            redWeaponIndex = (redWeaponIndex + 1) % redWeaponLib.size();
            blueHpFlag = true; //蓝方确定受到攻击
        }

        /****************************一轮攻击之后*******************************/
        if (judgeResult(redHpFlag, blueHpFlag))
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0x8(%rdi), %rax
movq %rax, -0x60(%rbp)
movq 0x8(%rdi), %r15
movq 0x18(%rdi), %rax
movq %rax, -0x38(%rbp)
movq %rdi, -0x68(%rbp)
leaq 0x18(%rdi), %rax
movq %rax, -0x58(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r15, -0x50(%rbp)
xorl %eax, %eax
movb %al, -0x2a(%rbp)
movb %al, -0x29(%rbp)
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rcx
movq 0x48(%rax), %rsi
subq %rcx, %rsi
sarq $0x4, %rsi
leaq 0x1(%rsi), %rax
movq %rcx, %rdx
decq %rax
je 0x4724
movq (%rdx), %rdi
addq $0x10, %rdx
cmpq $0x0, 0x38(%rdi)
je 0x466a
jmp 0x4691
incq %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movq %r12, %rbx
shlq $0x4, %rbx
movq (%rcx,%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x4683
movq -0x58(%rbp), %rax
movq (%rax), %r13
leaq -0x98(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x5392
movq -0x38(%rbp), %rax
addq 0x40(%rax), %rbx
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x52c4
movq %r13, %rdi
leaq -0x98(%rbp), %rsi
movq %r15, %rdx
callq 0xbacc
leaq -0xa0(%rbp), %rdi
callq 0x5302
leaq -0x90(%rbp), %rdi
callq 0x5302
incq %r12
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rcx
subq 0x40(%rax), %rcx
sarq $0x4, %rcx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movb $0x1, -0x2a(%rbp)
movq %rdx, %r12
movq -0x50(%rbp), %r15
movq 0x40(%r15), %rcx
movq 0x48(%r15), %rsi
subq %rcx, %rsi
sarq $0x4, %rsi
leaq 0x1(%rsi), %rax
movq %rcx, %rdx
decq %rax
je 0x47e1
movq (%rdx), %rdi
addq $0x10, %rdx
cmpq $0x0, 0x38(%rdi)
je 0x473a
jmp 0x4761
incq %r14
movq %r14, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r14
movq %r14, %rbx
shlq $0x4, %rbx
movq (%rcx,%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x4753
movq -0x60(%rbp), %rax
movq (%rax), %r13
leaq -0x88(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x5392
movq -0x50(%rbp), %r15
addq 0x40(%r15), %rbx
leaq -0x78(%rbp), %rdi
movq %rbx, %rsi
callq 0x52c4
movq %r13, %rdi
leaq -0x88(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0xbacc
leaq -0x70(%rbp), %rdi
callq 0x5302
leaq -0x80(%rbp), %rdi
callq 0x5302
incq %r14
movq 0x48(%r15), %rcx
subq 0x40(%r15), %rcx
sarq $0x4, %rcx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movb $0x1, -0x29(%rbp)
movq %rdx, %r14
movq -0x68(%rbp), %rdi
leaq -0x2a(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x4e16
testb %al, %al
je 0x4648
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4824
movq %rax, %rbx
leaq -0x70(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5302
movq -0x48(%rbp), %rdi
callq 0x5302
movq %rbx, %rdi
callq 0x4250