Page 1 of 1
Determining builder/factory
Posted: 17 Oct 2005, 17:08
by submarine
How do you quickly determine, which factory or builder ist needed to construct a certain unit/building or check, whether a ceratin cons. unit is capable of building a certain building?
Posted: 17 Oct 2005, 19:53
by cain
Code: Select all
const UnitDef *td=gs->callback->GetUnitDef(gameid);
if (td==0) {
def=NULL;
gs->logger->toInfoConsole("error #24: Unit not on LOS!");
}else {
def=new UnitDef();
*def=*td;
}
unittype=def->id;
std::map<int, std::string>::const_iterator it;
bo=def->buildOptions;
for (it=bo.begin();it!=bo.end();++it) {
buildTable.insert(gs->callback->GetUnitDef (it->second.c_str())->id);
}
frameFromLastCommand=-1000;
if (!def->canmove) {
pos=gs->callback->GetUnitPos(unitid);
}
now you have a set of the unit that a unit with that game id can build. just do a find(unitdef->id) on the set to see if you can build that. better using some caching here, however
Posted: 17 Oct 2005, 19:54
by cain
of curse, ignore the trailing junk of code that i've pasted for error =)
buildTable is obviously a set.