1 #include "simulation/ElementCommon.h"
2 #include "simulation/Air.h"
3
4 static int update(UPDATE_FUNC_ARGS);
5 static int graphics(GRAPHICS_FUNC_ARGS);
6
Element_TUNG()7 void Element::Element_TUNG()
8 {
9 Identifier = "DEFAULT_PT_TUNG";
10 Name = "TUNG";
11 Colour = PIXPACK(0x505050);
12 MenuVisible = 1;
13 MenuSection = SC_ELEC;
14 Enabled = 1;
15
16 Advection = 0.0f;
17 AirDrag = 0.00f * CFDS;
18 AirLoss = 0.90f;
19 Loss = 0.00f;
20 Collision = 0.0f;
21 Gravity = 0.0f;
22 Diffusion = 0.00f;
23 HotAir = 0.000f * CFDS;
24 Falldown = 0;
25
26 Flammable = 0;
27 Explosive = 0;
28 Meltable = 1;
29 Hardness = 1;
30
31 Weight = 100;
32
33 HeatConduct = 251;
34 Description = "Tungsten. Brittle metal with a very high melting point.";
35
36 Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC;
37
38 LowPressure = IPL;
39 LowPressureTransition = NT;
40 HighPressure = IPH;
41 HighPressureTransition = NT;
42 LowTemperature = ITL;
43 LowTemperatureTransition = NT;
44 HighTemperature = 3695.0f;// TUNG melts in its update function instead of in the normal way, but store the threshold here so that it can be changed from Lua
45 HighTemperatureTransition = NT;
46
47 Update = &update;
48 Graphics = &graphics;
49 }
50
update(UPDATE_FUNC_ARGS)51 static int update(UPDATE_FUNC_ARGS)
52 {
53 bool splode = false;
54 const float MELTING_POINT = sim->elements[PT_TUNG].HighTemperature;
55
56 if(parts[i].temp > 2400.0)
57 {
58 int r, rx, ry;
59 for (rx=-1; rx<2; rx++)
60 for (ry=-1; ry<2; ry++)
61 if (BOUNDS_CHECK && (rx || ry))
62 {
63 r = pmap[y+ry][x+rx];
64 if(TYP(r) == PT_O2)
65 {
66 splode = true;
67 }
68 }
69 }
70 if((parts[i].temp > MELTING_POINT && RNG::Ref().chance(1, 20)) || splode)
71 {
72 if (RNG::Ref().chance(1, 50))
73 {
74 sim->pv[y/CELL][x/CELL] += 50.0f;
75 }
76 else if (RNG::Ref().chance(1, 100))
77 {
78 sim->part_change_type(i, x, y, PT_FIRE);
79 parts[i].life = RNG::Ref().between(0, 499);
80 return 1;
81 }
82 else
83 {
84 sim->part_change_type(i, x, y, PT_LAVA);
85 parts[i].ctype = PT_TUNG;
86 return 1;
87 }
88 if(splode)
89 {
90 parts[i].temp = restrict_flt(MELTING_POINT + RNG::Ref().between(200, 799), MIN_TEMP, MAX_TEMP);
91 }
92 parts[i].vx += RNG::Ref().between(-50, 50);
93 parts[i].vy += RNG::Ref().between(-50, 50);
94 return 1;
95 }
96 parts[i].pavg[0] = parts[i].pavg[1];
97 parts[i].pavg[1] = sim->pv[y/CELL][x/CELL];
98 float diff = parts[i].pavg[1] - parts[i].pavg[0];
99 if (diff > 0.50f || diff < -0.50f)
100 {
101 sim->part_change_type(i,x,y,PT_BRMT);
102 parts[i].ctype = PT_TUNG;
103 return 1;
104 }
105 return 0;
106 }
107
graphics(GRAPHICS_FUNC_ARGS)108 static int graphics(GRAPHICS_FUNC_ARGS)
109 {
110 const float MELTING_POINT = ren->sim->elements[PT_TUNG].HighTemperature;
111 double startTemp = (MELTING_POINT - 1500.0);
112 double tempOver = (((cpart->temp - startTemp)/1500.0)*M_PI) - (M_PI/2.0);
113 if(tempOver > -(M_PI/2.0))
114 {
115 if(tempOver > (M_PI/2.0))
116 tempOver = (M_PI/2.0);
117 double gradv = sin(tempOver) + 1.0;
118 *firer = (int)(gradv * 258.0);
119 *fireg = (int)(gradv * 156.0);
120 *fireb = (int)(gradv * 112.0);
121 *firea = 30;
122
123 *colr += *firer;
124 *colg += *fireg;
125 *colb += *fireb;
126 *pixel_mode |= FIRE_ADD;
127 }
128 return 0;
129 }
130