Implement city production projects for units and buildings
This commit is contained in:
@@ -18,6 +18,29 @@ struct CityYieldSummary {
|
||||
int gold = 0;
|
||||
};
|
||||
|
||||
enum class CityProjectType {
|
||||
None,
|
||||
Unit,
|
||||
Building
|
||||
};
|
||||
|
||||
struct CityProject {
|
||||
CityProjectType type = CityProjectType::None;
|
||||
QString id = "";
|
||||
QString name = "";
|
||||
int laborCost = 0;
|
||||
int currentLabor = 0;
|
||||
QString district = "center";
|
||||
|
||||
bool isValid() const { return type != CityProjectType::None && !id.isEmpty(); }
|
||||
float getProgress() const {
|
||||
return laborCost > 0 ? std::max(0.0f, std::min(1.0f, (float)currentLabor / (float)laborCost)) : 0.0f;
|
||||
}
|
||||
int getRemainingLabor() const {
|
||||
return std::max(0, laborCost - currentLabor);
|
||||
}
|
||||
};
|
||||
|
||||
class City {
|
||||
public:
|
||||
int id;
|
||||
@@ -31,12 +54,45 @@ public:
|
||||
int inhabitantsPerPop;
|
||||
int accumulatedLabor = 0; // Local resource (Arbeid)
|
||||
|
||||
CityProject currentProject;
|
||||
std::vector<QString> completedBuildings; // IDs of completed buildings in the city
|
||||
|
||||
std::vector<std::pair<int, int>> territory; // Owned hex coordinates
|
||||
std::map<std::pair<int, int>, QString> workedTiles; // (x, y) -> resource name
|
||||
|
||||
City(int cId, int pId, const QString &cName, int tx, int ty, const QVector3D &pos,
|
||||
int initInhabitants = 1000, int initInhabitantsPerPop = 100000, int initRadius = 1);
|
||||
|
||||
bool hasBuilding(const QString &buildingId) const {
|
||||
for (const auto &b : completedBuildings) {
|
||||
if (b == buildingId) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool addBuilding(const QString &buildingId) {
|
||||
if (hasBuilding(buildingId)) return false;
|
||||
completedBuildings.push_back(buildingId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasActiveProject() const {
|
||||
return currentProject.isValid();
|
||||
}
|
||||
|
||||
void startProject(CityProjectType type, const QString &projId, const QString &projName, int cost, const QString &district = "center") {
|
||||
currentProject.type = type;
|
||||
currentProject.id = projId;
|
||||
currentProject.name = projName;
|
||||
currentProject.laborCost = std::max(1, cost);
|
||||
currentProject.currentLabor = 0;
|
||||
currentProject.district = district.isEmpty() ? "center" : district;
|
||||
}
|
||||
|
||||
void cancelProject() {
|
||||
currentProject = CityProject();
|
||||
}
|
||||
|
||||
bool addTerritory(int tx, int ty) {
|
||||
if (ownsTile(tx, ty)) return false;
|
||||
territory.emplace_back(tx, ty);
|
||||
|
||||
Reference in New Issue
Block a user