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 Sep 12, 2024
2 parents 54710fd + 83f8e0c commit 8e4dcac
Show file tree
Hide file tree
Showing 27 changed files with 349 additions and 216 deletions.
28 changes: 28 additions & 0 deletions Data/Scripts/CoreSystems/Ai/AiEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ internal void FatBlockAdded(MyCubeBlock cube)
//cube.CubeGrid.RemoveBlock(cube.SlimBlock, true);
}
}

//Projected block ammo removal
var slim = cube.SlimBlock as IMySlimBlock;
if (slim.BuildLevelRatio < 1 && cube.Storage != null && cube.Storage.ContainsKey(Session.I.CompDataGuid) && slim.ComponentStack.GetComponentStackInfo(0).MountedCount == 1)
{
ProtoWeaponRepo load = null;
string rawData;
if (cube.Storage.TryGetValue(Session.I.CompDataGuid, out rawData))
{
try
{
var base64 = Convert.FromBase64String(rawData);
load = MyAPIGateway.Utilities.SerializeFromBinary<ProtoWeaponRepo>(base64);
foreach (var ammo in load.Ammos)
{
ammo.CurrentAmmo = 0;
ammo.CurrentCharge = 0;
}
var save = MyAPIGateway.Utilities.SerializeToBinary<ProtoWeaponRepo>(load);
var base64Out = Convert.ToBase64String(save);
cube.Storage[Session.I.CompDataGuid] = base64Out;
}
catch (Exception e)
{
Log.Line("WeaponCore failed to strip ammo from projector placed block\n" + e);
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Ai/AiFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public partial class Ai
internal readonly ConcurrentDictionary<MyCubeGrid, byte> SubGridsRegistered = new ConcurrentDictionary<MyCubeGrid, byte>();
internal readonly double[] QuadraticCoefficientsStorage = new double[5];

internal readonly List<QueuedSoundEvent> QueuedSounds = new List<QueuedSoundEvent>();
internal readonly ConcurrentDictionary<QueuedSoundEvent, byte> QueuedSounds = new ConcurrentDictionary<QueuedSoundEvent, byte>();
internal readonly List<WeaponComponent> TrackingComps = new List<WeaponComponent>();
internal readonly List<WeaponComponent> WeaponComps = new List<WeaponComponent>(32);
internal readonly List<WeaponComponent> CriticalComps = new List<WeaponComponent>();
Expand Down
19 changes: 18 additions & 1 deletion Data/Scripts/CoreSystems/Ai/AiSupport.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.EntityComponents;
Expand Down Expand Up @@ -278,6 +279,21 @@ internal void ProcessQueuedSounds()
{
if (Session.I.HandlesInput && Environment.CurrentManagedThreadId == Session.I.MainThreadId)
{
foreach (var qs in QueuedSounds.Keys.ToArray())
{
switch (qs.Type)
{
case QueuedSoundEvent.SoundTypes.HardPointStart:
qs.Weapon.StartHardPointSound();
break;
case QueuedSoundEvent.SoundTypes.HardPointStop:
qs.Weapon.StopHardPointSound();
break;
}
byte val;
QueuedSounds.TryRemove(qs, out val);
}
/*
for (int i = 0; i < QueuedSounds.Count; i++)
{
var qs = QueuedSounds[i];
Expand All @@ -291,9 +307,10 @@ internal void ProcessQueuedSounds()
break;
}
}
*/
}

QueuedSounds.Clear();
//QueuedSounds.Clear();
}

private void WeaponShootOff()
Expand Down
16 changes: 9 additions & 7 deletions Data/Scripts/CoreSystems/Ai/AiTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private static bool AcquireTopMostEntity(Weapon w, ProtoWeaponOverrides overRide
if (w.FailedAcquires > 9 && !w.DelayedAcquire(info))
continue;

if (!AcquireBlock(w, target, info, ref waterSphere, ref w.TargetData.WeaponRandom.AcquireRandom, null, !focusTarget))
if (!AcquireBlock(w, target, info, ref waterSphere, ref w.TargetData.WeaponRandom.AcquireRandom, null, focusTarget))
continue;

target.TransferTo(w.Target, Session.I.Tick);
Expand Down Expand Up @@ -822,7 +822,7 @@ internal static bool ReacquireTarget(Projectile p)

if (!s.TrackGrids || !overRides.Grids || !focusTarget && tInfo.FatCount < 2 || !aConst.CheckFutureIntersection && Obstruction(ref tInfo, ref targetPos, p) || (!overRides.LargeGrid && tInfo.LargeGrid) || (!overRides.SmallGrid && !tInfo.LargeGrid)) continue;

if (!AcquireBlock(w, target, tInfo, ref waterSphere, ref info.Random, p, !focusTarget)) continue;
if (!AcquireBlock(w, target, tInfo, ref waterSphere, ref info.Random, p, focusTarget)) continue;
acquired = true;
break;
}
Expand Down Expand Up @@ -985,13 +985,15 @@ internal static bool ReAcquireProjectile(Projectile p)

return found;
}
private static bool AcquireBlock(Weapon w, Target target, TargetInfo info, ref BoundingSphereD waterSphere, ref XorShiftRandomStruct xRnd, Projectile p, bool checkPower = true)
private static bool AcquireBlock(Weapon w, Target target, TargetInfo info, ref BoundingSphereD waterSphere, ref XorShiftRandomStruct xRnd, Projectile p, bool focusedTarget)
{
var system = w.System;
var overRides = w.RotorTurretTracking ? w.Comp.MasterOverrides : w.Comp.Data.Repo.Values.Set.Overrides;

var checkPower = overRides.ObjectiveMode == ProtoWeaponOverrides.ObjectiveModes.Default && !focusedTarget || overRides.ObjectiveMode == ProtoWeaponOverrides.ObjectiveModes.Disabled;
if (system.TargetSubSystems)
{
var overRides = w.RotorTurretTracking ? w.Comp.MasterOverrides : w.Comp.Data.Repo.Values.Set.Overrides;


var targetLinVel = info.Target.Physics?.LinearVelocity ?? Vector3D.Zero;
var targetAccel = (int)system.Values.HardPoint.AimLeadingPrediction > 1 ? info.Target.Physics?.LinearAcceleration ?? Vector3D.Zero : Vector3.Zero;

Expand Down Expand Up @@ -1025,7 +1027,7 @@ private static bool AcquireBlock(Weapon w, Target target, TargetInfo info, ref B
return Session.I.TopEntityToInfoMap.TryGetValue((MyCubeGrid)info.Target, out topMap) && topMap.MyCubeBocks != null && FindRandomBlock(w, target, info, topMap.MyCubeBocks, ref waterSphere, ref xRnd, p, checkPower);
}

private static bool FindRandomBlock(Weapon w, Target target, TargetInfo info, ConcurrentCachingList<MyCubeBlock> subSystemList, ref BoundingSphereD waterSphere, ref XorShiftRandomStruct xRnd, Projectile p, bool checkPower = true)
private static bool FindRandomBlock(Weapon w, Target target, TargetInfo info, ConcurrentCachingList<MyCubeBlock> subSystemList, ref BoundingSphereD waterSphere, ref XorShiftRandomStruct xRnd, Projectile p, bool checkPower)
{
var totalBlocks = subSystemList.Count;
var system = w.System;
Expand Down Expand Up @@ -1821,7 +1823,7 @@ internal static bool SwitchToDrone(Weapon w)
continue;
}

if (!AcquireBlock(w, target, info, ref waterSphere, ref w.TargetData.WeaponRandom.AcquireRandom, null, true)) continue;
if (!AcquireBlock(w, target, info, ref waterSphere, ref w.TargetData.WeaponRandom.AcquireRandom, null, false)) continue;
target.TransferTo(w.Target, Session.I.Tick, true);

var validTarget = w.Target.TargetState == Target.TargetStates.IsEntity;
Expand Down
4 changes: 4 additions & 0 deletions Data/Scripts/CoreSystems/AudioVisual/RunAv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ internal void End()
}
if (av.Hit.Entity != null && av.AmmoDef.AmmoGraphics.Decals.MaxAge > 0 && !Vector3D.IsZero(av.Hit.SurfaceHit) && av.AmmoDef.Const.TextureHitMap.Count > 0 && !av.Hit.Entity.MarkedForClose && av.Hit.Entity.InScene)
{
//Starcore bug report on decals, parent "not found" and world position goes to NaN
var shield = av.Hit.Entity as IMyUpgradeModule;
var floating = av.Hit.Entity as MyFloatingObject;
if (shield == null && floating == null)
Expand Down Expand Up @@ -200,6 +201,9 @@ internal void End()
Position = av.Hit.SurfaceHit + (av.Direction * 0.01),
Normal = av.Direction,
};


//Log.Line($"Decal: {av.Hit.Entity.DebugName} mat{materialType} closed?{av.Hit.Entity.Closed} posCompNull?{av.Hit.Entity.PositionComp != null}");

//MyDecals.HandleAddDecal(av.Hit.Entity, hitInfo, Vector3.Zero, materialType, projectileMaterial, null, -1, voxelMaterial, false, MyDecalFlags.IgnoreOffScreenDeletion, MyAPIGateway.Session.GameplayFrameCounter + av.AmmoDef.AmmoGraphics.Decals.MaxAge);
}
Expand Down
1 change: 1 addition & 0 deletions Data/Scripts/CoreSystems/Definitions/CoreDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public class AmmoDef
[ProtoMember(30)] internal SynchronizeDef Sync;
[ProtoMember(31)] internal bool NoGridOrArmorScaling;
[ProtoMember(32)] internal string TerminalName;
[ProtoMember(33)] internal float BaseDamageCutoff;


[ProtoContract]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,6 @@ internal AmmoConstants(WeaponSystem.AmmoType ammo, WeaponDefinition wDef, Weapon
DynamicGuidance = ammo.AmmoDef.Trajectory.Guidance != TrajectoryDef.GuidanceType.None && ammo.AmmoDef.Trajectory.Guidance != TrajectoryDef.GuidanceType.TravelTo && !IsBeamWeapon;

if (CollisionSize > 5 && !Session.I.LocalVersion) Log.Line($"{ammo.AmmoDef.AmmoRound} has large largeCollisionSize: {CollisionSize} meters");
if (FeelsGravity && !IsSmart && system.TrackTargets && (system.Prediction == Prediction.Off || system.Prediction == Prediction.Basic) && ammo.AmmoDef.Trajectory.MaxTrajectory / ammo.AmmoDef.Trajectory.DesiredSpeed > 0.5f)
{
var flightTime = ammo.AmmoDef.Trajectory.MaxTrajectory / ammo.AmmoDef.Trajectory.DesiredSpeed;
Log.Line($"{ammo.AmmoDef.AmmoRound} has {(int)(0.5 * 9.8 * flightTime * flightTime)}m grav drop at 1g. {system.PartName} needs Accurate/Advanced aim prediction to account for gravity.");
}

FullSync = ammo.AmmoDef.Sync.Full && Session.I.MpActive && (IsDrone || IsSmart);
PdDeathSync = !FullSync && ammo.AmmoDef.Sync.PointDefense && Session.I.MpActive && Health > 0 && !IsBeamWeapon && !Ewar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,13 @@ public enum ControlModes
Painter,
}

public enum ObjectiveModes
{
Default,
Disabled,
Destroyed,
}

[ProtoMember(1)] public bool Neutrals;
[ProtoMember(2)] public bool Unowned;
[ProtoMember(3)] public bool Friendly;
Expand Down Expand Up @@ -667,6 +674,8 @@ public enum ControlModes
[ProtoMember(33), DefaultValue(true)] public bool SmallGrid = true;
[ProtoMember(34)] public bool AngularTracking;
[ProtoMember(35), DefaultValue(true)] public bool SupportingPD = true;
[ProtoMember(36), DefaultValue(ObjectiveModes.Default)] public ObjectiveModes ObjectiveMode = ObjectiveModes.Default;




Expand Down Expand Up @@ -703,7 +712,7 @@ public void Sync(ProtoWeaponOverrides syncFrom)
LargeGrid = syncFrom.LargeGrid;
SmallGrid = syncFrom.SmallGrid;
SupportingPD = syncFrom.SupportingPD;

ObjectiveMode = syncFrom.ObjectiveMode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,28 @@ public static void CreateAngularTracking(Session session)
action.Name = new StringBuilder("Predict Targets Angular Motion");
action.Action = CustomActions.TerminalActionToggleAngularTracking;
action.Writer = CustomActions.AngularTrackingWriter;
action.Enabled = TerminalHelpers.IsNotBomb;
action.Enabled = TerminalHelpers.HasTracking;
action.ValidForGroups = true;

MyAPIGateway.TerminalControls.AddAction<T>(action);
session.CustomActions.Add(action);
}


internal static void CreateObjectiveMode(Session session)
{
var action = MyAPIGateway.TerminalControls.CreateAction<T>("ObjectiveMode");
action.Icon = @"Textures\GUI\Icons\Actions\Toggle.dds";
action.Name = new StringBuilder("Cycle Objective Mode");//Need localization input
action.Action = CustomActions.TerminActionCycleObjectiveMode;
action.Writer = CustomActions.ObjectiveModeWriter;
action.Enabled = TerminalHelpers.HasTracking;
action.ValidForGroups = true;

MyAPIGateway.TerminalControls.AddAction<T>(action);
session.CustomActions.Add(action);
}


public static void CreateFocusTargets(Session session)
{
var action = MyAPIGateway.TerminalControls.CreateAction<T>("FocusTargets");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ internal static void AddTurretOrTrackingControls<T>(Session session) where T : I
{
AddComboboxNoAction<T>(session, "ControlModes", Localization.GetText("TerminalControlModesTitle"), Localization.GetText("TerminalControlModesTooltip"), BlockUi.GetControlMode, BlockUi.RequestControlMode, BlockUi.ListControlModes, TurretOrGuidedAmmo);

AddComboboxNoAction<T>(session, "ObjectiveMode", "Objective Mode", "Select when to cease firing at a block", BlockUi.GetObjectiveMode, BlockUi.RequestObjectiveMode, BlockUi.ListObjectiveModes, HasTracking);

AddComboboxNoAction<T>(session, "PickAmmo", Localization.GetText("TerminalPickAmmoTitle"), Localization.GetText("TerminalPickAmmoTooltip"), BlockUi.GetAmmos, BlockUi.RequestSetAmmo, BlockUi.ListAmmos, AmmoSelection);

AddComboboxNoAction<T>(session, "PickSubSystem", Localization.GetText("TerminalPickSubSystemTitle"), Localization.GetText("TerminalPickSubSystemTooltip"), BlockUi.GetSubSystem, BlockUi.RequestSubSystem, BlockUi.ListSubSystems, HasTracking);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ internal static void TerminActionCycleShootMode(IMyTerminalBlock blk)
Weapon.WeaponComponent.RequestSetValue(comp, "ShootMode", value, Session.I.PlayerId);
}

internal static void TerminActionCycleObjectiveMode(IMyTerminalBlock blk)
{
var comp = blk?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready)
return;

var numValue = (int)comp.Data.Repo.Values.Set.Overrides.ObjectiveMode;
var value = numValue + 1 <= 2 ? numValue + 1 : 0;

Weapon.WeaponComponent.RequestSetValue(comp, "ObjectiveMode", value, Session.I.PlayerId);
}


internal static void TerminActionCycleMouseControl(IMyTerminalBlock blk)
{
Expand Down Expand Up @@ -683,6 +695,14 @@ internal static void ShootModeWriter(IMyTerminalBlock blk, StringBuilder sb)
sb.Append(altAiControlName);
}

internal static void ObjectiveModeWriter(IMyTerminalBlock blk, StringBuilder sb)
{
var comp = blk.Components.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return;

sb.Append(comp.Data.Repo.Values.Set.Overrides.ObjectiveMode);
}

private const string InActive = "Inactive";
internal static void MouseToggleWriter(IMyTerminalBlock blk, StringBuilder sb)
{
Expand Down
27 changes: 27 additions & 0 deletions Data/Scripts/CoreSystems/EntityComp/Controls/Weapon/WeaponUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,33 @@ internal static void ListMovementModes(List<MyTerminalControlComboBoxItem> moveL
new MyTerminalControlComboBoxItem { Key = 3, Value = MyStringId.GetOrCompute($"{(ProtoWeaponOverrides.MoveModes)3}") },
};

internal static long GetObjectiveMode(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return 0;
return (int)comp.Data.Repo.Values.Set.Overrides.ObjectiveMode;
}

internal static void RequestObjectiveMode(IMyTerminalBlock block, long newValue)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready) return;

Weapon.WeaponComponent.RequestSetValue(comp, "ObjectiveMode", (int)newValue, Session.I.PlayerId);
}

internal static void ListObjectiveModes(List<MyTerminalControlComboBoxItem> moveList)
{
foreach (var sub in ObjectiveList) moveList.Add(sub);
}

private static readonly List<MyTerminalControlComboBoxItem> ObjectiveList = new List<MyTerminalControlComboBoxItem>
{
new MyTerminalControlComboBoxItem { Key = 0, Value = MyStringId.GetOrCompute($"{(ProtoWeaponOverrides.ObjectiveModes)0}") },
new MyTerminalControlComboBoxItem { Key = 1, Value = MyStringId.GetOrCompute($"{(ProtoWeaponOverrides.ObjectiveModes)1}") },
new MyTerminalControlComboBoxItem { Key = 2, Value = MyStringId.GetOrCompute($"{(ProtoWeaponOverrides.ObjectiveModes)2}") },
};

internal static long GetControlMode(IMyTerminalBlock block)
{
var comp = block?.Components?.Get<CoreComponent>() as Weapon.WeaponComponent;
Expand Down
Loading

0 comments on commit 8e4dcac

Please sign in to comment.