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