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;
|
||||
|
||||
|
|
|
|||
|
|
@ -351,7 +351,9 @@ namespace RacesOfValheim
|
|||
public static readonly float EyeGlowStrength = 0.22f;
|
||||
|
||||
// ─── The colony (stub - see SvermHive when that half is written) ─────
|
||||
/// <summary>Two nests per square mile. A square mile is 2.59 km2; the circle of equal area has r = 908 m.</summary>
|
||||
/// <summary>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.</summary>
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<int> CapFarmers;
|
||||
public static ConfigEntry<int> CapHaulers;
|
||||
public static ConfigEntry<int> CapBeehives;
|
||||
public static ConfigEntry<float> AuraRadiusValue;
|
||||
public static ConfigEntry<float> NestRadiusValue;
|
||||
public static ConfigEntry<int> NestMaxValue;
|
||||
|
||||
// ─── The nest and its mark ───────────────────────────────────────────
|
||||
public static ConfigEntry<float> 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;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static float AuraRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
float value = AuraRadiusValue?.Value ?? SvermConfig.HiveAuraRadius;
|
||||
return value > 0.01f ? value : SvermConfig.HiveAuraRadius;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}'.");
|
||||
}
|
||||
|
||||
/// <summary>Re-read the aura and cap the market to it. Safe to call any number of times.</summary>
|
||||
private static void RegisterMarketDensity()
|
||||
{
|
||||
PieceDensityLimit.Register(PieceName, SvermConfigManagement.AuraRadius, 1,
|
||||
"This hive already has a market.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The bench itself. Press E, the store opens on the nest it stands in.</summary>
|
||||
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) +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue