max-unit-count works for buildings

This commit is contained in:
Titus Tscharntke 2010-10-08 19:30:53 +00:00
parent ae010f85ab
commit 59b2cdb78f
2 changed files with 16 additions and 12 deletions

View File

@ -179,18 +179,15 @@ bool Faction::reqsOk(const RequirableType *rt) const{
}
}
if(dynamic_cast<const CommandType *>(rt) != NULL ){
const CommandType *ct=(CommandType *) rt;
if(ct->getProduced() != NULL && dynamic_cast<const UnitType *>(ct->getProduced()) != NULL ){
const UnitType *producedUnitType= (UnitType *) ct->getProduced();
if(producedUnitType->getMaxUnitCount()>0){
if(producedUnitType->getMaxUnitCount()<=getCountForMaxUnitCount(producedUnitType)){
return false;
}
}
}
if(dynamic_cast<const UnitType *>(rt) != NULL ){
const UnitType *producedUnitType=(UnitType *) rt;
if(producedUnitType->getMaxUnitCount()>0){
if(producedUnitType->getMaxUnitCount()<=getCountForMaxUnitCount(producedUnitType)){
return false;
}
}
}
return true;
}

View File

@ -690,13 +690,20 @@ int Unit::getCountOfProducedUnits(const UnitType *ut) const{
int count=0;
for(Commands::const_iterator it= commands.begin(); it!=commands.end(); ++it){
const CommandType* ct=(*it)->getCommandType();
if(ct->getClass()==ccProduce || ct->getClass()==ccMorph || ct->getClass()==ccBuild ){
if(ct->getClass()==ccProduce || ct->getClass()==ccMorph ){
const UnitType *producedUnitType= static_cast<const UnitType*>(ct->getProduced());
if(producedUnitType==ut)
{
count++;
}
}
if(ct->getClass()==ccBuild){
const UnitType *builtUnitType= (*it)->getUnitType();
if(builtUnitType==ut)
{
count++;
}
}
}
return count;
}