Skip to content

Extends functionality for modders to modify horse riding speed. #2735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tuncturel
Copy link

@tuncturel tuncturel commented Apr 9, 2025

Hi, I've found out that it was not possible for modders to modify the horse riding speed in DFU. I took some liberty in refactoring this script and adding this exact functionality. I followed the same format with which walking and running speeds were modified to keep my addition predictable and in line with the existing material. I also took a bit of liberty in renaming a few things, removing some possibly redundant comments, rewriting missing/incorrect comments as well. I made sure none of my changes impacted existing mods by keeping everything backwards compatible. I did some light testing to see if things are working as intended and they seemed okay but would love it if someone took the time to test it thoroughly. I'm by no means a stranger to Unity or coding with C#. I got many years under my belt but this is my first contribution in a public repo ever so please let me know if something doesn't make sense or if you have any input. I'm just a guy who wants to mod his horse to ride faster. 🐴

Copy link

@Nuboctane Nuboctane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tuncturel
Copy link
Author

tuncturel commented Apr 9, 2025

Below is the download link for the Unity package of my sample mod. You can click the link, unzip it and unpack the unity package to the Assets>Game>Mods folder of your DFU Unity project. I'm hoping this can help with the testing process for those who are interested in giving it a try.

Click this link to download FasterHorseRidingMod.zip

I have also provided a snippet from the unity package below so that you can see how the mod would utilize the functionality I've written in the merge request.

using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings;
using UnityEngine;


namespace FasterHorseRiding
{
    public class FasterHorseRidingModManager : MonoBehaviour
    {
        static Mod s_Mod;
        float m_HorseSpeedMultiplier = 1.0f;
        PlayerSpeedChanger m_PlayerSpeedChanger;
        PlayerMotor m_PlayerMotor = null;
        string m_SpeedModUID = null;

        [Invoke(StateManager.StateTypes.Game, 0)]
        public static void Init(InitParams initParams)
        {
            s_Mod = initParams.Mod;
            GameObject modGameObject = new GameObject(s_Mod.Title);
            modGameObject.AddComponent<FasterHorseRidingModManager>();
        }

        void Awake()
        {
            s_Mod = ModManager.Instance.GetMod("FasterHorseRiding");
            ModSettings modSettings = s_Mod.GetSettings();
            s_Mod.IsReady = true;
        }

        void Start()
        {
            Initialize();
        }

        void Initialize()
        {
            m_PlayerMotor = GameManager.Instance.PlayerMotor;
            m_HorseSpeedMultiplier = s_Mod.GetSettings().GetValue<float>("Main Settings", "Horse Speed Multiplier");
            m_PlayerSpeedChanger = GameManager.Instance.PlayerObject.GetComponent<PlayerSpeedChanger>();
            m_PlayerSpeedChanger.AddRideSpeedMod(out m_SpeedModUID, m_HorseSpeedMultiplier, true);
            Debug.Log("FasterHorseRidingModManager: Added ride speed of x" + m_HorseSpeedMultiplier.ToString() + " mod with UID: " + m_SpeedModUID);
        }

        void OnDestroy()
        {
            m_PlayerSpeedChanger.RemoveSpeedMod(m_SpeedModUID);
        }
    }
}

@KABoissonneault
Copy link
Collaborator

@ajrb Was that really not possible before? I know you've played with something similar, like the sprint you have in R&R. Maybe this is different, I'm not sure

@tuncturel
Copy link
Author

Hi @KABoissonneault , if it's possible to do it another way then I'm happy to consider that.👍 I did talk to other modders on the Lysandus' Tomb Discord working on a mod that increases the variety of rides among other things. They told me the following:

"We've only been able to make the horse speed slower. We still can't make it faster than its vanilla speed. The other aspect we've been able to modify is the "run" or "gallop" speed."

I wonder if @ajrb can weigh on it when he has the time. I'm always happy to delete or modify the pull request, of course.

@ajrb
Copy link
Collaborator

ajrb commented Apr 20, 2025

Hi, thanks for being patient and waiting for me to respond. The PlayerSpeedChanger class was not one I was veyr involved in, I only added changes to support the horse speed. This was based on the player speeds and thus the player speed stat - hopefully matching classic DF for horse and cart as best we could. I always considered that a mod of movement speed would operate on the base speeds. Anyway I have no problems with these changes, however I will add some review comments.

Comment on lines -33 to +34
private const float dfRideBase = dfWalkBase + 225f;
private const float dfCartBase = dfWalkBase + 100f;
private const float dfRideBase = 375f;
private const float dfCartBase = 250f;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change these definitions? Making this change would lose the context that the base speeds are based on the difference to the walk speed base.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this was purely a personal taste change and I think it can be discarded as it has no functional impact. These values are constants meanings they will never change during gameplay (if I'm not mistaken). Since they were not multiplied by the walk speed and were simply used in an addition I preferred to see them as their actual value instead of having to go and look at the walk speed.

Comment on lines -158 to +174
float rideSpeed = (GameManager.Instance.TransportManager.TransportMode == TransportModes.Cart) ? dfCartBase : dfRideBase;
baseSpeed = (playerSpeed + rideSpeed) / classicToUnitySpeedUnitRatio;
float currentRideBase = 0;
bool playerIsRidingHorseWithNoCart = GameManager.Instance.TransportManager.TransportMode == TransportModes.Horse;
if (playerIsRidingHorseWithNoCart)
currentRideBase = dfRideBase;
else
currentRideBase = dfCartBase;
baseSpeed = (playerSpeed + currentRideBase) / classicToUnitySpeedUnitRatio;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why this code is being changed.. I can't see any difference in what it does, it's just more verbose and in my eyes less easy to see what is being done. I might be biased since these lines were added by me, happy to take a consensus if many feel it's better written the new way, but otherwise I'd rather this change is removed.

Copy link
Author

@tuncturel tuncturel Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making it simple stupid and more 'verbose' as you put it. When code reads like prose it can sometimes help me understand it better; that's probably why I changed it. I believe no functional change in here so please feel free to pick the version you like. 👍

@ajrb
Copy link
Collaborator

ajrb commented Apr 20, 2025

@ajrb Was that really not possible before? I know you've played with something similar, like the sprint you have in R&R. Maybe this is different, I'm not sure

The speeds are based on normal char speeds with modifiers for horse/cart, normally sprinting is disabled when riding but R&R enables it when riding a horse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants