// File: /workspace/github_cpp_makefile_star2_O3/gilecheverria[P]UP_Battle_Project/Battle.cpp
// Function: Battle::enemyAction(int)
void Battle::enemyAction(int index)
{
    action_t action;
    int damage;
    int target;
    // Get a pointer to the monster that will act
    // Cast it to the correct Class pointer
    Monster * the_enemy = static_cast<Monster*> (enemy_party.getMember(index));

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

    // Get the action taken by the monster using its percentages
    action = the_enemy->selectAction();

    switch (action)
    {
        case ATTACK:
            // Get the damage dealt by the hero
            damage = the_enemy->performAttack();
            // Select the enemy to attack
            target = selectHeroTarget();
            // Apply the damate
            hero_party.getMember(target)->receiveDamage(damage);
            std::cout << the_enemy->getName() << " attacks hero " << target << " dealing " << damage << " damage\n";
            break;
        case DEFEND:
            the_enemy->defend();
            std::cout << the_enemy->getName() << " defends\n";
            break;
        case HEAL:
            the_enemy->healDamage(30);
            std::cout << the_enemy->getName() << " heals\n";
            break;
        default:
            std::cout << "The enemy does not know what to do and stands still\n";
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
addq $0x10, %rdi
callq 0x352e
cmpl $0x1, 0x48(%rax)
je 0x3c4f
movq %rax, %r14
movq %rax, %rdi
callq 0x3058
cmpl $0x2, %eax
je 0x3bf0
cmpl $0x1, %eax
je 0x3baf
testl %eax, %eax
jne 0x3c5a
movq %r14, %rdi
callq 0x2d74
movl %eax, %ebx
callq 0x2050
cltd
idivl 0x24(%r15)
movl %edx, %ebp
movq %r15, %rdi
movl %edx, %esi
callq 0x352e
movq %rax, %rdi
movl %ebx, %esi
callq 0x2d86
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x334a
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x4479(%rip), %rdi      # 0x7fc8
callq 0x2180
movq %rax, %r14
leaq 0x1899(%rip), %rsi      # 0x53f7
movl $0xe, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebp, %esi
callq 0x2220
movq %rax, %r14
leaq 0x1887(%rip), %rsi      # 0x5406
movl $0x9, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebx, %esi
callq 0x2220
leaq 0x1873(%rip), %rsi      # 0x5410
movl $0x8, %edx
movq %rax, %rdi
callq 0x2180
jmp 0x3c34
movq %r14, %rdi
callq 0x2dba
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x334a
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x43f3(%rip), %rdi      # 0x7fc8
callq 0x2180
leaq 0x1838(%rip), %rsi      # 0x5419
movl $0x9, %edx
movq %rax, %rdi
callq 0x2180
jmp 0x3c34
movq %r14, %rdi
movl $0x1e, %esi
callq 0x2da6
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x334a
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x43ad(%rip), %rdi      # 0x7fc8
callq 0x2180
leaq 0x17fc(%rip), %rsi      # 0x5423
movl $0x7, %edx
movq %rax, %rdi
callq 0x2180
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c4f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x4367(%rip), %rdi      # 0x7fc8
leaq 0x17c3(%rip), %rsi      # 0x542b
movl $0x34, %edx
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2180
jmp 0x3c80
jmp 0x3c80
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c9e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2230