// File: /workspace/github_cpp_makefile_star2_O1/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 0x353a
cmpl $0x1, 0x48(%rax)
je 0x391d
cmpl $0x0, 0x20(%rbx)
je 0x392c
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 0x4682(%rip), %r13      # 0x7fc8
leaq 0x19fc(%rip), %r12      # 0x5349
leaq 0x1a0c(%rip), %rbp      # 0x5360
movzbl 0xf(%rsp), %eax
addl $-0x61, %eax
cmpl $0x11, %eax
ja 0x396b
movl $0x20089, %ecx          # imm = 0x20089
btl %eax, %ecx
jb 0x391d
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 0x19b5(%rip), %rsi      # 0x5365
callq 0x2180
movl $0xb, %edx
movq %r13, %rdi
leaq 0x19ad(%rip), %rsi      # 0x5371
callq 0x2180
movl $0x9, %edx
movq %r13, %rdi
leaq 0x19a5(%rip), %rsi      # 0x537d
callq 0x2180
movl $0x8, %edx
movq %r13, %rdi
leaq 0x199b(%rip), %rsi      # 0x5387
callq 0x2180
movl $0xc, %edx
movq %r13, %rdi
leaq 0x1990(%rip), %rsi      # 0x5390
callq 0x2180
movq 0x45cc(%rip), %rdi      # 0x7fd8
leaq 0xf(%rsp), %rsi
callq 0x21d0
movzbl 0xf(%rsp), %eax
cmpl $0x67, %eax
jg 0x3a37
cmpl $0x61, %eax
je 0x3a74
cmpl $0x64, %eax
jne 0x3a5e
movq %r14, %rdi
callq 0x2db8
jmp 0x3aba
cmpl $0x68, %eax
je 0x3aad
cmpl $0x72, %eax
jne 0x3a5e
movl $0x2a, %edx
movq %r13, %rdi
leaq 0x194d(%rip), %rsi      # 0x539d
callq 0x2180
movl $0x2, 0x20(%rbx)
jmp 0x3aba
movl $0x1e, %edx
movq %r13, %rdi
leaq 0x195b(%rip), %rsi      # 0x53c8
callq 0x2180
jmp 0x3aba
movq %r14, %rdi
callq 0x2d72
movq %r12, %rbp
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3d46
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x353a
movq %rax, %rdi
movl %r12d, %esi
movq %rbp, %r12
leaq 0x18ba(%rip), %rbp      # 0x5360
callq 0x2d84
jmp 0x3aba
movq %r14, %rdi
movl $0x1e, %esi
callq 0x2da4
cmpl $0x0, 0x20(%rbx)
je 0x3954
jmp 0x391d
nop