// File: /workspace/github_cpp_makefile_star2_O2/MichaelXanth[P]RPG_Game/Market/Market.cpp
// Function: Market::NewStuff(std::vector<Hero*, std::allocator<Hero*>>&)
void Market::NewStuff(vector<Hero *>& heroes)
{
    if (heroes.size() == 1)
    {
        if (heroes[0]->Living::GetLevel() < prevLevel + 2)
            return;

        prevLevel = heroes[0]->Living::GetLevel();
    
    } else {
        unsigned int averageLevel = 0;

        for (unsigned int i = 0; i < heroes.size(); i++)
            averageLevel += heroes[i]->Living::GetLevel();
        
        averageLevel /= heroes.size();

        if (averageLevel < prevLevel + 2)
            return;

        prevLevel = averageLevel;
    }

    if (rand() % prevLevel < prevLevel / 6)
        AddLightingSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddFireSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddIceSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddWeapons(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddPotions(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddArmors(rand() % 10);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
cmpq $0x8, %rdx
jne 0x14016
movq (%rax), %rdi
callq 0xcef2
movl 0x1f0(%rbx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jb 0x1419c
movq (%r14), %rax
movq (%rax), %rdi
callq 0xcef2
jmp 0x1405c
xorl %r15d, %r15d
xorl %edx, %edx
movl %edx, %r12d
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x14044
movq (%rax,%r12,8), %rdi
callq 0xcef2
addl %eax, %r15d
leal 0x1(%r12), %edx
movq (%r14), %rax
movq 0x8(%r14), %rcx
jmp 0x1401b
movl %r15d, %eax
xorl %edx, %edx
divl %ecx
movl 0x1f0(%rbx), %ecx
addl $0x2, %ecx
cmpl %eax, %ecx
ja 0x1419c
movl %eax, 0x1f0(%rbx)
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
pushq $0x6
popq %r15
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
pushq $0xa
popq %r14
cmpl %eax, %esi
jae 0x1409d
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x12f0e
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
cmpl %eax, %esi
jae 0x140d0
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x1317c
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
cmpl %eax, %esi
jae 0x14103
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x133dc
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
cmpl %eax, %esi
jae 0x14136
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x13634
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
cmpl %eax, %esi
jae 0x14169
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x13836
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r15d
cmpl %eax, %esi
jae 0x1419c
callq 0x3060
cltd
idivl %r14d
leaq -0x24(%rbp), %rsi
movl %edx, (%rsi)
movq %rbx, %rdi
callq 0x13b56
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop