-
Notifications
You must be signed in to change notification settings - Fork 4
party
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
.
MSU adds the following new fields to party
:
- Equal to
BaseMovementSpeed
and records the vanilla movement speed of a party.
- 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.
- Equal to 1.0. This field will be changed by the MovementSpeedMult functions
- An array of functions changing
MovementSpeedMult
MSU adds the following new functions to party
:
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;
}
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;
}
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();
}
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 callingthis.getMovementSpeed(true) * delta
, wheredelta
is the result ofgetTimeDelta()
. Thus, all the movement speed multiplier functions will be called to update to the correct movement speed of the party.
- NOTE: MSU guarantees backwards compatibility for documented features and code only. Undocumented features/code of MSU may be changed at any time without notice, so we advise against using/referencing such code in your projects.
- For bug reports or feature requests, please create issues.
- If you would like to join the team, write to us at msu.team@protonmail.com.