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:
parent
fcb6cae3ee
commit
7ac7f99287
6 changed files with 165 additions and 30 deletions
|
|
@ -38,19 +38,42 @@ namespace RacesOfValheim
|
|||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static void SweepAura(Vector3 nest)
|
||||
{
|
||||
foreach (Beehive hive in Find(nest))
|
||||
List<Beehive> hives = Find(nest);
|
||||
int taken = 0;
|
||||
|
||||
foreach (Beehive hive in hives)
|
||||
{
|
||||
ZNetView nview = hive.GetComponent<ZNetView>();
|
||||
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<ZNetView>();
|
||||
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<Beehive> found = new List<Beehive>();
|
||||
|
||||
foreach (Collider collider in Physics.OverlapSphere(nest, SvermConfig.HiveAuraRadius))
|
||||
foreach (Collider collider in Physics.OverlapSphere(nest, SvermConfigManagement.AuraRadius))
|
||||
{
|
||||
if (collider == null) continue;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue