Skip to content

Commit

Permalink
Ask VF to notify us when a shot is fired
Browse files Browse the repository at this point in the history
Use that notification to generate filth and motes as needed.
  • Loading branch information
perkinslr committed Sep 22, 2023
1 parent 2da7eb7 commit e5f8082
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void PostLoad(ModContentPack content, ISettingsCE _)
VehicleTurret.LookupAmmosetCE = LookupAmmosetCE;
VehicleTurret.LaunchProjectileCE = LaunchProjectileCE;
VehicleTurret.LookupProjectileCountAndSpreadCE = LookupProjectileCountAndSpreadCE;
VehicleTurret.NotifyShotFiredCE = NotifyShotFiredCE;
global::CombatExtended.Compatibility.Patches.RegisterCollisionBodyFactorCallback(_GetCollisionBodyFactors);
global::CombatExtended.Compatibility.Patches.UsedAmmoCallbacks.Add(_GetUsedAmmo);
}
Expand Down Expand Up @@ -73,6 +74,29 @@ public static IEnumerable<ThingDef> _GetUsedAmmo()
}
}

public static void NotifyShotFiredCE(ThingDef projectileDef, ThingDef _ammoDef, Def _ammosetDef, VehicleTurret turret, float recoil) {
if (_ammoDef is AmmoDef ammoDef && _ammosetDef is AmmoSetDef ammosetDef)
{
foreach (var al in ammosetDef.ammoTypes)
{
if (al.ammo == ammoDef)
{
projectileDef = al.projectile;
break;
}
}
}
else
{
projectileDef = projectileDef.GetProjectile();
}
if (projectileDef.projectile is ProjectilePropertiesCE ppce)
{
CE_Utility.GenerateAmmoCasings(ppce, turret.TurretLocation, turret.vehicle.Map, -turret.TurretRotation, recoil);
}

}

public static Vector2 ProjectileAngleCE(float speed, float range, Thing shooter, LocalTargetInfo target, Vector3 shotOrigin, bool flyOverhead, float gravity, float sway, float spread, float recoil)
{
// TODO: Handle cover
Expand Down
Binary file modified Source/packages/Vehicles-reference.dll
Binary file not shown.

0 comments on commit e5f8082

Please sign in to comment.