I'm close to releaseing my mod.

  • Videogamer555
    19th May 2012 Member 1 Permalink
    My mod includes one of my own suggested elements CEXP (Customizable Explosive). At the bottom of this post is the C Code for my element. It required (on my older source code) certain other modifications including modifications to allow saving of TMP2 variable (which it uses) and to allow the console window to use !set with TMP2 variable. However the latest version of TPT already has these fixes so no additional modifications would be needed to implement this on the latest version of TPT.

    To set the temperature of the resulting flame from the explosion you set the TMP variable of the explosive.
    To set the pressure added to the existing pressure in a given air-block when a pixel of this stuff explodes, you set the LIFE variable.

    For example, if you want it so that when a pixel of this stuff explodes it will add 7 units of pressure to the air-cell this pixel is in and you want the temperature of the flame resulting from the explosion of this to be 5000Kelvins, you will (after having drawn some CEXP on the screen) use these two console commands:
    !set life cexp 7
    !set tmp cexp 5000

    Now the question comes to how to detonate it? Well this involves "binary flags" that set miscellaneous properties of the explosive, and the variable used for this is TMP2. Bits (flags) 0 to 7 correspond to decimal numbers 1, 2, 4, 8, 16, 32, 64, 128. And below is a list of how they are used.
    1 = explodes from contact with FIRE or PLSM elements
    2 = explodes from contact with LAVA
    4 = explodes from contact with SPRK
    8 = explodes if pressure in air-cell that explosive pixel is in is greater than or equal to 3 units of pressure
    16 = explodes if temperature of explosive pixel is greater than or equal to 500Kelvins
    32 = explosion produces PLSM regardless of if the temperature is normally high enough to convert FIRE into PLSM
    64 = explosion produces LAVA with CTYPE of BMTL (just like thermite, so think of this as a thermite bomb mode).
    128 = explosion produces no element output (only pressure, so great for a a bomb that just shatters stuff)

    To get combine these flags you just sum the numbers together for the properties you want and the resulting number is what you set TMP2 to using a console command like this:
    !set tmp2 cexp explosivepropertiesflags

    An example is if you want it to be set of by SPRK or if the pressure exceeds 3, and you want the explosion output to be PLSM regardless of the temperature of the explosion. For this you would use a calculator and add 4+8+32=44. Then you go to the console and type:
    !set tmp2 cexp 44

    If 32, 64, and 128 are all not set the explosion output of course is FIRE (unless the temperature is high enough for it to be PLSM instead).

    For these last three "explosion output" flags, if more than one of these is set, the one with the highest value takes precedence. This means if 32 and 64 are both set, it is the same as if 64 only is set. If all 3 are set, then it is the same as if only 128 is set.

    While it does explode slower than most explosives (almost like fast burning, unless you also make it pressure sensitive so it explodes quite quickly), its most important quality is that it explodes evenly (regardless of which side you light it on). This means that it it will explode at the same rate through the material if you light it off on the top, bottom, left, or right, unlike C4 which burns fast in one direction but explodes instantly in the other (due to scanning direction of TPT engine). My explosive has overcome this problem by having it take two passes to explode. The first pass checks if at least one of the conditions for explosion have been met. If it has, then it sets CTYPE to PT_FIRE (CTYPE is always PT_NONE by default). If on a given scan it detects that CTYPE is set to PT_FIRE then the explosion occurs. This means it takes 2 passes of TPT's scanning of the particles from when a trigger condition is applied to a particle of CEXP to when it actually explodes. By doing this it GUARANTIES it will explode evenly in all directions.

    In a practical application of the element you do ctrl+draw to make a box of this stuff, and then use the console !set commands for tmp, life, and tmp2 to get it configured how you want it. Finally, use the "s" key to save a stamp of this configured explosive. Now you can use it wherever you want to in your simulations. In fact I can EASILY see this element ending up in the official version of TPT at some point in the future.


    Here's the C code for this element:

    #include <element.h>

    int update_CEXP(UPDATE_FUNC_ARGS)
    {
    int r,rx,ry;
    if (parts[i].ctype==PT_FIRE){
    pv[y/CELL][x/CELL]+=parts[i].life;
    parts[i].temp=parts[i].tmp;
    parts[i].life=75;
    parts[i].type=PT_FIRE;
    if (parts[i].tmp2&32){
    parts[i].type=PT_PLSM;
    }
    if (parts[i].tmp2&64){
    parts[i].ctype=PT_BMTL;
    parts[i].type=PT_LAVA;
    }
    if (parts[i].tmp2&128){
    parts[i].type=PT_NONE;
    }
    } else {
    if (parts[i].tmp2&1){
    for (ry=-1;ry<2;ry++){
    for (rx=-1;rx<2;rx++){
    r=pmap[y+ry][x+rx];
    if (((r&0xff)==PT_FIRE)||((r&0xff)==PT_PLSM)){
    parts[i].ctype=PT_FIRE;
    }
    }
    }
    }
    if (parts[i].tmp2&2){
    for (ry=-1;ry<2;ry++){
    for (rx=-1;rx<2;rx++){
    r=pmap[y+ry][x+rx];
    if ((r&0xff)==PT_LAVA){
    parts[i].ctype=PT_FIRE;
    }
    }
    }
    }
    if (parts[i].tmp2&4){
    for (ry=-1;ry<2;ry++){
    for (rx=-1;rx<2;rx++){
    r=pmap[y+ry][x+rx];
    if ((r&0xff)==PT_SPRK){
    parts[i].ctype=PT_FIRE;
    }
    }
    }
    }
    if (((parts[i].tmp2&8)&&(pv[y/CELL][x/CELL]>=3.0f))||((parts[i].tmp2&16)&&(parts[i].temp>=500.0f))){
    parts[i].ctype=PT_FIRE;
    }
    }
    return 0;
    }
  • EqualsThree
    19th May 2012 Member 0 Permalink
    ..........

    You know, you can just release the mod when your done, you don't have to announce it to the public that "I'm almost gonna release my mod!"...
  • boxmein
    19th May 2012 Former Staff 0 Permalink
    Why thanks for listening to me and doing it yourself.
  • tommig
    19th May 2012 Member 0 Permalink
    No need for a new thread every time. No need to post every line of code either...
  • Videogamer555
    19th May 2012 Member 0 Permalink
    And it works AMAZINGLY WELL too!!!!! AWESOME ELEMENT!!!!! I can only hope that once I upload my mod the admins will see how awesome the element is and add it to the official TPT.
  • me4502
    19th May 2012 Member 0 Permalink
    Good for you.
  • Nab1929
    5th Jun 2012 Banned 0 Permalink
    This post is hidden because the user is banned
  • PacBrad
    6th Jun 2012 Banned 0 Permalink
    This post is hidden because the user is banned