Пример #1
0
void XAICUnitDGunControllerHandler::OnEvent(const XAIIEvent* e) {
	switch (e->type) {
		case XAI_EVENT_UNIT_FINISHED: {
			const XAIUnitFinishedEvent* ee = dynamic_cast<const XAIUnitFinishedEvent*>(e);

			const XAICUnit*   unit = xaih->unitHandler->GetUnitByID(ee->unitID);
			const XAIUnitDef* uDef = unit->GetUnitDefPtr();

			if (uDef->GetDGunWeaponDef() != 0) {
				AddController(ee->unitID);
			}
		} break;

		case XAI_EVENT_UNIT_DESTROYED: {
			const XAIUnitDestroyedEvent* ee = dynamic_cast<const XAIUnitDestroyedEvent*>(e);

			// silly to call for every destroyed unit, but
			// we can no longer retrieve the UnitDef here
			DelController(ee->unitID);
		} break;

		case XAI_EVENT_ENEMY_DESTROYED: {
			const XAIEnemyDestroyedEvent* ee = dynamic_cast<const XAIEnemyDestroyedEvent*>(e);

			std::map<int, XAICUnitDGunController*>::iterator it;

			for (it = controllers.begin(); it != controllers.end(); it++) {
				it->second->EnemyDestroyed(ee->attackerID, ee->unitID);
			}
		} break;

		case XAI_EVENT_UPDATE: {
			std::map<int, XAICUnitDGunController*>::iterator it;

			for (it = controllers.begin(); it != controllers.end(); it++) {
				it->second->Update();
			}
		} break;

		default: {
		} break;
	}
}
Пример #2
0
void CDGunControllerHandler::Update(int frame) {
	std::list<int> deadCons;
	std::list<int>::iterator deadConIt;

	std::map<int, CDGunController*>::iterator conIt;

	for (conIt = controllers.begin(); conIt != controllers.end(); conIt++) {
		const UnitDef* udef = ai->cb->GetUnitDef(conIt->first);

		if (udef == NULL || !udef->canDGun) {
			deadCons.push_back(conIt->first);
		} else {
			conIt->second->Update(frame);
		}
	}

	for (deadConIt = deadCons.begin(); deadConIt != deadCons.end(); deadConIt++) {
		// probably should tie this into [Notify]UnitDestroyed()
		DelController(*deadConIt);
	}
}