// File: 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
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x268(%rbp)
addq $0x50, %rdi
callq 0x19df0
movq %rax, %rsi
movl -0xc(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x2cca0
leaq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x318b0
testb $0x1, %al
jne 0x2f64b
jmp 0x2fd0e
leaq -0x20(%rbp), %rdi
callq 0x19df0
movq %rax, %rdi
callq 0x2cc40
movl %eax, -0x26c(%rbp)
jmp 0x2f664
movl -0x26c(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x2f679
cmpl $0x5, -0x24(%rbp)
jne 0x2f696
movl $0x1, -0x38(%rbp)
jmp 0x2ff10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2ff2e
movq -0x268(%rbp), %rax
testb $0x1, 0x49(%rax)
jne 0x2f6bb
cmpl $0x1, -0x24(%rbp)
je 0x2f6bb
cmpl $0x4, -0x24(%rbp)
je 0x2f6bb
movl $0x1, -0x38(%rbp)
jmp 0x2ff10
leaq -0x20(%rbp), %rdi
callq 0x19df0
movq %rax, %rsi
movb $0x0, -0x59(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2cc70
jmp 0x2f6d6
leaq -0x48(%rbp), %rdi
callq 0x19dd0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x26d(%rbp)
jne 0x2f6f0
jmp 0x2f736
leaq -0x20(%rbp), %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x2cc70
jmp 0x2f707
movb $0x1, -0x59(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2dc20
movq %rax, %rdi
callq 0x33d60
movl %eax, -0x274(%rbp)
jmp 0x2f724
movl -0x274(%rbp), %eax
cmpl $0x1, %eax
sete %al
movb %al, -0x26d(%rbp)
movb -0x26d(%rbp), %al
movb %al, -0x275(%rbp)
testb $0x1, -0x59(%rbp)
jne 0x2f74a
jmp 0x2f753
leaq -0x58(%rbp), %rdi
callq 0x19e40
leaq -0x48(%rbp), %rdi
callq 0x19e40
movb -0x275(%rbp), %al
testb $0x1, %al
jne 0x2f768
jmp 0x2f7af
movl $0x1, -0x38(%rbp)
jmp 0x2ff10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2f7a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
testb $0x1, -0x59(%rbp)
jne 0x2f796
jmp 0x2f79f
leaq -0x58(%rbp), %rdi
callq 0x19e40
jmp 0x2f7a1
leaq -0x48(%rbp), %rdi
callq 0x19e40
jmp 0x2ff2e
movq -0x268(%rbp), %rax
movb 0x49(%rax), %cl
movb $0x0, -0x71(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x276(%rbp)
jne 0x2f7f4
leaq -0x20(%rbp), %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x2cc70
jmp 0x2f7e1
movb $0x1, -0x71(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x19dd0
movb %al, -0x276(%rbp)
movb -0x276(%rbp), %al
movb %al, -0x277(%rbp)
testb $0x1, -0x71(%rbp)
jne 0x2f808
jmp 0x2f811
leaq -0x70(%rbp), %rdi
callq 0x19e40
movb -0x277(%rbp), %al
testb $0x1, %al
jne 0x2f81d
jmp 0x2f829
movl $0x1, -0x38(%rbp)
jmp 0x2ff10
leaq -0x20(%rbp), %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x2cf30
jmp 0x2f843
leaq -0x88(%rbp), %rdi
callq 0x19780
movb %al, -0x278(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x19530
movb -0x278(%rbp), %al
testb $0x1, %al
jne 0x2f86d
jmp 0x2f879
movl $0x1, -0x38(%rbp)
jmp 0x2ff10
movq -0x268(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x2ff40
jmp 0x2f88e
leaq -0x98(%rbp), %rdi
callq 0x19df0
movq %rax, -0x288(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x194e0
movq -0x288(%rbp), %rdi
movq -0x280(%rbp), %rsi
callq 0x2cc10
jmp 0x2f8cd
leaq -0xa8(%rbp), %rdi
callq 0x19530
leaq -0x98(%rbp), %rdi
callq 0x199a0
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x290(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x19e60
movq -0x268(%rbp), %rdi
movq -0x290(%rbp), %rsi
callq 0x2ff70
jmp 0x2f911
leaq -0xb8(%rbp), %rdi
callq 0x199a0
movq -0x268(%rbp), %rsi
addq $0x88, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6160
jmp 0x2f939
leaq 0x39a98(%rip), %rsi     # 0x693d8
leaq -0x118(%rbp), %rdi
callq 0x6160
jmp 0x2f94e
movl -0xc(%rbp), %esi
leaq -0x138(%rbp), %rdi
callq 0x34630
jmp 0x2f95f
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x118(%rbp), %rdx
leaq -0x138(%rbp), %rcx
callq 0x343f0
jmp 0x2f982
movq -0x268(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2eb60
jmp 0x2f997
leaq -0xd8(%rbp), %rdi
callq 0x65e8
leaq -0x138(%rbp), %rdi
callq 0x65e8
leaq -0x118(%rbp), %rdi
callq 0x65e8
leaq -0xf8(%rbp), %rdi
callq 0x65e8
movq -0x268(%rbp), %rdi
addq $0x50, %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
callq 0x2cf00
jmp 0x2f9e8
leaq -0x150(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
callq 0x1a400
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rdi
callq 0x1a430
movq %rax, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x1a460
testb $0x1, %al
jne 0x2fa38
jmp 0x2fd02
leaq -0x160(%rbp), %rdi
callq 0x1a4a0
movq %rax, %rsi
leaq -0x178(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x19e60
movq -0x298(%rbp), %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x188(%rbp), %rdi
callq 0x2cc70
jmp 0x2fa77
leaq -0x188(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2dbf0
testb $0x1, %al
jne 0x2fa90
jmp 0x2fcb0
movq -0x268(%rbp), %rsi
addq $0x88, %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x6160
jmp 0x2faac
leaq 0x39945(%rip), %rsi     # 0x693f8
leaq -0x1e8(%rbp), %rdi
callq 0x6160
jmp 0x2fac1
leaq -0x218(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
leaq -0x188(%rbp), %rsi
callq 0x19e10
movq -0x2a0(%rbp), %rsi
leaq -0x208(%rbp), %rdi
callq 0x34870
jmp 0x2faf0
leaq -0x1a8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
leaq -0x208(%rbp), %rcx
callq 0x343f0
jmp 0x2fb13
movq -0x268(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x2eb60
jmp 0x2fb28
leaq -0x1a8(%rbp), %rdi
callq 0x65e8
leaq -0x208(%rbp), %rdi
callq 0x65e8
leaq -0x218(%rbp), %rdi
callq 0x19e40
leaq -0x1e8(%rbp), %rdi
callq 0x65e8
leaq -0x1c8(%rbp), %rdi
callq 0x65e8
jmp 0x2fcb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x19530
leaq -0x98(%rbp), %rdi
callq 0x199a0
jmp 0x2ff2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x199a0
jmp 0x2ff2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fc09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fbfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fbf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x65e8
leaq -0x138(%rbp), %rdi
callq 0x65e8
leaq -0x118(%rbp), %rdi
callq 0x65e8
leaq -0xf8(%rbp), %rdi
callq 0x65e8
jmp 0x2ff2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fcd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fca2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fc8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2fc7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x65e8
leaq -0x208(%rbp), %rdi
callq 0x65e8
leaq -0x218(%rbp), %rdi
callq 0x19e40
leaq -0x1e8(%rbp), %rdi
callq 0x65e8
leaq -0x1c8(%rbp), %rdi
callq 0x65e8
jmp 0x2fcd9
leaq -0x188(%rbp), %rdi
callq 0x19e40
leaq -0x178(%rbp), %rdi
callq 0x199a0
leaq -0x160(%rbp), %rdi
callq 0x1a4e0
jmp 0x2fa1c
leaq -0x188(%rbp), %rdi
callq 0x19e40
leaq -0x178(%rbp), %rdi
callq 0x199a0
leaq -0x150(%rbp), %rdi
callq 0x1a2f0
jmp 0x2ff2e
leaq -0x150(%rbp), %rdi
callq 0x1a2f0
movq -0x268(%rbp), %rdi
addq $0x50, %rdi
callq 0x19df0
movq %rax, %rsi
leaq -0x228(%rbp), %rdi
callq 0x2cc70
jmp 0x2fd2f
movq -0x268(%rbp), %rax
testb $0x1, 0x49(%rax)
je 0x2fefd
leaq -0x228(%rbp), %rdi
callq 0x19dd0
testb $0x1, %al
jne 0x2fd55
jmp 0x2fefd
leaq -0x238(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
leaq -0x228(%rbp), %rsi
callq 0x19e10
movq -0x268(%rbp), %rdi
movq -0x2a8(%rbp), %rsi
callq 0x30010
jmp 0x2fd84
leaq -0x238(%rbp), %rdi
callq 0x19e40
leaq -0x228(%rbp), %rdi
callq 0x2dc20
movq %rax, %rdi
movb $0x0, -0x249(%rbp)
callq 0x33d60
movl %eax, -0x2ac(%rbp)
jmp 0x2fdb3
movl -0x2ac(%rbp), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x2ad(%rbp)
jne 0x2fe11
leaq -0x248(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
leaq -0x228(%rbp), %rsi
callq 0x318e0
movq -0x2b8(%rbp), %rdi
movb $0x1, -0x249(%rbp)
callq 0x31930
movq %rax, %rdi
callq 0x33cd0
movb %al, -0x2ae(%rbp)
jmp 0x2fe03
movb -0x2ae(%rbp), %al
xorb $-0x1, %al
movb %al, -0x2ad(%rbp)
movb -0x2ad(%rbp), %al
movb %al, -0x2b9(%rbp)
testb $0x1, -0x249(%rbp)
jne 0x2fe28
jmp 0x2fe34
leaq -0x248(%rbp), %rdi
callq 0x19be0
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x2fe43
jmp 0x2fefb
movq -0x268(%rbp), %rdi
addq $0x50, %rdi
callq 0x19df0
movq %rax, -0x2d0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x1a190
movq -0x2d0(%rbp), %rdi
movq -0x2c8(%rbp), %rsi
callq 0x2cbe0
jmp 0x2fe86
leaq -0x260(%rbp), %rdi
callq 0x19e40
jmp 0x2fefb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x19e40
jmp 0x2ff22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2ff22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
testb $0x1, -0x249(%rbp)
jne 0x2fed3
jmp 0x2fedf
leaq -0x248(%rbp), %rdi
callq 0x19be0
jmp 0x2ff22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x19e40
jmp 0x2ff22
jmp 0x2fefd
leaq -0x228(%rbp), %rdi
callq 0x19e40
movl $0x0, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x199a0
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x19e40
leaq -0x20(%rbp), %rdi
callq 0x199a0
movq -0x30(%rbp), %rdi
callq 0x6550