// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0x129a5(%rip), %rdi     # 0x24fd0
leaq 0x6136(%rip), %rsi      # 0x18768
callq 0x4200
movq -0x18(%rbp), %rsi
movq %rax, %rdi
addq $0xa8, %rsi
callq 0x41d0
movq %rax, %rdi
leaq 0x611d(%rip), %rsi      # 0x18771
callq 0x4200
movq %rax, %rdi
movq 0x1295d(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x12961(%rip), %rdi     # 0x24fd0
leaq 0x6c02(%rip), %rsi      # 0x19278
callq 0x4200
movq %rax, %rdi
movq 0x1293b(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x1292c(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x18(%rbp), %rdi
callq 0xfc30
movq 0x12927(%rip), %rdi     # 0x24fd0
leaq 0x63b2(%rip), %rsi      # 0x18a62
callq 0x4200
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x128ef(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x128e0(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x18(%rbp), %rdi
callq 0xfdb0
movq -0x18(%rbp), %rdi
callq 0x10830
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
je 0x12a10
movb $0x30, -0x9(%rbp)
movl $0x0, -0x10(%rbp)
movq 0x128b6(%rip), %rdi     # 0x24fd0
leaq 0x6341(%rip), %rsi      # 0x18a62
callq 0x4200
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x1287e(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x1286f(%rip), %rsi     # 0x24fc0
callq 0x4230
movsbl -0x9(%rbp), %ecx
xorl %eax, %eax
cmpl $0x79, %ecx
movb %al, -0x19(%rbp)
je 0x12771
movsbl -0x9(%rbp), %eax
cmpl $0x6e, %eax
setne %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x1277a
jmp 0x127c1
movq -0x18(%rbp), %rsi
addq $0xa8, %rsi
movq 0x12844(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x6aef(%rip), %rsi      # 0x1928a
callq 0x4200
movq %rax, %rdi
movq 0x12816(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x1282a(%rip), %rdi     # 0x24fe0
leaq -0x9(%rbp), %rsi
callq 0x42b0
jmp 0x12756
movsbl -0x9(%rbp), %eax
cmpl $0x6e, %eax
jne 0x127cf
jmp 0x12a10
jmp 0x127d1
movb $0x1, %al
cmpl $0x1, -0x10(%rbp)
movb %al, -0x1a(%rbp)
jb 0x12803
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %eax
movq %rax, -0x28(%rbp)
addq $0x88, %rdi
callq 0xb2f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
cmpq %rcx, %rax
seta %al
movb %al, -0x1a(%rbp)
movb -0x1a(%rbp), %al
testb $0x1, %al
jne 0x1280f
jmp 0x12891
movq -0x18(%rbp), %rdi
callq 0xfdb0
movq -0x18(%rbp), %rsi
addq $0xa8, %rsi
movq 0x127a6(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x6a87(%rip), %rsi      # 0x192c0
callq 0x4200
movq -0x18(%rbp), %rdi
movq %rax, -0x30(%rbp)
addq $0x88, %rdi
callq 0xb2f0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
leaq 0x6ca9(%rip), %rsi      # 0x19511
callq 0x4200
movq %rax, %rdi
movq 0x12749(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x1275d(%rip), %rdi     # 0x24fe0
leaq -0x10(%rbp), %rsi
callq 0x4050
jmp 0x127d1
movq -0x18(%rbp), %rdi
addq $0x88, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x143f0
movq (%rax), %rdi
callq 0x13cf0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x128e4
movq 0x1270c(%rip), %rdi     # 0x24fd0
leaq 0x6a1b(%rip), %rsi      # 0x192e6
callq 0x4200
movq %rax, %rdi
movq 0x126e6(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x126f7
movq -0x18(%rbp), %rdi
addq $0x88, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x143f0
movq (%rax), %rdi
callq 0x13d70
movq -0x18(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jbe 0x12939
movq 0x126b7(%rip), %rdi     # 0x24fd0
leaq 0x69fc(%rip), %rsi      # 0x1931c
callq 0x4200
movq %rax, %rdi
movq 0x12691(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x126f7
movq -0x18(%rbp), %rdi
addq $0x88, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x143f0
movq (%rax), %rdi
callq 0x13d70
movl %eax, %edx
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xa0(%rax)
movq 0x1265a(%rip), %rdi     # 0x24fd0
leaq 0x69d4(%rip), %rsi      # 0x19351
callq 0x4200
movq %rax, %rdi
movq 0x12634(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x12625(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x18(%rbp), %rdi
addq $0x88, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x143f0
movq -0x18(%rbp), %rdi
movq (%rax), %rsi
callq 0x12ac0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x13790
movq -0x18(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x38(%rbp)
addq $0x88, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x143f0
movq -0x38(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rdx, (%rcx)
movq 0x18(%rax), %rdi
callq 0x137c0
jmp 0x126f7
movq 0x125b9(%rip), %rdi     # 0x24fd0
leaq 0x62b4(%rip), %rsi      # 0x18cd2
callq 0x4200
movq %rax, %rdi
movq 0x12593(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x18(%rbp), %rcx
movl 0xa0(%rcx), %eax
cmpl 0xa4(%rcx), %eax
jbe 0x12a53
movq -0x18(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0x12a60
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, 0xa0(%rax)
movl 0xa0(%rax), %ecx
movl %ecx, 0xa4(%rax)
movq 0x12550(%rip), %rdi     # 0x24fd0
leaq 0x6288(%rip), %rsi      # 0x18d0f
callq 0x4200
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x12518(%rip), %rsi     # 0x24fc0
callq 0x4230
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)