1 #include "simulation/ElementCommon.h" 2 3 static int update(UPDATE_FUNC_ARGS); 4 Element_TSNS()5void Element::Element_TSNS() 6 { 7 Identifier = "DEFAULT_PT_TSNS"; 8 Name = "TSNS"; 9 Colour = PIXPACK(0xFD00D5); 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 HeatConduct = 0; 32 Description = "Temperature sensor, creates a spark when there's a nearby particle with a greater temperature."; 33 34 Properties = TYPE_SOLID; 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 DefaultProperties.tmp2 = 2; 46 47 Update = &update; 48 } 49 update(UPDATE_FUNC_ARGS)50static int update(UPDATE_FUNC_ARGS) 51 { 52 int rd = parts[i].tmp2; 53 if (rd > 25) 54 parts[i].tmp2 = rd = 25; 55 if (parts[i].life) 56 { 57 parts[i].life = 0; 58 for (int rx = -2; rx <= 2; rx++) 59 for (int ry = -2; ry <= 2; ry++) 60 if (BOUNDS_CHECK && (rx || ry)) 61 { 62 int r = pmap[y+ry][x+rx]; 63 if (!r) 64 continue; 65 int rt = TYP(r); 66 if (sim->parts_avg(i, ID(r), PT_INSL) != PT_INSL) 67 { 68 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) 69 { 70 parts[ID(r)].life = 4; 71 parts[ID(r)].ctype = rt; 72 sim->part_change_type(ID(r), x+rx, y+ry, PT_SPRK); 73 } 74 } 75 } 76 } 77 bool setFilt = false; 78 int photonWl = 0; 79 for (int rx = -rd; rx <= rd; rx++) 80 for (int ry = -rd; ry <= rd; ry++) 81 if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) 82 { 83 int r = pmap[y+ry][x+rx]; 84 if (!r) 85 r = sim->photons[y+ry][x+rx]; 86 if (!r) 87 continue; 88 if (parts[i].tmp == 0 && TYP(r) != PT_TSNS && TYP(r) != PT_METL && parts[ID(r)].temp > parts[i].temp) 89 parts[i].life = 1; 90 if (parts[i].tmp == 2 && TYP(r) != PT_TSNS && TYP(r) != PT_METL && parts[ID(r)].temp < parts[i].temp) 91 parts[i].life = 1; 92 if (parts[i].tmp == 1 && TYP(r) != PT_TSNS && TYP(r) != PT_FILT) 93 { 94 setFilt = true; 95 photonWl = parts[ID(r)].temp; 96 } 97 } 98 if (setFilt) 99 { 100 int nx, ny; 101 for (int rx = -1; rx <= 1; rx++) 102 for (int ry = -1; ry <= 1; ry++) 103 if (BOUNDS_CHECK && (rx || ry)) 104 { 105 int r = pmap[y+ry][x+rx]; 106 if (!r) 107 continue; 108 nx = x + rx; 109 ny = y + ry; 110 while (TYP(r) == PT_FILT) 111 { 112 parts[ID(r)].ctype = 0x10000000 + photonWl; 113 nx += rx; 114 ny += ry; 115 if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) 116 break; 117 r = pmap[ny][nx]; 118 } 119 } 120 } 121 return 0; 122 } 123