1 #include "simulation/ElementCommon.h"
2 
3 static int update(UPDATE_FUNC_ARGS);
4 static int graphics(GRAPHICS_FUNC_ARGS);
5 bool Element_PCLN_ctypeDraw(CTYPEDRAW_FUNC_ARGS);
6 
Element_PBCN()7 void Element::Element_PBCN()
8 {
9 	Identifier = "DEFAULT_PT_PBCN";
10 	Name = "PBCN";
11 	Colour = PIXPACK(0x3B1D0A);
12 	MenuVisible = 1;
13 	MenuSection = SC_POWERED;
14 	Enabled = 1;
15 
16 	Advection = 0.0f;
17 	AirDrag = 0.00f * CFDS;
18 	AirLoss = 0.97f;
19 	Loss = 0.50f;
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 = 0;
29 	Hardness = 12;
30 
31 	Weight = 100;
32 
33 	HeatConduct = 251;
34 	Description = "Powered breakable clone.";
35 
36 	Properties = TYPE_SOLID | PROP_NOCTYPEDRAW;
37 
38 	LowPressure = IPL;
39 	LowPressureTransition = NT;
40 	HighPressure = IPH;
41 	HighPressureTransition = NT;
42 	LowTemperature = ITL;
43 	LowTemperatureTransition = NT;
44 	HighTemperature = ITH;
45 	HighTemperatureTransition = NT;
46 
47 	Update = &update;
48 	Graphics = &graphics;
49 	CtypeDraw = &Element_PCLN_ctypeDraw;
50 }
51 
52 constexpr float ADVECTION = 0.1f;
53 
update(UPDATE_FUNC_ARGS)54 static int update(UPDATE_FUNC_ARGS)
55 {
56 	int r, rx, ry, rt;
57 	if (!parts[i].tmp2 && sim->pv[y/CELL][x/CELL]>4.0f)
58 		parts[i].tmp2 = RNG::Ref().between(80, 119);
59 	if (parts[i].tmp2)
60 	{
61 		parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL];
62 		parts[i].vy += ADVECTION*sim->vy[y/CELL][x/CELL];
63 		parts[i].tmp2--;
64 		if(!parts[i].tmp2){
65 			sim->kill_part(i);
66 			return 1;
67 		}
68 	}
69 	if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOL)))
70 		for (rx=-1; rx<2; rx++)
71 			for (ry=-1; ry<2; ry++)
72 				if (BOUNDS_CHECK)
73 				{
74 					r = sim->photons[y+ry][x+rx];
75 					if (!r)
76 						r = pmap[y+ry][x+rx];
77 					if (!r)
78 						continue;
79 					rt = TYP(r);
80 					if (rt!=PT_CLNE && rt!=PT_PCLN &&
81 					    rt!=PT_BCLN &&  rt!=PT_SPRK &&
82 					    rt!=PT_NSCN && rt!=PT_PSCN &&
83 					    rt!=PT_STKM && rt!=PT_STKM2 &&
84 					    rt!=PT_PBCN && rt<PT_NUM)
85 					{
86 						parts[i].ctype = rt;
87 						if (rt==PT_LIFE || rt==PT_LAVA)
88 							parts[i].tmp = parts[ID(r)].ctype;
89 					}
90 				}
91 	if (parts[i].life!=10)
92 	{
93 		if (parts[i].life>0)
94 			parts[i].life--;
95 	}
96 	else
97 	{
98 		for (rx=-2; rx<3; rx++)
99 			for (ry=-2; ry<3; ry++)
100 				if (BOUNDS_CHECK && (rx || ry))
101 				{
102 					r = pmap[y+ry][x+rx];
103 					if (!r)
104 						continue;
105 					if (TYP(r)==PT_PBCN)
106 					{
107 						if (parts[ID(r)].life<10&&parts[ID(r)].life>0)
108 							parts[i].life = 9;
109 						else if (parts[ID(r)].life==0)
110 							parts[ID(r)].life = 10;
111 					}
112 				}
113 		if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled)
114 		{
115 			if (parts[i].ctype==PT_PHOT) {//create photons a different way
116 				for (rx=-1; rx<2; rx++)
117 					for (ry = -1; ry < 2; ry++)
118 						if (rx || ry)
119 						{
120 							int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT);
121 							if (r != -1)
122 							{
123 								parts[r].vx = rx * 3;
124 								parts[r].vy = ry * 3;
125 								if (r>i)
126 								{
127 									// Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced
128 									parts[r].flags |= FLAG_SKIPMOVE;
129 								}
130 							}
131 						}
132 			}
133 			else if (parts[i].ctype==PT_LIFE)//create life a different way
134 				for (rx=-1; rx<2; rx++)
135 					for (ry=-1; ry<2; ry++)
136 						sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp);
137 
138 			else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30))
139 			{
140 				int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype));
141 				if (np>-1)
142 				{
143 					if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)
144 						parts[np].ctype = parts[i].tmp;
145 				}
146 			}
147 		}
148 	}
149 
150 	return 0;
151 }
152 
graphics(GRAPHICS_FUNC_ARGS)153 static int graphics(GRAPHICS_FUNC_ARGS)
154 {
155 	int lifemod = ((cpart->life>10?10:cpart->life)*10);
156 	*colr += lifemod;
157 	*colg += lifemod/2;
158 	return 0;
159 }
160