1 #include "simulation/ElementCommon.h"
2
3 static int update(UPDATE_FUNC_ARGS);
4
Element_ARAY()5 void Element::Element_ARAY()
6 {
7 Identifier = "DEFAULT_PT_ARAY";
8 Name = "ARAY";
9 Colour = PIXPACK(0xFFBB00);
10 MenuVisible = 1;
11 MenuSection = SC_ELEC;
12 Enabled = 1;
13
14 Advection = 0.0f;
15 AirDrag = 0.00f * CFDS;
16 AirLoss = 0.90f;
17 Loss = 0.00f;
18 Collision = 0.0f;
19 Gravity = 0.0f;
20 Diffusion = 0.00f;
21 HotAir = 0.000f * CFDS;
22 Falldown = 0;
23
24 Flammable = 0;
25 Explosive = 0;
26 Meltable = 0;
27 Hardness = 1;
28
29 Weight = 100;
30
31 HeatConduct = 0;
32 Description = "Ray Emitter. Rays create points when they collide.";
33
34 Properties = TYPE_SOLID|PROP_LIFE_DEC;
35
36 LowPressure = IPL;
37 LowPressureTransition = NT;
38 HighPressure = IPH;
39 HighPressureTransition = NT;
40 LowTemperature = ITL;
41 LowTemperatureTransition = NT;
42 HighTemperature = ITH;
43 HighTemperatureTransition = NT;
44
45 Update = &update;
46 }
47
update(UPDATE_FUNC_ARGS)48 static int update(UPDATE_FUNC_ARGS)
49 {
50 if (!parts[i].life)
51 {
52 for (int rx = -1; rx <= 1; rx++)
53 for (int ry = -1; ry <= 1; ry++)
54 if (BOUNDS_CHECK && (rx || ry))
55 {
56 int r = pmap[y+ry][x+rx];
57 if (!r)
58 continue;
59 if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3)
60 {
61 bool isBlackDeco = false;
62 int destroy = (parts[ID(r)].ctype==PT_PSCN) ? 1 : 0;
63 int nostop = (parts[ID(r)].ctype==PT_INST) ? 1 : 0;
64 int colored = 0, rt;
65 for (int docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi)
66 {
67 if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0))
68 break;
69
70 r = pmap[y+nyi+nyy][x+nxi+nxx];
71 rt = TYP(r);
72 r = ID(r);
73 if (!rt)
74 {
75 int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
76 if (nr != -1)
77 {
78 // if it came from PSCN
79 if (destroy)
80 {
81 parts[nr].tmp = 2;
82 parts[nr].life = 2;
83 }
84 else
85 parts[nr].ctype = colored;
86 parts[nr].temp = parts[i].temp;
87 if (isBlackDeco)
88 parts[nr].dcolour = 0xFF000000;
89 }
90 }
91 else if (!destroy)
92 {
93 if (rt == PT_BRAY)
94 {
95 // cases for hitting different BRAY modes
96 switch(parts[r].tmp)
97 {
98 // normal white
99 case 0:
100 if (nyy != 0 || nxx !=0)
101 {
102 parts[r].life = 1020; // makes it last a while
103 parts[r].tmp = 1;
104 if (!parts[r].ctype) // and colors it if it isn't already
105 parts[r].ctype = colored;
106 }
107 // red bray or any other random tmp mode, stop
108 case 2:
109 default:
110 docontinue = 0;
111 break;
112 // long life, reset it
113 case 1:
114 parts[r].life = 1020;
115 //docontinue = 1;
116 break;
117 }
118 if (isBlackDeco)
119 parts[r].dcolour = 0xFF000000;
120 }
121 // get color if passed through FILT
122 else if (rt == PT_FILT)
123 {
124 if (parts[r].tmp != 6)
125 {
126 int Element_FILT_interactWavelengths(Particle* cpart, int origWl);
127 colored = Element_FILT_interactWavelengths(&parts[r], colored);
128 if (!colored)
129 break;
130 }
131 isBlackDeco = (parts[r].dcolour==0xFF000000);
132 parts[r].life = 4;
133 }
134 else if (rt == PT_STOR)
135 {
136 if (parts[r].tmp)
137 {
138 //Cause STOR to release
139 for (int ry1 = 1; ry1 >= -1; ry1--)
140 {
141 for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1)
142 {
143 int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp));
144 if (np != -1)
145 {
146 parts[np].temp = parts[r].temp;
147 parts[np].life = parts[r].tmp2;
148 parts[np].tmp = parts[r].pavg[0];
149 parts[np].ctype = parts[r].pavg[1];
150 parts[r].tmp = 0;
151 parts[r].life = 10;
152 break;
153 }
154 }
155 }
156 }
157 else
158 {
159 parts[r].life = 10;
160 }
161 // this if prevents BRAY from stopping on certain materials
162 }
163 else if (rt != PT_INWR && (rt != PT_SPRK || parts[r].ctype != PT_INWR) && rt != PT_ARAY && rt != PT_WIFI && !(rt == PT_SWCH && parts[r].life >= 10))
164 {
165 if (nyy!=0 || nxx!=0)
166 sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
167
168 if (!(nostop && parts[r].type==PT_SPRK && parts[r].ctype >= 0 && parts[r].ctype < PT_NUM && (sim->elements[parts[r].ctype].Properties&PROP_CONDUCTS)))
169 docontinue = 0;
170 else
171 docontinue = 1;
172 }
173 }
174 else if (destroy)
175 {
176 if (rt == PT_BRAY)
177 {
178 parts[r].tmp = 2;
179 parts[r].life = 1;
180 docontinue = 1;
181 if (isBlackDeco)
182 parts[r].dcolour = 0xFF000000;
183 //this if prevents red BRAY from stopping on certain materials
184 }
185 else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10))
186 {
187 if (rt == PT_STOR)
188 {
189 parts[r].tmp = 0;
190 parts[r].life = 0;
191 }
192 else if (rt == PT_FILT)
193 {
194 isBlackDeco = (parts[r].dcolour==0xFF000000);
195 parts[r].life = 2;
196 }
197 docontinue = 1;
198 }
199 else
200 {
201 docontinue = 0;
202 }
203 }
204 }
205 }
206 //parts[i].life = 4;
207 }
208 }
209 return 0;
210 }
211