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
6 changes: 6 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ClCompile Include="src\Commands\Commands.cpp" />
<ClCompile Include="src\Commands\Dummy.h" />
<ClCompile Include="src\Ext\AnimType\Hooks.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\BombardTrajectory.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.cpp" />
<ClCompile Include="src\Ext\Bullet\Trajectories\StraightTrajectory.cpp" />
<ClCompile Include="src\Ext\Scenario\Hooks.Variables.cpp" />
<ClCompile Include="src\Ext\Sidebar\Body.cpp" />
<ClCompile Include="src\Ext\Sidebar\Hooks.cpp" />
Expand Down Expand Up @@ -117,6 +120,9 @@
<ClInclude Include="src\Commands\ObjectInfo.h" />
<ClInclude Include="src\Commands\Commands.h" />
<ClInclude Include="src\Commands\QuickSave.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\BombardTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\StraightTrajectory.h" />
<ClInclude Include="src\Ext\Sidebar\Body.h" />
<ClInclude Include="src\Ext\Anim\Body.h" />
<ClInclude Include="src\Ext\TAction\Body.h" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Credits
- **Belonit (Gluk-v48)** - project author (retired)
- **Kerbiter (Metadorius)** - project co-author, current maintainer ([Patreon](http://patreon.com/kerbiter))
- **Uranusian (Thrifinesma)** - developer, CN community ambassador ([Patreon](https://www.patreon.com/uranusian), [AliPay](http://tiebapic.baidu.com/forum/w%3D580/sign=4b04b953307f9e2f70351d002f31e962/b3f89909b3de9c823bd7f23a7b81800a18d84371.jpg))
- **secsome (SEC-SOME)** - developer ([Patreon](https://www.patreon.com/secsome))
- **secsome (SEC-SOME)** - developer
- **Otamaa (Fahroni, BoredEXE)** - developer ([PayPal](https://paypal.me/GeneralOtama))
- **FS-21** - developer
- **Starkku** - developer
Expand Down
4 changes: 1 addition & 3 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ Grinding.Weapon= ; WeaponType
### 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`.
- Setting `Gravity=0` is not recommended. It will cause the projectile unable to hit the target which is not at the same height. We'd suggest to use `Straight` Trajectory instead. See [here](New-or-Enhanced-Logics.md#projectile-trajectories).

In `rulesmd.ini`:
```ini
[SOMEPROJECTILE] ; Projectile
Gravity=6.0 ; double
Gravity.HeightFix=false ; boolean
```

## Technos
Expand Down
38 changes: 38 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,34 @@ Interceptor.EliteMinimumGuardRange=0.0 ; double
Interceptable=no ; boolean
```

### Projectile trajectories

- Projectiles can now have customizable trajectories.
- `Trajectory` should not be combined with original game's projectile trajectory logics (`Arcing`, `ROT` or `Inviso`).

#### Straight trajectory

- Self-explanatory, is a straight-shot trajectory.
- Initial speed is determined by weapon's `Trajectory.Speed`.

In `rulesmd.ini`
```ini
[SOMEPROJECTILE] ; Projectile
Trajectory=Straight ; Trajectory type
```

#### Bombard trajectory

- Similar trajectory to `Straight`, but targets a coordinate above the intended target (height determined by `Trajectory.Bombard.Height`). When the projectile approaches that coordinate, it will free fall and explodes when it hits the target or ground.
- Initial speed is determined by weapon's `Trajectory.Speed`.

In `rulesmd.ini`
```ini
[SOMEPROJECTILE] ; Projectile
Trajectory=Bombard ; Trajectory type
Trajectory.Bombard.Height=0.0 ; double
```

### Shrapnel enhancement
- Shrapnel behavior can be triggered on the ground and buildings.

Expand Down Expand Up @@ -1240,6 +1268,16 @@ Strafing.Shots=5 ; integer
Strafing.SimulateBurst=false ; bool
```

### Trajectory speed

- This sets projectile speed used by custom [projectile trajectories](#projectile-trajectories).

In `rulesmd.ini`:
```ini
[SOMEWEAPON] ; WeaponType
Trajectory.Speed=100.0 ; double
```

### Weapon targeting filter

- You can now specify which targets or houses a weapon can fire at. This also affects weapon selection, other than certain special cases where the selection is fixed.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ New:
- Feedback weapon (by Starkku)
- TerrainType & ore minimap color customization (by Starkku)
- Single-color weapon lasers (by Starkku)
- Customizable projectile trajectory (by secsome)

Vanilla fixes:
- Fixed laser drawing code to allow for thicker lasers in house color draw mode (by Kerbiter, ChrisLv_CN)
Expand Down
5 changes: 5 additions & 0 deletions src/Ext/Bullet/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ void BulletExt::ExtData::Serialize(T& Stm)
.Process(this->ShouldIntercept)
.Process(this->LaserTrails)
;

this->Trajectory = PhobosTrajectory::ProcessFromStream(Stm, this->Trajectory);
}

void BulletExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
Expand Down Expand Up @@ -119,6 +121,9 @@ DEFINE_HOOK(0x4665E9, BulletClass_DTOR, 0xA)
{
GET(BulletClass*, pItem, ESI);

if (auto pTraj = BulletExt::ExtMap.Find(pItem)->Trajectory)
GameDelete(pTraj);

BulletExt::ExtMap.Remove(pItem);
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Ext/Bullet/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <New/Entity/LaserTrailClass.h>

#include "Trajectories/PhobosTrajectory.h"

class BulletExt
{
public:
Expand All @@ -18,11 +20,14 @@ class BulletExt
Valueable<bool> Intercepted;
Valueable<bool> ShouldIntercept;
ValueableVector<std::unique_ptr<LaserTrailClass>> LaserTrails;

PhobosTrajectory* Trajectory;

ExtData(BulletClass* OwnerObject) : Extension<BulletClass>(OwnerObject)
, Intercepted { false }
, ShouldIntercept { false }
, LaserTrails {}
, Trajectory { nullptr }
{ }

virtual ~ExtData() = default;
Expand Down
27 changes: 1 addition & 26 deletions src/Ext/Bullet/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DEFINE_HOOK(0x4666F7, BulletClass_AI, 0x6)
if (pBulletExt && pBulletExt->LaserTrails.size())
{
CoordStruct location = pThis->GetCoords();
BulletVelocity velocity = pThis->Velocity;
const BulletVelocity& velocity = pThis->Velocity;

// We adjust LaserTrails to account for vanilla bug of drawing stuff one frame ahead.
// Pretty meh solution but works until we fix the bug - Kerbiter
Expand Down Expand Up @@ -155,31 +155,6 @@ DEFINE_HOOK(0x773087, WeaponTypeClass_GetSpeed_ApplyGravity, 0x6)
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;
}

DEFINE_HOOK(0x46A3D6, BulletClass_Shrapnel_Forced, 0xA)
{
enum { Shrapnel = 0x46A40C, Skip = 0x46ADCD };
Expand Down
95 changes: 95 additions & 0 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "BombardTrajectory.h"

#include <Ext/BulletType/Body.h>

bool BombardTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
{
this->PhobosTrajectoryType::Load(Stm, false);
Stm.Process(this->Height, false);
return true;
}

bool BombardTrajectoryType::Save(PhobosStreamWriter& Stm) const
{
this->PhobosTrajectoryType::Save(Stm);
Stm.Process(this->Height);
return true;
}

void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
{
this->Height = pINI->ReadDouble(pSection, "Trajectory.Bombard.Height", 0.0);
}

bool BombardTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
{
this->PhobosTrajectory::Load(Stm, false);

Stm
.Process(this->IsFalling)
.Process(this->Height)
;

return true;
}

bool BombardTrajectory::Save(PhobosStreamWriter& Stm) const
{
this->PhobosTrajectory::Save(Stm);

Stm
.Process(this->IsFalling)
.Process(this->Height)
;

return true;
}

void BombardTrajectory::OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity)
{
this->Height = this->GetTrajectoryType<BombardTrajectoryType>(pBullet)->Height + pBullet->TargetCoords.Z;

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>(this->Height - pBullet->SourceCoords.Z);
pBullet->Velocity *= this->GetTrajectorySpeed(pBullet) / pBullet->Velocity.Magnitude();
}

void BombardTrajectory::OnAI(BulletClass* pBullet)
{
// Close enough
if (pBullet->TargetCoords.DistanceFrom(pBullet->Location) < 100) // This value maybe adjusted?
{
pBullet->Explode(true);
pBullet->UnInit();
pBullet->LastMapCoords = CellClass::Coord2Cell(pBullet->Location);
}
}

void BombardTrajectory::OnAIVelocity(BulletClass* pBullet, BulletVelocity* pSpeed, BulletVelocity* pPosition)
{
if (!this->IsFalling)
{
pSpeed->Z += BulletTypeExt::GetAdjustedGravity(pBullet->Type);
if (pBullet->Location.Z + pBullet->Velocity.Z >= this->Height)
{
this->IsFalling = true;
pSpeed->X = 0.0;
pSpeed->Y = 0.0;
pSpeed->Z = 0.0;
pPosition->X = pBullet->TargetCoords.X;
pPosition->Y = pBullet->TargetCoords.Y;
}
}

}

TrajectoryCheckReturnType BombardTrajectory::OnAITargetCoordCheck(BulletClass* pBullet)
{
return TrajectoryCheckReturnType::ExecuteGameCheck; // Execute game checks.
}

TrajectoryCheckReturnType BombardTrajectory::OnAITechnoCheck(BulletClass* pBullet, TechnoClass* pTechno)
{
return TrajectoryCheckReturnType::SkipGameCheck; // Bypass game checks entirely.
}
44 changes: 44 additions & 0 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "PhobosTrajectory.h"

class BombardTrajectoryType final : public PhobosTrajectoryType
{
public:
BombardTrajectoryType() : PhobosTrajectoryType(TrajectoryFlag::Bombard)
, Height { 0.0 }
{ }

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
virtual bool Save(PhobosStreamWriter& Stm) const override;

virtual void Read(CCINIClass* const pINI, const char* pSection) override;

double Height;
};

class BombardTrajectory final : public PhobosTrajectory
{
public:
BombardTrajectory() : PhobosTrajectory(TrajectoryFlag::Bombard)
, IsFalling { false }
, Height { 0.0 }
{}

BombardTrajectory(PhobosTrajectoryType* pType) : PhobosTrajectory(TrajectoryFlag::Bombard)
, IsFalling { false }
, Height { 0.0 }
{}

virtual bool Load(PhobosStreamReader& Stm, bool RegisterForChange) override;
virtual bool Save(PhobosStreamWriter& Stm) const override;

virtual void OnUnlimbo(BulletClass* pBullet, CoordStruct* pCoord, BulletVelocity* pVelocity) override;
virtual void OnAI(BulletClass* pBullet) override;
virtual void OnAIVelocity(BulletClass* pBullet, BulletVelocity* pSpeed, BulletVelocity* pPosition) override;
virtual TrajectoryCheckReturnType OnAITargetCoordCheck(BulletClass* pBullet) override;
virtual TrajectoryCheckReturnType OnAITechnoCheck(BulletClass* pBullet, TechnoClass* pTechno) override;

bool IsFalling;
double Height;
};
Loading