Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified 1.4/Assemblies/SCGF.dll
Binary file not shown.
37 changes: 35 additions & 2 deletions Source/SCGF1.4/ExtendedGasGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,40 @@ private void Overflow(IntVec3 cell, GasDef gasDef, int amount)
}, GenRadial.NumCellsInRadius(40f), rememberParents: true);
}

public void TryDissipateGasses(int cellIndex)
public void Tick(List<IntVec3> cardinalDirections, ref int cycleIndexDissipation, ref int cycleIndexDiffusion)
{
if (!CalculateGasEffects)
{
return;
}

int area = map.Area;
int num = Mathf.CeilToInt((float)area * (1f / 64f));
List<IntVec3> cellsInRandomOrder = map.cellsInRandomOrder.GetAll();

for (int i = 0; i < num; i++)
{
if (cycleIndexDissipation >= area)
{
cycleIndexDissipation = 0;
}
TryDissipateGasses(CellIndicesUtility.CellToIndex(cellsInRandomOrder[cycleIndexDissipation], map.Size.x));
cycleIndexDissipation++;
}

num = Mathf.CeilToInt((float)area * (1f / 32f));
for (int j = 0; j < num; j++)
{
if (cycleIndexDiffusion >= area)
{
cycleIndexDiffusion = 0;
}
TryDiffuseGasses(cellsInRandomOrder[cycleIndexDiffusion], cardinalDirections);
cycleIndexDiffusion++;
}
}

private void TryDissipateGasses(int cellIndex)
{
if (!AnyGasAt(cellIndex))
{
Expand Down Expand Up @@ -241,7 +274,7 @@ public void TryDissipateGasses(int cellIndex)
}
}

public void TryDiffuseGasses(IntVec3 cell, List<IntVec3> cardinalDirections)
private void TryDiffuseGasses(IntVec3 cell, List<IntVec3> cardinalDirections)
{
int sourceCellIndex = CellIndicesUtility.CellToIndex(cell, map.Size.x);

Expand Down
23 changes: 15 additions & 8 deletions Source/SCGF1.4/Patches/Patches_GasGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public static void PatchAll(Harmony harmony)
harmony.Patch(AccessTools.Method(gasGrid, nameof(GasGrid.Notify_ThingSpawned)),
postfix: new HarmonyMethod(patchType, nameof(Notify_ThingSpawned_Postfix)));

harmony.Patch(AccessTools.Method(gasGrid, "TryDissipateGasses"), // private method
postfix: new HarmonyMethod(patchType, nameof(TryDissipateGasses_Postfix)));
// harmony.Patch(AccessTools.Method(gasGrid, "TryDissipateGasses"), // private method
// postfix: new HarmonyMethod(patchType, nameof(TryDissipateGasses_Postfix)));

harmony.Patch(AccessTools.Method(gasGrid, nameof(GasGrid.EqualizeGasThroughBuilding)),
postfix: new HarmonyMethod(patchType, nameof(EqualizeGasThroughBuilding_Postfix)));

harmony.Patch(AccessTools.Method(gasGrid, "TryDiffuseGasses"), // private method
postfix: new HarmonyMethod(patchType, nameof(TryDiffuseGasses_Postfix)));
//harmony.Patch(AccessTools.Method(gasGrid, "TryDiffuseGasses"), // private method
// postfix: new HarmonyMethod(patchType, nameof(TryDiffuseGasses_Postfix)));

harmony.Patch(AccessTools.Method(gasGrid, nameof(GasGrid.Tick)), postfix: new HarmonyMethod(patchType, nameof(Tick_Postfix)));

harmony.Patch(AccessTools.Method(gasGrid, nameof(GasGrid.Debug_FillAll)),
postfix: new HarmonyMethod(patchType, nameof(Debug_FillAll_Postfix)));
Expand Down Expand Up @@ -130,13 +132,18 @@ public static void Notify_ThingSpawned_Postfix(ExtendedGasGrid __instance, Thing
__instance.Notify_ThingSpawned(thing);
}

public static void Tick_Postfix(ExtendedGasGrid __instance, List<IntVec3> ___cardinalDirections, ref int ___cycleIndexDissipation, ref int ___cycleIndexDiffusion)
{
__instance.Tick(___cardinalDirections, ref ___cycleIndexDissipation, ref ___cycleIndexDiffusion);
}

/// <summary>
/// A call to dissipate vanilla gases should also try to dissipate custom gases.
/// </summary>
public static void TryDissipateGasses_Postfix(ExtendedGasGrid __instance, int index)
/*public static void TryDissipateGasses_Postfix(ExtendedGasGrid __instance, int index)
{
__instance.TryDissipateGasses(index);
}
}*/

/// <summary>
/// A call to equalize vanilla gases should also try to equalize custom gases.
Expand All @@ -149,10 +156,10 @@ public static void EqualizeGasThroughBuilding_Postfix(ExtendedGasGrid __instance
/// <summary>
/// A call to diffuse vanilla gases should also try to diffuse custom gases.
/// </summary>
public static void TryDiffuseGasses_Postfix(ExtendedGasGrid __instance, IntVec3 cell, List<IntVec3> ___cardinalDirections)
/*public static void TryDiffuseGasses_Postfix(ExtendedGasGrid __instance, IntVec3 cell, List<IntVec3> ___cardinalDirections)
{
__instance.TryDiffuseGasses(cell, ___cardinalDirections);
}
}*/

/// <summary>
/// The debug 'Fill All Gas' option should also fill cells with custom gases instead of just the vanilla ones.
Expand Down