1 #include "simulation/ElementCommon.h"
2 
3 static int update(UPDATE_FUNC_ARGS);
4 static int graphics(GRAPHICS_FUNC_ARGS);
5 
Element_ACID()6 void Element::Element_ACID()
7 {
8 	Identifier = "DEFAULT_PT_ACID";
9 	Name = "ACID";
10 	Colour = PIXPACK(0xED55FF);
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 = 40;
26 	Explosive = 0;
27 	Meltable = 0;
28 	Hardness = 0;
29 	PhotonReflectWavelengths = 0x1FE001FE;
30 
31 	Weight = 10;
32 
33 	HeatConduct = 34;
34 	Description = "Dissolves almost everything.";
35 
36 	Properties = TYPE_LIQUID|PROP_DEADLY;
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 	DefaultProperties.life = 75;
48 
49 	Update = &update;
50 	Graphics = &graphics;
51 }
52 
update(UPDATE_FUNC_ARGS)53 static int update(UPDATE_FUNC_ARGS)
54 {
55 	int r, rx, ry, trade;
56 	for (rx=-2; rx<3; rx++)
57 		for (ry=-2; ry<3; ry++)
58 			if (BOUNDS_CHECK && (rx || ry))
59 			{
60 				r = pmap[y+ry][x+rx];
61 				if (!r)
62 					continue;
63 				int rt = TYP(r);
64 				if (rt != PT_ACID && rt != PT_CAUS)
65 				{
66 					if (rt == PT_PLEX || rt == PT_NITR || rt == PT_GUNP || rt == PT_RBDM || rt == PT_LRBD)
67 					{
68 						sim->part_change_type(i,x,y,PT_FIRE);
69 						sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE);
70 						parts[i].life = 4;
71 						parts[ID(r)].life = 4;
72 					}
73 					else if (rt == PT_WTRV)
74 					{
75 						if (RNG::Ref().chance(1, 250))
76 						{
77 							sim->part_change_type(i, x, y, PT_CAUS);
78 							parts[i].life = RNG::Ref().between(25, 74);
79 							sim->kill_part(ID(r));
80 						}
81 					}
82 					else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness, 1000.0))
83 					{
84 						if (sim->parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid
85 						{
86 							float newtemp = ((60.0f-(float)sim->elements[rt].Hardness))*7.0f;
87 							if(newtemp < 0){
88 								newtemp = 0;
89 							}
90 							parts[i].temp += newtemp;
91 							parts[i].life--;
92 							sim->kill_part(ID(r));
93 						}
94 					}
95 					else if (parts[i].life<=50)
96 					{
97 						sim->kill_part(i);
98 						return 1;
99 					}
100 				}
101 			}
102 	for (trade = 0; trade<2; trade++)
103 	{
104 		rx = RNG::Ref().between(-2, 2);
105 		ry = RNG::Ref().between(-2, 2);
106 		if (BOUNDS_CHECK && (rx || ry))
107 		{
108 			r = pmap[y+ry][x+rx];
109 			if (!r)
110 				continue;
111 			if (TYP(r) == PT_ACID && (parts[i].life > parts[ID(r)].life) && parts[i].life>0)//diffusion
112 			{
113 				int temp = parts[i].life - parts[ID(r)].life;
114 				if (temp == 1)
115 				{
116 					parts[ID(r)].life++;
117 					parts[i].life--;
118 				}
119 				else if (temp>0)
120 				{
121 					parts[ID(r)].life += temp/2;
122 					parts[i].life -= temp/2;
123 				}
124 			}
125 		}
126 	}
127 	return 0;
128 }
129 
graphics(GRAPHICS_FUNC_ARGS)130 static int graphics(GRAPHICS_FUNC_ARGS)
131 {
132 	int s = cpart->life;
133 	if (s>75) s = 75; //These two should not be here.
134 	if (s<49) s = 49;
135 	s = (s-49)*3;
136 	if (s==0) s = 1;
137 	*colr += s*4;
138 	*colg += s*1;
139 	*colb += s*2;
140 	*pixel_mode |= PMODE_BLUR;
141 	return 0;
142 }
143