// File: /workspace/github_cpp_makefile_star2_O1/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 0x4877
sarq $0x4, %rsi
cmpq $0x1, %rsi
movq %rsi, %rax
adcq $0x0, %rax
movq %rcx, %rdx
movq (%rdx), %rdi
cmpq $0x0, 0x38(%rdi)
jne 0x47a7
addq $0x10, %rdx
decq %rax
jne 0x478f
jmp 0x4877
movq %r13, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x47cc
incq %r13
movq %r13, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r13
movq %rdx, %rax
jmp 0x47aa
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdi
movq %rax, -0x70(%rbp)
movq 0x10(%rbx), %rax
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x47fa
movq 0x127dc(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x47f6
incl 0x8(%rax)
jmp 0x47fa
lock
incl 0x8(%rax)
movq 0x40(%r15), %rax
movq %r13, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
movq %rdx, -0x60(%rbp)
movq 0x8(%rax,%rcx), %rax
movq %rax, -0x58(%rbp)
testq %rax, %rax
je 0x4830
movq 0x127a6(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x482c
incl 0x8(%rax)
jmp 0x4830
lock
incl 0x8(%rax)
leaq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0xd0a0
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x484b
callq 0x57ba
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x4859
callq 0x57ba
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 0x4982
sarq $0x4, %rsi
cmpq $0x1, %rsi
movq %rsi, %rax
adcq $0x0, %rax
movq %rcx, %rdx
movq (%rdx), %rdi
cmpq $0x0, 0x38(%rdi)
jne 0x48b2
addq $0x10, %rdx
decq %rax
jne 0x489a
jmp 0x4982
movq %r12, %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x48d7
incq %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movq %rdx, %rax
jmp 0x48b5
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rax
movq %rax, -0x50(%rbp)
movq 0x20(%rbx), %rax
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x4905
movq 0x126d1(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x4901
incl 0x8(%rax)
jmp 0x4905
lock
incl 0x8(%rax)
movq 0x40(%r14), %rax
movq %r12, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
movq %rdx, -0x40(%rbp)
movq 0x8(%rax,%rcx), %rax
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x493b
movq 0x1269b(%rip), %rcx     # 0x16fc8
cmpb $0x0, (%rcx)
je 0x4937
incl 0x8(%rax)
jmp 0x493b
lock
incl 0x8(%rax)
leaq -0x50(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xd0a0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x4956
callq 0x57ba
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x4964
callq 0x57ba
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 0x522a
testb %al, %al
je 0x4764
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 0x49ba
callq 0x57ba
movq -0x48(%rbp), %rdi
jmp 0x49d5
movq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x49d1
callq 0x57ba
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x49df
callq 0x57ba
movq %rbx, %rdi
callq 0x4230
nop