예제 #1
0
bool SW_EMPulse::Activate(SuperClass* pThis, const CellStruct &Coords, bool IsPlayer)
{
	auto pType = pThis->Type;
	auto pData = SWTypeExt::ExtMap.Find(pType);

	if(!pData) {
		return false;
	}

	auto pOwner = pThis->Owner;
	pOwner->EMPTarget = Coords;

	// the maximum number of buildings to fire. negative means all.
	const auto Count = (pData->SW_MaxCount >= 0)
		? static_cast<size_t>(pData->SW_MaxCount)
		: std::numeric_limits<size_t>::max();

	// if linked, only one needs to be in range (and CanFireAt checked that already).
	const bool ignoreRange = pData->EMPulse_Linked || pData->EMPulse_TargetSelf;

	auto IsEligible = [&](BuildingClass* pBld) {
		return IsLaunchSiteEligible(pData, Coords, pBld, ignoreRange);
	};

	// only call on up to Count buildings that suffice IsEligible
	Helpers::Alex::for_each_if_n(pOwner->Buildings.begin(), pOwner->Buildings.end(),
		Count, IsEligible, [&](BuildingClass* pBld)
	{
		if(!pData->EMPulse_TargetSelf) {
			// set extended properties
			auto pExt = TechnoExt::ExtMap.Find(pBld);
			pExt->SuperWeapon = pThis;
			pExt->SuperTarget = MapClass::Instance->TryGetCellAt(Coords);

			// setup the cannon and start the fire mission
			pBld->FiringSWType = pType->ArrayIndex;
			pBld->QueueMission(Mission::Missile, false);
			pBld->NextMission();
		} else {
			// create a bullet and detonate immediately
			if(auto pWeapon = pBld->GetWeapon(0)->WeaponType) {
				auto pExt = BulletTypeExt::ExtMap.Find(pWeapon->Projectile);

				if(auto pBullet = pExt->CreateBullet(pBld, pBld, pWeapon)) {
					pBullet->SetWeaponType(pWeapon);
					pBullet->Remove();
					pBullet->Detonate(BuildingExt::GetCenterCoords(pBld));
					pBullet->Release();
				}
			}
		}
	});

	return true;
}
예제 #2
0
bool NewSWType::HasLaunchSite(SWTypeExt::ExtData* pSWType, HouseClass* pOwner, const CellStruct &Coords) const
{
	// the quick way out: no range restriction at all
	auto range = GetLaunchSiteRange(pSWType);

	if(range.first < 0.0 && range.second < 0.0) {
		return true;
	}

	return std::any_of(pOwner->Buildings.begin(), pOwner->Buildings.end(), [=, &Coords](BuildingClass* pBld) {
		return IsLaunchSiteEligible(pSWType, Coords, pBld, false);
	});
}