1 vector PointInBrush_vec;
2 entity PointInBrush_brush;
3 .float dphitcontentsmask;
4 float PointInBrush_Recurse()
10 traceline(PointInBrush_vec, PointInBrush_vec, 0, world);
13 if(trace_ent == PointInBrush_brush)
19 f = PointInBrush_Recurse();
24 float PointInBrush(entity brush, vector point)
28 if not(brush.modelindex)
32 brush.solid = SOLID_BSP;
33 PointInBrush_vec = point;
34 PointInBrush_brush = brush;
35 f = PointInBrush_Recurse();
41 .float cnt; // effect number
42 .vector velocity; // particle velocity
43 .float waterlevel; // direction jitter
44 .float count; // count multiplier
45 .float glow_color; // palette color
46 .float impulse; // density
47 .string noise; // sound
51 .vector movedir; // trace direction
53 void Draw_PointParticles()
60 sz = self.maxs - self.mins;
61 n = self.impulse * drawframetime;
65 for(i = random(); i <= n && fail <= 64*n; ++i)
68 p_x += random() * sz_x;
69 p_y += random() * sz_y;
70 p_z += random() * sz_z;
71 if(PointInBrush(self, p))
73 if(self.movedir != '0 0 0')
75 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
77 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
80 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
84 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
87 else if(self.absolute)
96 void Ent_PointParticles_Remove()
99 strunzone(self.noise);
100 self.noise = string_null;
103 void Ent_PointParticles()
110 self.impulse = ReadCoord(); // density (<0: point, >0: volume)
114 self.origin_x = ReadCoord();
115 self.origin_y = ReadCoord();
116 self.origin_z = ReadCoord();
120 self.modelindex = ReadShort();
123 self.mins_x = ReadCoord();
124 self.mins_y = ReadCoord();
125 self.mins_z = ReadCoord();
126 self.maxs_x = ReadCoord();
127 self.maxs_y = ReadCoord();
128 self.maxs_z = ReadCoord();
133 self.maxs_x = ReadCoord();
134 self.maxs_y = ReadCoord();
135 self.maxs_z = ReadCoord();
138 self.cnt = ReadShort(); // effect number
140 self.velocity = decompressShortVector(ReadShort());
141 self.movedir = decompressShortVector(ReadShort());
142 self.waterlevel = ReadCoord();
143 self.count = ReadCoord();
144 self.glow_color = ReadByte();
146 strunzone(self.noise);
147 self.noise = strzone(ReadString());
150 self.atten = ReadByte() / 64.0;
151 self.volume = ReadByte() / 255.0;
157 self.absolute = (self.impulse >= 0);
160 v = self.maxs - self.mins;
161 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
165 setorigin(self, self.origin);
166 setsize(self, self.mins, self.maxs);
167 self.solid = SOLID_NOT;
168 self.draw = Draw_PointParticles;
169 self.entremove = Ent_PointParticles_Remove;
174 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
179 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
182 void Ent_RainOrSnow()
184 self.impulse = ReadByte(); // Rain, Snow, or Whatever
185 self.origin_x = ReadCoord();
186 self.origin_y = ReadCoord();
187 self.origin_z = ReadCoord();
188 self.maxs_x = ReadCoord();
189 self.maxs_y = ReadCoord();
190 self.maxs_z = ReadCoord();
191 self.velocity = decompressShortVector(ReadShort());
192 self.count = ReadShort() * 10;
193 self.glow_color = ReadByte(); // color
195 self.mins = -0.5 * self.maxs;
196 self.maxs = 0.5 * self.maxs;
197 self.origin = self.origin - self.mins;
199 setorigin(self, self.origin);
200 setsize(self, self.mins, self.maxs);
201 self.solid = SOLID_NOT;
203 self.draw = Draw_Rain;
205 self.draw = Draw_Snow;
209 void zcurveparticles(float effectnum, vector start, vector end, float end_dz, float speed, float depth)
212 // IF IT WERE A STRAIGHT LINE, it'd end end_dz above end
215 mid = (start + end) * 0.5;
221 if(depth < 0 || normalize(mid - start) * normalize(end - start) > 0.999999)
222 // TODO make this a variable threshold
223 // currently: 0.081 degrees
224 // 0.99999 would be 0.256 degrees and is visible
226 zcurve.velocity = speed * normalize(end - start);
227 trailparticles(zcurve, effectnum, start, end);
231 zcurveparticles(effectnum, start, mid, end_dz, speed, depth);
232 zcurveparticles(effectnum, mid, end, end_dz, speed, depth);
236 void Net_ReadZCurveParticles()
240 float effectnum, speed;
245 zcurve.classname = "zcurve";
248 effectnum = ReadShort();
250 start_x = ReadCoord();
251 start_y = ReadCoord();
252 start_z = ReadCoord();
256 end_dz = ReadCoord();
257 speed = ReadShort() * 16;
259 zcurveparticles(effectnum, start, end, end_dz, speed, 5); // at most 32 segments
262 void Net_ReadNexgunBeamParticle()
264 vector shotorg, endpos;
265 shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
266 endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
268 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
270 //draw either the old v2.3 beam or the new beam
271 if (cvar("cl_particles_oldnexbeam") && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
272 trailparticles(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos);
274 trailparticles(world, particleeffectnum("nex_beam"), shotorg, endpos);