Beispiel #1
0
        public void ConnectToTransmitter(CompPower 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 <CompPower>();
            }
            transmitter.connectChildren.Add(this);
            PowerNet powerNet = this.PowerNet;

            if (powerNet != null)
            {
                powerNet.RegisterConnector(this);
            }
        }
        public static CompPower BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <PowerNet> disallowedNets = null)
        {
            CellRect cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(6).ClipInsideMap(map);

            cellRect.ClipInsideMap(map);
            float     num    = 999999f;
            CompPower 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)
                    {
                        CompPower powerComp = transmitter.PowerComp;
                        if (powerComp != null && powerComp.TransmitsPowerNow && (transmitter.def.building == null || transmitter.def.building.allowWireConnection))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(powerComp.transNet))
                            {
                                float num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num    = num2;
                                    result = powerComp;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
 public DelayedAction(PowerNetManager.DelayedActionType type, CompPower compPower)
 {
     this.type      = type;
     this.compPower = compPower;
     this.position  = compPower.parent.Position;
     this.rotation  = compPower.parent.Rotation;
 }
Beispiel #4
0
        private void TryManualReconnect()
        {
            if (CompPower.lastManualReconnector != this)
            {
                CompPower.recentlyConnectedNets.Clear();
                CompPower.lastManualReconnector = this;
            }
            if (this.PowerNet != null)
            {
                CompPower.recentlyConnectedNets.Add(this.PowerNet);
            }
            CompPower compPower = PowerConnectionMaker.BestTransmitterForConnector(this.parent.Position, this.parent.Map, CompPower.recentlyConnectedNets);

            if (compPower == null)
            {
                CompPower.recentlyConnectedNets.Clear();
                compPower = PowerConnectionMaker.BestTransmitterForConnector(this.parent.Position, this.parent.Map, null);
            }
            if (compPower != null)
            {
                PowerConnectionMaker.DisconnectFromPowerNet(this);
                this.ConnectToTransmitter(compPower, false);
                for (int i = 0; i < 5; i++)
                {
                    MoteMaker.ThrowMetaPuff(compPower.parent.Position.ToVector3Shifted(), compPower.parent.Map);
                }
                this.parent.Map.mapDrawer.MapMeshDirty(this.parent.Position, MapMeshFlag.PowerGrid);
                this.parent.Map.mapDrawer.MapMeshDirty(this.parent.Position, MapMeshFlag.Things);
            }
        }
        private static IEnumerable <CompPower> PotentialConnectorsForTransmitter(CompPower 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]).PowerComp);
                        }
                    }
                }
            }
            yield break;
        }
Beispiel #6
0
 public static IEnumerable <Building> GetShortCircuitablePowerConduits(Map map)
 {
     ShortCircuitUtility.tmpPowerNetHasActivePowerSource.Clear();
     try
     {
         List <Thing> conduits = map.listerThings.ThingsOfDef(ThingDefOf.PowerConduit);
         for (int i = 0; i < conduits.Count; i++)
         {
             Building  b     = (Building)conduits[i];
             CompPower power = b.PowerComp;
             if (power != null)
             {
                 bool hasActivePowerSource;
                 if (!ShortCircuitUtility.tmpPowerNetHasActivePowerSource.TryGetValue(power.PowerNet, out hasActivePowerSource))
                 {
                     hasActivePowerSource = power.PowerNet.HasActivePowerSource;
                     ShortCircuitUtility.tmpPowerNetHasActivePowerSource.Add(power.PowerNet, hasActivePowerSource);
                 }
                 if (hasActivePowerSource)
                 {
                     yield return(b);
                 }
             }
         }
     }
     finally
     {
         base.< > __Finally0();
     }
 }
Beispiel #7
0
 public DelayedAction(DelayedActionType type, CompPower compPower)
 {
     this.type      = type;
     this.compPower = compPower;
     position       = compPower.parent.Position;
     rotation       = compPower.parent.Rotation;
 }
Beispiel #8
0
 public static IEnumerable <Building> GetShortCircuitablePowerConduits(Map map)
 {
     tmpPowerNetHasActivePowerSource.Clear();
     try
     {
         List <Thing> conduits = map.listerThings.ThingsOfDef(ThingDefOf.PowerConduit);
         for (int i = 0; i < conduits.Count; i++)
         {
             Building  building  = (Building)conduits[i];
             CompPower powerComp = building.PowerComp;
             if (powerComp != null)
             {
                 if (!tmpPowerNetHasActivePowerSource.TryGetValue(powerComp.PowerNet, out bool value))
                 {
                     value = powerComp.PowerNet.HasActivePowerSource;
                     tmpPowerNetHasActivePowerSource.Add(powerComp.PowerNet, value);
                 }
                 if (value)
                 {
                     yield return(building);
                 }
             }
         }
     }
     finally
     {
         tmpPowerNetHasActivePowerSource.Clear();
     }
 }
 public virtual void LostConnectParent()
 {
     this.connectParent = null;
     if (this.parent.Spawned)
     {
         this.parent.Map.powerNetManager.Notify_ConnectorWantsConnect(this);
     }
 }
Beispiel #10
0
 public void Notify_ConnectorWantsConnect(CompPower wantingCon)
 {
     if (Scribe.mode == LoadSaveMode.Inactive && !this.HasRegisterConnectorDuplicate(wantingCon))
     {
         this.delayedActions.Add(new PowerNetManager.DelayedAction(PowerNetManager.DelayedActionType.RegisterConnector, wantingCon));
     }
     this.NotifyDrawersForWireUpdate(wantingCon.parent.Position);
 }
Beispiel #11
0
 public virtual void ResetPowerVars()
 {
     transNet        = null;
     connectParent   = null;
     connectChildren = null;
     recentlyConnectedNets.Clear();
     lastManualReconnector = null;
 }
 public virtual void ResetPowerVars()
 {
     this.transNet        = null;
     this.connectParent   = null;
     this.connectChildren = null;
     CompPower.recentlyConnectedNets.Clear();
     CompPower.lastManualReconnector = null;
 }
Beispiel #13
0
 public void Notfiy_TransmitterTransmitsPowerNowChanged(CompPower transmitter)
 {
     if (transmitter.parent.Spawned)
     {
         this.delayedActions.Add(new PowerNetManager.DelayedAction(PowerNetManager.DelayedActionType.DeregisterTransmitter, transmitter));
         this.delayedActions.Add(new PowerNetManager.DelayedAction(PowerNetManager.DelayedActionType.RegisterTransmitter, transmitter));
         this.NotifyDrawersForWireUpdate(transmitter.parent.Position);
     }
 }
 public static void ConnectAllConnectorsToTransmitter(CompPower newTransmitter)
 {
     foreach (CompPower compPower in PowerConnectionMaker.PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (compPower.connectParent == null)
         {
             compPower.ConnectToTransmitter(newTransmitter, false);
         }
     }
 }
 public static void ConnectAllConnectorsToTransmitter(CompPower newTransmitter)
 {
     foreach (CompPower item in PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (item.connectParent == null)
         {
             item.ConnectToTransmitter(newTransmitter);
         }
     }
 }
Beispiel #16
0
 public void RegisterConnector(CompPower b)
 {
     if (this.connectors.Contains(b))
     {
         Log.Error("PowerNet registered connector it already had: " + b);
         return;
     }
     this.connectors.Add(b);
     this.RegisterAllComponentsOf(b.parent);
 }
Beispiel #17
0
        private bool IsActivePowerSource(CompPower cp)
        {
            CompPowerBattery compPowerBattery = cp as CompPowerBattery;

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

            return(compPowerTrader != null && compPowerTrader.PowerOutput > 0f);
        }
Beispiel #18
0
 public void RegisterConnector(CompPower b)
 {
     if (connectors.Contains(b))
     {
         Log.Error("PowerNet registered connector it already had: " + b);
     }
     else
     {
         connectors.Add(b);
         RegisterAllComponentsOf(b.parent);
     }
 }
 private bool IsPowerSource(CompPower cp)
 {
     if (cp is CompPowerBattery)
     {
         return(true);
     }
     if (cp is CompPowerTrader && cp.Props.basePowerConsumption < 0f)
     {
         return(true);
     }
     return(false);
 }
Beispiel #20
0
 public void ConnectToTransmitter(CompPower transmitter, bool reconnectingAfterLoading = false)
 {
     if (connectParent != null && (!reconnectingAfterLoading || connectParent != transmitter))
     {
         Log.Error("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 <CompPower>();
     }
     transmitter.connectChildren.Add(this);
     PowerNet?.RegisterConnector(this);
 }
 public static void TryConnectToAnyPowerNet(CompPower pc, List <PowerNet> disallowedNets = null)
 {
     if (pc.connectParent == null && pc.parent.Spawned)
     {
         CompPower compPower = PowerConnectionMaker.BestTransmitterForConnector(pc.parent.Position, pc.parent.Map, disallowedNets);
         if (compPower != null)
         {
             pc.ConnectToTransmitter(compPower, false);
         }
         else
         {
             pc.connectParent = null;
         }
     }
 }
Beispiel #22
0
        private bool IsActivePowerSource(CompPower cp)
        {
            CompPowerBattery compPowerBattery = cp as CompPowerBattery;
            bool             result;

            if (compPowerBattery != null && compPowerBattery.StoredEnergy > 0f)
            {
                result = true;
            }
            else
            {
                CompPowerTrader compPowerTrader = cp as CompPowerTrader;
                result = (compPowerTrader != null && compPowerTrader.PowerOutput > 0f);
            }
            return(result);
        }
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompPower deadPc, Map map)
 {
     if (deadPc.connectChildren != null)
     {
         for (int i = 0; i < deadPc.connectChildren.Count; i++)
         {
             CompPower compPower = deadPc.connectChildren[i];
             compPower.connectParent = null;
             CompPowerTrader compPowerTrader = compPower as CompPowerTrader;
             if (compPowerTrader != null)
             {
                 compPowerTrader.PowerOn = false;
             }
             map.powerNetManager.Notify_ConnectorWantsConnect(compPower);
         }
     }
 }
Beispiel #24
0
 public void ConnectToTransmitter(CompPower transmitter, bool reconnectingAfterLoading = false)
 {
     if (connectParent != null && (!reconnectingAfterLoading || connectParent != transmitter))
     {
         Log.Error(string.Concat("Tried to connect ", this, " to transmitter ", transmitter, " but it's already connected to ", connectParent, "."));
     }
     else
     {
         connectParent = transmitter;
         if (connectParent.connectChildren == null)
         {
             connectParent.connectChildren = new List <CompPower>();
         }
         transmitter.connectChildren.Add(this);
         PowerNet?.RegisterConnector(this);
     }
 }
Beispiel #25
0
 private bool HasRegisterConnectorDuplicate(CompPower compPower)
 {
     for (int num = delayedActions.Count - 1; num >= 0; num--)
     {
         if (delayedActions[num].compPower == compPower)
         {
             if (delayedActions[num].type == DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (delayedActions[num].type == DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public static void TryDrawPowerGridAndAnticipatedConnection(BuildableDef def, Rot4 rotation)
        {
            ThingDef thingDef = def as ThingDef;

            if (thingDef != null && (thingDef.EverTransmitsPower || thingDef.ConnectToPower))
            {
                OverlayDrawHandler.DrawPowerGridOverlayThisFrame();
                if (thingDef.ConnectToPower)
                {
                    IntVec3   intVec    = UI.MouseCell();
                    CompPower compPower = PowerConnectionMaker.BestTransmitterForConnector(intVec, Find.CurrentMap, null);
                    if (compPower != null && !compPower.parent.Position.Fogged(compPower.parent.Map))
                    {
                        PowerNetGraphics.RenderAnticipatedWirePieceConnecting(intVec, rotation, def.Size, compPower.parent);
                    }
                }
            }
        }
Beispiel #27
0
 private bool HasRegisterConnectorDuplicate(CompPower compPower)
 {
     for (int i = this.delayedActions.Count - 1; i >= 0; i--)
     {
         if (this.delayedActions[i].compPower == compPower)
         {
             if (this.delayedActions[i].type == PowerNetManager.DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (this.delayedActions[i].type == PowerNetManager.DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #28
0
        public override void PostExposeData()
        {
            Thing refee = null;

            if (Scribe.mode == LoadSaveMode.Saving && connectParent != null)
            {
                refee = connectParent.parent;
            }
            Scribe_References.Look(ref refee, "parentThing");
            if (refee != null)
            {
                connectParent = ((ThingWithComps)refee).GetComp <CompPower>();
            }
            if (Scribe.mode == LoadSaveMode.PostLoadInit && connectParent != null)
            {
                ConnectToTransmitter(connectParent, reconnectingAfterLoading: true);
            }
        }
Beispiel #29
0
        public override void PostExposeData()
        {
            Thing thing = null;

            if (Scribe.mode == LoadSaveMode.Saving && this.connectParent != null)
            {
                thing = this.connectParent.parent;
            }
            Scribe_References.Look(ref thing, "parentThing", false);
            if (thing != null)
            {
                this.connectParent = ((ThingWithComps)thing).GetComp <CompPower>();
            }
            if (Scribe.mode == LoadSaveMode.PostLoadInit && this.connectParent != null)
            {
                this.ConnectToTransmitter(this.connectParent, true);
            }
        }
        public static IEnumerable <Building> GetShortCircuitablePowerConduits(Map map)
        {
            ShortCircuitUtility.tmpPowerNetHasActivePowerSource.Clear();
            try
            {
                List <Thing> conduits = map.listerThings.ThingsOfDef(ThingDefOf.PowerConduit);
                int          i        = 0;
                Building     b;
                while (true)
                {
                    if (i < conduits.Count)
                    {
                        b = (Building)conduits[i];
                        CompPower power = b.PowerComp;
                        if (power != null)
                        {
                            bool hasActivePowerSource;
                            if (!ShortCircuitUtility.tmpPowerNetHasActivePowerSource.TryGetValue(power.PowerNet, out hasActivePowerSource))
                            {
                                hasActivePowerSource = power.PowerNet.HasActivePowerSource;
                                ShortCircuitUtility.tmpPowerNetHasActivePowerSource.Add(power.PowerNet, hasActivePowerSource);
                            }
                            if (hasActivePowerSource)
                            {
                                break;
                            }
                        }
                        i++;
                        continue;
                    }
                    yield break;
                }
                yield return(b);

                /*Error: Unable to find new state assignment for yield return*/;
            }
            finally
            {
                ((_003CGetShortCircuitablePowerConduits_003Ec__Iterator0) /*Error near IL_0150: stateMachine*/)._003C_003E__Finally0();
            }
IL_0160:
            /*Error near IL_0161: Unexpected return in MoveNext()*/;
        }