Implement technology tree, research queue by least remaining work, and unit/building tech availability & obsolescence
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
#define PLAYER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QColor>
|
||||
#include <QMap>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
struct Player {
|
||||
int id;
|
||||
@@ -12,11 +16,17 @@ struct Player {
|
||||
QColor secondaryColor;
|
||||
|
||||
// National resources (shared across all cities of this nation)
|
||||
// Note: science represents per-tick science generation rate (no longer stockpiled)
|
||||
int culture;
|
||||
int science;
|
||||
int gold;
|
||||
int faith;
|
||||
|
||||
// Technology Tree & Research Progression
|
||||
std::set<QString> researchedTechs;
|
||||
QMap<QString, int> techProgress; // Tech ID -> accumulated science towards that tech
|
||||
std::vector<QString> researchQueue; // Ordered queue of Tech IDs (front is active research)
|
||||
|
||||
Player()
|
||||
: id(0), name("Unknown"), primaryColor(Qt::blue), secondaryColor(Qt::white),
|
||||
culture(10000), science(0), gold(0), faith(0) {}
|
||||
@@ -24,6 +34,55 @@ struct Player {
|
||||
int pCulture = 10000, int pScience = 0, int pGold = 0, int pFaith = 0)
|
||||
: id(pId), name(pName), primaryColor(primary), secondaryColor(secondary),
|
||||
culture(pCulture), science(pScience), gold(pGold), faith(pFaith) {}
|
||||
|
||||
bool hasResearched(const QString &techId) const {
|
||||
if (techId.isEmpty()) return true;
|
||||
return researchedTechs.find(techId) != researchedTechs.end();
|
||||
}
|
||||
|
||||
int getTechProgress(const QString &techId) const {
|
||||
return techProgress.value(techId, 0);
|
||||
}
|
||||
|
||||
bool hasActiveResearch() const {
|
||||
return !researchQueue.empty();
|
||||
}
|
||||
|
||||
QString getActiveResearchTech() const {
|
||||
return researchQueue.empty() ? QString() : researchQueue.front();
|
||||
}
|
||||
|
||||
bool isTechQueued(const QString &techId) const {
|
||||
return std::find(researchQueue.begin(), researchQueue.end(), techId) != researchQueue.end();
|
||||
}
|
||||
|
||||
int getTechQueuePosition(const QString &techId) const {
|
||||
for (size_t i = 0; i < researchQueue.size(); ++i) {
|
||||
if (researchQueue[i] == techId) {
|
||||
return static_cast<int>(i) + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool arePrerequisitesMet(const QStringList &prerequisites) const {
|
||||
for (const QString &pre : prerequisites) {
|
||||
if (!hasResearched(pre)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isItemUnlocked(const QString &requiredTech) const {
|
||||
return requiredTech.isEmpty() || hasResearched(requiredTech);
|
||||
}
|
||||
|
||||
bool isItemObsolete(const QString &obsoleteTech) const {
|
||||
return !obsoleteTech.isEmpty() && hasResearched(obsoleteTech);
|
||||
}
|
||||
|
||||
bool isItemBuildable(const QString &requiredTech, const QString &obsoleteTech) const {
|
||||
return isItemUnlocked(requiredTech) && !isItemObsolete(obsoleteTech);
|
||||
}
|
||||
};
|
||||
|
||||
class PlayerManager {
|
||||
|
||||
Reference in New Issue
Block a user