Skip to content

Commit

Permalink
Merge pull request #25 from StarCoreSE/upstreamattempt2024
Browse files Browse the repository at this point in the history
merge upstream wc
  • Loading branch information
InvalidArgument3 authored Aug 6, 2024
2 parents 4e878db + d0e81c0 commit 3ada976
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 135 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 @@ -69,7 +69,7 @@ public partial class Ai
internal readonly List<SupportSys.SupportComponent> SupportComps = new List<SupportSys.SupportComponent>(32);
internal readonly List<ControlSys.ControlComponent> ControlComps = new List<ControlSys.ControlComponent>(32);
internal readonly List<WeaponComponent> PhantomComps = new List<WeaponComponent>(32);
internal readonly List<Projectile> DeadProjectiles = new List<Projectile>();
internal readonly HashSet<Projectile> DeadProjectiles = new HashSet<Projectile>();
internal readonly List<Ai> TargetAisTmp = new List<Ai>();
internal readonly List<Shields> NearByShieldsTmp = new List<Shields>();
internal readonly List<MyEntity> NearByFriendlyShields = new List<MyEntity>();
Expand Down
1 change: 0 additions & 1 deletion Data/Scripts/CoreSystems/Ai/AiSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ private static int[] GetDeck(ref int[] deck, int firstCard, int cardsToSort, int
deck[i] = deck[j];
deck[j] = i + firstCard;
}

return deck;
}

Expand Down
60 changes: 27 additions & 33 deletions Data/Scripts/CoreSystems/Ai/AiTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private static bool AcquireTopMostEntity(Weapon w, ProtoWeaponOverrides overRide
var character = info.Target as IMyCharacter;

var targetRadius = character != null ? info.TargetRadius * 5 : info.TargetRadius;
if (targetRadius < minTargetRadius || info.TargetRadius > maxTargetRadius && maxTargetRadius < 8192 || !focusTarget && info.OffenseRating <= 0) continue;
if (targetRadius <= minTargetRadius || info.TargetRadius >= maxTargetRadius && maxTargetRadius < 8192 || !focusTarget && info.OffenseRating <= 0) continue;

var targetCenter = info.Target.PositionComp.WorldAABB.Center;
var targetDistSqr = Vector3D.DistanceSquared(targetCenter, weaponPos);
Expand All @@ -244,25 +244,24 @@ private static bool AcquireTopMostEntity(Weapon w, ProtoWeaponOverrides overRide
Vector3D targetLinVel = info.Target.Physics?.LinearVelocity ?? Vector3D.Zero;
Vector3D targetAccel = accelPrediction ? info.Target.Physics?.LinearAcceleration ?? Vector3D.Zero : Vector3.Zero;
Vector3D predictedPos;
if (w.System.TargetGridCenter)
{
if (!Weapon.CanShootTarget(w, ref targetCenter, targetLinVel, targetAccel, out predictedPos, false, null, MathFuncs.DebugCaller.CanShootTarget2)) continue;
double rayDist;
Vector3D.Distance(ref weaponPos, ref targetCenter, out rayDist);
var shortDist = rayDist;
var origDist = rayDist;
var topEntId = info.Target.GetTopMostParent().EntityId;
target.Set(info.Target, targetCenter, shortDist, origDist, topEntId);
target.TransferTo(w.Target, Session.I.Tick);

if (w.Target.TargetState == Target.TargetStates.IsEntity)
Session.I.NewThreat(w);
return true;
}

if (info.IsGrid)
{
if (!s.TrackGrids || !overRides.Grids || (!overRides.LargeGrid && info.LargeGrid) || (!overRides.SmallGrid && !info.LargeGrid) || !focusTarget && info.FatCount < 2) continue;
if (w.System.TargetGridCenter)
{
if (!Weapon.CanShootTarget(w, ref targetCenter, targetLinVel, targetAccel, out predictedPos, false, null, MathFuncs.DebugCaller.CanShootTarget2)) continue;
double rayDist;
Vector3D.Distance(ref weaponPos, ref targetCenter, out rayDist);
var shortDist = rayDist;
var origDist = rayDist;
var topEntId = info.Target.GetTopMostParent().EntityId;
target.Set(info.Target, targetCenter, shortDist, origDist, topEntId);
target.TransferTo(w.Target, Session.I.Tick);
if (w.Target.TargetState == Target.TargetStates.IsEntity)
Session.I.NewThreat(w);
return true;
}
session.CanShoot++;
Vector3D newCenter;
if (!w.TurretController && !w.RotorTurretTracking)
Expand Down Expand Up @@ -291,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.XorRnd, 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 @@ -437,7 +436,7 @@ private static bool AcquireObstruction(Weapon w, ProtoWeaponOverrides overRides)


var targetRadius = character != null ? info.Target.PositionComp.LocalVolume.Radius * 5 : info.Target.PositionComp.LocalVolume.Radius;
if (targetRadius < minTargetRadius || targetRadius > maxTargetRadius && maxTargetRadius < 8192) continue;
if (targetRadius <= minTargetRadius || targetRadius >= maxTargetRadius && maxTargetRadius < 8192) continue;

var targetCenter = info.Target.PositionComp.WorldAABB.Center;
var targetDistSqr = Vector3D.DistanceSquared(targetCenter, weaponPos);
Expand Down Expand Up @@ -604,7 +603,7 @@ internal static bool AcquireProjectile(Weapon w, ulong id = ulong.MaxValue)
continue;

var targetRadius = lpaConst.CollisionSize;
if (targetRadius < minTargetRadius || targetRadius > maxTargetRadius && maxTargetRadius < 8192) continue;
if (targetRadius <= minTargetRadius || targetRadius >= maxTargetRadius && maxTargetRadius < 8192) continue;

var lpAccel = lp.Velocity - lp.PrevVelocity;

Expand Down Expand Up @@ -811,7 +810,7 @@ internal static bool ReacquireTarget(Projectile p)
continue;

var targetRadius = tInfo.Target.PositionComp.LocalVolume.Radius;
if (targetRadius < minTargetRadius || targetRadius > maxTargetRadius && maxTargetRadius < 8192 || topTarget != null && tInfo.Target != topTarget) continue;
if (targetRadius <= minTargetRadius || targetRadius >= maxTargetRadius && maxTargetRadius < 8192 || topTarget != null && tInfo.Target != topTarget) continue;
if (water != null)
{
if (new BoundingSphereD(ai.MyPlanet.PositionComp.WorldAABB.Center, water.MinRadius).Contains(new BoundingSphereD(targetPos, targetRadius)) == ContainmentType.Contains)
Expand Down Expand Up @@ -916,7 +915,7 @@ internal static bool ReAcquireProjectile(Projectile p)
continue;

var targetRadius = lpaConst.CollisionSize;
if (targetRadius < minTargetRadius || targetRadius > maxTargetRadius && maxTargetRadius < 8192) continue;
if (targetRadius <= minTargetRadius || targetRadius >= maxTargetRadius && maxTargetRadius < 8192) continue;

var needsCast = false;

Expand Down Expand Up @@ -992,16 +991,13 @@ private static bool AcquireBlock(Weapon w, Target target, TargetInfo info, ref B
if (system.TargetSubSystems)
{
var overRides = w.RotorTurretTracking ? w.Comp.MasterOverrides : w.Comp.Data.Repo.Values.Set.Overrides;
var subSystems = system.Values.Targeting.SubSystems;
var focusSubSystem = overRides.FocusSubSystem || overRides.FocusSubSystem;

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

foreach (var blockType in subSystems)
foreach (var blockType in system.Values.Targeting.SubSystems)
{
var bt = focusSubSystem ? subSystem : blockType;
var bt = overRides.FocusSubSystem ? overRides.SubSystem : blockType;

ConcurrentDictionary<BlockTypes, ConcurrentCachingList<MyCubeBlock>> blockTypeMap;
Session.I.GridToBlockTypeMap.TryGetValue((MyCubeGrid)info.Target, out blockTypeMap);
Expand All @@ -1020,10 +1016,10 @@ private static bool AcquireBlock(Weapon w, Target target, TargetInfo info, ref B
else if (FindRandomBlock(w, target, info, subSystemList, ref waterSphere, ref xRnd, p, checkPower)) return true;
}

if (focusSubSystem) break;
if (overRides.FocusSubSystem) break;
}

if (system.OnlySubSystems || focusSubSystem && subSystem != Any) return false;
if (system.OnlySubSystems || overRides.FocusSubSystem && overRides.SubSystem != Any) return false;
}
TopMap topMap;
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);
Expand Down Expand Up @@ -1073,10 +1069,8 @@ private static bool FindRandomBlock(Weapon w, Target target, TargetInfo info, Co
if (totalBlocks < lastBlocks) lastBlocks = totalBlocks;

int checkSize;
if (w.System.CycleBlocks <= 0)
if (w.System.CycleBlocks <= 0 || w.System.CycleBlocks >= totalBlocks)
checkSize = totalBlocks;
else if (w.System.CycleBlocks > totalBlocks)
checkSize = w.System.CycleBlocks - totalBlocks;
else
checkSize = w.System.CycleBlocks;

Expand Down Expand Up @@ -1789,7 +1783,7 @@ internal static bool SwitchToDrone(Weapon w)

var character = info.Target as IMyCharacter;
var targetRadius = character != null ? info.TargetRadius * 5 : info.TargetRadius;
if (targetRadius < minTargetRadius || info.TargetRadius > maxTargetRadius && maxTargetRadius < 8192) continue;
if (targetRadius <= minTargetRadius || info.TargetRadius >= maxTargetRadius && maxTargetRadius < 8192) continue;

var targetCenter = info.Target.PositionComp.WorldAABB.Center;
var targetDistSqr = Vector3D.DistanceSquared(targetCenter, weaponPos);
Expand Down Expand Up @@ -1827,7 +1821,7 @@ internal static bool SwitchToDrone(Weapon w)
continue;
}

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

var validTarget = w.Target.TargetState == Target.TargetStates.IsEntity;
Expand Down
5 changes: 4 additions & 1 deletion Data/Scripts/CoreSystems/Ai/AiTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ internal void Sync(PaintedTargetPacket packet, Ai ai)

internal FakeWorldTargetInfo GetFakeTargetInfo(Ai ai)
{
var cleared = false;
if (TmpEntity != null && EntityId == TmpEntity.EntityId && TmpEntity.Physics != null && !TmpEntity.MarkedForClose && !TmpEntity.Closed)
{
if (Session.I.Tick != LastInfoTick)
Expand All @@ -273,15 +274,17 @@ internal FakeWorldTargetInfo GetFakeTargetInfo(Ai ai)
else if (Type == FakeType.Painted && EntityId != 0)
{
ClearMark(Session.I.Tick, MarkClearResons.PaintSwitchOrNoTargetInDb);
cleared = true;
}
}
}
else if (Type == FakeType.Painted && EntityId != 0)
{
ClearMark(Session.I.Tick, MarkClearResons.NoTarget);
cleared = true;
}

return FakeInfo;
return cleared ? null : FakeInfo;
}

internal enum MarkClearResons
Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Api/ApiBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ private bool SetAiFocus(MyEntity shooter, MyEntity target, int priority = 0)
{
var topEntity = shooter.GetTopMostParent();

if (topEntity != null)
if (topEntity != null && target != null)
{
Ai ai;
if (Session.I.EntityToMasterAi.TryGetValue(topEntity, out ai))
Expand Down
9 changes: 5 additions & 4 deletions Data/Scripts/CoreSystems/Definitions/CoreSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using static CoreSystems.Support.PartAnimation;
using static CoreSystems.Support.WeaponDefinition;
using static CoreSystems.Support.WeaponDefinition.AmmoDef.AreaOfDamageDef;
using static CoreSystems.Support.WeaponDefinition.AnimationDef;
using static CoreSystems.Support.WeaponDefinition.AnimationDef.PartAnimationSetDef;
using static CoreSystems.Support.WeaponDefinition.HardPointDef;
using static CoreSystems.Support.WeaponDefinition.TargetingDef.CommunicationDef;
Expand All @@ -33,7 +34,7 @@ public class CoreSystem
public Dictionary<string, EmissiveState> PartEmissiveSet;
public Dictionary<string, Matrix[]> PartLinearMoveSet;
public string[] HeatingSubparts;

public Dictionary<string, PartEmissive> EmissiveLookup;
}

internal class UpgradeSystem : CoreSystem
Expand All @@ -57,7 +58,7 @@ public UpgradeSystem(MyStringHash partNameIdHash, UpgradeDefinition values, stri
StayCharged = values.HardPoint.Other.StayCharged;
IdlePower = values.HardPoint.HardWare.IdlePower > 0 ? values.HardPoint.HardWare.IdlePower : 0.001f;

Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents);
Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents, out EmissiveLookup);

}
}
Expand All @@ -81,7 +82,7 @@ public SupportSystem(MyStringHash partNameIdHash, SupportDefinition values, stri
StayCharged = values.HardPoint.Other.StayCharged;
IdlePower = values.HardPoint.HardWare.IdlePower > 0 ? values.HardPoint.HardWare.IdlePower : 0.001f;

Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents);
Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents, out EmissiveLookup);

}
}
Expand Down Expand Up @@ -368,7 +369,7 @@ public WeaponSystem(WeaponStructure structure, MyStringHash partNameIdHash, MySt
GetThreats(out Threats, out ProjectilesFirst, out ProjectilesOnly);
SubSystems(out TargetSubSystems, out OnlySubSystems);
ValidTargetSize(out MinTargetRadius, out MaxTargetRadius);
Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents);
Session.CreateAnimationSets(Values.Animations, this, out WeaponAnimationSet, out PartEmissiveSet, out PartLinearMoveSet, out AnimationIdLookup, out PartAnimationLengths, out HeatingSubparts, out ParticleEvents, out EmissiveLookup);

// CheckForBadAnimations();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public enum Texture
public readonly double MinOffsetLength;
public readonly double MaxOffsetLength;
public readonly double FragProximity;
public readonly double FragProximitySqr;
public readonly double SmartOffsetSqr;
public readonly double HeatModifier;
public readonly double AccelInMetersPerSec;
Expand Down Expand Up @@ -445,7 +446,7 @@ internal AmmoConstants(WeaponSystem.AmmoType ammo, WeaponDefinition wDef, Weapon
TargetLossDegree = ammo.AmmoDef.Trajectory.TargetLossDegree > 0 ? (float)Math.Cos(MathHelper.ToRadians(ammo.AmmoDef.Trajectory.TargetLossDegree)) : 0;

Fragments(ammo, out HasFragmentOffset, out HasNegFragmentOffset, out FragmentOffset, out FragRadial, out FragDegrees, out FragReverse, out FragDropVelocity, out FragMaxChildren, out FragIgnoreArming, out FragOnEolArmed, out ArmedWhenHit, out FragOnEnd, out HasAdvFragOffset, out FragOffset);
TimedSpawn(ammo, out TimedFragments, out FragStartTime, out FragInterval, out MaxFrags, out FragGroupSize, out FragGroupDelay, out FragProximity, out HasFragProximity, out FragParentDies, out FragPointAtTarget, out HasFragGroup, out FragPointType, out DirectAimCone, out UseAimCone);
TimedSpawn(ammo, out TimedFragments, out FragStartTime, out FragInterval, out MaxFrags, out FragGroupSize, out FragGroupDelay, out FragProximity, out HasFragProximity, out FragParentDies, out FragPointAtTarget, out HasFragGroup, out FragPointType, out DirectAimCone, out UseAimCone, out FragProximitySqr);

ArmorCoreActive = Session.I.ArmorCoreActive;

Expand Down Expand Up @@ -803,7 +804,7 @@ private void Fragments(WeaponSystem.AmmoType ammo, out bool hasFragmentOffset, o
fragOffset = ammo.AmmoDef.Fragment.AdvOffset;
}

private void TimedSpawn(WeaponSystem.AmmoType ammo, out bool timedFragments, out int startTime, out int interval, out int maxSpawns, out int groupSize, out int groupDelay, out double proximity, out bool hasProximity, out bool parentDies, out bool pointAtTarget, out bool hasGroup, out PointTypes pointType, out float directAimCone, out bool useAimCone)
private void TimedSpawn(WeaponSystem.AmmoType ammo, out bool timedFragments, out int startTime, out int interval, out int maxSpawns, out int groupSize, out int groupDelay, out double proximity, out bool hasProximity, out bool parentDies, out bool pointAtTarget, out bool hasGroup, out PointTypes pointType, out float directAimCone, out bool useAimCone, out double proximitySqr)
{
timedFragments = ammo.AmmoDef.Fragment.TimedSpawns.Enable && HasFragment;
startTime = ammo.AmmoDef.Fragment.TimedSpawns.StartTime;
Expand All @@ -819,6 +820,7 @@ private void TimedSpawn(WeaponSystem.AmmoType ammo, out bool timedFragments, out
pointType = ammo.AmmoDef.Fragment.TimedSpawns.PointType;
useAimCone = ammo.AmmoDef.Fragment.TimedSpawns.DirectAimCone > 0 && pointType == PointTypes.Direct;
directAimCone = MathHelper.ToRadians(Math.Max(ammo.AmmoDef.Fragment.TimedSpawns.DirectAimCone, 1));
proximitySqr = proximity * proximity;
}

private void ComputeApproaches(WeaponSystem.AmmoType ammo, WeaponDefinition wDef, out int approachesCount, out ApproachConstants[] approaches, out Stack<ApproachInfo> approachInfoPool, out bool hasApproaches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ public void Init(Weapon w)
{
if (Session.I.IsServer)
CurrentSeed = int.MaxValue - w.UniquePartId;
else
else
Session.I.WeaponLookUp[w.PartState.Id] = w;

TurretRandom = new XorShiftRandomStruct((ulong)CurrentSeed);
AcquireRandom = new XorShiftRandomStruct((ulong)CurrentSeed);
AcquireRandom.NextBoolean();
}

public void Sync(WeaponRandomGenerator syncFrom)
Expand Down
Loading

0 comments on commit 3ada976

Please sign in to comment.