1 #include "simulation/ElementCommon.h"
2 
3 static int update(UPDATE_FUNC_ARGS);
4 static int graphics(GRAPHICS_FUNC_ARGS);
5 
Element_WIFI()6 void Element::Element_WIFI()
7 {
8 	Identifier = "DEFAULT_PT_WIFI";
9 	Name = "WIFI";
10 	Colour = PIXPACK(0x40A060);
11 	MenuVisible = 1;
12 	MenuSection = SC_ELEC;
13 	Enabled = 1;
14 
15 	Advection = 0.0f;
16 	AirDrag = 0.00f * CFDS;
17 	AirLoss = 0.90f;
18 	Loss = 0.00f;
19 	Collision = 0.0f;
20 	Gravity = 0.0f;
21 	Diffusion = 0.00f;
22 	HotAir = 0.000f	* CFDS;
23 	Falldown = 0;
24 
25 	Flammable = 0;
26 	Explosive = 0;
27 	Meltable = 0;
28 	Hardness = 2;
29 
30 	Weight = 100;
31 
32 	HeatConduct = 0;
33 	Description = "Wireless transmitter, transfers spark to any other wifi on the same temperature channel.";
34 
35 	Properties = TYPE_SOLID;
36 
37 	LowPressure = IPL;
38 	LowPressureTransition = NT;
39 	HighPressure = 15.0f;
40 	HighPressureTransition = PT_BRMT;
41 	LowTemperature = ITL;
42 	LowTemperatureTransition = NT;
43 	HighTemperature = ITH;
44 	HighTemperatureTransition = NT;
45 
46 	Update = &update;
47 	Graphics = &graphics;
48 }
49 
update(UPDATE_FUNC_ARGS)50 static int update(UPDATE_FUNC_ARGS)
51 {
52 	int r, rx, ry;
53 	parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
54 	if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;
55 	else if (parts[i].tmp<0) parts[i].tmp = 0;
56 	for (rx=-1; rx<2; rx++)
57 		for (ry=-1; ry<2; ry++)
58 			if (BOUNDS_CHECK && (rx || ry))
59 			{
60 				r = pmap[y+ry][x+rx];
61 				if (!r)
62 					continue;
63 				// wireless[][0] - whether channel is active on this frame
64 				// wireless[][1] - whether channel should be active on next frame
65 				if (sim->wireless[parts[i].tmp][0])
66 				{
67 					if ((TYP(r)==PT_NSCN||TYP(r)==PT_PSCN||TYP(r)==PT_INWR)&&parts[ID(r)].life==0 && sim->wireless[parts[i].tmp][0])
68 					{
69 						parts[ID(r)].ctype = TYP(r);
70 						sim->part_change_type(ID(r),x+rx,y+ry,PT_SPRK);
71 						parts[ID(r)].life = 4;
72 					}
73 				}
74 				if (TYP(r)==PT_SPRK && parts[ID(r)].ctype!=PT_NSCN && parts[ID(r)].life>=3)
75 				{
76 					sim->wireless[parts[i].tmp][1] = 1;
77 					sim->ISWIRE = 2;
78 				}
79 			}
80 	return 0;
81 }
82 
83 constexpr float FREQUENCY = 0.0628f;
84 
graphics(GRAPHICS_FUNC_ARGS)85 static int graphics(GRAPHICS_FUNC_ARGS)
86 {
87 	int q = (int)((cpart->temp-73.15f)/100+1);
88 	*colr = sin(FREQUENCY*q + 0) * 127 + 128;
89 	*colg = sin(FREQUENCY*q + 2) * 127 + 128;
90 	*colb = sin(FREQUENCY*q + 4) * 127 + 128;
91 	*pixel_mode |= EFFECT_DBGLINES;
92 	return 0;
93 }
94