This commit is contained in:
2025-09-17 15:20:42 +08:00
parent 0c118ca8a6
commit 40be0d2faf
4 changed files with 19 additions and 10 deletions

Binary file not shown.

View File

@@ -39,11 +39,12 @@
<li>ARA_MorphableResearchBench</li> <li>ARA_MorphableResearchBench</li>
</linkableBuildings> </linkableBuildings>
<maxDistance>80</maxDistance> <!-- 供能范围 --> <maxDistance>80</maxDistance> <!-- 供能范围 -->
<maxEfficiency>0.9</maxEfficiency>
</li> </li>
<!-- 自身的燃料库 --> <!-- 自身的燃料库 -->
<li Class="ArachnaeSwarm.CompProperties_RefuelableNutrition"> <li Class="ArachnaeSwarm.CompProperties_RefuelableNutrition">
<fuelCapacity>1000.0</fuelCapacity> <fuelCapacity>10000.0</fuelCapacity>
<fuelFilter> <fuelFilter>
<categories> <categories>
<li>Foods</li> <li>Foods</li>
@@ -418,8 +419,7 @@
<Flammability>0.5</Flammability> <Flammability>0.5</Flammability>
</statBases> </statBases>
<costList> <costList>
<Steel>150</Steel> <ARA_Carapace>50</ARA_Carapace>
<ComponentIndustrial>4</ComponentIndustrial>
</costList> </costList>
<altitudeLayer>Building</altitudeLayer> <altitudeLayer>Building</altitudeLayer>
<passability>PassThroughOnly</passability> <passability>PassThroughOnly</passability>
@@ -467,6 +467,8 @@
<li>ARA_BioforgeIncubator</li> <li>ARA_BioforgeIncubator</li>
<li>ARA_BioforgeIncubator_Thing</li> <li>ARA_BioforgeIncubator_Thing</li>
</linkableBuildings> </linkableBuildings>
<maxSimultaneous>10</maxSimultaneous>
<maxDistance>20</maxDistance>
<statOffsets> <statOffsets>
<NutrientTransmissionEfficiency>0.05</NutrientTransmissionEfficiency> <NutrientTransmissionEfficiency>0.05</NutrientTransmissionEfficiency>
<ARA_IncubationSpeedFactor>0.1</ARA_IncubationSpeedFactor> <ARA_IncubationSpeedFactor>0.1</ARA_IncubationSpeedFactor>

View File

@@ -9,6 +9,7 @@ namespace ArachnaeSwarm
public class CompNutrientProvider : CompFacility public class CompNutrientProvider : CompFacility
{ {
private CompRefuelableNutrition selfRefuelable; private CompRefuelableNutrition selfRefuelable;
private new CompProperties_NutrientProvider Props => (CompProperties_NutrientProvider)props;
public override void PostSpawnSetup(bool respawningAfterLoad) public override void PostSpawnSetup(bool respawningAfterLoad)
{ {
@@ -20,7 +21,7 @@ namespace ArachnaeSwarm
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, 0.1f); float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, Props.maxEfficiency);
sb.AppendLine("生物质传输效率".Translate() + ": " + efficiency.ToStringPercent()); sb.AppendLine("生物质传输效率".Translate() + ": " + efficiency.ToStringPercent());
sb.AppendLine("链接的建筑".Translate() + ":"); sb.AppendLine("链接的建筑".Translate() + ":");
@@ -48,15 +49,12 @@ namespace ArachnaeSwarm
public override void CompTick() public override void CompTick()
{ {
base.CompTick(); base.CompTick();
// Log.Message($"[NutrientProvider] CompTick called for {parent.Label}."); // This will be too spammy
if (!parent.IsHashIntervalTick(250)) if (!parent.IsHashIntervalTick(250))
{ {
return; return;
} }
Log.Message($"[NutrientProvider] Rare Tick Logic executing for {parent.Label}.");
if (selfRefuelable == null || !selfRefuelable.HasFuel) if (selfRefuelable == null || !selfRefuelable.HasFuel)
{ {
return; return;
@@ -73,12 +71,18 @@ namespace ArachnaeSwarm
var consumerComp = targetBuilding.Comp; var consumerComp = targetBuilding.Comp;
float desiredLevel = GetDesiredFuelLevel(consumerComp); float desiredLevel = GetDesiredFuelLevel(consumerComp);
float fuelNeeded = desiredLevel - consumerComp.Fuel; float fuelNeeded = desiredLevel - consumerComp.Fuel;
if (fuelNeeded < 0.1f)
{
return;
}
float fuelToTransfer = Mathf.Min(fuelNeeded, selfRefuelable.Fuel); float fuelToTransfer = Mathf.Min(fuelNeeded, selfRefuelable.Fuel);
float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, 0.1f); float efficiency = Mathf.Clamp(parent.GetStatValue(StatDef.Named("NutrientTransmissionEfficiency")), 0f, Props.maxEfficiency);
float finalCost = fuelToTransfer * (1 - efficiency); float finalCost = fuelToTransfer * (1 - efficiency);
Log.Message($"[NutrientProvider] Found target: {targetBuilding.Building.Label}. Fuel: {consumerComp.Fuel:F0}/{consumerComp.Props.fuelCapacity:F0}. Needs: {fuelNeeded:F2}. Transferring: {fuelToTransfer:F2}. Final cost: {finalCost:F2}"); // Log.Message($"[NutrientProvider] Found target: {targetBuilding.Building.Label}. Fuel: {consumerComp.Fuel:F0}/{consumerComp.Props.fuelCapacity:F0}. Needs: {fuelNeeded:F2}. Transferring: {fuelToTransfer:F2}. Final cost: {finalCost:F2}");
selfRefuelable.ConsumeFuel(finalCost); selfRefuelable.ConsumeFuel(finalCost);
consumerComp.ReceiveFuel(fuelToTransfer); consumerComp.ReceiveFuel(fuelToTransfer);
@@ -88,7 +92,7 @@ namespace ArachnaeSwarm
private bool NeedsFuel(CompRefuelableNutrition comp) private bool NeedsFuel(CompRefuelableNutrition comp)
{ {
if (comp == null) return false; if (comp == null) return false;
return comp.Fuel < GetDesiredFuelLevel(comp); return GetDesiredFuelLevel(comp) - comp.Fuel >= 0.1f;
} }
private float GetDesiredFuelLevel(CompRefuelableNutrition comp) private float GetDesiredFuelLevel(CompRefuelableNutrition comp)

View File

@@ -1,9 +1,12 @@
using RimWorld; using RimWorld;
using Verse;
namespace ArachnaeSwarm namespace ArachnaeSwarm
{ {
public class CompProperties_NutrientProvider : CompProperties_Facility public class CompProperties_NutrientProvider : CompProperties_Facility
{ {
public float maxEfficiency = 0.9f;
public CompProperties_NutrientProvider() public CompProperties_NutrientProvider()
{ {
compClass = typeof(CompNutrientProvider); compClass = typeof(CompNutrientProvider);