bugfix for MaxUnitCount

This commit is contained in:
titiger 2020-12-13 03:47:50 +01:00
parent d7847f5f1c
commit 805de06291
3 changed files with 9 additions and 5 deletions

View File

@ -956,7 +956,7 @@ int Faction::getCountForMaxUnitCount(const UnitType *unitType) const{
count++;
}
//check if there is any command active which already produces this unit
count=count+unit->getCountOfProducedUnits(unitType);
count=count+unit->getCountOfProducedUnitsPreExistence(unitType);
}
return count;
}

View File

@ -1784,8 +1784,10 @@ unsigned int Unit::getCommandSize() const {
return (unsigned int)commands.size();
}
//return current command, assert that there is always one command
int Unit::getCountOfProducedUnits(const UnitType *ut) const{
/*
* (this is meant for MaxUnitCount)
*/
int Unit::getCountOfProducedUnitsPreExistence(const UnitType *ut) const{
int count=0;
for(Commands::const_iterator it= commands.begin(); it!=commands.end(); ++it){
const CommandType* ct=(*it)->getCommandType();
@ -1798,7 +1800,9 @@ int Unit::getCountOfProducedUnits(const UnitType *ut) const{
}
if(ct->getClass()==ccBuild){
const UnitType *builtUnitType= (*it)->getUnitType();
if(builtUnitType==ut)
// we dont count builded units if they are already exist. So we just count the units that will be build.
// otherwise we will get double counts of alive units and units beeing build.
if(builtUnitType==ut && (*it)->getUnit()==NULL)
{
count++;
}

View File

@ -654,7 +654,7 @@ public:
return NULL;
}
void replaceCurrCommand(Command *cmd);
int getCountOfProducedUnits(const UnitType *ut) const;
int getCountOfProducedUnitsPreExistence(const UnitType *ut) const;
unsigned int getCommandSize() const;
std::pair<CommandResult,string> giveCommand(Command *command, bool tryQueue = false); //give a command
CommandResult finishCommand(); //command finished