UPD: Fix canBuild method to actually check resource costs

This commit is contained in:
sebastian 2026-02-21 10:55:46 +01:00
parent ae618b628b
commit dcfa6ea38a
2 changed files with 10 additions and 6 deletions

View File

@ -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;
}

View File

@ -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;