Implement default best-yield resource and long-press resource selection for city slots

This commit is contained in:
bart
2026-11-08 21:43:11 +01:00
parent 4b237872eb
commit 43b8b1556d
9 changed files with 492 additions and 52 deletions
+17
View File
@@ -59,6 +59,7 @@ public:
std::vector<std::pair<int, int>> territory; // Owned hex coordinates
std::map<std::pair<int, int>, QString> workedTiles; // (x, y) -> resource name
std::map<std::pair<int, int>, QString> tilePreferredResources; // (x, y) -> user chosen resource
City(int cId, int pId, const QString &cName, int tx, int ty, const QVector3D &pos,
int initInhabitants = 1000, int initInhabitantsPerPop = 100000, int initRadius = 1);
@@ -127,8 +128,24 @@ public:
return it != workedTiles.end() ? it->second : "";
}
QString getEffectiveResource(int tx, int ty, const QString &defaultBestRes) const {
auto itW = workedTiles.find({tx, ty});
if (itW != workedTiles.end()) return itW->second;
auto itP = tilePreferredResources.find({tx, ty});
if (itP != tilePreferredResources.end()) return itP->second;
return defaultBestRes;
}
void setTilePreferredResource(int tx, int ty, const QString &resource) {
tilePreferredResources[{tx, ty}] = resource;
if (isTileWorked(tx, ty)) {
workedTiles[{tx, ty}] = resource;
}
}
bool assignWorker(int tx, int ty, const QString &resource) {
if (!ownsTile(tx, ty)) return false;
tilePreferredResources[{tx, ty}] = resource;
if (isTileWorked(tx, ty)) {
workedTiles[{tx, ty}] = resource;
return true;