Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Ext/Techno/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
206 changes: 111 additions & 95 deletions src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TechnoClass*>(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<TechnoClass*>(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<InfantryClass*>(pTarget);
if (pInf->IsDisguised()) {
pInf->ClearDisguise();
}
}
if (pTarget->WhatAmI() == AbstractType::Infantry)
{
auto pInf = abstract_cast<InfantryClass*>(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);
}