1 #include "simulation/ElementCommon.h"
2
3 static int update(UPDATE_FUNC_ARGS);
4
Element_PSNS()5 void Element::Element_PSNS()
6 {
7 Identifier = "DEFAULT_PT_PSNS";
8 Name = "PSNS";
9 Colour = PIXPACK(0xDB2020);
10 MenuVisible = 1;
11 MenuSection = SC_SENSOR;
12 Enabled = 1;
13
14 Advection = 0.0f;
15 AirDrag = 0.00f * CFDS;
16 AirLoss = 0.96f;
17 Loss = 0.00f;
18 Collision = 0.0f;
19 Gravity = 0.0f;
20 Diffusion = 0.00f;
21 HotAir = 0.000f * CFDS;
22 Falldown = 0;
23
24 Flammable = 0;
25 Explosive = 0;
26 Meltable = 0;
27 Hardness = 1;
28
29 Weight = 100;
30
31 DefaultProperties.temp = 4.0f + 273.15f;
32 HeatConduct = 0;
33 Description = "Pressure sensor, creates a spark when the pressure is greater than its temperature.";
34
35 Properties = TYPE_SOLID;
36
37 LowPressure = IPL;
38 LowPressureTransition = NT;
39 HighPressure = IPH;
40 HighPressureTransition = NT;
41 LowTemperature = ITL;
42 LowTemperatureTransition = NT;
43 HighTemperature = ITH;
44 HighTemperatureTransition = NT;
45
46 Update = &update;
47 }
48
update(UPDATE_FUNC_ARGS)49 static int update(UPDATE_FUNC_ARGS)
50 {
51 int r, rx, ry, rt;
52 if ((parts[i].tmp == 0 && sim->pv[y/CELL][x/CELL] > parts[i].temp-273.15f) || (parts[i].tmp == 2 && sim->pv[y/CELL][x/CELL] < parts[i].temp-273.15f))
53 {
54 parts[i].life = 0;
55 for (rx = -2; rx <= 2; rx++)
56 for (ry = -2; ry <= 2; ry++)
57 if (BOUNDS_CHECK && (rx || ry))
58 {
59 r = pmap[y+ry][x+rx];
60 if (!r)
61 continue;
62 if (sim->parts_avg(i,ID(r),PT_INSL) != PT_INSL)
63 {
64 rt = TYP(r);
65 if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0)
66 {
67 parts[ID(r)].life = 4;
68 parts[ID(r)].ctype = rt;
69 sim->part_change_type(ID(r),x+rx,y+ry,PT_SPRK);
70 }
71 }
72 }
73 }
74 if (parts[i].tmp == 1)
75 {
76 parts[i].life = 0;
77 bool setFilt = true;
78 float photonWl = sim->pv[y / CELL][x / CELL];
79 if (setFilt)
80 {
81 int nx, ny;
82 for (rx = -1; rx <= 1; rx++)
83 for (ry = -1; ry <= 1; ry++)
84 if (BOUNDS_CHECK && (rx || ry))
85 {
86 r = pmap[y + ry][x + rx];
87 if (!r)
88 continue;
89 nx = x + rx;
90 ny = y + ry;
91 while (TYP(r) == PT_FILT)
92 {
93 parts[ID(r)].ctype = 0x10000000 + roundl(photonWl) + 256;
94 nx += rx;
95 ny += ry;
96 if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)
97 break;
98 r = pmap[ny][nx];
99 }
100 }
101 }
102 }
103 return 0;
104 }
105