Modding Help Where is the code for warping and fuel consumption located?

Discussion in 'Starbound Modding' started by Stroomschok, Jul 29, 2016.

  1. Stroomschok

    Stroomschok Void-Bound Voyager

    I made a (very) simple mod removing the cost cap of 500 fuel for warping around long distances. http://steamcommunity.com/sharedfiles/filedetails/?id=733601915

    However, when putting in custom coordinates (and thus travelling further than you could manually scroll the map for a week), it often happens that the fuel costs suddenly is a negative two-million-something. And this then breaks the UI, yet it still allows you to warp (thus breaking the UI some more).

    I suspect this is caused by something like a variable in the fuel calculation going out of bounds, but I can't find the actual code for it. I would like to find the location of the code that I need to alter to do things like prohibiting warping at a negative fuel cost (like where is the code hidden that stops your from warping at 0 fuel?), maybe even fixing the bug that makes the fuel cost go negative in the first place (though I'm guessing that part is in the C++ engine).

    Thanks for any help :)
     
    Last edited: Jul 29, 2016
  2. lazarus78

    lazarus78 The Waste of Time

    There is no code we can alter. However, getting negatives seems like you screwed up somewhere. Ive never seen that happen/

    Could you post a non-steam version so I can look at what you did?
     
  3. Stroomschok

    Stroomschok Void-Bound Voyager

    Ok I've looked into it quite a bit more and I think I figured out most of it.

    This is from fuelcost.functions :
    Code:
    {
      "interSystemFuelcost" : [ "linear", "clamp",
        [0, 10],
        [10, 50],
        [100, 500]
      ]
    }
    First what I did was patch 'clamp' into 'extrapolate'. Single as pie and worked fine unless people mess with custom coordinates. The thing is, the fuel cost is calculated in the C++ engine (I think) and they apparently used a max variable integer for the result, which can only up to 2147483647.

    And this isn't enough because that's barely more than the axis length of Starbounds galaxy (Pythagoras shakes his head at this), yet the fuel:distance ratio is 5:1, so it goes out of bounds very easily (in fact, removing a single digit from an axis of a 9x9 digit coordinate already breaks it). And apparently with an out of bounds output integer the fuel calculation function breaks, returning a negative max integer value instead.

    So I've worked around it by putting the 'clamp' back on, but changing the last value into [400000000, 2000000000], and the mod now at least serves it's purpose without bugging out. Which is good enough for me.

    Too bad though that we can't access the warping code. I would have loved to create a mod that put a tiny fuel cost on interplanetary travel.
     

Share This Page