Exemple #1
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);
	}
}
// 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);
		}
	}
}