Skip to content

Commit

Permalink
Merge pull request #616 from PapaJoesSoup/dev
Browse files Browse the repository at this point in the history
Merge from dev for KSP 1.6
  • Loading branch information
jrodrigv authored Dec 28, 2018
2 parents 4270ff8 + d626670 commit 8bbc297
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 1,150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ BDArmory/LocalDev/Refs/UnityEngine.dll
/BDArmory.Events/obj/Release
/Binaries
/BDArmory/Distribution/GameData/BDArmory/Plugins
/BDArmory/_ReSharper.Caches/ReSharperPlatformVs15182_74c703de.BDArmory.00
12 changes: 10 additions & 2 deletions BDArmory.Core/Module/HitpointTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class HitpointTracker : PartModule
{
#region KSP Fields

[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Hitpoints"),
[KSPField(isPersistant = false, guiActive = true, guiActiveEditor = true, guiName = "Hitpoints"),
UI_ProgressBar(affectSymCounterparts = UI_Scene.None, controlEnabled = false, scene = UI_Scene.All, maxValue = 100000, minValue = 0, requireFullControl = false)]
public float Hitpoints;

Expand Down Expand Up @@ -186,9 +186,17 @@ public float CalculateTotalHitpoints()
//Debug.Log("[BDArmory]: Hitpoint Calc" + part.name + " | structuralMass : " + structuralMass);
//3. final calculations
hitpoints = structuralMass * hitpointMultiplier *0.33f;
hitpoints = Mathf.Round(hitpoints / HpRounding) * HpRounding;

if (hitpoints > 10 * part.mass * 1000f || hitpoints < 0.1f * part.mass * 1000f)
{
Debug.Log($"[BDArmory]: HitpointTracker::Clamping hitpoints for part {part.name}");
hitpoints = hitpointMultiplier * part.mass * 333f;
}

hitpoints = Mathf.Round(hitpoints / HpRounding) * HpRounding;
if (hitpoints <= 0) hitpoints = HpRounding;


}
else
{
Expand Down
4 changes: 2 additions & 2 deletions BDArmory.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyVersion("1.2.4.0")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: KSPAssembly("BDArmory.Core", 1, 0)]
1,031 changes: 0 additions & 1,031 deletions BDArmory/.vs/config/applicationhost.config

This file was deleted.

10 changes: 5 additions & 5 deletions BDArmory/Distribution/GameData/BDArmory/BDArmory.version
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
{
"MAJOR":1,
"MINOR":2,
"PATCH":3,
"PATCH":4,
"BUILD":0
},
"KSP_VERSION":
{
"MAJOR":1,
"MINOR":5,
"PATCH":1
"MINOR":6,
"PATCH":0
},
"KSP_VERSION_MIN":
{
"MAJOR":1,
"MINOR":5,
"MINOR":6,
"PATCH":1
},
"KSP_VERSION_MAX":
{
"MAJOR":1,
"MINOR":5,
"MINOR":6,
"PATCH":999
}
}
12 changes: 11 additions & 1 deletion BDArmory/Distribution/GameData/BDArmory/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
v1.2.3
v1.2.4
* NEW FEATURES:
* Weapons groups - different weapons firing in parallel(thanks to @SuicidalInsanity)
* ENHANCEMENTS:
* Recompiled for KSP 1.6.0
* FIXES
* Fixing modular missiles roll correction.
* Fixing modular missiles stage on proximity.
* Fixing Hipoints for mods like AirplanePlus #598

v1.2.3
* NEW FEATURES:
* Recompiled for KSP 1.5.1
* EC per shot for energy weapons like Rail guns. #486
Expand Down
22 changes: 14 additions & 8 deletions BDArmory/FX/ExplosionFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,17 @@ private void ProcessBuildingEvent(DestructibleBuilding building, List<BlastHitEv
private void ProcessPartEvent(Part part, List<BlastHitEvent> eventList, List<Part> partsAdded)
{
RaycastHit hit;

if (IsInLineOfSight(part, ExplosivePart, out hit))
float distance = 0;
if (IsInLineOfSight(part, ExplosivePart, out hit, out distance))
{
if (IsAngleAllowed(Direction, hit))
{
var realDistance = Vector3.Distance(Position, hit.point);
//Adding damage hit
eventList.Add(new PartBlastHitEvent()
{
Distance = realDistance,
Distance = distance,
Part = part,
TimeToImpact = realDistance / ExplosionVelocity,
TimeToImpact = distance / ExplosionVelocity,
HitPoint = hit.point,
});
partsAdded.Add(part);
Expand All @@ -190,7 +189,7 @@ private bool IsAngleAllowed(Vector3 direction, RaycastHit hit)
/// <param name="explosivePart"></param>
/// <param name="hit"> out property with the actual hit</param>
/// <returns></returns>
private bool IsInLineOfSight(Part part, Part explosivePart, out RaycastHit hit)
private bool IsInLineOfSight(Part part, Part explosivePart, out RaycastHit hit, out float distance)
{
Ray partRay = new Ray(Position, part.transform.position - Position);

Expand All @@ -202,24 +201,31 @@ private bool IsInLineOfSight(Part part, Part explosivePart, out RaycastHit hit)
Part partHit = hitsEnu.Current.collider.GetComponentInParent<Part>();
if (partHit == null) continue;
hit = hitsEnu.Current;

distance = Vector3.Distance(Position, hit.point);
if (partHit == part)
{
return true;
}
if (partHit != part)
{
// ignoring collsions against the explosive
// ignoring collisions against the explosive
if (explosivePart != null && partHit.vessel == explosivePart.vessel)
{
continue;
}
// if there are parts in between but we still inside the critical sphere of damage.
if (distance <= 0.1f * Range)
{
continue;
}

return false;
}
}
}

hit = new RaycastHit();
distance = 0;
return false;
}

Expand Down
12 changes: 9 additions & 3 deletions BDArmory/Modules/BDExplosivePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void OnStart (StartState state)
{
if (HighLogic.LoadedSceneIsFlight)
{
part.explosionPotential = 1.0f;
part.OnJustAboutToBeDestroyed += DetonateIfPossible;
part.force_activate();
}
Expand All @@ -73,6 +74,11 @@ public void Update()
{
OnUpdateEditor();
}

if (hasDetonated)
{
this.part.explode();
}
}

private void OnUpdateEditor()
Expand All @@ -87,16 +93,16 @@ private void CalculateBlast()
if (part.Resources["HighExplosive"].amount == previousMass) return;

tntMass = (float) (part.Resources["HighExplosive"].amount * part.Resources["HighExplosive"].info.density * 1000) * 1.5f;

previousMass = part.Resources["HighExplosive"].amount;
part.explosionPotential = tntMass / 10f;
previousMass = part.Resources["HighExplosive"].amount;
}

blastRadius = BlastPhysicsUtils.CalculateBlastRange(tntMass);
}

public void DetonateIfPossible()
{
if(!hasDetonated && Armed && part.vessel.speed > 10)
if(!hasDetonated && Armed)
{
Vector3 direction = default(Vector3);

Expand Down
40 changes: 26 additions & 14 deletions BDArmory/Modules/BDModularGuidance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ public override void OnFixedUpdate()
CheckDetonationDistance();
CheckDelayedFired();
CheckNextStage();

if (isTimed && TimeIndex > detonationTime)
{
AutoDestruction();
}
}
}

if (HasExploded && StageToTriggerOnProximity == 0)
{
AutoDestruction();
}
}

Expand Down Expand Up @@ -457,7 +462,7 @@ private void OnStageOnProximity(BaseField baseField, object o)
{
detonationDistance = (UI_FloatRange) Fields["DetonationDistance"].uiControlEditor;

detonationDistance.maxValue = 2000;
detonationDistance.maxValue = 8000;

detonationDistance.stepIncrement = 50;
}
Expand Down Expand Up @@ -724,11 +729,11 @@ private void SetRoll()

if (futureAngle > 0.5f || currentAngle > 0.5f)
{
this.Roll = Mathf.Clamp(Roll + 0.001f, 0, 1f);
this.Roll = Mathf.Clamp(Roll - 0.001f, -1f, 0f);
}
else if (futureAngle < -0.5f || currentAngle < -0.5f)
{
this.Roll = Mathf.Clamp(Roll - 0.001f, -1f, 0f);
this.Roll = Mathf.Clamp(Roll + 0.001f, 0, 1f);
}
debugString.Append($"Roll value: {this.Roll}");

Expand Down Expand Up @@ -850,8 +855,9 @@ public override void FireMissile()
SetTargeting();
Jettison();
AddTargetInfoToVessel();
IncreaseTolerance();



this.initialMissileRollPlane = -this.vessel.transform.up;
this.initialMissileForward = this.vessel.transform.forward;
vessel.vesselName = GetShortName();
Expand All @@ -876,6 +882,16 @@ public override void FireMissile()
}
}

private void IncreaseTolerance()
{
foreach (var vesselPart in this.vessel.parts)
{
vesselPart.crashTolerance = 99;
vesselPart.breakingForce = 99;
vesselPart.breakingTorque = 99;
}
}

private void SetTargeting()
{
startDirection = GetForwardTransform();
Expand Down Expand Up @@ -968,21 +984,19 @@ protected override void PartDie(Part p)

private void AutoDestruction()
{
List<Part>.Enumerator vesselPart = vessel.Parts.GetEnumerator();
while (vesselPart.MoveNext())
for (int i = this.vessel.parts.Count - 1; i >= 0; i--)
{
if (vesselPart.Current == null) continue;
vesselPart.Current.Destroy();
this.vessel.parts[i]?.explode();
}
vesselPart.Dispose();
}

public override void Detonate()
{
if (HasExploded || !HasFired) return;
if (SourceVessel == null) SourceVessel = vessel;

if (StageToTriggerOnProximity != 0)
HasExploded = true;
if (StageToTriggerOnProximity != 0)
{
vessel.ActionGroups.ToggleGroup(
(KSPActionGroup) Enum.Parse(typeof(KSPActionGroup), "Custom0" + (int)StageToTriggerOnProximity));
Expand All @@ -993,8 +1007,6 @@ public override void Detonate()
AutoDestruction();
}


HasExploded = true;
}

public override Vector3 GetForwardTransform()
Expand Down
11 changes: 9 additions & 2 deletions BDArmory/Modules/EngageableWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,12 @@ public bool GetEngageSLWTargets()
return engageSLW;
}

}
}
[KSPField(isPersistant = true)]
public string shortName = string.Empty;

public string GetShortName()
{
return shortName;
}
}
}
26 changes: 20 additions & 6 deletions BDArmory/Modules/MissileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -965,20 +965,33 @@ public void CheckDetonationState()
//We are now close enough to start checking the detonation distance
DetonationDistanceState = DetonationDistanceStates.CheckingProximity;
}
break;
else
{
BDModularGuidance bdModularGuidance = this as BDModularGuidance;



if (bdModularGuidance == null) return;

if(Vector3.Distance(futureMissilePosition, futureTargetPosition) > this.DetonationDistance) return;


DetonationDistanceState = DetonationDistanceStates.CheckingProximity;
}
break;
case DetonationDistanceStates.CheckingProximity:

if (DetonationDistance == 0)
{
if (weaponClass == WeaponClasses.Bomb) return;

if (TimeIndex > 1f && vessel.srfSpeed > part.crashTolerance)
if (TimeIndex > 1f)
{
//Vector3 floatingorigin_current = FloatingOrigin.Offset;

Ray rayFuturePosition = new Ray(vessel.CoM, futureMissilePosition);
Ray rayFuturePosition = new Ray(vessel.CoM, futureMissilePosition);

var hitsFuture = Physics.RaycastAll(rayFuturePosition, (float) missileDistancePerFrame.magnitude, 557057).AsEnumerable();
var hitsFuture = Physics.RaycastAll(rayFuturePosition, (float) missileDistancePerFrame.magnitude, 557057).AsEnumerable();

using (var hitsEnu = hitsFuture.GetEnumerator())
{
Expand All @@ -993,8 +1006,9 @@ public void CheckDetonationState()
if (hitPart?.vessel != SourceVessel && hitPart?.vessel != vessel )
{
//We found a hit to other vessel
vessel.transform.position = hit.point;
vessel.SetPosition(hit.point);
DetonationDistanceState = DetonationDistanceStates.Detonate;
Detonate();
return;
}
}
Expand All @@ -1004,7 +1018,7 @@ public void CheckDetonationState()
}
}
}
}
}

previousPos = part.transform.position;

Expand Down
Loading

0 comments on commit 8bbc297

Please sign in to comment.