public DelayedAction(DelayedActionType type, CompSteam CompSteam)
 {
     this.type      = type;
     this.CompSteam = CompSteam;
     position       = CompSteam.parent.Position;
     rotation       = CompSteam.parent.Rotation;
 }
 public void Notify_TransmitterSpawned(CompSteam newTransmitter)
 {
     //string output = "Transmitter Spawned Called for: " + newTransmitter.parent.Label;
     //SteamUtility.PrintDebugMessage(output);
     delayedActions.Add(new DelayedAction(DelayedActionType.RegisterTransmitter, newTransmitter));
     NotifyDrawersForWireUpdate(newTransmitter.parent.Position);
 }
        private static IEnumerable <CompSteam> PotentialConnectorsForTransmitter(CompSteam b)
        {
            if (!b.parent.Spawned)
            {
                Log.Warning("Can't check potential connectors for " + b + " because it's unspawned.");
                yield break;
            }
            var rect = b.parent.OccupiedRect().ExpandedBy(ConnectMaxDist).ClipInsideMap(b.parent.Map);

            for (var z = rect.minZ; z <= rect.maxZ; z++)
            {
                for (var x = rect.minX; x <= rect.maxX; x++)
                {
                    var c         = new IntVec3(x, 0, z);
                    var thingList = b.parent.Map.thingGrid.ThingsListAt(c);
                    foreach (var t in thingList)
                    {
                        if (t?.TryGetComp <CompSteam>() is CompSteam w)
                        {
                            yield return(w);
                        }
                    }
                }
            }
            yield break;
        }
        public static CompSteam BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <SteamNet> disallowedNets = null)
        {
            var cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(ConnectMaxDist).ClipInsideMap(map);

            cellRect.ClipInsideMap(map);
            var       num    = 999999f;
            CompSteam result = null;

            for (var i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (var j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    var c           = new IntVec3(j, 0, i);
                    var transmitter = c.GetSteamTransmitter(map);
                    if (transmitter != null && !transmitter.Destroyed)
                    {
                        var steamComp = transmitter.TryGetComp <CompSteam>();
                        if (steamComp != null && steamComp.TransmitsSteamNow && (transmitter.def.building == null || transmitter.def.building.allowWireConnection))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(steamComp.transNet))
                            {
                                var num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num    = num2;
                                    result = steamComp;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        public static PressureLevel GetCurPressureLevel(CompSteam compSteam, float curFuelLevel)
        {
            var curPressureLevel = curFuelLevel * ((compSteam.TransmitsSteamNow) ? 1f : 0f);

            if (curPressureLevel <= 0.01f)
            {
                return(PressureLevel.Off);
            }
            else if (curPressureLevel <= fuelLevelNominal)
            {
                return(PressureLevel.Nominal);
            }
            else if (curPressureLevel <= fuelLevelCaution)
            {
                return(PressureLevel.Caution);
            }
            else if (curPressureLevel <= fuelLevelDanger)
            {
                return(PressureLevel.Danger);
            }
            else
            {
                return(PressureLevel.Maximum);
            }
        }
 public void ConnectToTransmitter(CompSteam transmitter, bool reconnectingAfterLoading = false)
 {
     //SteamUtility.PrintDebugMessage("ConnectToTransmitter Called");
     if (connectParent != null && (!reconnectingAfterLoading || connectParent != transmitter))
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to connect ",
             this,
             " to transmitter ",
             transmitter,
             " but it's already connected to ",
             connectParent,
             "."
         }));
         return;
     }
     connectParent = transmitter;
     if (connectParent.connectChildren == null)
     {
         connectParent.connectChildren = new List <CompSteam>();
     }
     transmitter.connectChildren.Add(this);
     //SteamUtility.PrintDebugMessage(transmitter.parent.Label);
     //foreach (var v in transmitter.connectChildren)
     //SteamUtility.PrintDebugMessage("->" + v.parent.Label);
     SteamNet?.RegisterConnector(this);
 }
 public void Notify_ConnectorWantsConnect(CompSteam wantingCon)
 {
     if (Scribe.mode == LoadSaveMode.Inactive && !HasRegisterConnectorDuplicate(wantingCon))
     {
         delayedActions.Add(new DelayedAction(DelayedActionType.RegisterConnector, wantingCon));
     }
     NotifyDrawersForWireUpdate(wantingCon.parent.Position);
 }
 public static void ConnectAllConnectorsToTransmitter(CompSteam newTransmitter)
 {
     foreach (var compSteam in PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (compSteam.connectParent == null)
         {
             compSteam.ConnectToTransmitter(newTransmitter);
         }
     }
 }
 public void Notfiy_TransmitterTransmitsPowerNowChanged(CompSteam transmitter)
 {
     if (!transmitter.parent.Spawned)
     {
         return;
     }
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, transmitter));
     delayedActions.Add(new DelayedAction(DelayedActionType.RegisterTransmitter, transmitter));
     NotifyDrawersForWireUpdate(transmitter.parent.Position);
 }
 public void RegisterConnector(CompSteam b)
 {
     //SteamUtility.PrintDebugMessage("RegisterConnector Called");
     if (this.connectors.Contains(b))
     {
         Log.Error("SteamNet registered connector it already had: " + b);
         return;
     }
     this.connectors.Add(b);
     this.RegisterAllComponentsOf(b.parent);
 }
        private bool IsActiveSteamSource(CompSteam cp)
        {
            CompSteamTank CompSteamTank = cp as CompSteamTank;

            if (CompSteamTank != null && CompSteamTank.StoredSteam > 0f)
            {
                return(true);
            }
            CompSteamTrader compSteamTrader = cp as CompSteamTrader;

            return(compSteamTrader != null && compSteamTrader.SteamOutput > 0f);
        }
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompSteam deadPc, Map map)
 {
     if (deadPc.connectChildren == null)
     {
         return;
     }
     foreach (var compSteam in deadPc.connectChildren)
     {
         compSteam.connectParent = null;
         if (compSteam is CompSteamTrader compSteamTrader)
         {
             compSteamTrader.SteamOn = false;
         }
         map.GetComponent <SteamNetManager>().Notify_ConnectorWantsConnect(compSteam);
     }
 }
 public static void DisconnectFromSteamNet(CompSteam pc)
 {
     if (pc.connectParent == null)
     {
         return;
     }
     pc.SteamNet?.DeregisterConnector(pc);
     if (pc.connectParent.connectChildren != null)
     {
         pc.connectParent.connectChildren.Remove(pc);
         if (pc.connectParent.connectChildren.Count == 0)
         {
             pc.connectParent.connectChildren = null;
         }
     }
     pc.connectParent = null;
 }
 private bool HasRegisterConnectorDuplicate(CompSteam CompSteam)
 {
     for (int i = delayedActions.Count - 1; i >= 0; i--)
     {
         if (delayedActions[i].CompSteam == CompSteam)
         {
             if (delayedActions[i].type == DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (delayedActions[i].type == DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public static void TryConnectToAnySteamNet(CompSteam pc, List <SteamNet> disallowedNets = null)
        {
            if (pc.connectParent != null)
            {
                return;
            }
            if (!pc.parent.Spawned)
            {
                return;
            }
            var compSteam = BestTransmitterForConnector(pc.parent.Position, pc.parent.Map, disallowedNets);

            if (compSteam != null)
            {
                pc.ConnectToTransmitter(compSteam);
            }
            else
            {
                pc.connectParent = null;
            }
        }
Exemple #16
0
        public static bool TransmitsSteamNow(this Building b)
        {
            CompSteam steamComp = b.TryGetComp <CompSteam>();

            return(steamComp != null && steamComp.Props.transmitsSteam);
        }
 public void Notify_ConnectorDespawned(CompSteam oldCon)
 {
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterConnector, oldCon));
     NotifyDrawersForWireUpdate(oldCon.parent.Position);
 }
 public void Notify_TransmitterDespawned(CompSteam oldTransmitter)
 {
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, oldTransmitter));
     NotifyDrawersForWireUpdate(oldTransmitter.parent.Position);
 }
 public void DeregisterConnector(CompSteam b)
 {
     this.connectors.Remove(b);
     this.DeregisterAllComponentsOf(b.parent);
 }
 private bool IsSteamSource(CompSteam cp)
 {
     return(cp is CompSteamTank || (cp is CompSteamTrader && (cp.Props.baseSteamConsumption < 0f || cp.Props.baseWaterConsumption < 0f)));
 }