Ejemplo n.º 1
0
 private static IEnumerable <CompSteam> PotentialConnectorsForTransmitter(CompSteam b)
 {
     if (!b.parent.Spawned)
     {
         Log.Warning("Can't check potential connectors for " + b + " because it's unspawned.");
     }
     else
     {
         CellRect rect = b.parent.OccupiedRect().ExpandedBy(ConnectMaxDist).ClipInsideMap(b.parent.Map);
         for (int z = rect.minZ; z <= rect.maxZ; z++)
         {
             for (int x = rect.minX; x <= rect.maxX; x++)
             {
                 IntVec3      c         = new IntVec3(x, 0, z);
                 List <Thing> thingList = b.parent.Map.thingGrid.ThingsListAt(c);
                 foreach (Thing thing in thingList)
                 {
                     if (thing.def.CompDefFor <CompSteam>() != null)
                     {
                         yield return(((Building)thing).GetComp <CompSteam>());
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void SteamSprayerTick()
 {
     if (sprayTicksLeft > 0)
     {
         sprayTicksLeft--;
         CompSteam       comp   = parent.TryGetComp <CompSteam>();
         CompSteamTrader trader = parent.TryGetComp <CompSteamTrader>();
         if (Rand.Value < 0.6f && (trader == null || trader.SteamOn) &&
             (comp != null && comp.SteamNet.CurrentStoredEnergy() >= PressureCutoff) &&
             (parent.TryGetComp <CompFlickable>() == null || FlickUtility.WantsToBeOn(parent)))
         {
             MoteMaker.ThrowSmoke(parent.TrueCenter(), parent.Map, SmokeAmount);
             MoteMaker.ThrowAirPuffUp(parent.TrueCenter(), parent.Map);
         }
         if (sprayTicksLeft <= 0)
         {
             endSprayCallback?.Invoke();
             ticksUntilSpray = Rand.RangeInclusive(MinTicksBetweenSprays, MaxTicksBetweenSprays);
         }
     }
     else
     {
         ticksUntilSpray--;
         if (ticksUntilSpray <= 0)
         {
             startSprayCallback?.Invoke();
             sprayTicksLeft = Rand.RangeInclusive(MinSprayDuration, MaxSprayDuration);
         }
     }
 }
Ejemplo n.º 3
0
 public static void ConnectAllConnectorsToTransmitter(CompSteam newTransmitter)
 {
     foreach (CompSteam current in PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (current.connectParent == null)
         {
             current.ConnectToTransmitter(newTransmitter, false);
         }
     }
 }
Ejemplo n.º 4
0
        public static void TryConnectToAnySteamNet(CompSteam pc, List <SteamPowerNet> disallowedNets = null)
        {
            if (pc.connectParent != null || !pc.parent.Spawned)
            {
                return;
            }
            CompSteam compSteam = BestTransmitterForConnector(pc.parent.Position, pc.parent.Map, disallowedNets);

            if (compSteam != null)
            {
                pc.ConnectToTransmitter(compSteam, false);
            }
            else
            {
                pc.connectParent = null;
            }
        }
Ejemplo n.º 5
0
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompSteam deadPc, Map map, SteamNetManager steamNetManager)
 {
     if (deadPc.connectChildren == null)
     {
         return;
     }
     for (int i = 0; i < deadPc.connectChildren.Count; i++)
     {
         CompSteam compSteam = deadPc.connectChildren[i];
         compSteam.connectParent = null;
         CompSteamTrader compSteamTrader = compSteam as CompSteamTrader;
         if (compSteamTrader != null)
         {
             compSteamTrader.SteamOn = false;
         }
         steamNetManager.Notify_ConnectorWantsConnect(compSteam);
     }
 }
Ejemplo n.º 6
0
 public static void DisconnectFromSteamNet(CompSteam pc)
 {
     if (pc.connectParent == null)
     {
         return;
     }
     if (pc.SteamNet != null)
     {
         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;
 }
Ejemplo n.º 7
0
        public static CompSteam BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <SteamPowerNet> disallowedNets = null)
        {
            CellRect cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(ConnectMaxDist).ClipInsideMap(map);

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

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3  c           = new IntVec3(j, 0, i);
                    Building transmitter = c.GetTransmitter(map);
                    if (transmitter != null && !transmitter.Destroyed)
                    {
                        CompSteam steamComp = transmitter.GetComp <CompSteam>();
                        if (steamComp != null && steamComp.TransmitsSteamPower &&
                            (transmitter.GetComp <CompSteam>() != null ||
                             transmitter.GetComp <CompSteam>().Props.allowPipeUnderneath))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(steamComp.SteamNet))
                            {
                                float num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num    = num2;
                                    result = steamComp;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
 public DelayedAction(DelayedActionType type, CompSteam steamPower)
 {
     this.type      = type;
     this.steamComp = steamPower;
 }