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 Jun 19, 2024
2 parents 683215c + 9c33c30 commit 5cc4980
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 42 deletions.
37 changes: 7 additions & 30 deletions Data/Scripts/CoreSystems/Ai/AiConstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,15 @@ public void RegisterSubGrid(MyCubeGrid grid)
grid.OnFatBlockAdded += FatBlockAdded;
grid.OnFatBlockRemoved += FatBlockRemoved;

//BDC Temp debugging
var tempBlockArray = grid.GetFatBlocks().ToArray();
try
foreach (var cube in grid.GetFatBlocks())
{
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;
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)
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)
{
if (!tempBlockArray.Contains(modified))
msg += $"Block {modified.DisplayName} was added \n";
}
Log.Line(msg);
MyLog.Default.WriteLine(msg);
throw ex;
if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null)
FatBlockAdded(cube);
}
SubGridsRegistered[grid] = byte.MaxValue;
}
Expand Down
14 changes: 9 additions & 5 deletions Data/Scripts/CoreSystems/Ai/AiEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,20 @@ 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);
Session.I.FutureEvents.Schedule(QueuedBlockRemoval, cube, 10);
//cube.CubeGrid.RemoveBlock(cube.SlimBlock, true);
}
}
}
}

private void QueuedBlockRemoval(object o)
{
var cube = o as MyCubeBlock;
if (cube != null)
cube.CubeGrid.RemoveBlock(cube.SlimBlock, true);
}

private void FatBlockRemoved(MyCubeBlock cube)
{
var stator = cube as IMyMotorStator;
Expand Down
12 changes: 9 additions & 3 deletions Data/Scripts/CoreSystems/EntityComp/ModelSupport/Dummies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ internal MyEntity Entity
internal Vector3D CachedPos;
internal Vector3D CachedDir;
internal Vector3D CachedUpDir;
internal bool Ejector;


private readonly string[] _path;
private readonly Dictionary<string, IMyModelDummy> _tmp1 = new Dictionary<string, IMyModelDummy>();
private readonly Dictionary<string, IMyModelDummy> _tmp2 = new Dictionary<string, IMyModelDummy>();
private readonly Part _part;
private readonly DummyInfo _info = new DummyInfo();
private MyEntity _entity;
public Dummy(MyEntity e, Part w, params string[] path)
public Dummy(MyEntity e, Part w, bool ejector, params string[] path)
{
_part = w;
Entity = e;
_path = path;
Ejector = ejector;
}

private bool _failed = true;
Expand Down Expand Up @@ -133,7 +136,10 @@ public DummyInfo Info
var offset = !wComp.Rifle.GunBase.HasIronSightsActive;
partWorldMatrix = wComp.GetHandWeaponApproximateWorldMatrix(offset);
Vector3D.Transform(ref localPos, ref partWorldMatrix, out CachedPos);
CachedDir = Vector3D.Normalize(wComp.CharacterPosComp.LogicalCrosshairPoint - CachedPos);
if (Ejector)
Vector3D.TransformNormal(ref localDir, ref partWorldMatrix, out CachedDir);
else
CachedDir = Vector3D.Normalize(wComp.CharacterPosComp.LogicalCrosshairPoint - CachedPos);
CachedUpDir = partWorldMatrix.Up;
}
else
Expand All @@ -146,7 +152,7 @@ public DummyInfo Info
if (rifle) // I lack the words to describe the level of my disgust
{
var wComp = (Weapon.WeaponComponent)_part.BaseComp;
clientRifleOffset = !wComp.Rifle.GunBase.HasIronSightsActive;
clientRifleOffset = !wComp.Rifle.GunBase.HasIronSightsActive && !Ejector;
var keenWhyPartWorldMatrix = wComp.GetHandWeaponApproximateWorldMatrix(clientRifleOffset);
CachedUpDir = keenWhyPartWorldMatrix.Up;
if (clientRifleOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ internal Weapon(MyEntity entity, WeaponSystem system, int partId, WeaponComponen
string ejectorMatch;
MyEntity ejectorPart;
if (System.HasEjector && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Ejector, System.AltEjectorName, out ejectorPart, out ejectorMatch))
Ejector = new Dummy(ejectorPart,this, System.Values.Assignments.Ejector);
Ejector = new Dummy(ejectorPart, this, true, System.Values.Assignments.Ejector);

string scopeMatch;
MyEntity scopePart;
if (System.HasScope && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Scope, System.AltScopeName, out scopePart, out scopeMatch))
Scope = new Dummy(scopePart, this, scopeMatch);
Scope = new Dummy(scopePart, this, false, scopeMatch);

comp.Platform.SetupWeaponUi(this);

Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/EntityComp/PlatformInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void CompileTurret(Weapon weapon)
var muzzleName = weaponSystem.Muzzles[i];
if (weapon.Muzzles[i] == null)
{
weapon.Dummies[i] = new Dummy(weapon.MuzzlePart.Entity, weapon, muzzleName);
weapon.Dummies[i] = new Dummy(weapon.MuzzlePart.Entity, weapon, false, muzzleName);
var muzzle = new Weapon.Muzzle(weapon, i);
weapon.Muzzles[i] = muzzle;
weapon.MuzzleIdToName.Add(i, muzzleName);
Expand Down
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Session/SessionAnimationMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ private static bool CreateParticleDummy(MyEntity cube, string emptyName, out Dum

if (dummyPart != null)
{
particleDummy = new Dummy(dummyPart, null, emptyName);
particleDummy = new Dummy(dummyPart, null, false, emptyName);
partName = nameLookup[dummyPart];
return true;
}
Expand Down

0 comments on commit 5cc4980

Please sign in to comment.