// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq 0x18(%rdi), %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %eax, %eax
movb %al, -0x2a(%rbp)
movb %al, -0x29(%rbp)
movq 0x40(%r15), %rcx
movq 0x48(%r15), %rsi
subq %rcx, %rsi
je 0x4859
sarq $0x4, %rsi
cmpq $0x1, %rsi
movq %rsi, %rax
adcq $0x0, %rax
movq %rcx, %rdx
movq (%rdx), %rdi
cmpq $0x0, 0x38(%rdi)
jne 0x4789
addq $0x10, %rdx
decq %rax
jne 0x4771
jmp 0x4859
movq %r13, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x47ae
incq %r13
movq %r13, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r13
movq %rdx, %rax
jmp 0x478c
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdi
movq %rax, -0x70(%rbp)
movq 0x10(%rbx), %rax
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x47e0
movq 0x127fa(%rip), %rdx     # 0x16fc8
cmpb $0x0, (%rdx)
je 0x47d8
incl 0x8(%rax)
jmp 0x47e0
lock
incl 0x8(%rax)
movq 0x40(%r15), %rcx
movq %r13, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rdx
movq %rdx, -0x60(%rbp)
movq 0x8(%rcx,%rax), %rax
movq %rax, -0x58(%rbp)
testq %rax, %rax
je 0x4812
movq 0x127c4(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x480e
incl 0x8(%rax)
jmp 0x4812
lock
incl 0x8(%rax)
leaq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0xd018
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x482d
callq 0x57a8
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x483b
callq 0x57a8
incq %r13
movq 0x48(%r15), %rcx
subq 0x40(%r15), %rcx
sarq $0x4, %rcx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movb $0x1, -0x2a(%rbp)
movq %rdx, %r13
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rsi
subq %rcx, %rsi
je 0x4964
sarq $0x4, %rsi
cmpq $0x1, %rsi
movq %rsi, %rax
adcq $0x0, %rax
movq %rcx, %rdx
movq (%rdx), %rdi
cmpq $0x0, 0x38(%rdi)
jne 0x4894
addq $0x10, %rdx
decq %rax
jne 0x487c
jmp 0x4964
movq %r12, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x48b9
incq %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movq %rdx, %rax
jmp 0x4897
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rax
movq %rax, -0x50(%rbp)
movq 0x20(%rbx), %rax
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x48eb
movq 0x126ef(%rip), %rdx     # 0x16fc8
cmpb $0x0, (%rdx)
je 0x48e3
incl 0x8(%rax)
jmp 0x48eb
lock
incl 0x8(%rax)
movq 0x40(%r14), %rcx
movq %r12, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rdx
movq %rdx, -0x40(%rbp)
movq 0x8(%rcx,%rax), %rax
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x491d
movq 0x126b9(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x4919
incl 0x8(%rax)
jmp 0x491d
lock
incl 0x8(%rax)
leaq -0x50(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xd018
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x4938
callq 0x57a8
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x4946
callq 0x57a8
incq %r12
movq 0x48(%r14), %rcx
subq 0x40(%r14), %rcx
sarq $0x4, %rcx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movb $0x1, -0x29(%rbp)
movq %rdx, %r12
movq %rbx, %rdi
leaq -0x2a(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x522c
testb %al, %al
je 0x4746
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x499c
callq 0x57a8
movq -0x48(%rbp), %rdi
jmp 0x49b7
movq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x49b3
callq 0x57a8
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x49c1
callq 0x57a8
movq %rbx, %rdi
callq 0x4230
nop