Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed May 29, 2024
2 parents 5bb44b9 + a3e2888 commit 2c20c20
Show file tree
Hide file tree
Showing 22 changed files with 213 additions and 135 deletions.
41 changes: 31 additions & 10 deletions Data/Scripts/CoreSystems/Ai/AiConstruct.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CoreSystems.Platform;
using CoreSystems.Projectiles;
using Sandbox.Game.Entities;
Expand Down Expand Up @@ -59,20 +60,40 @@ public void RegisterSubGrid(MyCubeGrid grid)
grid.OnFatBlockAdded += FatBlockAdded;
grid.OnFatBlockRemoved += FatBlockRemoved;

SubGridsRegistered[grid] = byte.MaxValue;

foreach (var cube in grid.GetFatBlocks()) {

var battery = cube as MyBatteryBlock;
var stator = cube as IMyMotorStator;
var tool = cube as IMyShipToolBase;
var offense = cube as IMyOffensiveCombatBlock;
//BDC Temp debugging
var tempBlockArray = grid.GetFatBlocks().ToArray();
try
{
foreach (var cube in grid.GetFatBlocks())
{
var battery = cube as MyBatteryBlock;
var stator = cube as IMyMotorStator;
var tool = cube as IMyShipToolBase;
var offense = cube as IMyOffensiveCombatBlock;

if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null)
if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null)
FatBlockAdded(cube);
}
}
catch (Exception ex)
{
var modifiedBlockArray = grid.GetFatBlocks();
var msg = $"Original GetFatBlocks contained {tempBlockArray.Length} items, modified contains {modifiedBlockArray.Count}";
foreach (var original in tempBlockArray)
{
if(!modifiedBlockArray.Contains(original))
msg += $"Block {original.DisplayName} was removed \n";
}
foreach (var modified in modifiedBlockArray)
{
FatBlockAdded(cube);
if (!tempBlockArray.Contains(modified))
msg += $"Block {modified.DisplayName} was added \n";
}
Log.Line(msg);
MyLog.Default.WriteLine(msg);
throw ex;
}
SubGridsRegistered[grid] = byte.MaxValue;
}

public void UnRegisterSubGrid(MyCubeGrid grid)
Expand Down
5 changes: 5 additions & 0 deletions Data/Scripts/CoreSystems/Ai/AiEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using VRage.Collections;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.Utils;
using VRageMath;

namespace CoreSystems.Support
Expand Down Expand Up @@ -186,6 +187,10 @@ internal void FatBlockAdded(MyCubeBlock cube)
if (Session.I.IsServer)
{
cube.CubeGrid.RemoveBlock(cube.SlimBlock, true);
//BDC Temp debugging
var msg = $"WeaponCore Removed {cube.BlockDefinition.Id.SubtypeId} block due to placement violations";
Log.Line(msg);
MyLog.Default.WriteLine(msg);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Data/Scripts/CoreSystems/Ai/AiTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ private static bool AcquireTopMostEntity(Weapon w, ProtoWeaponOverrides overRide
if (w.LastHitInfo?.HitEntity != null && (!w.System.Values.HardPoint.Other.MuzzleCheck || !w.MuzzleHitSelf()))
{
TargetInfo hitInfo;
if (w.LastHitInfo.HitEntity == info.Target || ai.Targets.TryGetValue((MyEntity)w.LastHitInfo.HitEntity, out hitInfo) && (hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies || hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Neutral || hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership))
var targMatch = w.LastHitInfo.HitEntity == info.Target;
var targOther = !targMatch && ai.Targets.TryGetValue((MyEntity)w.LastHitInfo.HitEntity, out hitInfo) && (hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies || hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Neutral || hitInfo.EntInfo.Relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership);
var targChar = !targMatch && character != null && !ai.ObstructionLookup.ContainsKey((MyEntity)w.LastHitInfo.HitEntity);

if (targMatch || targOther || targChar)
{
double rayDist;
Vector3D.Distance(ref weaponPos, ref targetCenter, out rayDist);
Expand Down
37 changes: 23 additions & 14 deletions Data/Scripts/CoreSystems/AudioVisual/AvShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ internal void LineVariableEffects()

var color = skipTracerFactionColor ? aConst.LinearTracerColor : aConst.TracerFactionColor == FactionColor.Foreground ? FgFactionColor : BgFactionColor;
var segmentColor = skipSegFactionColor ? aConst.LinearSegmentColor : aConst.SegFactionColor == FactionColor.Foreground ? FgFactionColor : BgFactionColor;
if (aConst.LineColorVariance)
if (aConst.LineColorVariance && skipTracerFactionColor)
{
var tracerStart = aConst.LinearTracerColorStart;
var tracerEnd = aConst.LinearTracerColorEnd;
Expand All @@ -682,7 +682,7 @@ internal void LineVariableEffects()
}
}

if (aConst.SegmentColorVariance)
if (aConst.SegmentColorVariance && skipSegFactionColor)
{
// gross inlined random
var tempX = rnd.Y;
Expand Down Expand Up @@ -1030,21 +1030,30 @@ internal void SetupSounds(double distanceFromCameraSqr)

if (AmmoDef.Const.ShotSound)
{
if (distanceFromCameraSqr <= AmmoDef.Const.ShotSoundDistSqr && (IsFragment || Weapon.System.FiringSound == WeaponSystem.FiringSoundState.None))
try //SharpDX bughunting
{
FireEmitter = Session.Av.FireEmitters.Count > 0 ? Session.Av.FireEmitters.Pop() : new MyEntity3DSoundEmitter(null);
FireEmitter.CanPlayLoopSounds = true;
FireEmitter.Entity = null;
FireEmitter.SetPosition(Origin);
FireEmitter.PlaySound(AmmoDef.Const.ShotSoundPair, true);
if (distanceFromCameraSqr <= AmmoDef.Const.ShotSoundDistSqr && (IsFragment || Weapon.System.FiringSound == WeaponSystem.FiringSoundState.None))
{
FireEmitter = Session.Av.FireEmitters.Count > 0 ? Session.Av.FireEmitters.Pop() : new MyEntity3DSoundEmitter(null);
FireEmitter.CanPlayLoopSounds = true;
FireEmitter.Entity = null;
FireEmitter.SetPosition(Origin);
FireEmitter.PlaySound(AmmoDef.Const.ShotSoundPair, true);
}
else if (Weapon.System.FiringSound == WeaponSystem.FiringSoundState.PerShot && distanceFromCameraSqr <= Weapon.System.FiringSoundDistSqr)
{
FireEmitter = Session.Av.FireEmitters.Count > 0 ? Session.Av.FireEmitters.Pop() : new MyEntity3DSoundEmitter(null);
FireEmitter.CanPlayLoopSounds = true;
FireEmitter.Entity = Weapon.Comp.CoreEntity;
FireEmitter.SetPosition(Origin);
FireEmitter.PlaySound(AmmoDef.Const.ShotSoundPair, true);
}
}
else if (Weapon.System.FiringSound == WeaponSystem.FiringSoundState.PerShot && distanceFromCameraSqr <= Weapon.System.FiringSoundDistSqr)
catch (Exception e)
{
FireEmitter = Session.Av.FireEmitters.Count > 0 ? Session.Av.FireEmitters.Pop() : new MyEntity3DSoundEmitter(null);
FireEmitter.CanPlayLoopSounds = true;
FireEmitter.Entity = Weapon.Comp.CoreEntity;
FireEmitter.SetPosition(Origin);
FireEmitter.PlaySound(AmmoDef.Const.ShotSoundPair, true);
MyLog.Default.Error($"Sound error with ammo: {AmmoDef.AmmoRound} from {Weapon.Comp.TerminalBlock.DisplayName} soundID {AmmoDef.Const.ShotSoundPair.SoundId} cuename {AmmoDef.Const.ShotSoundPair.GetCueName()}" +
$"FireEmitter.Entity null? {FireEmitter?.Entity == null} \n Origin: {Origin}");
throw e;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Data/Scripts/CoreSystems/Definitions/CoreDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ public struct LoadingDef
[ProtoMember(22)] internal int MaxReloads;
[ProtoMember(23)] internal bool GoHomeToReload;
[ProtoMember(24)] internal bool DropTargetUntilLoaded;
[ProtoMember(25)] internal bool ProhibitCoolingWhenOff;

}

Expand All @@ -529,6 +530,8 @@ public struct UiDef
[ProtoMember(6)] internal bool DisableStatus;
[ProtoMember(7)] internal float RateOfFireMin;
[ProtoMember(8)] internal bool DisableSupportingPD;
[ProtoMember(9)] internal bool ProhibitShotDelay;
[ProtoMember(10)] internal bool ProhibitBurstCount;
}


Expand Down Expand Up @@ -784,6 +787,7 @@ public struct ObjectsHitDef
{
[ProtoMember(1)] internal int MaxObjectsHit;
[ProtoMember(2)] internal bool CountBlocks;
[ProtoMember(3)] internal bool SkipBlocksForAOE;
}


Expand Down Expand Up @@ -1084,6 +1088,7 @@ public enum EwarType
Push,
Pull,
Tractor,
AntiSmartv2,
}

public enum EwarMode
Expand Down
6 changes: 4 additions & 2 deletions Data/Scripts/CoreSystems/Definitions/CoreSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public AmmoType(AmmoDef ammoDef, MyDefinitionId ammoDefinitionId, MyDefinitionId
public readonly bool OnlySubSystems;
public readonly bool ClosestFirst;
public readonly bool DegRof;
public readonly bool ProhibitCoolingWhenOff;
public readonly bool TrackProjectile;
public readonly bool DisableSupportingPD;
public readonly bool ScanTrackOnly;
Expand Down Expand Up @@ -357,7 +358,7 @@ public WeaponSystem(WeaponStructure structure, MyStringHash partNameIdHash, MySt
HasScope = !string.IsNullOrEmpty(Values.Assignments.Scope);
AltScopeName = HasScope ? "subpart_" + Values.Assignments.Scope : string.Empty;
TurretMovements(out AzStep, out ElStep, out MinAzimuth, out MaxAzimuth, out MinElevation, out MaxElevation, out HomeAzimuth, out HomeElevation, out TurretMovement);
Heat(out DegRof, out MaxHeat, out WepCoolDown);
Heat(out DegRof, out MaxHeat, out WepCoolDown, out ProhibitCoolingWhenOff);
BarrelValues(out BarrelsPerShot, out ShotsPerBurst);
BarrelsAv(out BarrelEffect1, out BarrelEffect2, out Barrel1AvTicks, out Barrel2AvTicks, out BarrelSpinRate, out HasBarrelRotation);
Track(out ScanTrackOnly, out NonThreatsOnly, out TrackProjectile, out TrackGrids, out TrackCharacters, out TrackMeteors, out TrackNeutrals, out ScanNonThreats, out ScanThreats, out MaxTrackingTime, out MaxTrackingTicks, out TrackTopMostEntities);
Expand Down Expand Up @@ -482,8 +483,9 @@ private void GetThreats(out HashSet<int> set, out bool projectilesFirst, out boo
projectilesOnly = projectilesFirst && Values.Targeting.Threats.Length == 1;
}

private void Heat(out bool degRof, out int maxHeat, out float wepCoolDown)
private void Heat(out bool degRof, out int maxHeat, out float wepCoolDown, out bool coolWhenOff)
{
coolWhenOff = Values.HardPoint.Loading.ProhibitCoolingWhenOff;
degRof = Values.HardPoint.Loading.DegradeRof;
maxHeat = Values.HardPoint.Loading.MaxHeat;
wepCoolDown = Values.HardPoint.Loading.Cooldown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ internal AmmoConstants(WeaponSystem.AmmoType ammo, WeaponDefinition wDef, Weapon
else if (ammo.AmmoDef.Ejection.Type == AmmoDef.EjectionDef.SpawnType.Particle && !string.IsNullOrEmpty(ammo.AmmoDef.AmmoGraphics.Particles.Eject.Name))
HasEjectEffect = true;

if (AmmoItem.Content != null && !Session.I.AmmoItems.ContainsKey(AmmoItem.ItemId))
Session.I.AmmoItems[AmmoItem.ItemId] = AmmoItem;

var fragGuidedAmmo = false;
var fragAntiSmart = false;
var fragTargetOverride = false;
Expand All @@ -371,7 +368,7 @@ internal AmmoConstants(WeaponSystem.AmmoType ammo, WeaponDefinition wDef, Weapon
if (hasTimed)
fragHasTimedSpawn = true;

if (ammoType.Ewar.Type == EwarType.AntiSmart)
if (ammoType.Ewar.Type == EwarType.AntiSmart || ammoType.Ewar.Type == EwarType.AntiSmartv2)
fragAntiSmart = true;

if (hasGuidance && ammoType.Trajectory.Smarts.OverideTarget)
Expand Down Expand Up @@ -890,7 +887,7 @@ private void ComputeAmmoPattern(WeaponSystem.AmmoType ammo, WeaponSystem system,
if (!patternGuidedAmmo && hasGuidance)
patternGuidedAmmo = true;

if (!patternAntiSmart && ammoDef.Ewar.Type == EwarType.AntiSmart)
if (!patternAntiSmart && (ammoDef.Ewar.Type == EwarType.AntiSmart || ammoDef.Ewar.Type == EwarType.AntiSmartv2))
patternAntiSmart = true;
if (hasGuidance && ammoDef.Trajectory.Smarts.OverideTarget)
patternTargetOverride = true;
Expand All @@ -905,7 +902,7 @@ private void ComputeAmmoPattern(WeaponSystem.AmmoType ammo, WeaponSystem system,
}

hasGuidedAmmo = fragGuidedAmmo || patternGuidedAmmo || ammo.AmmoDef.Trajectory.Guidance != TrajectoryDef.GuidanceType.None;
hasAntiSmart = fragAntiSmart || patternAntiSmart || ammo.AmmoDef.Ewar.Type == EwarType.AntiSmart;
hasAntiSmart = fragAntiSmart || patternAntiSmart || ammo.AmmoDef.Ewar.Type == EwarType.AntiSmart || ammo.AmmoDef.Ewar.Type == EwarType.AntiSmartv2;
hasTargetOverride = fragTargetOverride || patternTargetOverride || OverrideTarget;
}

Expand Down Expand Up @@ -957,7 +954,7 @@ private void AreaEffects(AmmoDef ammoDef, out float byBlockHitDepth, out float e
largestHitSize = Math.Max(byBlockHitRadius, Math.Max(endOfLifeRadius, ewarEffectSize));

eWar = ammoDef.Ewar.Enable;
nonAntiSmart = !eWar || ewarType != EwarType.AntiSmart;
nonAntiSmart = !eWar || !(ewarType == EwarType.AntiSmart || ewarType == EwarType.AntiSmartv2);
eWarFieldTrigger = eWar && EwarField && ammoDef.Ewar.Field.TriggerRange > 0;
minArmingTime = ammoDef.AreaOfDamage.EndOfLife.MinArmingTime;
if (ammoDef.AreaOfDamage.ByBlockHit.Enable) byBlockHitDepth = ammoDef.AreaOfDamage.ByBlockHit.Depth <= 0 ? (float)ammoDef.AreaOfDamage.ByBlockHit.Radius : ammoDef.AreaOfDamage.ByBlockHit.Depth;
Expand Down
13 changes: 11 additions & 2 deletions Data/Scripts/CoreSystems/EntityComp/Controls/TerminalHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal static void AddTurretOrTrackingControls<T>(Session session) where T : I
Separator<T>(session, "WC_sep3", IsTrue);

AddWeaponBurstCountSliderRange<T>(session, "Burst Count", Localization.GetText("TerminalBurstShotsTitle"), Localization.GetText("TerminalBurstShotsTooltip"), BlockUi.GetBurstCount, BlockUi.RequestSetBurstCount, CanBurstIsNotBomb, BlockUi.GetMinBurstCount, BlockUi.GetMaxBurstCount, true);
AddWeaponBurstDelaySliderRange<T>(session, "Burst Delay", Localization.GetText("TerminalBurstDelayTitle"), Localization.GetText("TerminalBurstDelayTooltip"), BlockUi.GetBurstDelay, BlockUi.RequestSetBurstDelay, IsNotBomb, BlockUi.GetMinBurstDelay, BlockUi.GetMaxBurstDelay, true);
AddWeaponBurstDelaySliderRange<T>(session, "Burst Delay", Localization.GetText("TerminalBurstDelayTitle"), Localization.GetText("TerminalBurstDelayTooltip"), BlockUi.GetBurstDelay, BlockUi.RequestSetBurstDelay, AllowShotDelay, BlockUi.GetMinBurstDelay, BlockUi.GetMaxBurstDelay, true);
AddWeaponSequenceIdSliderRange<T>(session, "Sequence Id", Localization.GetText("TerminalSequenceIdTitle"), Localization.GetText("TerminalSequenceIdTooltip"), BlockUi.GetSequenceId, BlockUi.RequestSetSequenceId, IsNotBomb, BlockUi.GetMinSequenceId, BlockUi.GetMaxSequenceId, false);
AddWeaponGroupIdIdSliderRange<T>(session, "Weapon Group Id", Localization.GetText("TerminalWeaponGroupIdTitle"), Localization.GetText("TerminalWeaponGroupIdTooltip"), BlockUi.GetWeaponGroupId, BlockUi.RequestSetWeaponGroupId, IsNotBomb, BlockUi.GetMinWeaponGroupId, BlockUi.GetMaxWeaponGroupId, true);

Expand Down Expand Up @@ -316,7 +316,7 @@ internal static bool CanBurst(IMyTerminalBlock block)
if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip())
return false;

return !comp.HasDisabledBurst;
return !comp.ProhibitBurstCount && !comp.HasDisabledBurst;
}

internal static bool CanBurstIsNotBomb(IMyTerminalBlock block)
Expand Down Expand Up @@ -534,6 +534,15 @@ internal static bool IsNotBomb(IMyTerminalBlock block)

return !comp.IsBomb && !comp.HasAlternateUi;
}
internal static bool AllowShotDelay(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
var valid = comp != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Data?.Repo != null;
if (!valid || Session.I.PlayerId != comp.Data.Repo.Values.State.PlayerId && !comp.TakeOwnerShip())
return false;

return !comp.ProhibitShotDelay;
}
internal static bool HasSupport(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public partial class WeaponComponent : CoreComponent
internal bool HasDrone;
internal bool ShootRequestDirty;
internal bool DisableSupportingPD;
internal bool ProhibitShotDelay;
internal bool ProhibitBurstCount;

internal WeaponComponent(MyEntity coreEntity, MyDefinitionId id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,13 @@ internal void UpdateWeaponHeat(object o = null)
{
try
{
var hsRateMod = HsRate + (float)Comp.HeatLoss;
Comp.CurrentHeat = Comp.CurrentHeat >= hsRateMod ? Comp.CurrentHeat - hsRateMod : 0;
PartState.Heat = PartState.Heat >= hsRateMod ? PartState.Heat - hsRateMod : 0;
Comp.HeatLoss = 0;
if (!System.ProhibitCoolingWhenOff || System.ProhibitCoolingWhenOff && Comp.Cube.IsWorking)
{
var hsRateMod = HsRate + (float)Comp.HeatLoss;
Comp.CurrentHeat = Comp.CurrentHeat >= hsRateMod ? Comp.CurrentHeat - hsRateMod : 0;
PartState.Heat = PartState.Heat >= hsRateMod ? PartState.Heat - hsRateMod : 0;
Comp.HeatLoss = 0;
}

var set = PartState.Heat - LastHeat > 0.001 || PartState.Heat - LastHeat < 0.001;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ internal void Load()
if (w.System.Values.HardPoint.HardWare.CriticalReaction.DefaultArmedTimer > Repo.Values.Set.Overrides.ArmedTimer)
Repo.Values.Set.Overrides.ArmedTimer = w.System.Values.HardPoint.HardWare.CriticalReaction.DefaultArmedTimer;

if (Comp.HasDisabledBurst)
Repo.Values.Set.Overrides.BurstCount = w.System.Values.HardPoint.Loading.ShotsInBurst;
}
}

Expand Down
Loading

0 comments on commit 2c20c20

Please sign in to comment.