Guest User

Untitled

a guest
Sep 18th, 2011
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 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)
  10. parts[i].temp = R_TEMP + 273.15f;
  11. if (ct<=0 || ct>=PT_NUM)
  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_IRON) {
  56. for (rx=-1; rx<2; rx++)
  57. for (ry=-1; ry<2; ry++)
  58. if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  59. {
  60. r = pmap[y+ry][x+rx];
  61. if ((r>>8)>=NPART || !r)
  62. continue;
  63. if (((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) ||
  64. ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) ||
  65. ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000))))
  66. {
  67. if (rand()<RAND_MAX/3)
  68. part_change_type(r>>8,x+rx,y+ry,PT_O2);
  69. else
  70. part_change_type(r>>8,x+rx,y+ry,PT_H2);
  71. }
  72. }
  73. }
  74. for (rx=-2; rx<3; rx++)
  75. for (ry=-2; ry<3; ry++)
  76. if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  77. {
  78. r = pmap[y+ry][x+rx];
  79. if ((r>>8)>=NPART || !r)
  80. continue;
  81. rt = parts[r>>8].type;
  82. conduct_sprk = 1;
  83.  
  84.  
  85. pavg = parts_avg(r>>8, i,PT_INSL);
  86. if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL) // make sparked SWCH turn off correctly
  87. {
  88. if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) {
  89. parts[r>>8].life = 10;
  90. }
  91. if (ct==PT_NSCN) {
  92. part_change_type(r>>8,x+rx,y+ry,PT_SWCH);
  93. parts[r>>8].ctype = PT_NONE;
  94. parts[r>>8].life = 9;
  95. }
  96. }
  97. else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN||(rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2))) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves
  98. {
  99. if (ct==PT_PSCN) parts[r>>8].life = 10;
  100. else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9;
  101. }
  102.  
  103.  
  104. // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed
  105.  
  106. if (pavg == PT_INSL) conduct_sprk = 0;
  107. if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST||rt==PT_QRTZ||rt==PT_SPCR)) conduct_sprk = 0;
  108. if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH)
  109. conduct_sprk = 0;
  110.  
  111.  
  112. 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)
  113. {
  114. parts[r>>8].temp = 473.0f;
  115. if (rt==PT_NTCT||rt==PT_PTCT)
  116. conduct_sprk = 0;
  117. }
  118. if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f)))
  119. conduct_sprk = 0;
  120. if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f)))
  121. conduct_sprk = 0;
  122. if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN))
  123. conduct_sprk = 0;
  124. if (ct==PT_NSCN && rt==PT_PSCN)
  125. conduct_sprk = 0;
  126. if (ct==PT_SPCR && !parts[i].temp<=73.15f)
  127. conduct_sprk = 0;
  128. 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))
  129. conduct_sprk = 0;
  130. if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0;
  131. 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))
  132. conduct_sprk = 0;
  133. 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)))
  134. conduct_sprk = 0;
  135. if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)))
  136. conduct_sprk = 0;
  137. if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)))
  138. conduct_sprk = 0;
  139. if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN))
  140. conduct_sprk = 0;
  141. if (rt==PT_INST&&ct!=PT_PSCN)
  142. conduct_sprk = 0;
  143.  
  144. if (conduct_sprk) {
  145. if (rt==PT_WATR||rt==PT_SLTW) {
  146. if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)))
  147. {
  148. part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
  149. if (rt==PT_WATR) parts[r>>8].life = 6;
  150. else parts[r>>8].life = 5;
  151. parts[r>>8].ctype = rt;
  152. }
  153. }
  154. else if (rt==PT_INST) {
  155. if (parts[i].life>=3&&parts[r>>8].life==0)
  156. {
  157. flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1);//spark the wire
  158. }
  159. }
  160. else if (rt==PT_SPCR) {
  161. if (parts[i].life>=3&&parts[r>>8].life==0)
  162. {
  163. flood_parts(x+rx,y+ry,PT_SPRK,PT_SPCR,-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