diff --git a/1.4/Assemblies/VFEF.dll b/1.4/Assemblies/VFEF.dll index b05c16c..527ed28 100644 Binary files a/1.4/Assemblies/VFEF.dll and b/1.4/Assemblies/VFEF.dll differ diff --git a/Source/VFEF/CompSprinkler.cs b/Source/VFEF/CompSprinkler.cs index 26eeb96..39cd6cb 100644 --- a/Source/VFEF/CompSprinkler.cs +++ b/Source/VFEF/CompSprinkler.cs @@ -1,7 +1,7 @@ -using RimWorld; -using System.Collections.Generic; -using Verse; +using System.Collections.Generic; using System.Linq; +using RimWorld; +using Verse; namespace VFEF { @@ -25,28 +25,35 @@ public CompProperties_Sprinkler Props public List affectCells = new List(); + public Map map; + public CompPowerTrader compPowerTrader; + public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); - parent.Map.GetComponent().Register(this); - LastSprinkledMotesTick = (long)(GenTicks.TicksAbs - 60000); - affectCells.AddRange(parent.Map.AllCells.Where(cell => parent.Position.DistanceTo(cell) < Props.effectRadius)); + map = parent.Map; + + LastSprinkledMotesTick = GenTicks.TicksAbs - 60000; + affectCells = GenRadial.RadialCellsAround(parent.Position, Props.effectRadius, true).ToList(); + + map.GetComponent().Register(this); + compPowerTrader = parent.GetComp(); } public override void PostDeSpawn(Map map) { base.PostDeSpawn(map); - map.GetComponent().Deregister(this); affectCells.Clear(); + map.GetComponent().Deregister(this); } public void StartSprinklingMotes() { curRot = 0f; CurrentlySprinklingMotes = true; - MoteSprinkleEndTick = (long)(GenTicks.TicksAbs + Props.sprinkleDurationTicks); + MoteSprinkleEndTick = GenTicks.TicksAbs + Props.sprinkleDurationTicks; SprinkleMotes(); - LastSprinkledMotesTick = (long)GenTicks.TicksAbs; + LastSprinkledMotesTick = GenTicks.TicksAbs; } public void SprinkleMotes() @@ -57,7 +64,7 @@ public void SprinkleMotes() } if (GenTicks.TicksAbs % Props.moteMod == 0) { - MoteSprinkler.ThrowWaterSpray(parent.TrueCenter(), parent.Map, curRot, Props.moteThingDef); + MoteSprinkler.ThrowWaterSpray(parent.TrueCenter(), map, curRot, Props.moteThingDef); } curRot += Props.degreesPerTick; } diff --git a/Source/VFEF/VFEF_SprinklersManager.cs b/Source/VFEF/VFEF_SprinklersManager.cs index 65e9c4a..a22c433 100644 --- a/Source/VFEF/VFEF_SprinklersManager.cs +++ b/Source/VFEF/VFEF_SprinklersManager.cs @@ -34,8 +34,7 @@ public void Deregister(CompSprinkler c) private void BoostPlantAt(IntVec3 cell) { - Plant _plant = cell.GetPlant(map); - if (_plant != null && !_plant.def.plant.IsTree) // No tree growth boost + if (cell.GetPlant(map) is Plant _plant && !_plant.def.plant.IsTree) // No tree growth boost { _plant.Growth += 0.04f; } @@ -54,33 +53,29 @@ public override void MapComponentTick() { if (GenLocalDate.HourOfDay(map) == 7) { - for (int i = 0; i < comps.Count; i++) + var ticksAbs = GenTicks.TicksAbs; + for (int c = 0; c < comps.Count; c++) { - CompSprinkler _sprinkler = comps[i]; - if (_sprinkler.parent.GetComp().PowerOn && !_sprinkler.CurrentlySprinklingMotes && GenTicks.TicksAbs - _sprinkler.LastSprinkledMotesTick >= 57500L) + CompSprinkler _sprinkler = comps[c]; + if (_sprinkler.Props.shouldSprinkleMotes) { - if (_sprinkler.Props.shouldSprinkleMotes) + if (_sprinkler.compPowerTrader.PowerOn && !_sprinkler.CurrentlySprinklingMotes && ticksAbs - _sprinkler.LastSprinkledMotesTick >= 57500L) { _sprinkler.StartSprinklingMotes(); + for (int i = 0; i < affectedCells.Count; i++) + { + var cell = affectedCells[i]; + var list = map.thingGrid.ThingsListAt(cell); + if (list.Count == 0 || !list.Any(b => b is Building building && exception.Contains(building.def.defName))) + { + BoostPlantAt(cell); + } + } + } + else if (_sprinkler.CurrentlySprinklingMotes) + { + _sprinkler.SprinkleMotes(); } - } - else if (_sprinkler.Props.shouldSprinkleMotes && _sprinkler.CurrentlySprinklingMotes) - { - _sprinkler.SprinkleMotes(); - } - } - - for (int i = 0; i < affectedCells.Count; i++) - { - IntVec3 cell = affectedCells[i]; - List list = map.thingGrid.ThingsListAt(cell); - if (list.Count == 0) - { - BoostPlantAt(cell); - } - else if (!list.FindAll(b => b is Building building && building != null && building.def.altitudeLayer != AltitudeLayer.Conduits && !exception.Contains(building.def.defName)).Any()) - { - BoostPlantAt(cell); } } }