1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-15 05:53:42 +08:00

work in progress

This commit is contained in:
2025-05-23 18:51:45 +08:00
parent 35d75646a0
commit 5f6fd0fe8c
3 changed files with 100 additions and 57 deletions

View File

@@ -87,8 +87,8 @@ public class CheatEnabler : BaseUnityPlugin
"Unlock Dyson Sphere max orbit radius"); "Unlock Dyson Sphere max orbit radius");
DysonSpherePatch.UnlockMaxOrbitRadiusValue = Config.Bind("DysonSphere", "MaxOrbitRadiusValue", 10_000_000f, DysonSpherePatch.UnlockMaxOrbitRadiusValue = Config.Bind("DysonSphere", "MaxOrbitRadiusValue", 10_000_000f,
"Unlocked Dyson Sphere max orbit radius value"); "Unlocked Dyson Sphere max orbit radius value");
Functions.DysonSphereFunctions.RetainShellsCount = Config.Bind("DysonSphere", "RetainShellsCount", 2048, Functions.DysonSphereFunctions.ShellsCountForFunctions = Config.Bind("DysonSphere", "ShellsCountForFunctions", 2048,
"Retain dyson shells count"); "Shells count for various functions");
CombatPatch.MechaInvincibleEnabled = Config.Bind("Battle", "MechaInvincible", false, CombatPatch.MechaInvincibleEnabled = Config.Bind("Battle", "MechaInvincible", false,
"Mecha and Drones/Fleets invincible"); "Mecha and Drones/Fleets invincible");
CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false, CombatPatch.BuildingsInvincibleEnabled = Config.Bind("Battle", "BuildingsInvincible", false,

View File

@@ -10,7 +10,7 @@ namespace CheatEnabler.Functions;
public static class DysonSphereFunctions public static class DysonSphereFunctions
{ {
public static ConfigEntry<int> RetainShellsCount; public static ConfigEntry<int> ShellsCountForFunctions;
public static void Init() public static void Init()
{ {
@@ -625,7 +625,7 @@ public static class DysonSphereFunctions
return true; return true;
} }
private static int QuickAddDysonShell(this DysonSphereLayer layer, int protoId, DysonNode[] nodes, DysonFrame[] frames) private static int QuickAddDysonShell(this DysonSphereLayer layer, int protoId, DysonNode[] nodes, DysonFrame[] frames, bool limit)
{ {
int shellId = 0; int shellId = 0;
if (layer.shellRecycleCursor > 0) if (layer.shellRecycleCursor > 0)
@@ -682,7 +682,7 @@ public static class DysonSphereFunctions
shell.nodes.Add(dysonNode); shell.nodes.Add(dysonNode);
shell.frames.Add(dysonFrame); shell.frames.Add(dysonFrame);
} }
if (!shell.MyGenerateGeometry() || DysonShell.s_vmap.Count < 32000) if (!shell.MyGenerateGeometry() || (limit && DysonShell.s_vmap.Count < 32000))
{ {
CheatEnabler.Logger.LogDebug($"Stripped VertCount: {DysonShell.s_vmap.Count}"); CheatEnabler.Logger.LogDebug($"Stripped VertCount: {DysonShell.s_vmap.Count}");
shell.Free(); shell.Free();
@@ -701,6 +701,22 @@ public static class DysonSphereFunctions
return shellId; return shellId;
} }
private static void QuickRemoveDysonNode(this DysonSphereLayer layer, int nodeId)
{
var node = layer.nodePool[nodeId];
if (node == null || node.id != nodeId) return;
var dysonSphere = layer.dysonSphere;
dysonSphere.swarm.OnNodeRemove(layer.id, nodeId);
dysonSphere.RemoveAutoNode(node);
dysonSphere.RemoveNodeRocket(node);
dysonSphere.RemoveDysonNodeRData(node);
node.Free();
layer.nodePool[nodeId] = null;
int recycleIndex = layer.nodeRecycleCursor;
layer.nodeRecycleCursor = recycleIndex + 1;
layer.nodeRecycle[recycleIndex] = nodeId;
}
private static void QuickRemoveDysonFrame(this DysonSphereLayer layer, int frameId) private static void QuickRemoveDysonFrame(this DysonSphereLayer layer, int frameId)
{ {
var frame = layer.framePool[frameId]; var frame = layer.framePool[frameId];
@@ -759,13 +775,9 @@ public static class DysonSphereFunctions
{ {
var shell = layer.shellPool[j]; var shell = layer.shellPool[j];
if (shell == null || shell.id != j) continue; if (shell == null || shell.id != j) continue;
if (shell.nodes.Count != 3) continue; nodePos.AddRange(shell.nodes.Select(node => node.pos));
nodePos.Add(shell.nodes[0].pos); isEuler.AddRange(shell.frames.Select(frame => frame.euler));
nodePos.Add(shell.nodes[1].pos); break;
nodePos.Add(shell.nodes[2].pos);
isEuler.Add(shell.frames[0].euler);
isEuler.Add(shell.frames[1].euler);
isEuler.Add(shell.frames[2].euler);
} }
break; break;
} }
@@ -774,6 +786,7 @@ public static class DysonSphereFunctions
UIMessageBox.Show("CheatEnabler".Translate(), string.Format("There is no Dyson Sphere shell on \"{0}\".".Translate(), star.displayName), "确定".Translate(), 3, null); UIMessageBox.Show("CheatEnabler".Translate(), string.Format("There is no Dyson Sphere shell on \"{0}\".".Translate(), star.displayName), "确定".Translate(), 3, null);
return; return;
} }
CheatEnabler.Logger.LogDebug($"NodePositions: {nodePos[0]}, {nodePos[1]}, {nodePos[2]}");
UXAssist.Functions.DysonSphereFunctions.InitCurrentDysonLayer(star, -1); UXAssist.Functions.DysonSphereFunctions.InitCurrentDysonLayer(star, -1);
dysonSphere = GameMain.data?.dysonSpheres[star.index]; dysonSphere = GameMain.data?.dysonSpheres[star.index];
for (var i = 1; i < dysonSphere.layersIdBased.Length; i++) for (var i = 1; i < dysonSphere.layersIdBased.Length; i++)
@@ -784,19 +797,28 @@ public static class DysonSphereFunctions
dysonSphere.QueryLayerRadius(ref orbitRadius, out var speed); dysonSphere.QueryLayerRadius(ref orbitRadius, out var speed);
Quaternion quaternion = Quaternion.Euler(0f, 0f, 0f); Quaternion quaternion = Quaternion.Euler(0f, 0f, 0f);
layer = dysonSphere.AddLayer(orbitRadius, quaternion,speed); layer = dysonSphere.AddLayer(orbitRadius, quaternion,speed);
DysonNode[] nodes = [ var nodeCount = nodePos.Count;
layer.QuickAddDysonNode(0, nodePos[0]), DysonNode[] nodes = [.. nodePos.Select(pos => layer.QuickAddDysonNode(0, pos))];
layer.QuickAddDysonNode(0, nodePos[1]), DysonFrame[] frames = [.. nodes.Select((node, index) => layer.QuickAddDysonFrame(0, node, nodes[(index + 1) % nodes.Length], isEuler[index]))];
layer.QuickAddDysonNode(0, nodePos[2]), layer.QuickAddDysonShell(0, nodes, frames, false);
]; long[] cpMax = [.. nodes.Select(node => node.totalCpMax)];
DysonFrame[] frames = [ long[] totalCpMax = [.. cpMax];
layer.QuickAddDysonFrame(0, nodes[0], nodes[1], isEuler[0]), var keepCount = ShellsCountForFunctions.Value;
layer.QuickAddDysonFrame(0, nodes[1], nodes[2], isEuler[1]), for (var i = 1; i < keepCount; i++)
layer.QuickAddDysonFrame(0, nodes[2], nodes[0], isEuler[2]),
];
for (var i = 0; i < 1024; i++)
{ {
layer.QuickAddDysonShell(0, nodes, frames); for (var j = 0; j < nodeCount; j++)
{
totalCpMax[j] += cpMax[j];
if (totalCpMax[j] > int.MaxValue)
{
totalCpMax[j] = cpMax[j];
nodes[j] = layer.QuickAddDysonNode(0, nodePos[j]);
var prev = j > 0 ? j - 1 : nodeCount - 1;
frames[prev] = layer.QuickAddDysonFrame(0, nodes[prev], nodes[j], isEuler[prev]);
frames[j] = layer.QuickAddDysonFrame(0, nodes[j], nodes[(j + 1) % nodeCount], isEuler[j]);
}
}
layer.QuickAddDysonShell(0, nodes, frames, false);
} }
foreach (var node in nodes) foreach (var node in nodes)
{ {
@@ -810,6 +832,10 @@ public static class DysonSphereFunctions
} }
dysonSphere.modelRenderer.RebuildModels(); dysonSphere.modelRenderer.RebuildModels();
GameMain.gameScenario.NotifyOnPlanDysonShell(); GameMain.gameScenario.NotifyOnPlanDysonShell();
dysonSphere.inEditorRenderMaskS = 0;
dysonSphere.inEditorRenderMaskL = 0;
dysonSphere.inGameRenderMaskS = 0;
dysonSphere.inGameRenderMaskL = 0;
} }
public static void CreatePossibleFramesAndShells2() public static void CreatePossibleFramesAndShells2()
@@ -842,7 +868,6 @@ public static class DysonSphereFunctions
for (var i = 1; i < dysonSphere.layersIdBased.Length; i++) for (var i = 1; i < dysonSphere.layersIdBased.Length; i++)
{ {
Dictionary<(int, int), int> availableFrames = []; Dictionary<(int, int), int> availableFrames = [];
HashSet<DysonNode> dirtyNodes = [];
HashSet<int> unusedFrameIds = []; HashSet<int> unusedFrameIds = [];
var layer = dysonSphere.layersIdBased[i]; var layer = dysonSphere.layersIdBased[i];
if (layer == null || layer.id != i) continue; if (layer == null || layer.id != i) continue;
@@ -895,50 +920,67 @@ public static class DysonSphereFunctions
unusedFrameIds.Add(frame.id); unusedFrameIds.Add(frame.id);
} }
} }
var total = 0;
DysonFrame[] frames = null; DysonFrame[] frames = null;
DysonNode[] nodes = null; DysonNode[] nodes = null;
for (j = 0; j < count && total < 8192; j++) var maxJ = -1;
var maxVertCount = -1;
for (j = 0; j < count; j++)
{ {
var shell = supposedShells[j]; var shell = supposedShells[j];
frames = [layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeB.id)]], layer.framePool[availableFrames[(shell.nodeB.id, shell.nodeC.id)]], layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeC.id)]]]; frames = [layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeB.id)]], layer.framePool[availableFrames[(shell.nodeB.id, shell.nodeC.id)]], layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeC.id)]]];
nodes = [shell.nodeA, shell.nodeB, shell.nodeC]; nodes = [shell.nodeA, shell.nodeB, shell.nodeC];
if (layer.QuickAddDysonShell(0, nodes, frames) <= 0) continue; if (layer.QuickAddDysonShell(0, nodes, frames, true) <= 0) {
var vertCount = DysonShell.s_vmap.Count;
if (vertCount < 32768 && vertCount > maxVertCount) {
maxVertCount = vertCount;
maxJ = j;
}
continue;
}
unusedFrameIds.Remove(frames[0].id); unusedFrameIds.Remove(frames[0].id);
unusedFrameIds.Remove(frames[1].id); unusedFrameIds.Remove(frames[1].id);
unusedFrameIds.Remove(frames[2].id); unusedFrameIds.Remove(frames[2].id);
dirtyNodes.Add(shell.nodeA); CheatEnabler.Logger.LogDebug($"Added Shell {shell.nodeA.pos}, {shell.nodeB.pos}, {shell.nodeC.pos} {DysonShell.s_vmap.Count}");
dirtyNodes.Add(shell.nodeB);
dirtyNodes.Add(shell.nodeC);
total++;
shellsChanged = true; shellsChanged = true;
maxJ = -1;
maxVertCount = -1;
break; break;
} }
while (total < 2048) if (maxJ >= 0)
{ {
layer.QuickAddDysonShell(0, nodes, frames); var shell = supposedShells[maxJ];
total++; frames = [layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeB.id)]], layer.framePool[availableFrames[(shell.nodeB.id, shell.nodeC.id)]], layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeC.id)]]];
nodes = [shell.nodeA, shell.nodeB, shell.nodeC];
layer.QuickAddDysonShell(0, nodes, frames, false);
unusedFrameIds.Remove(frames[0].id);
unusedFrameIds.Remove(frames[1].id);
unusedFrameIds.Remove(frames[2].id);
CheatEnabler.Logger.LogDebug($"Added Shell {shell.nodeA.pos}, {shell.nodeB.pos}, {shell.nodeC.pos} {DysonShell.s_vmap.Count}");
shellsChanged = true;
} }
foreach (var frameId in unusedFrameIds) foreach (var frameId in unusedFrameIds)
{ {
layer.QuickRemoveDysonFrame(frameId); layer.QuickRemoveDysonFrame(frameId);
} }
foreach (var node in dirtyNodes) foreach (var node in layer.nodePool)
{ {
node.RecalcSpReq(); if (node == null) continue;
node.RecalcCpReq(); if (node.frames.Count != 0 || node.shells.Count != 0) {
node.RecalcSpReq();
node.RecalcCpReq();
continue;
}
layer.QuickRemoveDysonNode(node.id);
} }
} }
dysonSphere.CheckAutoNodes(); dysonSphere.CheckAutoNodes();
if (dysonSphere.autoNodeCount <= 0) if (dysonSphere.autoNodeCount <= 0) dysonSphere.PickAutoNode();
{ dysonSphere.modelRenderer.RebuildModels();
dysonSphere.PickAutoNode(); if (shellsChanged) GameMain.gameScenario.NotifyOnPlanDysonShell();
} dysonSphere.inEditorRenderMaskS = 0;
if (shellsChanged) dysonSphere.inEditorRenderMaskL = 0;
{ dysonSphere.inGameRenderMaskS = 0;
GameMain.gameScenario.NotifyOnPlanDysonShell(); dysonSphere.inGameRenderMaskL = 0;
dysonSphere.modelRenderer.RebuildModels();
}
} }
public static void CreatePossibleFramesAndShells() public static void CreatePossibleFramesAndShells()
@@ -1046,7 +1088,7 @@ public static class DysonSphereFunctions
if (availableShells.TryGetValue((shell.nodeA.id, shell.nodeB.id, shell.nodeC.id), out _)) continue; if (availableShells.TryGetValue((shell.nodeA.id, shell.nodeB.id, shell.nodeC.id), out _)) continue;
DysonFrame[] frames = [layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeB.id)]], layer.framePool[availableFrames[(shell.nodeB.id, shell.nodeC.id)]], layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeC.id)]]]; DysonFrame[] frames = [layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeB.id)]], layer.framePool[availableFrames[(shell.nodeB.id, shell.nodeC.id)]], layer.framePool[availableFrames[(shell.nodeA.id, shell.nodeC.id)]]];
DysonNode[] nodes = [shell.nodeA, shell.nodeB, shell.nodeC]; DysonNode[] nodes = [shell.nodeA, shell.nodeB, shell.nodeC];
if (layer.QuickAddDysonShell(0, nodes, frames) <= 0) continue; if (layer.QuickAddDysonShell(0, nodes, frames, false) <= 0) continue;
unusedFrameIds.Remove(frames[0].id); unusedFrameIds.Remove(frames[0].id);
unusedFrameIds.Remove(frames[1].id); unusedFrameIds.Remove(frames[1].id);
unusedFrameIds.Remove(frames[2].id); unusedFrameIds.Remove(frames[2].id);
@@ -1101,7 +1143,7 @@ public static class DysonSphereFunctions
UIMessageBox.Show("CheatEnabler".Translate(), string.Format("There is no Dyson Sphere shell on \"{0}\".".Translate(), star.displayName), "确定".Translate(), 3, null); UIMessageBox.Show("CheatEnabler".Translate(), string.Format("There is no Dyson Sphere shell on \"{0}\".".Translate(), star.displayName), "确定".Translate(), 3, null);
return; return;
} }
int retainCount = RetainShellsCount.Value; int retainCount = ShellsCountForFunctions.Value;
for (var i = 1; i < dysonSphere.layersIdBased.Length; i++) for (var i = 1; i < dysonSphere.layersIdBased.Length; i++)
{ {
var layer = dysonSphere.layersIdBased[i]; var layer = dysonSphere.layersIdBased[i];

View File

@@ -102,9 +102,9 @@ public static class UIConfigWindow
} }
} }
class RetainShellsCountMapper : MyWindow.RangeValueMapper<int> class ShellsCountMapper : MyWindow.RangeValueMapper<int>
{ {
public RetainShellsCountMapper() : base(1, 46) public ShellsCountMapper() : base(1, 139)
{ {
} }
@@ -115,7 +115,8 @@ public static class UIConfigWindow
< 4 => value, < 4 => value,
< 64 => value / 4 + 3, < 64 => value / 4 + 3,
< 256 => value / 16 + 15, < 256 => value / 16 + 15,
_ => value / 256 + 30, < 4096 => value / 64 + 27,
_ => value / 256 + 75,
}; };
} }
@@ -126,7 +127,8 @@ public static class UIConfigWindow
< 4 => index, < 4 => index,
< 19 => (index - 3) * 4, < 19 => (index - 3) * 4,
< 31 => (index - 15) * 16, < 31 => (index - 15) * 16,
_ => (index - 30) * 256, < 91 => (index - 27) * 64,
_ => (index - 75) * 256,
}; };
} }
} }
@@ -196,7 +198,6 @@ public static class UIConfigWindow
FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged += OnBeltSignalChanged; FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged += OnBeltSignalChanged;
wnd.OnFree += () => { FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged -= OnBeltSignalChanged; }; wnd.OnFree += () => { FactoryPatch.BeltSignalGeneratorEnabled.SettingChanged -= OnBeltSignalChanged; };
OnBeltSignalChanged(null, null); OnBeltSignalChanged(null, null);
void OnBeltSignalChanged(object o, EventArgs e) void OnBeltSignalChanged(object o, EventArgs e)
{ {
var on = FactoryPatch.BeltSignalGeneratorEnabled.Value; var on = FactoryPatch.BeltSignalGeneratorEnabled.Value;
@@ -290,18 +291,18 @@ public static class UIConfigWindow
{ {
slider.slider.enabled = DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.Value; slider.slider.enabled = DysonSpherePatch.UnlockMaxOrbitRadiusEnabled.Value;
} }
;
} }
x = 300f; x = 300f;
y = 10f; y = 10f;
wnd.AddButton(x, y, 300f, tab4, "Complete Dyson Sphere shells instantly", 16, "button-complete-dyson-sphere-shells-instantly", DysonSphereFunctions.CompleteShellsInstantly); wnd.AddButton(x, y, 300f, tab4, "Complete Dyson Sphere shells instantly", 16, "button-complete-dyson-sphere-shells-instantly", DysonSphereFunctions.CompleteShellsInstantly);
y += 36f; y += 36f;
wnd.AddButton(x, y, 300f, tab4, "Generate max production shell", 16, "button-generate-max-production-shell", DysonSphereFunctions.CreatePossibleFramesAndShells2);
y += 36f;
wnd.AddButton(x, y, 300f, tab4, "Generate tricky dyson shells", 16, "button-generate-tricky-dyson-shells", DysonSphereFunctions.CreatePossibleFramesAndShells3); wnd.AddButton(x, y, 300f, tab4, "Generate tricky dyson shells", 16, "button-generate-tricky-dyson-shells", DysonSphereFunctions.CreatePossibleFramesAndShells3);
y += 36f; y += 36f;
wnd.AddButton(x, y, 300f, tab4, "Remove low production dyson shells", 16, "button-remove-low-production-dyson-shells", () => DysonSphereFunctions.RemoveLowProductionShells()); wnd.AddButton(x, y, 300f, tab4, "Remove low production dyson shells", 16, "button-remove-low-production-dyson-shells", () => DysonSphereFunctions.RemoveLowProductionShells());
y += 30f; y += 30f;
wnd.AddSlider(x + 20f, y, tab4, DysonSphereFunctions.RetainShellsCount, new RetainShellsCountMapper()); wnd.AddSlider(x + 20f, y, tab4, DysonSphereFunctions.ShellsCountForFunctions, new ShellsCountMapper());
var tab5 = wnd.AddTab(_windowTrans, "Mecha/Combat"); var tab5 = wnd.AddTab(_windowTrans, "Mecha/Combat");
x = 0f; x = 0f;