/// <summary> /// compares builder.connected to wasConnected. if any changed return true /// </summary> /// <returns></returns> private bool connectedChanged(int searchID) { if (myConnectedChanged_ID == searchID) // already searching { return(false); } nextConnectedChanged = DateTime.UtcNow + timeBetweenConnectedChanged; myConnectedChanged_ID = searchID; foreach (KeyValuePair <IMySlimBlock, wasConnected> pair in allConnectors) { MyObjectBuilder_ShipConnector builder = pair.Key.GetObjectBuilder() as MyObjectBuilder_ShipConnector; if (builder.Connected != pair.Value.connected) { return(true); } } foreach (AttachedGrids connected in attachedToMe) { if (connected.connectedChanged(searchID)) { return(true); } } return(false); }
private bool isAttached_connector(AttachedGrids partner) { foreach (KeyValuePair <IMySlimBlock, wasConnected> pair in allConnectors) { IMySlimBlock connector = pair.Key; MyObjectBuilder_ShipConnector builder_conn = connector.GetObjectBuilder() as MyObjectBuilder_ShipConnector; pair.Value.connected = builder_conn.Connected; if (!builder_conn.Connected) { continue; } long connectedEntityId = builder_conn.ConnectedEntityId; foreach (IMySlimBlock connectPartner in partner.allConnectors.Keys) { if (connectedEntityId == connectPartner.FatBlock.EntityId) { log("matched " + myGrid.DisplayName + " : " + connector.FatBlock.DefinitionDisplayNameText + " to " + partner.myGrid.DisplayName + " : " + connectPartner.FatBlock.DefinitionDisplayNameText, "isAttached_connector()", Logger.severity.TRACE); tryAddAttached(partner); return(true); } } } return(false); }
public ShipConnectorEntity(CubeGridEntity parent, MyObjectBuilder_ShipConnector definition, Object backingObject) : base(parent, definition, backingObject) { m_inventory = new InventoryEntity(definition.Inventory, InternalGetContainerInventory()); }
public ShipConnectorEntity(CubeGridEntity parent, MyObjectBuilder_ShipConnector definition) : base(parent, definition) { m_inventory = new InventoryEntity(definition.Inventory); }
private static void CheckGridConnection(IMyEntity block) { IMyCubeBlock cubeBlock = (IMyCubeBlock)block; if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase)) { MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity connectedEntity = null; if (pistonBase.TopBlockId.HasValue && MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId.Value, out connectedEntity)) { IMyEntity parent = connectedEntity.Parent; if (parent is IMyCubeGrid) { if (!m_conveyorConnected.ContainsKey(parent.EntityId)) { m_conveyorConnected.Add(parent.EntityId, new long[] { pistonBase.TopBlockId.Value, pistonBase.EntityId }); } } } } else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase)) { MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity connectedEntity = null; if (pistonBase.TopBlockId.HasValue && MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId.Value, out connectedEntity)) { IMyEntity parent = connectedEntity.Parent; if (parent is IMyCubeGrid) { if (!m_conveyorConnected.ContainsKey(parent.EntityId)) { m_conveyorConnected.Add(parent.EntityId, new long[] { pistonBase.TopBlockId.Value, pistonBase.EntityId }); } } } } else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector)) { MyObjectBuilder_ShipConnector connector = (MyObjectBuilder_ShipConnector)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity connectedEntity = null; if (connector.Connected && MyAPIGateway.Entities.TryGetEntityById(connector.ConnectedEntityId, out connectedEntity)) { if (!m_conveyorConnected.ContainsKey(connectedEntity.Parent.EntityId)) { //IMyCubeGrid grid = MyAPIGateway.Entities.GetEntityById(connectedEntity.Parent.EntityId); m_conveyorConnected.Add(connectedEntity.Parent.EntityId, new long[] { connectedEntity.EntityId, connector.EntityId }); } } } else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator)) { MyObjectBuilder_MotorAdvancedStator stator = (MyObjectBuilder_MotorAdvancedStator)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity connectedEntity = null; if (stator.RotorEntityId.HasValue && MyAPIGateway.Entities.TryGetEntityById(stator.RotorEntityId.Value, out connectedEntity)) { IMyEntity parent = connectedEntity.Parent; if (parent is IMyCubeGrid) { if (!m_conveyorConnected.ContainsKey(parent.EntityId)) { m_conveyorConnected.Add(parent.EntityId, new long[] { stator.RotorEntityId.Value, stator.EntityId }); } } } } }
private static List <IMyCubeGrid> GetConnectedGridList(HashSet <IMyEntity> checkedGrids, List <IMySlimBlock> blocks) { List <IMyCubeGrid> connectedGrids = new List <IMyCubeGrid>(); foreach (IMySlimBlock slimBlock in blocks) { try { if (slimBlock.FatBlock != null && slimBlock.FatBlock is IMyCubeBlock) { IMyCubeBlock cubeBlock = (IMyCubeBlock)slimBlock.FatBlock; // Check for Piston if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_PistonBase)) { MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity entity = null; if (MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId, out entity)) { IMyCubeGrid parent = (IMyCubeGrid)entity.Parent; if (!checkedGrids.Contains(parent)) { connectedGrids.Add(parent); } } } else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ExtendedPistonBase)) { MyObjectBuilder_PistonBase pistonBase = (MyObjectBuilder_PistonBase)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity entity = null; if (MyAPIGateway.Entities.TryGetEntityById(pistonBase.TopBlockId, out entity)) { IMyCubeGrid parent = (IMyCubeGrid)entity.Parent; if (!checkedGrids.Contains(parent)) { connectedGrids.Add(parent); } } } // Connector else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ShipConnector)) { MyObjectBuilder_ShipConnector connector = (MyObjectBuilder_ShipConnector)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity entity = null; if (MyAPIGateway.Entities.TryGetEntityById(connector.ConnectedEntityId, out entity)) //IMyEntity entity = MyAPIGateway.Entities.GetEntityById(connector.ConnectedEntityId); //if(entity != null) { IMyCubeGrid parent = (IMyCubeGrid)entity.Parent; if (!checkedGrids.Contains(parent)) { connectedGrids.Add(parent); } } } else if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MotorAdvancedStator)) { MyObjectBuilder_MotorAdvancedStator stator = (MyObjectBuilder_MotorAdvancedStator)cubeBlock.GetObjectBuilderCubeBlock(); IMyEntity connectedEntity = null; if (stator.RotorEntityId.HasValue && MyAPIGateway.Entities.TryGetEntityById(stator.RotorEntityId.Value, out connectedEntity)) { IMyCubeGrid parent = (IMyCubeGrid)connectedEntity.Parent; if (!checkedGrids.Contains(parent)) { connectedGrids.Add(parent); } } } } } catch { continue; } } return(connectedGrids); }