// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
addq $0x10, %rdi
movl -0xc(%rbp), %esi
callq 0x4020
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4bc0
cmpl $0x1, %eax
jne 0x46d0
jmp 0x4921
movq -0x20(%rbp), %rdi
callq 0x3b40
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x9c(%rbp)
testl %eax, %eax
je 0x4710
jmp 0x46eb
movl -0x9c(%rbp), %eax
subl $0x1, %eax
je 0x481a
jmp 0x46fc
movl -0x9c(%rbp), %eax
subl $0x2, %eax
je 0x4890
jmp 0x490e
movq -0x20(%rbp), %rdi
callq 0x33c0
movq -0x98(%rbp), %rdi
movl %eax, -0x14(%rbp)
callq 0x4b80
movq -0x98(%rbp), %rdi
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %esi
callq 0x4020
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33f0
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x3e70
movq -0xb0(%rbp), %rsi
movq 0x4861(%rip), %rdi      # 0x8fc8
callq 0x2180
movq %rax, -0xa8(%rbp)
jmp 0x4775
movq -0xa8(%rbp), %rdi
leaq 0x1cb5(%rip), %rsi      # 0x6438
callq 0x21b0
movq %rax, -0xb8(%rbp)
jmp 0x4791
movq -0xb8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x2310
movq %rax, -0xc0(%rbp)
jmp 0x47a9
movq -0xc0(%rbp), %rdi
leaq 0x1c90(%rip), %rsi      # 0x6447
callq 0x21b0
movq %rax, -0xc8(%rbp)
jmp 0x47c5
movq -0xc8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2310
movq %rax, -0xd0(%rbp)
jmp 0x47dd
movq -0xd0(%rbp), %rdi
leaq 0x1c66(%rip), %rsi      # 0x6451
callq 0x21b0
jmp 0x47f2
leaq -0x40(%rbp), %rdi
callq 0x2100
jmp 0x4921
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2100
jmp 0x492a
movq -0x20(%rbp), %rdi
callq 0x34a0
movq -0x20(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x3e70
movq -0xe0(%rbp), %rsi
movq 0x4783(%rip), %rdi      # 0x8fc8
callq 0x2180
movq %rax, -0xd8(%rbp)
jmp 0x4853
movq -0xd8(%rbp), %rdi
leaq 0x1bf9(%rip), %rsi      # 0x645a
callq 0x21b0
jmp 0x4868
leaq -0x70(%rbp), %rdi
callq 0x2100
jmp 0x4921
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2100
jmp 0x492a
movq -0x20(%rbp), %rdi
movl $0x1e, %esi
callq 0x3460
movq -0x20(%rbp), %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x3e70
movq -0xf0(%rbp), %rsi
movq 0x4705(%rip), %rdi      # 0x8fc8
callq 0x2180
movq %rax, -0xe8(%rbp)
jmp 0x48d1
movq -0xe8(%rbp), %rdi
leaq 0x1b85(%rip), %rsi      # 0x6464
callq 0x21b0
jmp 0x48e6
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x4921
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x492a
movq 0x46b3(%rip), %rdi      # 0x8fc8
leaq 0x1b50(%rip), %rsi      # 0x646c
callq 0x21b0
addq $0xf0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x2320
nopw %cs:(%rax,%rax)