Determining builder/factory

Determining builder/factory

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Determining builder/factory

Post 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?
cain
AI Developer
Posts: 124
Joined: 09 Aug 2005, 10:04

Post 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
cain
AI Developer
Posts: 124
Joined: 09 Aug 2005, 10:04

Post by cain »

of curse, ignore the trailing junk of code that i've pasted for error =)
buildTable is obviously a set.
Post Reply

Return to “AI”