UPD: Fix canBuild method to actually check resource costs
This commit is contained in:
parent
ae618b628b
commit
dcfa6ea38a
@ -7,6 +7,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bits/ostream.tcc>
|
#include <bits/ostream.tcc>
|
||||||
|
|
||||||
|
#include "hexWorld/building/BuildingConfig.h"
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
GameMode::GameMode() {
|
GameMode::GameMode() {
|
||||||
@ -14,12 +15,15 @@ GameMode::GameMode() {
|
|||||||
addPlayer(1, "Player 2");
|
addPlayer(1, "Player 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameMode::canBuild(PlayerID player, BuildingType buildingType) {
|
bool GameMode::canBuild(PlayerID player, BuildingType buildingType) const {
|
||||||
int woodCost = 10;
|
|
||||||
if (!players[player].getInventory()->hasEnough(RessourceType::WOOD, woodCost)) {
|
const auto def = BuildingConfig::get(buildingType);
|
||||||
std::cout << "Not enough wood" << std::endl;
|
const auto buildingCosts = def.resourceCosts;
|
||||||
|
for (const auto& [resource, amount] : buildingCosts) {
|
||||||
|
if (!canAfford(player, resource, amount)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
class GameMode {
|
class GameMode {
|
||||||
public:
|
public:
|
||||||
GameMode();
|
GameMode();
|
||||||
bool canBuild(EntityID player, BuildingType buildingType);
|
bool canBuild(EntityID player, BuildingType buildingType) const;
|
||||||
|
|
||||||
bool canAfford(PlayerID player_id, RessourceType ressource, int amount) const;
|
bool canAfford(PlayerID player_id, RessourceType ressource, int amount) const;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user