Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Customized] Undeploy building on impact #1468

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ This page lists all the individual contributions to the project by their author.
- Fix for sidebar not updating queued unit numbers when on hold
- New Parabola trajectory
- Enhanced Bombard trajectory
- Sell or undeploy building on impact
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
14 changes: 14 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,20 @@ In `rulesmd.ini`:
NotHuman.DeathSequence= ; integer (1 to 5)
```

### Sell or undeploy building on impact

- Warheads with `BuildingSell` can now sell buildings with build up image. It has a higher priority than `BuildingUndeploy`.
- Warheads with `BuildingUndeploy` can now undeploy buildings with `UndeploysInto`.
- `BuildingUndeploy.Leave` controls whether need to let them move to low threat locations nearby. The threat degree here is calculated using the technos' cost. If a nearby techno has no primary weapons or is owned by your allies, it will not be included.

In `rulesmd.ini`:
```ini
[SOMEWARHEAD] ; Warhead
BuildingSell=false ; boolean
BuildingUndeploy=false ; boolean
BuildingUndeploy.Leave=false ; boolean
```

## Weapons

### AreaFire target customization
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ New:
- Enhanced Bombard trajectory (by CrimRecya & Ollerus, based on knowledge of NaotoYuuki)
- Toggle waypoint for building (by TaranDahl)
- Bunkerable checks dehardcode (by TaranDahl)
- Sell or undeploy building on impact (by CrimRecya)

Vanilla fixes:
- Aircraft will now behave as expected according to it's `MovementZone` and `SpeedType` when moving onto different surfaces. In particular, this fixes erratic behavior when vanilla aircraft is ordered to move onto water surface and instead the movement order changes to a shore nearby (by CrimRecya)
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Building/Hooks.Selling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool __forceinline BuildingExt::CanUndeployOnSell(BuildingClass* pThis)
if (!GameModeOptionsClass::Instance->MCVRedeploy)
return false;
// or MindControlledBy YURIX (why? for balance?)
if (pThis->MindControlledBy || !pThis->Owner->IsControlledByHuman())
if (pThis->MindControlledBy)
return false;
}

Expand Down
12 changes: 11 additions & 1 deletion src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->SuppressReflectDamage.Read(exINI, pSection, "SuppressReflectDamage");
this->SuppressReflectDamage_Types.Read(exINI, pSection, "SuppressReflectDamage.Types");

this->BuildingSell.Read(exINI, pSection, "BuildingSell");
this->BuildingUndeploy.Read(exINI, pSection, "BuildingUndeploy");
this->BuildingUndeploy_Leave.Read(exINI, pSection, "BuildingUndeploy.Leave");

this->CombatAlert_Suppress.Read(exINI, pSection, "CombatAlert.Suppress");

// Convert.From & Convert.To
Expand Down Expand Up @@ -321,6 +325,8 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
|| this->AttachEffects.AttachTypes.size() > 0
|| this->AttachEffects.RemoveTypes.size() > 0
|| this->AttachEffects.RemoveGroups.size() > 0
|| this->BuildingSell
|| this->BuildingUndeploy
);

char tempBuffer[32];
Expand Down Expand Up @@ -492,8 +498,12 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
.Process(this->CLIsBlack)
.Process(this->Particle_AlphaImageIsLightFlash)

.Process(this->BuildingSell)
.Process(this->BuildingUndeploy)
.Process(this->BuildingUndeploy_Leave)

.Process(this->CombatAlert_Suppress)

// Ares tags
.Process(this->AffectsEnemies)
.Process(this->AffectsOwner)
Expand Down
9 changes: 9 additions & 0 deletions src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class WarheadTypeExt
Valueable<bool> SuppressReflectDamage;
ValueableVector<AttachEffectTypeClass*> SuppressReflectDamage_Types;

Valueable<bool> BuildingSell;
Valueable<bool> BuildingUndeploy;
Valueable<bool> BuildingUndeploy_Leave;

Nullable<bool> CombatAlert_Suppress;

// Ares tags
Expand Down Expand Up @@ -305,6 +309,10 @@ class WarheadTypeExt
, SuppressReflectDamage { false }
, SuppressReflectDamage_Types {}

, BuildingSell { false }
, BuildingUndeploy { false }
, BuildingUndeploy_Leave { false }

, CombatAlert_Suppress {}

, AffectsEnemies { true }
Expand Down Expand Up @@ -355,6 +363,7 @@ class WarheadTypeExt
void ApplyCrit(HouseClass* pHouse, TechnoClass* pTarget, TechnoClass* Owner, TechnoExt::ExtData* pTargetExt);
void ApplyShieldModifiers(TechnoClass* pTarget, TechnoExt::ExtData* pTargetExt);
void ApplyAttachEffects(TechnoClass* pTarget, HouseClass* pInvokerHouse, TechnoClass* pInvoker);
void ApplyBuildingUndeploy(TechnoClass* pTarget);
double GetCritChance(TechnoClass* pFirer) const;
};

Expand Down
83 changes: 83 additions & 0 deletions src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass*
if (this->AttachEffects.AttachTypes.size() > 0 || this->AttachEffects.RemoveTypes.size() > 0 || this->AttachEffects.RemoveGroups.size() > 0)
this->ApplyAttachEffects(pTarget, pHouse, pOwner);

if (this->BuildingSell || this->BuildingUndeploy)
this->ApplyBuildingUndeploy(pTarget);

#ifdef LOCO_TEST_WARHEADS
if (this->InflictLocomotor)
this->ApplyLocomotorInfliction(pTarget);
Expand All @@ -180,6 +183,86 @@ void WarheadTypeExt::ExtData::DetonateOnOneUnit(HouseClass* pHouse, TechnoClass*

}

void WarheadTypeExt::ExtData::ApplyBuildingUndeploy(TechnoClass* pTarget)
{
const auto pBuilding = abstract_cast<BuildingClass*>(pTarget);

if (!pBuilding || !pBuilding->IsAlive || !pBuilding->IsOnMap || pBuilding->InLimbo)
return;

const auto mission = pBuilding->CurrentMission;

if (mission == Mission::Construction || mission == Mission::Selling)
return;

if (this->BuildingSell)
{
pBuilding->Sell(1);
return;
}

const auto pType = pBuilding->Type;

if (!pType->UndeploysInto || (pType->ConstructionYard && !GameModeOptionsClass::Instance->MCVRedeploy))
return;

auto cell = pBuilding->GetMapCoords();
const auto width = pType->GetFoundationWidth();
const auto height = pType->GetFoundationHeight(false);

if (width > 2 || height > 2)
cell += CellStruct { 1, 1 };

if (this->BuildingUndeploy_Leave)
{
const auto pHouse = pBuilding->Owner;
const auto pItems = Helpers::Alex::getCellSpreadItems(pBuilding->GetCoords(), 20);
int record[16] = {0};

for (const auto& pItem : pItems)
{
if ((!pHouse || !pHouse->IsAlliedWith(pItem)) && pItem->IsArmed())
record[pBuilding->GetTargetDirection(pItem).GetValue<4>()] += pItem->GetTechnoType()->Cost;
}

int costs = 0;
int dir = 0;

for (int i = 16; i < 32; ++i)
{
int newCosts = 0;

for (int j = -7; j < 8; ++j)
newCosts += ((8 - abs(j)) * record[(i + j) & 15]);

if (newCosts > costs)
{
dir = (i - 16);
costs = newCosts;
}
}

if (!costs)
dir = ScenarioClass::Instance->Random.RandomRanged(0, 15);

const double radian = -(((dir - 4) / 16.0) * Math::TwoPi);

cell.X -= static_cast<short>(14 * cos(radian));
cell.Y += static_cast<short>(14 * sin(radian));

const auto newCell = MapClass::Instance->NearByLocation(cell, pType->UndeploysInto->SpeedType, -1, pType->UndeploysInto->MovementZone,
false, (width + 2), (height + 2), false, false, false, false, CellStruct::Empty, false, false);

if (newCell != CellStruct::Empty)
cell = newCell;
}

if (const auto pCell = MapClass::Instance->TryGetCellAt(cell))
pBuilding->SetArchiveTarget(pCell);

pBuilding->Sell(1);
}

void WarheadTypeExt::ExtData::ApplyShieldModifiers(TechnoClass* pTarget, TechnoExt::ExtData* pTargetExt = nullptr)
{
if (!pTargetExt)
Expand Down