mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(cheatenabler): track signal belts by their owning planet
The belt hooks keyed signal belts by the local planet's factory index. Battlefield Analysis Base drones can finish belts on other planets and Dark Fog attacks can destroy them there, so such changes started or stopped generation on a belt of the current planet, or were dropped while in space, and a destroyed remote belt kept its signal entry for any belt later built in its place. Use the factory that owns the CargoTraffic instead.
This commit is contained in:
1 parent
c000debdc1
commit
7715a2023f
2 files changed
+15
-15
No files matched your search
@@ -427,13 +427,15 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RemoveBeltComponent))]
|
||||
public static void CargoTraffic_RemoveBeltComponent_Prefix(int id)
|
||||
public static void CargoTraffic_RemoveBeltComponent_Prefix(CargoTraffic __instance, int id)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
var planet = GameMain.localPlanet;
|
||||
if (planet == null) return;
|
||||
RemoveSignalBeltPortalEnd(planet.factoryIndex, id);
|
||||
RemoveSignalBelt(planet.factoryIndex, id);
|
||||
// Belts also change on planets other than the local one, for example through Battlefield Analysis Base
|
||||
// construction or Dark Fog attacks, so always use the factory that owns the belt.
|
||||
var factory = __instance.factory;
|
||||
if (factory == null) return;
|
||||
RemoveSignalBeltPortalEnd(factory.index, id);
|
||||
RemoveSignalBelt(factory.index, id);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
@@ -441,9 +443,8 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
public static void CargoTraffic_SetBeltSignalIcon_Postfix(CargoTraffic __instance, int signalId, int entityId)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
var planet = GameMain.localPlanet;
|
||||
if (planet == null) return;
|
||||
var factory = __instance.factory;
|
||||
if (factory == null) return;
|
||||
int number;
|
||||
var needAdd = false;
|
||||
switch (signalId)
|
||||
@@ -460,7 +461,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
break;
|
||||
case >= 601 and <= 609:
|
||||
number = Mathf.RoundToInt(factory.entitySignPool[entityId].count0);
|
||||
var factoryIndex = planet.factoryIndex;
|
||||
var factoryIndex = factory.index;
|
||||
var beltId = factory.entityPool[entityId].beltId;
|
||||
if (number > 0)
|
||||
SetSignalBeltPortalTo(factoryIndex, beltId, number);
|
||||
@@ -472,7 +473,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
}
|
||||
|
||||
{
|
||||
var factoryIndex = planet.factoryIndex;
|
||||
var factoryIndex = factory.index;
|
||||
var beltId = factory.entityPool[entityId].beltId;
|
||||
if (needAdd)
|
||||
{
|
||||
@@ -492,9 +493,8 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
public static void CargoTraffic_SetBeltSignalNumber_Postfix(CargoTraffic __instance, float number, int entityId)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
var planet = GameMain.localPlanet;
|
||||
if (planet == null) return;
|
||||
var factory = __instance.factory;
|
||||
if (factory == null) return;
|
||||
var entitySignPool = factory.entitySignPool;
|
||||
uint signalId;
|
||||
if (entitySignPool[entityId].iconType == 0U || (signalId = entitySignPool[entityId].iconId0) == 0U) return;
|
||||
@@ -506,7 +506,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
case >= 1000 and < 20000:
|
||||
break;
|
||||
case >= 601 and <= 609:
|
||||
var factoryIndex = planet.factoryIndex;
|
||||
var factoryIndex = factory.index;
|
||||
var beltId = factory.entityPool[entityId].beltId;
|
||||
RemoveSignalBeltPortalEnd(factoryIndex, beltId);
|
||||
SetSignalBeltPortalTo(factoryIndex, beltId, Mathf.RoundToInt(number));
|
||||
@@ -516,7 +516,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||
}
|
||||
|
||||
{
|
||||
var factoryIndex = planet.factoryIndex;
|
||||
var factoryIndex = factory.index;
|
||||
var beltId = factory.entityPool[entityId].beltId;
|
||||
var n = Mathf.RoundToInt(number);
|
||||
if (n == 0)
|
||||
|
||||
Reference in new issue
Block a user