feat(sverm): enforce the beehive cap, and put the aura and the nest limits in config

"Beehives per Aura" was bound into the config and then read by nobody.
SvermConfigManagement.Beehives had no callers and neither did the
constant behind it, so the entry described a limit that did not exist and
a player could raise thirty hives in one aura and get thirty workers.

SweepAura is two passes now, with the cap between them. The first applies
to hives already taken and counts them - that maintenance is not
skippable, it is what survives a zone reload - and only then are new
candidates considered. One pass would have let the order the physics
query happens to return decide whether a hive counted against the cap or
was measured by it. The minute keeps running on a hive that does not fit
today, so when a taken hive is destroyed the one that has waited longest
is claimed on the next sweep instead of starting over; lowering the cap
never hands a hive back.

Three limits are now the player's: Aura Radius, Nests per Radius and Nest
Spacing Radius. PieceDensityLimit.Register takes a snapshot of its
numbers, so the Hive Market and the Brood Mound both watch their entries
and re-register when one moves - Register replaces an entry rather than
stacking a second limit on the same piece.

All three are clamped, and the reason is not tidiness: Register REFUSES a
radius of zero or a maximum below one, and a refused limit is no limit at
all. A player typing 0 into "Nests per Radius" to mean "no nests" would
have been handed unlimited nests.

Every player-facing string that stated the old numbers now reads the live
ones - the two build refusals, the orphaned market's message and hover,
and the two Compendium lines. The nest's hover shows the cap next to the
count, so moving the knob has visible effect.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Ferdinando 2026-08-29 08:45:28 +02:00
commit 7ac7f99287
6 changed files with 165 additions and 30 deletions

View file

@ -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}'.");
}
/// <summary>Re-read how thinly nests must be spread. Safe to call any number of times.</summary>
private static void RegisterNestDensity()
{
PieceDensityLimit.Register(PieceName, SvermConfigManagement.NestRadius, SvermConfigManagement.NestMax,
"There is already a hive holding this ground.");
}
/// <summary>
/// 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" +
"[<color=yellow><b>$KEY_Use</b></color>] Feed it a stack";
}