// File: sagardoshi[P]NegotiationsEncounter/src/Encounter.cpp
// Function: Encounter::runEncounter(bool&)
bool Encounter::runEncounter(bool &didWin) {
    string title = "YOU ARE NEGOTIATING WITH " + getCapsName();
    string promptWithUI = "Negotiate! (type \"help\" for the menu)";
    string promptWithoutUI = "Hit <RETURN> to see the negotiating table";
    string promptToPrint = "";

    string entry = "";
    string echo = "";
    bool firstLoop = true;
    bool uiOnScreen = true;

    while (true) {

        ////////////////////////////////////////////////////////////////////////
        // FIRST HANDLE UI AND PRINTOUTS
        ////////////////////////////////////////////////////////////////////////

        if (firstLoop) {
            firstLoop = false;
            clearScreen();                // To remove incorrect title
            printTitle(title);            // first need an immediate print

            // Special settings just for prologue's first loop
            if (isPrologue) {
                printStrategy();          // Just on firstLoop
                promptToPrint = promptWithoutUI;
            } else {
                printUI();                // After prologue, print UI, normally
                promptToPrint = promptWithUI;
            }
        }
        else {                            // For every time apart from the first
            promptToPrint = promptWithUI; // Assume UI visible
            if (uiOnScreen) printUI();
            else {                        // If on a menu screen
                uiOnScreen = true;
                promptToPrint = promptWithoutUI;
            }
        }

        // Print prompt, take user input, and convert number to item string
        userEntry(entry, echo, promptToPrint);


        // For the next screen, clear current view and start with title of next
        clearScreen();                    // Critical in this position
        if (!firstLoop) printTitle(title);



        ////////////////////////////////////////////////////////////////////////
        // NEXT HANDLE POSSIBLE USER ENTRIES
        ////////////////////////////////////////////////////////////////////////

        ///// IMMEDIATE QUIT
        if      (entry == "quit") {
            player->takeBackOffer(table); // In case quit typed halfway through
            return false;
        }

        ///// FOR NEXT THREE, HIDE UI AND PRINT ACCORDINGLY
        else if (entry == "strategy") {
            uiOnScreen = false;
            printStrategy();
        }
        else if (entry == "help") {
            uiOnScreen = false;
            printHelp();
        }
        else if (entry == "turns") {
            uiOnScreen = false;
            printTurns();
        }

        ///// EMPTY STRING RETURNS TO DEFAULT UI VIEW
        else if (entry == "" || entry == "back") continue; // loop empty input

        ///// NEXT TWO HANDLE IMMEDIATE ENCOUNTER ENDS
        else if (entry == "super") { // Superuser access, not shown in menu
            didWin = true;
            handleEnd(didWin);
            return true;
        }
        else if (entry == "forfeit") {
            didWin = false; // don't check for encounter end; just assume loss
            handleEnd(didWin);
            return true;
        }
        else if (entry == "propose" || entry == "proposal") {
            // Save current value, in case it's encounter-ending
            offerInvValue = table->getInvValue();

            // Check if nego done, and break if so
            if (encounterIsOver(didWin)) {
                handleEnd(didWin);
                return true;
            }
        }

        ///// NEXT THREE HANDLE PLACING AND TAKING ITEMS FROM THE TABLE
        else if (entry == "cancel") {
            if (table->isEmpty()) {
                echo = "There's nothing on the table for you to take back.\n\n";
            } else echo = "You take your offer back from the table.\n\n";
            player->takeBackOffer(table);
        }
        else if (player->knowsOfItem(entry)) {
            // Finally! Item exists, and player has it
            if (player->hasItem(entry)) {
                echo = "You place your " + entry + " on the table.\n\n";
                player->placeItemOnTable(entry, table);
            // Item exists, but player doesn't currently have it in inventory
            } else echo = "You have no " + entry + " to give.\n\n";
        }
        // Erroneous entry... there is no such thing in the economy
        else echo = "You have no such thing. Try again.\n\n";
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x288(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0xedc0
movq -0x280(%rbp), %rdx
leaq 0xc335(%rip), %rsi      # 0x1cb21
leaq -0x38(%rbp), %rdi
callq 0x11340
jmp 0x107f7
leaq -0x58(%rbp), %rdi
callq 0x3200
leaq -0x89(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x3520
movq -0x290(%rbp), %rdx
leaq 0xc31a(%rip), %rsi      # 0x1cb3b
leaq -0x88(%rbp), %rdi
callq 0x3b80
jmp 0x1082f
leaq -0x89(%rbp), %rdi
callq 0x3350
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x3520
movq -0x298(%rbp), %rdx
leaq 0xc305(%rip), %rsi      # 0x1cb61
leaq -0xb0(%rbp), %rdi
callq 0x3b80
jmp 0x1086a
leaq -0xb1(%rbp), %rdi
callq 0x3350
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x3520
movq -0x2a0(%rbp), %rdx
leaq 0xbb31(%rip), %rsi      # 0x1c3c8
leaq -0xd8(%rbp), %rdi
callq 0x3b80
jmp 0x108a5
leaq -0xd9(%rbp), %rdi
callq 0x3350
leaq -0x101(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3520
movq -0x2a8(%rbp), %rdx
leaq 0xbaf6(%rip), %rsi      # 0x1c3c8
leaq -0x100(%rbp), %rdi
callq 0x3b80
jmp 0x108e0
leaq -0x101(%rbp), %rdi
callq 0x3350
leaq -0x129(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x3520
movq -0x2b0(%rbp), %rdx
leaq 0xbabb(%rip), %rsi      # 0x1c3c8
leaq -0x128(%rbp), %rdi
callq 0x3b80
jmp 0x1091b
leaq -0x129(%rbp), %rdi
callq 0x3350
movb $0x1, -0x12a(%rbp)
movb $0x1, -0x12b(%rbp)
jmp 0x10937
testb $0x1, -0x12a(%rbp)
je 0x10ac4
movq -0x288(%rbp), %rdi
movb $0x0, -0x12a(%rbp)
callq 0xf340
jmp 0x10959
leaq -0x150(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3170
jmp 0x1096b
movq -0x288(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xf410
jmp 0x10980
leaq -0x150(%rbp), %rdi
callq 0x3200
movq -0x288(%rbp), %rax
testb $0x1, (%rax)
je 0x10a9d
movq -0x288(%rbp), %rdi
callq 0xfc50
jmp 0x109aa
leaq -0xd8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3050
jmp 0x109bf
jmp 0x10ac2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3200
jmp 0x1128b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x3350
jmp 0x11282
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x3350
jmp 0x11276
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xd9(%rbp), %rdi
callq 0x3350
jmp 0x1126a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x101(%rbp), %rdi
callq 0x3350
jmp 0x1125e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x3350
jmp 0x11252
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x11246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3200
jmp 0x11246
movq -0x288(%rbp), %rdi
callq 0xffc0
jmp 0x10aab
leaq -0xd8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3050
jmp 0x10ac0
jmp 0x10ac2
jmp 0x10b12
leaq -0xd8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3050
jmp 0x10ad9
testb $0x1, -0x12b(%rbp)
je 0x10af2
movq -0x288(%rbp), %rdi
callq 0xffc0
jmp 0x10af0
jmp 0x10b10
movb $0x1, -0x12b(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3050
jmp 0x10b0e
jmp 0x10b10
jmp 0x10b12
leaq -0x170(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x3170
jmp 0x10b27
movq -0x288(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x128(%rbp), %rdx
leaq -0x170(%rbp), %rcx
callq 0xf9d0
jmp 0x10b4a
leaq -0x170(%rbp), %rdi
callq 0x3200
movq -0x288(%rbp), %rdi
callq 0xf340
jmp 0x10b64
testb $0x1, -0x12a(%rbp)
jne 0x10bdc
leaq -0x190(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3170
jmp 0x10b7f
movq -0x288(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xf410
jmp 0x10b94
leaq -0x190(%rbp), %rdi
callq 0x3200
jmp 0x10bdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3200
jmp 0x11246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3200
jmp 0x11246
leaq 0xb7bd(%rip), %rsi      # 0x1c3a0
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b1(%rbp)
jmp 0x10bf7
movb -0x2b1(%rbp), %al
testb $0x1, %al
jne 0x10c03
jmp 0x10c2c
movq -0x288(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rax), %rsi
callq 0x1b080
jmp 0x10c19
movb $0x0, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x111f3
leaq 0xbf58(%rip), %rsi      # 0x1cb8b
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b2(%rbp)
jmp 0x10c47
movb -0x2b2(%rbp), %al
testb $0x1, %al
jne 0x10c53
jmp 0x10c6d
movq -0x288(%rbp), %rdi
movb $0x0, -0x12b(%rbp)
callq 0xfc50
jmp 0x10c68
jmp 0x111ec
leaq 0xbf20(%rip), %rsi      # 0x1cb94
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b3(%rbp)
jmp 0x10c88
movb -0x2b3(%rbp), %al
testb $0x1, %al
jne 0x10c94
jmp 0x10cae
movq -0x288(%rbp), %rdi
movb $0x0, -0x12b(%rbp)
callq 0xfe50
jmp 0x10ca9
jmp 0x111ea
leaq 0xbee4(%rip), %rsi      # 0x1cb99
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b4(%rbp)
jmp 0x10cc9
movb -0x2b4(%rbp), %al
testb $0x1, %al
jne 0x10cd5
jmp 0x10cef
movq -0x288(%rbp), %rdi
movb $0x0, -0x12b(%rbp)
callq 0xfad0
jmp 0x10cea
jmp 0x111e8
leaq 0xb6d2(%rip), %rsi      # 0x1c3c8
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b5(%rbp)
jmp 0x10d0a
movb -0x2b5(%rbp), %al
testb $0x1, %al
jne 0x10d3d
jmp 0x10d16
leaq 0xbe82(%rip), %rsi      # 0x1cb9f
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b6(%rbp)
jmp 0x10d31
movb -0x2b6(%rbp), %al
testb $0x1, %al
jne 0x10d3d
jmp 0x10d42
jmp 0x10935
leaq 0xbe5b(%rip), %rsi      # 0x1cba4
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b7(%rbp)
jmp 0x10d5d
movb -0x2b7(%rbp), %al
testb $0x1, %al
jne 0x10d69
jmp 0x10d9b
movq -0x288(%rbp), %rdi
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x18(%rbp), %rax
movzbl (%rax), %esi
andl $0x1, %esi
callq 0x10580
jmp 0x10d88
movb $0x1, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x111f3
leaq 0xbe08(%rip), %rsi      # 0x1cbaa
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b8(%rbp)
jmp 0x10db6
movb -0x2b8(%rbp), %al
testb $0x1, %al
jne 0x10dc2
jmp 0x10df4
movq -0x288(%rbp), %rdi
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movzbl (%rax), %esi
andl $0x1, %esi
callq 0x10580
jmp 0x10de1
movb $0x1, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x111f3
leaq 0xbdb7(%rip), %rsi      # 0x1cbb2
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2b9(%rbp)
jmp 0x10e0f
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x10e42
jmp 0x10e1b
leaq 0xbd98(%rip), %rsi      # 0x1cbba
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2ba(%rbp)
jmp 0x10e36
movb -0x2ba(%rbp), %al
testb $0x1, %al
jne 0x10e42
jmp 0x10ebd
movq -0x288(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x12a90
movss %xmm0, -0x2c0(%rbp)
jmp 0x10e5c
movq -0x288(%rbp), %rdi
movss -0x2c0(%rbp), %xmm0
movss %xmm0, 0x2c(%rdi)
movq -0x18(%rbp), %rsi
callq 0x10000
movb %al, -0x2c1(%rbp)
jmp 0x10e81
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x10e8d
jmp 0x10eb8
movq -0x288(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl (%rax), %esi
andl $0x1, %esi
callq 0x10580
jmp 0x10ea5
movb $0x1, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x111f3
jmp 0x111e0
leaq 0xbcff(%rip), %rsi      # 0x1cbc3
leaq -0x100(%rbp), %rdi
callq 0x8a80
movb %al, -0x2c2(%rbp)
jmp 0x10ed8
movb -0x2c2(%rbp), %al
testb $0x1, %al
jne 0x10ee4
jmp 0x10f51
movq -0x288(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x12990
movb %al, -0x2c3(%rbp)
jmp 0x10efc
movb -0x2c3(%rbp), %al
testb $0x1, %al
jne 0x10f08
jmp 0x10f1f
leaq 0xbcbb(%rip), %rsi      # 0x1cbca
leaq -0x128(%rbp), %rdi
callq 0x3400
jmp 0x10f1d
jmp 0x10f36
leaq 0xbcd9(%rip), %rsi      # 0x1cbff
leaq -0x128(%rbp), %rdi
callq 0x3400
jmp 0x10f34
jmp 0x10f36
movq -0x288(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rax), %rsi
callq 0x1b080
jmp 0x10f4c
jmp 0x111de
movq -0x288(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3170
jmp 0x10f78
movq -0x2d0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x12000
movb %al, -0x2d1(%rbp)
jmp 0x10f93
leaq -0x1b8(%rbp), %rdi
callq 0x3200
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0x10fae
jmp 0x111c5
movq -0x288(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2e0(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3170
jmp 0x10fd5
movq -0x2e0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x12a60
movb %al, -0x2e1(%rbp)
jmp 0x10ff0
leaq -0x1d8(%rbp), %rdi
callq 0x3200
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x1100b
jmp 0x11141
leaq 0xbc18(%rip), %rsi      # 0x1cc2a
leaq -0x218(%rbp), %rdi
leaq -0x100(%rbp), %rdx
callq 0x8970
jmp 0x11027
leaq 0xbc0c(%rip), %rdx      # 0x1cc3a
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x8440
jmp 0x11043
leaq -0x128(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
movq %rsi, -0x2f8(%rbp)
callq 0x3390
movq -0x2f8(%rbp), %rdi
callq 0x3200
leaq -0x218(%rbp), %rdi
callq 0x3200
movq -0x288(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2f0(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3170
jmp 0x1109c
movq -0x2f0(%rbp), %rdi
movq -0x288(%rbp), %rax
movq 0x20(%rax), %rdx
leaq -0x238(%rbp), %rsi
callq 0x1b030
jmp 0x110bc
leaq -0x238(%rbp), %rdi
callq 0x3200
jmp 0x111c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3200
jmp 0x11246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3200
jmp 0x11246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x3200
jmp 0x11246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x3200
jmp 0x11246
leaq 0xbb03(%rip), %rsi      # 0x1cc4b
leaq -0x278(%rbp), %rdi
leaq -0x100(%rbp), %rdx
callq 0x8970
jmp 0x1115d
leaq 0xbaf4(%rip), %rdx      # 0x1cc58
leaq -0x258(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x8440
jmp 0x11179
leaq -0x128(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3390
leaq -0x258(%rbp), %rdi
callq 0x3200
leaq -0x278(%rbp), %rdi
callq 0x3200
jmp 0x111c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x3200
jmp 0x11246
jmp 0x111dc
leaq 0xba98(%rip), %rsi      # 0x1cc64
leaq -0x128(%rbp), %rdi
callq 0x3400
jmp 0x111da
jmp 0x111dc
jmp 0x111de
jmp 0x111e0
jmp 0x111e2
jmp 0x111e4
jmp 0x111e6
jmp 0x111e8
jmp 0x111ea
jmp 0x111ec
jmp 0x111ee
jmp 0x10935
leaq -0x128(%rbp), %rdi
callq 0x3200
leaq -0x100(%rbp), %rdi
callq 0x3200
leaq -0xd8(%rbp), %rdi
callq 0x3200
leaq -0xb0(%rbp), %rdi
callq 0x3200
leaq -0x88(%rbp), %rdi
callq 0x3200
leaq -0x38(%rbp), %rdi
callq 0x3200
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
leaq -0x128(%rbp), %rdi
callq 0x3200
leaq -0x100(%rbp), %rdi
callq 0x3200
leaq -0xd8(%rbp), %rdi
callq 0x3200
leaq -0xb0(%rbp), %rdi
callq 0x3200
leaq -0x88(%rbp), %rdi
callq 0x3200
leaq -0x38(%rbp), %rdi
callq 0x3200
movq -0x60(%rbp), %rdi
callq 0x3510
nopw %cs:(%rax,%rax)
nop