// File: 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
subq $0x200, %rsp            # imm = 0x200
movq %rsi, -0x168(%rbp)
movq %rdi, %rax
movq -0x168(%rbp), %rdi
movq %rdi, -0x160(%rbp)
movq %rdx, -0x158(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
callq 0x5db0
movq %rax, %rdi
callq 0x61d0
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x60f0
movq -0x148(%rbp), %rsi
movq 0x27dd2(%rip), %rdi     # 0x2cfd0
callq 0x4170
movq %rax, -0x140(%rbp)
jmp 0x520c
movq -0x140(%rbp), %rdi
leaq 0x19861(%rip), %rsi     # 0x1ea7b
callq 0x4180
movq %rax, -0x170(%rbp)
jmp 0x5228
movq -0x160(%rbp), %rdi
callq 0x5db0
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x61f0
jmp 0x5242
movq -0x170(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4170
movq %rax, -0x178(%rbp)
jmp 0x525b
movq -0x178(%rbp), %rdi
leaq 0x19812(%rip), %rsi     # 0x1ea7b
callq 0x4180
movq %rax, -0x180(%rbp)
jmp 0x5277
movq -0x160(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x6220
movq %rax, -0x188(%rbp)
jmp 0x5294
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdi
callq 0x4060
movq %rax, -0x190(%rbp)
jmp 0x52b0
movq -0x190(%rbp), %rdi
leaq 0x18d56(%rip), %rsi     # 0x1e014
callq 0x4180
movq %rax, -0x198(%rbp)
jmp 0x52cc
movq -0x158(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x61d0
movl %eax, -0x19c(%rbp)
jmp 0x52e8
movl -0x19c(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x60f0
jmp 0x52fc
movq -0x198(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4170
movq %rax, -0x1a8(%rbp)
jmp 0x5318
movq -0x1a8(%rbp), %rdi
leaq 0x19755(%rip), %rsi     # 0x1ea7b
callq 0x4180
movq %rax, -0x1b0(%rbp)
jmp 0x5334
movq -0x158(%rbp), %rdi
callq 0x5db0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x61f0
jmp 0x5351
movq -0x1b0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4170
movq %rax, -0x1b8(%rbp)
jmp 0x536d
movq -0x1b8(%rbp), %rdi
leaq 0x19700(%rip), %rsi     # 0x1ea7b
callq 0x4180
movq %rax, -0x1c0(%rbp)
jmp 0x5389
movq -0x158(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x6220
movq %rax, -0x1c8(%rbp)
jmp 0x53a6
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdi
callq 0x4060
movq %rax, -0x1d0(%rbp)
jmp 0x53c2
movq -0x1d0(%rbp), %rdi
leaq 0x18caf(%rip), %rsi     # 0x1e07f
callq 0x4180
movq %rax, -0x1d8(%rbp)
jmp 0x53de
movq -0x158(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x6240
movq %rax, -0x1e0(%rbp)
jmp 0x53fb
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdi
callq 0x4060
movq %rax, -0x1e8(%rbp)
jmp 0x5417
movq -0x1e8(%rbp), %rdi
movq 0x27b93(%rip), %rsi     # 0x2cfb8
callq 0x41c0
jmp 0x542c
leaq -0xa8(%rbp), %rdi
callq 0x40f0
leaq -0x88(%rbp), %rdi
callq 0x40f0
leaq -0x68(%rbp), %rdi
callq 0x40f0
leaq -0x38(%rbp), %rdi
callq 0x40f0
movq -0x160(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x5dd0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x5e80
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x5eb0
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x5740
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x62f0
movq -0xb0(%rbp), %rdi
callq 0x5eb0
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x62f0
movq -0x1f0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x6260
movq -0x158(%rbp), %rdi
movq %rax, -0xf0(%rbp)
callq 0x5db0
movq %rax, %rdi
callq 0x5dd0
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x5e80
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x5eb0
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rsi
leaq -0xdcf(%rip), %rdx      # 0x47a0
callq 0x5e30
movq -0xf8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
callq 0x5e80
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
callq 0x5eb0
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x6330
testb $0x1, %al
jne 0x55c4
jmp 0x56ea
leaq -0x118(%rbp), %rdi
callq 0x6370
movq %rax, -0x128(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x5ee0
cmpq $0xa, %rax
jbe 0x5653
jmp 0x56ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5645
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x563c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x40f0
leaq -0x88(%rbp), %rdi
callq 0x40f0
leaq -0x68(%rbp), %rdi
callq 0x40f0
leaq -0x38(%rbp), %rdi
callq 0x40f0
jmp 0x572e
movq -0x128(%rbp), %rdi
callq 0x5d30
movq %rax, %rdi
callq 0x5d70
cmpq $0x0, %rax
jbe 0x56d7
movq -0x160(%rbp), %rdi
callq 0x5db0
movq %rax, -0x200(%rbp)
movq -0x128(%rbp), %rsi
leaq -0x138(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x6390
movq -0x200(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x193d0
jmp 0x56af
leaq -0x138(%rbp), %rdi
callq 0x63c0
jmp 0x56d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x63c0
jmp 0x572e
jmp 0x56d9
leaq -0x118(%rbp), %rdi
callq 0x63e0
jmp 0x55a8
movq -0x158(%rbp), %rdi
callq 0x5db0
movq %rax, %rdi
callq 0x61d0
cmpl $0x0, %eax
jne 0x5715
movq -0x150(%rbp), %rdi
addq $0x8, %rdi
callq 0x6400
jmp 0x5725
movq -0x150(%rbp), %rdi
addq $0x18, %rdi
callq 0x6400
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4300
nopw (%rax,%rax)