Skip to content

Commit 35c7982

Browse files
committed
Merge pull request #65 from Databean/fixTradingAgain
Fixed trading again
2 parents fe5d202 + c0c232a commit 35c7982

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/GameController.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,12 @@ auto negativeArr(std::array<int, size> arr) -> std::array<int, size> {
472472
bool GameController::handlePlayerClick(ScreenCoordinate coord, Player& player) {
473473
if(getState() == BASESTATE){
474474
using namespace std::placeholders;
475-
Player& initiating = *model.getPlayers()[0];
475+
Player& initiating = model.getCurrentPlayer();
476476
Player& receiving = player;
477477
auto priority = -10;
478478

479479
std::array<int, 5> initial{{0, 0, 0, 0, 0}};
480-
481-
//std::function<bool(std::array<int, 5>, ScreenCoordinate)> tradeFunction(std::bind(&GameController::handleTradeOffer, this, _2, std::ref(initiating), _1, std::ref(receiving)));
480+
482481
std::function<bool(std::array<int, 5>, ScreenCoordinate)> tradeFunction([this, &initiating, &receiving](std::array<int, 5> offer, ScreenCoordinate coord) {
483482
std::array<int, 5> initial{{0, 0, 0, 0, 0}};
484483
std::array<int, 5> reverseOffer = negativeArr<5>(offer);

src/Player.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,13 @@ int Player::giveAllResources(int resourceType){
606606

607607
bool Player::acceptOffer(Player& p, std::array<int, 5> offer, std::array<int, 5> demand)
608608
{
609-
if(!checkResources(offer.data()) || !p.checkResources(demand.data())) {
609+
std::cout << getName() << "\t" << p.getName() << std::endl;
610+
for(int i = 0; i < 5; i++) {
611+
std::cout << offer[i] << " " << demand[i] << std::endl;
612+
}
613+
if(!checkResources(demand.data()) || !p.checkResources(offer.data())) {
614+
std::cout << "failed" << std::endl;
615+
std::cout << checkResources(offer.data()) << " " << p.checkResources(demand.data()) << std::endl;
610616
return false;
611617
}
612618
p.addWood(demand[WOOD_INDEX] - offer[WOOD_INDEX]);

0 commit comments

Comments
 (0)