// File: 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
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5ad0
cmpq $0x1, %rax
jne 0x313b8
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movq -0x38(%rbp), %rcx
movl 0x1f0(%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jae 0x31392
jmp 0x31608
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1f0(%rax)
jmp 0x31446
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x31409
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x313c6
movq -0x10(%rbp), %rdi
callq 0x5ad0
movq -0x38(%rbp), %rcx
movq %rax, %rsi
movl -0x14(%rbp), %eax
xorl %edx, %edx
divq %rsi
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl 0x1f0(%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jae 0x31439
jmp 0x31608
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x1f0(%rax)
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x44(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x44(%rbp), %edx
cmpl %eax, %edx
jae 0x31491
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x1c(%rbp)
leaq -0x1c(%rbp), %rsi
callq 0x2f700
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x48(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x48(%rbp), %edx
cmpl %eax, %edx
jae 0x314dc
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x20(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x2fa90
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x4c(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x4c(%rbp), %edx
cmpl %eax, %edx
jae 0x31527
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x24(%rbp)
leaq -0x24(%rbp), %rsi
callq 0x2fdf0
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x50(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x50(%rbp), %edx
cmpl %eax, %edx
jae 0x31572
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x30160
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x54(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x54(%rbp), %edx
cmpl %eax, %edx
jae 0x315bd
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x2c(%rbp)
leaq -0x2c(%rbp), %rsi
callq 0x30460
callq 0x40a0
movq -0x38(%rbp), %rcx
xorl %edx, %edx
divl 0x1f0(%rcx)
movq -0x38(%rbp), %rax
movl %edx, -0x58(%rbp)
movl 0x1f0(%rax), %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl -0x58(%rbp), %edx
cmpl %eax, %edx
jae 0x31608
callq 0x40a0
movq -0x38(%rbp), %rdi
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x309a0
addq $0x60, %rsp
popq %rbp
retq
nop