コード例 #1
0
ファイル: CompPipe.cs プロジェクト: juanosarg/BotanicRim
        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);
            NutrientPipeNet pipeNet = this.NutrientPipeNet;

            if (pipeNet != null)
            {
                pipeNet.RegisterConnector(this);
            }
        }
コード例 #2
0
 public DelayedAction(DelayedActionType type, CompPipe compPipe)
 {
     this.type     = type;
     this.compPipe = compPipe;
     this.position = compPipe.parent.Position;
     this.rotation = compPipe.parent.Rotation;
 }
コード例 #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;
        }
コード例 #4
0
        public static CompPipe BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <NutrientPipeNet> 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.TransmitsPowerNow && (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);
        }
コード例 #5
0
 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);
 }
コード例 #6
0
ファイル: CompPipe.cs プロジェクト: juanosarg/BotanicRim
 public virtual void ResetPowerVars()
 {
     this.transNet        = null;
     this.connectParent   = null;
     this.connectChildren = null;
     CompPipe.recentlyConnectedNets.Clear();
     CompPipe.lastManualReconnector = null;
 }
コード例 #7
0
ファイル: CompPipe.cs プロジェクト: juanosarg/BotanicRim
 public virtual void LostConnectParent()
 {
     this.connectParent = null;
     if (this.parent.Spawned)
     {
         this.parent.Map.GetComponent <PipeMapComponent>().Notify_ConnectorWantsConnect(this);
     }
 }
コード例 #8
0
 public static void ConnectAllConnectorsToTransmitter(CompPipe newTransmitter)
 {
     foreach (CompPipe compPipe in PipeConnectionMaker.PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (compPipe.connectParent == null)
         {
             compPipe.ConnectToTransmitter(newTransmitter, false);
         }
     }
 }
コード例 #9
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);
 }
コード例 #10
0
 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);
 }
コード例 #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);
        }
コード例 #12
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);
     }
 }
コード例 #13
0
ファイル: CompPipe.cs プロジェクト: juanosarg/BotanicRim
        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 <CompPipe>();
            }
            if (Scribe.mode == LoadSaveMode.PostLoadInit && this.connectParent != null)
            {
                this.ConnectToTransmitter(this.connectParent, true);
            }
        }
コード例 #14
0
 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);
 }
コード例 #15
0
 public static void DisconnectFromPowerNet(CompPipe pc)
 {
     if (pc.connectParent == null)
     {
         return;
     }
     if (pc.NutrientPipeNet != null)
     {
         pc.NutrientPipeNet.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;
 }
コード例 #16
0
        public static void TryConnectToAnyPowerNet(CompPipe pc, List <NutrientPipeNet> 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;
            }
        }
コード例 #17
0
 public void DeregisterConnector(CompPipe b)
 {
     this.connectors.Remove(b);
     this.DeregisterAllComponentsOf(b.parent);
 }
コード例 #18
0
 private bool IsPowerSource(CompPipe cp)
 {
     return(cp is CompPipeTank || (cp is CompPipeTank && cp.Props.basePowerConsumption < 0f));
 }
コード例 #19
0
 public void Notify_ConnectorDespawned(CompPipe oldCon)
 {
     this.delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterConnector, oldCon));
     this.NotifyDrawersForWireUpdate(oldCon.parent.Position);
 }
コード例 #20
0
        public bool GetPipeTransmission(Building transmitter)
        {
            CompPipe pipeComp = transmitter.GetComp <CompPipe>();

            return(pipeComp != null && pipeComp.Props.transmitsPower);
        }
コード例 #21
0
 public void Notify_TransmitterDespawned(CompPipe oldTransmitter)
 {
     this.delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, oldTransmitter));
     this.NotifyDrawersForWireUpdate(oldTransmitter.parent.Position);
 }