bugfix 06/10/26 + bone ship

This commit is contained in:
Ferdinando 2026-10-06 11:36:18 +02:00
commit 553303d0fd
27 changed files with 3206 additions and 226 deletions

View file

@ -143,10 +143,22 @@ namespace RacesOfValheim
return Mathf.Clamp(nview.GetZDO().GetInt(SlotKey, 0), 0, SvermConfigManagement.BlisterTick);
}
/// <summary>
/// How many slots this nest may own: the configured cap, and never more than the nest's
/// clutch holds at its stage (five plus the stage). A slot is an egg that never comes back,
/// so the clutch is the honest ceiling - the flat cap alone let a nest at its first stage
/// keep ten ticks on a clutch of six.
/// </summary>
public static int SlotCap(Transform nest)
{
return Mathf.Min(SvermConfigManagement.BlisterTick, SvermBroodEggs.Cap(nest));
}
public static void BuySlot(Transform nest)
{
ZNetView nview = nest != null ? nest.GetComponent<ZNetView>() : null;
if (nview == null || !nview.IsValid()) return;
if (SlotsOf(nest) >= SlotCap(nest)) return;
if (!nview.IsOwner()) nview.ClaimOwnership();
nview.GetZDO().Set(SlotKey, SlotsOf(nest) + 1);

View file

@ -100,7 +100,7 @@ namespace RacesOfValheim
Refusal = hive =>
{
int slots = SvermBlisterTick.SlotsOf(hive.transform);
if (slots >= SvermConfigManagement.BlisterTick)
if (slots >= SvermBlisterTick.SlotCap(hive.transform))
{
return ModText.Get("rov_sverm_refusal_keeps", slots);
}
@ -118,6 +118,12 @@ namespace RacesOfValheim
return;
}
if (SvermBlisterTick.SlotsOf(hive.transform) >= SvermBlisterTick.SlotCap(hive.transform))
{
SvermBiomass.Refund(hive.transform, SvermConfig.TickPrice);
return;
}
SvermBlisterTick.BuySlot(hive.transform);
SvermBlisterTick.Hatch(hive);
},

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text;
using HarmonyLib;
using Jotunn.Managers;
using UnityEngine;
@ -79,6 +80,14 @@ namespace RacesOfValheim
ai.m_afraidOfFire = false;
}
// The troops' fighting bounds (SvermConfig.TroopAlertRange). The Seeker's own are 9999.
MonsterAI monster = prefab.GetComponent<MonsterAI>();
if (monster != null)
{
monster.m_alertRange = SvermConfig.TroopAlertRange;
monster.m_maxChaseDistance = SvermConfig.TroopAlertRange;
}
prefab.AddComponent<SvermWorkerBehaviour>();
// The Bone Smith's brain, whole: the Forge family of stations, fed from chests that hold
@ -214,6 +223,13 @@ namespace RacesOfValheim
/// <summary>How far a worker that has no nest on its ZDO looks for one to adopt.</summary>
private const float AdoptRange = 40f;
/// <summary>Further out than this a worker has been carried off, not sent: it is put back.
/// Also what brings home the ones the old build already let wander.</summary>
private const float WorkerHardLeash = 60f;
private static readonly System.Reflection.FieldInfo SpawnPointField =
AccessTools.Field(typeof(BaseAI), "m_spawnPoint");
private Character m_character;
private MonsterAI m_ai;
private ZNetView m_nview;
@ -282,6 +298,46 @@ namespace RacesOfValheim
float edge = SvermBrood.RingRadius(nest);
m_smith.m_homeDistance = edge;
m_smith.m_radiusBonus = edge;
Leash(nest.transform.position);
}
/// <summary>
/// Keeps a fight inside the nest's own ground. The smith's brain hands the tick to vanilla
/// while there is a fight, and vanilla measures how far it may chase from m_spawnPoint - the
/// place the worker happened to be born, never the nest - with a Seeker's range on top, which
/// is effectively unlimited. A worker that picked a target kept following it across the map.
///
/// The same three things the Skadi golem does: pin the point vanilla measures from, drop a
/// target that is outside the circle, and as a failsafe put back one that is far out.
/// </summary>
private void Leash(Vector3 home)
{
if (m_ai == null) return;
if (SpawnPointField != null) SpawnPointField.SetValue(m_ai, home);
float distance = Vector3.Distance(transform.position, home);
Character target = m_ai.GetTargetCreature();
bool targetOutside = target != null &&
Vector3.Distance(target.transform.position, home) > SvermConfig.TroopAlertRange;
if (distance > SvermConfig.TroopAlertRange || targetOutside)
{
Traverse traverse = Traverse.Create(m_ai);
traverse.Field("m_targetCreature").SetValue(null);
traverse.Field("m_targetStatic").SetValue(null);
}
if (distance > WorkerHardLeash)
{
Vector2 offset = Random.insideUnitCircle * 3f;
transform.position = home + new Vector3(offset.x, 0.5f, offset.y);
Rigidbody body = GetComponent<Rigidbody>();
if (body != null) body.linearVelocity = Vector3.zero;
}
}
/// <summary>