1 #include "simulation/ElementCommon.h"
2 
3 int Element_BIZR_update(UPDATE_FUNC_ARGS);
4 int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS);
5 
Element_BIZR()6 void Element::Element_BIZR()
7 {
8 	Identifier = "DEFAULT_PT_BIZR";
9 	Name = "BIZR";
10 	Colour = PIXPACK(0x00FF77);
11 	MenuVisible = 1;
12 	MenuSection = SC_LIQUID;
13 	Enabled = 1;
14 
15 	Advection = 0.6f;
16 	AirDrag = 0.01f * CFDS;
17 	AirLoss = 0.98f;
18 	Loss = 0.95f;
19 	Collision = 0.0f;
20 	Gravity = 0.1f;
21 	Diffusion = 0.00f;
22 	HotAir = 0.000f	* CFDS;
23 	Falldown = 2;
24 
25 	Flammable = 0;
26 	Explosive = 0;
27 	Meltable = 0;
28 	Hardness = 20;
29 
30 	Weight = 30;
31 
32 	HeatConduct = 29;
33 	Description = "Bizarre... contradicts the normal state changes. Paints other elements with its deco color.";
34 
35 	Properties = TYPE_LIQUID;
36 
37 	LowPressure = IPL;
38 	LowPressureTransition = NT;
39 	HighPressure = IPH;
40 	HighPressureTransition = NT;
41 	LowTemperature = 100.0f;
42 	LowTemperatureTransition = PT_BIZRG;
43 	HighTemperature = 400.0f;
44 	HighTemperatureTransition = PT_BIZRS;
45 
46 	DefaultProperties.ctype = 0x47FFFF;
47 
48 	Update = &Element_BIZR_update;
49 	Graphics = &Element_BIZR_graphics;
50 }
51 
52 constexpr float BLEND = 0.95f;
53 
Element_BIZR_update(UPDATE_FUNC_ARGS)54 int Element_BIZR_update(UPDATE_FUNC_ARGS)
55 {
56 	int r, rx, ry, nr, ng, nb, na;
57 	float tr, tg, tb, ta, mr, mg, mb, ma;
58 	if(parts[i].dcolour){
59 		for (rx=-2; rx<3; rx++)
60 			for (ry=-2; ry<3; ry++)
61 				if (BOUNDS_CHECK && (rx || ry))
62 				{
63 					r = pmap[y+ry][x+rx];
64 					if (!r)
65 						continue;
66 					if (TYP(r)!=PT_BIZR && TYP(r)!=PT_BIZRG  && TYP(r)!=PT_BIZRS)
67 					{
68 						tr = (parts[ID(r)].dcolour>>16)&0xFF;
69 						tg = (parts[ID(r)].dcolour>>8)&0xFF;
70 						tb = (parts[ID(r)].dcolour)&0xFF;
71 						ta = (parts[ID(r)].dcolour>>24)&0xFF;
72 
73 						mr = (parts[i].dcolour>>16)&0xFF;
74 						mg = (parts[i].dcolour>>8)&0xFF;
75 						mb = (parts[i].dcolour)&0xFF;
76 						ma = (parts[i].dcolour>>24)&0xFF;
77 
78 						nr = (tr*BLEND) + (mr*(1 - BLEND));
79 						ng = (tg*BLEND) + (mg*(1 - BLEND));
80 						nb = (tb*BLEND) + (mb*(1 - BLEND));
81 						na = (ta*BLEND) + (ma*(1 - BLEND));
82 
83 						parts[ID(r)].dcolour = nr<<16 | ng<<8 | nb | na<<24;
84 					}
85 				}
86 	}
87 	return 0;
88 }
89 
Element_BIZR_graphics(GRAPHICS_FUNC_ARGS)90 int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS)
91  //BIZR, BIZRG, BIZRS
92 {
93 	int x = 0;
94 	float brightness = fabs(cpart->vx) + fabs(cpart->vy);
95 	if (cpart->ctype&0x3FFFFFFF)
96 	{
97 		*colg = 0;
98 		*colb = 0;
99 		*colr = 0;
100 		for (x=0; x<12; x++) {
101 			*colr += (cpart->ctype >> (x+18)) & 1;
102 			*colb += (cpart->ctype >>  x)     & 1;
103 		}
104 		for (x=0; x<12; x++)
105 			*colg += (cpart->ctype >> (x+9))  & 1;
106 		x = 624 / (*colr + *colg + *colb + 1);
107 		*colr *= x;
108 		*colg *= x;
109 		*colb *= x;
110 	}
111 
112 	if(brightness>0)
113 	{
114 		brightness /= 5;
115 		*firea = 255;
116 		*fireg = *colg * brightness;
117 		*fireb = *colb * brightness;
118 		*firer = *colr * brightness;
119 		*pixel_mode |= FIRE_ADD;
120 	}
121 	*pixel_mode |= PMODE_BLUR;
122 	return 0;
123 }
124