//Rule: The representative of block is its cube grid, the representative of a character is himself private MyEntity GetInteractedEntityRepresentative(MyEntity controlledEntity) { if (controlledEntity is MyCubeBlock) { return(MyAntennaSystem.GetLogicalGroupRepresentative((controlledEntity as MyCubeBlock).CubeGrid)); } //assumption: it is impossible to open the character control panel when in a ship return(MySession.LocalCharacter); }
private HashSet <CubeGridInfo> GetAllCubeGridsInfo() { HashSet <CubeGridInfo> output = new HashSet <CubeGridInfo>(); HashSet <long> AddedItems = new HashSet <long>(); //First, you always add yourself AddedItems.Add(m_openInventoryInteractedEntityRepresentative.EntityId); output.Add(new CubeGridInfo() { EntityId = m_openInventoryInteractedEntityRepresentative.EntityId, Distance = 0, AppendedDistance = new StringBuilder("0"), Name = m_openInventoryInteractedEntityRepresentative.DisplayName, Status = m_openInventoryInteractedEntityRepresentative == MySession.LocalCharacter ? MyCubeGridConnectionStatus.Me : MyCubeGridConnectionStatus.PhysicallyConnected }); //then you add your owned grids foreach (var gridId in MySession.LocalHumanPlayer.Grids) { MyCubeGrid grid; if (!MyEntities.TryGetEntityById <MyCubeGrid>(gridId, out grid)) { continue; } if (!PlayerOwnsShip(grid)) { continue; } var representative = MyAntennaSystem.GetLogicalGroupRepresentative(grid); if (AddedItems.Contains(representative.EntityId)) { continue; } AddedItems.Add(representative.EntityId); float dist = GetPlayerGridDistance(representative); output.Add(new CubeGridInfo() { EntityId = representative.EntityId, Distance = dist, AppendedDistance = new StringBuilder().AppendDecimal(dist, 0), Name = representative.DisplayName, Status = GetShipStatus(representative) }); } return(output); }