// File: Agusyc[P]CTRPG/src/battle.cpp
// Function: Battle::loop()
void Battle::loop() {
    // Run this loop until the user loses or wins
    while (!over) {
        if (playerTurn) {
            // Checks the user response from the menu
            switch(showMenu()) {
            case 1:
                if (attack() == 1) {
                    continue;
                }
                break;
            case 2:
                defending = true;
                printMessage(string("You use your ") + YELLOW + string("shield ") + WHITE + string("to, like, defend yourself."));
                break;
            case 3:
                if (useItem() == 1) {
                    continue;
                }
                break;
            case 4:
                int chance;
                // If player has more than 50 % of his health
                if (player.hp >= (parsePlayer().hp / 2)) {
                    chance = 75; // 75% chance of fleeing
                } else {
                    chance = 32; // 32% chance of fleeing
                }
                // See if the player flees or not
                if (rand() % 100 < chance) {
                    printMessage("You escape... You chicken!");
                    over = true;
                    writeItems();
                    continue;
                } else {
                    printMessage("You tried to escape... But you couldn't!");
                }
                break;
            default:
                printMessage("That is not a valid option...");
                continue;
            }
        } else {
            // The enemy attacks
            attack();
        }
        // Pass to the next turn
        playerTurn = !playerTurn;
    }

    clearScreen();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
movb 0xd8(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3c02
jmp 0x43d4
movq -0x2a8(%rbp), %rax
testb $0x1, 0xd9(%rax)
je 0x43aa
movq -0x2a8(%rbp), %rdi
callq 0x4400
decl %eax
movl %eax, %ecx
movq %rcx, -0x2b0(%rbp)
subl $0x3, %eax
ja 0x4284
movq -0x2b0(%rbp), %rax
leaq 0xd3c0(%rip), %rcx      # 0x11004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x2a8(%rbp), %rdi
callq 0x4560
cmpl $0x1, %eax
jne 0x3c60
jmp 0x3bea
jmp 0x43a8
movq -0x2a8(%rbp), %rax
movb $0x1, 0xda(%rax)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3540
movq -0x2b8(%rbp), %rdx
leaq 0xd3bf(%rip), %rsi      # 0x11053
leaq -0xa8(%rbp), %rdi
callq 0x33a0
jmp 0x3ca2
leaq 0xd387(%rip), %rdx      # 0x11030
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8280
jmp 0x3cbe
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x3540
movq -0x2c0(%rbp), %rdx
leaq 0xd382(%rip), %rsi      # 0x11061
leaq -0xe0(%rbp), %rdi
callq 0x33a0
jmp 0x3ced
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x81b0
jmp 0x3d06
leaq 0xd32f(%rip), %rdx      # 0x1103c
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x8280
jmp 0x3d1c
leaq -0x109(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x3540
movq -0x2c8(%rbp), %rdx
leaq 0xd32c(%rip), %rsi      # 0x11069
leaq -0x108(%rbp), %rdi
callq 0x33a0
jmp 0x3d4b
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0x81b0
jmp 0x3d61
leaq -0x131(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x3540
movq -0x2d0(%rbp), %rdx
leaq 0xd2ba(%rip), %rsi      # 0x1103c
leaq -0x130(%rbp), %rdi
callq 0x33a0
jmp 0x3d90
leaq -0x28(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0x10e00
jmp 0x3db2
leaq -0x130(%rbp), %rdi
callq 0x31b0
leaq -0x131(%rbp), %rdi
callq 0x32d0
leaq -0x28(%rbp), %rdi
callq 0x31b0
leaq -0x108(%rbp), %rdi
callq 0x31b0
leaq -0x109(%rbp), %rdi
callq 0x32d0
leaq -0x48(%rbp), %rdi
callq 0x31b0
leaq -0x68(%rbp), %rdi
callq 0x31b0
leaq -0xe0(%rbp), %rdi
callq 0x31b0
leaq -0xe1(%rbp), %rdi
callq 0x32d0
leaq -0x88(%rbp), %rdi
callq 0x31b0
leaq -0xa8(%rbp), %rdi
callq 0x31b0
leaq -0xa9(%rbp), %rdi
callq 0x32d0
jmp 0x43a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x3f0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x31b0
leaq -0x131(%rbp), %rdi
callq 0x32d0
leaq -0x28(%rbp), %rdi
callq 0x31b0
leaq -0x108(%rbp), %rdi
callq 0x31b0
leaq -0x109(%rbp), %rdi
callq 0x32d0
leaq -0x48(%rbp), %rdi
callq 0x31b0
leaq -0x68(%rbp), %rdi
callq 0x31b0
leaq -0xe0(%rbp), %rdi
callq 0x31b0
leaq -0xe1(%rbp), %rdi
callq 0x32d0
leaq -0x88(%rbp), %rdi
callq 0x31b0
leaq -0xa8(%rbp), %rdi
callq 0x31b0
leaq -0xa9(%rbp), %rdi
callq 0x32d0
jmp 0x43e7
movq -0x2a8(%rbp), %rdi
callq 0x66e0
cmpl $0x1, %eax
jne 0x3fa1
jmp 0x3bea
jmp 0x43a8
movq -0x2a8(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x2d4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xe1d0
movl -0x17c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2d8(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8170
movl -0x2d8(%rbp), %ecx
movl -0x2d4(%rbp), %eax
cmpl %ecx, %eax
jl 0x3ffe
movl $0x4b, -0x138(%rbp)
jmp 0x4008
movl $0x20, -0x138(%rbp)
callq 0x30c0
movl $0x64, %ecx
cltd
idivl %ecx
cmpl -0x138(%rbp), %edx
jge 0x415b
leaq -0x1d1(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x3540
movq -0x2e0(%rbp), %rdx
leaq 0xd042(%rip), %rsi      # 0x11084
leaq -0x1d0(%rbp), %rdi
callq 0x33a0
jmp 0x4050
leaq -0x1f9(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x3540
movq -0x2e8(%rbp), %rdx
leaq 0xcfcb(%rip), %rsi      # 0x1103c
leaq -0x1f8(%rbp), %rdi
callq 0x33a0
jmp 0x407f
leaq -0x1d0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0x10e00
jmp 0x40a4
leaq -0x1f8(%rbp), %rdi
callq 0x31b0
leaq -0x1f9(%rbp), %rdi
callq 0x32d0
leaq -0x1d0(%rbp), %rdi
callq 0x31b0
leaq -0x1d1(%rbp), %rdi
callq 0x32d0
movq -0x2a8(%rbp), %rdi
movb $0x1, 0xd8(%rdi)
callq 0x6f40
jmp 0x3bea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x414a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4132
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x31b0
leaq -0x1f9(%rbp), %rdi
callq 0x32d0
leaq -0x1d0(%rbp), %rdi
callq 0x31b0
leaq -0x1d1(%rbp), %rdi
callq 0x32d0
jmp 0x43e7
leaq -0x221(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x3540
movq -0x2f0(%rbp), %rdx
leaq 0xcf23(%rip), %rsi      # 0x1109f
leaq -0x220(%rbp), %rdi
callq 0x33a0
jmp 0x418a
leaq -0x249(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x3540
movq -0x2f8(%rbp), %rdx
leaq 0xce91(%rip), %rsi      # 0x1103c
leaq -0x248(%rbp), %rdi
callq 0x33a0
jmp 0x41b9
leaq -0x220(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0x10e00
jmp 0x41de
leaq -0x248(%rbp), %rdi
callq 0x31b0
leaq -0x249(%rbp), %rdi
callq 0x32d0
leaq -0x220(%rbp), %rdi
callq 0x31b0
leaq -0x221(%rbp), %rdi
callq 0x32d0
jmp 0x427f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x426e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4256
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x31b0
leaq -0x249(%rbp), %rdi
callq 0x32d0
leaq -0x220(%rbp), %rdi
callq 0x31b0
leaq -0x221(%rbp), %rdi
callq 0x32d0
jmp 0x43e7
jmp 0x43a8
leaq -0x271(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x3540
movq -0x300(%rbp), %rdx
leaq 0xce23(%rip), %rsi      # 0x110c8
leaq -0x270(%rbp), %rdi
callq 0x33a0
jmp 0x42b3
leaq -0x299(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x3540
movq -0x308(%rbp), %rdx
leaq 0xcd68(%rip), %rsi      # 0x1103c
leaq -0x298(%rbp), %rdi
callq 0x33a0
jmp 0x42e2
leaq -0x270(%rbp), %rdi
leaq -0x298(%rbp), %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0x10e00
jmp 0x4307
leaq -0x298(%rbp), %rdi
callq 0x31b0
leaq -0x299(%rbp), %rdi
callq 0x32d0
leaq -0x270(%rbp), %rdi
callq 0x31b0
leaq -0x271(%rbp), %rdi
callq 0x32d0
jmp 0x3bea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x439a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4382
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x31b0
leaq -0x299(%rbp), %rdi
callq 0x32d0
leaq -0x270(%rbp), %rdi
callq 0x31b0
leaq -0x271(%rbp), %rdi
callq 0x32d0
jmp 0x43e7
jmp 0x43b6
movq -0x2a8(%rbp), %rdi
callq 0x4560
movq -0x2a8(%rbp), %rax
movb 0xd9(%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
movb %cl, 0xd9(%rax)
jmp 0x3bea
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x10ee0
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x3530
nopw %cs:(%rax,%rax)