Ejemplo n.º 1
0
        private void RegisterAllComponentsOf(ThingWithComps parentThing)
        {
            CompWaterTrader comp = parentThing.GetComp <CompWaterTrader>();

            if (comp != null)
            {
                if (this.WaterComps.Contains(comp))
                {
                    //Log.Error("WaterNet adding WaterComp " + comp + " which it already has.");
                }
                else
                {
                    this.WaterComps.Add(comp);
                }
            }
            CompWaterTank comp2 = parentThing.GetComp <CompWaterTank>();

            if (comp2 != null)
            {
                if (this.batteryComps.Contains(comp2))
                {
                    //Log.Error("WaterNet adding WaterTankComp " + comp2 + " which it already has.");
                }
                else
                {
                    this.batteryComps.Add(comp2);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private void DeregisterAllComponentsOf(ThingWithComps parentThing)
        {
            CompWaterTrader comp = parentThing.GetComp <CompWaterTrader>();

            if (comp != null)
            {
                this.WaterComps.Remove(comp);
            }
            CompWaterTank comp2 = parentThing.GetComp <CompWaterTank>();

            if (comp2 != null)
            {
                this.batteryComps.Remove(comp2);
            }
        }
Ejemplo n.º 4
0
        public void WaterNetTick()
        {
            float num  = this.CurrentWaterGainRate();
            float num2 = this.CurrentStoredWater();

            if (num2 + num >= -1E-07f && !this.Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare))
            {
                float num3;
                if (this.batteryComps.Count > 0 && num2 >= 0.1f)
                {
                    num3 = num2 - 5f;
                }
                else
                {
                    num3 = num2;
                }
                if (UnityData.isDebugBuild)
                {
                    this.debugLastApparentStoredWater = num3;
                    this.debugLastCreatedWater        = num;
                    this.debugLastRawStoredWater      = num2;
                }
                if (num3 + num >= 0f)
                {
                    WaterNet.partsWantingWaterOn.Clear();
                    for (int i = 0; i < this.WaterComps.Count; i++)
                    {
                        if (!this.WaterComps[i].WaterOn && FlickUtility.WantsToBeOn(this.WaterComps[i].parent) && !this.WaterComps[i].parent.IsBrokenDown())
                        {
                            WaterNet.partsWantingWaterOn.Add(this.WaterComps[i]);
                        }
                    }
                    if (WaterNet.partsWantingWaterOn.Count > 0)
                    {
                        int num4 = 200 / WaterNet.partsWantingWaterOn.Count;
                        if (num4 < 30)
                        {
                            num4 = 30;
                        }
                        if (Find.TickManager.TicksGame % num4 == 0)
                        {
                            int num5 = Mathf.Max(1, Mathf.RoundToInt((float)WaterNet.partsWantingWaterOn.Count * 0.05f));
                            for (int j = 0; j < num5; j++)
                            {
                                CompWaterTrader compWaterTrader = WaterNet.partsWantingWaterOn.RandomElement <CompWaterTrader>();
                                if (!compWaterTrader.WaterOn)
                                {
                                    if (num + num2 >= -(compWaterTrader.WaterOutputPerTick + 1E-07f))
                                    {
                                        compWaterTrader.WaterOn = true;
                                        num += compWaterTrader.WaterOutputPerTick;
                                    }
                                }
                            }
                        }
                    }
                }
                this.ChangeStoredWater(num);
            }
            else if (Find.TickManager.TicksGame % 20 == 0)
            {
                WaterNet.potentialShutdownParts.Clear();
                for (int k = 0; k < this.WaterComps.Count; k++)
                {
                    if (this.WaterComps[k].WaterOn && this.WaterComps[k].WaterOutputPerTick < 0f)
                    {
                        WaterNet.potentialShutdownParts.Add(this.WaterComps[k]);
                    }
                }
                if (WaterNet.potentialShutdownParts.Count > 0)
                {
                    int num6 = Mathf.Max(1, Mathf.RoundToInt((float)WaterNet.potentialShutdownParts.Count * 0.05f));
                    for (int l = 0; l < num6; l++)
                    {
                        WaterNet.potentialShutdownParts.RandomElement <CompWaterTrader>().WaterOn = false;
                    }
                }
            }
        }