// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq 0x89f1(%rip), %r14      # 0x10fd0
leaq 0x228d(%rip), %rsi      # 0xa873
movq %r14, %rdi
callq 0x31a0
leaq 0xa8(%rbx), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3170
leaq 0x2275(%rip), %rsi      # 0xa87c
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
leaq 0x2db7(%rip), %rsi      # 0xb3d5
movq %r14, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movq %rbx, %rdi
callq 0x71ae
leaq 0x257a(%rip), %rsi      # 0xabbf
movq %r14, %rdi
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movq %rbx, %rdi
callq 0x7272
movq %rbx, %rdi
callq 0x78ac
leaq 0x2fec(%rip), %rbp      # 0xb66e
movq 0x8957(%rip), %r12      # 0x10fe0
leaq 0x4(%rsp), %r13
cmpl $0x0, 0xa0(%rbx)
je 0x883e
movb $0x30, 0x3(%rsp)
andl $0x0, 0x4(%rsp)
movq %r14, %rdi
leaq 0x2510(%rip), %rsi      # 0xabbf
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movzbl 0x3(%rsp), %eax
cmpl $0x6e, %eax
je 0x883e
cmpl $0x79, %eax
je 0x8774
movq %r14, %rdi
movq %r15, %rsi
callq 0x3170
movq %rax, %rdi
leaq 0x2ce9(%rip), %rsi      # 0xb3e7
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %r12, %rdi
leaq 0x3(%rsp), %rsi
callq 0x31f0
jmp 0x86d2
movq %rbx, %rdi
callq 0x7272
movq %r14, %rdi
movq %r15, %rsi
callq 0x3170
movq %rax, %rdi
leaq 0x2ce6(%rip), %rsi      # 0xb41d
callq 0x31a0
movq 0x90(%rbx), %rsi
subq 0x88(%rbx), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
movq %rbp, %rsi
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %r12, %rdi
movq %r13, %rsi
callq 0x3250
movl 0x4(%rsp), %eax
testq %rax, %rax
je 0x871a
movq 0x88(%rbx), %rcx
movq 0x90(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x871a
decl %eax
movq (%rcx,%rax,8), %rax
cmpb $0x0, 0x2d(%rax)
je 0x87ba
movl 0xa0(%rbx), %ecx
subl 0x28(%rax), %ecx
jae 0x87d6
movq %r14, %rdi
leaq 0x2cc1(%rip), %rsi      # 0xb479
jmp 0x87c4
movq %r14, %rdi
leaq 0x2c7f(%rip), %rsi      # 0xb443
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
jmp 0x868e
movl %ecx, 0xa0(%rbx)
movq %r14, %rdi
leaq 0x2cc8(%rip), %rsi      # 0xb4ae
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movq %rax, %rdi
callq 0x30d0
movl 0x4(%rsp), %eax
decl %eax
movq 0x88(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
callq 0x88ae
movq 0x18(%rbx), %rax
movq 0x88(%rbx), %rcx
movq (%rax), %rax
movq 0x10(%rax), %rax
movl 0x4(%rsp), %edx
decl %edx
movq %rax, (%rcx,%rdx,8)
movq 0x18(%rbx), %rdi
callq 0x8f86
jmp 0x868e
movq 0x878b(%rip), %r14      # 0x10fd0
leaq 0x25e3(%rip), %rsi      # 0xae2f
movq %r14, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x30d0
movl 0xa0(%rbx), %eax
movl 0xa4(%rbx), %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movl %ecx, 0xa0(%rbx)
movl %ecx, 0xa4(%rbx)
leaq 0x25ec(%rip), %rsi      # 0xae6c
movq %r14, %rdi
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x30d0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop