// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, (%rsp)
movq %rdi, %rbx
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6fde
leaq 0x4c94(%rip), %rsi      # 0xcb11
leaq 0xc8(%rsp), %rdi
movq %r14, %rdx
callq 0x8472
leaq 0x68(%rsp), %rdi
callq 0x3130
leaq 0x4c8d(%rip), %rsi      # 0xcb2b
leaq 0x68(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x3860
leaq 0x4c9a(%rip), %rsi      # 0xcb51
leaq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x3860
leaq 0x44e8(%rip), %rsi      # 0xc3b8
leaq 0x48(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x3860
leaq 0x44cf(%rip), %rsi      # 0xc3b8
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3860
leaq 0x44b6(%rip), %rsi      # 0xc3b8
leaq 0x8(%rsp), %rdi
leaq 0x148(%rsp), %rdx
callq 0x3860
movb $0x1, %r14b
leaq 0x1a8(%rsp), %r12
leaq 0xa8(%rsp), %r15
movb $0x1, %bpl
testb $0x1, %r14b
je 0x7f76
callq 0x7204
leaq 0x188(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x32b0
leaq 0x188(%rsp), %r14
movq %r14, %rsi
callq 0x727c
movq %r14, %rdi
callq 0x3130
cmpb $0x1, (%rbx)
jne 0x7faf
callq 0x76f8
leaq 0x88(%rsp), %rsi
jmp 0x7fbc
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3170
testb $0x1, %bpl
je 0x7f98
movb $0x1, %bpl
movq %rbx, %rdi
callq 0x79bc
jmp 0x7fc9
movb $0x1, %bpl
leaq 0x48(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3170
jmp 0x7fc9
movq %rbx, %rdi
callq 0x79bc
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x3170
xorl %r14d, %r14d
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x32b0
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
movq %r12, %rcx
callq 0x7522
movq %r12, %rdi
callq 0x3130
callq 0x7204
testb $0x1, %r14b
jne 0x8029
leaq 0x168(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x32b0
leaq 0x168(%rsp), %r13
movq %r13, %rsi
callq 0x727c
movq %r13, %rdi
callq 0x3130
movq %r15, %rdi
leaq 0x435d(%rip), %rsi      # 0xc390
callq 0x5c90
movl %eax, %r13d
testb %al, %al
jne 0x8303
movq %r15, %rdi
leaq 0x4b2e(%rip), %rsi      # 0xcb7b
callq 0x5c90
testb %al, %al
je 0x8062
xorl %ebp, %ebp
callq 0x76f8
jmp 0x7f2a
movq %r15, %rdi
leaq 0x4b18(%rip), %rsi      # 0xcb84
callq 0x5c90
testb %al, %al
je 0x8081
xorl %ebp, %ebp
callq 0x789e
jmp 0x7f2a
movq %r15, %rdi
leaq 0x4afe(%rip), %rsi      # 0xcb89
callq 0x5c90
testb %al, %al
je 0x80a3
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x75e8
jmp 0x7f2a
movq %r15, %rdi
leaq 0x430b(%rip), %rsi      # 0xc3b8
callq 0x5c90
testb %al, %al
jne 0x7f2a
movq %r15, %rdi
leaq 0x4acb(%rip), %rsi      # 0xcb8f
callq 0x5c90
testb %al, %al
jne 0x7f2a
movq %r15, %rdi
leaq 0x4ab9(%rip), %rsi      # 0xcb94
callq 0x5c90
testb %al, %al
jne 0x836e
movq %r15, %rdi
leaq 0x4aa8(%rip), %rsi      # 0xcb9a
callq 0x5c90
testb %al, %al
jne 0x8379
movq %r15, %rdi
leaq 0x4a99(%rip), %rsi      # 0xcba2
callq 0x5c90
testb %al, %al
jne 0x8125
movq %r15, %rdi
leaq 0x4a8e(%rip), %rsi      # 0xcbaa
callq 0x5c90
testb %al, %al
je 0x814c
movq 0x20(%rbx), %rdi
callq 0x8b94
movss %xmm0, 0x2c(%rbx)
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x79dc
testb %al, %al
je 0x7f2a
jmp 0x8384
movq %r15, %rdi
leaq 0x4a5d(%rip), %rsi      # 0xcbb3
callq 0x5c90
testb %al, %al
je 0x8198
movq 0x20(%rbx), %rdi
callq 0x8b48
testb %al, %al
leaq 0x4a7e(%rip), %rsi      # 0xcbef
leaq 0x4a42(%rip), %rax      # 0xcbba
cmovneq %rax, %rsi
leaq 0x8(%rsp), %rdi
callq 0x33c0
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq 0xbd84
jmp 0x7f2a
movq 0x10(%rbx), %r13
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x32b0
movq %r13, %rdi
leaq 0x108(%rsp), %rsi
callq 0x886a
movl %eax, %r13d
leaq 0x108(%rsp), %rdi
callq 0x3130
testb %r13b, %r13b
je 0x8299
movq 0x10(%rbx), %r13
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x32b0
movq %r13, %rdi
leaq 0xe8(%rsp), %rsi
callq 0x8b82
movl %eax, %r13d
leaq 0xe8(%rsp), %rdi
callq 0x3130
testb %r13b, %r13b
je 0x82af
leaq 0x28(%rsp), %rdi
leaq 0x49fc(%rip), %rsi      # 0xcc1a
movq %r15, %rdx
callq 0x5c1a
leaq 0x148(%rsp), %r13
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x49ed(%rip), %rdx      # 0xcc2a
callq 0x5a9a
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x3270
movq %r13, %rdi
callq 0x3130
leaq 0x28(%rsp), %rdi
callq 0x3130
movq 0x10(%rbx), %r13
leaq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0x32b0
movq 0x20(%rbx), %rdx
movq %r13, %rdi
leaq 0x128(%rsp), %r13
movq %r13, %rsi
callq 0xbd56
movq %r13, %rdi
callq 0x3130
jmp 0x7f2a
leaq 0x8(%rsp), %rdi
leaq 0x49af(%rip), %rsi      # 0xcc54
callq 0x33c0
jmp 0x7f2a
leaq 0x28(%rsp), %rdi
leaq 0x4980(%rip), %rsi      # 0xcc3b
movq %r15, %rdx
callq 0x5c1a
leaq 0x148(%rsp), %r13
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x496e(%rip), %rdx      # 0xcc48
callq 0x5a9a
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x3270
movq %r13, %rdi
callq 0x3130
leaq 0x28(%rsp), %rdi
callq 0x3130
jmp 0x7f2a
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq 0xbd84
xorb $0x1, %r13b
leaq 0x8(%rsp), %rdi
callq 0x3130
leaq 0xa8(%rsp), %rdi
callq 0x3130
leaq 0x48(%rsp), %rdi
callq 0x3130
leaq 0x88(%rsp), %rdi
callq 0x3130
leaq 0x68(%rsp), %rdi
callq 0x3130
leaq 0xc8(%rsp), %rdi
callq 0x3130
movl %r13d, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movb $0x1, (%rax)
movb $0x1, %al
jmp 0x838a
movq (%rsp), %rax
movb $0x0, (%rax)
xorl %eax, %eax
jmp 0x838a
movq (%rsp), %rax
movb (%rax), %al
movzbl %al, %esi
movq %rbx, %rdi
callq 0x7d2c
jmp 0x8310
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x841b
jmp 0x83ab
jmp 0x8422
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x841b
jmp 0x8422
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x841b
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
jmp 0x841b
jmp 0x8422
movq %rax, %rbx
jmp 0x842f
movq %rax, %rbx
jmp 0x843c
movq %rax, %rbx
jmp 0x8446
movq %rax, %rbx
jmp 0x8453
movq %rax, %rbx
jmp 0x845d
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x8465
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
jmp 0x841b
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
jmp 0x841b
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x3130
jmp 0x8425
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3130
leaq 0xa8(%rsp), %rdi
callq 0x3130
leaq 0x48(%rsp), %rdi
callq 0x3130
leaq 0x88(%rsp), %rdi
callq 0x3130
leaq 0x68(%rsp), %rdi
callq 0x3130
leaq 0xc8(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3380