// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rdi, %r14
movq %rsi, -0x30(%rbp)
movq (%rsi), %rax
movl 0x8(%rax), %esi
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
callq 0x503f
movq 0x11504(%rip), %rdi     # 0x15fd0
movq %rbx, %rsi
callq 0x4150
leaq 0x9f88(%rip), %rsi      # 0xea63
movq %rax, %rdi
callq 0x4160
movq %rax, %rbx
movq -0x30(%rbp), %rax
movq (%rax), %rsi
addq $0x10, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x41d0
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x4150
leaq 0x9f50(%rip), %rsi      # 0xea63
movq %rax, %rdi
callq 0x4160
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %rsi
movq %rax, %rdi
callq 0x40f0
leaq 0x94eb(%rip), %rsi      # 0xe020
movq %rax, %rdi
callq 0x4160
movq %rax, %rbx
movq (%r15), %rax
movl 0x8(%rax), %esi
leaq -0x90(%rbp), %rdi
callq 0x503f
leaq -0x90(%rbp), %rsi
movq %rbx, %rdi
callq 0x4150
leaq 0x9efb(%rip), %rsi      # 0xea63
movq %rax, %rdi
callq 0x4160
movq %rax, %rbx
movq (%r15), %rsi
addq $0x10, %rsi
leaq -0x70(%rbp), %rdi
callq 0x41d0
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x4150
leaq 0x9ecd(%rip), %rsi      # 0xea63
movq %rax, %rdi
callq 0x4160
movq (%r15), %rcx
movq 0x30(%rcx), %rsi
movq %rax, %rdi
callq 0x40f0
leaq 0x94d7(%rip), %rsi      # 0xe08b
movq %rax, %rdi
callq 0x4160
movq (%r15), %rcx
movq 0x58(%rcx), %rsi
movq %rax, %rdi
callq 0x40f0
movq %rax, %rdi
callq 0x40b0
movq %r15, -0x38(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x40a0
leaq -0x90(%rbp), %rdi
callq 0x40a0
leaq -0xb0(%rbp), %rdi
callq 0x40a0
leaq -0xd0(%rbp), %rdi
callq 0x40a0
movq -0x30(%rbp), %rax
movq (%rax), %r15
leaq 0x40(%r15), %rdi
movq 0x40(%r15), %rbx
movq 0x48(%r15), %r13
movq %r13, %rax
subq %rbx, %rax
movq %rax, %rcx
sarq $0x6, %rcx
movq %r14, -0x40(%rbp)
testq %rcx, %rcx
jle 0x4c69
movq (%rbx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x4cbd
movq 0x10(%rbx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x4cad
movq 0x20(%rbx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x4cb3
movq 0x30(%rbx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x4cb9
addq $0x40, %rbx
decq %rcx
addq $-0x40, %rax
jmp 0x4c28
sarq $0x4, %rax
cmpq $0x1, %rax
je 0x4c9f
cmpq $0x2, %rax
je 0x4c91
cmpq $0x3, %rax
jne 0x4db3
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x4cbd
addq $0x10, %rbx
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x4cbd
addq $0x10, %rbx
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
cmovneq %r13, %rbx
jmp 0x4cbd
addq $0x10, %rbx
jmp 0x4cbd
addq $0x20, %rbx
jmp 0x4cbd
addq $0x30, %rbx
cmpq %r13, %rbx
je 0x4cfd
movq %rbx, %r12
addq $0x10, %rbx
cmpq %r13, %rbx
je 0x4cf7
movq (%rbx), %rax
addq $0x10, %rbx
cmpq $0x0, 0x38(%rax)
je 0x4cc9
addq $-0x10, %rbx
movq %rdi, %r14
movq %r12, %rdi
movq %rbx, %rsi
callq 0x547c
movq %r14, %rdi
addq $0x10, %r12
jmp 0x4cc5
movq 0x48(%r15), %r13
jmp 0x4d00
movq %rbx, %r12
movq %r12, %rsi
movq %r13, %rdx
callq 0x508e
movq -0x38(%rbp), %rax
movq (%rax), %r14
movq 0x40(%r14), %rdi
movq 0x48(%r14), %rsi
leaq -0x7f7(%rip), %rdx      # 0x452a
callq 0x54dc
movq 0x40(%r14), %rbx
movq 0x48(%r14), %r12
leaq -0x50(%rbp), %r13
cmpq %r12, %rbx
je 0x4d7d
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
cmpq $0xaf, %rax
ja 0x4d7d
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x4d77
movq -0x30(%rbp), %rax
movq (%rax), %r14
movq %r13, %rdi
movq %rbx, %rsi
callq 0x52c4
movq %r14, %rdi
movq %r13, %rsi
callq 0xbb0a
leaq -0x48(%rbp), %rdi
callq 0x5302
addq $0x10, %rbx
jmp 0x4d32
movq -0x38(%rbp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x8(%rax)
setne %cl
shll $0x4, %ecx
movq -0x40(%rbp), %rax
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
callq 0x5098
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r12
jmp 0x4d00
jmp 0x4dc1
jmp 0x4dcb
jmp 0x4dc6
movq %rax, %rbx
jmp 0x4ddc
movq %rax, %rbx
jmp 0x4df4
movq %rax, %rbx
jmp 0x4de8
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x40a0
leaq -0x90(%rbp), %rdi
callq 0x40a0
leaq -0xb0(%rbp), %rdi
callq 0x40a0
leaq -0xd0(%rbp), %rdi
callq 0x40a0
jmp 0x4e0e
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x5302
movq %rbx, %rdi
callq 0x4250