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 .float bgmscriptdecay;
55 float pointparticles_scriptbuf;
56 float pointparticles_scriptbufsize;
57 float pointparticles_scriptbufloaded;
58 void PointparticlesScript_Init()
62 pointparticles_scriptbuf = pointparticles_scriptbufsize = 0;
63 pointparticles_scriptbufloaded = 1;
64 s = strcat("maps/", mi_shortname, ".bgs");
65 fh = fopen(s, FILE_READ);
68 pointparticles_scriptbuf = buf_create();
69 while((s = fgets(fh)))
71 bufstr_set(pointparticles_scriptbuf, pointparticles_scriptbufsize, s);
72 ++pointparticles_scriptbufsize;
79 .float scriptvelocity;
82 void PointparticlesScript_InitEntity(entity e)
86 if(!pointparticles_scriptbufloaded)
87 PointparticlesScript_Init();
93 for(i = 0; i < pointparticles_scriptbufsize; ++i)
95 tokenize_sane(bufstr_get(pointparticles_scriptbuf, i));
96 if(argv(0) == e.bgmscript)
99 e.scriptline = e.scriptline0 = i;
100 if(i >= pointparticles_scriptbufsize)
102 print("func_pointparticles: script does not define ", mychar, "\n");
108 float PointparticlesScript(entity e)
112 if(e.bgmscript == "")
115 if(cvar("bgmvolume") <= 0)
118 e.switchedon = FALSE;
120 t = gettime(GETTIME_CDTRACK);
122 tokenize_sane(bufstr_get(pointparticles_scriptbuf, e.scriptline));
125 e.scriptline = e.scriptline0;
127 tokenize_sane(bufstr_get(pointparticles_scriptbuf, e.scriptline));
130 if(argv(0) != e.bgmscript)
132 // end of script, will revert to beginning later
134 else if(t >= stof(argv(1)))
136 // time code reached!
137 e.scriptvelocity = stof(argv(2));
138 if(e.scriptvelocity > 0)
141 e.scripttime = stof(argv(1));
150 if(e.bgmscriptdecay >= 1)
156 return pow(0.5, (t - e.scripttime) * (e.bgmscriptdecay / (1 - e.bgmscriptdecay))) * e.scriptvelocity;
163 void Draw_PointParticles()
170 sz = self.maxs - self.mins;
171 n = self.impulse * drawframetime;
172 n *= PointparticlesScript(self);
176 for(i = random(); (self.switchedon || i <= n) && fail <= 64*n; ++i)
179 p_x += random() * sz_x;
180 p_y += random() * sz_y;
181 p_z += random() * sz_z;
182 if(PointInBrush(self, p))
184 if(self.movedir != '0 0 0')
186 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
188 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
191 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
195 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
199 else if(self.absolute)
208 void Ent_PointParticles_Remove()
211 strunzone(self.noise);
212 self.noise = string_null;
214 strunzone(self.bgmscript);
215 self.bgmscript = string_null;
218 void Ent_PointParticles()
225 i = ReadCoord(); // density (<0: point, >0: volume)
226 if(i && !self.impulse)
232 self.origin_x = ReadCoord();
233 self.origin_y = ReadCoord();
234 self.origin_z = ReadCoord();
238 self.modelindex = ReadShort();
243 self.mins_x = ReadCoord();
244 self.mins_y = ReadCoord();
245 self.mins_z = ReadCoord();
246 self.maxs_x = ReadCoord();
247 self.maxs_y = ReadCoord();
248 self.maxs_z = ReadCoord();
253 self.maxs_x = ReadCoord();
254 self.maxs_y = ReadCoord();
255 self.maxs_z = ReadCoord();
260 self.mins = self.maxs = '0 0 0';
263 self.cnt = ReadShort(); // effect number
267 self.velocity = decompressShortVector(ReadShort());
268 self.movedir = decompressShortVector(ReadShort());
272 self.velocity = self.movedir = '0 0 0';
276 self.waterlevel = ReadShort() / 16.0;
277 self.count = ReadByte() / 16.0;
278 self.glow_color = ReadByte();
282 self.waterlevel = self.glow_color = 0;
286 strunzone(self.noise);
288 strunzone(self.bgmscript);
291 self.noise = strzone(ReadString());
294 self.atten = ReadByte() / 64.0;
295 self.volume = ReadByte() / 255.0;
297 self.bgmscript = strzone(ReadString());
298 if(self.bgmscript != "")
299 self.bgmscriptdecay = ReadByte() / 255.0;
300 PointparticlesScript_InitEntity(self);
304 self.noise = self.bgmscript = string_null;
310 self.absolute = (self.impulse >= 0);
313 v = self.maxs - self.mins;
314 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
318 setorigin(self, self.origin);
319 setsize(self, self.mins, self.maxs);
320 self.solid = SOLID_NOT;
321 self.draw = Draw_PointParticles;
322 self.entremove = Ent_PointParticles_Remove;
327 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
332 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
335 void Ent_RainOrSnow()
337 self.impulse = ReadByte(); // Rain, Snow, or Whatever
338 self.origin_x = ReadCoord();
339 self.origin_y = ReadCoord();
340 self.origin_z = ReadCoord();
341 self.maxs_x = ReadCoord();
342 self.maxs_y = ReadCoord();
343 self.maxs_z = ReadCoord();
344 self.velocity = decompressShortVector(ReadShort());
345 self.count = ReadShort() * 10;
346 self.glow_color = ReadByte(); // color
348 self.mins = -0.5 * self.maxs;
349 self.maxs = 0.5 * self.maxs;
350 self.origin = self.origin - self.mins;
352 setorigin(self, self.origin);
353 setsize(self, self.mins, self.maxs);
354 self.solid = SOLID_NOT;
356 self.draw = Draw_Rain;
358 self.draw = Draw_Snow;
362 void zcurveparticles(float effectnum, vector start, vector end, float end_dz, float speed, float depth)
365 // IF IT WERE A STRAIGHT LINE, it'd end end_dz above end
368 mid = (start + end) * 0.5;
374 if(depth < 0 || normalize(mid - start) * normalize(end - start) > 0.999999)
375 // TODO make this a variable threshold
376 // currently: 0.081 degrees
377 // 0.99999 would be 0.256 degrees and is visible
379 zcurve.velocity = speed * normalize(end - start);
380 trailparticles(zcurve, effectnum, start, end);
384 zcurveparticles(effectnum, start, mid, end_dz, speed, depth);
385 zcurveparticles(effectnum, mid, end, end_dz, speed, depth);
389 void Net_ReadZCurveParticles()
393 float effectnum, speed;
398 zcurve.classname = "zcurve";
401 effectnum = ReadShort();
403 start_x = ReadCoord();
404 start_y = ReadCoord();
405 start_z = ReadCoord();
409 end_dz = ReadCoord();
410 speed = ReadShort() * 16;
412 zcurveparticles(effectnum, start, end, end_dz, speed, 5); // at most 32 segments
415 void Net_ReadNexgunBeamParticle()
417 vector shotorg, endpos;
418 shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
419 endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
421 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
423 //draw either the old v2.3 beam or the new beam
424 if (cvar("cl_particles_oldnexbeam") && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
425 trailparticles(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos);
427 trailparticles(world, particleeffectnum("nex_beam"), shotorg, endpos);