// File: rozpo[P]enemy/data/game/battle/Battle.cpp
// Function: Battle::doBattle(std::shared_ptr<Player>&, std::shared_ptr<Enemy>&, std::vector<std::shared_ptr<Skill>, std::allocator<std::shared_ptr<Skill>>> const&)
void Battle::doBattle(std::shared_ptr<Player> &player,
                      std::shared_ptr<Enemy> &enemy,
                      const std::vector<std::shared_ptr<Skill>> &skills)
{
    if(player->hitpoints > 0)
    {
        int x;
        do
        {
            printBattle(player, enemy);
            printMoves(player, skills);
            std::cin >> x;
            if (x == 1 || x == 2 || x == 3 || x == 4)
            {
                if(player->uses[x-1] !=0)
                {
                    calculateDamage(player, enemy, x - 1, skills);
                    player->uses[x-1]--;
                }
                else
                    std::cout << player->name << " is exhausted\n";

                x = (std::rand () % 3)+1;

                if(enemy->uses[x-1] != 0)
                {
                    calculateDamage(enemy, player, x - 1, skills);
                    enemy->uses[x-1]--;
                }
                else
                    std::cout << enemy->name << " is exhausted\n";
            }
        } while(player->hitpoints > 0 && enemy->hitpoints > 0);
        endBattle (player,enemy);
    }
    else
        std::cout << player->name << " cant fight!\n";

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
cmpl $0x0, 0x8(%rax)
jle 0xaaa2
jmp 0xa8e9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xaae0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xac70
movq 0x246d6(%rip), %rdi     # 0x2efe0
leaq -0x1c(%rbp), %rsi
callq 0x40e0
cmpl $0x1, -0x1c(%rbp)
je 0xa92f
cmpl $0x2, -0x1c(%rbp)
je 0xa92f
cmpl $0x3, -0x1c(%rbp)
je 0xa92f
cmpl $0x4, -0x1c(%rbp)
jne 0xaa5c
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rdi
addq $0x2c, %rdi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xafa0
cmpl $0x0, (%rax)
je 0xa990
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %edx
subl $0x1, %edx
movq -0x18(%rbp), %rcx
callq 0xafd0
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rdi
addq $0x2c, %rdi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xafa0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
jmp 0xa9bb
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rsi
addq $0x40, %rsi
movq 0x24629(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x12ad7(%rip), %rsi     # 0x1d48d
callq 0x41b0
callq 0x4050
movl $0x3, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0xaf80
movq %rax, %rdi
addq $0x2c, %rdi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xafa0
cmpl $0x0, (%rax)
je 0xaa2f
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %edx
subl $0x1, %edx
movq -0x18(%rbp), %rcx
callq 0xb410
movq -0x10(%rbp), %rdi
callq 0xaf80
movq %rax, %rdi
addq $0x2c, %rdi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xafa0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
jmp 0xaa5a
movq -0x10(%rbp), %rdi
callq 0xaf80
movq %rax, %rsi
addq $0x40, %rsi
movq 0x2458a(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x12a38(%rip), %rsi     # 0x1d48d
callq 0x41b0
jmp 0xaa5c
jmp 0xaa5e
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x0, 0x8(%rcx)
movb %al, -0x1d(%rbp)
jle 0xaa88
movq -0x10(%rbp), %rdi
callq 0xaf80
cmpl $0x0, 0x8(%rax)
setg %al
movb %al, -0x1d(%rbp)
movb -0x1d(%rbp), %al
testb $0x1, %al
jne 0xa8e9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xa750
jmp 0xaacd
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rsi
addq $0x40, %rsi
movq 0x24517(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x129d4(%rip), %rsi     # 0x1d49c
callq 0x41b0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)