Skip to content

Commit 5e6e4d4

Browse files
committed
Fix AirburstWeapon... cannot fire Arcing bullets correctly
1 parent eaccfff commit 5e6e4d4

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

src/Ext/Bullet/Body.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,38 @@ void BulletExt::SimulatedFiringUnlimbo(BulletClass* pBullet, HouseClass* pHouse,
317317
// House
318318
BulletExt::ExtMap.Find(pBullet)->FirerHouse = pHouse;
319319

320-
if (pBullet->Type->FirersPalette)
320+
const auto pType = pBullet->Type;
321+
322+
// Palette
323+
if (pType->FirersPalette)
321324
pBullet->InheritedColor = pHouse->ColorSchemeIndex;
322325

323326
// Velocity
324327
auto velocity = BulletVelocity::Empty;
325328

326-
if (randomVelocity)
329+
// If someone asks me, I would say Arcing is just a piece of shit
330+
// But there are still people who like to use it, so anyway, it has been fixed
331+
if (pType->Arcing)
332+
{
333+
// The target must exist during launch
334+
const auto targetCoords = pBullet->Target->GetCenterCoords();
335+
const auto gravity = BulletTypeExt::GetAdjustedGravity(pType);
336+
const auto horizontalDistance = Point2D{targetCoords.X, targetCoords.Y}.DistanceFrom(Point2D{sourceCoords.X, sourceCoords.Y});
337+
338+
if (horizontalDistance < 1e-10 || !pBullet->Speed)
339+
{
340+
velocity.Z = pBullet->Speed;
341+
}
342+
else
343+
{
344+
const auto mult = pBullet->Speed / horizontalDistance;
345+
const auto distanceCoords = targetCoords - sourceCoords;
346+
velocity.X = static_cast<double>(distanceCoords.X) * mult;
347+
velocity.Y = static_cast<double>(distanceCoords.Y) * mult;
348+
velocity.Z = static_cast<double>(distanceCoords.Z) * mult + (gravity * horizontalDistance) / (2 * pBullet->Speed);
349+
}
350+
}
351+
else if (randomVelocity)
327352
{
328353
DirStruct dir;
329354
dir.SetValue<5>(ScenarioClass::Instance->Random.RandomRanged(0, 31));

src/Ext/Rules/Body.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
263263
this->ProneSpeed_Crawls.Read(exINI, GameStrings::General, "ProneSpeed.Crawls");
264264
this->ProneSpeed_NoCrawls.Read(exINI, GameStrings::General, "ProneSpeed.NoCrawls");
265265

266-
this->DamagedSpeed.Read(exINI, GameStrings::General, "DamagedSpeed");
266+
this->DamagedSpeed.Read(exINI, GameStrings::General, "DamagedSpeed");
267267

268268
this->HarvesterScanAfterUnload.Read(exINI, GameStrings::General, "HarvesterScanAfterUnload");
269269

@@ -487,7 +487,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
487487
.Process(this->BuildingTypeSelectable)
488488
.Process(this->ProneSpeed_Crawls)
489489
.Process(this->ProneSpeed_NoCrawls)
490-
.Process(this->DamagedSpeed)
490+
.Process(this->DamagedSpeed)
491491
.Process(this->HarvesterScanAfterUnload)
492492
;
493493
}

src/Ext/Rules/Body.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class RulesExt
216216
Valueable<double> ProneSpeed_Crawls;
217217
Valueable<double> ProneSpeed_NoCrawls;
218218

219-
Valueable<double> DamagedSpeed;
219+
Valueable<double> DamagedSpeed;
220220

221221
Valueable<bool> HarvesterScanAfterUnload;
222222

@@ -306,7 +306,7 @@ class RulesExt
306306
, ForceShield_ExtraTintIntensity { 0.0 }
307307
, AllowWeaponSelectAgainstWalls { false }
308308
, ColorAddUse8BitRGB { false }
309-
, ROF_RandomDelay { { 0 ,2 } }
309+
, ROF_RandomDelay { { 0 ,2 } }
310310
, ToolTip_Background_Color { { 0, 0, 0 } }
311311
, ToolTip_Background_Opacity { 100 }
312312
, ToolTip_Background_BlurSize { 0.0f }
@@ -321,10 +321,10 @@ class RulesExt
321321
, IsVoiceCreatedGlobal { false }
322322
, SelectionFlashDuration { 0 }
323323
, DrawInsignia_OnlyOnSelected { false }
324-
, DrawInsignia_AdjustPos_Infantry { { 5, 2 } }
325-
, DrawInsignia_AdjustPos_Buildings { { 10, 6 } }
324+
, DrawInsignia_AdjustPos_Infantry { { 5, 2 } }
325+
, DrawInsignia_AdjustPos_Buildings { { 10, 6 } }
326326
, DrawInsignia_AdjustPos_BuildingsAnchor {}
327-
, DrawInsignia_AdjustPos_Units { { 10, 6 } }
327+
, DrawInsignia_AdjustPos_Units { { 10, 6 } }
328328
, DrawInsignia_UsePixelSelectionBracketDelta { { false } }
329329
, Promote_VeteranAnimation {}
330330
, Promote_EliteAnimation {}
@@ -382,7 +382,7 @@ class RulesExt
382382
, ProneSpeed_Crawls { 0.67 }
383383
, ProneSpeed_NoCrawls { 1.5 }
384384

385-
, DamagedSpeed { 0.75 }
385+
, DamagedSpeed { 0.75 }
386386

387387
, HarvesterScanAfterUnload { false }
388388
{ }

src/Ext/WarheadType/Body.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
291291
this->KillWeapon_Affects.Read(exINI, pSection, "KillWeapon.Affects");
292292
this->KillWeapon_OnFirer_Affects.Read(exINI, pSection, "KillWeapon.OnFirer.Affects");
293293

294-
this->ElectricAssaultLevel.Read(exINI, pSection, "ElectricAssaultLevel");
294+
this->ElectricAssaultLevel.Read(exINI, pSection, "ElectricAssaultLevel");
295295

296296
this->AirstrikeTargets.Read(exINI, pSection, "AirstrikeTargets");
297297

@@ -544,7 +544,7 @@ void WarheadTypeExt::ExtData::Serialize(T& Stm)
544544
.Process(this->KillWeapon_Affects)
545545
.Process(this->KillWeapon_OnFirer_Affects)
546546

547-
.Process(this->ElectricAssaultLevel)
547+
.Process(this->ElectricAssaultLevel)
548548

549549
.Process(this->AirstrikeTargets)
550550

src/Ext/WarheadType/Body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class WarheadTypeExt
173173
Valueable<AffectedTarget> KillWeapon_Affects;
174174
Valueable<AffectedTarget> KillWeapon_OnFirer_Affects;
175175

176-
Valueable<int> ElectricAssaultLevel;
176+
Valueable<int> ElectricAssaultLevel;
177177

178178
Valueable<AffectedTarget> AirstrikeTargets;
179179

src/Misc/Hooks.BugFixes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ DEFINE_HOOK(0x6FC617, TechnoClass_GetFireError_Spawner, 0x8)
13551355
int __fastcall Check2DDistanceInsteadOf3D(ObjectClass* pSource, void* _, AbstractClass* pTarget)
13561356
{
13571357
// At present, it seems that aircraft use their own mapcoords and the team destination's mapcoords to check.
1358-
// During the previous test, it was found that if the aircraft uses this and needs to return to the airport
1358+
// During the previous test, it was found that if the aircraft uses this and needs to return to the airport
13591359
// with the script first, it will interrupt the remaining tasks for unknown reasons - CrimRecya
13601360
return (pSource->IsInAir() && pSource->WhatAmI() != AbstractType::Aircraft) // Jumpjets or sth in the air
13611361
? (pSource->DistanceFrom(pTarget) * 2) // 2D distance (2x is the bonus to units in the air)
@@ -1648,7 +1648,7 @@ DEFINE_HOOK(0x5F530B, ObjectClass_Disappear_AnnounceExpiredPointer, 0x6)
16481648
GET(ObjectClass*, pThis, ESI);
16491649
GET_STACK(bool, removed, STACK_OFFSET(0x8, 0x4));
16501650
R->ECX(pThis);
1651-
// Do not working for buildings for now, because it will break some vanilla building tracking.
1651+
// Do not working for buildings for now, because it will break some vanilla building tracking.
16521652
// Hoping someone could investigate thoroughly and enable it for buildings.
16531653
R->EDX(((pThis->AbstractFlags & AbstractFlags::Foot) != AbstractFlags::None) ? Disappear::removed : removed);
16541654
Disappear::removed = false;

0 commit comments

Comments
 (0)