// File: /workspace/github_cpp_makefile_star2_O2/MichaelXanth[P]RPG_Game/Market/Market.cpp
// Function: Market::isAbleToBuy(Hero const*, bool const&)
int Market::isAbleToBuy(const Hero* hero, const bool& info = true)
{
    int buyState = 2;
    bool found = false;

    if (hero->GetMoney() == 0) {
        if (info) {
            if (lightingSpellsForSale || fireSpellsForSale || iceSpellsForSale || weaponsForSale || potionsForSale || armorsForSale) {
                
                DisplayMarket(false, hero, 3);
                cerr << endl;
                cerr << "-------------------------------" << endl << endl;
                cerr << "\033[35mWarning:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m has no money. The minimum required amount is: " << minPrice << endl;
                usleep(2500000);
            
            } else
                cerr << endl << "\033[31mError:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m has no money. The minimum required amount is: " << minPrice << endl;
        }
        return -1;
    }

    if (hero->GetMoney() < minPrice) {
        if (info) {
            if (lightingSpellsForSale || fireSpellsForSale || iceSpellsForSale || weaponsForSale || potionsForSale || armorsForSale) {

                DisplayMarket(false,hero,3);
                cerr << endl;
                cerr << "-------------------------------" << endl << endl;
                cerr << "\033[35mWarning:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m doesn't have enough money. The minimum required amount is: " << minPrice << endl;
                usleep(2500000);
            
            } else
                cerr << endl << "\033[31mError:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m doesn't have enough money. The minimum required amount is: " << minPrice << endl;
        }
        return -1;
    }

    if (hero->GetAvailableItemSlots() == 0 || hero->GetMoney() < minItemPrice) {
        if (hero->GetAvailableSpellSlots() == 0 || hero->GetMoney() < minSpellPrice) {
            if (info) {
                if (lightingSpellsForSale || fireSpellsForSale || iceSpellsForSale || weaponsForSale || potionsForSale || armorsForSale) {
                    
                    DisplayMarket(false,hero,3);
                    cerr << endl;
                    cerr << "-------------------------------" << endl << endl;
                    cerr << "\033[35mWarning:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m doesn't have any other available Item and Spell slots." << endl;
                    usleep(2500000);
                
                } else
                    cerr << endl << "\033[31mError:\033[0m Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m doesn't have enough money. The minimum required amount is: " << minPrice << endl;
            }
            return -1;
        }
        buyState = 0;   //Means that he can buy Spells only
    
    } else if (hero->GetAvailableSpellSlots() == 0 || hero->GetMoney() < minSpellPrice) {
        buyState = 1;   //Means that he can buy Items only
    }

    if (buyState != 1) {
        
        unsigned int i;

        for (i = 0; i < iceSpellsArray.size() && !canBeBought(iceSpellsArray[i],hero); i++)
            ;
        if (i < iceSpellsArray.size())
            found = true;

        for (i = 0; i < fireSpellsArray.size() && !canBeBought(fireSpellsArray[i],hero); i++)
            ;
        if (i < fireSpellsArray.size())
            found = true;

        for (i = 0; i < lightingSpellsArray.size() && !canBeBought(lightingSpellsArray[i],hero); i++)
            ;
        if (i < lightingSpellsArray.size())
            found = true;
    }

    if (buyState != 0) {

        unsigned int i;

        for (i = 0; i < weaponsArray.size() && !canBeBought(weaponsArray[i],hero); i++)
            ;
        if (i < weaponsArray.size())
            found = true;

        for (i = 0; i < armorsArray.size() && !canBeBought(armorsArray[i],hero); i++)
            ;
        if (i < armorsArray.size())
            found = true;

        for (i = 0; i < potionsArray.size() && !canBeBought(potionsArray[i],hero); i++)
            ;
        if (i < potionsArray.size())
            found = true;
    }

    if (!found) {
        if (info) {
            cerr << endl << "\033[31mError:\033[0m There are no available Items or Spells for Hero \033[38;5;220m" << hero->Living::GetName() << "\033[0m to buy." << endl;
            usleep(3000000);
        }
        return -1;
    }

    return buyState;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0xd0a8
testl %eax, %eax
je 0x142ae
movq %r15, %rdi
callq 0xd0a8
cmpl 0x1e8(%r14), %eax
jae 0x14373
pushq $-0x1
popq %rbx
cmpb $0x1, (%r12)
jne 0x1493a
cmpl $0x0, 0x1c8(%r14)
jne 0x1455c
cmpl $0x0, 0x1cc(%r14)
jne 0x1455c
cmpl $0x0, 0x1d0(%r14)
jne 0x1455c
cmpl $0x0, 0x1d4(%r14)
jne 0x1455c
cmpl $0x0, 0x1d8(%r14)
jne 0x1455c
cmpl $0x0, 0x1dc(%r14)
jne 0x1455c
movq 0x12d9e(%rip), %rdi     # 0x26ff0
callq 0x30d0
leaq 0xa048(%rip), %rsi      # 0x1e2a6
movq %rax, %rdi
callq 0x31d0
movq %rax, %r12
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xced6
movq %r12, %rdi
movq %r13, %rsi
callq 0x3190
leaq 0xa03d(%rip), %rsi      # 0x1e2c7
movq %rax, %rdi
callq 0x31d0
movl 0x1e8(%r14), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
jmp 0x14479
pushq $-0x1
popq %rbx
cmpb $0x1, (%r12)
jne 0x1493a
cmpl $0x0, 0x1c8(%r14)
jne 0x144c2
cmpl $0x0, 0x1cc(%r14)
jne 0x144c2
cmpl $0x0, 0x1d0(%r14)
jne 0x144c2
cmpl $0x0, 0x1d4(%r14)
jne 0x144c2
cmpl $0x0, 0x1d8(%r14)
jne 0x144c2
cmpl $0x0, 0x1dc(%r14)
jne 0x144c2
movq 0x12cd9(%rip), %rdi     # 0x26ff0
callq 0x30d0
leaq 0x9f83(%rip), %rsi      # 0x1e2a6
movq %rax, %rdi
callq 0x31d0
movq %rax, %r12
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xced6
movq %r12, %rdi
movq %r13, %rsi
callq 0x3190
leaq 0x9f23(%rip), %rsi      # 0x1e272
movq %rax, %rdi
callq 0x31d0
movl 0x1e8(%r14), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
jmp 0x14479
movq %r15, %rdi
callq 0xd088
testl %eax, %eax
movq %r14, -0x40(%rbp)
je 0x14398
movq %r15, %rdi
callq 0xd0a8
cmpl 0x1e4(%r14), %eax
jae 0x14487
movq %r15, %rdi
callq 0xd080
testl %eax, %eax
je 0x143b9
movq %r15, %rdi
callq 0xd0a8
cmpl 0x1e0(%r14), %eax
jae 0x145f6
pushq $-0x1
popq %rbx
cmpb $0x1, (%r12)
jne 0x1493a
cmpl $0x0, 0x1c8(%r14)
jne 0x1460b
cmpl $0x0, 0x1cc(%r14)
jne 0x1460b
cmpl $0x0, 0x1d0(%r14)
jne 0x1460b
cmpl $0x0, 0x1d4(%r14)
jne 0x1460b
cmpl $0x0, 0x1d8(%r14)
jne 0x1460b
cmpl $0x0, 0x1dc(%r14)
jne 0x1460b
movq 0x12bce(%rip), %rdi     # 0x26ff0
callq 0x30d0
leaq 0x9e78(%rip), %rsi      # 0x1e2a6
movq %rax, %rdi
callq 0x31d0
movq %rax, %r12
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xced6
movq %r12, %rdi
movq %r13, %rsi
callq 0x3190
leaq 0x9e6d(%rip), %rsi      # 0x1e2c7
movq %rax, %rdi
callq 0x31d0
movl 0x1e8(%r14), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
leaq -0x60(%rbp), %rdi
callq 0x30c0
jmp 0x1493a
movq %r15, %rdi
callq 0xd080
pushq $0x1
popq %rbx
testl %eax, %eax
movq %r12, -0x68(%rbp)
je 0x146a9
movq %r15, %rdi
callq 0xd0a8
movl $0x0, -0x30(%rbp)
cmpl 0x1e0(%r14), %eax
jae 0x146b8
movl %ebx, -0x2c(%rbp)
jmp 0x147cc
leaq -0x60(%rbp), %rsi
movb $0x0, (%rsi)
pushq $0x3
popq %rcx
movq %r14, %rdi
movq %r15, %rdx
callq 0x1496c
movq 0x12b12(%rip), %r12     # 0x26ff0
movq %r12, %rdi
callq 0x30d0
leaq 0x9d65(%rip), %rsi      # 0x1e252
movq %r12, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
leaq 0x6f33(%rip), %rsi      # 0x1b43f
movq %r12, %rdi
callq 0x31d0
movq %rax, %r12
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xced6
movq %r12, %rdi
movq %r13, %rsi
callq 0x3190
leaq 0x9d3a(%rip), %rsi      # 0x1e272
movq %rax, %rdi
callq 0x31d0
movl 0x1e8(%r14), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
jmp 0x14691
leaq -0x60(%rbp), %rsi
movb $0x0, (%rsi)
pushq $0x3
popq %rcx
movq %r14, %rdi
movq %r15, %rdx
callq 0x1496c
movq 0x12a78(%rip), %r12     # 0x26ff0
movq %r12, %rdi
callq 0x30d0
leaq 0x9ccb(%rip), %rsi      # 0x1e252
movq %r12, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
leaq 0x6e99(%rip), %rsi      # 0x1b43f
movq %r12, %rdi
callq 0x31d0
movq %rax, %r12
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xced6
movq %r12, %rdi
movq %r13, %rsi
callq 0x3190
leaq 0x9cf5(%rip), %rsi      # 0x1e2c7
movq %rax, %rdi
callq 0x31d0
movl 0x1e8(%r14), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
jmp 0x14691
movq %r12, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
movb $0x1, %al
movl %eax, -0x30(%rbp)
jmp 0x146be
leaq -0x60(%rbp), %rsi
movb $0x0, (%rsi)
pushq $0x3
popq %rcx
movq %r14, %rdi
movq %r15, %rdx
callq 0x1496c
movq 0x129c9(%rip), %r14     # 0x26ff0
movq %r14, %rdi
callq 0x30d0
leaq 0x9c1c(%rip), %rsi      # 0x1e252
movq %r14, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
leaq 0x6dea(%rip), %rsi      # 0x1b43f
movq %r14, %rdi
callq 0x31d0
movq %rax, %r14
leaq -0x60(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xced6
movq %r14, %rdi
movq %r12, %rsi
callq 0x3190
leaq 0x9c87(%rip), %rsi      # 0x1e308
movq %rax, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
leaq -0x60(%rbp), %rdi
callq 0x30c0
movl $0x2625a0, %edi         # imm = 0x2625A0
callq 0x32a0
jmp 0x1493a
movl %ebx, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x147cc
pushq $0x2
popq %rax
movl %eax, -0x2c(%rbp)
xorl %ecx, %ecx
movl %ecx, %r13d
movq 0xd8(%r14), %rax
movq 0xe0(%r14), %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %r13, %rbx
jbe 0x14703
movq (%rax,%r13,8), %rsi
movq %r15, %rdx
callq 0x171a2
leal 0x1(%r13), %ecx
testb %al, %al
je 0x146c0
movq 0xe0(%r14), %rbx
subq 0xd8(%r14), %rbx
sarq $0x3, %rbx
movq %r15, -0x38(%rbp)
xorl %ecx, %ecx
movl %ecx, %r12d
movq 0xc0(%r14), %rax
movq 0xc8(%r14), %r15
subq %rax, %r15
sarq $0x3, %r15
cmpq %r12, %r15
jbe 0x1474e
movq (%rax,%r12,8), %rsi
movq -0x38(%rbp), %rdx
callq 0x171a2
leal 0x1(%r12), %ecx
testb %al, %al
je 0x14709
movq 0xc8(%r14), %r15
subq 0xc0(%r14), %r15
sarq $0x3, %r15
xorl %ecx, %ecx
movl %ecx, %r14d
movq -0x40(%rbp), %rax
movq 0xa8(%rax), %rcx
movq 0xb0(%rax), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x1479c
movq (%rcx,%r14,8), %rsi
movq -0x38(%rbp), %rdx
callq 0x171a2
leal 0x1(%r14), %ecx
testb %al, %al
je 0x14750
movq -0x40(%rbp), %rcx
movq 0xb0(%rcx), %rax
subq 0xa8(%rcx), %rax
sarq $0x3, %rax
cmpq %r12, %r15
seta %dl
cmpq %r13, %rbx
seta %cl
cmpq %r14, %rax
seta %al
orb %dl, %cl
orb %al, %cl
cmpb $0x0, -0x30(%rbp)
je 0x147bf
testb %cl, %cl
jmp 0x148c6
movl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
xorl %ecx, %ecx
movl %ecx, %r13d
movq 0xf0(%r14), %rax
movq 0xf8(%r14), %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %r13, %rbx
jbe 0x14811
movq (%rax,%r13,8), %rsi
movq %r15, %rdx
callq 0x171f4
leal 0x1(%r13), %ecx
testb %al, %al
je 0x147ce
movq 0xf8(%r14), %rbx
subq 0xf0(%r14), %rbx
sarq $0x3, %rbx
movq %r15, -0x38(%rbp)
xorl %ecx, %ecx
movl %ecx, %r12d
movq 0x120(%r14), %rax
movq 0x128(%r14), %r15
subq %rax, %r15
sarq $0x3, %r15
cmpq %r12, %r15
jbe 0x1485c
movq (%rax,%r12,8), %rsi
movq -0x38(%rbp), %rdx
callq 0x171f4
leal 0x1(%r12), %ecx
testb %al, %al
je 0x14817
movq 0x128(%r14), %r15
subq 0x120(%r14), %r15
sarq $0x3, %r15
xorl %ecx, %ecx
movl %ecx, %r14d
movq -0x40(%rbp), %rax
movq 0x108(%rax), %rcx
movq 0x110(%rax), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x148aa
movq (%rcx,%r14,8), %rsi
movq -0x38(%rbp), %rdx
callq 0x171f4
leal 0x1(%r14), %ecx
testb %al, %al
je 0x1485e
movq -0x40(%rbp), %rcx
movq 0x110(%rcx), %rax
subq 0x108(%rcx), %rax
sarq $0x3, %rax
cmpq %r12, %r15
seta %cl
cmpq %r13, %rbx
seta %dl
cmpq %r14, %rax
seta %al
orb %cl, %dl
orb -0x30(%rbp), %dl
orb %al, %dl
testb $0x1, %dl
movl -0x2c(%rbp), %ebx
jne 0x1493a
pushq $-0x1
popq %rbx
movq -0x68(%rbp), %rax
cmpb $0x1, (%rax)
jne 0x1493a
movq 0x12712(%rip), %rdi     # 0x26ff0
callq 0x30d0
leaq 0x9a5a(%rip), %rsi      # 0x1e344
movq %rax, %rdi
callq 0x31d0
movq %rax, %r14
leaq -0x60(%rbp), %r12
movq %r12, %rdi
movq -0x38(%rbp), %rsi
callq 0xced6
movq %r14, %rdi
movq %r12, %rsi
callq 0x3190
leaq 0x9a79(%rip), %rsi      # 0x1e390
movq %rax, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
leaq -0x60(%rbp), %rdi
callq 0x30c0
movl $0x2dc6c0, %edi         # imm = 0x2DC6C0
jmp 0x1469f
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14957
jmp 0x14957
jmp 0x14957
jmp 0x14957
jmp 0x14957
jmp 0x14957
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3330
nop