Page 1 of 1

Linear Impulse

Posted: Tue Jan 24, 2023 6:01 pm
by [object Object]
Linear Impulse is a hex segment (can be inserted directly, not required to call with Hermes) that linearizes the cost of an Impulse by using several 1-length impulses. This technique has been floating around on Discord for a while, but this particular implementation is my own.

Linear Impulse
entity, vector
Meta-eval usage: ceil(|v|) + 1
Dust cost (integer length): max(0, 2*|v| - 1)
Dust cost (non-integer length): 2*floor(|v|) + (|v| - floor(|v|))^2
(Note: |v| is the length of the vector.)
awqqqwaqww
Patterns
qqqMuninn's ReflectionRotation Gambit IIGemini DecompositionVector Reflection ZeroInequality DistillationqqqGemini DecompositionLength PurificationUndertaker's GambitDivision Dstl.Jester's GambiteeeqqqNumerical Reflection: 0eeeAugur's ExaltationqqqGemini DecompositionNumerical Reflection: 1Maximus DistillationqqqRotation Gambit IIDioscuri GambitImpulseRotation GambitNumerical Reflection: 1Subtractive DistillationeeeMuninn's ReflectionCombination DistillationqqqMultiplicative Dstl.ImpulseeeeAugur's ExaltationHermes' GambiteeeGemini DecompositionHuginn's GambitCombination DistillationHermes' GambitHuginn's Gambiteee

Code: Select all

#define Linear Impulse (SOUTH_WEST awqqqwaqww) = entity, vector ->
{
    // save previous ravenmind
    Muninn's Reflection
    Rotation Gambit II

    // on the first iteration, normalize the impulse vector and get its length
    // or just push 0 if it's the zero vector to avoid dividing by zero
    Gemini Decomposition
    Vector Reflection Zero
    Inequality Distillation
    {
        Gemini Decomposition
        Length Purification
        Undertaker's Gambit
        Division Distillation
        Jester's Gambit
    }
    {
        Numerical Reflection: 0
    }
    Augur's Exaltation
    
    // recursive function to actually do the impulse
    {
        // is the remaining speed greater than 1?
        Gemini Decomposition
        Numerical Reflection: 1
        Maximus Distillation
        
        // if so, impulse by the unit vector (length 1) and decrement the speed
        // then do the recursive function again
        {
            Rotation Gambit II
            Dioscuri Gambit
            Impulse
            Rotation Gambit
            Numerical Reflection: 1
            Subtractive Distillation
        }
        Muninn's Reflection
        Combination Distillation
        
        // otherwise, impulse by the remaining speed and don't recurse
        {
            Multiplicative Distillation
            Impulse
        }

        Augur's Exaltation
        Hermes' Gambit
    }
    Gemini Decomposition
    Huginn's Gambit
    Combination Distillation
    Hermes' Gambit

    // restore previous ravenmind
    Huginn's Gambit
}
How it works
Normally, Impulse costs dust equal to the square of the length of the vector (|v|). However, if you split up this impulse into |v| length-1 impulses (assuming integer length), then each impulse would cost just one dust. The mod also adds one dust to the cost of all impulses on the same entity in the same hex after the first (to avoid stacking very short impulses for basically free), so the cost is increased slightly, but it's still linear, not quadratic. If the vector is of non-integer length, the hex does floor(|v|) length-1 impulses, then one impulse equal to the decimal component of the length.