party - MSUTeam/MSU GitHub Wiki

Description

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. The hooked file is scripts/entity/world/party.nut.

Fields

MSU adds the following new fields to party:

VanillaBaseMovementSpeed

  • Equal to BaseMovementSpeed and records the vanilla movement speed of a party.

BaseMovementSpeedMult

  • Equal to 1.0. This is changed based on the MovementSpeedMult of party templates derived from the spawnlists, or otherwise provides a way to more permanently change the speed of a party. This value is serialized.

MovementSpeedMult

MovementSpeedFunctions

  • An array of functions changing MovementSpeedMult

Added Functions

MSU adds the following new functions to party:

Utility Functions:

getVanillaBaseMovementSpeed()
{
    return this.m.VanillaBaseMovementSpeed;
}
setVanillaBaseMovementSpeed( _speed )
{
    this.m.VanillaBaseMovementSpeed = _speed;
}
setBaseMovementSpeed ( _speed )
{
    this.m.BaseMovementSpeed = _speed;
}
resetBaseMovementSpeedfunction()
{
    this.setBaseMovementSpeed(100);
}
setBaseMovementSpeedMult( _mult )
{
    this.m.BaseMovementSpeedMult = _mult;
}
getMovementSpeedMult()
{
    return this.m.MovementSpeedMult;
}
setMovementSpeedMult( _mult )
{
    this.m.MovementSpeedMult = _mult;
}
setMovementSpeed( _speed )
{
    this.setBaseMovementSpeedMult(_speed / 100.0);
}
getFinalMovementSpeedMult()
{
    local mult = 1.0;
    foreach (key, func in this.m.MovementSpeedMultFunctions)
    {
	local funcResult = func();
	mult *= funcResult;
    }
    return mult;
}
updateMovementSpeedMult()
{
    this.setMovementSpeedMult(this.getFinalMovementSpeedMult());
}
getMovementSpeed( _update = false )
{
    if (_update)
    {
	this.updateMovementSpeedMult();
    }
    local speed = this.getBaseMovementSpeed() * this.getMovementSpeedMult();
    return speed;
}
getTimeDelta() 
{
    local delta = ::Math.maxf(0.0, this.Time.getVirtualTimeF() - this.m.LastUpdateTime);
    return delta;
}

MovementSpeedMult Functions:

These functions extract out some factor that was previously either fetched in onUpdate or hardcoded somewhere else in the code.

getBaseMovementSpeedMult()
{
    return this.m.BaseMovementSpeedMult;
}
getSlowdownPerUnitMovementSpeedMult()
{
    return (1.0 - ::Math.minf(0.5, this.m.Troops.len() * ::Const.World.MovementSettings.SlowDownPartyPerTroop));
}
getGlobalMovementSpeedMult()
{
    return ::Const.World.MovementSettings.GlobalMult;
}
getRoadMovementSpeedMult()
{
    if (this.isIgnoringCollision())
    {
	    return 1.0;
    }
    local myTile = this.getTile();
    if (myTile.HasRoad)
    {
	    return ::Math.maxf(::Const.World.TerrainTypeSpeedMult[myTile.Type] * ::Const.World.MovementSettings.RoadMult, 1.0);
    }
    else
    {
	    return ::Const.World.TerrainTypeSpeedMult[myTile.Type];
    }
   }
getNightTimeMovementSpeedMult()
{
    if (!this.m.IsSlowerAtNight || ::World.isDaytime())
    {
    	return 1.0;
    }
    return ::Const.World.MovementSettings.NighttimeMult;
}
getRiverMovementSpeedMult()
{
    if (!this.getTile().HasRiver)
    {
    	return 1.0;
    }
    return ::Const.World.MovementSettings.RiverMult;
}
getNotPlayerMovementSpeedMult()
{
    if (this.m.IsPlayer)
    {
    	return 1.0;
    }
    return this.m.IsPlayer ? 1.0 :  ::Const.World.MovementSettings.NotPlayerMult;
}

Hooked Functions

MSU hooks the following functions of party:

function onSerialize( _out )
{
    this.getFlags().set("VanillaBaseMovementSpeed", this.getVanillaBaseMovementSpeed());
    this.getFlags().set("BaseMovementSpeedMult", this.getBaseMovementSpeedMult());
    onSerialize(_out);
}
function onDeserialize( _in )
{
    onDeserialize(_in);
    if (this.getFlags().has("VanillaBaseMovementSpeed"))
    {
    	this.setVanillaBaseMovementSpeed(this.getFlags().get("VanillaBaseMovementSpeed"));
    }
    if (this.getFlags().has("BaseMovementSpeedMult"))
    {
    	this.setBaseMovementSpeedMult(this.getFlags().get("BaseMovementSpeedMult"));
    }
    this.resetBaseMovementSpeed();
}

Overwritten Functions

MSU overwrites the following functions of party:

function getMovementSpeed( _update = false )
{
    if (_update)
    {
        this.updateMovementSpeedMult();
    }
    local speed = this.getBaseMovementSpeed() * this.getMovementSpeedMult();
    return speed;
}

This makes sure that the movement speed is updated when required, such as when this function is called during onUpdate.

  • onUpdate() Now gets the speed of the party via calling this.getMovementSpeed(true) * delta, where delta is the result of getTimeDelta(). Thus, all the movement speed multiplier functions will be called to update to the correct movement speed of the party.
⚠️ **GitHub.com Fallback** ⚠️