// File: sagardoshi[P]NegotiationsEncounter/src/Negotiator.cpp
// Function: Negotiator::reactToOffer(Inventory*, float)
bool Negotiator::reactToOffer(Inventory* table, float keyValue) {
    map<string, int>::iterator it;
    float sum = 0.0, response = 0.0;

    string item = "";
    int amount = 0;

    // Iterate through items on the table
    for (it = table->inventory.begin(); it != table->inventory.end(); it++) {
        item = it->first;
        amount = it->second;

        // Get negotiator's preferences * base market value * quantity
        if (amount > 0) sum += prefs[item] * economy[item] * amount;
    }

    // Turn that sum into a ratio of the value of free passage for this level
    generosityOfOffer = sum / keyValue;

    // If player offers more than the key's value, automatic acceptance
    if (generosityOfOffer >= 1) return true;
    // If player offers less than half the key's value, automatic rejection
    else if (generosityOfOffer <= 0.5) return false;
    // Offers 50%-100% apply randomness and negotiator's personality
    else {
        // See asterisked comment at bottom of file for method
        response = (amiability * getRandWeight()) + generosityOfOffer;

        if (response > 1) return true;
        else return false;
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8740
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x3520
movq -0x90(%rbp), %rdx
leaq 0x57e0(%rip), %rsi      # 0x1c3c8
leaq -0x50(%rbp), %rdi
callq 0x3b80
jmp 0x16bf3
leaq -0x51(%rbp), %rdi
callq 0x3350
movl $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0x8760
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0x87c0
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x8790
testb $0x1, %al
jne 0x16c43
jmp 0x16d3d
leaq -0x28(%rbp), %rdi
callq 0x87f0
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x3050
jmp 0x16c5a
leaq -0x28(%rbp), %rdi
callq 0x87f0
movl 0x20(%rax), %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
jle 0x16d27
movq -0x98(%rbp), %rdi
addq $0x90, %rdi
leaq -0x50(%rbp), %rsi
callq 0x17dc0
movq %rax, -0xa0(%rbp)
jmp 0x16c93
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0xac(%rbp)
addq $0x8, %rdi
leaq -0x50(%rbp), %rsi
callq 0x8890
movq %rax, -0xa8(%rbp)
jmp 0x16cc3
movss -0xac(%rbp), %xmm0
movq -0xa8(%rbp), %rax
cvtsi2ssl (%rax), %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0x68(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
jmp 0x16d27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x3350
jmp 0x16e4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3200
jmp 0x16e4b
jmp 0x16d29
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x8810
movq %rax, -0x80(%rbp)
jmp 0x16c1c
movq -0x98(%rbp), %rax
movss -0x2c(%rbp), %xmm0
divss -0x1c(%rbp), %xmm0
movss %xmm0, 0x8c(%rax)
movss 0x8c(%rax), %xmm0
movss 0x60ae(%rip), %xmm1     # 0x1ce14
ucomiss %xmm1, %xmm0
jb 0x16d7e
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x16e34
movq -0x98(%rbp), %rax
movss 0x8c(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6087(%rip), %xmm0     # 0x1ce20
ucomisd %xmm1, %xmm0
jb 0x16db2
movb $0x0, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x16e34
movq -0x98(%rbp), %rdi
movss 0x88(%rdi), %xmm0
movss %xmm0, -0xb4(%rbp)
callq 0x16b10
movss %xmm0, -0xb0(%rbp)
jmp 0x16dd8
movss -0xb0(%rbp), %xmm2
movss -0xb4(%rbp), %xmm0
movq -0x98(%rbp), %rax
movss 0x8c(%rax), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
movss 0x6003(%rip), %xmm1     # 0x1ce14
ucomiss %xmm1, %xmm0
jbe 0x16e26
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x16e34
movb $0x0, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3200
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x3510
nopw %cs:(%rax,%rax)