// File: Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone2(std::vector<unsigned char, std::allocator<unsigned char>>&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone2(std::vector<BYTE>& generalIds, RNG& rng)
{
    // There are no special considerations in this zone.  We may want to reconsider because
    // Luo Yang can change for the final battle, but for now, we'll leave it intact.

    vector<int> battlesToFill = {0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movups 0x181203(%rip), %xmm0   # 0x59b9dc
movaps %xmm0, -0x50(%rbp)
movups 0x1811e8(%rip), %xmm0   # 0x59b9cc
movaps %xmm0, -0x60(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x8, -0x38(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x416e40
movq -0xd8(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x41be20
jmp 0x41a822
leaq -0x61(%rbp), %rdi
callq 0x4107c0
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x405780
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0x405610
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x40ffd0
testb $0x1, %al
jne 0x41a86f
jmp 0x41a984
leaq -0x88(%rbp), %rdi
callq 0x410010
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4172d0
movq -0xf0(%rbp), %rdi
movl %eax, %edx
decl %edx
xorl %esi, %esi
callq 0x41dba0
movl %eax, -0xe4(%rbp)
jmp 0x41a8b0
movl -0xe4(%rbp), %eax
movl %eax, -0x9c(%rbp)
movslq -0x9c(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x41bea0
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0xe0(%rbp), %rdi
movq -0x98(%rbp), %rax
movb (%rax), %al
movl -0xa0(%rbp), %edx
movzbl %al, %esi
callq 0x4181b0
xorb $-0x1, %al
testb $0x1, %al
jne 0x41a8fa
jmp 0x41a971
movl -0x9c(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0xf8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4172d0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x9c(%rbp)
movslq -0x9c(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x41bea0
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
jmp 0x41a8d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x4107c0
jmp 0x41aa2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x41aa24
jmp 0x41a973
leaq -0x88(%rbp), %rdi
callq 0x410030
jmp 0x41a853
movq -0x10(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x4101c0
jmp 0x41a996
leaq -0xd0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x41bf30
jmp 0x41a9a8
movq -0xe0(%rbp), %rdi
movq -0x18(%rbp), %rcx
leaq -0xb8(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x418290
jmp 0x41a9c8
leaq -0xd0(%rbp), %rdi
callq 0x410580
leaq -0xb8(%rbp), %rdi
callq 0x404f50
leaq -0x30(%rbp), %rdi
callq 0x410580
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x41aa18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x410580
leaq -0xb8(%rbp), %rdi
callq 0x404f50
leaq -0x30(%rbp), %rdi
callq 0x410580
movq -0x70(%rbp), %rdi
callq 0x4c9ba0
nopw %cs:(%rax,%rax)