Advertisement
tommig

Untitled

Nov 11th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. #include "simulation/Elements.h"
  2. //#TPT-Directive ElementClass Element_VIBR PT_VIBR 165
  3. Element_VIBR::Element_VIBR()
  4. {
  5. Identifier = "DEFAULT_PT_VIBR";
  6. Name = "VIBR";
  7. Colour = PIXPACK(0x005000);
  8. MenuVisible = 1;
  9. MenuSection = SC_NUCLEAR;
  10. Enabled = 1;
  11.  
  12. Advection = 0.0f;
  13. AirDrag = 0.00f * CFDS;
  14. AirLoss = 0.85f;
  15. Loss = 0.00f;
  16. Collision = 0.0f;
  17. Gravity = 0.0f;
  18. Diffusion = 0.00f;
  19. HotAir = 0.000f * CFDS;
  20. Falldown = 0;
  21.  
  22. Flammable = 0;
  23. Explosive = 0;
  24. Meltable = 0;
  25. Hardness = 0;
  26.  
  27. Weight = 100;
  28.  
  29. Temperature = 273.15f;
  30. HeatConduct = 251;
  31. Description = "Vibranium. Stores energy and releases it in violent explosions.";
  32.  
  33. State = ST_SOLID;
  34. Properties = TYPE_SOLID|PROP_LIFE_DEC;
  35.  
  36. LowPressure = IPL;
  37. LowPressureTransition = NT;
  38. HighPressure = IPH;
  39. HighPressureTransition = NT;
  40. LowTemperature = ITL;
  41. LowTemperatureTransition = NT;
  42. HighTemperature = ITH;
  43. HighTemperatureTransition = NT;
  44.  
  45. Update = &Element_VIBR::update;
  46. Graphics = &Element_VIBR::graphics;
  47. }
  48.  
  49. //#TPT-Directive ElementHeader Element_VIBR static int update(UPDATE_FUNC_ARGS)
  50. int Element_VIBR::update(UPDATE_FUNC_ARGS) {
  51. int r, rx, ry;
  52. int trade, transfer;
  53. if (parts[i].ctype == 1) //leaving in, just because
  54. {
  55. if (sim->pv[y/CELL][x/CELL] > -2.5 || parts[i].tmp)
  56. {
  57. parts[i].ctype = 0;
  58. sim->part_change_type(i, x, y, PT_VIBR);
  59. }
  60. }
  61. else if (!parts[i].life) //if not exploding
  62. {
  63. //Heat absorption code
  64. if (parts[i].temp > 274.65f)
  65. {
  66. parts[i].tmp++;
  67. parts[i].temp -= 3;
  68. }
  69. if (parts[i].temp < 271.65f)
  70. {
  71. parts[i].tmp--;
  72. parts[i].temp += 3;
  73. }
  74. //Pressure absorption code
  75. if (sim->pv[y/CELL][x/CELL] > 2.5)
  76. {
  77. parts[i].tmp += 7;
  78. sim->pv[y/CELL][x/CELL]--;
  79. }
  80. if (sim->pv[y/CELL][x/CELL] < -2.5)
  81. {
  82. parts[i].tmp -= 2;
  83. sim->pv[y/CELL][x/CELL]++;
  84. }
  85. //initiate explosion counter
  86. if (parts[i].tmp > 1000)
  87. parts[i].life = 750;
  88. }
  89. else //if it is exploding
  90. {
  91. //Release sparks before explode
  92. if (parts[i].life < 300)
  93. {
  94. rx = rand()%3-1;
  95. ry = rand()%3-1;
  96. r = pmap[y+ry][x+rx];
  97. if ((r&0xFF) && (r&0xFF) != PT_BREC && (sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && !parts[r>>8].life)
  98. {
  99. parts[r>>8].life = 4;
  100. parts[r>>8].ctype = r&0xFF;
  101. sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
  102. }
  103. }
  104. //Release all heat
  105. if (parts[i].life < 500)
  106. {
  107. int random = rand();
  108. rx = random%7-3;
  109. ry = (random>>3)%7-3;
  110. if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES)
  111. {
  112. r = pmap[y+ry][x+rx];
  113. if ((r&0xFF) && (r&0xFF)!=PT_VIBR && (r&0xFF)!=PT_BVBR && sim->elements[r&0xFF].HeatConduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10))
  114. {
  115. parts[r>>8].temp += parts[i].tmp*3;
  116. parts[i].tmp = 0;
  117. }
  118. }
  119. }
  120. //Explosion code
  121. if (parts[i].life == 1)
  122. {
  123. int random = rand(), index;
  124. sim->create_part(i, x, y, PT_EXOT);
  125. parts[i].tmp2 = rand()%1000;
  126. index = sim->create_part(-3,x+((random>>4)&3)-1,y+((random>>6)&3)-1,PT_ELEC);
  127. if (index != -1)
  128. parts[index].temp = 7000;
  129. index = sim->create_part(-3,x+((random>>8)&3)-1,y+((random>>10)&3)-1,PT_PHOT);
  130. if (index != -1)
  131. parts[index].temp = 7000;
  132. index = sim->create_part(-1,x+((random>>12)&3)-1,y+rand()%3-1,PT_BREC);
  133. if (index != -1)
  134. parts[index].temp = 7000;
  135. parts[i].temp=9000;
  136. sim->pv[y/CELL][x/CELL] += 50;
  137.  
  138. return 1;
  139. }
  140. }
  141. //Neighbor check loop
  142. for (rx=-2; rx<3; rx++)
  143. for (ry=-2; ry<3; ry++)
  144. if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  145. {
  146. r = pmap[y+ry][x+rx];
  147. if (!r)
  148. r = sim->photons[y+ry][x+rx];
  149. if (!r)
  150. continue;
  151. //Melts into EXOT
  152. if ((r&0xFF) == PT_EXOT && !(rand()%250))
  153. {
  154. sim->create_part(i, x, y, PT_EXOT);
  155. }
  156. else if ((r&0xFF) == PT_ANAR)
  157. {
  158. sim->part_change_type(i,x,y,PT_BVBR);
  159. sim->pv[y/CELL][x/CELL] -= 1;
  160. }
  161. else if (parts[i].life && ((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR) && !parts[r>>8].life)
  162. {
  163. parts[r>>8].tmp += 10;
  164. }
  165. //Absorbs energy particles
  166. if ((sim->elements[r&0xFF].Properties & TYPE_ENERGY))
  167. {
  168. parts[i].tmp += 20;
  169. sim->kill_part(r>>8);
  170. }
  171. }
  172. for (trade = 0; trade < 9; trade++)
  173. {
  174. int random = rand();
  175. rx = random%7-3;
  176. ry = (random>>3)%7-3;
  177. if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
  178. {
  179. r = pmap[y+ry][x+rx];
  180. if ((r&0xFF) != PT_VIBR && (r&0xFF) != PT_BVBR)
  181. continue;
  182. if (parts[i].tmp > parts[r>>8].tmp)
  183. {
  184. transfer = parts[i].tmp - parts[r>>8].tmp;
  185. if (transfer == 1)
  186. {
  187. parts[r>>8].tmp += 1;
  188. parts[i].tmp -= 1;
  189. trade = 9;
  190. }
  191. else if (transfer > 0)
  192. {
  193. parts[r>>8].tmp += transfer/2;
  194. parts[i].tmp -= transfer/2;
  195. trade = 9;
  196. }
  197. }
  198. }
  199. }
  200. if (parts[i].tmp < 0)
  201. parts[i].tmp = 0; // only preventing because negative tmp doesn't save
  202. return 0;
  203. }
  204.  
  205. //#TPT-Directive ElementHeader Element_VIBR static int graphics(GRAPHICS_FUNC_ARGS)
  206. int Element_VIBR::graphics(GRAPHICS_FUNC_ARGS)
  207. {
  208. int gradient = cpart->tmp/10;
  209. if (gradient >= 100 || cpart->life)
  210. {
  211. *colr = (int)(fabs(sin(exp((750.0f-cpart->life)/170)))*200.0f);
  212. *colg = 255;
  213. *colb = (int)(fabs(sin(exp((750.0f-cpart->life)/170)))*200.0f);
  214. *firea = 90;
  215. *firer = *colr;
  216. *fireg = *colg;
  217. *fireb = *colb;
  218. *pixel_mode = PMODE_NONE;
  219. *pixel_mode |= FIRE_BLEND;
  220. }
  221. else if (gradient < 100)
  222. {
  223. *colr += (int)restrict_flt(gradient*2.0f,0,255);
  224. *colg += (int)restrict_flt(gradient*2.0f,0,175);
  225. *colb += (int)restrict_flt(gradient*2.0f,0,255);
  226. *firea = (int)restrict_flt(gradient*.6f,0,60);
  227. *firer = *colr/2;
  228. *fireg = *colg/2;
  229. *fireb = *colb/2;
  230. *pixel_mode |= FIRE_BLEND;
  231. }
  232. return 0;
  233. }
  234.  
  235. Element_VIBR::~Element_VIBR() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement