public DetectInfo(Session session, MyEntity parent, Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo, int partCount, int fatCount) { Parent = parent; EntInfo = entInfo; PartCount = partCount; FatCount = fatCount; var armed = false; var isGrid = false; var largeGrid = false; var grid = parent as MyCubeGrid; if (grid != null) { isGrid = true; largeGrid = grid.GridSizeEnum == MyCubeSize.Large; ConcurrentDictionary <BlockTypes, ConcurrentCachingList <MyCubeBlock> > blockTypeMap; if (session.GridToBlockTypeMap.TryGetValue((MyCubeGrid)Parent, out blockTypeMap)) { ConcurrentCachingList <MyCubeBlock> weaponBlocks; if (blockTypeMap.TryGetValue(BlockTypes.Offense, out weaponBlocks) && weaponBlocks.Count > 0) { armed = true; } } } else if (parent is MyMeteor || parent is IMyCharacter) { armed = true; } Armed = armed; IsGrid = isGrid; LargeGrid = largeGrid; }
public static Color GetRelationshipColor(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo Info) { Color retval = Color.Black; switch (Info.Relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: retval = Color.LightBlue; break; case MyRelationsBetweenPlayerAndBlock.Neutral: retval = Color.White; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: retval = Color.DarkGreen; break; case MyRelationsBetweenPlayerAndBlock.Enemies: retval = Color.Red; break; case MyRelationsBetweenPlayerAndBlock.NoOwnership: retval = Color.Gray; break; } return(retval); }
public static IMyCubeGrid GetGrid(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) { if (!entityInfo.IsGrid()) { return(null); } return(MyAPIGateway.Entities.GetEntityById(entityInfo.EntityId) as IMyCubeGrid); }
internal void Init(ref DetectInfo detectInfo, MyCubeGrid myGrid, GridAi myAi, GridAi targetAi) { EntInfo = detectInfo.EntInfo; Target = detectInfo.Parent; PartCount = detectInfo.PartCount; FatCount = detectInfo.FatCount; IsStatic = Target.Physics.IsStatic; IsGrid = detectInfo.IsGrid; LargeGrid = detectInfo.LargeGrid; MyGrid = myGrid; MyAi = myAi; TargetAi = targetAi; Velocity = Target.Physics.LinearVelocity; VelLenSqr = Velocity.LengthSquared(); var targetSphere = Target.PositionComp.WorldVolume; TargetPos = targetSphere.Center; TargetRadius = targetSphere.Radius; var myCenter = myAi.GridVolume.Center; if (!MyUtils.IsZero(Velocity, 1E-02F)) { var targetMag = myCenter - TargetPos; Approaching = MathFuncs.IsDotProductWithinTolerance(ref Velocity, ref targetMag, myAi.Session.ApproachDegrees); } else { Approaching = false; TargetHeading = Vector3D.Zero; } if (targetAi != null) { OffenseRating = targetAi.Construct.OptimalDps / myAi.Construct.OptimalDps; } else if (detectInfo.Armed) { OffenseRating = 0.0001f; } else { OffenseRating = 0; } var myRadius = myAi.MyGrid.PositionComp.LocalVolume.Radius; var sphereDistance = MyUtils.GetSmallestDistanceToSphere(ref myCenter, ref targetSphere); if (sphereDistance <= myRadius) { sphereDistance = 0; } else { sphereDistance -= myRadius; } DistSqr = sphereDistance * sphereDistance; }
public int Compare(Sandbox.ModAPI.Ingame.MyDetectedEntityInfo x, Sandbox.ModAPI.Ingame.MyDetectedEntityInfo y) { double distanceX = Vector3D.DistanceSquared(Position, x.Position); double distanceY = Vector3D.DistanceSquared(Position, y.Position); if (distanceX < distanceY) { return(-1); } return(distanceX > distanceY ? 1 : 0); }
internal void Init(ref DetectInfo detectInfo, MyCubeGrid myGrid, GridAi myAi, GridAi targetAi) { EntInfo = detectInfo.EntInfo; Target = detectInfo.Parent; PartCount = detectInfo.PartCount; FatCount = detectInfo.FatCount; IsGrid = detectInfo.IsGrid; LargeGrid = detectInfo.LargeGrid; MyGrid = myGrid; MyAi = myAi; TargetAi = targetAi; Velocity = Target.Physics.LinearVelocity; VelLenSqr = Velocity.LengthSquared(); var targetSphere = Target.PositionComp.WorldVolume; TargetPos = targetSphere.Center; TargetRadius = targetSphere.Radius; if (!MyUtils.IsZero(Velocity, 1E-02F)) { TargetDir = Vector3D.Normalize(Velocity); var refDir = Vector3D.Normalize(myAi.GridVolume.Center - TargetPos); Approaching = MathFuncs.IsDotProductWithinTolerance(ref TargetDir, ref refDir, myAi.Session.ApproachDegrees); } else { TargetDir = Vector3D.Zero; Approaching = false; } if (targetAi != null) { OffenseRating = targetAi.Construct.OptimalDps / myAi.Construct.OptimalDps; } else if (detectInfo.Armed) { OffenseRating = 0.0001f; } else { OffenseRating = 0; } var targetDist = Vector3D.Distance(myAi.GridVolume.Center, TargetPos) - TargetRadius; targetDist -= myAi.GridVolume.Radius; if (targetDist < 0) { targetDist = 0; } DistSqr = targetDist * targetDist; }
public int Compare(Sandbox.ModAPI.Ingame.MyDetectedEntityInfo x, Sandbox.ModAPI.Ingame.MyDetectedEntityInfo y) { var DistanceX = Vector3D.DistanceSquared(Position, x.Position); var DistanceY = Vector3D.DistanceSquared(Position, y.Position); if (DistanceX < DistanceY) { return(-1); } if (DistanceX > DistanceY) { return(1); } return(0); }
public static bool IsAllied(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo Info) { return(Info.Relationship == MyRelationsBetweenPlayerAndBlock.Owner || Info.Relationship == MyRelationsBetweenPlayerAndBlock.FactionShare); }
public static bool IsGrid(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo Info) { return(Info.Type == Sandbox.ModAPI.Ingame.MyDetectedEntityType.SmallGrid || Info.Type == Sandbox.ModAPI.Ingame.MyDetectedEntityType.LargeGrid); }
/// <summary> /// Retrieves entity mass, in tonnes. /// </summary> public static float GetMassT(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) { return(entityInfo.GetEntity().Physics.Mass / 1000); }
public static IMyEntity GetEntity(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) { return(MyAPIGateway.Entities.GetEntityById(entityInfo.EntityId)); }
//public static bool IsValid(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) //{ // return !entityInfo.IsEmpty(); //} public static bool IsHostile(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) { return(entityInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies); }
public static bool IsValid(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo EntityInfo) { return(!EntityInfo.IsEmpty()); }
internal bool CreateEntInfo(MyEntity entity, long gridOwner, out Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo) { if (entity == null) { entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(); return(false); } var topMostParent = entity.GetTopMostParent() as MyCubeGrid; if (topMostParent != null) { var type = topMostParent.GridSizeEnum != MyCubeSize.Small ? Sandbox.ModAPI.Ingame.MyDetectedEntityType.LargeGrid : Sandbox.ModAPI.Ingame.MyDetectedEntityType.SmallGrid; var hasOwner = topMostParent.BigOwners.Count != 0; MyRelationsBetweenPlayerAndBlock relationship; if (hasOwner) { var topOwner = topMostParent.BigOwners[0]; relationship = MyIDModule.GetRelationPlayerBlock(gridOwner, topOwner, MyOwnershipShareModeEnum.Faction); if (relationship == MyRelationsBetweenPlayerAndBlock.Neutral) { var topFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(topOwner); if (topFaction != null) { var aiFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(gridOwner); if (aiFaction != null && MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(aiFaction.FactionId, topFaction.FactionId) < -500) { relationship = MyRelationsBetweenPlayerAndBlock.Enemies; } } } } else { relationship = MyRelationsBetweenPlayerAndBlock.Owner; } entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(topMostParent.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship, new BoundingBoxD(), Session.Tick); return(true); } var myCharacter = entity as IMyCharacter; if (myCharacter != null) { var controllingId = myCharacter.ControllerInfo?.ControllingIdentityId; var playerId = controllingId ?? 0; var type = !myCharacter.IsPlayer ? Sandbox.ModAPI.Ingame.MyDetectedEntityType.CharacterOther : Sandbox.ModAPI.Ingame.MyDetectedEntityType.CharacterHuman; var relationPlayerBlock = MyIDModule.GetRelationPlayerBlock(gridOwner, playerId, MyOwnershipShareModeEnum.Faction); entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationPlayerBlock, new BoundingBoxD(), Session.Tick); return(!myCharacter.IsDead); } const MyRelationsBetweenPlayerAndBlock relationship1 = MyRelationsBetweenPlayerAndBlock.Neutral; var myPlanet = entity as MyPlanet; if (myPlanet != null) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Planet; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship1, new BoundingBoxD(), Session.Tick); return(true); } if (entity is MyVoxelMap) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Asteroid; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship1, new BoundingBoxD(), Session.Tick); return(true); } if (entity is MyMeteor) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Meteor; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, MyRelationsBetweenPlayerAndBlock.Enemies, new BoundingBoxD(), Session.Tick); return(true); } entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(); return(false); }
internal bool CreateEntInfo(MyEntity entity, long gridOwner, out Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo) { try { MyRelationsBetweenPlayerAndBlock relationship = MyRelationsBetweenPlayerAndBlock.Neutral; if (entity == null) { entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(); return(false); } var grid = entity.GetTopMostParent() as MyCubeGrid; if (grid != null) { if (!grid.DestructibleBlocks || grid.Immune || grid.GridGeneralDamageModifier <= 0) { entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(); return(false); } var bigOwners = grid.BigOwners; var topOwner = bigOwners.Count > 0 ? bigOwners[0] : long.MaxValue; relationship = topOwner != long.MaxValue ? MyIDModule.GetRelationPlayerBlock(gridOwner, topOwner, MyOwnershipShareModeEnum.Faction) : MyRelationsBetweenPlayerAndBlock.NoOwnership; var type = grid.GridSizeEnum != MyCubeSize.Small ? Sandbox.ModAPI.Ingame.MyDetectedEntityType.LargeGrid : Sandbox.ModAPI.Ingame.MyDetectedEntityType.SmallGrid; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(grid.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship, new BoundingBoxD(), Session.Tick); return(true); } var myCharacter = entity as IMyCharacter; if (myCharacter != null) { var type = !myCharacter.IsPlayer ? Sandbox.ModAPI.Ingame.MyDetectedEntityType.CharacterOther : Sandbox.ModAPI.Ingame.MyDetectedEntityType.CharacterHuman; var getComponentOwner = entity as IMyComponentOwner <MyIDModule>; long playerId; MyIDModule targetIdModule; if (getComponentOwner != null && getComponentOwner.GetComponent(out targetIdModule)) { playerId = targetIdModule.Owner; } else { var controllingId = myCharacter.ControllerInfo?.ControllingIdentityId; playerId = controllingId ?? 0; } relationship = MyIDModule.GetRelationPlayerBlock(gridOwner, playerId, MyOwnershipShareModeEnum.Faction); entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship, new BoundingBoxD(), Session.Tick); return(!myCharacter.IsDead && myCharacter.Integrity > 0); } var myPlanet = entity as MyPlanet; if (myPlanet != null) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Planet; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship, new BoundingBoxD(), Session.Tick); return(true); } if (entity is MyVoxelMap) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Asteroid; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, relationship, new BoundingBoxD(), Session.Tick); return(true); } if (entity is MyMeteor) { const Sandbox.ModAPI.Ingame.MyDetectedEntityType type = Sandbox.ModAPI.Ingame.MyDetectedEntityType.Meteor; entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(entity.EntityId, string.Empty, type, null, MatrixD.Zero, Vector3.Zero, MyRelationsBetweenPlayerAndBlock.Enemies, new BoundingBoxD(), Session.Tick); return(true); } } catch (Exception ex) { Log.Line($"Exception in CreateEntInfo: {ex}"); } entInfo = new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(); return(false); }
public static Sandbox.ModAPI.Ingame.MyDetectedEntityInfo Rename(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo Info, string Name) { return(new Sandbox.ModAPI.Ingame.MyDetectedEntityInfo(Info.EntityId, Name, Info.Type, Info.HitPosition, Info.Orientation, Info.Velocity, Info.Relationship, Info.BoundingBox, Info.TimeStamp)); }
public static bool IsNonFriendly(this Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entityInfo) { return(entityInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies || entityInfo.Relationship == MyRelationsBetweenPlayerAndBlock.Neutral); }