diff --git a/JotunnModStub/Butler/BoneServantAI.cs b/JotunnModStub/Butler/BoneServantAI.cs
index 922cb36..e5c1894 100644
--- a/JotunnModStub/Butler/BoneServantAI.cs
+++ b/JotunnModStub/Butler/BoneServantAI.cs
@@ -295,8 +295,14 @@ namespace RacesOfValheim
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
// four-state machine and the cook is a five-state one, and that is the whole of the
// simplification the split bought.
+ // REFUEL BEFORE LOAD, and that order is the whole of the blast furnace fix. FreeSlots goes
+ // back above zero the instant a furnace eats one ore, so while there is scrap left in any
+ // chest PlanLoad always has an answer and PlanFuel, sitting behind it, never got a turn -
+ // the furnace was topped up forever and burned down to nothing. Fuel cannot starve loading
+ // in return, because FuelWanted is zero for a station with no work: an empty furnace asks
+ // for no coal, gets filled, and only then becomes worth stoking.
Job job = m_family == ButlerFamily.Kitchen ? PlanRescue() : null;
- job = job ?? PlanCollect() ?? PlanLoad() ?? PlanFuel();
+ job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
{
@@ -449,7 +455,7 @@ namespace RacesOfValheim
}
///
- /// 3. LOAD. Urgency, then distance - and the urgency of a station with nothing wrong with it is
+ /// 4. LOAD. Urgency, then distance - and the urgency of a station with nothing wrong with it is
/// how long it has been waiting. A metre of walking is worth four seconds of a station standing
/// idle, so the far furnace wins eventually instead of never.
///
@@ -495,9 +501,20 @@ namespace RacesOfValheim
};
}
- /// 4. REFUEL. Only stations that actually have something to work on.
+ ///
+ /// 3. REFUEL. Only stations that actually have something to work on.
+ ///
+ /// Scored by the walk, the same way PlanLoad is, and for a reason that only appeared once this
+ /// moved up the list: taking the first station in scan order was harmless while refuelling was
+ /// the job of last resort, but ahead of loading it lets one furnace at the edge of the circle
+ /// hold the servant while a cold one two metres away waits.
+ ///
private Job PlanFuel()
{
+ Container bestChest = null;
+ string bestFuel = null;
+ float bestScore = float.MaxValue;
+
foreach (ButlerStation station in m_stations)
{
if (!station.Alive || IsPenalised(station.Id)) continue;
@@ -512,16 +529,24 @@ namespace RacesOfValheim
Container chest = FindChestWith(fuel);
if (chest == null) continue;
- return new Job
- {
- Kind = "fuel",
- Target = ZdoOf(chest),
- Point = chest.transform.position,
- Label = "Fetching " + fuel,
- };
+ float score = Vector3.Distance(transform.position, chest.transform.position) +
+ Vector3.Distance(chest.transform.position, station.Position);
+ if (score >= bestScore) continue;
+
+ bestScore = score;
+ bestChest = chest;
+ bestFuel = fuel;
}
- return null;
+ if (bestChest == null) return null;
+
+ return new Job
+ {
+ Kind = "fuel",
+ Target = ZdoOf(bestChest),
+ Point = bestChest.transform.position,
+ Label = "Fetching " + bestFuel,
+ };
}
/// Where the load in hand is going: on to its station, or back into a chest.
@@ -563,8 +588,31 @@ namespace RacesOfValheim
};
}
- // Every sealed chest is full. Beside the table it goes: a stalled chain is worse than a
- // tidy floor, and nothing may vanish (sec. 7.3).
+ // Every sealed chest is full - but a chest is not the only place a thing can go. A station
+ // that BURNS what is in hand is a destination too, and for the smith it is usually the
+ // right one: the charcoal kiln releases its whole batch in one go (verified in the IL -
+ // UpdateSmelter only calls SpawnProcessed once the ore queue empties), which is exactly the
+ // delivery a nearly full chest cannot absorb, and the coal it makes is what the furnace
+ // beside it is waiting for. Offering the load to a consumer before giving up is what turns
+ // "nowhere to put 20x Coal" into a full blast furnace.
+ //
+ // It comes AFTER the chest and not before, so a product still goes home to the chest that
+ // paid for it whenever there is room; this is the step before the floor, not instead of
+ // storing.
+ ButlerStation consumer = StationWanting();
+ if (consumer != null)
+ {
+ return new Job
+ {
+ Kind = "deposit_station",
+ Target = consumer.Id,
+ Point = consumer.Position,
+ Label = "Loading " + Describe(),
+ };
+ }
+
+ // Nothing will take it. Beside the table it goes: a stalled chain is worse than a tidy
+ // floor, and nothing may vanish (sec. 7.3).
return new Job
{
Kind = "drop",
@@ -574,6 +622,29 @@ namespace RacesOfValheim
};
}
+ /// The nearest station that will take something out of the payload, as material or as
+ /// fuel. No FreeSlots check, for the reason spelled out above the KeyTarget branch: fuel does
+ /// not go into a slot, and AcceptsAnything already asks the right question of both doors.
+ private ButlerStation StationWanting()
+ {
+ ButlerStation best = null;
+ float bestDistance = float.MaxValue;
+
+ foreach (ButlerStation station in m_stations)
+ {
+ if (!station.Alive || IsPenalised(station.Id)) continue;
+ if (!station.Operable || !AcceptsAnything(station)) continue;
+
+ float distance = Vector3.Distance(transform.position, station.Position);
+ if (distance >= bestDistance) continue;
+
+ bestDistance = distance;
+ best = station;
+ }
+
+ return best;
+ }
+
// ================================================================ execution
private void Execute(float dt)
@@ -691,23 +762,35 @@ namespace RacesOfValheim
/// At a station with something finished. Pull first, sweep second - and the sweep is the only
/// place the servant ever picks anything up off the ground, which is what keeps it from tidying
/// away things the player left lying about on purpose.
+ ///
+ /// THE ORDER IS THE POINT, and it used to be the other way round. Sweeping first meant every
+ /// visit collected what the LAST visit had thrown on the floor and then threw a fresh one down;
+ /// since Plan() hands the servant to PlanDelivery the moment it is carrying anything, it walked
+ /// off to the chest the instant the sweep landed and abandoned the item it had just pulled.
+ /// While a hearth kept working there was therefore always exactly one cooked meat lying on the
+ /// ground - the "loses one per batch, whether that is two or five" the testers reported.
+ ///
+ /// The loop is the other half of it. RPC_RemoveDoneItem empties ONE slot per call, so a hearth
+ /// with five done slots needs five calls; one per visit turned one batch into five round trips
+ /// to the chest. It runs against OutputPulls rather than against HasOutput alone because the
+ /// fermenter's Ready survives its own tap for the length of the animation.
///
private bool DoCollect()
{
ButlerStation station = StationById(m_job.Target);
if (station == null || !station.Alive) return false;
- int before = PayloadCount();
- SweepDrops(station.Position);
- bool swept = PayloadCount() > before;
-
bool pulled = false;
- if (station.HasOutput)
+ for (int i = 0; i < station.OutputPulls && station.HasOutput; i++)
{
station.PullOutput(transform.position);
pulled = true;
}
+ int before = PayloadCount();
+ SweepDrops(station.Position);
+ bool swept = PayloadCount() > before;
+
if (swept)
{
// The product belongs to whoever fed the station. If nothing was written there - the
diff --git a/JotunnModStub/Butler/ButlerStation.cs b/JotunnModStub/Butler/ButlerStation.cs
index 2b47de5..be76226 100644
--- a/JotunnModStub/Butler/ButlerStation.cs
+++ b/JotunnModStub/Butler/ButlerStation.cs
@@ -155,6 +155,17 @@ namespace RacesOfValheim
/// pickup routine will find them.
public abstract void PullOutput(Vector3 at);
+ ///
+ /// How many times PullOutput is worth calling in a single visit, which is not the same question
+ /// as how much is finished.
+ ///
+ /// One, everywhere except the hearth. The Fermenter is the reason this is not simply "keep
+ /// pulling while HasOutput": tapping does not clear Ready straight away - DelayedTap waits
+ /// m_tapDelay for the animation - so a loop on HasOutput would pull the same tap over and over
+ /// in one frame.
+ ///
+ public virtual int OutputPulls { get { return 1; } }
+
/// Seconds until something in here is ruined. float.MaxValue for the two families that
/// cannot spoil, which is what keeps the urgency comparison honest without special cases.
public virtual float SecondsToSpoil { get { return float.MaxValue; } }
@@ -394,9 +405,14 @@ namespace RacesOfValheim
public override bool HasOutput { get { return Vanilla.Call(Vanilla.CookHaveDone, m_cooking, false); } }
///
- /// ONE per done slot, and the 1 is not a stylistic choice. RPC_RemoveDoneItem spawns the
- /// item amount times PER SLOT (verified in the IL: the inner loop runs to the
- /// argument), so passing anything above 1 would not collect faster - it would print money.
+ /// ONE CALL, ONE SLOT - and the 1 is the count, not the slot.
+ ///
+ /// Read again off the IL after the cook was reported losing a meat per batch, because the
+ /// first reading of it was wrong in a way that mattered. RPC_RemoveDoneItem walks the slots,
+ /// finds the FIRST one that is Done, spawns its item amount times, clears that slot,
+ /// sends RPC_SetSlotVisual and RETURNS. It does not go on to the other slots. So the
+ /// argument is a multiplier - anything above 1 prints money - and a hearth with five cooked
+ /// slots needs five calls, which is what OutputPulls below is for.
///
public override void PullOutput(Vector3 at)
{
@@ -404,6 +420,10 @@ namespace RacesOfValheim
Nview.InvokeRPC("RPC_RemoveDoneItem", at, 1);
}
+ /// One call per slot, so a full hearth is emptied in one visit instead of one item
+ /// per errand. The loop that uses this stops on HasOutput anyway; this is only its bound.
+ public override int OutputPulls { get { return Mathf.Max(1, SlotCount); } }
+
///
/// The clock this whole feature exists for. Done at m_cookTime, Burnt at 2x - so what is
/// left is 2*cookTime - cookedTime, and a slot already Done is the urgent one because its
diff --git a/JotunnModStub/RaceClaws.cs b/JotunnModStub/RaceClaws.cs
index 5d0846d..3e3c540 100644
--- a/JotunnModStub/RaceClaws.cs
+++ b/JotunnModStub/RaceClaws.cs
@@ -636,10 +636,35 @@ namespace RacesOfValheim
// it is put back to full once rather than left as a stale figure in the save file.
if (claws.m_durability < claws.GetMaxDurability()) claws.m_durability = claws.GetMaxDurability();
- // Empty-handed means clawed. Anything else in the right hand wins until it is put away,
- // which is the whole compromise.
- ItemDrop.ItemData held = Traverse.Create((Humanoid)player).Field("m_rightItem").Value;
- if (held == null && !player.InAttack())
+ // Empty-handed means clawed. Anything the player is actually holding wins until it is
+ // put away, which is the whole compromise.
+ //
+ // BOTH HANDS, and asking only about the right one is what broke the bow. A bow is held
+ // in m_leftItem, so a bow-wielding player read as empty-handed here and got the claws
+ // forced into his hands - and Humanoid.EquipItem's OneHandedWeapon branch (read off the
+ // IL) does this before it puts anything in the right hand:
+ //
+ // UnequipItem(m_rightItem);
+ // if (m_leftItem != null && m_leftItem.m_shared.m_itemType != Shield)
+ // UnequipItem(m_leftItem);
+ //
+ // Everything but a shield is torn out of the left hand. So the archer's bow was pulled
+ // out from under him, up to twice a second - and not only on the throttled tick, because
+ // RaceClaws_UnequipItem_Patch calls Maintain from inside UnequipItem and EquipItem calls
+ // UnequipItem first, so drawing a bow started the fight immediately.
+ //
+ // Free is therefore defined as "nothing the claws would displace", which is that rule
+ // mirrored rather than a second guess at it: a shield stays because equipping the claws
+ // over a shield costs the player nothing.
+ Humanoid humanoid = player;
+ ItemDrop.ItemData right = Traverse.Create(humanoid).Field("m_rightItem").Value;
+ ItemDrop.ItemData left = Traverse.Create(humanoid).Field("m_leftItem").Value;
+
+ bool leftIsShield = left != null && left.m_shared != null &&
+ left.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Shield;
+ bool handsFree = right == null && (left == null || leftIsShield);
+
+ if (handsFree && !player.InAttack())
{
player.EquipItem(claws, false);
}
diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs
index 5710509..fcb3abc 100644
--- a/JotunnModStub/RaceCompendium.cs
+++ b/JotunnModStub/RaceCompendium.cs
@@ -184,13 +184,13 @@ namespace RacesOfValheim
}
else
{
- sb.AppendLine($"Brood Mound (Hammer): Your nest, and no more than two of them may stand within {SvermConfig.HiveDensityRadius:0} meters of each other. Press it, or the hive at its foot, to feed it a whole stack out of your pack: any food, any wood, any resin. Honey and royal jelly are medicine now and it will not take them.\n");
+ sb.AppendLine($"Brood Mound (Hammer): Your nest, and no more than {SvermConfigManagement.NestMax} of them may stand within {SvermConfigManagement.NestRadius:0} meters of each other. Press it, or the hive at its foot, to feed it a whole stack out of your pack: any food, any wood, any resin. Honey and royal jelly are medicine now and it will not take them.\n");
sb.AppendLine($"Digestion: what you feed it is not yours to spend yet. It seeps into the nest's bank at {SvermConfigManagement.DigestRate:0.#} a second, and only what has arrived can be spent.\n");
sb.AppendLine($"Brood Eggs: the nest lays one every {SvermConfig.EggInterval:0} seconds and holds {SvermConfig.EggCapBase + 1} of them at its first stage, one more at each stage after. Every troop costs an egg as well as biomass - the egg grows back, the biomass does not.\n");
- sb.AppendLine("Hive Market (Hammer): a counter raised within ten meters of a nest. Everything the colony buys is bought here, out of that nest's bank.\n");
+ sb.AppendLine($"Hive Market (Hammer): a counter raised within {SvermConfigManagement.AuraRadius:0} meters of a nest. Everything the colony buys is bought here, out of that nest's bank.\n");
sb.AppendLine($"Growth: {SvermHiveStage.NameOf(2)} {SvermHiveStage.PriceToLeave(1):0}, {SvermHiveStage.NameOf(3)} {SvermHiveStage.PriceToLeave(2):0}, {SvermHiveStage.NameOf(4)} {SvermHiveStage.PriceToLeave(3):0}. Each one costs that stage's whole tankful and opens the next rung of the roster.\n");
@@ -210,7 +210,7 @@ namespace RacesOfValheim
sb.AppendLine("Surrenal Glands 800 and Hyperplasia 1600: everything hatched after them is born with one star, then two.\n");
- sb.AppendLine($"The beehives: raise vanilla hives inside the nest's ten meters and the colony takes them over after a minute - twice the speed, three times the honey, and royal jelly instead once Yagluth is down. Press honey or royal jelly on one of your own insects to heal it: {SvermConfig.HoneyHealing:0} and {SvermConfig.RoyalJellyHealing:0}.\n");
+ sb.AppendLine($"The beehives: raise vanilla hives inside the nest's {SvermConfigManagement.AuraRadius:0} meters and the colony takes them over after a minute, up to {SvermConfigManagement.Beehives} of them per nest - twice the speed, three times the honey, and royal jelly instead once Yagluth is down. Press honey or royal jelly on one of your own insects to heal it: {SvermConfig.HoneyHealing:0} and {SvermConfig.RoyalJellyHealing:0}.\n");
}
knownTexts["Sverm Secrets"] = sb.ToString();
diff --git a/JotunnModStub/RaceInput.cs b/JotunnModStub/RaceInput.cs
index 04f8f08..02b3847 100644
--- a/JotunnModStub/RaceInput.cs
+++ b/JotunnModStub/RaceInput.cs
@@ -14,6 +14,14 @@ namespace RacesOfValheim
/// its own controls through Player.TakeInput, which reports false for exactly those states
/// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining
/// a parallel list of GUI checks that would drift as the game changes.
+ ///
+ /// ONE GUI THAT TakeInput DOES NOT COVER: the hammer's piece selection panel. Read off the IL,
+ /// TakeInput tests Chat, Console, TextInput, StoreGui, InventoryGui, Menu, TextViewer, the map,
+ /// free-fly and the barber - and nothing else. Vanilla does not need it there because build
+ /// input is handled separately in UpdatePlacement, but a mod ability reading the device
+ /// directly does: Skadi's cold spell is bound to middle mouse and kept casting while the build
+ /// menu was open. Hud.IsPieceSelectionVisible is static, public and null-safe on its own
+ /// instance, so it costs one call and no reflection.
///
public static class RaceInput
{
@@ -27,6 +35,9 @@ namespace RacesOfValheim
Player player = Player.m_localPlayer;
if (player == null) return false;
+ // Checked before TakeInput, so it holds even on the fail-open path below.
+ if (Hud.IsPieceSelectionVisible()) return false;
+
// Fail open: if a game update ever renames the method, abilities stay usable
// rather than silently going dead.
if (TakeInputMethod == null) return true;
diff --git a/JotunnModStub/Sverm/SvermBeehive.cs b/JotunnModStub/Sverm/SvermBeehive.cs
index bd0ad1e..975a540 100644
--- a/JotunnModStub/Sverm/SvermBeehive.cs
+++ b/JotunnModStub/Sverm/SvermBeehive.cs
@@ -38,19 +38,42 @@ namespace RacesOfValheim
///
/// Called by the nest, on a timer. Claims what is in range and ripens what has waited.
+ ///
+ /// TWO PASSES, AND THE CAP SITS BETWEEN THEM. "Beehives per Aura" was bound into the config
+ /// and then read by nobody: the number sat in the file describing a limit that did not
+ /// exist, and a player could raise thirty hives in one aura and get thirty workers. The
+ /// maintenance of hives already taken has to happen either way - Apply is what survives a
+ /// zone reload, so skipping it would quietly hand hives back at vanilla speed - which is
+ /// exactly why the count has to be finished before the first new one is considered. One
+ /// pass would let the order the physics query happens to return decide whether a hive
+ /// counts against the cap or is measured by it.
+ ///
+ /// LOWERING THE CAP NEVER UNTAKES ANYTHING. An infected hive is an egg the player has been
+ /// looking at and a worker that already exists; the cap governs what happens next, not what
+ /// has happened. Over the cap simply means nothing new is claimed until one goes.
///
public static void SweepAura(Vector3 nest)
{
- foreach (Beehive hive in Find(nest))
+ List hives = Find(nest);
+ int taken = 0;
+
+ foreach (Beehive hive in hives)
{
ZNetView nview = hive.GetComponent();
if (nview == null || !nview.IsValid()) continue;
+ if (!nview.GetZDO().GetBool(InfectedKey, false)) continue;
- if (nview.GetZDO().GetBool(InfectedKey, false))
- {
- Apply(hive, nview);
- continue;
- }
+ Apply(hive, nview);
+ taken++;
+ }
+
+ int cap = SvermConfigManagement.Beehives;
+
+ foreach (Beehive hive in hives)
+ {
+ ZNetView nview = hive.GetComponent();
+ if (nview == null || !nview.IsValid()) continue;
+ if (nview.GetZDO().GetBool(InfectedKey, false)) continue;
// First sighting starts the clock. Stored as world time rather than counted in a
// field, because a nest that unloads and comes back must not restart the minute.
@@ -63,10 +86,17 @@ namespace RacesOfValheim
if (ZNet.instance.GetTimeSeconds() - claimedAt < SvermConfig.BeehiveInfectionSeconds) continue;
+ // Ripe, and the colony may still be full. The cap is tested HERE and not at the top
+ // of the loop so the minute keeps running on a hive that does not fit today: when a
+ // taken hive is destroyed, the one that has been waiting longest is claimed on the
+ // very next sweep instead of starting its minute over.
+ if (taken >= cap) continue;
+
nview.GetZDO().Set(InfectedKey, true);
Apply(hive, nview);
+ taken++;
- Jotunn.Logger.LogInfo("[Sverm] A beehive has been taken over by the colony.");
+ Jotunn.Logger.LogInfo($"[Sverm] A beehive has been taken over by the colony ({taken} of {cap}).");
}
}
@@ -130,7 +160,7 @@ namespace RacesOfValheim
{
List found = new List();
- foreach (Collider collider in Physics.OverlapSphere(nest, SvermConfig.HiveAuraRadius))
+ foreach (Collider collider in Physics.OverlapSphere(nest, SvermConfigManagement.AuraRadius))
{
if (collider == null) continue;
diff --git a/JotunnModStub/Sverm/SvermConfig.cs b/JotunnModStub/Sverm/SvermConfig.cs
index 69e7a82..c96e988 100644
--- a/JotunnModStub/Sverm/SvermConfig.cs
+++ b/JotunnModStub/Sverm/SvermConfig.cs
@@ -351,7 +351,9 @@ namespace RacesOfValheim
public static readonly float EyeGlowStrength = 0.22f;
// ─── The colony (stub - see SvermHive when that half is written) ─────
- /// Two nests per square mile. A square mile is 2.59 km2; the circle of equal area has r = 908 m.
+ /// Two nests per square mile. A square mile is 2.59 km2; the circle of equal area
+ /// has r = 908 m. The DEFAULT pair only - both are bound in SvermConfigManagement, and
+ /// SvermHive re-registers its density limit when either moves.
public static readonly float HiveDensityRadius = 908f;
public const int HiveDensityMax = 2;
@@ -361,8 +363,8 @@ namespace RacesOfValheim
// ─── Colony caps ─────────────────────────────────────────────────────
// The DEFAULTS. What is actually enforced comes from SvermConfigManagement, which binds
// these into the .cfg so a machine that cannot carry nineteen creatures can say so without
- // a rebuild. Only the nest density stays out of reach - two per square mile is a rule
- // about the world, not a comfort setting.
+ // a rebuild. Nothing in this block is read directly by the game any more - the nest density
+ // above was the last exception and it is bound too now.
public const int CapBrood = 8;
public const int CapSeeker = 6;
public const int CapSoldier = 3;
diff --git a/JotunnModStub/Sverm/SvermConfigManagement.cs b/JotunnModStub/Sverm/SvermConfigManagement.cs
index 72a5051..ccc36e3 100644
--- a/JotunnModStub/Sverm/SvermConfigManagement.cs
+++ b/JotunnModStub/Sverm/SvermConfigManagement.cs
@@ -60,6 +60,9 @@ namespace RacesOfValheim
public static ConfigEntry CapFarmers;
public static ConfigEntry CapHaulers;
public static ConfigEntry CapBeehives;
+ public static ConfigEntry AuraRadiusValue;
+ public static ConfigEntry NestRadiusValue;
+ public static ConfigEntry NestMaxValue;
// ─── The nest and its mark ───────────────────────────────────────────
public static ConfigEntry WorkerChestRangeValue;
@@ -137,7 +140,7 @@ namespace RacesOfValheim
MarketSizeValue = config.Bind(nest, "Market Bench Size", SvermConfig.MarketSize,
"How big the Hive Market bench is, in metres. It is a building you raise inside a " +
- "hive's ten metres, not a part of the nest.");
+ "hive's aura, not a part of the nest - see 'Aura Radius' under Colony Caps.");
DigestRateValue = config.Bind(nest, "Digestion Rate", SvermConfig.BiomassDigestRate,
"How much biomass moves from digestion into the hive's spendable bank each second. " +
@@ -178,9 +181,29 @@ namespace RacesOfValheim
"nearby chests into the hive. Separate pool from the farmers.");
CapBeehives = config.Bind(caps, "Beehives per Aura", SvermConfig.HiveAuraBeehiveMax,
- "How many beehives may stand in one nest's ten metres. Every one of them ends up " +
- "infected and producing a worker, so this is the number that really decides how " +
- "busy a base gets.");
+ "How many beehives one nest will take over. Every taken hive ends up producing a " +
+ "worker, so this is the number that really decides how busy a base gets. Hives past " +
+ "the cap are left alone and stay the player's; 0 stops the takeover entirely. " +
+ "Lowering it never hands a hive BACK - what is already the colony's stays taken.");
+
+ AuraRadiusValue = config.Bind(caps, "Aura Radius", SvermConfig.HiveAuraRadius,
+ "Metres around a nest that count as its aura. It is one circle doing three jobs: " +
+ "which beehives get taken over, how far a Hive Market may stand from its nest, and " +
+ "how far a market looks to find one. Takes effect immediately - beehives that fall " +
+ "outside a shrunk aura simply stop being swept, but a market already built stays " +
+ "where it is.");
+
+ NestMaxValue = config.Bind(caps, "Nests per Radius", SvermConfig.HiveDensityMax,
+ "How many Brood Mounds may stand within 'Nest Spacing Radius' of each other. The " +
+ "default pair, over the default radius, is two nests per square mile. Minimum 1 - " +
+ "for practical purposes 'no limit' is a large number here, not zero. Only checked " +
+ "when a nest is PLACED: lowering it leaves nests already standing where they are.");
+
+ NestRadiusValue = config.Bind(caps, "Nest Spacing Radius", SvermConfig.HiveDensityRadius,
+ "Metres over which 'Nests per Radius' is counted. 908 m is not an arbitrary figure: " +
+ "it is the radius of a circle with the area of one square mile, which is how the " +
+ "rule was written down. Counted over ZDOs rather than loaded objects, so a nest on " +
+ "the far side of the world still counts.");
// FOUND IN PLAY: 180, the figure that fixed the flying Deathsquito, faces the Seeker
// Brute straight at the camera - its own forward already matches the player's, unlike
@@ -248,6 +271,46 @@ namespace RacesOfValheim
public static int Haulers => CapHaulers?.Value ?? SvermConfig.CapHaulers;
public static int Beehives => CapBeehives?.Value ?? SvermConfig.HiveAuraBeehiveMax;
+ ///
+ /// The aura, in metres. Clamped above zero because it is fed straight into an OverlapSphere
+ /// and into PieceDensityLimit.Register, which refuses a radius of zero and would leave the
+ /// market uncapped rather than infinitely capped - a typed 0 must not be the one value that
+ /// turns a limit off.
+ ///
+ public static float AuraRadius
+ {
+ get
+ {
+ float value = AuraRadiusValue?.Value ?? SvermConfig.HiveAuraRadius;
+ return value > 0.01f ? value : SvermConfig.HiveAuraRadius;
+ }
+ }
+
+ ///
+ /// How far apart nests must be spread, and how many fit. Clamped for the same reason
+ /// AuraRadius is, and it bites harder here: PieceDensityLimit.Register refuses a radius of
+ /// zero OR a maximum below one and logs a warning, and a refused limit is not a strict limit
+ /// - it is NO limit. Typing 0 to mean "no nests" would hand the player unlimited nests,
+ /// which is the exact opposite of what they asked for.
+ ///
+ public static float NestRadius
+ {
+ get
+ {
+ float value = NestRadiusValue?.Value ?? SvermConfig.HiveDensityRadius;
+ return value > 0.01f ? value : SvermConfig.HiveDensityRadius;
+ }
+ }
+
+ public static int NestMax
+ {
+ get
+ {
+ int value = NestMaxValue?.Value ?? SvermConfig.HiveDensityMax;
+ return value >= 1 ? value : 1;
+ }
+ }
+
public static float ChestRange => WorkerChestRangeValue?.Value ?? SvermConfig.WorkerChestRange;
public static bool WorkerDebug => WorkerDebugValue?.Value ?? false;
diff --git a/JotunnModStub/Sverm/SvermHive.cs b/JotunnModStub/Sverm/SvermHive.cs
index 59a3b89..f174aff 100644
--- a/JotunnModStub/Sverm/SvermHive.cs
+++ b/JotunnModStub/Sverm/SvermHive.cs
@@ -152,10 +152,22 @@ namespace RacesOfValheim
},
}));
- // Two per square mile, as before. The radius is 908 m because that is the circle of
+ // Two per square mile by default. The radius is 908 m because that is the circle of
// equal area, and PieceDensityLimit counts over ZDOs rather than loaded objects.
- PieceDensityLimit.Register(PieceName, SvermConfig.HiveDensityRadius, SvermConfig.HiveDensityMax,
- "There is already a hive holding this ground.");
+ //
+ // Both numbers are the player's now. Register takes a snapshot, so - exactly as the Hive
+ // Market does with the aura - the two entries are watched and the limit re-registered
+ // when either moves; Register replaces the entry rather than stacking a second one.
+ RegisterNestDensity();
+
+ if (SvermConfigManagement.NestRadiusValue != null)
+ {
+ SvermConfigManagement.NestRadiusValue.SettingChanged += (sender, args) => RegisterNestDensity();
+ }
+ if (SvermConfigManagement.NestMaxValue != null)
+ {
+ SvermConfigManagement.NestMaxValue.SettingChanged += (sender, args) => RegisterNestDensity();
+ }
// The gate. Race first, then the boss - two separate refusals, because "you are not a
// Sverm" and "you have not killed The Elder" are different problems and a player who
@@ -182,6 +194,13 @@ namespace RacesOfValheim
Jotunn.Logger.LogInfo($"[Sverm] Registered '{PieceName}' from '{sourcePrefab}'.");
}
+ /// Re-read how thinly nests must be spread. Safe to call any number of times.
+ private static void RegisterNestDensity()
+ {
+ PieceDensityLimit.Register(PieceName, SvermConfigManagement.NestRadius, SvermConfigManagement.NestMax,
+ "There is already a hive holding this ground.");
+ }
+
///
/// What the two mouths borrow their look from, best first. SCENERY ONLY.
///
@@ -444,7 +463,7 @@ namespace RacesOfValheim
// disappears is one the player has to notice twice before they believe it.
return $"{SvermHiveStage.NameOf(SvermHiveStage.Of(transform))}\n" +
SvermHiveReadout.Tank(transform) +
- $"Beehives {infected} taken of {beehives} in range\n" +
+ $"Beehives {infected} taken of {SvermConfigManagement.Beehives} allowed, {beehives} in range\n" +
"[$KEY_Use] Feed it a stack";
}
diff --git a/JotunnModStub/Sverm/SvermHiveStore.cs b/JotunnModStub/Sverm/SvermHiveStore.cs
index c4fd0d1..d194ad3 100644
--- a/JotunnModStub/Sverm/SvermHiveStore.cs
+++ b/JotunnModStub/Sverm/SvermHiveStore.cs
@@ -366,9 +366,18 @@ namespace RacesOfValheim
}));
// One counter to a nest. The radius is the nest's own aura, so "another market too close"
- // and "inside this nest's ten metres" are the same circle measured from opposite ends.
- PieceDensityLimit.Register(PieceName, SvermConfig.HiveAuraRadius, 1,
- "This hive already has a market.");
+ // and "inside this nest's aura" are the same circle measured from opposite ends.
+ //
+ // Register takes a SNAPSHOT of the radius, so the aura being configurable means this one
+ // has to be told when it changes - the gate below and the sweep read the live value on
+ // every call and need nothing. Re-registering is the documented way to do it: Register
+ // replaces the entry rather than stacking a second limit on the same piece.
+ RegisterMarketDensity();
+
+ if (SvermConfigManagement.AuraRadiusValue != null)
+ {
+ SvermConfigManagement.AuraRadiusValue.SettingChanged += (sender, args) => RegisterMarketDensity();
+ }
PieceDensityLimit.RegisterGate(PieceName, (player, position) =>
{
@@ -380,10 +389,10 @@ namespace RacesOfValheim
return false;
}
- if (SvermHive.NearestNest(position, SvermConfig.HiveAuraRadius) == null)
+ if (SvermHive.NearestNest(position, SvermConfigManagement.AuraRadius) == null)
{
player.Message(MessageHud.MessageType.Center,
- "A market has to stand within ten metres of a hive.");
+ $"A market has to stand within {SvermConfigManagement.AuraRadius:0} metres of a hive.");
return false;
}
@@ -392,12 +401,19 @@ namespace RacesOfValheim
Jotunn.Logger.LogInfo($"[Sverm] Registered '{PieceName}' from '{sourceName}'.");
}
+
+ /// Re-read the aura and cap the market to it. Safe to call any number of times.
+ private static void RegisterMarketDensity()
+ {
+ PieceDensityLimit.Register(PieceName, SvermConfigManagement.AuraRadius, 1,
+ "This hive already has a market.");
+ }
}
/// The bench itself. Press E, the store opens on the nest it stands in.
public class SvermHiveMarket : MonoBehaviour, Hoverable, Interactable
{
- private SvermHiveBehaviour Nest => SvermHive.NearestNest(transform.position, SvermConfig.HiveAuraRadius);
+ private SvermHiveBehaviour Nest => SvermHive.NearestNest(transform.position, SvermConfigManagement.AuraRadius);
public bool Interact(Humanoid user, bool hold, bool alt)
{
@@ -418,7 +434,8 @@ namespace RacesOfValheim
SvermHiveBehaviour nest = Nest;
if (nest == null)
{
- player.Message(MessageHud.MessageType.Center, "No hive within ten metres. This counter is dead.");
+ player.Message(MessageHud.MessageType.Center,
+ $"No hive within {SvermConfigManagement.AuraRadius:0} metres. This counter is dead.");
return true;
}
@@ -432,7 +449,11 @@ namespace RacesOfValheim
public string GetHoverText()
{
SvermHiveBehaviour nest = Nest;
- if (nest == null) return $"{SvermHiveMarketPiece.DisplayName}\nNo hive within ten metres.";
+ if (nest == null)
+ {
+ return $"{SvermHiveMarketPiece.DisplayName}\n" +
+ $"No hive within {SvermConfigManagement.AuraRadius:0} metres.";
+ }
return $"{SvermHiveMarketPiece.DisplayName}\n" +
SvermHiveReadout.Tank(nest.transform) +