API Question [SOLVED] Touchdown points update not applying when vessel is landed

nbcfrosty

Well-known member
Joined
Jun 16, 2023
Messages
181
Reaction score
214
Points
58
Location
US
Hello. I am updating the Velcro.dll to adjust the rocket's height with respect to the launch pad while in game.

Code:
int Velcro::clbkConsumeBufferedKey(DWORD key, bool down, char* kstate)
{
    if (!down) return 0; // only process keydown events
    switch (key) {
        case OAPI_KEY_EQUALS: {
            padbias += 1;
            adjust_td();
            display_padbias_time = oapiGetSimTime() + 3;
            break;
        }
        case OAPI_KEY_MINUS: {
            padbias -= 1;
            adjust_td();
            display_padbias_time = oapiGetSimTime() + 3;
            break;
        }
    }
    return 0;
}

void Velcro::adjust_td() {
   
    if (!GroundContact()) {
        return;
    }

    VECTOR3 p4 = _V(0, 0, 1);
   
    static const DWORD ntdvtx_geardown = 4;
    static TOUCHDOWNVTX tdvtx_geardown[ntdvtx_geardown] = {
        {_V(p1.x, p1.y, p1.z - padbias), 1e8, 1e6, 3, 1},
        {_V(p2.x, p2.y, p2.z - padbias), 1e8, 1e6, 3, 1},
        {_V(p3.x, p3.y, p3.z - padbias), 1e8, 1e6, 3, 1},
        {p4, 1e8, 1e6, 3},
    };
    SetTouchdownPoints(tdvtx_geardown, ntdvtx_geardown);
    ParkVessel(this);
}

This code works fine when padbias is read through the scenario file and adjust_td is called in the first time step from clbkPreStep. But when adjust_td is called through clbkConsumeBufferedKey the vessel remains seated and in place, with no apparent change in touchdown points. If a little thrust is applied, and height is reduced, the rocket starts falling, but as soon as it enters landed state, it once again reverts to the previous height as if no bias is applied. Even with using scenario editor, no change in apparent height of rocket.

In hopes of emulating the DG I tried to defer the td point update in clbkPostStep but it didn't help, either.
 

nbcfrosty

Well-known member
Joined
Jun 16, 2023
Messages
181
Reaction score
214
Points
58
Location
US
I figured out the problem, it's that I am a C++ newb! The touchdown points are declared statically, which is causing issues. Getting rid of the static keyword fixes it!
 
Top