// File: MichaelXanth[P]RPG_Game/Market/Market.cpp
// Function: Market::AddLightingSpells(int const&)
void Market::AddLightingSpells(const int& num)
{
    string spellName;
    LightingSpell* tmpLightingSpell;

    for (int i = 0; i < num; i++)
    {
        unsigned int level;
        int tmpMinDamage;
        int tmpMaxDamage;

        if ( ((double)rand() / RAND_MAX) < 0.7 )
            level = rand() % 30 + 1;
        else
            level = rand() % 70 + 31;

        spellName = name.lightingSpellsNames[rand() % name.lightingSpellsNames.size()];

        do {
            tmpMinDamage = ((rand() % 2) + 2) * level;
            tmpMaxDamage = ((rand() % 4) + 2) * level;
        } while(tmpMinDamage == tmpMaxDamage);

        if (tmpMaxDamage < tmpMinDamage) {
            int temp     = tmpMinDamage;
            tmpMinDamage = tmpMaxDamage;
            tmpMaxDamage = temp;
        }

        tmpLightingSpell = new LightingSpell(spellName , ((rand() % 2) + 3) * level, (rand() % 4) + 1 , level, tmpMinDamage , tmpMaxDamage,
                                             ((rand() % 4) + 1) * level , (unsigned int)((rand() % 6) + 1) * ((level / 25) + 1));

        lightingSpellsArray.push_back(tmpLightingSpell);

        if (minSpellPrice > tmpLightingSpell->GetPrice())
            minSpellPrice = tmpLightingSpell->GetPrice();
    }

    if (mostItems < lightingSpellsArray.size())
        mostItems = lightingSpellsArray.size();

    if (minPrice > minSpellPrice)
        minPrice = minSpellPrice;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4380
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2f9fb
callq 0x40a0
cvtsi2sd %eax, %xmm1
movsd 0xdb15(%rip), %xmm0     # 0x3d260
divsd %xmm0, %xmm1
movsd 0xc8b9(%rip), %xmm0     # 0x3c010
ucomisd %xmm1, %xmm0
jbe 0x2f772
callq 0x40a0
movl $0x1e, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x40(%rbp)
jmp 0x2f785
callq 0x40a0
movl $0x46, %ecx
cltd
idivl %ecx
addl $0x1f, %edx
movl %edx, -0x40(%rbp)
movq -0x78(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x88(%rbp)
callq 0x40a0
movq -0x88(%rbp), %rdi
cltq
movq %rax, -0x80(%rbp)
callq 0x5010
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movq -0x80(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
callq 0x4ff0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x4050
jmp 0x2f7d6
jmp 0x2f7d8
callq 0x40a0
movl $0x2, %ecx
cltd
idivl %ecx
movl %edx, %eax
addl $0x2, %eax
imull -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
callq 0x40a0
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, %eax
addl $0x2, %eax
imull -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x2f7d8
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x2f83f
movl -0x44(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x2f83f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2fa78
movl $0x48, %edi
callq 0x4270
movq %rax, -0x90(%rbp)
jmp 0x2f852
callq 0x40a0
movl %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
movl %ecx, %edx
addl %eax, %edx
andl $-0x2, %edx
movl %ecx, %eax
negl %edx
movl %edx, %ecx
leal 0x3(%rax,%rcx), %eax
movl -0x40(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0x5c(%rbp)
callq 0x40a0
movl %eax, %edx
movl %edx, %ecx
addl $0x3, %ecx
testl %edx, %edx
movl %edx, %eax
cmovsl %ecx, %eax
andl $-0x4, %eax
negl %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x68(%rbp)
callq 0x40a0
movl %eax, %edx
movl %edx, %ecx
addl $0x3, %ecx
testl %edx, %edx
movl %edx, %eax
cmovsl %ecx, %eax
andl $-0x4, %eax
negl %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx), %eax
movl -0x40(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0x6c(%rbp)
callq 0x40a0
movq -0x90(%rbp), %rdi
movl %eax, %ecx
movslq %ecx, %rax
imulq $0x2aaaaaab, %rax, %rdx # imm = 0x2AAAAAAB
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
addl %edx, %edx
movl %edx, %eax
leal (%rax,%rax,2), %edx
movl %ecx, %eax
negl %edx
movl %edx, %ecx
leal 0x1(%rax,%rcx), %eax
movl -0x40(%rbp), %ecx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
shrq $0x23, %rcx
incl %ecx
imull %ecx, %eax
movl %eax, -0x70(%rbp)
movq %rsp, %rax
leaq -0x70(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq -0x6c(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x68(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x30(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x64(%rbp), %r9
callq 0x3b400
jmp 0x2f951
movq -0x78(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, -0x38(%rbp)
addq $0xa8, %rdi
leaq -0x38(%rbp), %rsi
callq 0x26fc0
jmp 0x2f972
movq -0x78(%rbp), %rax
movl 0x1e0(%rax), %eax
movl %eax, -0x98(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, -0x94(%rbp)
jmp 0x2f997
movl -0x98(%rbp), %eax
movl -0x94(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x2f9eb
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, -0x9c(%rbp)
jmp 0x2f9bc
movq -0x78(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl %ecx, 0x1e0(%rax)
jmp 0x2f9eb
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x4240
jmp 0x2fa78
jmp 0x2f9ed
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f72b
movq -0x78(%rbp), %rdi
movl 0x1ec(%rdi), %eax
movq %rax, -0xa8(%rbp)
addq $0xa8, %rdi
callq 0x26e20
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2fa44
movq -0x78(%rbp), %rdi
addq $0xa8, %rdi
callq 0x26e20
movq %rax, %rcx
movq -0x78(%rbp), %rax
movl %ecx, 0x1ec(%rax)
movq -0x78(%rbp), %rcx
movl 0x1e8(%rcx), %eax
cmpl 0x1e0(%rcx), %eax
jbe 0x2fa66
movq -0x78(%rbp), %rax
movl 0x1e0(%rax), %ecx
movl %ecx, 0x1e8(%rax)
leaq -0x30(%rbp), %rdi
callq 0x4160
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x4160
movq -0x50(%rbp), %rdi
callq 0x4440
nopw (%rax,%rax)