mirror of
https://github.com/glest/glest-source.git
synced 2025-02-23 11:15:02 +01:00
If player doesn't have enough resources, options are grayed out
This commit is contained in:
parent
98c724770f
commit
c509fb1247
@ -1122,6 +1122,18 @@ namespace Glest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//required resources
|
||||||
|
for (int i = 0; i < rt->getCostCount(); i++) {
|
||||||
|
const ResourceType *resource = rt->getCost(i)->getType();
|
||||||
|
int cost = rt->getCost(i)->getAmount();
|
||||||
|
if (cost > 0) {
|
||||||
|
int available = getResource(resource)->getAmount();
|
||||||
|
if (cost > available) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (dynamic_cast <const UnitType *>(rt) != NULL) {
|
if (dynamic_cast <const UnitType *>(rt) != NULL) {
|
||||||
const UnitType *producedUnitType =
|
const UnitType *producedUnitType =
|
||||||
dynamic_cast <const UnitType *>(rt);
|
dynamic_cast <const UnitType *>(rt);
|
||||||
|
@ -56,38 +56,74 @@ namespace Glest {
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
string RequirableType::getReqDesc(bool translatedValue) const {
|
string RequirableType::getReqDesc(bool translatedValue) const {
|
||||||
bool anyReqs = false;
|
return getReqDesc(false, translatedValue);
|
||||||
|
}
|
||||||
|
|
||||||
string reqString = "";
|
const Resource *RequirableType::getCost(const ResourceType * rt) const {
|
||||||
for (int i = 0; i < getUnitReqCount(); ++i) {
|
for (int i = 0; i < (int) costs.size(); ++i) {
|
||||||
if (getUnitReq(i) == NULL) {
|
if (costs[i].getType() == rt) {
|
||||||
throw megaglest_runtime_error("getUnitReq(i) == NULL");
|
return &costs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string RequirableType::getResourceReqDesc(bool lineBreaks,
|
||||||
|
bool translatedValue) const {
|
||||||
|
string str = "";
|
||||||
|
for (int i = 0; i < getCostCount(); ++i) {
|
||||||
|
if (getCost(i)->getAmount() != 0) {
|
||||||
|
str += getCost(i)->getType()->getName(translatedValue);
|
||||||
|
str += ": " + intToStr(getCost(i)->getAmount());
|
||||||
|
if (lineBreaks == true) {
|
||||||
|
str += "\n";
|
||||||
|
} else {
|
||||||
|
str += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
string RequirableType::getUnitAndUpgradeReqDesc(bool lineBreaks,
|
||||||
|
bool translatedValue)
|
||||||
|
const {
|
||||||
|
string str = "";
|
||||||
|
for (int i = 0; i < getUnitReqCount(); ++i) {
|
||||||
|
str += getUnitReq(i)->getName(translatedValue);
|
||||||
|
if (lineBreaks == true) {
|
||||||
|
str += "\n";
|
||||||
|
} else {
|
||||||
|
str += " ";
|
||||||
}
|
}
|
||||||
reqString += getUnitReq(i)->getName(translatedValue);
|
|
||||||
reqString += "\n";
|
|
||||||
anyReqs = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < getUpgradeReqCount(); ++i) {
|
for (int i = 0; i < getUpgradeReqCount(); ++i) {
|
||||||
if (getUpgradeReq(i) == NULL) {
|
str += getUpgradeReq(i)->getName(translatedValue);
|
||||||
throw megaglest_runtime_error("getUpgradeReq(i) == NULL");
|
if (lineBreaks == true) {
|
||||||
|
str += "\n";
|
||||||
|
} else {
|
||||||
|
str += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
reqString += getUpgradeReq(i)->getName(translatedValue);
|
|
||||||
reqString += "\n";
|
|
||||||
anyReqs = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string str = getName(translatedValue);
|
return str;
|
||||||
if (anyReqs) {
|
}
|
||||||
return str + " " + Lang::getInstance().getString("Reqs",
|
|
||||||
(translatedValue ==
|
string RequirableType::getReqDesc(bool ignoreResourceRequirements, bool translatedValue) const {
|
||||||
true ? "" :
|
string str =
|
||||||
"english")) +
|
getName(translatedValue) + " " +
|
||||||
":\n" + reqString;
|
Lang::getInstance().getString("Reqs",
|
||||||
} else {
|
(translatedValue ==
|
||||||
return str;
|
true ? "" : "english")) + ":\n";
|
||||||
|
if (ignoreResourceRequirements == false) {
|
||||||
|
str += getResourceReqDesc(true, translatedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str += getUnitAndUpgradeReqDesc(true, translatedValue);
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void RequirableType::saveGame(XmlNode *rootNode) const {
|
//void RequirableType::saveGame(XmlNode *rootNode) const {
|
||||||
@ -124,77 +160,6 @@ namespace Glest {
|
|||||||
ProducibleType::~ProducibleType() {
|
ProducibleType::~ProducibleType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Resource *ProducibleType::getCost(const ResourceType * rt) const {
|
|
||||||
for (int i = 0; i < (int) costs.size(); ++i) {
|
|
||||||
if (costs[i].getType() == rt) {
|
|
||||||
return &costs[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ProducibleType::getReqDesc(bool translatedValue) const {
|
|
||||||
return getReqDesc(false, translatedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
string ProducibleType::getResourceReqDesc(bool lineBreaks,
|
|
||||||
bool translatedValue) const {
|
|
||||||
string str = "";
|
|
||||||
for (int i = 0; i < getCostCount(); ++i) {
|
|
||||||
if (getCost(i)->getAmount() != 0) {
|
|
||||||
str += getCost(i)->getType()->getName(translatedValue);
|
|
||||||
str += ": " + intToStr(getCost(i)->getAmount());
|
|
||||||
if (lineBreaks == true) {
|
|
||||||
str += "\n";
|
|
||||||
} else {
|
|
||||||
str += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ProducibleType::getUnitAndUpgradeReqDesc(bool lineBreaks,
|
|
||||||
bool translatedValue)
|
|
||||||
const {
|
|
||||||
string str = "";
|
|
||||||
for (int i = 0; i < getUnitReqCount(); ++i) {
|
|
||||||
str += getUnitReq(i)->getName(translatedValue);
|
|
||||||
if (lineBreaks == true) {
|
|
||||||
str += "\n";
|
|
||||||
} else {
|
|
||||||
str += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < getUpgradeReqCount(); ++i) {
|
|
||||||
str += getUpgradeReq(i)->getName(translatedValue);
|
|
||||||
if (lineBreaks == true) {
|
|
||||||
str += "\n";
|
|
||||||
} else {
|
|
||||||
str += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ProducibleType::getReqDesc(bool ignoreResourceRequirements,
|
|
||||||
bool translatedValue) const {
|
|
||||||
string str =
|
|
||||||
getName(translatedValue) + " " +
|
|
||||||
Lang::getInstance().getString("Reqs",
|
|
||||||
(translatedValue ==
|
|
||||||
true ? "" : "english")) + ":\n";
|
|
||||||
if (ignoreResourceRequirements == false) {
|
|
||||||
str += getResourceReqDesc(true, translatedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
str += getUnitAndUpgradeReqDesc(true, translatedValue);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
//void ProducibleType::saveGame(XmlNode *rootNode) const {
|
//void ProducibleType::saveGame(XmlNode *rootNode) const {
|
||||||
// RequirableType::saveGame(rootNode);
|
// RequirableType::saveGame(rootNode);
|
||||||
//
|
//
|
||||||
|
@ -74,10 +74,12 @@ namespace Glest {
|
|||||||
private:
|
private:
|
||||||
typedef vector < const UnitType *>UnitReqs;
|
typedef vector < const UnitType *>UnitReqs;
|
||||||
typedef vector < const UpgradeType *>UpgradeReqs;
|
typedef vector < const UpgradeType *>UpgradeReqs;
|
||||||
|
typedef vector < Resource > Costs;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UnitReqs unitReqs; //needed units
|
UnitReqs unitReqs; //needed units
|
||||||
UpgradeReqs upgradeReqs; //needed upgrades
|
UpgradeReqs upgradeReqs; //needed upgrades
|
||||||
|
Costs costs; //needed costs
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//get
|
//get
|
||||||
@ -93,10 +95,24 @@ namespace Glest {
|
|||||||
const UnitType *getUnitReq(int i) const {
|
const UnitType *getUnitReq(int i) const {
|
||||||
return unitReqs[i];
|
return unitReqs[i];
|
||||||
}
|
}
|
||||||
|
//get
|
||||||
|
int getCostCount() const {
|
||||||
|
return (int) costs.size();
|
||||||
|
}
|
||||||
|
const Resource *getCost(int i) const {
|
||||||
|
return &costs[i];
|
||||||
|
}
|
||||||
|
const Resource *getCost(const ResourceType * rt) const;
|
||||||
|
|
||||||
//other
|
//other
|
||||||
virtual string getReqDesc(bool translatedValue) const;
|
virtual string getReqDesc(bool translatedValue) const;
|
||||||
|
|
||||||
|
string getResourceReqDesc(bool lineBreaks, bool translatedValue) const;
|
||||||
|
string getUnitAndUpgradeReqDesc(bool lineBreaks,
|
||||||
|
bool translatedValue) const;
|
||||||
|
string getReqDesc(bool ignoreResourceRequirements,
|
||||||
|
bool translatedValue) const;
|
||||||
|
|
||||||
//virtual void saveGame(XmlNode *rootNode) const;
|
//virtual void saveGame(XmlNode *rootNode) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -108,11 +124,7 @@ namespace Glest {
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class ProducibleType :public RequirableType {
|
class ProducibleType :public RequirableType {
|
||||||
private:
|
|
||||||
typedef vector < Resource > Costs;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Costs costs;
|
|
||||||
Texture2D *cancelImage;
|
Texture2D *cancelImage;
|
||||||
int productionTime;
|
int productionTime;
|
||||||
|
|
||||||
@ -120,14 +132,6 @@ namespace Glest {
|
|||||||
ProducibleType();
|
ProducibleType();
|
||||||
virtual ~ProducibleType();
|
virtual ~ProducibleType();
|
||||||
|
|
||||||
//get
|
|
||||||
int getCostCount() const {
|
|
||||||
return (int) costs.size();
|
|
||||||
}
|
|
||||||
const Resource *getCost(int i) const {
|
|
||||||
return &costs[i];
|
|
||||||
}
|
|
||||||
const Resource *getCost(const ResourceType * rt) const;
|
|
||||||
int getProductionTime() const {
|
int getProductionTime() const {
|
||||||
return productionTime;
|
return productionTime;
|
||||||
}
|
}
|
||||||
@ -135,16 +139,6 @@ namespace Glest {
|
|||||||
return cancelImage;
|
return cancelImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
//varios
|
|
||||||
void checkCostStrings(TechTree * techTree);
|
|
||||||
|
|
||||||
virtual string getReqDesc(bool translatedValue) const;
|
|
||||||
string getResourceReqDesc(bool lineBreaks, bool translatedValue) const;
|
|
||||||
string getUnitAndUpgradeReqDesc(bool lineBreaks,
|
|
||||||
bool translatedValue) const;
|
|
||||||
string getReqDesc(bool ignoreResourceRequirements,
|
|
||||||
bool translatedValue) const;
|
|
||||||
|
|
||||||
// virtual void saveGame(XmlNode *rootNode) const;
|
// virtual void saveGame(XmlNode *rootNode) const;
|
||||||
// void loadGame(const XmlNode *rootNode);
|
// void loadGame(const XmlNode *rootNode);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user