// File: /workspace/github_cpp_makefile_star2_O2/Serfati[P]Heroes-of-Might-and-Magic-3/Hero.cpp
// Function: Hero::attackEnemy(Hero&)
bool Hero::attackEnemy(Hero &enemy) {
    int attackCount,defendCount;
    double ratio,howMuchToDelete;
    string attack,toAttack,line;
    Creature c;
    if ( ! enemy.army->isDestroyed() && ! army->isDestroyed()) {
        cout << this->getName() << "'s turn:" << endl;
        /* -~=[  Gets creature to attack and creature to defend  ]~=- */
        do {
            try {
                if ( std::cin.peek() == '\n' )
                    std::cin.ignore();
                getline(cin , line);
                stringstream ss(line);
                ss >> attack >> toAttack;
                if ( enemy.army->getArmyList()[c.creaTypeByName(toAttack)] < 1 ||
                     this->army->getArmyList()[c.creaTypeByName(attack)] < 1 )
                    throw std::invalid_argument("Creature to attack not found! try again.");
            }
            catch( std::invalid_argument &e ) {
                cout << e.what() << endl;
            }
        } while ( enemy.army->getArmyList()[c.creaTypeByName(toAttack)] < 1 ||
                  this->army->getArmyList()[c.creaTypeByName(attack)] < 1 );

        /* -~=[  Battle | Update | Save | Show and Return   ]=~- */

        //attack!
        ratio = (army->getRealArmy()[c.creaTypeByName(attack)]->attackAnother(
                *enemy.army->getRealArmy()[c.creaTypeByName(toAttack)]));
        attackCount = army->getArmyList()[c.creaTypeByName(attack)];
        defendCount = enemy.army->getArmyList()[c.creaTypeByName(toAttack)];
        howMuchToDelete = floor(ratio * attackCount);

        //delete destroyed and update
        int x = int(howMuchToDelete >= defendCount ? 0 : (defendCount - howMuchToDelete));
        enemy.army->setAtArmyList(c.creaTypeByName(toAttack),x);

        //reset creatures details
        army->reBuild();
        enemy.army->reBuild();
        //saves
        save();
        enemy.save();
        //SHOW
        if ( !enemy.army->isDestroyed() && !army->isDestroyed()) {
            enemy.showHeroFight();
            this->showHeroFight();
        }
        return enemy.attackEnemy(*this);
    }
    /* -~=[  Check if Eliminated  ]=~- */
    if ( army->isDestroyed()) {

        cout << "victorious" << endl;
        enemy.addGold(this->getGold());
        isAlive = false;
        this->rmdir();
        return 1;
    }
    if ( enemy.army->isDestroyed()) {
        cout << "You have been perished" << endl;
        this->addGold(enemy.getGold());
        enemy.isAlive = false;
        enemy.rmdir();
        return 0;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %rbx
movq %rdi, -0x30(%rbp)
xorl %ecx, %ecx
leaq -0x68(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq -0xc8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x82b4
movq %rbx, -0x38(%rbp)
movq 0x40(%rbx), %rdi
callq 0x621a
testb %al, %al
jne 0x7545
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x621a
testb %al, %al
je 0x760b
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x621a
testb %al, %al
je 0x75aa
movq 0x6a63(%rip), %rdi      # 0xdfc0
leaq 0x2150(%rip), %rsi      # 0x96b4
callq 0x3270
movq %rax, %rdi
callq 0x3150
movq -0x38(%rbp), %rcx
cmpb $0x1, 0x3a(%rcx)
jne 0x7596
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm0
addsd 0x30(%rcx), %xmm0
minsd 0x206f(%rip), %xmm0     # 0x9600
movsd %xmm0, 0x30(%rcx)
movq -0x30(%rbp), %rdi
movb $0x0, 0x3a(%rdi)
movb $0x1, %bl
callq 0x7d5e
jmp 0x7a9f
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x621a
testb %al, %al
je 0x7604
movq 0x69fe(%rip), %rdi      # 0xdfc0
leaq 0x20f6(%rip), %rsi      # 0x96bf
callq 0x3270
movq %rax, %rdi
callq 0x3150
movq -0x30(%rbp), %rax
cmpb $0x1, 0x3a(%rax)
movq -0x38(%rbp), %rdi
jne 0x75fb
movsd 0x30(%rdi), %xmm0
addsd 0x30(%rax), %xmm0
minsd 0x200a(%rip), %xmm0     # 0x9600
movsd %xmm0, 0x30(%rax)
movb $0x0, 0x3a(%rdi)
callq 0x7d5e
xorl %ebx, %ebx
jmp 0x7a9f
movq -0x30(%rbp), %rax
leaq 0x8(%rax), %rsi
leaq -0x378(%rbp), %rdi
callq 0x32f0
movq 0x699a(%rip), %rdi      # 0xdfc0
leaq -0x378(%rbp), %rsi
callq 0x3260
leaq 0x2049(%rip), %rsi      # 0x9682
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
callq 0x3150
leaq -0x378(%rbp), %rdi
callq 0x3130
leaq -0x58(%rbp), %r12
leaq -0x1f0(%rbp), %rbx
leaq -0x1d0(%rbp), %r15
movq 0x6972(%rip), %rdi      # 0xdfe0
callq 0x30f0
cmpl $0xa, %eax
jne 0x7684
movq 0x6961(%rip), %rdi      # 0xdfe0
callq 0x3410
movq 0x6955(%rip), %rdi      # 0xdfe0
leaq -0xd8(%rbp), %rsi
callq 0x3060
leaq -0x378(%rbp), %r13
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x3360
movq %r13, %rdi
leaq -0x98(%rbp), %rsi
callq 0x32d0
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x32d0
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r13
leaq -0xb8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32f0
movq %r12, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x8454
cltq
movq (%r13), %rcx
cmpl $0x0, (%rcx,%rax,4)
jle 0x77e4
movq -0x30(%rbp), %rax
movq 0x40(%rax), %r13
movq %rbx, %rdi
leaq -0x98(%rbp), %rsi
callq 0x32f0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x8454
cltq
movq (%r13), %rcx
movl (%rcx,%rax,4), %r13d
movq %rbx, %rdi
callq 0x3130
leaq -0xb8(%rbp), %rdi
callq 0x3130
testl %r13d, %r13d
jle 0x77f0
leaq -0x378(%rbp), %rdi
callq 0x31f0
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r13
movq %r15, %rdi
leaq -0x78(%rbp), %rsi
callq 0x32f0
movq %r12, %rdi
movq %r15, %rsi
callq 0x8454
cltq
movq (%r13), %rcx
cmpl $0x0, (%rcx,%rax,4)
jle 0x77d7
movq -0x30(%rbp), %rax
movq 0x40(%rax), %r13
leaq -0x1b0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x32f0
movq %r12, %rdi
leaq -0x1b0(%rbp), %r14
movq %r14, %rsi
callq 0x8454
cltq
movq (%r13), %rcx
movl (%rcx,%rax,4), %r13d
movq %r14, %rdi
callq 0x3130
movq %r15, %rdi
callq 0x3130
testl %r13d, %r13d
jle 0x7667
jmp 0x78b4
movq %r15, %rdi
callq 0x3130
jmp 0x7667
leaq -0xb8(%rbp), %rdi
callq 0x3130
pushq $0x10
popq %rdi
callq 0x3160
movq %rax, -0x40(%rbp)
movq %rax, %rdi
leaq 0x1e85(%rip), %rsi      # 0x968b
callq 0x3440
movq -0x40(%rbp), %rdi
movq 0x67c2(%rip), %rsi      # 0xdfd8
movq 0x67ab(%rip), %rdx      # 0xdfc8
callq 0x33d0
jmp 0x7ad4
movq %rdx, %r13
movq %rax, %r14
movq %rbx, %rdi
callq 0x3130
jmp 0x7850
movq %rdx, %r13
movq %rax, %r14
movq -0x40(%rbp), %rdi
callq 0x31e0
jmp 0x786c
jmp 0x785e
movq %rdx, %r13
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
callq 0x3130
jmp 0x786c
movq %rdx, %r13
movq %rax, %r14
jmp 0x7878
movq %rdx, %r13
movq %rax, %r14
leaq -0x378(%rbp), %rdi
callq 0x31f0
cmpl $0x1, %r13d
jne 0x7b65
movq %r14, %rdi
callq 0x3100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x6726(%rip), %rdi      # 0xdfc0
movq %rax, %rsi
callq 0x3270
movq %rax, %rdi
callq 0x3150
callq 0x3390
jmp 0x7757
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x190(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x8454
cltq
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rbx
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r14
leaq -0x170(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x8454
cltq
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movsd %xmm0, -0x40(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3130
leaq -0x190(%rbp), %rdi
callq 0x3130
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x150(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8454
cltq
movq (%rbx), %rcx
movl (%rcx,%rax,4), %ebx
leaq -0x150(%rbp), %rdi
callq 0x3130
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r14
leaq -0x130(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x8454
cltq
movq (%r14), %rcx
cvtsi2sdl (%rcx,%rax,4), %xmm0
movapd %xmm0, -0xf0(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3130
cvtsi2sd %ebx, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x33b0
movsd %xmm0, -0x40(%rbp)
movq -0x38(%rbp), %r14
movq 0x40(%r14), %rbx
leaq -0x110(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8454
movapd -0xf0(%rbp), %xmm1
movapd %xmm1, %xmm0
movsd -0x40(%rbp), %xmm2
subsd %xmm2, %xmm0
cmplesd %xmm2, %xmm1
andnpd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
cltq
movq (%rbx), %rdx
movl %ecx, (%rdx,%rax,4)
leaq -0x110(%rbp), %rdi
callq 0x3130
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x652a
movq 0x40(%r14), %rdi
callq 0x652a
movq -0x30(%rbp), %rdi
callq 0x7b8e
movq %r14, %rdi
callq 0x7b8e
movq 0x40(%r14), %rdi
callq 0x621a
testb %al, %al
jne 0x7a91
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x621a
testb %al, %al
jne 0x7a91
movq %r14, %rdi
callq 0x73a6
movq -0x30(%rbp), %rdi
callq 0x73a6
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x74c6
movl %eax, %ebx
leaq -0xd8(%rbp), %rdi
callq 0x3130
leaq -0x78(%rbp), %rdi
callq 0x3130
leaq -0x98(%rbp), %rdi
callq 0x3130
movl %ebx, %eax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7b51
movq %rax, %r14
callq 0x3390
jmp 0x7b65
movq %rax, %rdi
callq 0x5858
movq %rax, %r14
leaq -0x110(%rbp), %rdi
jmp 0x7b60
movq %rax, %r14
leaq -0x130(%rbp), %rdi
jmp 0x7b60
movq %rax, %r14
leaq -0x150(%rbp), %rdi
jmp 0x7b60
jmp 0x7b51
movq %rax, %r14
leaq -0x170(%rbp), %rdi
callq 0x3130
jmp 0x7b25
movq %rax, %r14
leaq -0x190(%rbp), %rdi
jmp 0x7b60
movq %rax, %r14
leaq -0x378(%rbp), %rdi
jmp 0x7b60
jmp 0x7b51
jmp 0x7b51
jmp 0x7b51
movq %rax, %r14
leaq -0x1b0(%rbp), %rdi
callq 0x3130
jmp 0x7b59
movq %rax, %r14
jmp 0x7b65
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x3130
leaq -0xd8(%rbp), %rdi
callq 0x3130
leaq -0x78(%rbp), %rdi
callq 0x3130
leaq -0x98(%rbp), %rdi
callq 0x3130
movq %r14, %rdi
callq 0x33f0