// File: /workspace/github_cpp_makefile_star2_O3/AngelPn[P]L5R-card_game/src/Player.cpp
// Function: Player::economyPhase()
void Player::economyPhase()
{
	char input;
	unsigned int i;

	cout << "Player: " << this->name << " is playing " << endl;
	cout << "Economy Phase ..." << endl << endl;
	this->revealProvinces(); //reveal not-destroyed provinces
	cout << "Available money : " << money << endl << endl;
	this->printProvinces(); //prints not-destroyed provinces
	this->tapHoldings(); //tap any holdings in case you need extra money

	while(money)  //while player has money and wants to
	{
		input = '0';
		i = 0;
		cout << "Available money : " << money << endl << endl;
		while (input != 'y' && input != 'n')
		{
			cout << this->name<< ", do you want buy from any provinces (y:yes / n:no) ?" << endl;
			cin >> input;
		}

		if (input == 'n')
			break; //exit economy phase

		while (i < 1 || i > provinces.size())
		{
			this->printProvinces();
			cout << this->name<< ", choose a province to buy from : (1-" << provinces.size() << ")" << endl;
			cin >> i;
		}

		if (provinces[i-1]->is_revealed() == false)
		{
			cout <<"This province is not revealed yet, purchase cancelled" << endl;
			continue;
		}

		if (provinces[i-1]->get_cost() > money)
		{
			cout << "This province cannot be afforded, purchase cancelled" << endl;
			continue;
		}

		//at this point purchase is made
		money -= provinces[i-1]->get_cost();
		cout << "Province purchase successful " << endl << endl;
		this->equipProvince(provinces[i-1]); //add province to army or holdings vector and call checkChains for upper-sub holding connections
		//provinces.erase(provinces.begin() + (i-1)); //remove card from provinces
		provinces[i-1] = dynastyDeck->front(); //remove card from provinces and replace it with top of dynasty-deck (not revealed)
	  dynastyDeck->pop_front();
	}

	cout << "Any remainder of the money from the tapped holdings is lost " << endl;
	money = (money > roundMoney) ? roundMoney : money ;
	roundMoney = money;
	cout << "Available money now is " << money << endl;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x760f(%rip), %rbx      # 0x11fd0
leaq 0x1eab(%rip), %rsi      # 0xc873
movl $0x8, %edx
movq %rbx, %rdi
callq 0x31a0
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
movq %rbx, %rdi
callq 0x31a0
movq %rax, %r15
leaq 0x1e87(%rip), %rsi      # 0xc87c
movl $0xc, %edx
movq %rax, %rdi
callq 0x31a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
leaq 0x29a5(%rip), %rsi      # 0xd3d5
movl $0x11, %edx
movq %rbx, %rdi
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %r14, %rdi
callq 0x8664
leaq 0x2122(%rip), %rsi      # 0xcbbf
movl $0x12, %edx
movq %rbx, %rdi
callq 0x31a0
movl 0xa0(%r14), %esi
movq %rbx, %rdi
callq 0x30e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %r14, %rdi
callq 0x87f4
movq %r14, %rdi
callq 0x92d6
cmpl $0x0, 0xa0(%r14)
je 0xae35
leaq 0x2b3c(%rip), %r13      # 0xd66e
movq 0x74a7(%rip), %rbp      # 0x11fe0
leaq 0x4(%rsp), %r15
movb $0x30, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x12, %edx
movq %rbx, %rdi
leaq 0x2065(%rip), %rsi      # 0xcbbf
callq 0x31a0
movl 0xa0(%r14), %esi
movq %rbx, %rdi
callq 0x30e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movzbl 0x3(%rsp), %eax
cmpl $0x6e, %eax
je 0xae35
cmpl $0x79, %eax
je 0xacd2
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
movq %rbx, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x35, %edx
movq %rax, %rdi
leaq 0x27e6(%rip), %rsi      # 0xd3e7
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
leaq 0x3(%rsp), %rsi
callq 0x31c0
jmp 0xabc2
movq %r14, %rdi
callq 0x87f4
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
movq %rbx, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x25, %edx
movq %rax, %rdi
leaq 0x27b0(%rip), %rsi      # 0xd41d
callq 0x31a0
movq 0x90(%r14), %rsi
subq 0x88(%r14), %rsi
sarq $0x3, %rsi
movq %r12, %rdi
callq 0x30e0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3210
movl 0x4(%rsp), %eax
testq %rax, %rax
je 0xac3d
movq 0x88(%r14), %rcx
movq 0x90(%r14), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0xac3d
decl %eax
movq (%rcx,%rax,8), %rax
cmpb $0x0, 0x2d(%rax)
je 0xad26
movl 0xa0(%r14), %ecx
subl 0x28(%rax), %ecx
jae 0xad66
movl $0x34, %edx
movq %rbx, %rdi
leaq 0x2755(%rip), %rsi      # 0xd479
jmp 0xad35
movl $0x35, %edx
movq %rbx, %rdi
leaq 0x270e(%rip), %rsi      # 0xd443
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
jmp 0xae27
movl %ecx, 0xa0(%r14)
movl $0x1d, %edx
movq %rbx, %rdi
leaq 0x2732(%rip), %rsi      # 0xd4ae
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl 0x4(%rsp), %eax
decl %eax
movq 0x88(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0xaeee
movq 0x18(%r14), %rax
movq 0x88(%r14), %rcx
movq (%rax), %rax
movq 0x10(%rax), %rax
movl 0x4(%rsp), %edx
decl %edx
movq %rax, (%rcx,%rdx,8)
movq 0x18(%r14), %rax
movq (%rax), %r12
decq 0x10(%rax)
movq %r12, %rdi
callq 0x31f0
movl $0x18, %esi
movq %r12, %rdi
callq 0x3180
cmpl $0x0, 0xa0(%r14)
jne 0xab3e
leaq 0x1ff3(%rip), %rsi      # 0xce2f
movl $0x3c, %edx
movq %rbx, %rdi
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl 0xa0(%r14), %eax
movl 0xa4(%r14), %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movl %ecx, 0xa0(%r14)
movl %ecx, 0xa4(%r14)
leaq 0x1fd4(%rip), %rsi      # 0xce6c
movl $0x17, %edx
movq %rbx, %rdi
callq 0x31a0
movl 0xa0(%r14), %esi
movq %rbx, %rdi
callq 0x30e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop