Advertisement
Guest User

randals mod

a guest
Jun 2nd, 2011
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.20 KB | None | 0 0
  1. #include <element.h>
  2.  
  3. int update_SPRK(UPDATE_FUNC_ARGS) {
  4.     int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype;
  5.     update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
  6.  
  7.     if (parts[i].life<=0)
  8.     {
  9.         if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD||ct==PT_INWR||ct==MERC||ct==FLRC)
  10.             parts[i].temp = R_TEMP + 273.15f;
  11.         if (!ct)
  12.             ct = PT_METL;
  13.         part_change_type(i,x,y,ct);
  14.         parts[i].ctype = PT_NONE;
  15.         parts[i].life = 4;
  16.         if (ct == PT_WATR)
  17.             parts[i].life = 64;
  18.         if (ct == PT_SLTW)
  19.             parts[i].life = 54;
  20.         if (ct == PT_SWCH)
  21.             parts[i].life = 14;
  22.         return 0;
  23.     }
  24.     if (ct==PT_SPRK)
  25.     {
  26.         kill_part(i);
  27.         return 1;
  28.     }
  29.     else if (ct==PT_NTCT || ct==PT_PTCT)
  30.     {
  31.         update_NPTCT(UPDATE_FUNC_SUBCALL_ARGS);
  32.     }
  33.     else if (ct==PT_ETRD&&parts[i].life==1)
  34.     {
  35.         nearp = nearest_part(i, PT_ETRD);
  36.         if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL)
  37.         {
  38.             create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM);
  39.             part_change_type(i,x,y,ct);
  40.             ct = parts[i].ctype = PT_NONE;
  41.             parts[i].life = 20;
  42.             part_change_type(nearp,(int)(parts[nearp].x+0.5f),(int)(parts[nearp].y+0.5f),PT_SPRK);
  43.             parts[nearp].life = 9;
  44.             parts[nearp].ctype = PT_ETRD;
  45.         }
  46.     }
  47.     else if (ct==PT_NBLE&&parts[i].life<=1)
  48.     {
  49.         parts[i].life = rand()%150+50;
  50.         part_change_type(i,x,y,PT_PLSM);
  51.         parts[i].ctype = PT_NBLE;
  52.         parts[i].temp = 3500;
  53.         pv[y/CELL][x/CELL] += 1;
  54.     }
  55.     else if (ct==PT_FLRC&&parts[i].life<=1&&parts[r>>8].type=PT_MERC)
  56.     {
  57.         parts[i].life = rand()%150+90;
  58.         parts_change_type(i,x,y) (PT_PLSM);
  59.         parts[i].ctype = PT_FLRC;
  60.         parts[i].temp = 100;
  61.         pv[y/CELL][x/CELL]+=0.5;
  62.     }
  63.     else if (ct==PT_IRON) {
  64.         for (rx=-1; rx<2; rx++)
  65.             for (ry=-1; ry<2; ry++)
  66.                 if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  67.                 {
  68.                     r = pmap[y+ry][x+rx];
  69.                     if ((r>>8)>=NPART || !r)
  70.                         continue;
  71.                     if (((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) ||
  72.                             ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) ||
  73.                             ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000))))
  74.                     {
  75.                         if (rand()<RAND_MAX/3)
  76.                             part_change_type(r>>8,x+rx,y+ry,PT_O2);
  77.                         else
  78.                             part_change_type(r>>8,x+rx,y+ry,PT_H2);
  79.                     }
  80.                 }
  81.     }
  82.     for (rx=-2; rx<3; rx++)
  83.         for (ry=-2; ry<3; ry++)
  84.             if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  85.             {
  86.                 r = pmap[y+ry][x+rx];
  87.                 if ((r>>8)>=NPART || !r)
  88.                     continue;
  89.                 rt = parts[r>>8].type;
  90.                 conduct_sprk = 1;
  91.  
  92.  
  93.                 pavg = parts_avg(r>>8, i,PT_INSL);
  94.                 if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL) // make sparked SWCH turn off correctly
  95.                 {
  96.                     if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) {
  97.                         parts[r>>8].life = 10;
  98.                     }
  99.                     if (ct==PT_NSCN) {
  100.                         part_change_type(r>>8,x+rx,y+ry,PT_SWCH);
  101.                         parts[r>>8].ctype = PT_NONE;
  102.                         parts[r>>8].life = 9;
  103.                     }
  104.                 }
  105.                 else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_HSWC||(rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2)))
  106.                 {
  107.                     if (ct==PT_PSCN) parts[r>>8].life = 10;
  108.                     else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9;
  109.                 }
  110.  
  111.  
  112.                 // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed
  113.  
  114.                 if (pavg == PT_INSL) conduct_sprk = 0;
  115.                 if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST||rt==PT_QRTZ)) conduct_sprk = 0;
  116.                 if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH)
  117.                     conduct_sprk = 0;
  118.  
  119.  
  120.                 if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL)
  121.                 {
  122.                     parts[r>>8].temp = 473.0f;
  123.                     if (rt==PT_NTCT||rt==PT_PTCT)
  124.                         conduct_sprk = 0;
  125.                 }
  126.                 if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f)))
  127.                     conduct_sprk = 0;
  128.                 if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f)))
  129.                     conduct_sprk = 0;
  130.                 if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN))
  131.                     conduct_sprk = 0;
  132.                 if (ct==PT_NSCN && rt==PT_PSCN)
  133.                     conduct_sprk = 0;
  134.                 if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN))
  135.                     conduct_sprk = 0;
  136.                 if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0;
  137.                 if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR))
  138.                     conduct_sprk = 0;
  139.                 if (rt==PT_QRTZ && !((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||pv[(y+ry)/CELL][(x+rx)/CELL]>8)))
  140.                     conduct_sprk = 0;
  141.                 if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)))
  142.                     conduct_sprk = 0;
  143.                 if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)))
  144.                     conduct_sprk = 0;
  145.                 if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN))
  146.                     conduct_sprk = 0;
  147.                 if (rt==PT_INST&&ct!=PT_PSCN)
  148.                     conduct_sprk = 0;
  149.  
  150.                 if (conduct_sprk) {
  151.                     if (rt==PT_WATR||rt==PT_SLTW) {
  152.                         if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)))
  153.                         {
  154.                             part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
  155.                             if (rt==PT_WATR) parts[r>>8].life = 6;
  156.                             else parts[r>>8].life = 5;
  157.                             parts[r>>8].ctype = rt;
  158.                         }
  159.                     }
  160.                     else if (rt==PT_INST) {
  161.                         if (parts[i].life>=3&&parts[r>>8].life==0)
  162.                         {
  163.                             flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1);//spark the wire
  164.                         }
  165.                     }
  166.                     else if (parts[r>>8].life==0 && (parts[i].life<3 || ((r>>8)<i && parts[i].life<4))) {
  167.                         parts[r>>8].life = 4;
  168.                         parts[r>>8].ctype = rt;
  169.                         part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
  170.                         if (parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON))
  171.                             parts[r>>8].temp = parts[r>>8].temp+10.0f;
  172.                     }
  173.                     else if (ct==PT_ETRD && parts[i].life==5)
  174.                     {
  175.                         part_change_type(i,x,y,ct);
  176.                         parts[i].ctype = PT_NONE;
  177.                         parts[i].life = 20;
  178.                         parts[r>>8].life = 4;
  179.                         parts[r>>8].ctype = rt;
  180.                         part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
  181.                     }
  182.                 }
  183.             }
  184.     return 0;
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement