Complete city production queue implementation

This commit is contained in:
bart
2026-11-08 22:30:13 +01:00
parent 4eda595861
commit 980e777199
14 changed files with 222 additions and 20 deletions
+75 -1
View File
@@ -55,6 +55,7 @@ public:
int accumulatedLabor = 0; // Local resource (Arbeid)
CityProject currentProject;
std::vector<CityProject> projectQueue;
std::vector<QString> completedBuildings; // IDs of completed buildings in the city
std::vector<std::pair<int, int>> territory; // Owned hex coordinates
@@ -77,6 +78,34 @@ public:
return true;
}
bool isBuildingQueuedOrBuilt(const QString &buildingId) const {
if (hasBuilding(buildingId)) return true;
if (currentProject.isValid() && currentProject.type == CityProjectType::Building && currentProject.id == buildingId) return true;
for (const auto &q : projectQueue) {
if (q.type == CityProjectType::Building && q.id == buildingId) return true;
}
return false;
}
int getQueuedBuildingPosition(const QString &buildingId) const {
for (size_t i = 0; i < projectQueue.size(); ++i) {
if (projectQueue[i].type == CityProjectType::Building && projectQueue[i].id == buildingId) {
return (int)i + 1;
}
}
return 0;
}
int getQueuedUnitCount(const QString &unitId) const {
int count = 0;
for (const auto &q : projectQueue) {
if (q.type == CityProjectType::Unit && q.id == unitId) {
count++;
}
}
return count;
}
bool hasActiveProject() const {
return currentProject.isValid();
}
@@ -90,8 +119,53 @@ public:
currentProject.district = district.isEmpty() ? "center" : district;
}
bool queueProject(CityProjectType type, const QString &projId, const QString &projName, int cost, const QString &district = "center", int maxQueueSize = 6) {
if (!hasActiveProject()) {
startProject(type, projId, projName, cost, district);
return true;
}
if ((int)projectQueue.size() >= maxQueueSize) {
return false;
}
CityProject q;
q.type = type;
q.id = projId;
q.name = projName;
q.laborCost = std::max(1, cost);
q.currentLabor = 0;
q.district = district.isEmpty() ? "center" : district;
projectQueue.push_back(q);
return true;
}
void cancelActiveProject() {
if (!projectQueue.empty()) {
currentProject = projectQueue.front();
projectQueue.erase(projectQueue.begin());
} else {
currentProject = CityProject();
}
}
void cancelProject() {
currentProject = CityProject();
cancelActiveProject();
}
bool removeQueuedProject(int index) {
if (index >= 0 && index < (int)projectQueue.size()) {
projectQueue.erase(projectQueue.begin() + index);
return true;
}
return false;
}
void advanceQueue() {
if (!projectQueue.empty()) {
currentProject = projectQueue.front();
projectQueue.erase(projectQueue.begin());
} else {
currentProject = CityProject();
}
}
bool addTerritory(int tx, int ty) {