// File: /workspace/github_cpp_makefile_star2_O1/MichaelXanth[P]RPG_Game/Battle/Battle.cpp
// Function: Battle::CastSpell(Hero&, Monster&)
bool Battle::CastSpell(Hero& hero, Monster& monster) 
{
    unsigned int totalDamage;
    unsigned int slotNumber;
    unsigned int typeOfSpell;
    Spell* chosenSpell;

    if (hero.DisplaySpells(chosenSpell , slotNumber , typeOfSpell) == false)
        return false;

    // Checks if the hero has enough magic power
    if (hero.UseSpell(*chosenSpell) == true) { 
        hero.ReduceMagicPower(chosenSpell->GetReqEnergy()); // Reduces the hero's magic power
        totalDamage = chosenSpell->HeroDamage(hero);        // Gets the total damage that will be caused
        monster.ChangeHealth(floor((double)(totalDamage * totalDamage) / (totalDamage + monster.MonsterGetDefence())));
        monster.HitBySpell(chosenSpell);                    // Applies the after attack effects of the spell
        hero.SpellUsed(slotNumber , typeOfSpell);           // Deletes the spell
        
        if (monster.Fainted()) {
            cout << "The hero " << hero.GetName() << " defeated the monster " << monster.GetName() << endl;
            return true;
        }
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq %rsp, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x14d2c
movl %eax, %ebx
testb %al, %al
je 0xb520
movq (%rsp), %rsi
movq %r15, %rdi
callq 0x10bd0
testb %al, %al
je 0xb520
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
leaq 0x38(%rsp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x10ab2
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x22a84
movl %eax, %ebp
imull %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x18e06
addl %ebp, %eax
cvtsi2sd %rax, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x32c0
cvttsd2si %xmm0, %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movq (%rsp), %rsi
movq %r14, %rdi
callq 0x18e1c
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movq %r15, %rdi
callq 0x11518
movq %r14, %rdi
callq 0x108b8
testb %al, %al
je 0xb520
movq 0x23b72(%rip), %r12     # 0x2efc8
leaq 0x18e32(%rip), %rsi     # 0x2428f
movl $0x9, %edx
movq %r12, %rdi
callq 0x31e0
leaq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x108c2
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r12, %rdi
callq 0x31e0
movq %rax, %r15
leaq 0x18e05(%rip), %rsi     # 0x24299
movl $0x16, %edx
movq %rax, %rdi
callq 0x31e0
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x108c2
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r15, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb505
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb520
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31b0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb533
movq %rax, %rbx
jmp 0xb556
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb556
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb571
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31b0
movq %rbx, %rdi
callq 0x32f0
nop