Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static List<IMyShipConnector> connectors = new List<IMyShipConnector>();//initially populated as usual during typical setup
- class ConnectorInfo
- {
- bool lcon = false;
- public IMyShipConnector connector = null;
- public IMyShipConnector otherConnector = null;
- public bool sortConnected = false;
- //public bool blockConnected = false;
- public bool upd()
- {
- var con = connector.Status == MyShipConnectorStatus.Connected;
- var o = connector.OtherConnector;
- if (lcon != con)
- {
- lcon = con;
- if (!con) o = null;
- otherConnector = o;
- sortConnected = false;
- if (otherConnector != null)
- {
- var n = connector.CustomName;
- var n2 = otherConnector.CustomName;
- if (n.Contains(nosort) || n.Contains(nosort2) ||
- n2.Contains(nosort) || n2.Contains(nosort2))
- {
- sortConnected = false;
- }
- else sortConnected = true;
- }
- return true;
- }
- else return false;
- }
- }
- Dictionary<IMyShipConnector, ConnectorInfo> connectorState = new Dictionary<IMyShipConnector, ConnectorInfo>();
- public bool updateConnectors()
- {
- bool evnt = false;
- foreach (var c in connectors)
- {
- ConnectorInfo v = null;
- connectorState.TryGetValue(c, out v);
- if (v == null)
- {
- v = new ConnectorInfo();
- v.connector = c;
- connectorState[c] = v;
- }
- evnt = v.upd() || evnt;
- }
- return evnt;
- }
- bool cnctE = false;
- public void connectEvent2()
- {
- try
- {
- bool evnt = updateConnectors();
- if (evnt)
- {
- log("connector change");
- List<IMyProgrammableBlock> pgms = new List<IMyProgrammableBlock>();
- GridTerminalSystem.GetBlocksOfType(pgms, b => b != Me && b.HasPlayerAccess(Me.OwnerId) && b.CustomData.StartsWith("KTZINV") && b.IsWorking);
- bool awake = true;
- if (pgms.Count > 0)
- {
- bool stati = Me.CubeGrid.IsStatic;
- foreach (var c in pgms)
- {
- if (c.CubeGrid.IsStatic && !stati)
- {
- awake = false;
- break;
- }
- }
- if (awake)
- {
- foreach (var c in pgms)
- {
- if (c.EntityId < Me.EntityId && (!stati || c.CubeGrid.IsStatic))
- {
- awake = false;
- break;
- }
- }
- }
- }
- SLEEPING = !awake;
- if (SLEEPING)
- {
- gInv.lastStatus = "Sleeping while a connected KTZInv runs.";
- if (statusLog != null) statusLog.WriteText(gInv.lastStatus);
- return;
- }
- recalcInvBlocks();
- }
- }
- catch (Exception e)//because torch or something i forget
- {
- if (!cnctE)
- {
- cnctE = true;
- log("Exception: " + e.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement