Skip to content

Commit

Permalink
sprinkler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KylianB committed Oct 29, 2022
1 parent 276212b commit 492da33
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
Binary file modified 1.4/Assemblies/VFEF.dll
Binary file not shown.
27 changes: 17 additions & 10 deletions Source/VFEF/CompSprinkler.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -25,28 +25,35 @@ public CompProperties_Sprinkler Props

public List<IntVec3> affectCells = new List<IntVec3>();

public Map map;
public CompPowerTrader compPowerTrader;

public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
parent.Map.GetComponent<VFEF_SprinklersManager>().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<VFEF_SprinklersManager>().Register(this);
compPowerTrader = parent.GetComp<CompPowerTrader>();
}

public override void PostDeSpawn(Map map)
{
base.PostDeSpawn(map);
map.GetComponent<VFEF_SprinklersManager>().Deregister(this);
affectCells.Clear();
map.GetComponent<VFEF_SprinklersManager>().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()
Expand All @@ -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;
}
Expand Down
43 changes: 19 additions & 24 deletions Source/VFEF/VFEF_SprinklersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<CompPowerTrader>().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<Thing> 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);
}
}
}
Expand Down

0 comments on commit 492da33

Please sign in to comment.