public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = null) { if (entity == null) { return(new MyDetectedEntityInfo()); } MatrixD orientation = MatrixD.Zero; Vector3 velocity = Vector3D.Zero; int timeStamp = MySandboxGame.TotalGamePlayTimeInMilliseconds; MyDetectedEntityType type; BoundingBoxD boundingBox = entity.PositionComp.WorldAABB; MyRelationsBetweenPlayerAndBlock relationship; string name; if (entity.Physics != null) { orientation = entity.Physics.GetWorldMatrix().GetOrientation(); velocity = entity.Physics.LinearVelocity; } //using GetTopMostParent in case we are looking at a MyCubeBlock; we want the grid the block is on var grid = entity.GetTopMostParent() as MyCubeGrid; if (grid != null) { if (grid.GridSizeEnum == MyCubeSize.Small) { type = MyDetectedEntityType.SmallGrid; } else { type = MyDetectedEntityType.LargeGrid; } if (grid.BigOwners.Count == 0) { relationship = MyRelationsBetweenPlayerAndBlock.NoOwnership; } else { relationship = MyIDModule.GetRelation(sensorOwner, grid.BigOwners[0], MyOwnershipShareModeEnum.Faction); } if (relationship == MyRelationsBetweenPlayerAndBlock.Owner || relationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { name = grid.DisplayName; } else { if (grid.GridSizeEnum == MyCubeSize.Small) { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid); } else { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid); } } return(new MyDetectedEntityInfo(grid.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var character = entity as MyCharacter; if (character != null) { if (character.IsPlayer) { type = MyDetectedEntityType.CharacterHuman; } else { type = MyDetectedEntityType.CharacterOther; } relationship = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction); if (relationship == MyRelationsBetweenPlayerAndBlock.Owner || relationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { name = character.DisplayNameText; } else { if (character.IsPlayer) { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman); } else { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther); } } BoundingBoxD bound = character.Model.BoundingBox.Transform(character.WorldMatrix); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, bound, timeStamp)); } relationship = MyRelationsBetweenPlayerAndBlock.Neutral; var floating = entity as MyFloatingObject; if (floating != null) { type = MyDetectedEntityType.FloatingObject; name = floating.Item.Content.SubtypeName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var backpack = entity as MyInventoryBagEntity; if (backpack != null) { type = MyDetectedEntityType.FloatingObject; name = backpack.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var planet = entity as MyPlanet; if (planet != null) { type = MyDetectedEntityType.Planet; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); //shrink the planet's bounding box to only encompass terrain boundingBox = BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MaximumRadius)); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var voxelPhysics = entity as MyVoxelPhysics; if (voxelPhysics != null) { type = MyDetectedEntityType.Planet; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); //shrink the planet's bounding box to only encompass terrain boundingBox = BoundingBoxD.CreateFromSphere(new BoundingSphereD(voxelPhysics.Parent.PositionComp.GetPosition(), voxelPhysics.Parent.MaximumRadius)); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var voxel = entity as MyVoxelMap; if (voxel != null) { type = MyDetectedEntityType.Asteroid; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var meteor = entity as MyMeteor; if (meteor != null) { type = MyDetectedEntityType.Meteor; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var missile = entity as MyMissile; if (missile != null) { type = MyDetectedEntityType.Missile; name = entity.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } //error case return(new MyDetectedEntityInfo(0, String.Empty, MyDetectedEntityType.Unknown, null, new MatrixD(), new Vector3(), MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), MySandboxGame.TotalGamePlayTimeInMilliseconds)); }
public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = new Vector3D?()) { MyDetectedEntityType type; MyRelationsBetweenPlayerAndBlock neutral; string displayName; if (entity == null) { return(new MyDetectedEntityInfo()); } MatrixD zero = MatrixD.Zero; Vector3 velocity = (Vector3)Vector3D.Zero; int totalGamePlayTimeInMilliseconds = MySandboxGame.TotalGamePlayTimeInMilliseconds; BoundingBoxD worldAABB = entity.PositionComp.WorldAABB; if (entity.Physics != null) { zero = entity.Physics.GetWorldMatrix().GetOrientation(); velocity = entity.Physics.LinearVelocity; } MyCubeGrid topMostParent = entity.GetTopMostParent(null) as MyCubeGrid; if (topMostParent != null) { type = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyDetectedEntityType.LargeGrid : MyDetectedEntityType.SmallGrid; neutral = (topMostParent.BigOwners.Count != 0) ? MyIDModule.GetRelation(sensorOwner, topMostParent.BigOwners[0], MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare) : MyRelationsBetweenPlayerAndBlock.NoOwnership; if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare)) { displayName = topMostParent.DisplayName; } else { displayName = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid) : MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid); } zero = topMostParent.WorldMatrix.GetOrientation(); return(new MyDetectedEntityInfo(topMostParent.EntityId, displayName, type, hitPosition, zero, topMostParent.Physics.LinearVelocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyCharacter character = entity as MyCharacter; if (character != null) { type = !character.IsPlayer ? MyDetectedEntityType.CharacterOther : MyDetectedEntityType.CharacterHuman; neutral = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare); if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare)) { displayName = character.DisplayNameText; } else { displayName = !character.IsPlayer ? MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther) : MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman); } return(new MyDetectedEntityInfo(entity.EntityId, displayName, type, hitPosition, zero, velocity, neutral, character.Model.BoundingBox.Transform(character.WorldMatrix), (long)totalGamePlayTimeInMilliseconds)); } neutral = MyRelationsBetweenPlayerAndBlock.Neutral; MyFloatingObject obj2 = entity as MyFloatingObject; if (obj2 != null) { displayName = obj2.Item.Content.SubtypeName; return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity; if (entity2 != null) { displayName = entity2.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyPlanet planet = entity as MyPlanet; if (planet != null) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), (double)planet.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds)); } MyVoxelPhysics physics = entity as MyVoxelPhysics; if (physics != null) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(physics.Parent.PositionComp.GetPosition(), (double)physics.Parent.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyVoxelMap) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Asteroid, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyMeteor) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Meteor, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyMissile) { return(new MyDetectedEntityInfo(entity.EntityId, entity.DisplayName, MyDetectedEntityType.Missile, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } Vector3D?nullable = null; MatrixD orientation = new MatrixD(); Vector3 vector2 = new Vector3(); return(new MyDetectedEntityInfo(0L, string.Empty, MyDetectedEntityType.Unknown, nullable, orientation, vector2, MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), (long)MySandboxGame.TotalGamePlayTimeInMilliseconds)); }