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 26, 2024
2 parents 94e1e1d + 7922857 commit 1222841
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 70 deletions.
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 ConcurrentDictionary<QueuedSoundEvent, byte> QueuedSounds = new ConcurrentDictionary<QueuedSoundEvent, byte>();
internal readonly List<QueuedSoundEvent> QueuedSounds = new List<QueuedSoundEvent>();
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
21 changes: 2 additions & 19 deletions Data/Scripts/CoreSystems/Ai/AiSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,7 @@ internal List<Projectile> GetProCache(Weapon w, bool supportingPD)
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 @@ -307,10 +292,8 @@ internal void ProcessQueuedSounds()
break;
}
}
*/
}

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

private void WeaponShootOff()
Expand Down
6 changes: 2 additions & 4 deletions Data/Scripts/CoreSystems/Ai/AiTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static bool AcquireTopMostEntity(Weapon w, ProtoWeaponOverrides overRide
var forceFoci = focusOnly || w.System.ScanTrackOnly;
var session = Session.I;
session.TargetRequests++;
var weaponPos = w.BarrelOrigin + (w.MyPivotFwd * w.MuzzleDistToBarrelCenter);
var weaponPos = w.MyPivotPos;
var target = w.NewTarget;
var accelPrediction = (int)s.Values.HardPoint.AimLeadingPrediction > 1;
var minRadius = overRides.MinSize * 0.5f;
Expand Down Expand Up @@ -1042,9 +1042,7 @@ private static bool FindRandomBlock(Weapon w, Target target, TargetInfo info, Co
}
else
{
var barrelPos = w.BarrelOrigin;
var targetNormDir = Vector3D.Normalize(info.Target.PositionComp.WorldAABB.Center - barrelPos);
weaponPos = barrelPos + (targetNormDir * w.MuzzleDistToBarrelCenter);
weaponPos = w.MyPivotPos;
aConst = w.ActiveAmmoDef.AmmoDef.Const;
}

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 @@ -549,6 +549,7 @@ public struct AiDef
[ProtoMember(7)] internal bool OverrideLeads;
[ProtoMember(8)] internal int DefaultLeadGroup;
[ProtoMember(9)] internal bool TargetGridCenter;
[ProtoMember(10)] internal bool PainterUseMaxTargeting;
}

[ProtoContract]
Expand Down
2 changes: 2 additions & 0 deletions Data/Scripts/CoreSystems/Definitions/CoreSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public AmmoType(AmmoDef ammoDef, MyDefinitionId ammoDefinitionId, MyDefinitionId
public readonly bool ClosestFirst;
public readonly bool DegRof;
public readonly bool ProhibitCoolingWhenOff;
public readonly bool PainterUseMaxTargeting;
public readonly bool TrackProjectile;
public readonly bool DisableSupportingPD;
public readonly bool ScanTrackOnly;
Expand Down Expand Up @@ -361,6 +362,7 @@ public WeaponSystem(WeaponStructure structure, MyStringHash partNameIdHash, MySt
AltEjectorName = HasEjector ? "subpart_" + Values.Assignments.Ejector : string.Empty;
HasScope = !string.IsNullOrEmpty(Values.Assignments.Scope);
AltScopeName = HasScope ? "subpart_" + Values.Assignments.Scope : string.Empty;
PainterUseMaxTargeting = Values.HardPoint.Ai.PainterUseMaxTargeting;
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, out ProhibitCoolingWhenOff);
BarrelValues(out BarrelsPerShot, out ShotsPerBurst);
Expand Down
41 changes: 27 additions & 14 deletions Data/Scripts/CoreSystems/EntityComp/EntityEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRageMath;
using static CoreSystems.Platform.CorePlatform;
using static CoreSystems.Session;
using static VRage.Game.ObjectBuilders.Definitions.MyObjectBuilder_GameDefinition;
Expand Down Expand Up @@ -223,12 +224,20 @@ private void AppendingCustomInfoWeapon(IMyTerminalBlock block, StringBuilder str
try
{
var comp = ((Weapon.WeaponComponent)this);
/*
var r = "[color=#DDFF0000]"; //ARGB in hex values
var y = "[color=#DDFFFF00]";
var g = "[color=#DD00FF00]";
var e = "[/color]";
stringBuilder.Append($"{r}Red{e} {y}Yellow{e} {g}Green{e}");
*/

var collection = comp.HasAlternateUi ? SortAndGetTargetTypes() : TypeSpecific != CompTypeSpecific.Phantom ? Platform.Weapons : Platform.Phantoms;
var debug = Debug || comp.Data.Repo.Values.Set.Overrides.Debug;
var advanced = (I.Settings.ClientConfig.AdvancedMode || debug) && !comp.HasAlternateUi;
if (HasServerOverrides)
stringBuilder.Append("\nWeapon modified by server!\n")
.Append("Report issues to server admins.\n");
stringBuilder.Append($"\nWeapon modified by server!\n")
.Append($"Report issues to server admins.\n");

//Start of new formatting
if (IdlePower > 0.01)
Expand All @@ -242,32 +251,36 @@ private void AppendingCustomInfoWeapon(IMyTerminalBlock block, StringBuilder str
{
var chargeTime = w.AssignedPower > 0 ? (int)((w.MaxCharge - w.ProtoWeaponAmmo.CurrentCharge) / w.AssignedPower * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS) : 0;
shots += "\nDraw/Max: " + (SinkPower - IdlePower).ToString("0.00") + "/" + w.ActiveAmmoDef.AmmoDef.Const.PowerPerTick.ToString("0.00") + " MW" +
$"\n{(chargeTime == 0 ? "Charged" : "Charged in " + chargeTime + "s")}";
$"\n{(chargeTime == 0 ? "Power: Charged" : "Power: Charged in " + chargeTime + "s")}";
}

var endReturn = i + 1 != collection.Count ? "\n" : string.Empty;
var timeToLoad = (int)(w.ReloadEndTick - Session.I.Tick) / 60;
var showName = w.ActiveAmmoDef.AmmoDef.Const.TerminalName != w.ActiveAmmoDef.AmmoDef.Const.MagazineDef.DisplayNameText;
var displayName = showName ? w.ActiveAmmoDef.AmmoDef.Const.TerminalName + " (" + w.ActiveAmmoDef.AmmoDef.Const.MagazineDef.DisplayNameText + ")" : w.ActiveAmmoDef.AmmoDef.Const.TerminalName;
stringBuilder.Append($"\n\n" + w.System.PartName +
shots +
$" {(w.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo ? string.Empty : "\n" + (w.Loading ? timeToLoad < 0 ? "Waiting on charge" : "Loaded in " + timeToLoad + "s" : w.ProtoWeaponAmmo.CurrentAmmo > 0 ? "Loaded " + w.ProtoWeaponAmmo.CurrentAmmo + "x " + w.ActiveAmmoDef.AmmoDef.AmmoRound : "No Ammo"))}" +
$" {(w.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo ? string.Empty : "\nAmmo: " + (w.Loading ? timeToLoad < 0 ? "Waiting on charge" : "Loaded in " + timeToLoad + "s": w.ProtoWeaponAmmo.CurrentAmmo > 0 ? "Loaded " + w.ProtoWeaponAmmo.CurrentAmmo + "x " + displayName : "No Ammo"))}" +
$" {(w.ActiveAmmoDef.AmmoDef.Const.RequiresTarget ? "\n" + Localization.GetText("WeaponInfoHasTarget") + ": " + w.Target.HasTarget : string.Empty)}" +
$" {(w.ActiveAmmoDef.AmmoDef.Const.RequiresTarget ? "\n" + Localization.GetText("WeaponInfoLoS") + ": " + (w.Target.HasTarget ? "" + !w.PauseShoot : "No Target") : string.Empty)}" +
endReturn);
}

if (HeatPerSecond > 0)
stringBuilder.Append($"\n{Localization.GetText("WeaponInfoCurrentHeat")}: {CurrentHeat:0.} W ({(CurrentHeat / MaxHeat):P})");
stringBuilder.Append($"\nHeat per Sec/Max: {HeatPerSecond}/{MaxHeat}" +
$"\n{Localization.GetText("WeaponInfoCurrentHeat")}: {CurrentHeat:0.} W ({(CurrentHeat / MaxHeat):P})");

if (advanced)
{
stringBuilder.Append($"\n\n--- Stats ---");
stringBuilder.Append($"\n\n--- Stats ---" +
$"\nDPS: {comp.PeakDps:0.}");
for (int i = 0; i < collection.Count; i++)
{
var w = collection[i];
stringBuilder.Append($"" +
$"{(w.MinTargetDistance > 0 ? "\nMin Range: " + w.MinTargetDistance : string.Empty)}" +
$"\nMax Range: {w.MaxTargetDistance}" +
$"\nRoF: {w.RateOfFire}/min");
stringBuilder.Append($" {(collection.Count > 1 ? "\n{w.FriendlyName}" : string.Empty)}" +
$"{(w.MinTargetDistance > 0 ? "\nMin Range: " + w.MinTargetDistance + "m" : string.Empty)}" +
$"\nMax Range: {w.MaxTargetDistance}m" +
$"\nRoF: {w.ActiveAmmoDef.AmmoDef.Const.RealShotsPerMin}/min");
if(w.ActiveAmmoDef.AmmoDef.Const.RequiresTarget)
{
var targ = "Target: ";
Expand All @@ -277,7 +290,7 @@ private void AppendingCustomInfoWeapon(IMyTerminalBlock block, StringBuilder str
var eTarg = w.Target.TargetObject as MyEntity;
if(pTarg != null)
{

targ += "Projectile";
}
else if (eTarg != null)
{
Expand Down Expand Up @@ -305,9 +318,9 @@ private void AppendingCustomInfoWeapon(IMyTerminalBlock block, StringBuilder str
continue;

if (otherAmmo == null)
otherAmmo = "\n\nMagazine Types:";

otherAmmo += $"\n{ammo.AmmoDef.AmmoRound}";
otherAmmo = "\n\nAmmo Types (Mag if different):";
var showName = ammo.AmmoDef.Const.TerminalName != ammo.AmmoDef.Const.MagazineDef.DisplayNameText && ammo.AmmoDef.Const.MagazineDef.DisplayNameText != "Energy";
otherAmmo += $"\n{ammo.AmmoDef.Const.TerminalName} {(showName ? "(" + ammo.AmmoDef.Const.MagazineDef.DisplayNameText + ")" : "")}";
}

if (otherAmmo != null)
Expand Down
6 changes: 4 additions & 2 deletions Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponAv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ public void StartHardPointSound()

if (Environment.CurrentManagedThreadId != Session.I.MainThreadId)
{
Comp.Ai.QueuedSounds.TryAdd(new Ai.QueuedSoundEvent {Type = Ai.QueuedSoundEvent.SoundTypes.HardPointStart, Weapon = this}, byte.MinValue);
lock (Comp.Ai.QueuedSounds)
Comp.Ai.QueuedSounds.Add(new Ai.QueuedSoundEvent {Type = Ai.QueuedSoundEvent.SoundTypes.HardPointStart, Weapon = this });
return;
}

Expand All @@ -499,7 +500,8 @@ public void StopHardPointSound(object o = null)

if (Environment.CurrentManagedThreadId != Session.I.MainThreadId)
{
Comp.Ai.QueuedSounds.TryAdd(new Ai.QueuedSoundEvent { Type = Ai.QueuedSoundEvent.SoundTypes.HardPointStop, Weapon = this }, byte.MinValue);
lock (Comp.Ai.QueuedSounds)
Comp.Ai.QueuedSounds.Add(new Ai.QueuedSoundEvent { Type = Ai.QueuedSoundEvent.SoundTypes.HardPointStop, Weapon = this });
return;
}

Expand Down
29 changes: 25 additions & 4 deletions Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponComp.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.Remoting;
using CoreSystems.Support;
using Jakaria.API;
using Sandbox.Game.Entities;
Expand All @@ -11,10 +9,11 @@
using Sandbox.ModAPI.Weapons;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRage.Utils;
using VRageMath;
using static VRage.Game.ObjectBuilders.Definitions.MyObjectBuilder_GameDefinition;

namespace CoreSystems.Platform
{
Expand Down Expand Up @@ -1014,8 +1013,30 @@ internal void ImmediateRemoveActiveTarget(object target)

internal void RequestForceReload()
{
var refundMags = !Session.I.IsCreative && TypeSpecific != CompTypeSpecific.Rifle && TypeSpecific != CompTypeSpecific.Phantom && IsWorking && HasInventory;

foreach (var w in Collection)
{
if (refundMags && !w.ActiveAmmoDef.AmmoDef.Const.EnergyAmmo && w.ActiveAmmoDef.AmmoDef.Const.Reloadable)
{
var refundableMags = w.ProtoWeaponAmmo.CurrentAmmo / w.ActiveAmmoDef.AmmoDef.Const.MagazineSize;
if (refundableMags > 0 && Session.I.AmmoMaps.ContainsKey(w.Comp.Structure.SubtypeId) && Session.I.AmmoMaps[w.Comp.Structure.SubtypeId].ContainsKey(w.ActiveAmmoDef.AmmoDef.AmmoRound))
{
var ammoType = Session.I.AmmoMaps[w.Comp.Structure.SubtypeId][w.ActiveAmmoDef.AmmoDef.AmmoRound];
MyInventoryBase inventory;
if(w.Comp.Cube.TryGetInventory(out inventory))
{
while (refundableMags > 0)
{
var successAdd = inventory.AddItems(1, MyObjectBuilderSerializer.CreateNewObject(ammoType.AmmoDefinitionId));
if (!successAdd)
refundableMags = 0;
else
refundableMags--;
}
}
}
}
w.ProtoWeaponAmmo.CurrentAmmo = 0;
w.ProtoWeaponAmmo.CurrentCharge = 0;
w.ClientMakeUpShots = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ internal Weapon(MyEntity entity, WeaponSystem system, int partId, WeaponComponen
}
}
}
catch (Exception ex) { Log.Line($"Exception in {comp.SubtypeName} AnimationsSet for {subtype.String}. Ensure you don't have multiple weapons with different subparts referencing the same AnimationDef: {ex}", null, true); }
catch (Exception ex) { Log.Line($"Exception in {Comp.SubtypeName} AnimationsSet for {Comp.SubTypeId}. Ensure you don't have multiple weapons with different subparts referencing the same AnimationDef: {ex}", null, true); }



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using CoreSystems.Support;
using VRageMath;
using VRage.Utils;
using static CoreSystems.Support.CoreComponent;
using static CoreSystems.Support.WeaponDefinition.AnimationDef.PartAnimationSetDef;

Expand Down Expand Up @@ -208,11 +208,10 @@ internal bool ComputeServerStorage(bool calledFromReload = false)
var magsRequested = (int)((System.FullAmmoVolume - CurrentAmmoVolume) / ActiveAmmoDef.AmmoDef.Const.MagVolume + .0001f);
var magsGranted = magsRequested > spotsFree ? spotsFree : magsRequested;
var requestedVolume = ActiveAmmoDef.AmmoDef.Const.MagVolume * magsGranted;
var spaceAvailable = freeVolume >= requestedVolume;
var spaceAvailable = freeVolume >= requestedVolume || MyUtils.IsEqual(freeVolume, requestedVolume);
var pullAmmo = magsGranted > 0 && CurrentAmmoVolume < System.LowAmmoVolume && spaceAvailable;

var failSafeTimer = s.Tick - LastInventoryTick > 600;

if (pullAmmo && (CheckInventorySystem || failSafeTimer && Comp.Ai.Construct.RootAi.Construct.OutOfAmmoWeapons.Contains(this)) && s.PartToPullConsumable.TryAdd(this, byte.MaxValue)) {

CheckInventorySystem = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,8 @@ internal static bool TrackingTarget(Weapon w, Target target, out bool targetLock
else if (r25 && (w.PrevRangeEvent != EventTriggers.TargetRanged25 || !w.RangeEventActive))
w.EventTriggerStateChanged(EventTriggers.TargetRanged25, true);


var targetDir = targetPos - w.MyPivotPos;
var readyToTrack = validEstimate && !w.Comp.ResettingSubparts && (w.Comp.ManualMode || w.Comp.PainterMode && rangeToTargetSqr <= w.ActiveAmmoDef.AmmoDef.Const.MaxTrajectorySqr && rangeToTargetSqr >= w.MinTargetDistanceSqr || rangeToTargetSqr <= w.MaxTargetDistanceSqr && rangeToTargetSqr >= w.MinTargetDistanceSqr);
var readyToTrack = validEstimate && !w.Comp.ResettingSubparts && (w.Comp.ManualMode || w.Comp.PainterMode && rangeToTargetSqr <= (w.System.PainterUseMaxTargeting ? w.MaxTargetDistanceSqr : w.ActiveAmmoDef.AmmoDef.Const.MaxTrajectorySqr) && rangeToTargetSqr >= w.MinTargetDistanceSqr || rangeToTargetSqr <= w.MaxTargetDistanceSqr && rangeToTargetSqr >= w.MinTargetDistanceSqr);
var locked = true;
var isTracking = false;

Expand Down
7 changes: 4 additions & 3 deletions Data/Scripts/CoreSystems/Projectiles/Projectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,9 +2297,10 @@ private void DroneMissions(MyEntity parentEnt, ref BoundingSphereD orbitSphere,
{
case DroneInfo.DroneMission.Attack:

orbitSphere.Radius += fragProx;
orbitSphereFar.Radius += fragProx + speedLimitPerTick + MaxSpeed; //first whack at dynamic setting
orbitSphereClose.Radius += MaxSpeed * 0.3f + ammo.Shape.Diameter; //Magic number, needs logical work?
orbitSphereClose.Radius = targetSphere.Radius + MaxSpeed * 0.3f + ammo.Shape.Diameter; //Magic number, needs logical work?
orbitSphere.Radius = orbitSphereClose.Radius < fragProx ? fragProx : targetSphere.Radius + fragProx *0.5f;
orbitSphereFar.Radius = orbitSphere.Radius + fragProx + speedLimitPerTick + MaxSpeed; //first whack at dynamic setting

if (hasObstacle && orbitSphereClose.Contains(s.Obstacle.Entity.PositionComp.GetPosition()) != ContainmentType.Contains && s.DroneInfo.DroneStat != DroneInfo.DroneStatus.Kamikaze)
{
orbitSphereClose = s.Obstacle.Entity.PositionComp.WorldVolume;
Expand Down
1 change: 0 additions & 1 deletion Data/Scripts/CoreSystems/Session/SessionCleanUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ internal void PurgeAll()
GridMapPool.Clean();

DirtyGridsTmp.Clear();
PlayersToAdd.Clear();
WeaponValuesMap.Clear();
AmmoValuesMap.Clear();

Expand Down
1 change: 1 addition & 0 deletions Data/Scripts/CoreSystems/Session/SessionDamageMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ private void DamageDestObj(HitEntity hitEnt, ProInfo info)
var destObj = hitEnt.Entity as IMyDestroyableObject;

if (destObj == null || entity == null) return;
info.ObjectsHit++;

var directDmgGlobal = Settings.Enforcement.DirectDamageModifer;
var areaDmgGlobal = Settings.Enforcement.AreaDamageModifer;
Expand Down
Loading

0 comments on commit 1222841

Please sign in to comment.