mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-02-04 21:42:19 +08:00
Update LogisticMiner.
* Set mining scale to 0 by default, for auto-detect(by Advance Mining Machine tech). * Update mining cost rate and speed scale related variables only when you unlocks related upgrades, for performance optimizations. * Update README
This commit is contained in:
@@ -16,10 +16,14 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
private static long _oilEnergyConsume = 3600000;
|
private static long _oilEnergyConsume = 3600000;
|
||||||
private static long _waterEnergyConsume = 20000000;
|
private static long _waterEnergyConsume = 20000000;
|
||||||
private static int _waterSpeed = 100;
|
private static int _waterSpeed = 100;
|
||||||
private static int _miningScale = 100;
|
private static int _miningScale;
|
||||||
|
|
||||||
private static float _frame;
|
private static float _frame;
|
||||||
private static float _miningCostRate;
|
private static float _miningCostRateByTech;
|
||||||
|
private static float _miningSpeedScaleByTech;
|
||||||
|
private static float _miningFrames;
|
||||||
|
private static long _miningSpeedScaleLong;
|
||||||
|
private static bool _advancedMiningMachineUnlocked;
|
||||||
private static uint _miningCostBarrier;
|
private static uint _miningCostBarrier;
|
||||||
private static uint _miningCostBarrierOil;
|
private static uint _miningCostBarrierOil;
|
||||||
|
|
||||||
@@ -40,7 +44,7 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
_waterSpeed = Config.Bind("General", "WaterMiningSpeed", _waterSpeed,
|
_waterSpeed = Config.Bind("General", "WaterMiningSpeed", _waterSpeed,
|
||||||
"Water mining speed (count per second)").Value;
|
"Water mining speed (count per second)").Value;
|
||||||
_miningScale = Config.Bind("General", "MiningScale", _miningScale,
|
_miningScale = Config.Bind("General", "MiningScale", _miningScale,
|
||||||
"Must not be less than 100. Mining scale(in percents) for slots below half of slot limits, and the scale reduces to 100% smoothly till reach full. Please note that the power consumption increases by the square of the scale which is the same as Advanced Mining Machine")
|
"0 for Auto(which means having researched makes mining scale 300, otherwise 100). Mining scale(in percents) for slots below half of slot limits, and the scale reduces to 100% smoothly till reach full. Please note that the power consumption increases by the square of the scale which is the same as Advanced Mining Machine")
|
||||||
.Value;
|
.Value;
|
||||||
if (_miningScale < 100)
|
if (_miningScale < 100)
|
||||||
{
|
{
|
||||||
@@ -51,6 +55,27 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
Harmony.CreateAndPatchAll(typeof(LogisticMiner));
|
Harmony.CreateAndPatchAll(typeof(LogisticMiner));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CheckRecipes()
|
||||||
|
{
|
||||||
|
_advancedMiningMachineUnlocked = GameMain.history.recipeUnlocked.Contains(119);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateMiningCostRate()
|
||||||
|
{
|
||||||
|
_miningCostRateByTech = GameMain.history.miningCostRate;
|
||||||
|
_miningCostBarrier = (uint)(int)Math.Ceiling(2147483646.0 * _miningCostRateByTech);
|
||||||
|
_miningCostBarrierOil =
|
||||||
|
(uint)(int)Math.Ceiling(2147483646.0 * _miningCostRateByTech * 0.401116669f /
|
||||||
|
GameMain.gameScenario.gameData.gameDesc.resourceMultiplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateSpeedScale()
|
||||||
|
{
|
||||||
|
_miningSpeedScaleByTech = GameMain.history.miningSpeedScale;
|
||||||
|
_miningSpeedScaleLong = (long)(_miningSpeedScaleByTech * 100);
|
||||||
|
_miningFrames = 120f / _miningSpeedScaleByTech;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(GameDesc))]
|
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(GameDesc))]
|
||||||
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(string))]
|
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(string))]
|
||||||
@@ -58,13 +83,38 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
Logger.LogInfo("Game Start");
|
Logger.LogInfo("Game Start");
|
||||||
PlanetVeinCacheData.Clear();
|
PlanetVeinCacheData.Clear();
|
||||||
_frame = 0f;
|
/* Thinking: storage max may affect mining scale?
|
||||||
/* codes reserved for future use: storage max may affect mining scale
|
|
||||||
_localStationMax = LDB.items.Select(2103).prefabDesc.stationMaxItemCount;
|
_localStationMax = LDB.items.Select(2103).prefabDesc.stationMaxItemCount;
|
||||||
_remoteStationMax = LDB.items.Select(2104).prefabDesc.stationMaxItemCount;
|
_remoteStationMax = LDB.items.Select(2104).prefabDesc.stationMaxItemCount;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(GameMain), "Start")]
|
||||||
|
private static void OnGameLoaded()
|
||||||
|
{
|
||||||
|
_frame = 0f;
|
||||||
|
|
||||||
|
UpdateMiningCostRate();
|
||||||
|
UpdateSpeedScale();
|
||||||
|
CheckRecipes();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
|
||||||
|
private static void OnUnlockTech(int func)
|
||||||
|
{
|
||||||
|
switch (func)
|
||||||
|
{
|
||||||
|
case 20:
|
||||||
|
UpdateMiningCostRate();
|
||||||
|
break;
|
||||||
|
case 21:
|
||||||
|
UpdateSpeedScale();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(GameData), "GameTick")]
|
[HarmonyPatch(typeof(GameData), "GameTick")]
|
||||||
private static void FrameTick()
|
private static void FrameTick()
|
||||||
@@ -85,6 +135,16 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(GameHistoryData), "UnlockRecipe")]
|
||||||
|
private static void OnUnlockRecipe(int recipeId)
|
||||||
|
{
|
||||||
|
if (recipeId == 119)
|
||||||
|
{
|
||||||
|
CheckRecipes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(PlanetFactory), "Init")]
|
[HarmonyPatch(typeof(PlanetFactory), "Init")]
|
||||||
[HarmonyPatch(typeof(PlanetFactory), "RecalculateVeinGroup")]
|
[HarmonyPatch(typeof(PlanetFactory), "RecalculateVeinGroup")]
|
||||||
@@ -106,7 +166,7 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
vcd = new VeinCacheData();
|
vcd = new VeinCacheData();
|
||||||
vcd.GenVeins(factory);
|
vcd.GenVeins(factory);
|
||||||
vcd.FrameNext = _frame + 120f / GameMain.history.miningSpeedScale;
|
vcd.FrameNext = _frame + _miningFrames;
|
||||||
PlanetVeinCacheData.Add(planetId, vcd);
|
PlanetVeinCacheData.Add(planetId, vcd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,10 +175,7 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
[HarmonyPatch(typeof(FactorySystem), "CheckBeforeGameTick")]
|
[HarmonyPatch(typeof(FactorySystem), "CheckBeforeGameTick")]
|
||||||
private static void Miner(FactorySystem __instance)
|
private static void Miner(FactorySystem __instance)
|
||||||
{
|
{
|
||||||
var history = GameMain.history;
|
if (_miningSpeedScaleLong <= 0)
|
||||||
var miningSpeedScalef = history.miningSpeedScale;
|
|
||||||
var miningSpeedScale = (long)(miningSpeedScalef * 100);
|
|
||||||
if (miningSpeedScale <= 0)
|
|
||||||
return;
|
return;
|
||||||
var factory = __instance.factory;
|
var factory = __instance.factory;
|
||||||
var planetId = factory.planetId;
|
var planetId = factory.planetId;
|
||||||
@@ -131,22 +188,11 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
{
|
{
|
||||||
PlanetVeinCacheData[planetId] = new VeinCacheData
|
PlanetVeinCacheData[planetId] = new VeinCacheData
|
||||||
{
|
{
|
||||||
FrameNext = _frame + 120f / miningSpeedScalef
|
FrameNext = _frame + _miningFrames
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var miningFrames = 120f / miningSpeedScalef;
|
|
||||||
var miningCostRate = history.miningCostRate;
|
|
||||||
if (!miningCostRate.Equals(_miningCostRate))
|
|
||||||
{
|
|
||||||
_miningCostRate = miningCostRate;
|
|
||||||
_miningCostBarrier = (uint)(int)Math.Ceiling(2147483646.0 * miningCostRate);
|
|
||||||
_miningCostBarrierOil =
|
|
||||||
(uint)(int)Math.Ceiling(2147483646.0 * miningCostRate * 0.401116669f /
|
|
||||||
factory.gameData.gameDesc.resourceMultiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
var planetTransport = __instance.planet.factory.transport;
|
var planetTransport = __instance.planet.factory.transport;
|
||||||
var factoryProductionStat =
|
var factoryProductionStat =
|
||||||
GameMain.statistics.production.factoryStatPool[__instance.factory.index];
|
GameMain.statistics.production.factoryStatPool[__instance.factory.index];
|
||||||
@@ -177,19 +223,20 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
long energyConsume;
|
long energyConsume;
|
||||||
isCollecting = true;
|
isCollecting = true;
|
||||||
var miningScale = _miningScale;
|
var miningScale = _miningScale;
|
||||||
if (miningScale > 100)
|
if (miningScale == 0)
|
||||||
|
{
|
||||||
|
miningScale = _advancedMiningMachineUnlocked ? 300 : 100;
|
||||||
|
}
|
||||||
|
if (miningScale > 100 && stationStore.count * 2 > stationStore.max)
|
||||||
{
|
{
|
||||||
if (stationStore.count * 2 > stationStore.max)
|
|
||||||
miningScale = 100 +
|
miningScale = 100 +
|
||||||
((miningScale - 100) * (stationStore.max - stationStore.count / 2) +
|
((miningScale - 100) * (stationStore.max - stationStore.count) * 2 +
|
||||||
stationStore.max - 1) / stationStore.max;
|
stationStore.max - 1) / stationStore.max;
|
||||||
else
|
|
||||||
miningScale = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVein)
|
if (isVein)
|
||||||
{
|
{
|
||||||
(amount, energyConsume) = vcd.Mine(factory, stationStore.itemId, miningScale, miningSpeedScale,
|
(amount, energyConsume) = vcd.Mine(factory, stationStore.itemId, miningScale, _miningSpeedScaleLong,
|
||||||
stationComponent.energy);
|
stationComponent.energy);
|
||||||
if (amount < 0)
|
if (amount < 0)
|
||||||
{
|
{
|
||||||
@@ -200,7 +247,7 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
energyConsume = (_waterEnergyConsume * miningScale * miningScale + 9999L) / 100L /
|
energyConsume = (_waterEnergyConsume * miningScale * miningScale + 9999L) / 100L /
|
||||||
miningSpeedScale;
|
_miningSpeedScaleLong;
|
||||||
if (stationComponent.energy < energyConsume)
|
if (stationComponent.energy < energyConsume)
|
||||||
{
|
{
|
||||||
k = int.MaxValue - 1;
|
k = int.MaxValue - 1;
|
||||||
@@ -231,7 +278,7 @@ public class LogisticMiner : BaseUnityPlugin
|
|||||||
stationComponent.energy += count * heatValue;
|
stationComponent.energy += count * heatValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
vcd.FrameNext += miningFrames;
|
vcd.FrameNext += _miningFrames;
|
||||||
} while (vcd.FrameNext <= _frame);
|
} while (vcd.FrameNext <= _frame);
|
||||||
|
|
||||||
PerformanceMonitor.EndSample(ECpuWorkEntry.Miner);
|
PerformanceMonitor.EndSample(ECpuWorkEntry.Miner);
|
||||||
|
|||||||
37
README.md
37
README.md
@@ -1,7 +1,9 @@
|
|||||||
# DSP Mods by Soar Qin
|
# DSP Mods by Soar Qin
|
||||||
|
|
||||||
## [CheatEnabler](CheatEnabler)
|
## [CheatEnabler](CheatEnabler)
|
||||||
|
|
||||||
### Enable cheat functions as below
|
### Enable cheat functions as below
|
||||||
|
|
||||||
* Disable abnormal determinants (Disable all sanity checks, and can get achievements on using Console and DevShortcuts).
|
* Disable abnormal determinants (Disable all sanity checks, and can get achievements on using Console and DevShortcuts).
|
||||||
* Shift+F4 to switch Developer Mode on/off (no message, tip or sounds on switch).
|
* Shift+F4 to switch Developer Mode on/off (no message, tip or sounds on switch).
|
||||||
* Numpad 1: Gets all items and extends bag.
|
* Numpad 1: Gets all items and extends bag.
|
||||||
@@ -25,18 +27,39 @@
|
|||||||
* Always infinite resource.
|
* Always infinite resource.
|
||||||
* Each function can be enabled individually in config file.
|
* Each function can be enabled individually in config file.
|
||||||
|
|
||||||
|
|
||||||
## [LogisticMiner](LogisticMiner)
|
## [LogisticMiner](LogisticMiner)
|
||||||
### Logistic Storages can mine all ores/water on current planet
|
|
||||||
* Inspired by [PlanetMiner](https://dsp.thunderstore.io/package/blacksnipebiu/PlanetMiner)([github](https://github.com/blacksnipebiu/PlanetMiner)).
|
|
||||||
* The same speed as normal Mining Machine for normal ores and 100/s(configurable) for water.
|
|
||||||
* Can set mining scale in configuration, which makes ILS working like Advance Mining Machines: power consumption increases by the square of the scale.
|
|
||||||
* `Veins Utilization` upgrades affects mining speed and ore consumption as normal miners.
|
|
||||||
* Energy costs: 1MW/vein-group & 10MW/water-slot & 1.8MW/oil-seep(configurable), `Veins Utilization` upgrades does not increase power consumption(unlike PlanetMiner).
|
|
||||||
|
|
||||||
|
### Logistic Storages can mine all ores/water on current planet
|
||||||
|
|
||||||
|
* Inspired
|
||||||
|
by [PlanetMiner](https://dsp.thunderstore.io/package/blacksnipebiu/PlanetMiner)([github](https://github.com/blacksnipebiu/PlanetMiner))
|
||||||
|
.
|
||||||
|
But it is heavily optimized to resolve performance, accuracy and other issues in PlanetMiner:
|
||||||
|
* Only recalculate count of veins when vein chunks are changed (added/removed by foundations/Sandbox-Mode, or
|
||||||
|
exhausted), so this removes Dictionary allocation on each planet for every frame.
|
||||||
|
* More accurate frame counting by use float number.
|
||||||
|
* Does not increase power consumptions on `Veins Utilization` upgrades.
|
||||||
|
* Separate power consumptions for veins, oil seeps and water.
|
||||||
|
* Power consumptions are counted by groups of veins and count of oil seeps, which is more sensible.
|
||||||
|
* All used parameters are configurable:
|
||||||
|
* ILS has the same speed as normal Mining Machine for normal ores by default.
|
||||||
|
|
||||||
|
But you can set mining scale in configuration, which makes ILS working like Advance Mining Machines: power
|
||||||
|
consumption increases by the square of the scale, and gradually decrease mining speed over half of the maximum
|
||||||
|
count.
|
||||||
|
|
||||||
|
This applies to all of veins, oils and water.
|
||||||
|
|
||||||
|
Mining scale can be set to 0(by default), which means it is automatically set by tech unlocks, set to 300 when you
|
||||||
|
reaches Advanced Mining Machine, otherwise 100.
|
||||||
|
* 100/s for water by default.
|
||||||
|
* Energy costs: 1MW/vein-group & 10MW/water-slot & 1.8MW/oil-seep(configurable), `Veins Utilization` upgrades
|
||||||
|
does not increase power consumption(unlike PlanetMiner).
|
||||||
|
|
||||||
## [HideTips](HideTips)
|
## [HideTips](HideTips)
|
||||||
|
|
||||||
### Hide/Disable various in-game tips/messages
|
### Hide/Disable various in-game tips/messages
|
||||||
|
|
||||||
* Tips/messages that can be hidden: random-reminder, tutorial, achievement/milestone card.
|
* Tips/messages that can be hidden: random-reminder, tutorial, achievement/milestone card.
|
||||||
* Each type of tips/messages can be configurable individually.
|
* Each type of tips/messages can be configurable individually.
|
||||||
* For sanity check warning messages, please check [CheatEnabler](CheatEnabler)
|
* For sanity check warning messages, please check [CheatEnabler](CheatEnabler)
|
||||||
|
|||||||
Reference in New Issue
Block a user