mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 23:33:33 +08:00
Dustbin: support for multi-level tank
This commit is contained in:
@@ -166,40 +166,71 @@ public static class TankPatch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct TankState
|
||||||
|
{
|
||||||
|
public int TankId;
|
||||||
|
public int FluidId;
|
||||||
|
public int FluidCount;
|
||||||
|
public int FluidInc;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(TankComponent), "GameTick")]
|
[HarmonyPatch(typeof(TankComponent), "GameTick")]
|
||||||
private static void TankComponent_GameTick_Prefix(ref TankComponent __instance, out long __state, PlanetFactory factory)
|
private static void TankComponent_GameTick_Prefix(ref TankComponent __instance, ref TankState __state, PlanetFactory factory)
|
||||||
{
|
{
|
||||||
var planetId = factory.planetId;
|
var planetId = factory.planetId;
|
||||||
if (tankIsDustbin[planetId / 100][planetId % 100][__instance.id])
|
var data = tankIsDustbin[planetId / 100][planetId % 100];
|
||||||
|
ref var tank = ref __instance;
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
__state = ((long)__instance.fluidInc << 36) | ((long)__instance.fluidCount << 16) | (uint)__instance.fluidId;
|
if (data[tank.id])
|
||||||
__instance.fluidId = __instance.fluidCount = __instance.fluidInc = 0;
|
{
|
||||||
}
|
__state.TankId = tank.id;
|
||||||
else
|
__state.FluidId = tank.fluidId;
|
||||||
{
|
__state.FluidCount = tank.fluidCount;
|
||||||
__state = -1;
|
__state.FluidInc = tank.fluidInc;
|
||||||
|
tank.fluidId = tank.fluidCount = tank.fluidInc = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tank.fluidCount < tank.fluidCapacity || tank.nextTankId <= 0)
|
||||||
|
{
|
||||||
|
__state.TankId = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var nextTankId = tank.nextTankId;
|
||||||
|
tank = ref factory.factoryStorage.tankPool[nextTankId];
|
||||||
|
if (tank.id == nextTankId) continue;
|
||||||
|
__state.TankId = -1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(TankComponent), "GameTick")]
|
[HarmonyPatch(typeof(TankComponent), "GameTick")]
|
||||||
private static void TankComponent_GameTick_Postfix(ref TankComponent __instance, long __state)
|
private static void TankComponent_GameTick_Postfix(ref TankComponent __instance, ref TankState __state, PlanetFactory factory)
|
||||||
{
|
{
|
||||||
if (__state < 0) return;
|
if (__state.TankId < 0) return;
|
||||||
__instance.fluidId = (int)(__state & 0xFFFFL);
|
var tankId = __state.TankId;
|
||||||
__instance.fluidCount = (int)((__state >> 16) & 0xFFFFFL);
|
if (__instance.id == tankId)
|
||||||
__instance.fluidInc = (int)(__state >> 36);
|
{
|
||||||
|
__instance.fluidId = __state.FluidId;
|
||||||
|
__instance.fluidCount = __state.FluidCount;
|
||||||
|
__instance.fluidInc = __state.FluidInc;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ref var tank = ref factory.factoryStorage.tankPool[tankId];
|
||||||
|
if (tank.id != tankId) return;
|
||||||
|
tank.fluidId = __state.FluidId;
|
||||||
|
tank.fluidCount = __state.FluidCount;
|
||||||
|
tank.fluidInc = __state.FluidInc;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(FactoryStorage), "RemoveTankComponent")]
|
[HarmonyPatch(typeof(FactoryStorage), "RemoveTankComponent")]
|
||||||
private static void FactoryStorage_RemoveTankComponent_Prefix(FactoryStorage __instance, int id)
|
private static void FactoryStorage_RemoveTankComponent_Prefix(FactoryStorage __instance, int id)
|
||||||
{
|
{
|
||||||
if (__instance.tankPool[id].id != 0)
|
if (__instance.tankPool[id].id <= 0) return;
|
||||||
{
|
var planetId = __instance.planet.id;
|
||||||
var planetId = __instance.planet.id;
|
tankIsDustbin[planetId / 100][planetId % 100][id] = false;
|
||||||
tankIsDustbin[planetId / 100][planetId % 100][id] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user