party speed - MSUTeam/MSU GitHub Wiki
MSU adds a robust movement speed system for parties on the world map. This is accomplished via new fields, new functions as well as some modified vanilla functions. The goal is to make party movement speed more modular, at it is buried in big function calls and hardcoded values in vanilla.
In vanilla, the BaseMovementSpeed
is directly changed to hardcoded values. For example, the Ranger start changes BaseMovementSpeed
to 111. MSU keeps BaseMovementSpeed
at 100, and instead applies multipliers to it. The main multiplier is MovementSpeedMult
. This is multiplied by a number of functions that are called via the MovementSpeedMultFunctions
table. All the vanilla factors have been extracted from onUpdate
of party.nut, such as getNightTimeMovementSpeedMult
.
The MovementSpeedMultFunctions
has been added to party.m
. This is where functions that change the movementspeed should be added. The function must return a multiplier, such as 1.1
for a 10% increase. Set it in the table, such as:
this.MyMultiplierFunction <- function()
{
return 1.1
}
this.m.MovementSpeedMultFunctions.MyMultiplier <- this.MyMultiplierFunction;
It will be automatically called when onUpdate
calculates the final movement speed, via getMovementSpeed(true)
, which calls updateMovementSpeedMult()
, which in turn updates the multiplier via this.getFinalMovementSpeedMult()
. Calling getMovementSpeed()
without the true
parameter does not update the multiplier.
The 'base' multiplier of AI parties that is defined in spawnlists is set in the new BaseMovementSpeedMult
variable. You can tune this to make certain parties inherently faster or slower. This value is serialized.
The player_party
hook adds some convenience functions that are set in MovementSpeedMultFunctions
. It will check for functions called getMovementSpeedMult
in the following entities:
- brothers / player roster entitites
- stash items
- origin
- retinue
For performance reasons, dummy functions were not added to the classes. To add a new multiplier to one of these entities, simply add the function to it. This is demonstrated in the conversion of the scout follower to the new system:
local mod = ::Hooks.register("mod_my_mod", "1.0.0", "My Mod");
mod.hook("scripts/retinue/followers/scout_follower", function(q) {
q.getMovementSpeedMult <- function()
{
return ::World.Assets.getTerrainTypeSpeedMult(this.World.State.getPlayer().getTile().Type);
}
})
Should you need the vanilla movement speed, it is recorded in the this.m.VanillaBaseMovementSpeed
field. This value is serialized.