// File: /workspace/github_cpp_makefile_star2_O3/XxAdi101xX[P]ChamberCrawler/Character/Character.cc
// Function: Character::doMove(Direction)
void Character::doMove(Direction direction) {
	shared_ptr<Cell> cell = (this->currentCell)->getNeighbour(direction);
	if (cell != nullptr) {
		// type of cell attempting to move to
		CellType cellType = cell->getCellType();

		// seperating cases of non movement for clarity

		// nobody can enter a Wall or Null
		if ((cellType == CellType::Wall)
			|| (cellType == CellType::Null)) {

			return;
		}

		// NPCs cannot leave their chamber
		if (!(this->isPlayer) && (cellType != CellType::FloorTile)
			&& (cellType != CellType::Stairs)) {

			return;
		}

		// nobody can walk over a potion
		if (cell->getItem() && (cell->getItem())->getItemType()
			== ItemType::Potion) {

			return;
		}

		// NPCs cannot occupy a tile if it has an item
		if (!(this->isPlayer) && cell->getItem()) {

			return;
		}

		// two characters cannot be on the same cell
		if (cell->getOccupant()) {
			return;
		}

		// otherwise move as normal

		// removes character from currentCell
		(this->getCurrentCell())->setOccupant(nullptr);

		// changes currentCell to the new one
		// setOccupant is done in setCell
		this->setCell(cell);

		// reports movement
		this->addAction(makeMsg(this->name, WORD_MOVE_PAST_TENSE,
			directionToText(direction)));

		// gets the neighbourhood
		vector<shared_ptr<Cell>> neighbourhood 
			= (this->currentCell)->getNeighbours();

		// reports all item sightings
		for (auto neighbour: neighbourhood) {
			shared_ptr<Item> item = neighbour->getItem();

			if (item != nullptr) {
				this->addAction(makeMsg(this->name, WORD_SEE_PAST_TENSE,
					itemToText(item)));
			}

		}

	}

	// if is player, and there's an item on the new cell (not potion);
	shared_ptr<Item> tempItem = currentCell->getItem();

	if (this->isPlayer && tempItem) {
		// uses the item
		// wont do anything if its a dragon hoard
		this->applyItem(tempItem);

		// remove the item from the cell (only if it isnt a dragon hoard)
		if (tempItem->getItemType() != ItemType::GoldPile 
			|| !(static_pointer_cast<GoldPile>(tempItem)->getBoundState())) {
			
			currentCell->setItem(nullptr);
		}

	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movl %esi, %ebp
movq %rdi, %rbx
movq 0x50(%rdi), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
callq 0x1504a
movq (%r14), %rdi
testq %rdi, %rdi
je 0x17204
callq 0x1501a
testl %eax, %eax
je 0x172ef
cmpl $0x5, %eax
je 0x172ef
cmpb $0x0, 0x49(%rbx)
jne 0x16d91
cmpl $0x4, %eax
je 0x16d91
cmpl $0x1, %eax
jne 0x172ef
movq 0x28(%rsp), %rsi
movq %rsp, %rdi
callq 0x1501e
cmpq $0x0, (%rsp)
je 0x16dd6
movq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x1501e
movq 0x18(%rsp), %rdi
callq 0x1a33e
cmpl $0x1, %eax
sete %r14b
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x16dd9
callq 0x1235a
jmp 0x16dd9
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x16de8
callq 0x1235a
testb %r14b, %r14b
jne 0x172ef
cmpb $0x0, 0x49(%rbx)
jne 0x16e20
movq 0x28(%rsp), %rsi
movq %rsp, %rdi
callq 0x1501e
movq (%rsp), %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x16e17
callq 0x1235a
testq %r14, %r14
jne 0x172ef
movq 0x28(%rsp), %rsi
movq %rsp, %rdi
callq 0x15190
movq (%rsp), %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x16e40
callq 0x1235a
testq %r14, %r14
jne 0x172ef
movq 0x50(%rbx), %rdi
movq 0x58(%rbx), %r14
testq %r14, %r14
je 0x16e6d
movq 0x1214b(%rip), %rax     # 0x28fa8
cmpb $0x0, (%rax)
je 0x16e68
incl 0x8(%r14)
jmp 0x16e6d
lock
incl 0x8(%r14)
xorps %xmm0, %xmm0
leaq 0x160(%rsp), %rsi
movaps %xmm0, (%rsi)
callq 0x14ff8
movq 0x168(%rsp), %rdi
testq %rdi, %rdi
je 0x16e92
callq 0x1235a
testq %r14, %r14
je 0x16e9f
movq %r14, %rdi
callq 0x1235a
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x16ed0
movq 0x120e6(%rip), %rcx     # 0x28fa8
cmpb $0x0, (%rcx)
je 0x16ecc
incl 0x8(%rax)
jmp 0x16ed0
lock
incl 0x8(%rax)
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x17568
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x16eef
callq 0x1235a
leaq 0x120(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rdi
callq 0x1942c
leaq 0x100(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x143d4(%rip), %rsi     # 0x2b300
movq 0x143d5(%rip), %rdx     # 0x2b308
addq %rsi, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x1942c
leaq 0x178(%rsp), %rdi
movl %ebp, %esi
callq 0x1a9e4
leaq 0x130(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0x178(%rsp), %rcx
callq 0x1a5ac
leaq 0x68(%rbx), %rdi
movq 0x130(%rsp), %rsi
movq 0x138(%rsp), %rdx
movq %rdi, 0xc8(%rsp)
callq 0x5100
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16fb9
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x5280
leaq 0x188(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16fda
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0xf0(%rsp), %rdi
cmpq %r15, %rdi
je 0x16ff7
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x110(%rsp), %rdi
cmpq %r14, %rdi
je 0x17014
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x50(%rbx), %rsi
movq %rsp, %rdi
callq 0x1517e
movq (%rsp), %r15
movq 0x8(%rsp), %r13
cmpq %r13, %r15
je 0x171fc
leaq 0x88(%rsp), %rbp
leaq 0xd0(%rsp), %r12
movq (%r15), %rsi
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x17065
movq 0x11f53(%rip), %rax     # 0x28fa8
cmpb $0x0, (%rax)
je 0x17060
incl 0x8(%r14)
jmp 0x17065
lock
incl 0x8(%r14)
leaq 0x18(%rsp), %rdi
callq 0x1501e
cmpq $0x0, 0x18(%rsp)
je 0x171d3
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x1942c
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x14269(%rip), %rsi     # 0x2b320
movq 0x1426a(%rip), %rdx     # 0x2b328
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x1942c
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x48(%rsp)
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x170f7
movq 0x11ebf(%rip), %rcx     # 0x28fa8
cmpb $0x0, (%rcx)
je 0x170f3
incl 0x8(%rax)
jmp 0x170f7
lock
incl 0x8(%rax)
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x1abd1
leaq 0xa8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x1a5ac
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
movq 0xc8(%rsp), %rdi
callq 0x5100
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x1715e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x17183
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x17192
callq 0x1235a
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x171b7
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x171d3
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x171e2
callq 0x1235a
testq %r14, %r14
je 0x171ef
movq %r14, %rdi
callq 0x1235a
addq $0x10, %r15
cmpq %r13, %r15
jne 0x17042
movq %rsp, %rdi
callq 0x12220
movq 0x50(%rbx), %rsi
movq %rsp, %rdi
callq 0x1501e
cmpb $0x1, 0x49(%rbx)
jne 0x172e0
movq (%rsp), %rax
testq %rax, %rax
je 0x172e0
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x17250
movq 0x11d66(%rip), %rcx     # 0x28fa8
cmpb $0x0, (%rcx)
je 0x1724c
incl 0x8(%rax)
jmp 0x17250
lock
incl 0x8(%rax)
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x175e4
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1726c
callq 0x1235a
movq (%rsp), %rdi
callq 0x1a33e
testl %eax, %eax
jne 0x172b7
movq (%rsp), %rdi
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x1729e
movq 0x11d1a(%rip), %rax     # 0x28fa8
cmpb $0x0, (%rax)
je 0x17299
incl 0x8(%r14)
jmp 0x1729e
lock
incl 0x8(%r14)
callq 0x1a31c
movl %eax, %ebp
testq %r14, %r14
je 0x172b2
movq %r14, %rdi
callq 0x1235a
testb %bpl, %bpl
jne 0x172e0
movq 0x50(%rbx), %rdi
xorps %xmm0, %xmm0
leaq 0x150(%rsp), %rsi
movaps %xmm0, (%rsi)
callq 0x14fd6
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0x172e0
callq 0x1235a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x172ef
callq 0x1235a
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x172fe
callq 0x1235a
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17521
movq %rax, %rbx
leaq 0x140(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1733e
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x5280
jmp 0x1733e
movq %rax, %rbx
leaq 0x188(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17364
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5280
jmp 0x17364
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r15, %rdi
je 0x17386
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x5280
jmp 0x17386
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %r14, %rdi
je 0x17524
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x5280
jmp 0x17524
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0x17428
movq %rax, %rbx
movq 0x168(%rsp), %rdi
testq %rdi, %rdi
je 0x173ce
callq 0x1235a
testq %r14, %r14
je 0x17524
movq %r14, %rdi
jmp 0x17431
jmp 0x17521
movq %rax, %rbx
testq %r14, %r14
je 0x17423
movq %r14, %rdi
jmp 0x1741e
jmp 0x17521
movq %rax, %rbx
movq 0x158(%rsp), %rdi
jmp 0x17419
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x17419
jmp 0x1740c
movq %rax, %rbx
jmp 0x17423
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x17423
callq 0x1235a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x17524
callq 0x1235a
jmp 0x17524
jmp 0x17521
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x1747f
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x5280
jmp 0x1747f
movq %rax, %rbx
jmp 0x174f4
movq %rax, %rbx
jmp 0x174d8
movq %rax, %rbx
jmp 0x174a4
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x174a4
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x174b3
callq 0x1235a
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x174d8
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x174f4
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5280
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1750a
callq 0x1235a
jmp 0x1750a
jmp 0x17521
movq %rax, %rbx
testq %r14, %r14
je 0x17517
movq %r14, %rdi
callq 0x1235a
movq %rsp, %rdi
callq 0x12220
jmp 0x17524
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x17533
callq 0x1235a
movq %rbx, %rdi
callq 0x53e0
nop