public void ConnectToTransmitter(CompPipe transmitter, bool reconnectingAfterLoading = false)
        {
            if (this.connectParent != null && (!reconnectingAfterLoading || this.connectParent != transmitter))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to connect ",
                    this,
                    " to transmitter ",
                    transmitter,
                    " but it's already connected to ",
                    this.connectParent,
                    "."
                }), false);
                return;
            }
            this.connectParent = transmitter;
            if (this.connectParent.connectChildren == null)
            {
                this.connectParent.connectChildren = new List <CompPipe>();
            }
            transmitter.connectChildren.Add(this);
            GasPipeNet pipeNet = this.GasPipeNet;

            if (pipeNet != null)
            {
                pipeNet.RegisterConnector(this);
            }
        }
 public DelayedAction(DelayedActionType type, CompPipe compPipe)
 {
     this.type     = type;
     this.compPipe = compPipe;
     this.position = compPipe.parent.Position;
     this.rotation = compPipe.parent.Rotation;
 }
Esempio n. 3
0
        private static IEnumerable <CompPipe> PotentialConnectorsForTransmitter(CompPipe b)
        {
            if (!b.parent.Spawned)
            {
                Log.Warning("Can't check potential connectors for " + b + " because it's unspawned.", false);
                yield break;
            }
            CellRect rect = b.parent.OccupiedRect().ExpandedBy(6).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);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i].def.ConnectToPower)
                        {
                            yield return(((Building)thingList[i]).GetComp <CompPipe>());
                        }
                    }
                }
            }
            yield break;
        }
Esempio n. 4
0
        public static CompPipe BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <GasPipeNet> disallowedNets = null)
        {
            CellRect cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(1).ClipInsideMap(map);

            cellRect.ClipInsideMap(map);
            float    num    = 999999f;
            CompPipe 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)
                    {
                        CompPipe pipeComp = transmitter.GetComp <CompPipe>();
                        if (pipeComp != null && pipeComp.TransmitsGasNow && (transmitter.def.building == null || transmitter.def.building.allowWireConnection))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(pipeComp.transNet))
                            {
                                float num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num    = num2;
                                    result = pipeComp;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
 public static IEnumerable <Building> GetExplodableGasConduits(Map map)
 {
     GasExplosionUtility.tmpPowerNetHasActivePowerSource.Clear();
     try
     {
         List <Thing> conduits = map.listerThings.ThingsOfDef(ThingDef.Named("VPE_GasPipe"));
         int          num;
         for (int i = 0; i < conduits.Count; i = num + 1)
         {
             Building building = (Building)conduits[i];
             CompPipe pipeComp = building.GetComp <CompPipe>();
             if (pipeComp != null)
             {
                 bool hasActivePowerSource;
                 if (!GasExplosionUtility.tmpPowerNetHasActivePowerSource.TryGetValue(pipeComp.GasPipeNet, out hasActivePowerSource))
                 {
                     hasActivePowerSource = pipeComp.GasPipeNet.HasActivePowerSource;
                     GasExplosionUtility.tmpPowerNetHasActivePowerSource.Add(pipeComp.GasPipeNet, hasActivePowerSource);
                 }
                 if (hasActivePowerSource)
                 {
                     yield return(building);
                 }
             }
             num = i;
         }
         conduits = null;
     }
     finally
     {
         GasExplosionUtility.tmpPowerNetHasActivePowerSource.Clear();
     }
     yield break;
     yield break;
 }
 public virtual void ResetPowerVars()
 {
     this.transNet        = null;
     this.connectParent   = null;
     this.connectChildren = null;
     CompPipe.recentlyConnectedNets.Clear();
     CompPipe.lastManualReconnector = null;
 }
 public virtual void LostConnectParent()
 {
     this.connectParent = null;
     if (this.parent.Spawned)
     {
         this.parent.Map.GetComponent <PipeMapComponent>().Notify_ConnectorWantsConnect(this);
     }
 }
 public void Notify_ConnectorWantsConnect(CompPipe wantingCon)
 {
     if (Scribe.mode == LoadSaveMode.Inactive && !this.HasRegisterConnectorDuplicate(wantingCon))
     {
         this.delayedActions.Add(new DelayedAction(DelayedActionType.RegisterConnector, wantingCon));
     }
     this.NotifyDrawersForWireUpdate(wantingCon.parent.Position);
 }
 public void Notfiy_TransmitterTransmitsPowerNowChanged(CompPipe transmitter)
 {
     if (!transmitter.parent.Spawned)
     {
         return;
     }
     this.delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, transmitter));
     this.delayedActions.Add(new DelayedAction(DelayedActionType.RegisterTransmitter, transmitter));
     this.NotifyDrawersForWireUpdate(transmitter.parent.Position);
 }
Esempio n. 10
0
 public void RegisterConnector(CompPipe b)
 {
     if (this.connectors.Contains(b))
     {
         Log.Error("PowerNet registered connector it already had: " + b, false);
         return;
     }
     this.connectors.Add(b);
     this.RegisterAllComponentsOf(b.parent);
 }
Esempio n. 11
0
        private bool IsActivePowerSource(CompPipe cp)
        {
            CompPipeTank compPowerBattery = cp as CompPipeTank;

            if (compPowerBattery != null && compPowerBattery.StoredEnergy > 0f)
            {
                return(true);
            }
            CompPipeTrader compPowerTrader = cp as CompPipeTrader;

            return(compPowerTrader != null && compPowerTrader.PowerOutput > 0f);
        }
Esempio n. 12
0
 public static void ConnectAllConnectorsToTransmitter(CompPipe newTransmitter)
 {
     try
     {
         if (newTransmitter != null)
         {
             foreach (CompPipe compPipe in PipeConnectionMaker.PotentialConnectorsForTransmitter(newTransmitter))
             {
                 if (compPipe.connectParent == null)
                 {
                     compPipe.ConnectToTransmitter(newTransmitter, false);
                 }
             }
         }
     }
     catch { }
 }
Esempio n. 13
0
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompPipe deadPc, Map map)
 {
     if (deadPc.connectChildren == null)
     {
         return;
     }
     for (int i = 0; i < deadPc.connectChildren.Count; i++)
     {
         CompPipe compPipe = deadPc.connectChildren[i];
         compPipe.connectParent = null;
         CompPipeTrader compPipeTrader = compPipe as CompPipeTrader;
         if (compPipeTrader != null)
         {
             compPipeTrader.PowerOn = false;
         }
         map.GetComponent <PipeMapComponent>().Notify_ConnectorWantsConnect(compPipe);
     }
 }
 private bool HasRegisterConnectorDuplicate(CompPipe compPipe)
 {
     for (int i = this.delayedActions.Count - 1; i >= 0; i--)
     {
         if (this.delayedActions[i].compPipe == compPipe)
         {
             if (this.delayedActions[i].type == DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (this.delayedActions[i].type == DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 15
0
 public static void DisconnectFromPowerNet(CompPipe pc)
 {
     if (pc.connectParent == null)
     {
         return;
     }
     if (pc.GasPipeNet != null)
     {
         pc.GasPipeNet.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;
 }
Esempio n. 16
0
        public static void TryConnectToAnyPowerNet(CompPipe pc, List <GasPipeNet> disallowedNets = null)
        {
            if (pc.connectParent != null)
            {
                return;
            }
            if (!pc.parent.Spawned)
            {
                return;
            }
            CompPipe compPipe = BestTransmitterForConnector(pc.parent.Position, pc.parent.Map, disallowedNets);

            if (compPipe != null)
            {
                pc.ConnectToTransmitter(compPipe, false);
            }
            else
            {
                pc.connectParent = null;
            }
        }
        public override void PostExposeData()
        {
            Thing thing = null;

            if ((this.parent.def.defName != "VPE_HelixienGenerator") && (this.parent.def.defName != "VPE_IndustrialHelixienGenerator"))
            {
                if (Scribe.mode == LoadSaveMode.Saving && this.connectParent != null)
                {
                    thing = this.connectParent.parent;
                }
                Scribe_References.Look <Thing>(ref thing, "parentThing", false);
                if (thing != null)
                {
                    this.connectParent = ((ThingWithComps)thing).GetComp <CompPipe>();
                }
                if (Scribe.mode == LoadSaveMode.PostLoadInit && this.connectParent != null)
                {
                    this.ConnectToTransmitter(this.connectParent, true);
                }
            }
        }
 public void Notify_TransmitterDespawned(CompPipe oldTransmitter)
 {
     this.delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, oldTransmitter));
     this.NotifyDrawersForWireUpdate(oldTransmitter.parent.Position);
 }
Esempio n. 19
0
 private bool IsPowerSource(CompPipe cp)
 {
     return(cp is CompPipeTank || (cp is CompPipeTank && cp.Props.basePowerConsumption < 0f));
 }
 public void Notify_ConnectorDespawned(CompPipe oldCon)
 {
     this.delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterConnector, oldCon));
     this.NotifyDrawersForWireUpdate(oldCon.parent.Position);
 }
        public bool GetPipeTransmission(Building transmitter)
        {
            CompPipe pipeComp = transmitter.GetComp <CompPipe>();

            return(pipeComp != null && pipeComp.Props.transmitsGas);
        }
Esempio n. 22
0
 public void DeregisterConnector(CompPipe b)
 {
     this.connectors.Remove(b);
     this.DeregisterAllComponentsOf(b.parent);
 }