From 59b2cdb78f531afe90b220911881c93cefed6a03 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Fri, 8 Oct 2010 19:30:53 +0000 Subject: [PATCH] max-unit-count works for buildings --- source/glest_game/type_instances/faction.cpp | 19 ++++++++----------- source/glest_game/type_instances/unit.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index cb6eba76..e3984f0e 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -179,18 +179,15 @@ bool Faction::reqsOk(const RequirableType *rt) const{ } } - if(dynamic_cast(rt) != NULL ){ - const CommandType *ct=(CommandType *) rt; - if(ct->getProduced() != NULL && dynamic_cast(ct->getProduced()) != NULL ){ - - const UnitType *producedUnitType= (UnitType *) ct->getProduced(); - if(producedUnitType->getMaxUnitCount()>0){ - if(producedUnitType->getMaxUnitCount()<=getCountForMaxUnitCount(producedUnitType)){ - return false; - } - } - } + if(dynamic_cast(rt) != NULL ){ + const UnitType *producedUnitType=(UnitType *) rt; + if(producedUnitType->getMaxUnitCount()>0){ + if(producedUnitType->getMaxUnitCount()<=getCountForMaxUnitCount(producedUnitType)){ + return false; + } + } } + return true; } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index ba4d42a0..9c27bb48 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -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(ct->getProduced()); if(producedUnitType==ut) { count++; } } + if(ct->getClass()==ccBuild){ + const UnitType *builtUnitType= (*it)->getUnitType(); + if(builtUnitType==ut) + { + count++; + } + } } return count; }