From 9a3ab78666a1c20c49c57344dc406490f764543a Mon Sep 17 00:00:00 2001 From: Ferdinando Date: Sat, 3 Oct 2026 08:11:05 +0200 Subject: [PATCH] chore(release): v1.5.4 - Sverm troops keep their own place around the player and the boat Co-Authored-By: Claude Sonnet 5.5 --- JotunnModStub/Package/manifest.json | 2 +- JotunnModStub/RacesOfValheim.cs | 2 +- JotunnModStub/Sverm/SvermConfig.cs | 20 ++++ JotunnModStub/Sverm/SvermTroopFollow.cs | 121 ++++++++++++++++++++++++ README.md | 8 ++ manifest.json | 2 +- 6 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 JotunnModStub/Sverm/SvermTroopFollow.cs diff --git a/JotunnModStub/Package/manifest.json b/JotunnModStub/Package/manifest.json index ac2c5e8..d5f4e66 100644 --- a/JotunnModStub/Package/manifest.json +++ b/JotunnModStub/Package/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.", - "version_number": "1.5.3", + "version_number": "1.5.4", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333", diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 79703b3..f6ff75c 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -15,7 +15,7 @@ namespace RacesOfValheim { public const string PluginGUID = "com.nandor.racesofvalheim"; public const string PluginName = "Races Of Valheim"; - public const string PluginVersion = "1.5.3"; + public const string PluginVersion = "1.5.4"; private readonly Harmony harmony = new Harmony(PluginGUID); diff --git a/JotunnModStub/Sverm/SvermConfig.cs b/JotunnModStub/Sverm/SvermConfig.cs index 0a341ca..70b1ece 100644 --- a/JotunnModStub/Sverm/SvermConfig.cs +++ b/JotunnModStub/Sverm/SvermConfig.cs @@ -523,6 +523,26 @@ namespace RacesOfValheim /// public static readonly float TroopAlertRange = 25f; + /// + /// How far from its player a following troop stands, and how far it may fall behind before it + /// walks back to its place. Vanilla BaseAI.Follow sends every follower to the player's exact + /// position and stops it at three metres, so a squad piled onto one point, shoved each other + /// and shoved the player. See SvermTroopFollow. + /// + public static readonly float TroopFollowRadius = 4f; + + /// How far past its place a troop may drift before it moves again - the hysteresis + /// that keeps a squad from jittering. + public static readonly float TroopFollowSlack = 3f; + + /// How far from a boat's hull a following troop keeps, measured off the hull's + /// bounds. Close enough to be a bodyguard, far enough not to push the ship around. + public static readonly float TroopShipDistance = 5f; + + /// Past this many metres from its player a following troop gives up the walk and + /// goes home to its nest. + public static readonly float TroopFollowGiveUp = 30f; + /// How long a troop outlives the nest that hatched it, in seconds. public static readonly float TroopWitherSeconds = 60f; diff --git a/JotunnModStub/Sverm/SvermTroopFollow.cs b/JotunnModStub/Sverm/SvermTroopFollow.cs new file mode 100644 index 0000000..f7d0ab5 --- /dev/null +++ b/JotunnModStub/Sverm/SvermTroopFollow.cs @@ -0,0 +1,121 @@ +using System.Runtime.CompilerServices; +using HarmonyLib; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// How a Sverm troop walks beside its player. + /// + /// Vanilla BaseAI.Follow (read off the IL) sends the follower to the player's exact position, + /// runs it past ten metres and stops it inside three. Three troops therefore converged on one + /// point, pushed each other and pushed the player - into water, in one report - and on a boat + /// the player's position is on the deck, so they drove into the hull and spun the ship. + /// + /// Replaced for Sverm troops only (a RaisedThrall that answers to the Sverm race). Thralls, + /// Aswid's and the skeletons keep the vanilla walk. + /// + /// - Each troop has its own place: a fixed bearing off the player's back, taken from its ZDO id, + /// so the squad fans out instead of stacking. + /// - It walks to that place only when it has drifted TroopFollowSlack metres off it, and stops + /// within a metre and a half, so it stands still instead of shuffling. + /// - With the player on a ship, the places lie on a ring around the hull, TroopShipDistance + /// metres past its bounds. + /// - Further than TroopFollowGiveUp from the player, it stops following and goes home. + /// + public static class SvermTroopFollow + { + private const float ArriveDistance = 1.5f; + private const float RunDistance = 8f; + + private static readonly System.Reflection.MethodInfo MoveToMethod = + AccessTools.Method(typeof(BaseAI), "MoveTo", new[] { typeof(float), typeof(Vector3), typeof(float), typeof(bool) }); + + private class State { public bool Moving; } + + private static readonly ConditionalWeakTable States = new ConditionalWeakTable(); + + [HarmonyPatch(typeof(BaseAI), "Follow")] + public static class Sverm_TroopFollow_Patch + { + /// False replaces vanilla, true leaves it alone. + public static bool Prefix(BaseAI __instance, GameObject go, float dt) + { + if (go == null) return true; + + RaisedThrall thrall = __instance.GetComponent(); + if (thrall == null || thrall.m_commandingRace != SvermConfig.RaceId) return true; + + Player player = go.GetComponent(); + if (player == null) return true; + + Vector3 here = __instance.transform.position; + Vector3 playerPos = player.transform.position; + + if (Flat(playerPos - here).magnitude > SvermConfig.TroopFollowGiveUp) + { + // Stands it down and sends it to its nest, exactly as the command would. + thrall.SetFollowing(player, false, announce: false); + return false; + } + + Vector3 place = PlaceFor(__instance, player, playerPos); + float toPlace = Flat(place - here).magnitude; + + State state = States.GetOrCreateValue(__instance); + if (state.Moving ? toPlace < ArriveDistance : toPlace < SvermConfig.TroopFollowSlack) state.Moving = false; + else state.Moving = true; + + if (!state.Moving) + { + __instance.StopMoving(); + return false; + } + + // Protected on BaseAI, so reached the way RaisedThrall reaches SetPatrolPoint. If it + // ever goes missing, vanilla's walk is the fallback rather than a frozen squad. + if (MoveToMethod == null) return true; + + MoveToMethod.Invoke(__instance, new object[] { dt, place, 0f, toPlace > RunDistance }); + return false; + } + } + + /// Where this troop should stand: behind the player, or round the player's ship. + private static Vector3 PlaceFor(BaseAI ai, Player player, Vector3 playerPos) + { + ZNetView nview = ai.GetComponent(); + int hash = nview != null && nview.IsValid() ? nview.GetZDO().m_uid.GetHashCode() : ai.GetInstanceID(); + + // Seven bearings, twenty degrees apart, fanned across the back half. Troops hatched + // together draw different ZDO ids, so they mostly land on different bearings. + float bearing = 180f + (((hash % 7) + 7) % 7 - 3) * 20f; + + Ship ship = player.GetControlledShip(); + if (ship == null) ship = player.GetStandingOnShip(); + + if (ship != null && ship.m_floatCollider != null) + { + Bounds bounds = ship.m_floatCollider.bounds; + float reach = Mathf.Max(bounds.extents.x, bounds.extents.z) + SvermConfig.TroopShipDistance; + return Ring(bounds.center, ship.transform.eulerAngles.y, bearing, reach, playerPos.y); + } + + return Ring(playerPos, player.transform.eulerAngles.y, bearing, SvermConfig.TroopFollowRadius, playerPos.y); + } + + private static Vector3 Ring(Vector3 center, float facingDegrees, float bearingDegrees, float radius, float y) + { + Quaternion turn = Quaternion.Euler(0f, facingDegrees + bearingDegrees, 0f); + Vector3 point = center + turn * Vector3.forward * radius; + point.y = y; + return point; + } + + private static Vector3 Flat(Vector3 v) + { + v.y = 0f; + return v; + } + } +} diff --git a/README.md b/README.md index 9f0c992..76a64b4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Support the mod: [Patreon — NandorTheModder](https://www.patreon.com/c/NandorT --- +## New in v1.5.4 + +Sverm troops no longer crowd you. Following soldiers used to run onto your exact spot, shove each other and push you around, even into the water, and on a boat they drove into the hull and spun it in circles. Each one now keeps its own place around you, and around the hull when you sail. Full details in the [changelog](#v154). + ## New in v1.5.3 Valheim 1.0's new creatures are on the menu. The Aswid can drink the seals, the moose, the Elaking and its Lantern, the Elaking Mole, the frozen Greydwarfs, the Jotun Warriors and Witch, the Barka, the Deep North Goblin and every Dvergr, and the Draugh can eat raw Seal Blubber and Moose Meat. The Aswid blood refinery takes the Elaking Hair Bundle as bone, and a Skeleton can now pick which of its unlocked looks to wear from the barber's chair. Full details in the [changelog](#v153). @@ -435,6 +439,10 @@ Both halves have an off switch under `Factions` in Configuration Manager: **Fact ## Changelog +### v1.5.4 +- **Fix - Sverm troops piled onto the player and pushed boats around:** the game sends every follower to the exact spot where you stand and stops it three metres away, so a squad of three converged on one point, shoved each other and shoved you, in one report into the water. On a boat your spot is on the deck, so they drove into the hull and spun the ship in circles. Each troop now has its own place, about 4 m behind you and fanned out from the others, and only walks back to it once it has drifted 3 m away, so it stands still instead of shuffling. While you are on a ship the places lie on a ring 5 m outside the hull. Past 30 m from you a troop stops following and goes home to its nest. Thralls, the Aswid's thralls and skeletons keep the game's own following. Thanks to the player who reported it. +- **Not tested in game yet:** the distances are estimates, and `SvermConfig` holds them if they need tuning. + ### v1.5.3 - **New - Valheim 1.0's creatures for the Aswid:** killing and devouring any of these now feeds the Aswid. Seals (adult and pup), the Greydwarf_Frozen and the frozen Shaman give the stats of Seal Meat Soup, with the seal's trophy as icon. The Elaking and the Elaking Lantern give a Cooked Asksvin Tail. Moose and its calf give Cooked Moose Meat. The rest follow the house rule, health halved up to 150 and twice the health in seconds, now capped at 50 minutes: the Barka, the Jotun Warrior and the dual-wielding one, and the Deep North Goblin, which lasts 20 minutes like every Fuling. Fixed values: the Jotun Witch 120 health for 60 minutes, the Elaking Mole 100 for 30, the Deep North Dvergr 100 for 30, and every earlier Dvergr (mages included, the Ashlands one too) 90 for 25. The Dvergr were never edible before. - **New - Raw Seal Blubber and Moose Meat for the Draugh:** the Draugh eats raw Seal Blubber for the stats of Seal Meat Soup, and raw Moose Meat for Cooked Moose Meat, keeping the raw item's name and icon. The Sverm and the Aswid blood refinery read the same table, so both now count them as flesh too. diff --git a/manifest.json b/manifest.json index ac2c5e8..d5f4e66 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.", - "version_number": "1.5.3", + "version_number": "1.5.4", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333",