// File: /workspace/github_cpp_makefile_star2_O3/gilecheverria[P]UP_Battle_Project/Battle.cpp
// Function: Battle::playerAction(int)
void Battle::playerAction(int index)
{
    char option = 'x';
    int damage;
    int target;
    // Get a pointer to the hero that will act
    // Cast it to the correct Class pointer
    Hero * the_hero = static_cast<Hero*> (hero_party.getMember(index));

    // Dead characters take no actions
    if (the_hero->getStatus() == DEAD)
        return;

    while (state == FIGHTING && option != 'a' && option != 'd' && option != 'h' && option != 'r')
    {
        // Show the menu
        std::cout << "Select an action for '" << the_hero->getName() << "': \n";
        std::cout << "\ta. Attack\n";
        std::cout << "\td. Defend\n";
        std::cout << "\th. Heal\n";
        std::cout << "\tr. Run\n";
        std::cout << "Your coice: ";
        std::cin >> option;

        switch (option)
        {
            case 'a':
                // Get the damage dealt by the hero
                damage = the_hero->performAttack();
                // Select the enemy to attack
                target = selectEnemyTarget();
                // Apply the damate
                enemy_party.getMember(target)->receiveDamage(damage);
                break;
            case 'd':
                the_hero->defend();
                break;
            case 'h':
                the_hero->healDamage(30);
                break;
            case 'r':
                // Quit the battle, conceding defeat
                std::cout << "Your party runs away. You lost the battle\n";
                state = ENEMY_WON;
                break;
            default:
                std::cout << "Invalid option. Try again ...\n";
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movb $0x78, 0xf(%rsp)
callq 0x352e
cmpl $0x1, 0x48(%rax)
je 0x3915
cmpl $0x0, 0x20(%rbx)
je 0x3924
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rax, %r15
addq $0x54, %r15
leaq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x468a(%rip), %r13      # 0x7fc8
leaq 0x1a14(%rip), %r12      # 0x5359
leaq 0x1a24(%rip), %rbp      # 0x5370
movzbl 0xf(%rsp), %eax
addl $-0x61, %eax
cmpl $0x11, %eax
ja 0x3963
movl $0x20089, %ecx          # imm = 0x20089
btl %eax, %ecx
jb 0x3915
movl $0x16, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x2180
movq %r15, %rdi
callq 0x2080
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
movl $0x4, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2180
movl $0xb, %edx
movq %r13, %rdi
leaq 0x19cd(%rip), %rsi      # 0x5375
callq 0x2180
movl $0xb, %edx
movq %r13, %rdi
leaq 0x19c5(%rip), %rsi      # 0x5381
callq 0x2180
movl $0x9, %edx
movq %r13, %rdi
leaq 0x19bd(%rip), %rsi      # 0x538d
callq 0x2180
movl $0x8, %edx
movq %r13, %rdi
leaq 0x19b3(%rip), %rsi      # 0x5397
callq 0x2180
movl $0xc, %edx
movq %r13, %rdi
leaq 0x19a8(%rip), %rsi      # 0x53a0
callq 0x2180
movq 0x45d4(%rip), %rdi      # 0x7fd8
leaq 0xf(%rsp), %rsi
callq 0x21d0
movzbl 0xf(%rsp), %eax
cmpl $0x67, %eax
jg 0x3a2f
cmpl $0x61, %eax
je 0x3a6c
cmpl $0x64, %eax
jne 0x3a56
movq %r14, %rdi
callq 0x2dba
jmp 0x3ab2
cmpl $0x68, %eax
je 0x3aa5
cmpl $0x72, %eax
jne 0x3a56
movl $0x2a, %edx
movq %r13, %rdi
leaq 0x1965(%rip), %rsi      # 0x53ad
callq 0x2180
movl $0x2, 0x20(%rbx)
jmp 0x3ab2
movl $0x1e, %edx
movq %r13, %rdi
leaq 0x1973(%rip), %rsi      # 0x53d8
callq 0x2180
jmp 0x3ab2
movq %r14, %rdi
callq 0x2d74
movq %r12, %rbp
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3d26
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x352e
movq %rax, %rdi
movl %r12d, %esi
movq %rbp, %r12
leaq 0x18d2(%rip), %rbp      # 0x5370
callq 0x2d86
jmp 0x3ab2
movq %r14, %rdi
movl $0x1e, %esi
callq 0x2da6
cmpl $0x0, 0x20(%rbx)
je 0x394c
jmp 0x3915
nop