C++ Question multistage2 no fuel bug workaroud?

malisle

Donator
Donator
Joined
Jul 8, 2012
Messages
110
Reaction score
0
Points
16
Hello everybody!
Few weeks ago I decided to stop flying and start learning how to make a .dll driven vessel. I manually converted some spacecraft3 driven vessel into .dll for practice and after some time I got it working (even the animations :hotcool:). The problem that keeps popping up is that after I separate the payload from Jarvis launcher (multistage2) it has no fuel. I know it is an old multistage2 bug easily solvable using scenario editor but i was hoping for something that didn't require my intervention. Searching the forums provided this but I wasn't able to replicate the solution.
I was wondering if anybody can share their tricks and workarounds, preferably in C++ in order to keep it simple?
 
Hello everybody!
Few weeks ago I decided to stop flying and start learning how to make a .dll driven vessel. I manually converted some spacecraft3 driven vessel into .dll for practice and after some time I got it working (even the animations :hotcool:). The problem that keeps popping up is that after I separate the payload from Jarvis launcher (multistage2) it has no fuel. I know it is an old multistage2 bug easily solvable using scenario editor but i was hoping for something that didn't require my intervention. Searching the forums provided this but I wasn't able to replicate the solution.
I was wondering if anybody can share their tricks and workarounds, preferably in C++ in order to keep it simple?

I'm not sure if I understand what you want here. Let me try to repeat it:

  1. You recreated your SC3 payload vessel as a DLL vessel.
  2. You want to use this vessel with the Jarvis launcher.
  3. If you do so, after separation your vessel has no fuel.
I guess the problem is either that:

  • the multistage2 framework just spawns a new object, but is not setting the propellant levels, AND you are not specifying an initial level in your CreatePropellantResource() call, OR
  • you are specifying a level in your CreatePropellantResource() call, but the multistage2 framework is explicitly setting all propellants to zero right after creation.
If the first is the case, an appropriate argument setting in CreatePropellantResource() should fix it. If it is the later one, I'd try the following workaround:
  1. In clbkSetClassCaps(), store the time you get with oapiGetSimTime() in e.g. creationTime. Add 500ms to it: creationTime+=0.5
  2. Implement clbkPreStep(), and if creationTime > 0, check oapiGetSimTime() again, store in currentTime and do step 3. Otherwise, return without action.
  3. Compare currentTime with creationTime. If currentTime > creationTime, set creationTime to zero and - if your propellant level is zero - reset your propellant levels.
In essence this is what the scenario-editor proposal does, just programmatically instead of manually. It simply checks after 0.5 seconds if fuel is zero, and refills it if so. Of course you can extend the delay to 1 second or even more, if it better fits your needs.

regards,
Face
 
  • you are specifying a level in your CreatePropellantResource() call, but the multistage2 framework is explicitly setting all propellants to zero right after creation.
If that's the case, then it's probably the VESSELSTATUS2 passed to oapiCreateVesselEx which is resetting the fuel to 0 (I haven't found references to (non-virtual) DefSetState[Ex] or SetFuelMass in import table of multistage2.dll, so the fuel is set only during vessel creation).

In such case, instead of delayed "refueling" after checking the time delta (in every time step, and requiring checking additional conditions, for example if the vessel was loaded from a scenario with empty tanks, and not created in runtime this way), I'd use the vessel's clbkSetStateEx callback to properly set the fuel amount to what it should be, when the status is set to reset tanks (for example, by resetting VS_FUELRESET flag from the passed status if it was indeed set).
 
In such case, instead of delayed "refueling" after checking the time delta (in every time step, and requiring checking additional conditions, for example if the vessel was loaded from a scenario with empty tanks, and not created in runtime this way), I'd use the vessel's clbkSetStateEx callback to properly set the fuel amount to what it should be, when the status is set to reset tanks (for example, by resetting VS_FUELRESET flag from the passed status if it was indeed set).

The described algorithm uses a cheap-shot self-holding mechanism with setting creationTime to zero, so it wouldn't check the time in every time step after the delay. I don't think it is a big performance problem, anyway.

Your idea with clbkSetStateEx() sounds elegant, but what about other add-ons using DefSetStateEx to fulfill their function? Would that also trigger the callback?
 
There would be still checked the condition for creationTime being 0 in every step.

I can't check it right now in debugger, but according to documentation clbkSetStateEx should be called only one time, after the vessel was created with oapiCreateVesselEx.
 
I'm not sure if I understand what you want here. Let me try to repeat it:

  1. You recreated your SC3 payload vessel as a DLL vessel.
  2. You want to use this vessel with the Jarvis launcher.
  3. If you do so, after separation your vessel has no fuel.

Correct.

I guess the problem is either that:

  • the multistage2 framework just spawns a new object, but is not setting the propellant levels, AND you are not specifying an initial level in your CreatePropellantResource() call, OR

It wasn't this, CreatePropellantResource() was used and initial level was set.

  • you are specifying a level in your CreatePropellantResource() call, but the multistage2 framework is explicitly setting all propellants to zero right after creation.
If the first is the case, an appropriate argument setting in CreatePropellantResource() should fix it. If it is the later one, I'd try the following workaround:
  1. In clbkSetClassCaps(), store the time you get with oapiGetSimTime() in e.g. creationTime. Add 500ms to it: creationTime+=0.5
  2. Implement clbkPreStep(), and if creationTime > 0, check oapiGetSimTime() again, store in currentTime and do step 3. Otherwise, return without action.
  3. Compare currentTime with creationTime. If currentTime > creationTime, set creationTime to zero and - if your propellant level is zero - reset your propellant levels.
In essence this is what the scenario-editor proposal does, just programmatically instead of manually. It simply checks after 0.5 seconds if fuel is zero, and refills it if so. Of course you can extend the delay to 1 second or even more, if it better fits your needs.

regards,
Face


I did as you instructed and it worked,the tank is full. Thank you Face! :tiphat:
 
Back
Top