Skip to content
Draft
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
17 changes: 14 additions & 3 deletions BDArmory/Ammo/PooledBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,22 @@ public void PostCollisions()
{
if (fuzeType == BulletFuzeTypes.Delay || fuzeType == BulletFuzeTypes.Penetrating)
{
fuzeTriggered = true;
delayedDetonationRoutine = StartCoroutine(DelayedDetonationRoutine());
if (!fuzeTriggered)
{
fuzeTriggered = true;
delayedDetonationRoutine = StartCoroutine(DelayedDetonationRoutine());
}
}
else //if (fuzeType != BulletFuzeTypes.None)
{
if (HEType != PooledBulletTypes.Slug)
{
ExplosionFx.CreateExplosion(currentPosition, tntMass, explModelPath, explSoundPath, ExplosionSourceType.Bullet, caliber, null, sourceVesselName, null, null, default, -1, false, bulletMass, -1, dmgMult);
}
if (nuclear)
{
NukeFX.CreateExplosion(currentPosition, ExplosionSourceType.Bullet, sourceVesselName, bullet.DisplayName, 0, tntMass * 200, tntMass, tntMass, EMP, blastSoundPath, flashModelPath, shockModelPath, blastModelPath, plumeModelPath, debrisModelPath, "", "");
}
hasDetonated = true;
if (BDArmorySettings.waterHitEffect && FlightGlobals.currentMainBody.ocean) FXMonger.Splash(currentPosition, caliber / 2);
KillBullet();
Expand Down Expand Up @@ -1510,7 +1517,11 @@ bool BulletHitAnalysis(BulletHit bulletHit, float period)
// Should penetrating fuzes also get triggered here? I guess they should...
if (fuzeType == BulletFuzeTypes.Delay || fuzeType == BulletFuzeTypes.Penetrating)
{
fuzeTriggered = true;
if (!fuzeTriggered)
{
fuzeTriggered = true;
delayedDetonationRoutine = StartCoroutine(DelayedDetonationRoutine());
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions BDArmory/BDArmory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
<Compile Include="WeaponMounts\MissileTurret.cs" />
<Compile Include="WeaponMounts\ModuleCustomTurret.cs" />
<Compile Include="WeaponMounts\ModuleTurret.cs" />
<Compile Include="WeaponMounts\TurretAxisManager.cs" />
<Compile Include="WeaponMounts\WMTurretGroup.cs" />
<Compile Include="Weapons\BDCustomWarhead.cs" />
<Compile Include="Weapons\BDWarheadBase.cs" />
Expand Down
135 changes: 80 additions & 55 deletions BDArmory/Control/MissileFire.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions BDArmory/Radar/RadarWarningReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ public override void OnStart(StartState state)
if (HighLogic.LoadedSceneIsFlight)
{
pingsData = new RWRSignatureData[dataCount];
MWSData = new RWRSignatureData[dataCount];
MWSData = new RWRSignatureData[2 *dataCount];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning for these being 2 * dataCount as opposed to some other length?
(I don't really understand what you're using these for, but hard-coded array sizes are suspicious.)

//pingWorldPositions = new Vector3[dataCount];
RWRSignatureData.ResetRWRSDArray(ref pingsData);
launchWarnings = new RWRSignatureData[dataCount]; //new List<TargetSignatureData>();
missileLockData = new RWRSignatureData[dataCount];
launchWarnings = new RWRSignatureData[2 * dataCount]; //new List<TargetSignatureData>();
missileLockData = new RWRSignatureData[2 * dataCount];

rwrIconLabelStyle = new GUIStyle();
rwrIconLabelStyle.alignment = TextAnchor.MiddleCenter;
Expand Down Expand Up @@ -431,7 +431,7 @@ private void CleanPings()

private void CleanMissileLocks()
{
float currentTime = Time.time;
float currentTime = Time.time + Time.fixedDeltaTime;
while (_missileLockSize > 0)
{
int idx = _missileLockHead;
Expand Down
90 changes: 84 additions & 6 deletions BDArmory/WeaponMounts/MissileTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public bool slavedGuard
[KSPField] public bool deployBlocksYaw = false; // Turret must deploy before yawing, turret must return to yaw standby position to stow/"undeploy".
[KSPField] public bool deployBlocksPitch = false; // Turret must deploy before pitching, turret must return to pitch standby position to stow/"undeploy".
public bool isReloading = false;
float _reloadUntil = 0;
[KSPField] public bool startsDeployed = false; //Turret starts in deployed position and only uses deploy anim for relaoding. TODO: proper reload anim support for turrets independent of deployAnim

//animation
Expand All @@ -112,7 +113,7 @@ public bool isDeployed()
//special
[KSPField] public bool activeMissileOnly = false;

MissileFire WeaponManager
public MissileFire WeaponManager
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why public? This isn't getting called externally.

{
get
{
Expand All @@ -123,6 +124,54 @@ MissileFire WeaponManager
}
MissileFire _weaponManager;

public float DeployIfBlocking(bool yaw)
{
if (!hasDeployAnimation)
{
turret.SetDeployFlag(true, true);
return 0;
}

// If not blocking, return 0 without doing anything
if (!(yaw ? deployBlocksYaw : deployBlocksPitch))
{
if (yaw)
{
turret.SetYawDeployFlag(true);
}
else
{
turret.SetPitchDeployFlag(true);
}
return 0;
}

bool reloadBlock = deployBlocksReload && isReloading;

// If no deploy animation or deployed and not reloading
if (!(deployAnimState.normalizedTime < 1 || reloadBlock)) return 0;

// If not blocked by reload
if (!reloadBlock)
{
if (deployAnimRoutine != null)
{
StopCoroutine(deployAnimRoutine);
}

deployAnimRoutine = StartCoroutine(DeployAnimation(true));

hasReturned = false;

return deployAnimState.length - deployAnimState.time;
}
else
{
// If blocked by reload, return time that reload completes at
return _reloadUntil - Time.fixedDeltaTime;
}
}

IEnumerator DeployAnimation(bool forward)
{
var wait = new WaitForFixedUpdate();
Expand All @@ -137,13 +186,19 @@ IEnumerator DeployAnimation(bool forward)
}

deployAnimState.normalizedTime = 1;

// Unblock turret
turret.SetDeployFlag(true, true);
}
else
{
deployAnimState.speed = 0;

yield return new WaitWhileFixed(() => pausingAfterShot);

// Block turret prior to undeploy
turret.SetDeployFlag(!deployBlocksYaw, !deployBlocksPitch);

while (deployAnimState.normalizedTime > 0)
{
deployAnimState.speed = -deployAnimationSpeed;
Expand Down Expand Up @@ -279,7 +334,7 @@ IEnumerator ReturnRoutine()
bool pitch = !turretEnabled || (deployBlocksPitch && deployBlocksReload);
bool yaw = !turretEnabled || (deployBlocksYaw && deployBlocksReload);

while (turret != null && !turret.ReturnTurret(pitch, yaw))
while (turret != null && !turret.ReturnTurret(pitch, yaw, isReloading))
{
UpdateMissilePositions();
yield return new WaitForFixedUpdate();
Expand Down Expand Up @@ -325,6 +380,7 @@ public override void OnStart(StartState state)
if (tur.Current == null) continue;
if (tur.Current.turretID != turretID) continue;
turret = tur.Current;
turret.turretMissile = this;
break;
}
tur.Dispose();
Expand Down Expand Up @@ -473,12 +529,34 @@ public void SetSlavedGuard(bool slavedGuard, MissileBase ml)
}
}

public bool IsCurrentWMMissile()
{
MissileFire wm;
if (!(wm = WeaponManager)) return false;

if (!wm.CurrentMissile) return false;

return slavedGuard || wm.CurrentMissile.GetPartName() == activeMissile.GetPartName();
}

public void SlavedAim()
{
if (pausingAfterShot) return;
bool deployCond = hasDeployAnimation && (deployAnimState.normalizedTime < 1 || isReloading);
bool deployCond = hasDeployAnimation && (deployAnimState.normalizedTime < 1 || (deployBlocksReload && isReloading));

turret.AimToTarget(slavedTargetPosition, !(deployCond && deployBlocksPitch), !(deployCond && deployBlocksYaw), IsCurrentWMMissile());
}

public void SetReloadBlock(float duration)
{
// Deploy must block reload and a deploy animation must exist before we block the turret
if (!(deployBlocksReload && hasDeployAnimation)) return;

_reloadUntil = Time.fixedDeltaTime + duration;

turret.AimToTarget(slavedTargetPosition, !(deployCond && deployBlocksPitch), !(deployCond && deployBlocksYaw));
// We only block if the respective toggle is also enabled
if (deployBlocksPitch && turret.pitchAxisManager) turret.pitchAxisManager.SetTurretBlock(_reloadUntil);
if (deployBlocksYaw && turret.yawAxisManager) turret.yawAxisManager.SetTurretBlock(_reloadUntil);
}

const int mouseAimLayerMask = (int)(LayerMasks.Parts | LayerMasks.Scenery | LayerMasks.EVA | LayerMasks.Unknown19 | LayerMasks.Unknown23 | LayerMasks.Wheels);
Expand Down Expand Up @@ -523,8 +601,8 @@ void MouseAim()
FlightCamera.fetch.mainCamera.transform.position;
}

bool deployCond = hasDeployAnimation && (deployAnimState.normalizedTime < 1 || isReloading);
turret.AimToTarget(targetPosition, !(deployCond && deployBlocksPitch), !(deployCond && deployBlocksYaw));
bool deployCond = hasDeployAnimation && (deployAnimState.normalizedTime < 1 || (deployBlocksReload && isReloading));
turret.AimToTarget(targetPosition, !(deployCond && deployBlocksPitch), !(deployCond && deployBlocksYaw), IsCurrentWMMissile());
}

public void UpdateMissileChildren()
Expand Down
Loading