RacesOfValheim/JotunnModStub/Sverm/SvermConfigManagement.cs
2026-09-10 19:14:05 +02:00

360 lines
23 KiB
C#

using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// The BepInEx-configurable slice of the Sverm's numbers, bound as ConfigEntry so they can be
/// retuned without a rebuild - see CONFIGURATION-MANAGER-HOWTO.md. Bound once, from
/// RacesOfValheim.Awake().
///
/// Configuration Manager is a convenience, not a requirement: these land in
/// BepInEx/config/com.nandor.racesofvalheim.cfg as plain text and can be edited with a text
/// editor and picked up on the next launch.
///
/// WHAT IS IN HERE AND WHAT IS NOT, on the same boundary DvergarConfigManagement draws:
/// SvermConfig keeps the identity constants that must never change once a character exists
/// (RaceId, status effect names) and the per-tier tables. What lives here is the handful of
/// numbers that can only be judged by looking at them on screen - where the claws sit on the
/// hand, how wide the wings open - because those are guesses until someone sees them, and a
/// guess that needs a rebuild to correct is a guess that gets corrected slowly.
/// </summary>
public static class SvermConfigManagement
{
// No claw entries. They were here for one build, while the claws were a model bolted to
// the hand bones and their angle was a guess only an eye could settle. They are a real
// equipped item now (SvermClawSlot), so the game's own attach point decides where they sit
// and there is nothing left to tune.
// ─── Dorsal spines ───────────────────────────────────────────────────
public static ConfigEntry<float> SpineSizeSmall;
public static ConfigEntry<float> SpineSizeFull;
public static ConfigEntry<string> SpineBoneName;
public static ConfigEntry<float> SpineRotationX;
public static ConfigEntry<float> SpineRotationY;
public static ConfigEntry<float> SpineRotationZ;
// ─── Emberform ───────────────────────────────────────────────────────
public static ConfigEntry<float> EmberGlowStrength;
// ─── Keybinds ────────────────────────────────────────────────────────
public static ConfigEntry<KeyboardShortcut> RavagerKey;
// ─── Ravager Strain, the model ───────────────────────────────────────
public static ConfigEntry<float> RavagerScaleMultiplier;
public static ConfigEntry<float> RavagerYawDegrees;
public static ConfigEntry<float> RavagerAttackOffsetValue;
// ─── Colony caps ─────────────────────────────────────────────────────
// Every ceiling on how many things the colony can have alive at once, in one section, so
// the "is this too many creatures for my machine" question has exactly one place to be
// answered - and can be answered without a rebuild.
//
// The nest density limit is deliberately NOT here. Two per square mile is a rule about
// what the world may look like rather than a comfort setting, and PieceDensityLimit reads
// it once when the piece registers.
public static ConfigEntry<int> CapBrood;
public static ConfigEntry<int> CapSeeker;
public static ConfigEntry<int> CapSoldier;
public static ConfigEntry<int> CapGjall;
public static ConfigEntry<int> CapBlisterTick;
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;
public static ConfigEntry<bool> WorkerDebugValue;
public static ConfigEntry<float> HiveScaleValue;
public static ConfigEntry<float> EggSizeValue;
public static ConfigEntry<float> EggHeightValue;
public static ConfigEntry<float> DigestRateValue;
public static ConfigEntry<float> StomachSizeValue;
public static ConfigEntry<float> StomachHeightValue;
public static ConfigEntry<float> MarketSizeValue;
public static ConfigEntry<float> StageGrowthValue;
public static ConfigEntry<float> NestVfxScaleValue;
public static ConfigEntry<float> BeehiveVfxScaleValue;
public static void Bind(ConfigFile config)
{
const string spines = "Sverm - Dorsal Spines";
const string ember = "Sverm - Emberform";
const string keybinds = "Sverm - Keybinds";
// G, like every other first transformation in the mod - the Aswid's bat, the Fenrir's
// wolf, the Dvergar's ping. A character only ever has one race, so they never collide.
RavagerKey = config.Bind(keybinds, "Ravager Strain", new KeyboardShortcut(UnityEngine.KeyCode.G),
"Turns into a Seeker Brute, and back. Unlocked at Yagluth.");
const string ravager = "Sverm - Ravager Strain";
RavagerScaleMultiplier = config.Bind(ravager, "Scale", 1f,
"Multiplies the Seeker Brute model's OWN authored scale. 1 means 'the full size " +
"the game draws one, bulk and all' - the form is meant to be worn at the " +
"creature's own size, not shrunk to fit.");
const string nest = "Sverm - Nest";
HiveScaleValue = config.Bind(nest, "Nest Scale", SvermConfig.HiveScale,
"How big the nest is. Only affects nests placed AFTER the change - the ones already " +
"standing keep the size they were built at, like every other building.");
EggSizeValue = config.Bind(nest, "Infection Egg Size", SvermConfig.HiveEggSize,
"How big the egg on a taken beehive is, in metres. The first pass used 0.35 and it " +
"was invisible in play.");
EggHeightValue = config.Bind(nest, "Infection Egg Height", SvermConfig.HiveEggHeight,
"How far above the beehive's own origin the egg sits, in metres. Too high and it " +
"floats clear of the roof; too low and it sinks into the mesh.");
// The two hives you press. Sizes are also how wide the sphere you point at is, so these
// decide how easy each mouth is to hit as much as how it looks. Read once, when the
// piece is registered: a change here shows up on the next launch, not on nests already
// standing.
StomachSizeValue = config.Bind(nest, "Stomach Size", SvermConfig.StomachSize,
"How big the hive at the foot of the nest is, in metres. It is the one you feed: " +
"press E on it and a whole stack goes in.");
StomachHeightValue = config.Bind(nest, "Stomach Height", SvermConfig.StomachHeight,
"How far up the trunk the stomach sits, in metres. Zero puts it on the ground.");
// NOT "Market Size" - that key already exists in everyone's .cfg holding the size of the
// mouth that used to hang on the trunk, and a key that is read back from a file laughs
// at a changed default. The market is a building of its own now and this is its scale,
// so it gets a name of its own too; the two old lines are orphans and are ignored.
StageGrowthValue = config.Bind(nest, "Growth At Last Stage", SvermConfig.HiveStageGrowth,
"How big a Hive Citadel is compared to the Brood Mound it started as, with the two " +
"middle stages spread evenly between. Applies to nests already standing, since it " +
"is worked out from the stage rather than baked in at placement.");
NestVfxScaleValue = config.Bind(nest, "Nest Swarm Scale", SvermConfig.NestVfxScale,
"How big the cloud of flies over the nest is, and the green reek it gives off while " +
"it is digesting. The reek only shows when there is something going down.");
BeehiveVfxScaleValue = config.Bind(nest, "Beehive Swarm Scale", SvermConfig.BeehiveVfxScale,
"The same two marks on a taken beehive, which wants a smaller cloud than the nest. " +
"Its gas shows when the hive is full of honey.");
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 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. " +
"What you sell the hive is not spendable until it has gone down. At the default a " +
"full stage-one tank takes a little over three minutes. Measured against the world " +
"clock, so a hive nobody is watching digests at the same speed.");
const string workers = "Sverm - Workers";
WorkerChestRangeValue = config.Bind(workers, "Chest Range", SvermConfig.WorkerChestRange,
"How far from the nest or the beehive a worker will look for a chest, in metres. " +
"Three is the design figure; widen it if your storage will not fit that close.");
WorkerDebugValue = config.Bind(workers, "Log Rounds", false,
"Writes a line to the log when a worker finishes a round and found nothing to do. " +
"Off by default because a worker works every few seconds and would bury the log.");
const string caps = "Sverm - Colony Caps";
CapBrood = config.Bind(caps, "Brood", SvermConfig.CapBrood,
"How many Seeker Brood the colony can keep alive at once.");
CapSeeker = config.Bind(caps, "Seeker", SvermConfig.CapSeeker,
"How many Seekers the colony can keep alive at once.");
CapSoldier = config.Bind(caps, "Soldier", SvermConfig.CapSoldier,
"How many Seeker Soldiers the colony can keep alive at once.");
CapGjall = config.Bind(caps, "Gjall", SvermConfig.CapGjall,
"How many Gjall the colony can keep alive at once.");
CapBlisterTick = config.Bind(caps, "Blister Ticks", SvermConfig.CapBlisterTick,
"How many bomb ticks the colony can keep alive at once. They respawn for free, so " +
"this number is also how many explosions are in the air at any moment.");
CapFarmers = config.Bind(caps, "Worker - Farmers", SvermConfig.CapFarmers,
"Seeker Workers produced by infected beehives, the ones that plant and harvest. " +
"Separate pool from the haulers.");
CapHaulers = config.Bind(caps, "Worker - Haulers", SvermConfig.CapHaulers,
"Seeker Workers produced by the nest after Bonemass, the ones that carry food from " +
"nearby chests into the hive. Separate pool from the farmers.");
CapBeehives = config.Bind(caps, "Beehives per Aura", SvermConfig.HiveAuraBeehiveMax,
"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
// the Deathsquito's. Different source rig, different answer; 0 is correct here.
RavagerYawDegrees = config.Bind(ravager, "Yaw", 0f,
"Turns the model on the vertical axis, in degrees. 0 is correct for the Seeker " +
"Brute; try 180 (or 90 / -90) if a future model swap ends up facing the wrong way.");
// FOUND IN PLAY: the hit itself lands where the PLAYER'S own body is, at the Brute's
// native scale (RavagerScale) the visible mouth/claws sit well forward of that - so
// the swing visibly connects a metre or more short of where the model appears to
// bite. Attack.m_attackOffset pushes the hit-detection origin forward from the
// player before m_attackRange is measured out from it; 1.5 is a first guess sized
// against the model's own scale, not a verified figure, so it lives here to be
// walked in by eye rather than baked into SvermConfig as if it were.
RavagerAttackOffsetValue = config.Bind(ravager, "Attack Reach Offset", 1.5f,
"How far forward of the player, in metres, the Brute's attacks are measured from. " +
"Raise it if a swing visibly connects short of the model's mouth/claws; lower it " +
"if it connects well past them.");
EmberGlowStrength = config.Bind(ember, "Glow Strength", SvermConfig.EmberGlowStrength,
"How hot the chitin burns at Fader. This multiplies an HDR colour and it is applied " +
"to the chest, the legs and the helmet at once, so it goes a very long way. Settled " +
"in game at 0.0625 after 1.0 blinded and 0.25 was still too bright. Above the bloom " +
"threshold more brightness buys a bigger white area and less red, so tune downward.");
SpineSizeSmall = config.Bind(spines, "Size Vestigial", SvermConfig.SpineSizeSmall,
"How tall the dorsal spines stand, in metres, from Moder to the Queen.");
SpineSizeFull = config.Bind(spines, "Size Full", SvermConfig.SpineSizeFull,
"How tall they stand from the Queen on.");
SpineBoneName = config.Bind(spines, "Bone", SvermConfig.SpineBoneName,
"Which bone the spines ride. This bone and no other - there is no fallback, so a " +
"name that is not in the rig means no crest at all. Leave it blank to use " +
"Spine2.");
// Spine3 was the shipped default and is not a bone this rig has, so a .cfg still holding it
// has never shown a crest. BepInEx keeps the value in the file over a changed default, so
// without this the fix would only ever reach fresh installs. Nobody can have picked Spine3
// on purpose and seen it work, which is what makes overwriting it safe.
if (string.Equals(SpineBoneName.Value?.Trim(), "Spine3", System.StringComparison.OrdinalIgnoreCase))
{
SpineBoneName.Value = SvermConfig.SpineBoneName;
}
// Defaults are the values found in game with the crest on screen, not zeroes: changing
// nothing here now reproduces the placement that was actually approved.
SpineRotationX = config.Bind(spines, "Rotation X", SvermConfig.SpineRotationX, "Pitch of the spines, in degrees.");
SpineRotationY = config.Bind(spines, "Rotation Y", SvermConfig.SpineRotationY, "Yaw of the spines, in degrees.");
SpineRotationZ = config.Bind(spines, "Rotation Z", SvermConfig.SpineRotationZ, "Roll of the spines, in degrees.");
}
// ─── Live reads ──────────────────────────────────────────────────────
// Null-guarded so the placement code works whether or not Bind has run - the main-menu
// character preview can build a body before Awake has finished on a slow load.
public static UnityEngine.Quaternion SpineRotation()
{
return UnityEngine.Quaternion.Euler(
SpineRotationX?.Value ?? SvermConfig.SpineRotationX,
SpineRotationY?.Value ?? SvermConfig.SpineRotationY,
SpineRotationZ?.Value ?? SvermConfig.SpineRotationZ);
}
public static float EmberStrength => EmberGlowStrength?.Value ?? SvermConfig.EmberGlowStrength;
public static int Brood => CapBrood?.Value ?? SvermConfig.CapBrood;
public static int Seeker => CapSeeker?.Value ?? SvermConfig.CapSeeker;
public static int Soldier => CapSoldier?.Value ?? SvermConfig.CapSoldier;
public static int Gjall => CapGjall?.Value ?? SvermConfig.CapGjall;
public static int BlisterTick => CapBlisterTick?.Value ?? SvermConfig.CapBlisterTick;
public static int Farmers => CapFarmers?.Value ?? SvermConfig.CapFarmers;
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;
public static float HiveScale => HiveScaleValue?.Value ?? SvermConfig.HiveScale;
public static float EggSize => EggSizeValue?.Value ?? SvermConfig.HiveEggSize;
public static float EggHeight => EggHeightValue?.Value ?? SvermConfig.HiveEggHeight;
public static float DigestRate => DigestRateValue?.Value ?? SvermConfig.BiomassDigestRate;
public static float StomachSize => StomachSizeValue?.Value ?? SvermConfig.StomachSize;
public static float StomachHeight => StomachHeightValue?.Value ?? SvermConfig.StomachHeight;
public static float MarketSize => MarketSizeValue?.Value ?? SvermConfig.MarketSize;
public static float StageGrowth => StageGrowthValue?.Value ?? SvermConfig.HiveStageGrowth;
public static float NestVfxScale => NestVfxScaleValue?.Value ?? SvermConfig.NestVfxScale;
public static float BeehiveVfxScale => BeehiveVfxScaleValue?.Value ?? SvermConfig.BeehiveVfxScale;
public static float RavagerScale => RavagerScaleMultiplier?.Value ?? 1f;
public static float RavagerYaw => RavagerYawDegrees?.Value ?? 0f;
public static float RavagerAttackOffset => RavagerAttackOffsetValue?.Value ?? 1.5f;
public static float SizeSmall => SpineSizeSmall?.Value ?? SvermConfig.SpineSizeSmall;
public static float SizeFull => SpineSizeFull?.Value ?? SvermConfig.SpineSizeFull;
/// <summary>
/// The bone name, never blank.
///
/// An empty string is not "no preference": FindBone's loose match asks whether a bone's
/// name CONTAINS the wanted string, and every string contains the empty one - so a blank
/// entry silently mounted the crest on the first bone of the armature. Clearing the field
/// while experimenting is an obvious thing to do, so it has to mean "the default".
/// </summary>
public static string Bone
{
get
{
string configured = SpineBoneName?.Value;
return string.IsNullOrWhiteSpace(configured) ? SvermConfig.SpineBoneName : configured;
}
}
}
}