diff --git a/src/Ext/Techno/Body.cpp b/src/Ext/Techno/Body.cpp index a2f376b789..4a7eb41ba0 100644 --- a/src/Ext/Techno/Body.cpp +++ b/src/Ext/Techno/Body.cpp @@ -18,13 +18,9 @@ void TechnoExt::ApplyMindControlRangeLimit(TechnoClass* pThis) if (auto Capturer = pThis->MindControlledBy) { auto pCapturerExt = TechnoTypeExt::ExtMap.Find(Capturer->GetTechnoType()); - if (pCapturerExt && pCapturerExt->MindControlRangeLimit > 0 && pThis->DistanceFrom(Capturer) > pCapturerExt->MindControlRangeLimit * 256.0) - { + if (pCapturerExt && pCapturerExt->MindControlRangeLimit > 0 + && pThis->DistanceFrom(Capturer) > pCapturerExt->MindControlRangeLimit * 256.0) Capturer->CaptureManager->FreeUnit(pThis); - - if (!pThis->IsHumanControlled) - pThis->QueueMission(Mission::Hunt, 0); - } } } diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index 99cb6dc949..caed42c648 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -12,115 +12,131 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse, BulletClass* pBullet, CoordStruct coords) { - if (pHouse) { - if (this->BigGap) { - for (auto pOtherHouse : *HouseClass::Array) { - if (pOtherHouse->ControlledByHuman() && // Not AI - !pOtherHouse->IsObserver() && // Not Observer - !pOtherHouse->Defeated && // Not Defeated - pOtherHouse != pHouse && // Not pThisHouse - !pHouse->IsAlliedWith(pOtherHouse)) // Not Allied - { - pOtherHouse->ReshroudMap(); - } - } - } - - if (this->SpySat) { - MapClass::Instance->Reveal(pHouse); - } - - if (this->TransactMoney) { - pHouse->TransactMoney(this->TransactMoney); - } - } - - this->RandomBuffer = ScenarioClass::Instance->Random.RandomDouble(); - - // List all Warheads here that respect CellSpread - const bool isCellSpreadWarhead = - this->RemoveDisguise || - this->RemoveMindControl || - this->Crit_Chance; - - const float cellSpread = this->OwnerObject()->CellSpread; - if (cellSpread && isCellSpreadWarhead) { - auto items = Helpers::Alex::getCellSpreadItems(coords, cellSpread, true); - for (auto pTarget : items) { - this->DetonateOnOneUnit(pHouse, pTarget); - } - } - else if (pBullet && isCellSpreadWarhead) { - if (auto pTarget = abstract_cast(pBullet->Target)) { - this->DetonateOnOneUnit(pHouse, pTarget); - } - } + if (pHouse) + { + if (this->BigGap) + { + for (auto pOtherHouse : *HouseClass::Array) + { + if (pOtherHouse->ControlledByHuman() && // Not AI + !pOtherHouse->IsObserver() && // Not Observer + !pOtherHouse->Defeated && // Not Defeated + pOtherHouse != pHouse && // Not pThisHouse + !pHouse->IsAlliedWith(pOtherHouse)) // Not Allied + { + pOtherHouse->ReshroudMap(); + } + } + } + + if (this->SpySat) + { + MapClass::Instance->Reveal(pHouse); + } + + if (this->TransactMoney) + { + pHouse->TransactMoney(this->TransactMoney); + } + } + + this->RandomBuffer = ScenarioClass::Instance->Random.RandomDouble(); + + // List all Warheads here that respect CellSpread + const bool isCellSpreadWarhead = + this->RemoveDisguise || + this->RemoveMindControl || + this->Crit_Chance; + + const float cellSpread = this->OwnerObject()->CellSpread; + if (cellSpread && isCellSpreadWarhead) + { + auto items = Helpers::Alex::getCellSpreadItems(coords, cellSpread, true); + for (auto pTarget : items) + { + this->DetonateOnOneUnit(pHouse, pTarget); + } + } + else if (pBullet && isCellSpreadWarhead) + { + if (auto pTarget = abstract_cast(pBullet->Target)) + { + this->DetonateOnOneUnit(pHouse, pTarget); + } + } } void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner) { - if (!pTarget || pTarget->InLimbo || !pTarget->IsAlive || !pTarget->Health) { - return; - } - - if (!this->CanTargetHouse(pHouse, pTarget)) { - return; - } - - if (this->RemoveDisguise) { - this->ApplyRemoveDisguiseToInf(pHouse, pTarget); - } - - if (this->RemoveMindControl) { - this->ApplyRemoveMindControl(pHouse, pTarget); - } - - if (this->Crit_Chance) { - this->ApplyCrit(pHouse, pTarget, pOwner); - } + if (!pTarget || pTarget->InLimbo || !pTarget->IsAlive || !pTarget->Health) + { + return; + } + + if (!this->CanTargetHouse(pHouse, pTarget)) + { + return; + } + + if (this->RemoveDisguise) + { + this->ApplyRemoveDisguiseToInf(pHouse, pTarget); + } + + if (this->RemoveMindControl) + { + this->ApplyRemoveMindControl(pHouse, pTarget); + } + + if (this->Crit_Chance) + { + this->ApplyCrit(pHouse, pTarget, pOwner); + } } void WarheadTypeExt::ExtData::ApplyRemoveMindControl(HouseClass* pHouse, TechnoClass* pTarget) { - if (auto pController = pTarget->MindControlledBy) { - pTarget->MindControlledBy->CaptureManager->FreeUnit(pTarget); - if (!pTarget->IsHumanControlled) { - pTarget->QueueMission(Mission::Hunt, false); - } - } + if (auto pController = pTarget->MindControlledBy) + pTarget->MindControlledBy->CaptureManager->FreeUnit(pTarget); } void WarheadTypeExt::ExtData::ApplyRemoveDisguiseToInf(HouseClass* pHouse, TechnoClass* pTarget) { - if (pTarget->WhatAmI() == AbstractType::Infantry) { - auto pInf = abstract_cast(pTarget); - if (pInf->IsDisguised()) { - pInf->ClearDisguise(); - } - } + if (pTarget->WhatAmI() == AbstractType::Infantry) + { + auto pInf = abstract_cast(pTarget); + if (pInf->IsDisguised()) + { + pInf->ClearDisguise(); + } + } } void WarheadTypeExt::ExtData::ApplyCrit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* pOwner) { - //auto& random = ScenarioClass::Instance->Random; - const double dice = this->RandomBuffer; //double(random.RandomRanged(1, 10)) / 10; - - if (this->Crit_Chance < dice) { - return; - } - - if (auto pTypeExt = TechnoTypeExt::ExtMap.Find(pTarget->GetTechnoType())) { - if (pTypeExt->ImmuneToCrit) - return; - } - - if (!this->IsCellEligible(pTarget->GetCell(), this->Crit_Affects)) { - return; - } - - if (!this->IsTechnoEligible(pTarget, this->Crit_Affects)) { - return; - } - - pTarget->ReceiveDamage(&this->Crit_ExtraDamage, 0, this->OwnerObject(), pOwner, false, false, pHouse); + //auto& random = ScenarioClass::Instance->Random; + const double dice = this->RandomBuffer; //double(random.RandomRanged(1, 10)) / 10; + + if (this->Crit_Chance < dice) + { + return; + } + + if (auto pTypeExt = TechnoTypeExt::ExtMap.Find(pTarget->GetTechnoType())) + { + if (pTypeExt->ImmuneToCrit) + return; + } + + if (!this->IsCellEligible(pTarget->GetCell(), this->Crit_Affects)) + { + return; + } + + if (!this->IsTechnoEligible(pTarget, this->Crit_Affects)) + { + return; + } + + pTarget->ReceiveDamage(&this->Crit_ExtraDamage, 0, this->OwnerObject(), pOwner, false, false, pHouse); }