Nitrous decompostion code

  • tommig
    18th Jan 2012 Member 0 Permalink
    Hi again! :-)
    I was putting all of the elements back into my mod, when I noticed that the Nitrous (NTRO here) decomposition code was not working. I looked at the code, and I can't find a reason why it doesn't work.

    if(pv[y/CELL][x/CELL]>0.0 && 1>(rand()%1000));{
                  if (1>rand()%3)
                    create_part(i,x,y,PT_O2);
                  else   
                    create_part(i,x,y,PT_NTRG);
                    }

    I want the element to, under pressure, break down into nitrogen and oxygen as an oxideiser for engines, but it won't work.

    Thanks
    Tommig
  • jacksonmj
    18th Jan 2012 Developer 0 Permalink
    In what way does it not work? If it always breaks down instantly, that is due to the rogue semicolon just before the '{'.

    After removing that, it works fine for me. So if "does not work" means it isn't breaking down at all, the problem is elsewhere in your code.

    if(pv[y/CELL][x/CELL]>0.0 && 1>(rand()%1000)){
  • tommig
    18th Jan 2012 Member 0 Permalink
    @jacksonmj (View Post)
    Right, ok. Well it must be somewhere else, I'll look at my update codes, I keep mis-abreviating it.
    EDIT:
    The problem is not in the update codes
    EDIT again:
    My full code

    #include <element.h>

    int update_NTRO(UPDATE_FUNC_ARGS) {
       int r, rx, ry;
            for(rx=-1; rx<2; rx++)
                for(ry=-1; ry<2; ry++)
                    if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES &&
                    pmap[y+ry][x+rx] &&
                    (pmap[y+ry][x+rx]&0xFF)!=PT_NTRO&&
                    (pmap[y+ry][x+rx]&0xFF)!=0xFF)
                    {
                        r = pmap[y+ry][x+rx];
                    if(pv[y/CELL][x/CELL]>0.0 && (1>rand()%1000))
                    {
                        if(1>rand()%3) create_part(i,x,y,PT_O2);
                        else
                        create_part(i,x,y,PT_NTRG);
                    }
                    if(pv[y/CELL][x/CELL]>10.0){
                        if ((r&0xFF)==PT_FIRE (r&0xFF)==PT_PLSM)
                        {
                            part_change_type(i,x,y,PT_FIRE);
                        }
                    }               
                    if ((r&0xFF)==PT_HEXN (r&0xFF)==PT_HEXV)
                    {
                        part_change_type(i,x,y,PT_NITR);
                        kill_part(r>>8);
                    }
        }
                    return 0;
    }

  • tommig
    18th Jan 2012 Member 0 Permalink
    Fixed it!
    For reference, the code should look like this:

    #include <element.h>

    int update_NTRO(UPDATE_FUNC_ARGS) {
       int r, rx, ry;
       if(pv[y/CELL][x/CELL]>1.0 && (1>rand()%500))
                    {
                        if(1>rand()%3) create_part(i,x,y,PT_O2);
                        else
                        create_part(i,x,y,PT_NTRG);
                    }
       else
            for(rx=-1; rx<2; rx++)
                for(ry=-1; ry<2; ry++)
                    if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES &&
                    pmap[y+ry][x+rx] &&
                    (pmap[y+ry][x+rx]&0xFF)!=PT_NTRO&&
                    (pmap[y+ry][x+rx]&0xFF)!=0xFF)
                    {
                    r = pmap[y+ry][x+rx];
                    if(pv[y/CELL][x/CELL]>10.0){
                        if ((r&0xFF)==PT_FIRE (r&0xFF)==PT_PLSM)
                        {
                            part_change_type(i,x,y,PT_FIRE);
                        }
                    }               
                    if ((r&0xFF)==PT_HEXN (r&0xFF)==PT_HEXV)
                    {
                        part_change_type(i,x,y,PT_NITR);
                        kill_part(r>>8);
                    }
        }
                    return 0;
    }