public void ConnectToTransmitter(CompShield 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,
                    "."
                }));
                return;
            }
            this.connectParent = transmitter;
            if (this.connectParent.connectChildren == null)
            {
                this.connectParent.connectChildren = new List <CompShield>();
            }
            transmitter.connectChildren.Add(this);
            ShieldNet powerNet = this.ShieldNet;

            if (powerNet != null)
            {
                powerNet.RegisterConnector(this);
            }
        }
        /*
         * [DebuggerHidden]
         * public override IEnumerable<Gizmo> CompGetGizmosExtra() {
         *  CompShield.< CompGetGizmosExtra > c__IteratorB2 < CompGetGizmosExtra > c__IteratorB = new CompShield.< CompGetGizmosExtra > c__IteratorB2();
         *
         *  < CompGetGizmosExtra > c__IteratorB.<> f__this = this;
         *  CompShield.< CompGetGizmosExtra > c__IteratorB2 expr_0E = < CompGetGizmosExtra > c__IteratorB;
         *  expr_0E.$PC = -2;
         *  return expr_0E;
         * }
         */

        private void TryManualReconnect()
        {
            if (CompShield.lastManualReconnector != this)
            {
                CompShield.recentlyConnectedNets.Clear();
                CompShield.lastManualReconnector = this;
            }
            if (this.ShieldNet != null)
            {
                CompShield.recentlyConnectedNets.Add(this.ShieldNet);
            }
            CompShield compPower = ShieldConnectionMaker.BestTransmitterForConnector(this.parent.Position, this.parent.Map, CompShield.recentlyConnectedNets);

            if (compShield == null)
            {
                CompShield.recentlyConnectedNets.Clear();
                compPower = ShieldConnectionMaker.BestTransmitterForConnector(this.parent.Position, this.parent.Map, null);
            }
            if (compPower != null)
            {
                ShieldConnectionMaker.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);
            }
        }
Esempio n. 3
0
 public void Notify_ConnectorWantsConnect(CompShield wantingCon)
 {
     if (Scribe.mode == LoadSaveMode.Inactive && !this.HasRegisterConnectorDuplicate(wantingCon))
     {
         this.delayedActions.Add(new ShieldNetManager.DelayedAction(ShieldNetManager.DelayedActionType.RegisterConnector, wantingCon));
     }
     this.NotifyDrawersForWireUpdate(wantingCon.parent.Position);
 }
 public virtual void ResetPowerVars()
 {
     this.transNet        = null;
     this.connectParent   = null;
     this.connectChildren = null;
     CompShield.recentlyConnectedNets.Clear();
     CompShield.lastManualReconnector = null;
 }
 public virtual void LostConnectParent()
 {
     this.connectParent = null;
     if (this.parent.Spawned)
     {
         this.parent.Map.shieldNetManager.Notify_ConnectorWantsConnect(this);
     }
 }
 public void RegisterConnector(CompShield b)
 {
     if (this.connectors.Contains(b))
     {
         Log.Error("PowerNet registered connector it already had: " + b);
         return;
     }
     this.connectors.Add(b);
     this.RegisterAllComponentsOf(b.parent);
 }
Esempio n. 7
0
 public void Notfiy_TransmitterTransmitsPowerNowChanged(CompShield transmitter)
 {
     if (!transmitter.parent.Spawned)
     {
         return;
     }
     this.delayedActions.Add(new ShieldNetManager.DelayedAction(ShieldNetManager.DelayedActionType.DeregisterTransmitter, transmitter));
     this.delayedActions.Add(new ShieldNetManager.DelayedAction(ShieldNetManager.DelayedActionType.RegisterTransmitter, transmitter));
     this.NotifyDrawersForWireUpdate(transmitter.parent.Position);
 }
Esempio n. 8
0
 private bool HasRegisterConnectorDuplicate(CompShield compPower)
 {
     for (int i = this.delayedActions.Count - 1; i >= 0; i--)
     {
         if (this.delayedActions[i].compShield == compPower)
         {
             if (this.delayedActions[i].type == ShieldNetManager.DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (this.delayedActions[i].type == ShieldNetManager.DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public override void PostExposeData()
        {
            Thing thing = null;

            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 <CompShield>();
            }
            if (Scribe.mode == LoadSaveMode.PostLoadInit && this.connectParent != null)
            {
                this.ConnectToTransmitter(this.connectParent, true);
            }
        }
Esempio n. 10
0
 public void DeregisterConnector(CompShield b)
 {
     this.connectors.Remove(b);
     this.DeregisterAllComponentsOf(b.parent);
 }
Esempio n. 11
0
 private bool IsPowerSource(CompShield cp)
 {
     return(cp is CompShieldBattery || (cp is CompShieldTrader && cp.Props.basePowerConsumption < 0f));
 }
Esempio n. 12
0
 public void Notify_ConnectorDespawned(CompShield oldCon)
 {
     this.delayedActions.Add(new ShieldNetManager.DelayedAction(ShieldNetManager.DelayedActionType.DeregisterConnector, oldCon));
     this.NotifyDrawersForWireUpdate(oldCon.parent.Position);
 }
Esempio n. 13
0
 public void Notify_TransmitterDespawned(CompShield oldTransmitter)
 {
     this.delayedActions.Add(new ShieldNetManager.DelayedAction(ShieldNetManager.DelayedActionType.DeregisterTransmitter, oldTransmitter));
     this.NotifyDrawersForWireUpdate(oldTransmitter.parent.Position);
 }
Esempio n. 14
0
 public DelayedAction(ShieldNetManager.DelayedActionType type, CompShield compShield)
 {
     this.type       = type;
     this.compShield = compShield;
 }