Skip to content

Commit

Permalink
Merge pull request Ash-LikeSnow#106 from BDCarrillo/master
Browse files Browse the repository at this point in the history
Negative Entity ID Nightmare
  • Loading branch information
BDCarrillo authored Nov 4, 2024
2 parents 958a1db + 19e342d commit 4ec7b4a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions Data/Scripts/CoreSystems/Ai/AiConstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ public bool ChangeDetected(Ai ai)
var forceUpdate = LastUpdateTick == 0 || Session.I.Tick - LastUpdateTick > 600;
if (forceUpdate || fd.Target != OldTarget || fd.Locked != OldLocked || fd.HasFocus != OldHasFocus || Math.Abs(fd.DistToNearestFocusSqr - OldDistToNearestFocusSqr) > 0)
{
if (fd.Target > 0)
if (fd.Target != 0)
PrevTarget = fd.Target;

OldTarget = fd.Target;
Expand Down Expand Up @@ -1031,7 +1031,7 @@ internal void ServerReleaseActive(Ai ai)
{
var fd = ai.Construct.Data.Repo.FocusData;

fd.Target = -1;
fd.Target = 0;
fd.Locked = LockModes.None;

ServerIsFocused(ai);
Expand All @@ -1052,12 +1052,12 @@ internal bool ServerIsFocused(Ai ai)
{
var fd = ai.Construct.Data.Repo.FocusData;

if (fd.Target > 0 && MyEntities.GetEntityById(fd.Target) != null) {
if (fd.Target != 0 && MyEntities.GetEntityById(fd.Target) != null) {
fd.HasFocus = true;
return true;
}

fd.Target = -1;
fd.Target = 0;
fd.Locked = LockModes.None;
fd.HasFocus = false;

Expand All @@ -1071,14 +1071,14 @@ internal bool ClientIsFocused(Ai ai)
if (Session.I.IsServer)
return ServerIsFocused(ai);

return fd.Target > 0 && MyEntities.GetEntityById(fd.Target) != null;
return fd.Target != 0 && MyEntities.GetEntityById(fd.Target) != null;
}

internal bool GetPriorityTarget(Ai ai, out MyEntity target)
{
var fd = ai.Construct.Data.Repo.FocusData;

if (fd.Target > 0 && MyEntities.TryGetEntityById(fd.Target, out target, true))
if (fd.Target != 0 && MyEntities.TryGetEntityById(fd.Target, out target, true))
return true;

if (MyEntities.TryGetEntityById(fd.Target, out target, true))
Expand Down
4 changes: 2 additions & 2 deletions Data/Scripts/CoreSystems/Ai/AiTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ internal static bool ReacquireTarget(Projectile p)
TargetInfo alphaInfo = null;
int offset = 0;
MyEntity fTarget;
if (!aConst.OverrideTarget && ai.Construct.Data.Repo.FocusData.Target > 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target, out fTarget) && ai.Targets.TryGetValue(fTarget, out alphaInfo))
if (!aConst.OverrideTarget && ai.Construct.Data.Repo.FocusData.Target != 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target, out fTarget) && ai.Targets.TryGetValue(fTarget, out alphaInfo))
offset++;

if (aConst.FocusOnly && offset <= 0)
Expand Down Expand Up @@ -1060,7 +1060,7 @@ private static bool FindRandomBlock(Weapon w, Target target, TargetInfo info, Co
{
TargetInfo priorityInfo;
MyEntity fTarget;
if (ai.Construct.Data.Repo.FocusData.Target > 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target, out fTarget) && ai.Targets.TryGetValue(fTarget, out priorityInfo) && priorityInfo.Target?.GetTopMostParent() == topEnt)
if (ai.Construct.Data.Repo.FocusData.Target != 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target, out fTarget) && ai.Targets.TryGetValue(fTarget, out priorityInfo) && priorityInfo.Target?.GetTopMostParent() == topEnt)
{
isPriroity = true;
lastBlocks = totalBlocks < 250 ? totalBlocks : 250;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ public void Sync(Weapon.WeaponComponent weaponComponent, ProtoWeaponCompTasks sy

public void Update(Weapon.WeaponComponent weaponComponent)
{
if (EnemyId <= 0 || !MyEntities.TryGetEntityById(EnemyId, out Enemy))
if (EnemyId != 0 || !MyEntities.TryGetEntityById(EnemyId, out Enemy))
{
Enemy = null;
EnemyId = 0;
}

if (FriendId <= 0 || !MyEntities.TryGetEntityById(FriendId, out Friend))
if (FriendId != 0 || !MyEntities.TryGetEntityById(FriendId, out Friend))
{
Friend = null;
FriendId = 0;
Expand All @@ -461,7 +461,7 @@ public void Update(Weapon.WeaponComponent weaponComponent)
public bool GetFriend(Session s, out MyEntity friend, out Ai ai)
{
friend = Friend;
var valid = FriendId > 0 && friend != null && !friend.MarkedForClose;
var valid = FriendId != 0 && friend != null && !friend.MarkedForClose;
if (valid && s.EntityAIs.TryGetValue(friend, out ai))
{
return true;
Expand All @@ -474,7 +474,7 @@ public bool GetFriend(Session s, out MyEntity friend, out Ai ai)
public bool GetEnemy(Session s, out MyEntity enemy, out Ai ai)
{
enemy = Enemy;
var valid = EnemyId > 0 && enemy != null && !enemy.MarkedForClose;
var valid = EnemyId != 0 && enemy != null && !enemy.MarkedForClose;
if (valid && s.EntityAIs.TryGetValue(enemy, out ai))
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Projectiles/Projectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ internal void RunSmart() // this is grossly inlined thanks to mod profiler... th
validEntity = !targetEnt.MarkedForClose;

var targetChange = validEntity && aConst.FocusOnly && Info.Target.TopEntityId != ai.Construct.Data.Repo.FocusData.Target;
if (targetChange && (aConst.FocusEviction || ai.Construct.Data.Repo.FocusData.Target > 0))
if (targetChange && (aConst.FocusEviction || ai.Construct.Data.Repo.FocusData.Target != 0))
validEntity = IsFocusTarget(targetEnt);
}

Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Session/SessionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private void AiLoop()
rootConstruct.CheckEmptyWeapons();
}

construct.HadFocus = rootConstruct.Data.Repo.FocusData.Target > 0 && MyEntities.TryGetEntityById(rootConstruct.Data.Repo.FocusData.Target, out rootConstruct.LastFocusEntity);
construct.HadFocus = rootConstruct.Data.Repo.FocusData.Target != 0 && MyEntities.TryGetEntityById(rootConstruct.Data.Repo.FocusData.Target, out rootConstruct.LastFocusEntity);
var constructResetTick = rootConstruct.TargetResetTick == Tick;
///
/// Upgrade update section
Expand Down
6 changes: 3 additions & 3 deletions Data/Scripts/CoreSystems/Ui/Targeting/TargetUiDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private void DrawTarget()
var detailedHud = !s.Settings.ClientConfig.MinimalHud && (s.Settings.ClientConfig.AdvancedMode || s.MinimalHudOverride);
var element = 0;

if (focus.Target <= 0) return;
if (focus.Target == 0) return;
var lockMode = focus.Locked;

var targetState = ai.TargetState;
Expand Down Expand Up @@ -515,7 +515,7 @@ internal void SetHit(ProInfo info)

var focus = Session.I.TrackingAi.Construct.Data.Repo.FocusData;
MyEntity target;
if (focus.Target > 0 && MyEntities.TryGetEntityById(focus.Target, out target) && CheckBlockWeaponEntityHit(target, info))
if (focus.Target != 0 && MyEntities.TryGetEntityById(focus.Target, out target) && CheckBlockWeaponEntityHit(target, info))
return;

if (LastSelectedEntity != null)
Expand Down Expand Up @@ -871,7 +871,7 @@ internal bool GetTargetState(Session s)
var targetId = ai.Construct.Data.Repo.FocusData.Target;
MyTuple<float, TargetControl, MyRelationsBetweenPlayerAndBlock> targetInfo;
MyEntity target;
if (targetId <= 0 || !MyEntities.TryGetEntityById(targetId, out target) || !_masterTargets.TryGetValue(target, out targetInfo))
if (targetId == 0 || !MyEntities.TryGetEntityById(targetId, out target) || !_masterTargets.TryGetValue(target, out targetInfo))
return false;

if (!s.Tick20) return true;
Expand Down

0 comments on commit 4ec7b4a

Please sign in to comment.