Ejemplo n.º 1
0
 public void Notify_TransmitterSpawned(CompWater newTransmitter)
 {
     //string output = "Transmitter Spawned Called for: " + newTransmitter.parent.Label;
     //WaterUtility.PrintDebugMessage(output);
     delayedActions.Add(new DelayedAction(DelayedActionType.RegisterTransmitter, newTransmitter));
     NotifyDrawersForWireUpdate(newTransmitter.parent.Position);
 }
        private static IEnumerable <CompWater> PotentialConnectorsForTransmitter(CompWater b)
        {
            if (!b.parent.Spawned)
            {
                Log.Warning("Can't check potential connectors for " + b + " because it's unspawned.");
                yield break;
            }
            var rect = b.parent.OccupiedRect().ExpandedBy(ConnectMaxDist).ClipInsideMap(b.parent.Map);

            for (var z = rect.minZ; z <= rect.maxZ; z++)
            {
                for (var x = rect.minX; x <= rect.maxX; x++)
                {
                    var c         = new IntVec3(x, 0, z);
                    var thingList = b.parent.Map.thingGrid.ThingsListAt(c);
                    foreach (var t in thingList)
                    {
                        if (t?.TryGetComp <CompWater>() is CompWater w)
                        {
                            yield return(w);
                        }
                    }
                }
            }
            yield break;
        }
Ejemplo n.º 3
0
 public DelayedAction(DelayedActionType type, CompWater CompWater)
 {
     this.type      = type;
     this.CompWater = CompWater;
     position       = CompWater.parent.Position;
     rotation       = CompWater.parent.Rotation;
 }
        public static CompWater BestTransmitterForConnector(IntVec3 connectorPos, Map map, List <WaterNet> disallowedNets = null)
        {
            var cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(ConnectMaxDist).ClipInsideMap(map);

            cellRect.ClipInsideMap(map);
            var       num    = 999999f;
            CompWater result = null;

            for (var i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (var j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    var c           = new IntVec3(j, 0, i);
                    var transmitter = c.GetWaterTransmitter(map);
                    if (transmitter != null && !transmitter.Destroyed)
                    {
                        var waterComp = transmitter.TryGetComp <CompWater>();
                        if (waterComp != null && waterComp.TransmitsWaterNow && (transmitter.def.building == null || transmitter.def.building.allowWireConnection))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(waterComp.transNet))
                            {
                                var num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num    = num2;
                                    result = waterComp;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
 public void ConnectToTransmitter(CompWater transmitter, bool reconnectingAfterLoading = false)
 {
     //WaterUtility.PrintDebugMessage("ConnectToTransmitter Called");
     if (connectParent != null && (!reconnectingAfterLoading || connectParent != transmitter))
     {
         Log.Error(string.Concat(new object[]
         {
             "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 <CompWater>();
     }
     transmitter.connectChildren.Add(this);
     //WaterUtility.PrintDebugMessage(transmitter.parent.Label);
     //foreach (var v in transmitter.connectChildren)
     //WaterUtility.PrintDebugMessage("->" + v.parent.Label);
     WaterNet?.RegisterConnector(this);
 }
Ejemplo n.º 6
0
 public void Notify_ConnectorWantsConnect(CompWater wantingCon)
 {
     if (Scribe.mode == LoadSaveMode.Inactive && !HasRegisterConnectorDuplicate(wantingCon))
     {
         delayedActions.Add(new DelayedAction(DelayedActionType.RegisterConnector, wantingCon));
     }
     NotifyDrawersForWireUpdate(wantingCon.parent.Position);
 }
 public static void ConnectAllConnectorsToTransmitter(CompWater newTransmitter)
 {
     foreach (var compWater in PotentialConnectorsForTransmitter(newTransmitter))
     {
         if (compWater.connectParent == null)
         {
             compWater.ConnectToTransmitter(newTransmitter);
         }
     }
 }
Ejemplo n.º 8
0
 public void Notify_TransmitterTransmitsWaterNowChanged(CompWater transmitter)
 {
     if (!transmitter.parent.Spawned)
     {
         return;
     }
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, transmitter));
     delayedActions.Add(new DelayedAction(DelayedActionType.RegisterTransmitter, transmitter));
     NotifyDrawersForWireUpdate(transmitter.parent.Position);
 }
Ejemplo n.º 9
0
 public void RegisterConnector(CompWater b)
 {
     //WaterUtility.PrintDebugMessage("RegisterConnector Called");
     if (this.connectors.Contains(b))
     {
         Log.Error("WaterNet registered connector it already had: " + b);
         return;
     }
     this.connectors.Add(b);
     this.RegisterAllComponentsOf(b.parent);
 }
Ejemplo n.º 10
0
        private bool IsActiveWaterSource(CompWater cp)
        {
            CompWaterTank CompWaterTank = cp as CompWaterTank;

            if (CompWaterTank != null && CompWaterTank.StoredWater > 0f)
            {
                return(true);
            }
            CompWaterTrader compWaterTrader = cp as CompWaterTrader;

            return(compWaterTrader != null && compWaterTrader.WaterOutput > 0f);
        }
 public static void DisconnectAllFromTransmitterAndSetWantConnect(CompWater deadPc, Map map)
 {
     if (deadPc.connectChildren == null)
     {
         return;
     }
     foreach (var compWater in deadPc.connectChildren)
     {
         compWater.connectParent = null;
         if (compWater is CompWaterTrader compWaterTrader)
         {
             compWaterTrader.WaterOn = false;
         }
         map.GetComponent <WaterNetManager>().Notify_ConnectorWantsConnect(compWater);
     }
 }
 public static void DisconnectFromWaterNet(CompWater pc)
 {
     if (pc.connectParent == null)
     {
         return;
     }
     pc.WaterNet?.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.º 13
0
 private bool HasRegisterConnectorDuplicate(CompWater CompWater)
 {
     for (int i = delayedActions.Count - 1; i >= 0; i--)
     {
         if (delayedActions[i].CompWater == CompWater)
         {
             if (delayedActions[i].type == DelayedActionType.DeregisterConnector)
             {
                 return(false);
             }
             if (delayedActions[i].type == DelayedActionType.RegisterConnector)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public static void TryConnectToAnyWaterNet(CompWater pc, List <WaterNet> disallowedNets = null)
        {
            if (pc.connectParent != null)
            {
                return;
            }
            if (!pc.parent.Spawned)
            {
                return;
            }
            var compWater = BestTransmitterForConnector(pc.parent.Position, pc.parent.Map, disallowedNets);

            if (compWater != null)
            {
                pc.ConnectToTransmitter(compWater);
            }
            else
            {
                pc.connectParent = null;
            }
        }
Ejemplo n.º 15
0
 private bool IsWaterSource(CompWater cp)
 {
     return(cp is CompWaterTank || (cp is CompWaterTrader && cp.Props.baseWaterConsumption < 0f));
 }
Ejemplo n.º 16
0
 public void Notify_ConnectorDespawned(CompWater oldCon)
 {
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterConnector, oldCon));
     NotifyDrawersForWireUpdate(oldCon.parent.Position);
 }
Ejemplo n.º 17
0
 public void DeregisterConnector(CompWater b)
 {
     this.connectors.Remove(b);
     this.DeregisterAllComponentsOf(b.parent);
 }
Ejemplo n.º 18
0
 public void Notify_TransmitterDespawned(CompWater oldTransmitter)
 {
     delayedActions.Add(new DelayedAction(DelayedActionType.DeregisterTransmitter, oldTransmitter));
     NotifyDrawersForWireUpdate(oldTransmitter.parent.Position);
 }
        public static bool TransmitsWaterNow(this Building b)
        {
            CompWater waterComp = b.TryGetComp <CompWater>();

            return(waterComp != null && waterComp.Props.transmitsWater);
        }