// File: /workspace/github_cpp_makefile_star2_O1/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 0x7751(%rip), %rbx      # 0x11fd0
leaq 0x2001(%rip), %rsi      # 0xc887
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 0x1fdd(%rip), %rsi      # 0xc890
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 0x2afb(%rip), %rsi      # 0xd3e9
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 0x8600
leaq 0x2278(%rip), %rsi      # 0xcbd3
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 0x8790
movq %r14, %rdi
callq 0x9252
cmpl $0x0, 0xa0(%r14)
je 0xacf3
leaq 0x2c92(%rip), %r13      # 0xd682
movq 0x75e9(%rip), %rbp      # 0x11fe0
leaq 0x4(%rsp), %r15
movb $0x30, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x12, %edx
movq %rbx, %rdi
leaq 0x21bb(%rip), %rsi      # 0xcbd3
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 0xacf3
cmpl $0x79, %eax
je 0xab90
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
movq %rbx, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x35, %edx
movq %rax, %rdi
leaq 0x293c(%rip), %rsi      # 0xd3fb
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 0xaa80
movq %r14, %rdi
callq 0x8790
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
movq %rbx, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x25, %edx
movq %rax, %rdi
leaq 0x2906(%rip), %rsi      # 0xd431
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 0xaafb
movq 0x88(%r14), %rcx
movq 0x90(%r14), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0xaafb
decl %eax
movq (%rcx,%rax,8), %rax
cmpb $0x0, 0x2d(%rax)
je 0xabe4
movl 0xa0(%r14), %ecx
subl 0x28(%rax), %ecx
jae 0xac24
movl $0x34, %edx
movq %rbx, %rdi
leaq 0x28ab(%rip), %rsi      # 0xd48d
jmp 0xabf3
movl $0x35, %edx
movq %rbx, %rdi
leaq 0x2864(%rip), %rsi      # 0xd457
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 0xace5
movl %ecx, 0xa0(%r14)
movl $0x1d, %edx
movq %rbx, %rdi
leaq 0x2888(%rip), %rsi      # 0xd4c2
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 0xadac
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 0xa9fc
leaq 0x2149(%rip), %rsi      # 0xce43
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 0x212a(%rip), %rsi      # 0xce80
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