// File: /workspace/github_cpp_makefile_star2_O1/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 0x353a
cmpl $0x1, 0x48(%rax)
je 0x3c57
movq %rax, %r14
movq %rax, %rdi
callq 0x3050
cmpl $0x2, %eax
je 0x3bf8
cmpl $0x1, %eax
je 0x3bb7
testl %eax, %eax
jne 0x3c62
movq %r14, %rdi
callq 0x2d72
movl %eax, %ebx
callq 0x2050
cltd
idivl 0x24(%r15)
movl %edx, %ebp
movq %r15, %rdi
movl %edx, %esi
callq 0x353a
movq %rax, %rdi
movl %ebx, %esi
callq 0x2d84
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3358
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x4471(%rip), %rdi      # 0x7fc8
callq 0x2180
movq %rax, %r14
leaq 0x1881(%rip), %rsi      # 0x53e7
movl $0xe, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebp, %esi
callq 0x2220
movq %rax, %r14
leaq 0x186f(%rip), %rsi      # 0x53f6
movl $0x9, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebx, %esi
callq 0x2220
leaq 0x185b(%rip), %rsi      # 0x5400
movl $0x8, %edx
movq %rax, %rdi
callq 0x2180
jmp 0x3c3c
movq %r14, %rdi
callq 0x2db8
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3358
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x43eb(%rip), %rdi      # 0x7fc8
callq 0x2180
leaq 0x1820(%rip), %rsi      # 0x5409
movl $0x9, %edx
movq %rax, %rdi
callq 0x2180
jmp 0x3c3c
movq %r14, %rdi
movl $0x1e, %esi
callq 0x2da4
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3358
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x43a5(%rip), %rdi      # 0x7fc8
callq 0x2180
leaq 0x17e4(%rip), %rsi      # 0x5413
movl $0x7, %edx
movq %rax, %rdi
callq 0x2180
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c57
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x435f(%rip), %rdi      # 0x7fc8
leaq 0x17ab(%rip), %rsi      # 0x541b
movl $0x34, %edx
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2180
jmp 0x3c88
jmp 0x3c88
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3ca6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2230