Home Forums Free SciFi Gaming Projects Pioneer How Do I Calculate….

Viewing 15 posts - 16 through 30 (of 33 total)

Humble Book Bundle ends on 9/11/2019

  • Author
  • #104605

    I’ve pinged the IRC channel to see if there’s anyone around to help, if not PM me at the weekend and I’ll try digging through the code myself.

    Humble Book Bundle ends on 9/11/2019


    @Bugbear please check data/ui/StationView/ShipMarket.lua. It’s actually used in very many places, like all mission scripts that send ships your way. And Pirates.lua. Those are all in data/modules/

    If you come up with something useful, and feel like contributing, let us know, maybe we/you can improve the Orbital Analysis tab so we can have it activated again?


    I started to work on a similar mod a while ago, but I got stuck, because I had to calculate the velocity. Fluffyfreak did something about the velocity in lua a while ago, maybe that can be helpful.

    Here’s where I got.

    I put the whole thing into the ShipInfo page, so I can check the value simply by pressing F3, and also there’s a lot of input to the console, so the numbers can be checked.

    I managed to get out almost all the data from the game except the speed if I remember correctly.

    The way I wanted to get the needed distance is to iterate the calculation several times, so the changing acceleration due to expelling mass can be taken into account.

    There are some comments where I put in my stuff, but I’m not sure how clear they are. 

    And I can’t really code, so I’m sure this whole thing is quite cringe inducing for somebody knowledgeable. 😀

    Hope it helps.




    I’ve made some progress with gathering the data I need to calculate the distance to stop given a starting velocity.

    Turns out all I need are the following:
    Fuel remaining –> Game.player.fuelMassLeft
    Ship mass (excluding fuel) –> Game.player.totalMass
    Exhaust velocity –> ShipDef[Game.player.shipId].effectiveExhaustVelocity
    Forward thrust –>ShipDef[Game.player.shipId].linearThrust.FORWARD
    Reverse thrust –> ShipDef[Game.player.shipId].linearThrust.REVERSE
    Current velocity –> ???

    So as you can see all I need now is the current speed relative to the current frame of reference.


    I think that you should be able to use “Game.player:GetVelocity()” as it’s quite new, and the API reference might be out of date, it might not be on the API listing.


    it returns a LuaVector




     * Method: GetVelocity


     * Get the ships velocity


     * > ship:GetVelocity()


     * Availability:


     *  April 2016


     * Status:


     *  experimental


    static int l_ship_get_velocity(lua_State *l)


    Ship *s = LuaObject<Ship>::CheckFromLua(1);

    LuaVector::PushToLua(l, s->GetVelocity());

    return 1;



    it might not be on the API listing.

    Most likely isn’t, since API is only updated manually, very rarely, when we kick our biological (rob)ot down under.


    OK, I’m still a little dense (I’m still fairly new to Lua).  How do I access the components of the LuaVector object?


    (In the menatime I’ll keep reading up on Lua basics…)


    Here’s a first draft of the ‘Distance to Stop’ calculations.  You can download the various required files via this link: https://app.box.com/s/0ancxt0768dixhqoqssf


    I’ve also included some screenshots in that link so you can see the results of the calculations.


    Bear in mind that this is an initial draft and the presentation of the data is not quite where I’d want it.


    Also, at this point I haven’t worked out how to get the current ship’s velocity so I’ve just hard coded 1000km/s for now, just so you can see the calculations in action…


    ** edit ** While I think of it, if I can get access to the distance to the selected destination, I should also be able to determine the turnaround distance and speed – this would also take into consideration the amount of fuel (propellant?) that you have in the tank…


    Dammit, I can see this mod getting bigger…


    Neat! A quick test gave me the good ballpark estimate of .10AU from the Barnard’s starting position.

    Are you sure you want to put all this data into the Orbit Analysis page? It might be more accessible in the ship info page, so you can check it quickly by pressing F3. (Sans proper customizable flight UI top put into)


    You can access the propellant flow of the ship: ShipDef.thrusterFuelUse. I saw you are calculating it. Don’t know which method is better though.


    Hey Noz…

    I’ll see how I go putting my data on the Ship Info page.  Now that I’ve done it once in the Orbital Analysis page, editing the other .lua files should be straight forward.  I’ll put my calculations under the ‘acceleration’ data.


    I want to make the output much more concise than I’ve done so far in my first draft.  I think the most essential information required is (apologies for the dodgy attempt at an ASCII table):


                                  |    Forward thrusters    |    Reverse thrusters    |

    Distance to stop     |                                    |                                    |

    Time to stop           |                                    |                                    |


    If a table looks too out of place on the F3 page, then I’ll just list it instead.


    The unit of measure displayed for both the distance and time would be dependent on the magnitude of the measurement, e.g. if distance is > 0.10 AU, then show distance in AU, otherwise in km.  I’d do something similar for time, with an aim to make the leading integral component of the measure as small as possible (easier to explain in code than in English…)


    I didn’t notice the thrusterFuelUse property.  I’ll use that instead.




    Some minor modifications – I’ve moved the calculation output to the Ship Info page – same link as above (https://app.box.com/s/0ancxt0768dixhqoqssf)


    Download the en.json (https://app.box.com/s/venvrlgguor8h3xayxxy31110dtl8abt) and the ShipInfo.lua (https://app.box.com/s/l04gnf0ltgliz3fxvuvo8klskfbivvai) to see it in action.


    Image of the display: https://app.box.com/s/1gv9d48kkb0jsiip9rkfp2xt85vmnflo


    Again, I don’t yet have the code for getting the current speed so an indicative speed of 1km/s has been hard coded on the ShipInfo.lua file.


    I also haven’t worked out how to grab the thrusterFuelUse property – not sure if this value changes from forward to reverse thruster, so not sure of the syntax for getting this value for a specific engine.


    All I need is the code to get the current speed….hint, hint 🙂


    I think it’s just a meta table with 3 elements. You can get each element by it’s index “x”, “y”, or “z” too.


    If you just want the velocity without the direction then you could just get it’s “length” which will give a single value for “speed” I guess.


    Looks very good.

    A bit of nitpicking: I think “Main” and “Retro” thrusters might be better terms. At least for me. Forward could imply that the thrusters are looking forward, or that they accelerate you forward.

    And a bit more: Maybe you could move them up above the acceleration displays, so the deltaV and Speed displays are right next to each other. Would make it easier to judge, how much juice you have left in your tanks.


    Anyhow, this feature will sure give the adventurous player an edge over the autopilot regarding transfer times. 🙂



    Also, if you zip it up this way, it can be used as a mod, making it easier to test:






    Thanks for the help on IRC.  No success yet but I’ll keep bashing away…


    We now have the distance to stop calculation available on the F3 page, and I’ve uploaded the latest ShipInfo.lua here: https://app.box.com/s/l04gnf0ltgliz3fxvuvo8klskfbivvai


    I’ll now do some work on figuring out how to display these numbers on the cockpit (aka WorldView screen).


    There is one minor gotcha with the calculations though – the distance to stop is based on the speed relative to the frame of reference (which admittedly is what I requested in the first place).  Now that I’ve had a chance to play with this, I’m thinking that speed relative to destination would be more useful.  When travelling from Earth to Mars for example, the point at which deceleration needs to begin occurs while the frame of reference is Sol, which means that the speed will be out by something like 25km/s.


    I’ll see what I can do about this looking at the underlying code…


    Another update.  After another couple of months of sporadically trawling through the Pioneer C++ source, I’ve been able to create a function in WorldView.cpp that calculates the distance to stop, and displays this on screen just below the current nav target relative speed indicator – screenshot here: https://app.box.com/s/2jt86yrl0s3eq3svkxymkzttvsro1f78 (The F means distance to stop using the ‘forward’ or main thrusters, the R means distance to stop using the ‘rear’ or retro thrusters.  The rear thrusters are less powerful than the front, therefore they will take more distance to accelerate / decelerate from a given speed).


    (After using this a few times, I’ll probably also add the current available delta-v – that’s a very important number when travelling between planets…)


    This is still a work in progress – my intent is to make this calculation available only to commanders that purchase the Nav Computer Upgrade in-game so as a result I would need to work out how to declare a new piece of purchasable equipment (knowing my luck and my schedule that will take me another couple of months…).


    I know that some other devs (in particular ecraven) have been doing some excellent work in not only calculating this information, but also presenting it on screen in a much more attractive manner (I’ve always said that I don’t do “pretty” very well), so it may be that my efforts so far will come to naught.


    What I’d like to to, though, is make available the code I’ve created so far, and have some of the devs look it over and tell me whether I’m on the right track (I really should work out git works… )


    WorldView.cpp – https://app.box.com/s/e7zo8hxyk8kj8uvs0isyjrhnpq203tz8

    WorldView.h – https://app.box.com/s/m5ynr4w3aw83u5n1hdijyoeotfm4bqa6



Viewing 15 posts - 16 through 30 (of 33 total)
  • You must be logged in to reply to this topic.