Skip to content

Commit

Permalink
Support for straight trail
Browse files Browse the repository at this point in the history
  • Loading branch information
secsome committed Nov 13, 2021
1 parent b5e82b6 commit 775e65e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ Bolt.Disable3=false ; boolean
### Customizable projectile gravity

- You can now specify individual projectile gravity.
- Set `Gravity=0` with an arcing projectile can create a straight trail.
- Set `Gravity.HeightFix=true` allows the projectile to hit target which is not at the same height while `Gravity=0`.

In `rulesmd.ini`:
```ini
[SOMEPROJECTILE] ; Projectile
Gravity=6.0 ; double
[SOMEPROJECTILE] ; Projectile
Gravity=6.0 ; double
Gravity.HeightFix=false ; boolean
```
25 changes: 25 additions & 0 deletions src/Ext/Bullet/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,29 @@ DEFINE_HOOK(0x773087, WeaponTypeClass_GetSpeed_ApplyGravity, 0x6)
__asm { fld nGravity };

return 0x7730A3;
}

DEFINE_HOOK(0x6FF031, TechnoClass_FireAt_ReverseVelocityWhileGravityIsZero, 0xA)
{
GET(BulletClass*, pBullet, EBX);

auto const pData = BulletTypeExt::ExtMap.Find(pBullet->Type);

if (pBullet->Type->Arcing && BulletTypeExt::GetAdjustedGravity(pBullet->Type) == 0.0)
{
pBullet->Velocity *= -1;
if (pData->Gravity_HeightFix)
{
auto speed = pBullet->Velocity.Magnitude();

pBullet->Velocity.X = static_cast<double>(pBullet->TargetCoords.X - pBullet->SourceCoords.X);
pBullet->Velocity.Y = static_cast<double>(pBullet->TargetCoords.Y - pBullet->SourceCoords.Y);
pBullet->Velocity.Z = static_cast<double>(pBullet->TargetCoords.Z - pBullet->SourceCoords.Z);

auto magnitude = pBullet->Velocity.Magnitude();
pBullet->Velocity *= speed / magnitude;
}
}

return 0;
}
2 changes: 2 additions & 0 deletions src/Ext/BulletType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void BulletTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)

this->Interceptable.Read(exINI, pSection, "Interceptable");
this->Gravity.Read(exINI, pSection, "Gravity");
this->Gravity_HeightFix.Read(exINI, pSection, "Gravity.HeightFix");

INI_EX exArtINI(CCINIClass::INI_Art);

Expand All @@ -41,6 +42,7 @@ void BulletTypeExt::ExtData::Serialize(T& Stm)
.Process(this->Interceptable)
.Process(this->LaserTrail_Types)
.Process(this->Gravity)
.Process(this->Gravity_HeightFix)
;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Ext/BulletType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class BulletTypeExt
Valueable<bool> Interceptable;
ValueableIdxVector<LaserTrailTypeClass> LaserTrail_Types;
Nullable<double> Gravity;
Valueable<bool> Gravity_HeightFix;

ExtData(BulletTypeClass* OwnerObject) : Extension<BulletTypeClass>(OwnerObject),
Interceptable(false),
LaserTrail_Types(),
Gravity()
Gravity(),
Gravity_HeightFix(false)
{ }

virtual ~ExtData() = default;
Expand Down

0 comments on commit 775e65e

Please sign in to comment.