// File: 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
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x3b0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4420
leaq -0x70(%rbp), %rdi
callq 0x4420
leaq -0x90(%rbp), %rdi
callq 0x4420
leaq -0xa8(%rbp), %rdi
callq 0x11b00
jmp 0x1017a
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x3b1(%rbp)
jmp 0x1018f
movb -0x3b1(%rbp), %al
testb $0x1, %al
jne 0x10b40
jmp 0x1019f
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x3b2(%rbp)
jmp 0x101b7
movb -0x3b2(%rbp), %al
testb $0x1, %al
jne 0x10b40
jmp 0x101c7
movq -0x3b0(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xf0c0
jmp 0x101dc
movq 0xbddd(%rip), %rdi      # 0x1bfc0
leaq -0xd8(%rbp), %rsi
callq 0x42f0
movq %rax, -0x3c0(%rbp)
jmp 0x101f8
movq -0x3c0(%rbp), %rdi
leaq 0x3484(%rip), %rsi      # 0x1368a
callq 0x4310
movq %rax, -0x3c8(%rbp)
jmp 0x10214
movq -0x3c8(%rbp), %rdi
movq 0xbd8e(%rip), %rsi      # 0x1bfb0
callq 0x4340
jmp 0x10229
leaq -0xd8(%rbp), %rdi
callq 0x4200
movq 0xbda4(%rip), %rdi      # 0x1bfe0
callq 0x4110
movl %eax, -0x3cc(%rbp)
jmp 0x10249
movl -0x3cc(%rbp), %eax
cmpl $0xa, %eax
jne 0x102cc
movq 0xbd85(%rip), %rdi      # 0x1bfe0
callq 0x4560
jmp 0x10262
jmp 0x102cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x10ce4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x10538
movq 0xbd0d(%rip), %rdi      # 0x1bfe0
leaq -0x90(%rbp), %rsi
callq 0x4080
jmp 0x102e1
movl $0x10, %edi
movl $0x8, %esi
callq 0x118d0
movl %eax, -0x3d0(%rbp)
jmp 0x102f8
movl -0x3d0(%rbp), %edx
leaq -0x260(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x44a0
jmp 0x10313
leaq -0x260(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x43e0
movq %rax, -0x3d8(%rbp)
jmp 0x1032c
movq -0x3d8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x43e0
jmp 0x1033e
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movb $0x0, -0x2a1(%rbp)
callq 0x118f0
movq %rax, -0x3e0(%rbp)
jmp 0x1035b
leaq -0x280(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4150
jmp 0x1036d
leaq -0xa8(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x11f40
movl %eax, -0x3e4(%rbp)
jmp 0x10388
movq -0x3e0(%rbp), %rdi
movl -0x3e4(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
movq %rax, %rcx
movb $0x1, %al
cmpl $0x1, (%rcx)
movb %al, -0x3e5(%rbp)
jl 0x1041b
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x118f0
movq %rax, -0x3f0(%rbp)
jmp 0x103c6
leaq -0x2a0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4150
jmp 0x103d8
movb $0x1, -0x2a1(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x11f40
movl %eax, -0x3f4(%rbp)
jmp 0x103fa
movq -0x3f0(%rbp), %rdi
movl -0x3f4(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
cmpl $0x1, (%rax)
setl %al
movb %al, -0x3e5(%rbp)
movb -0x3e5(%rbp), %al
movb %al, -0x3f5(%rbp)
testb $0x1, -0x2a1(%rbp)
jne 0x10432
jmp 0x1043e
leaq -0x2a0(%rbp), %rdi
callq 0x4200
leaq -0x280(%rbp), %rdi
callq 0x4200
movb -0x3f5(%rbp), %al
testb $0x1, %al
jne 0x10459
jmp 0x1051e
movl $0x10, %edi
callq 0x41a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x400(%rbp)
leaq 0x321c(%rip), %rsi      # 0x13693
callq 0x4590
jmp 0x1047e
movq -0x400(%rbp), %rdi
movq 0xbb4c(%rip), %rsi      # 0x1bfd8
movq 0xbb35(%rip), %rdx      # 0x1bfc8
callq 0x44f0
jmp 0x10d16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x1052c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x104f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
testb $0x1, -0x2a1(%rbp)
jne 0x104e2
jmp 0x104ee
leaq -0x2a0(%rbp), %rdi
callq 0x4200
jmp 0x104f0
leaq -0x280(%rbp), %rdi
callq 0x4200
jmp 0x1052c
movq -0x400(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x4250
jmp 0x1052c
leaq -0x260(%rbp), %rdi
callq 0x4260
jmp 0x105a4
leaq -0x260(%rbp), %rdi
callq 0x4260
movl -0xb4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x10cd8
movq -0xb0(%rbp), %rdi
callq 0x4130
movq %rax, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0xba48(%rip), %rdi      # 0x1bfc0
callq 0x4310
movq %rax, -0x408(%rbp)
jmp 0x10586
movq -0x408(%rbp), %rdi
movq 0xba1c(%rip), %rsi      # 0x1bfb0
callq 0x4340
jmp 0x1059b
callq 0x44c0
jmp 0x105a2
jmp 0x105a4
jmp 0x105a6
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movb $0x0, -0x2f1(%rbp)
callq 0x118f0
movq %rax, -0x410(%rbp)
jmp 0x105c3
leaq -0x2d0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4150
jmp 0x105d5
leaq -0xa8(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x11f40
movl %eax, -0x414(%rbp)
jmp 0x105f0
movq -0x410(%rbp), %rdi
movl -0x414(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
movq %rax, %rcx
movb $0x1, %al
cmpl $0x1, (%rcx)
movb %al, -0x415(%rbp)
jl 0x10683
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x118f0
movq %rax, -0x420(%rbp)
jmp 0x1062e
leaq -0x2f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4150
jmp 0x10640
movb $0x1, -0x2f1(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x11f40
movl %eax, -0x424(%rbp)
jmp 0x10662
movq -0x420(%rbp), %rdi
movl -0x424(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
cmpl $0x1, (%rax)
setl %al
movb %al, -0x415(%rbp)
movb -0x415(%rbp), %al
movb %al, -0x425(%rbp)
testb $0x1, -0x2f1(%rbp)
jne 0x1069a
jmp 0x106a6
leaq -0x2f0(%rbp), %rdi
callq 0x4200
leaq -0x2d0(%rbp), %rdi
callq 0x4200
movb -0x425(%rbp), %al
testb $0x1, %al
jne 0x10235
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x11920
movq %rax, -0x430(%rbp)
jmp 0x106d9
leaq -0x318(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4150
jmp 0x106eb
leaq -0xa8(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x11f40
movl %eax, -0x434(%rbp)
jmp 0x10706
movq -0x430(%rbp), %rdi
movl -0x434(%rbp), %eax
movslq %eax, %rsi
callq 0x11940
movq (%rax), %rax
movq %rax, -0x448(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x11920
movq %rax, -0x440(%rbp)
jmp 0x1073b
leaq -0x338(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4150
jmp 0x1074d
leaq -0xa8(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x11f40
movl %eax, -0x44c(%rbp)
jmp 0x10768
movq -0x440(%rbp), %rdi
movl -0x44c(%rbp), %eax
movslq %eax, %rsi
callq 0x11940
movq -0x448(%rbp), %rdi
movq (%rax), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movsd %xmm0, -0x458(%rbp)
jmp 0x1079a
movsd -0x458(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x4200
leaq -0x318(%rbp), %rdi
callq 0x4200
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x118f0
movq %rax, -0x460(%rbp)
jmp 0x107d8
leaq -0x358(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4150
jmp 0x107ea
leaq -0xa8(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x11f40
movl %eax, -0x464(%rbp)
jmp 0x10805
movq -0x460(%rbp), %rdi
movl -0x464(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x4200
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x118f0
movq %rax, -0x470(%rbp)
jmp 0x10841
leaq -0x378(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4150
jmp 0x10853
leaq -0xa8(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0x11f40
movl %eax, -0x474(%rbp)
jmp 0x1086e
movq -0x470(%rbp), %rdi
movl -0x474(%rbp), %eax
movslq %eax, %rsi
callq 0x11900
movl (%rax), %eax
movl %eax, -0x20(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x4200
movsd -0x28(%rbp), %xmm0
cvtsi2sdl -0x1c(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x44d0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x108c9
xorps %xmm0, %xmm0
movsd %xmm0, -0x480(%rbp)
jmp 0x108db
cvtsi2sdl -0x20(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x480(%rbp)
movsd -0x480(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x37c(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x488(%rbp)
leaq -0x3a0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4150
jmp 0x1090e
leaq -0xa8(%rbp), %rdi
leaq -0x3a0(%rbp), %rsi
callq 0x11f40
movl %eax, -0x48c(%rbp)
jmp 0x10929
movl -0x48c(%rbp), %esi
movq -0x488(%rbp), %rdi
movl -0x37c(%rbp), %edx
callq 0x11960
jmp 0x10943
leaq -0x3a0(%rbp), %rdi
callq 0x4200
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc700
jmp 0x10961
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc700
jmp 0x10970
movq -0x3b0(%rbp), %rdi
callq 0x10d20
jmp 0x1097e
movq -0x18(%rbp), %rdi
callq 0x10d20
jmp 0x10989
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x48d(%rbp)
jmp 0x1099e
movb -0x48d(%rbp), %al
testb $0x1, %al
jne 0x10b0e
jmp 0x109ae
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x48e(%rbp)
jmp 0x109c6
movb -0x48e(%rbp), %al
testb $0x1, %al
jne 0x10b0e
jmp 0x109d6
movq -0x18(%rbp), %rdi
callq 0xff00
jmp 0x109e1
movq -0x3b0(%rbp), %rdi
callq 0xff00
jmp 0x109ef
jmp 0x10b0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x44c0
jmp 0x10a0d
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x10a51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
testb $0x1, -0x2f1(%rbp)
jne 0x10a43
jmp 0x10a4f
leaq -0x2f0(%rbp), %rdi
callq 0x4200
jmp 0x10a51
leaq -0x2d0(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x10a94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x4200
leaq -0x318(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x3a0(%rbp), %rdi
callq 0x4200
jmp 0x10cd8
movq -0x3b0(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x10130
movb %al, -0x48f(%rbp)
jmp 0x10b26
movb -0x48f(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x3a4(%rbp)
jmp 0x10ca0
movq -0x3b0(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x490(%rbp)
jmp 0x10b58
movb -0x490(%rbp), %al
testb $0x1, %al
jne 0x10b67
jmp 0x10bf4
movq 0xb452(%rip), %rdi      # 0x1bfc0
leaq 0x2b47(%rip), %rsi      # 0x136bc
callq 0x4310
movq %rax, -0x498(%rbp)
jmp 0x10b83
movq -0x498(%rbp), %rdi
movq 0xb41f(%rip), %rsi      # 0x1bfb0
callq 0x4340
jmp 0x10b98
movq -0x3b0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x4a8(%rbp)
callq 0xf110
movsd %xmm0, -0x4a0(%rbp)
jmp 0x10bb9
movsd -0x4a0(%rbp), %xmm0
movq -0x4a8(%rbp), %rdi
callq 0x11040
jmp 0x10bcf
movq -0x3b0(%rbp), %rdi
movb $0x0, 0x3a(%rdi)
callq 0x110c0
jmp 0x10be1
movb $0x1, -0x1(%rbp)
movl $0x1, -0x3a4(%rbp)
jmp 0x10ca0
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xc050
movb %al, -0x4a9(%rbp)
jmp 0x10c09
movb -0x4a9(%rbp), %al
testb $0x1, %al
jne 0x10c15
jmp 0x10c92
movq 0xb3a4(%rip), %rdi      # 0x1bfc0
leaq 0x2aa4(%rip), %rsi      # 0x136c7
callq 0x4310
movq %rax, -0x4b8(%rbp)
jmp 0x10c31
movq -0x4b8(%rbp), %rdi
movq 0xb371(%rip), %rsi      # 0x1bfb0
callq 0x4340
jmp 0x10c46
movq -0x18(%rbp), %rdi
callq 0xf110
movsd %xmm0, -0x4c0(%rbp)
jmp 0x10c59
movsd -0x4c0(%rbp), %xmm0
movq -0x3b0(%rbp), %rdi
callq 0x11040
jmp 0x10c6f
movq -0x18(%rbp), %rax
movb $0x0, 0x3a(%rax)
movq -0x18(%rbp), %rdi
callq 0x110c0
jmp 0x10c82
movb $0x0, -0x1(%rbp)
movl $0x1, -0x3a4(%rbp)
jmp 0x10ca0
movb $0x0, -0x1(%rbp)
movl $0x1, -0x3a4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8a20
leaq -0x90(%rbp), %rdi
callq 0x4200
leaq -0x70(%rbp), %rdi
callq 0x4200
leaq -0x50(%rbp), %rdi
callq 0x4200
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0x8a20
leaq -0x90(%rbp), %rdi
callq 0x4200
leaq -0x70(%rbp), %rdi
callq 0x4200
leaq -0x50(%rbp), %rdi
callq 0x4200
movq -0xb0(%rbp), %rdi
callq 0x4520
movq %rax, %rdi
callq 0x4f20
nopw %cs:(%rax,%rax)