Пример #1
0
void CUnitHandler::UnitCreated(int unit)
{
	int category = ai->ut->GetCategory(unit);
	const UnitDef* newUnitDef = ai->cb->GetUnitDef(unit);
	if(category != -1){
		//L("Unit " << unit << " created, ID : " << newUnitDef->id << " Cat: " << category);
		AllUnitsByCat[category]->push_back(unit);
		AllUnitsByType[newUnitDef->id]->push_back(unit);
		////L("push sucessful");
		if(category == CAT_FACTORY){
			FactoryAdd(unit);
		}
		BuildTaskCreate(unit);	
		if(category == CAT_BUILDER){
			// Add the new builder
			BuilderTracker* builderTracker = new BuilderTracker;
			builderTracker->builderID = unit;
			builderTracker->buildTaskId = 0;
			builderTracker->taskPlanId = 0;
			builderTracker->factoryId = 0;
			builderTracker->stuckCount = 0;
			builderTracker->customOrderId = 0;
			builderTracker->commandOrderPushFrame = -2; // Under construction
			builderTracker->categoryMaker = -1;
			builderTracker->idleStartFrame = -2; // Wait for the first idle call, as this unit might be under construction
			BuilderTrackers.push_back(builderTracker);
		}
		
		if(category == CAT_MMAKER){
			MMakerAdd(unit);
		}

	}
}
Пример #2
0
// called when unit nanoframe first created
// (CEconomyTracker deals with UnitFinished())
void CUnitHandler::UnitCreated(int unitID) {
	UnitCategory ucat = ai->ut->GetCategory(unitID);
	const UnitDef* udef = ai->cb->GetUnitDef(unitID);

	if (ucat != CAT_LAST) {
		assert(ai->GetUnit(unitID)->isDead);
		ai->GetUnit(unitID)->isDead = false;

		AllUnitsByCat[ucat].push_back(unitID);
		AllUnitsByType[udef->id].push_back(unitID);

		if (ucat == CAT_FACTORY) {
			FactoryAdd(unitID);
		}

		BuildTaskCreate(unitID);

		if (ucat == CAT_BUILDER) {
			// add the new builder
			BuilderTracker* builderTracker = new BuilderTracker();
			builderTracker->builderID      = unitID;
			builderTracker->buildTaskId    = 0;
			builderTracker->taskPlanId     = 0;
			builderTracker->factoryId      = 0;
			builderTracker->stuckCount     = 0;
			// under construction
			builderTracker->commandOrderPushFrame = -2;
			builderTracker->categoryMaker = CAT_LAST;
			// wait for the first idle call, as this unit might be under construction
			builderTracker->idleStartFrame = -2;
			BuilderTrackers.push_back(builderTracker);
		}

		if (ucat == CAT_MMAKER) {
			MMakerAdd(unitID);
		}
		if (ucat == CAT_MEX) {
			MetalExtractorAdd(unitID);
		}

		if (ucat == CAT_NUKE) {
			NukeSiloAdd(unitID);
		}
	}
	const bool iscommander = CUNIT::IsCommander(udef);

	if ( iscommander && udef->canDGun) {
		ai->dgunConHandler->AddController(unitID);
	} else {
		ai->GetUnit(unitID)->SetFireState(2);
	}
}
Пример #3
0
// called when unit nanoframe first created
// (CEconomyTracker deals with UnitFinished())
void CUnitHandler::UnitCreated(int unit) {
	int category = ai->ut->GetCategory(unit);
	const UnitDef* newUnitDef = ai->cb->GetUnitDef(unit);

	if (category != -1) {
		AllUnitsByCat[category].push_back(unit);
		AllUnitsByType[newUnitDef->id].push_back(unit);

		if (category == CAT_FACTORY) {
			FactoryAdd(unit);
		}

		BuildTaskCreate(unit);

		if (category == CAT_BUILDER) {
			// add the new builder
			BuilderTracker* builderTracker = new BuilderTracker;
			builderTracker->builderID = unit;
			builderTracker->buildTaskId = 0;
			builderTracker->taskPlanId = 0;
			builderTracker->factoryId = 0;
			builderTracker->stuckCount = 0;
			builderTracker->customOrderId = 0;
			// under construction
			builderTracker->commandOrderPushFrame = -2;
			builderTracker->categoryMaker = -1;
			// wait for the first idle call, as this unit might be under construction
			builderTracker->idleStartFrame = -2;
			BuilderTrackers.push_back(builderTracker);
		}

		if (category == CAT_MMAKER) {
			MMakerAdd(unit);
		}
		if (category == CAT_MEX) {
			MetalExtractorAdd(unit);
		}

		if (category == CAT_NUKE) {
			NukeSiloAdd(unit);
		}
	}
}