macressler / bwapi

Automatically exported from code.google.com/p/bwapi
1 stars 0 forks source link

GetUnit name #420

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I ve tried to create o block of code which counts marines number. First i tried 
to parse all my units in a set collection and after that to find how many 
elements have the name Terran_Marine but it seems that doesnt work. Has someone 
any idea?

int counter2;

std::set<Unit*> myUnits = Broodwar->self()->getUnits();
  for(std::set<Unit*>::iterator i=myUnits.begin();i!=myUnits.end();i++)       {
            Unit* pUnit = *i;
        if( pUnit->getType().getName() == "Terran_Marine")
        {
         counter2++;
        }           
}
Broodwar->printf("The no of the marines are: %d" ,counter2);

Original issue reported on code.google.com by snake__p...@hotmail.com on 21 Nov 2011 at 5:56

GoogleCodeExporter commented 9 years ago
Pretty sure it's "Terran Marine", however this is inefficient and you should 
just use

pUnit->getType() == UnitTypes::Terran_Marine

since it will just compare an int instead of a string.

Original comment by AHeinerm on 21 Nov 2011 at 6:45

GoogleCodeExporter commented 9 years ago
Yohoo thanks man.

Original comment by snake__p...@hotmail.com on 21 Nov 2011 at 7:00