- bugfix for resource usage checking
- added new techtree validation in validation report to tell if a techtress has resources that are ununsed by the techtree
This commit is contained in:
parent
99f7038a86
commit
d8c337ae7b
|
@ -606,34 +606,7 @@ Map * AiInterface::getMap() {
|
|||
}
|
||||
|
||||
bool AiInterface::factionUsesResourceType(const FactionType *factionType, const ResourceType *rt) {
|
||||
bool factionUsesResourceType = false;
|
||||
for(int j = 0; factionUsesResourceType == false && j < factionType->getUnitTypeCount(); ++j) {
|
||||
const UnitType *ut= factionType->getUnitType(j);
|
||||
for(int k = 0; factionUsesResourceType == false && k < ut->getCostCount(); ++k) {
|
||||
const Resource *costResource = ut->getCost(k);
|
||||
if(costResource != NULL && costResource->getType() == rt) {
|
||||
factionUsesResourceType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(factionUsesResourceType == false) {
|
||||
for(int k = 0; factionUsesResourceType == false && k < ut->getCommandTypeCount(); ++k) {
|
||||
const CommandType *commandType = ut->getCommandType(k);
|
||||
if(commandType != NULL && commandType->getClass() == ccHarvest) {
|
||||
const HarvestCommandType *hct = dynamic_cast<const HarvestCommandType *>(commandType);
|
||||
if(hct != NULL && hct->getHarvestedResourceCount() > 0) {
|
||||
for(int l = 0; factionUsesResourceType == false && l < hct->getHarvestedResourceCount(); ++l) {
|
||||
if(hct->getHarvestedResource(l) == rt) {
|
||||
factionUsesResourceType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool factionUsesResourceType = factionType->factionUsesResourceType(rt);
|
||||
return factionUsesResourceType;
|
||||
}
|
||||
|
||||
|
|
|
@ -500,7 +500,7 @@ void AiRuleProduce::produceGeneric(const ProduceTask *pt){
|
|||
//add specific produce task
|
||||
if(!ableUnits.empty()){
|
||||
|
||||
if(ai->outputAIBehaviourToConsole()) printf("produceGeneric !ableUnits.empty(), ableUnits.size() = [%d] Testing AI RULE Name[%s]\n",ableUnits.size(), this->getName().c_str());
|
||||
if(ai->outputAIBehaviourToConsole()) printf("produceGeneric !ableUnits.empty(), ableUnits.size() = [%d] Testing AI RULE Name[%s]\n",(int)ableUnits.size(), this->getName().c_str());
|
||||
|
||||
//priority for non produced units
|
||||
for(unsigned int i=0; i<ableUnits.size(); ++i){
|
||||
|
|
|
@ -2014,8 +2014,6 @@ int glestMain(int argc, char** argv) {
|
|||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Disabling VBO's\n");
|
||||
}
|
||||
|
||||
//Game preCacheThreadGame;
|
||||
|
||||
//float pingTime = Socket::getAveragePingMS("soft-haus.com");
|
||||
//printf("Ping time = %f\n",pingTime);
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ std::vector<std::string> FactionType::validateFactionType() {
|
|||
std::vector<std::string> FactionType::validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes) {
|
||||
std::vector<std::string> results;
|
||||
|
||||
for(int i=0; i<unitTypes.size(); ++i){
|
||||
for(int i=0; i<unitTypes.size(); ++i) {
|
||||
UnitType &unitType = unitTypes[i];
|
||||
|
||||
// Check every unit's required resources to validate that for every resource-requirements
|
||||
|
@ -574,6 +574,42 @@ void FactionType::deletePixels() {
|
|||
}
|
||||
}
|
||||
|
||||
bool FactionType::factionUsesResourceType(const ResourceType *rt) const {
|
||||
bool factionUsesResourceType = false;
|
||||
for(unsigned int j = 0; factionUsesResourceType == false && j < this->getUnitTypeCount(); ++j) {
|
||||
const UnitType *ut= this->getUnitType(j);
|
||||
for(int k = 0; factionUsesResourceType == false && k < ut->getCostCount(); ++k) {
|
||||
const Resource *costResource = ut->getCost(k);
|
||||
//printf("#1 factionUsesResourceType, unit [%s] resource [%s] cost [%s]\n",ut->getName().c_str(),rt->getName().c_str(),costResource->getType()->getName().c_str());
|
||||
|
||||
if(costResource != NULL && costResource->getType()->getName() == rt->getName()) {
|
||||
factionUsesResourceType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(factionUsesResourceType == false) {
|
||||
for(unsigned int k = 0; factionUsesResourceType == false && k < ut->getCommandTypeCount(); ++k) {
|
||||
const CommandType *commandType = ut->getCommandType(k);
|
||||
if(commandType != NULL && commandType->getClass() == ccHarvest) {
|
||||
const HarvestCommandType *hct = dynamic_cast<const HarvestCommandType *>(commandType);
|
||||
if(hct != NULL && hct->getHarvestedResourceCount() > 0) {
|
||||
for(unsigned int l = 0; factionUsesResourceType == false && l < hct->getHarvestedResourceCount(); ++l) {
|
||||
//printf("#2 factionUsesResourceType, unit [%s] resource [%s] harvest [%s]\n",ut->getName().c_str(),rt->getName().c_str(),hct->getHarvestedResource(l)->getName().c_str());
|
||||
|
||||
if(hct->getHarvestedResource(l)->getName() == rt->getName()) {
|
||||
factionUsesResourceType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return factionUsesResourceType;
|
||||
}
|
||||
|
||||
std::string FactionType::toString() const {
|
||||
std::string result = "";
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
std::vector<std::string> validateFactionTypeUpgradeTypes();
|
||||
|
||||
void deletePixels();
|
||||
bool factionUsesResourceType(const ResourceType *rt) const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -215,9 +215,37 @@ std::vector<std::string> TechTree::validateFactionTypes() {
|
|||
|
||||
std::vector<std::string> TechTree::validateResourceTypes() {
|
||||
std::vector<std::string> results;
|
||||
for (int i = 0; i < factionTypes.size(); ++i) {
|
||||
ResourceTypes resourceTypesNotUsed = resourceTypes;
|
||||
for (unsigned int i = 0; i < factionTypes.size(); ++i) {
|
||||
//printf("Validating [%d / %d] faction [%s]\n",i,(int)factionTypes.size(),factionTypes[i].getName().c_str());
|
||||
|
||||
std::vector<std::string> factionResults = factionTypes[i].validateFactionTypeResourceTypes(resourceTypes);
|
||||
results.insert(results.end(), factionResults.begin(), factionResults.end());
|
||||
if(factionResults.size() > 0) {
|
||||
results.insert(results.end(), factionResults.begin(), factionResults.end());
|
||||
}
|
||||
|
||||
// Check if the faction uses the resources in this techtree
|
||||
// Now lets find a matching faction resource type for the unit
|
||||
for(int j = resourceTypesNotUsed.size() -1; j >= 0; --j) {
|
||||
const ResourceType &rt = resourceTypesNotUsed[j];
|
||||
//printf("Validating [%d / %d] resourcetype [%s]\n",j,(int)resourceTypesNotUsed.size(),rt.getName().c_str());
|
||||
|
||||
if(factionTypes[i].factionUsesResourceType(&rt) == true) {
|
||||
//printf("FOUND FACTION CONSUMER FOR RESOURCE - [%d / %d] faction [%s] resource [%d / %d] resourcetype [%s]\n",i,(int)factionTypes.size(),factionTypes[i].getName().c_str(),j,(int)resourceTypesNotUsed.size(),rt.getName().c_str());
|
||||
resourceTypesNotUsed.erase(resourceTypesNotUsed.begin() + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(resourceTypesNotUsed.size() > 0) {
|
||||
//printf("FOUND unused resource Types [%d]\n",(int)resourceTypesNotUsed.size());
|
||||
|
||||
for (unsigned int i = 0; i < resourceTypesNotUsed.size(); ++i) {
|
||||
const ResourceType &rt = resourceTypesNotUsed[i];
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"The Resource type [%s] is not used by any units in this techtree!",rt.getName().c_str());
|
||||
results.push_back(szBuf);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue