// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movb $0x78, -0xd(%rbp)
movl -0xc(%rbp), %esi
callq 0x4020
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4bc0
cmpl $0x1, %eax
jne 0x44da
jmp 0x467f
jmp 0x44dc
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x20(%rcx)
movb %al, -0x29(%rbp)
jne 0x4522
movsbl -0xd(%rbp), %ecx
xorl %eax, %eax
cmpl $0x61, %ecx
movb %al, -0x29(%rbp)
je 0x4522
movsbl -0xd(%rbp), %ecx
xorl %eax, %eax
cmpl $0x64, %ecx
movb %al, -0x29(%rbp)
je 0x4522
movsbl -0xd(%rbp), %ecx
xorl %eax, %eax
cmpl $0x68, %ecx
movb %al, -0x29(%rbp)
je 0x4522
movsbl -0xd(%rbp), %eax
cmpl $0x72, %eax
setne %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x452e
jmp 0x467f
movq 0x4a93(%rip), %rdi      # 0x8fc8
movq %rdi, -0x40(%rbp)
leaq 0x1e5a(%rip), %rsi      # 0x639a
callq 0x21b0
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4be0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x1e49(%rip), %rsi      # 0x63b1
callq 0x21b0
movq -0x40(%rbp), %rdi
leaq 0x1e3e(%rip), %rsi      # 0x63b6
callq 0x21b0
movq -0x40(%rbp), %rdi
leaq 0x1e3a(%rip), %rsi      # 0x63c2
callq 0x21b0
movq -0x40(%rbp), %rdi
leaq 0x1e36(%rip), %rsi      # 0x63ce
callq 0x21b0
movq -0x40(%rbp), %rdi
leaq 0x1e30(%rip), %rsi      # 0x63d8
callq 0x21b0
movq -0x40(%rbp), %rdi
leaq 0x1e29(%rip), %rsi      # 0x63e1
callq 0x21b0
movq 0x4a14(%rip), %rdi      # 0x8fd8
leaq -0xd(%rbp), %rsi
callq 0x22a0
movsbl -0xd(%rbp), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x11, %eax
ja 0x4667
movq -0x38(%rbp), %rax
leaq 0x1cee(%rip), %rcx      # 0x62dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
callq 0x33c0
movq -0x28(%rbp), %rdi
movl %eax, -0x14(%rbp)
callq 0x4a10
movq -0x28(%rbp), %rdi
movl %eax, -0x18(%rbp)
addq $0x10, %rdi
movl -0x18(%rbp), %esi
callq 0x4020
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33f0
jmp 0x467a
movq -0x20(%rbp), %rdi
callq 0x34a0
jmp 0x467a
movq -0x20(%rbp), %rdi
movl $0x1e, %esi
callq 0x3460
jmp 0x467a
movq 0x497a(%rip), %rdi      # 0x8fc8
leaq 0x1d99(%rip), %rsi      # 0x63ee
callq 0x21b0
movq -0x28(%rbp), %rax
movl $0x2, 0x20(%rax)
jmp 0x467a
movq 0x495a(%rip), %rdi      # 0x8fc8
leaq 0x1da4(%rip), %rsi      # 0x6419
callq 0x21b0
jmp 0x44dc
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)