Guest User

BANG.cpp?

a guest
May 17th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include "simulation/Elements.h"
  2. //#TPT-Directive ElementClass Element_BANG PT_BANG 139
  3. Element_BANG::Element_BANG()
  4. {
  5. Identifier = "DEFAULT_PT_BANG";
  6. Name = "TNT";
  7. Colour = PIXPACK(0xC05050);
  8. MenuVisible = 1;
  9. MenuSection = SC_EXPLOSIVE;
  10. Enabled = 1;
  11.  
  12. Advection = 0.0f;
  13. AirDrag = 0.00f * CFDS;
  14. AirLoss = 0.90f;
  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 = 1;
  24. Meltable = 0;
  25. Hardness = 1;
  26.  
  27. Weight = 100;
  28.  
  29. Temperature = R_TEMP+0.0f +273.15f;
  30. HeatConduct = 88;
  31. Description = "TNT, explodes all at once.";
  32.  
  33. State = ST_SOLID;
  34. Properties = TYPE_SOLID | PROP_NEUTPENETRATE;
  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_BANG::update;
  46.  
  47. }
  48.  
  49. //#TPT-Directive ElementHeader Element_BANG static int update(UPDATE_FUNC_ARGS)
  50. int Element_BANG::update(UPDATE_FUNC_ARGS)
  51. {
  52. int r, rx, ry, nb;
  53. if(parts[i].tmp==0)
  54. {
  55. if(parts[i].temp>=673.0f)
  56. parts[i].tmp = 1;
  57. else
  58. for (rx=-1; rx<2; rx++)
  59. for (ry=-1; ry<2; ry++)
  60. if (BOUNDS_CHECK && (rx || ry))
  61. {
  62. r = pmap[y+ry][x+rx];
  63. if (!r)
  64. continue;
  65. if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH)
  66. {
  67. parts[i].tmp = 1;
  68. }
  69. if ((r&0xFF)==PT_EXOT && (r&0xFF)==PT_BBNG)
  70. {
  71. sim->part_change_type(i,x,y,PT_BBNG);
  72. }
  73. }
  74.  
  75. }
  76. else if(parts[i].tmp==1)
  77. {
  78. if ((pmap[y][x]>>8 == i))
  79. {
  80. PropertyValue value;
  81. value.Integer = 2;
  82. sim->flood_prop(x, y, offsetof(Particle, tmp), value, StructProperty::Integer);
  83. }
  84. parts[i].tmp = 2;
  85. }
  86. else if(parts[i].tmp==2)
  87. {
  88. parts[i].tmp = 3;
  89. }
  90. else
  91. {
  92. float otemp = parts[i].temp-273.15f;
  93. //Explode!!
  94. sim->pv[y/CELL][x/CELL] += 0.5f;
  95. parts[i].tmp = 0;
  96. if(!(rand()%3))
  97. {
  98. if(!(rand()%2))
  99. {
  100. sim->create_part(i, x, y, PT_FIRE);
  101. }
  102. else
  103. {
  104. sim->create_part(i, x, y, PT_SMKE);
  105. parts[i].life = rand()%50+500;
  106. }
  107. parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
  108. }
  109. else
  110. {
  111. if(!(rand()%15))
  112. {
  113. sim->create_part(i, x, y, PT_EMBR);
  114. parts[i].tmp = 0;
  115. parts[i].life = 50;
  116. parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP);
  117. parts[i].vx = rand()%20-10;
  118. parts[i].vy = rand()%20-10;
  119. }
  120. else
  121. {
  122. sim->kill_part(i);
  123. }
  124. }
  125. return 1;
  126. }
  127. return 0;
  128. }
  129.  
  130.  
  131. Element_BANG::~Element_BANG() {}
Advertisement
Add Comment
Please, Sign In to add comment