1 #include "simulation/ElementCommon.h"
2
3 static int update(UPDATE_FUNC_ARGS);
4 static int graphics(GRAPHICS_FUNC_ARGS);
5
Element_EXOT()6 void Element::Element_EXOT()
7 {
8 Identifier = "DEFAULT_PT_EXOT";
9 Name = "EXOT";
10 Colour = PIXPACK(0x247BFE);
11 MenuVisible = 1;
12 MenuSection = SC_NUCLEAR;
13 Enabled = 1;
14
15 Advection = 0.3f;
16 AirDrag = 0.02f * CFDS;
17 AirLoss = 0.95f;
18 Loss = 0.80f;
19 Collision = 0.0f;
20 Gravity = 0.15f;
21 Diffusion = 0.00f;
22 HotAir = 0.0003f * CFDS;
23 Falldown = 2;
24
25 Flammable = 0;
26 Explosive = 0;
27 Meltable = 0;
28 Hardness = 2;
29
30 Weight = 46;
31
32 DefaultProperties.temp = R_TEMP - 2.0f + 273.15f;
33 HeatConduct = 250;
34 Description = "Exotic matter. Explodes with excess exposure to electrons. Has many other odd reactions.";
35
36 Properties = TYPE_LIQUID|PROP_NEUTPASS;
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 = 1000;
48 DefaultProperties.tmp = 244;
49
50 Update = &update;
51 Graphics = &graphics;
52 }
53
update(UPDATE_FUNC_ARGS)54 static int update(UPDATE_FUNC_ARGS)
55 {
56 int r, rt, rx, ry, trade, tym;
57 for (rx=-2; rx<=2; rx++)
58 for (ry=-2; ry<=2; ry++)
59 if (BOUNDS_CHECK && (rx || ry))
60 {
61 r = pmap[y+ry][x+rx];
62 if (!r)
63 continue;
64 rt = TYP(r);
65 if (rt == PT_WARP)
66 {
67 if (parts[ID(r)].tmp2>2000 && RNG::Ref().chance(1, 100))
68 {
69 parts[i].tmp2 += 100;
70 }
71 }
72 else if (rt == PT_EXOT)
73 {
74 if (parts[ID(r)].ctype == PT_PROT)
75 parts[i].ctype = PT_PROT;
76 if (parts[ID(r)].life == 1500 && RNG::Ref().chance(1, 1000))
77 parts[i].life = 1500;
78 }
79 else if (rt == PT_LAVA)
80 {
81 //turn molten TTAN or molten GOLD to molten VIBR
82 if (parts[ID(r)].ctype == PT_TTAN || parts[ID(r)].ctype == PT_GOLD)
83 {
84 if (RNG::Ref().chance(1, 10))
85 {
86 parts[ID(r)].ctype = PT_VIBR;
87 sim->kill_part(i);
88 return 1;
89 }
90 }
91 //molten VIBR will kill the leftover EXOT though, so the VIBR isn't killed later
92 else if (parts[ID(r)].ctype == PT_VIBR)
93 {
94 if (RNG::Ref().chance(1, 1000))
95 {
96 sim->kill_part(i);
97 return 1;
98 }
99 }
100 }
101 if (parts[i].tmp > 245 && parts[i].life > 1337)
102 if (rt!=PT_EXOT && rt!=PT_BREC && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PRTI && rt!=PT_PRTO && rt!=PT_PCLN && rt!=PT_VOID && rt!=PT_NBHL && rt!=PT_WARP)
103 {
104 sim->create_part(i, x, y, rt);
105 return 1;
106 }
107 }
108
109 parts[i].tmp--;
110 parts[i].tmp2--;
111 //reset tmp every 250 frames, gives EXOT it's slow flashing effect
112 if (parts[i].tmp < 1 || parts[i].tmp > 250)
113 parts[i].tmp = 250;
114
115 if (parts[i].tmp2 < 1)
116 parts[i].tmp2 = 1;
117 else if (parts[i].tmp2 > 6000)
118 {
119 parts[i].tmp2 = 10000;
120 if (parts[i].life < 1001)
121 {
122 sim->part_change_type(i, x, y, PT_WARP);
123 return 1;
124 }
125 }
126 else if(parts[i].life < 1001)
127 sim->pv[y/CELL][x/CELL] += (parts[i].tmp2*CFDS)/160000;
128
129 if (sim->pv[y/CELL][x/CELL]>200 && parts[i].temp>9000 && parts[i].tmp2>200)
130 {
131 parts[i].tmp2 = 6000;
132 sim->part_change_type(i, x, y, PT_WARP);
133 return 1;
134 }
135 if (parts[i].tmp2 > 100)
136 {
137 for (trade = 0; trade < 9; trade++)
138 {
139 rx = RNG::Ref().between(-2, 2);
140 ry = RNG::Ref().between(-2, 2);
141 if (BOUNDS_CHECK && (rx || ry))
142 {
143 r = pmap[y+ry][x+rx];
144 if (!r)
145 continue;
146 if (TYP(r)==PT_EXOT && (parts[i].tmp2 > parts[ID(r)].tmp2) && parts[ID(r)].tmp2 >= 0) //diffusion
147 {
148 tym = parts[i].tmp2 - parts[ID(r)].tmp2;
149 if (tym == 1)
150 {
151 parts[ID(r)].tmp2++;
152 parts[i].tmp2--;
153 break;
154 }
155 if (tym > 0)
156 {
157 parts[ID(r)].tmp2 += tym/2;
158 parts[i].tmp2 -= tym/2;
159 break;
160 }
161 }
162 }
163 }
164 }
165 if (parts[i].ctype == PT_PROT)
166 {
167 if (parts[i].temp < 50.0f)
168 {
169 sim->create_part(i, x, y, PT_CFLM);
170 return 1;
171 }
172 else
173 parts[i].temp -= 1.0f;
174 }
175 else if (parts[i].temp < 273.15f)
176 {
177 parts[i].vx = 0;
178 parts[i].vy = 0;
179 sim->pv[y/CELL][x/CELL] -= 0.01;
180 parts[i].tmp--;
181 }
182 return 0;
183 }
184
graphics(GRAPHICS_FUNC_ARGS)185 static int graphics(GRAPHICS_FUNC_ARGS)
186 {
187 int q = cpart->temp;
188 int b = cpart->tmp;
189 int c = cpart->tmp2;
190 if (cpart->life < 1001)
191 {
192 if (RNG::Ref().chance(cpart->tmp2 - 1, 1000))
193 {
194 float frequency = 0.04045;
195 *colr = (sin(frequency*c + 4) * 127 + 150);
196 *colg = (sin(frequency*c + 6) * 127 + 150);
197 *colb = (sin(frequency*c + 8) * 127 + 150);
198
199 *firea = 100;
200 *firer = 0;
201 *fireg = 0;
202 *fireb = 0;
203
204 *pixel_mode |= PMODE_FLAT;
205 *pixel_mode |= PMODE_FLARE;
206 }
207 else
208 {
209 float frequency = 0.00045;
210 *colr = (sin(frequency*q + 4) * 127 + (b/1.7));
211 *colg = (sin(frequency*q + 6) * 127 + (b/1.7));
212 *colb = (sin(frequency*q + 8) * 127 + (b/1.7));
213 *cola = cpart->tmp / 6;
214
215 *firea = *cola;
216 *firer = *colr;
217 *fireg = *colg;
218 *fireb = *colb;
219
220 *pixel_mode |= FIRE_ADD;
221 *pixel_mode |= PMODE_BLUR;
222 }
223 }
224 else
225 {
226 float frequency = 0.01300;
227 *colr = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
228 *colg = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
229 *colb = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
230 *cola = cpart->tmp / 6;
231 *firea = *cola;
232 *firer = *colr;
233 *fireg = *colg;
234 *fireb = *colb;
235 *pixel_mode |= FIRE_ADD;
236 *pixel_mode |= PMODE_BLUR;
237 }
238 return 0;
239 }
240