// File: /workspace/github_cpp_makefile_star2_O2/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, 0x7(%rsp)
callq 0x3116
cmpl $0x1, 0x48(%rax)
jne 0x3424
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 0x4b8a(%rip), %r13      # 0x7fc8
leaq 0x1f14(%rip), %r12      # 0x5359
leaq 0x1f24(%rip), %rbp      # 0x5370
movq %r15, 0x8(%rsp)
cmpl $0x0, 0x20(%rbx)
jne 0x3415
movzbl 0x7(%rsp), %eax
addl $-0x61, %eax
cmpl $0x11, %eax
ja 0x346e
movl $0x20089, %ecx          # imm = 0x20089
btl %eax, %ecx
jb 0x3415
movq %r13, %rdi
movq %r12, %rsi
callq 0x2130
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2130
movq %r13, %rdi
leaq 0x1edc(%rip), %rsi      # 0x5375
callq 0x2130
movq %r13, %rdi
leaq 0x1ed9(%rip), %rsi      # 0x5381
callq 0x2130
movq %r13, %rdi
leaq 0x1ed6(%rip), %rsi      # 0x538d
callq 0x2130
movq %r13, %rdi
leaq 0x1ed1(%rip), %rsi      # 0x5397
callq 0x2130
movq %r13, %rdi
leaq 0x1ecb(%rip), %rsi      # 0x53a0
callq 0x2130
movq 0x4af7(%rip), %rdi      # 0x7fd8
leaq 0x7(%rsp), %rsi
callq 0x21b0
movzbl 0x7(%rsp), %eax
cmpl $0x72, %eax
je 0x3567
cmpl $0x64, %eax
je 0x354a
cmpl $0x68, %eax
je 0x3557
cmpl $0x61, %eax
jne 0x3582
movq %r14, %rdi
callq 0x2b48
movq %r14, %r15
movq %rbp, %r14
movq %r12, %rbp
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3796
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x3116
movq %rax, %rdi
movl %r12d, %esi
movq %rbp, %r12
movq %r14, %rbp
movq %r15, %r14
movq 0x8(%rsp), %r15
callq 0x2b5a
jmp 0x3451
movq %r14, %rdi
callq 0x2b8a
jmp 0x3451
movq %r14, %rdi
pushq $0x1e
popq %rsi
callq 0x2b76
jmp 0x3451
movq %r13, %rdi
leaq 0x1e3c(%rip), %rsi      # 0x53ad
callq 0x2130
movl $0x2, 0x20(%rbx)
jmp 0x3451
movq %r13, %rdi
leaq 0x1e4c(%rip), %rsi      # 0x53d8
callq 0x2130
jmp 0x3451