// File: /workspace/github_cpp_makefile_star2_O1/Worthy-Wang[P]Warcraft3-StartWar/City.cpp
// Function: warcraft::City::win(std::shared_ptr<warcraft::Warrior>, std::shared_ptr<warcraft::Warrior>)
void City::win(WarriorPtr winner, WarriorPtr loser)
{
    cout << toString(winner->getColor()) << " " << winner->getName() << " " << winner->getId() <<" kills " << toString(loser->getColor()) << " " << loser->getName() << " " << loser->getId() << "in city " << loser->getCityId() << endl;

    //开始缴获敌人的武器, 当敌人没有武器的时候或者武器数量超过最大携带武器数时停止
    //首先胜者清理自己的武器
    vector<WeaponPtr>& winnerWeapons = winner->getWeapons();
    auto it = std::remove_if(winnerWeapons.begin(), winnerWeapons.end(), [](WeaponPtr& weapon){ return (weapon->getDurability()==0);  });
    winnerWeapons.erase(it, winnerWeapons.end());

    //缴获败者武器
    vector<WeaponPtr>& loserWeapons = loser->getWeapons();
    std::sort(loserWeapons.begin(), loserWeapons.end(), compAfterFight);
    for (auto &e :loserWeapons)
    {
        if (winnerWeapons.size() > MAX_WEAPON_SIZE)
            break;
        if (e->getDurability() > 0)
            winner->getNewWeapon(e);
    }

    //将败者的尸体扔出
    loser->getColor()==RED? (redWarrior.reset()):(blueWarrior.reset());

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, -0x30(%rbp)
movq %rdi, %r13
movq %rsi, -0x38(%rbp)
movq (%rsi), %rax
movl 0x8(%rax), %eax
leaq -0x48(%rbp), %rcx
movq %rcx, -0x10(%rcx)
cmpl $0x1, %eax
je 0x4cdb
testl %eax, %eax
jne 0x4cf0
movb $0x64, 0x2(%rcx)
movw $0x6572, (%rcx)         # imm = 0x6572
movq $0x3, -0x50(%rbp)
movb $0x0, -0x45(%rbp)
jmp 0x4cfc
movl $0x65756c62, -0x48(%rbp) # imm = 0x65756C62
movq $0x4, -0x50(%rbp)
movb $0x0, -0x44(%rbp)
jmp 0x4cfc
movq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x122c5(%rip), %rdi     # 0x16fd0
callq 0x4190
movq %rax, %r12
leaq 0xbd91(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x38(%rbp), %rax
movq (%rax), %rax
leaq -0xc0(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x5720
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq %r12, %rdi
callq 0x4190
movq %rax, %r12
leaq 0xbd3b(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rsi
movq %r12, %rdi
callq 0x40e0
movq %rax, %r12
leaq 0xb286(%rip), %rsi      # 0x10020
movl $0x7, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
leaq -0x68(%rbp), %r14
movq %r14, -0x10(%r14)
cmpl $0x1, %eax
je 0x4ddb
testl %eax, %eax
jne 0x4df0
movb $0x64, 0x2(%r14)
movw $0x6572, (%r14)         # imm = 0x6572
movq $0x3, -0x70(%rbp)
movb $0x0, -0x65(%rbp)
jmp 0x4dfc
movl $0x65756c62, -0x68(%rbp) # imm = 0x65756C62
movq $0x4, -0x70(%rbp)
movb $0x0, -0x64(%rbp)
jmp 0x4dfc
movq $0x0, -0x70(%rbp)
movb $0x0, -0x68(%rbp)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x4190
movq %rax, %r12
leaq 0xbc95(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
leaq -0xa0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x5720
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %r12, %rdi
callq 0x4190
movq %rax, %r12
leaq 0xbc3f(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rsi
movq %r12, %rdi
callq 0x40e0
movq %rax, %r12
leaq 0xb1f0(%rip), %rsi      # 0x10086
movl $0x8, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x58(%rax), %rsi
movq %r12, %rdi
callq 0x40e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4150
movsbl %al, %esi
movq %r12, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x40f0
movq -0xb0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4efb
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x4f10
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4f2b
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4f44
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x38(%rbp), %rax
movq (%rax), %r14
movq 0x40(%r14), %rax
movq 0x48(%r14), %rbx
movq %rbx, %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x6, %rdx
testq %rdx, %rdx
jle 0x4fb5
andq $-0x40, %rcx
addq %rax, %rcx
incq %rdx
addq $0x20, %rax
movq %rax, %r12
movq -0x20(%r12), %rax
cmpq $0x0, 0x38(%rax)
je 0x5001
movq -0x10(%r12), %rax
cmpq $0x0, 0x38(%rax)
je 0x5007
movq (%r12), %rax
cmpq $0x0, 0x38(%rax)
je 0x5011
movq 0x10(%r12), %rax
cmpq $0x0, 0x38(%rax)
je 0x500d
decq %rdx
addq $0x40, %r12
cmpq $0x1, %rdx
jg 0x4f76
movq %rcx, %rax
movq %rbx, %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq $0x1, %rcx
je 0x4ff0
cmpq $0x2, %rcx
je 0x4fe2
movq %rbx, %r12
cmpq $0x3, %rcx
jne 0x5011
movq (%rax), %rcx
cmpq $0x0, 0x38(%rcx)
je 0x4ffc
addq $0x10, %rax
movq (%rax), %rcx
cmpq $0x0, 0x38(%rcx)
je 0x4ffc
addq $0x10, %rax
movq (%rax), %rcx
cmpq $0x0, 0x38(%rcx)
cmovneq %rbx, %rax
movq %rax, %r12
jmp 0x5011
addq $-0x20, %r12
jmp 0x5011
addq $-0x10, %r12
jmp 0x5011
addq $0x10, %r12
movq %r13, -0x80(%rbp)
leaq 0x40(%r14), %r13
cmpq %rbx, %r12
sete %al
leaq 0x10(%r12), %r15
cmpq %rbx, %r15
sete %cl
orb %al, %cl
jne 0x5068
movq (%r15), %rax
cmpq $0x0, 0x38(%rax)
je 0x505f
movq 0x8(%r15), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq %rax, (%r12)
movq 0x8(%r12), %rdi
movq %rcx, 0x8(%r12)
testq %rdi, %rdi
je 0x505b
callq 0x57ba
addq $0x10, %r12
addq $0x10, %r15
cmpq %rbx, %r15
jne 0x502e
movq 0x48(%r14), %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x5826
movq -0x30(%rbp), %rax
movq (%rax), %r15
movq 0x40(%r15), %r12
movq 0x48(%r15), %r13
cmpq %r13, %r12
je 0x50c5
movq %r13, %rax
subq %r12, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xa9f(%rip), %rbx      # 0x460a
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rcx
callq 0x58f5
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x59c8
movq 0x40(%r15), %rbx
movq 0x48(%r15), %r13
cmpq %r13, %rbx
je 0x5149
leaq -0x90(%rbp), %r12
movq 0x11ee8(%rip), %r15     # 0x16fc8
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
cmpq $0xaf, %rax
ja 0x5149
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x5140
movq -0x38(%rbp), %rcx
movq (%rcx), %rdi
movq %rax, -0x90(%rbp)
movq 0x8(%rbx), %rax
movq %rax, -0x88(%rbp)
testq %rax, %rax
je 0x5127
cmpb $0x0, (%r15)
je 0x5123
incl 0x8(%rax)
jmp 0x5127
lock
incl 0x8(%rax)
movq %r12, %rsi
callq 0xd0de
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x5140
callq 0x57ba
addq $0x10, %rbx
cmpq %r13, %rbx
jne 0x50e0
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0x5167
xorps %xmm0, %xmm0
movq -0x80(%rbp), %rax
movq 0x20(%rax), %rdi
movups %xmm0, 0x18(%rax)
jmp 0x5176
xorps %xmm0, %xmm0
movq -0x80(%rbp), %rax
movq 0x10(%rax), %rdi
movups %xmm0, 0x8(%rax)
testq %rdi, %rdi
je 0x5180
callq 0x57ba
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5196
jmp 0x519b
movq %rax, %r12
jmp 0x51d9
movq %rax, %r12
jmp 0x5209
movq %rax, %r12
jmp 0x51ee
movq %rax, %r12
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x5222
callq 0x57ba
jmp 0x5222
movq %rax, %r12
movq -0xb0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x51d9
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x51ee
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x5209
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5222
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x4170
movq %r12, %rdi
callq 0x4230