1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 22:13:30 +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:
2022-09-06 17:11:35 +08:00
parent 284e05cf22
commit 3257314f83
2 changed files with 127 additions and 57 deletions

View File

@@ -16,10 +16,14 @@ public class LogisticMiner : BaseUnityPlugin
private static long _oilEnergyConsume = 3600000;
private static long _waterEnergyConsume = 20000000;
private static int _waterSpeed = 100;
private static int _miningScale = 100;
private static int _miningScale;
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 _miningCostBarrierOil;
@@ -40,7 +44,7 @@ public class LogisticMiner : BaseUnityPlugin
_waterSpeed = Config.Bind("General", "WaterMiningSpeed", _waterSpeed,
"Water mining speed (count per second)").Value;
_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;
if (_miningScale < 100)
{
@@ -51,6 +55,27 @@ public class LogisticMiner : BaseUnityPlugin
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]
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(GameDesc))]
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(string))]
@@ -58,13 +83,38 @@ public class LogisticMiner : BaseUnityPlugin
{
Logger.LogInfo("Game Start");
PlanetVeinCacheData.Clear();
_frame = 0f;
/* codes reserved for future use: storage max may affect mining scale
/* Thinking: storage max may affect mining scale?
_localStationMax = LDB.items.Select(2103).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]
[HarmonyPatch(typeof(GameData), "GameTick")]
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]
[HarmonyPatch(typeof(PlanetFactory), "Init")]
[HarmonyPatch(typeof(PlanetFactory), "RecalculateVeinGroup")]
@@ -106,7 +166,7 @@ public class LogisticMiner : BaseUnityPlugin
{
vcd = new VeinCacheData();
vcd.GenVeins(factory);
vcd.FrameNext = _frame + 120f / GameMain.history.miningSpeedScale;
vcd.FrameNext = _frame + _miningFrames;
PlanetVeinCacheData.Add(planetId, vcd);
}
}
@@ -115,10 +175,7 @@ public class LogisticMiner : BaseUnityPlugin
[HarmonyPatch(typeof(FactorySystem), "CheckBeforeGameTick")]
private static void Miner(FactorySystem __instance)
{
var history = GameMain.history;
var miningSpeedScalef = history.miningSpeedScale;
var miningSpeedScale = (long)(miningSpeedScalef * 100);
if (miningSpeedScale <= 0)
if (_miningSpeedScaleLong <= 0)
return;
var factory = __instance.factory;
var planetId = factory.planetId;
@@ -131,22 +188,11 @@ public class LogisticMiner : BaseUnityPlugin
{
PlanetVeinCacheData[planetId] = new VeinCacheData
{
FrameNext = _frame + 120f / miningSpeedScalef
FrameNext = _frame + _miningFrames
};
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 factoryProductionStat =
GameMain.statistics.production.factoryStatPool[__instance.factory.index];
@@ -177,19 +223,20 @@ public class LogisticMiner : BaseUnityPlugin
long energyConsume;
isCollecting = true;
var miningScale = _miningScale;
if (miningScale > 100)
if (miningScale == 0)
{
if (stationStore.count * 2 > stationStore.max)
miningScale = 100 +
((miningScale - 100) * (stationStore.max - stationStore.count / 2) +
stationStore.max - 1) / stationStore.max;
else
miningScale = 100;
miningScale = _advancedMiningMachineUnlocked ? 300 : 100;
}
if (miningScale > 100 && stationStore.count * 2 > stationStore.max)
{
miningScale = 100 +
((miningScale - 100) * (stationStore.max - stationStore.count) * 2 +
stationStore.max - 1) / stationStore.max;
}
if (isVein)
{
(amount, energyConsume) = vcd.Mine(factory, stationStore.itemId, miningScale, miningSpeedScale,
(amount, energyConsume) = vcd.Mine(factory, stationStore.itemId, miningScale, _miningSpeedScaleLong,
stationComponent.energy);
if (amount < 0)
{
@@ -200,7 +247,7 @@ public class LogisticMiner : BaseUnityPlugin
else
{
energyConsume = (_waterEnergyConsume * miningScale * miningScale + 9999L) / 100L /
miningSpeedScale;
_miningSpeedScaleLong;
if (stationComponent.energy < energyConsume)
{
k = int.MaxValue - 1;
@@ -231,7 +278,7 @@ public class LogisticMiner : BaseUnityPlugin
stationComponent.energy += count * heatValue;
}
vcd.FrameNext += miningFrames;
vcd.FrameNext += _miningFrames;
} while (vcd.FrameNext <= _frame);
PerformanceMonitor.EndSample(ECpuWorkEntry.Miner);

View File

@@ -1,42 +1,65 @@
# DSP Mods by Soar Qin
## [CheatEnabler](CheatEnabler)
### Enable cheat functions as below
* 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).
* Numpad 1: Gets all items and extends bag.
* Numpad 2: Boosts walk speed, gathering speed and mecha energy restoration.
* Numpad 3: Fills planet with foundations and bury all veins.
* Numpad 4: +1 construction drone.
* Numpad 5: Upgrades drone engine tech to full.
* Numpad 6: Unlocks researching tech.
* Numpad 7: Unlocks Drive Engine 1.
* Numpad 8: Unlocks Drive Engine 2 and maximize energy.
* Numpad 9: Unlocks ability to warp.
* Numpad 0: No costs for Logistic Storages' output.
* LCtrl + T: Unlocks all techs (not upgrades).
* LCtrl + A: Resets all local achievements.
* LCtrl + Q: Adds 10000 to every metadata.
* LCtrl + W: Enters Sandbox Mode.
* Numpad *: Proliferates items on hand.
* Numpad /: Removes proliferations from items on hand.
* PageDown: Remembers Pose of game camera.
* PageUp: Locks game camera using remembered Pose.
* Numpad 1: Gets all items and extends bag.
* Numpad 2: Boosts walk speed, gathering speed and mecha energy restoration.
* Numpad 3: Fills planet with foundations and bury all veins.
* Numpad 4: +1 construction drone.
* Numpad 5: Upgrades drone engine tech to full.
* Numpad 6: Unlocks researching tech.
* Numpad 7: Unlocks Drive Engine 1.
* Numpad 8: Unlocks Drive Engine 2 and maximize energy.
* Numpad 9: Unlocks ability to warp.
* Numpad 0: No costs for Logistic Storages' output.
* LCtrl + T: Unlocks all techs (not upgrades).
* LCtrl + A: Resets all local achievements.
* LCtrl + Q: Adds 10000 to every metadata.
* LCtrl + W: Enters Sandbox Mode.
* Numpad *: Proliferates items on hand.
* Numpad /: Removes proliferations from items on hand.
* PageDown: Remembers Pose of game camera.
* PageUp: Locks game camera using remembered Pose.
* Always infinite resource.
* Each function can be enabled individually in config file.
## [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)
### Hide/Disable various in-game tips/messages
* Tips/messages that can be hidden: random-reminder, tutorial, achievement/milestone card.
* Each type of tips/messages can be configurable individually.
* For sanity check warning messages, please check [CheatEnabler](CheatEnabler)