mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 10:53:31 +08:00
UXAssist: Optimize implementation for ProtectVeinsFromExhaustion
This commit is contained in:
@@ -994,12 +994,13 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
switch (__instance.type)
|
switch (__instance.type)
|
||||||
{
|
{
|
||||||
case EMinerType.Vein:
|
case EMinerType.Vein:
|
||||||
if (__instance.veinCount <= 0)
|
var veinCount = __instance.veinCount;
|
||||||
|
if (veinCount <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (__instance.time <= __instance.period)
|
if (__instance.time <= __instance.period)
|
||||||
{
|
{
|
||||||
__instance.time += (int)(power * __instance.speedDamper * __instance.speed * miningSpeed * __instance.veinCount);
|
__instance.time += (int)(power * __instance.speedDamper * __instance.speed * miningSpeed * veinCount);
|
||||||
res = 1U;
|
res = 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1008,23 +1009,16 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
veinId = __instance.veins[__instance.currentVeinIndex];
|
var currentVeinIndex = __instance.currentVeinIndex;
|
||||||
|
veinId = __instance.veins[currentVeinIndex];
|
||||||
lock (veinPool)
|
lock (veinPool)
|
||||||
{
|
{
|
||||||
if (veinPool[veinId].id == 0)
|
if (veinPool[veinId].id == 0)
|
||||||
{
|
{
|
||||||
__instance.RemoveVeinFromArray(__instance.currentVeinIndex);
|
__instance.RemoveVeinFromArray(currentVeinIndex);
|
||||||
__instance.GetMinimumVeinAmount(factory, veinPool);
|
__instance.GetMinimumVeinAmount(factory, veinPool);
|
||||||
if (__instance.veinCount > 1)
|
veinCount = __instance.veinCount;
|
||||||
{
|
__instance.currentVeinIndex = veinCount > 1 ? currentVeinIndex % veinCount : 0;
|
||||||
__instance.currentVeinIndex %= __instance.veinCount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__instance.currentVeinIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
__instance.time += (int)(power * __instance.speedDamper * __instance.speed * miningSpeed * __instance.veinCount);
|
|
||||||
__result = 0U;
|
__result = 0U;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1035,9 +1029,9 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
times = __instance.time / __instance.period;
|
times = __instance.time / __instance.period;
|
||||||
var outputCount = 0;
|
var outputCount = 0;
|
||||||
var amount = veinPool[veinId].amount;
|
var amount = veinPool[veinId].amount;
|
||||||
if (amount > KeepVeinAmount)
|
|
||||||
{
|
|
||||||
if (miningRate > 0f)
|
if (miningRate > 0f)
|
||||||
|
{
|
||||||
|
if (amount > KeepVeinAmount)
|
||||||
{
|
{
|
||||||
var usedCount = 0;
|
var usedCount = 0;
|
||||||
var maxAllowed = amount - KeepVeinAmount;
|
var maxAllowed = amount - KeepVeinAmount;
|
||||||
@@ -1078,18 +1072,34 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
factory.RemoveVeinWithComponents(veinId);
|
factory.RemoveVeinWithComponents(veinId);
|
||||||
factory.RecalculateVeinGroup(groupIndex);
|
factory.RecalculateVeinGroup(groupIndex);
|
||||||
factory.NotifyVeinExhausted(venType, pos);
|
factory.NotifyVeinExhausted(venType, pos);
|
||||||
|
veinCount = __instance.veinCount;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
__instance.currentVeinIndex++;
|
currentVeinIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (amount <= 0)
|
||||||
|
{
|
||||||
|
__instance.RemoveVeinFromArray(currentVeinIndex);
|
||||||
|
__instance.GetMinimumVeinAmount(factory, veinPool);
|
||||||
|
veinCount = __instance.veinCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentVeinIndex++;
|
||||||
|
}
|
||||||
|
__instance.currentVeinIndex = veinCount > 1 ? currentVeinIndex % veinCount : 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
outputCount = times;
|
outputCount = times;
|
||||||
}
|
}
|
||||||
|
|
||||||
__instance.productCount += outputCount;
|
__instance.productCount += outputCount;
|
||||||
lock (productRegister)
|
lock (productRegister)
|
||||||
{
|
{
|
||||||
@@ -1097,26 +1107,8 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
|||||||
factory.AddMiningFlagUnsafe(veinPool[veinId].type);
|
factory.AddMiningFlagUnsafe(veinPool[veinId].type);
|
||||||
factory.AddVeinMiningFlagUnsafe(veinPool[veinId].type);
|
factory.AddVeinMiningFlagUnsafe(veinPool[veinId].type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (amount <= 0)
|
|
||||||
{
|
|
||||||
__instance.RemoveVeinFromArray(__instance.currentVeinIndex);
|
|
||||||
__instance.GetMinimumVeinAmount(factory, veinPool);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__instance.currentVeinIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
__instance.time -= __instance.period * outputCount;
|
__instance.time -= __instance.period * outputCount;
|
||||||
if (__instance.veinCount > 1)
|
__instance.currentVeinIndex = veinCount > 1 ? currentVeinIndex % veinCount : 0;
|
||||||
{
|
|
||||||
__instance.currentVeinIndex %= __instance.veinCount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__instance.currentVeinIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user