1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 20:13:29 +08:00

work in progress

This commit is contained in:
2025-10-29 22:30:10 +08:00
parent 61811f9a8c
commit c99c59a117
3 changed files with 36 additions and 25 deletions

View File

@@ -1,7 +1,6 @@
using System;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UXAssist.Common;
using Random = UnityEngine.Random;
using GameLogicProc = UXAssist.Common.GameLogic;
@@ -72,7 +71,6 @@ public class Miner : PatchImpl<Miner>
private static void OnGameBegin()
{
VeinManager.Clear();
_frame = 0L;
UpdateMiningCostRate();
UpdateSpeedScale();
@@ -135,7 +133,6 @@ public class Miner : PatchImpl<Miner>
var frameCounter = _frame / 1200000L;
if (frameCounter <= 0) return;
_frame -= frameCounter * 1200000L;
// LogisticHub.Logger.LogDebug($"FrameCounter: {frameCounter}");
DeepProfiler.BeginSample(DPEntry.Miner);
var data = GameMain.data;
@@ -155,6 +152,7 @@ public class Miner : PatchImpl<Miner>
{
foreach (var storageIndex in demands[itemIndex])
{
LogisticHub.Logger.LogDebug($"StorageIndex: {storageIndex}");
var station = planetTransport.stationPool[storageIndex / 100];
if (station == null)
continue;
@@ -195,7 +193,7 @@ public class Miner : PatchImpl<Miner>
for (var i = planetTransport.stationCursor - 1; i > 0; i--)
{
var stationComponent = planetTransport.stationPool[i];
if (stationComponent.isCollector || stationComponent.isVeinCollector || stationComponent.energy * 2 >= stationComponent.energyMax) continue;
if (stationComponent == null || stationComponent.isCollector || stationComponent.isVeinCollector || stationComponent.energy * 2 >= stationComponent.energyMax) continue;
var index = (stationComponent.isStellar ? FuelIlsSlot.Value : FuelPlsSlot.Value) - 1;
var storage = stationComponent.storage;
if (index < 0 || index >= storage.Length)

View File

@@ -54,34 +54,37 @@ public class StationManager : PatchImpl<StationManager>
public static void Init()
{
GameLogicProc.OnGameBegin += () =>
{
_stations = null;
var data = GameMain.data;
for (var index = data.factoryCount - 1; index >= 0; index--)
{
var factory = data.factories[index];
if (factory == null || factory.index != index) continue;
var planetIndex = factory.index;
var stations = StationsByPlanet(planetIndex);
var transport = factory.transport;
var pool = transport.stationPool;
for (var i = transport.stationCursor - 1; i > 0; i--)
{
var station = pool[i];
if (station == null || station.id != i || station.isCollector || station.isVeinCollector) continue;
UpdateStationInfo(stations, station);
}
}
};
GameLogicProc.OnGameBegin += OnGameBegin;
Enable(true);
}
public static void Uninit()
{
GameLogicProc.OnGameBegin -= OnGameBegin;
Enable(false);
}
private static void OnGameBegin()
{
_stations = null;
var data = GameMain.data;
for (var index = data.factoryCount - 1; index >= 0; index--)
{
var factory = data.factories[index];
if (factory == null || factory.index != index) continue;
var planetIndex = factory.index;
var stations = StationsByPlanet(planetIndex);
var transport = factory.transport;
var pool = transport.stationPool;
for (var i = transport.stationCursor - 1; i > 0; i--)
{
var station = pool[i];
if (station == null || station.id != i || station.isCollector || station.isVeinCollector) continue;
UpdateStationInfo(stations, station);
}
}
}
private static int ItemIdToIndex(int itemId)
{
return itemId switch

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using HarmonyLib;
using UXAssist.Common;
using GameLogicProc = UXAssist.Common.GameLogic;
namespace LogisticHub.Module;
@@ -19,16 +20,25 @@ public class VeinManager : PatchImpl<VeinManager>
public static void Init()
{
Enable(true);
GameLogicProc.OnGameBegin += OnGameBegin;
}
public static void Uninit()
{
GameLogicProc.OnGameBegin -= OnGameBegin;
Enable(false);
}
public static void Clear()
private static void OnGameBegin()
{
_veins = null;
var data = GameMain.data;
for (var index = data.factoryCount - 1; index >= 0; index--)
{
var factory = data.factories[index];
if (factory == null || factory.index != index) continue;
RecalcVeins(factory);
}
}
public static ProductVeinData[] GetVeins(int planetIndex)