Tungsten

  • thomasa
    30th Jan 2015 Member 0 Permalink

    What sort of code would I need to put in the TPT 'Autorun" file to make tungsten a little less "fragile"? The way I'm trying to use it, it crumbles as soon as it receives spark near anything low pressure.

  • jward212
    30th Jan 2015 Member 0 Permalink

    you'd need to over write the existing function for tungsten...

    i'll have a look at the c++ source code

    checked, we will have to rewrite much of the expoldeing with heat in lua :/

    do you want that?

     

    Edited once by jward212. Last: 30th Jan 2015
  • boxmein
    30th Jan 2015 Former Staff 1 Permalink
    https://github.com/simtr/The-Powder-Toy/blob/master/src/simulation/elements/TUNG.cpp#L58-L105

    Write a replicate update function, tis easy! Something like this in pseudo-code:


    constant MAX_TEMPERATURE = 4800.0
    function update():
    explode? = false
    if this particle's temperature > MAX_TEMPERATURE:
    if there's O2 near this particle:
    explode? = true

    if (this particle's temperature > MAX_TEMPERATURE and 1/20 chance) or explode?:
    if 1/20 chance:
    set pressure to 50
    if 1/100 chance:
    transform into FIRE with life (random(0, 500))
    otherwise
    transform into LAVA(TUNG)
    skip moving and return
    if explode?:
    set this particle's temperature to MAX_TEMPERATURE + 200-800 K
    set this particle's vx and vy to random numbers between 0 and 50
    set TTAN "Update" property to this function




  • DanielGalrito
    30th Jan 2015 Member 0 Permalink

    Why can't changing the high pressure transition fix that?

  • jacob1
    30th Jan 2015 Developer 0 Permalink
    @DanielGalrito (View Post)
    TUNG doesn't have a high pressure transition. It breaks when the pressure difference between frames is > .5. It has special code for this in the update function.

    So if you want to change that, you have to replicate TUNG's update function so that the temperature transitions still work properly, but remove the pressure one. See the code here: https://github.com/simtr/The-Powder-Toy/blob/develop/src/simulation/elements/TUNG.cpp#L56 . Looks entirely replicatable to me.

    I don't feel like doing that myself though, so I decided to do the alternate way of creating an update function for BRMT and checking if it was created from TUNG (ctype TUNG), and if so turn it back into TUNG. That way didn't exactly work due to TPT bugs, so instead I did an even better worse way by abusing those same bugs. This should make TUNG never break:
    local function noshatter(i, x, y, s, nt)
    sim.partProperty(i, "type", tpt.el.tung.id)
    sim.partProperty(i, "ctype", 0)
    end
    pcall(elem.property, tpt.el.brmt.id, "Update", noshatter, "yayerror")
    local function ignore() end
    elem.property(tpt.el.tung.id, "Update", ignore)

    Technical explanation: When TUNG shatters due to pressure, it doesn't properly tell the game that it did, so it will continue to run through the update code assuming it's still TUNG. It notices that TUNG has a lua update function (which really does nothing) so goes to call it. Except the lua api notices that it's actually BRMT now, so instead calls the BRMT update function. The BRMT update function is simple, it always turns it back into TUNG. BRMT created through other methods won't turn into TUNG because the line that sets BRMT's update function errors (that final argument should be an int not a string), so the variable that tells the game BRMT has an update function is never set.

    Edit: here is a version for my mod (doesn't have the bug where it calls the wrong update function so I don't have to use the second glitch)
    local function noshatter(i, x, y, s, nt)
    if sim.partProperty(i, "type") == tpt.el.brmt.id then
    sim.partProperty(i, "type", tpt.el.tung.id)
    sim.partProperty(i, "ctype", 0)
    end
    end
    elem.property(tpt.el.tung.id, "Update", noshatter)
    Edited 2 times by jacob1. Last: 30th Jan 2015