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;
80 .float scriptvelocity;
83 void PointparticlesScript_InitEntity(entity e)
87 if(!pointparticles_scriptbufloaded)
88 PointparticlesScript_Init();
94 for(i = 0; i < pointparticles_scriptbufsize; ++i)
96 tokenize_sane(bufstr_get(pointparticles_scriptbuf, i));
97 if(argv(0) == e.bgmscript)
100 e.scriptline = e.scriptline0 = i;
101 if(i >= pointparticles_scriptbufsize)
103 print("func_pointparticles: script does not define ", mychar, "\n");
109 float PointparticlesScript(entity e)
113 if(e.bgmscript == "")
116 if(cvar("bgmvolume") <= 0)
119 e.switchedon = FALSE;
121 t = gettime(GETTIME_CDTRACK);
123 tokenize_sane(bufstr_get(pointparticles_scriptbuf, e.scriptline));
126 e.scriptline = e.scriptline0;
128 tokenize_sane(bufstr_get(pointparticles_scriptbuf, e.scriptline));
131 if(argv(0) != e.bgmscript)
133 e.scriptstate = 0; // end of script, will revert to beginning later
135 else if(t >= stof(argv(1)))
137 // time code reached!
138 e.scriptvelocity = stof(argv(2));
139 if(e.scriptvelocity > 0)
141 e.scripttime = stof(argv(1));
147 if(e.bgmscriptdecay >= 1)
148 return (e.scriptstate == 2);
150 return pow(0.5, (t - e.scripttime) * (e.bgmscriptdecay / (1 - e.bgmscriptdecay))) * e.scriptvelocity;
156 void Draw_PointParticles()
163 sz = self.maxs - self.mins;
164 n = self.impulse * drawframetime;
165 n *= PointparticlesScript(self);
169 for(i = random(); (self.switchedon || i <= n) && fail <= 64*n; ++i)
172 p_x += random() * sz_x;
173 p_y += random() * sz_y;
174 p_z += random() * sz_z;
175 if(PointInBrush(self, p))
177 if(self.movedir != '0 0 0')
179 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
181 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
184 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
188 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
192 else if(self.absolute)
201 void Ent_PointParticles_Remove()
204 strunzone(self.noise);
205 self.noise = string_null;
207 strunzone(self.bgmscript);
208 self.bgmscript = string_null;
211 void Ent_PointParticles()
218 i = ReadCoord(); // density (<0: point, >0: volume)
219 if(i && !self.impulse)
225 self.origin_x = ReadCoord();
226 self.origin_y = ReadCoord();
227 self.origin_z = ReadCoord();
231 self.modelindex = ReadShort();
236 self.mins_x = ReadCoord();
237 self.mins_y = ReadCoord();
238 self.mins_z = ReadCoord();
239 self.maxs_x = ReadCoord();
240 self.maxs_y = ReadCoord();
241 self.maxs_z = ReadCoord();
246 self.maxs_x = ReadCoord();
247 self.maxs_y = ReadCoord();
248 self.maxs_z = ReadCoord();
253 self.mins = self.maxs = '0 0 0';
256 self.cnt = ReadShort(); // effect number
260 self.velocity = decompressShortVector(ReadShort());
261 self.movedir = decompressShortVector(ReadShort());
265 self.velocity = self.movedir = '0 0 0';
269 self.waterlevel = ReadShort() / 16.0;
270 self.count = ReadByte() / 16.0;
271 self.glow_color = ReadByte();
275 self.waterlevel = self.count = self.glow_color = 0;
278 strunzone(self.noise);
280 strunzone(self.bgmscript);
283 self.noise = strzone(ReadString());
286 self.atten = ReadByte() / 64.0;
287 self.volume = ReadByte() / 255.0;
289 self.bgmscript = strzone(ReadString());
290 if(self.bgmscript != "")
291 self.bgmscriptdecay = ReadByte() / 255.0;
292 PointparticlesScript_InitEntity(self);
296 self.noise = self.bgmscript = string_null;
302 self.absolute = (self.impulse >= 0);
305 v = self.maxs - self.mins;
306 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
310 setorigin(self, self.origin);
311 setsize(self, self.mins, self.maxs);
312 self.solid = SOLID_NOT;
313 self.draw = Draw_PointParticles;
314 self.entremove = Ent_PointParticles_Remove;
319 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
324 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
327 void Ent_RainOrSnow()
329 self.impulse = ReadByte(); // Rain, Snow, or Whatever
330 self.origin_x = ReadCoord();
331 self.origin_y = ReadCoord();
332 self.origin_z = ReadCoord();
333 self.maxs_x = ReadCoord();
334 self.maxs_y = ReadCoord();
335 self.maxs_z = ReadCoord();
336 self.velocity = decompressShortVector(ReadShort());
337 self.count = ReadShort() * 10;
338 self.glow_color = ReadByte(); // color
340 self.mins = -0.5 * self.maxs;
341 self.maxs = 0.5 * self.maxs;
342 self.origin = self.origin - self.mins;
344 setorigin(self, self.origin);
345 setsize(self, self.mins, self.maxs);
346 self.solid = SOLID_NOT;
348 self.draw = Draw_Rain;
350 self.draw = Draw_Snow;
354 void zcurveparticles(float effectnum, vector start, vector end, float end_dz, float speed, float depth)
357 // IF IT WERE A STRAIGHT LINE, it'd end end_dz above end
360 mid = (start + end) * 0.5;
366 if(depth < 0 || normalize(mid - start) * normalize(end - start) > 0.999999)
367 // TODO make this a variable threshold
368 // currently: 0.081 degrees
369 // 0.99999 would be 0.256 degrees and is visible
371 zcurve.velocity = speed * normalize(end - start);
372 trailparticles(zcurve, effectnum, start, end);
376 zcurveparticles(effectnum, start, mid, end_dz, speed, depth);
377 zcurveparticles(effectnum, mid, end, end_dz, speed, depth);
381 void Net_ReadZCurveParticles()
385 float effectnum, speed;
390 zcurve.classname = "zcurve";
393 effectnum = ReadShort();
395 start_x = ReadCoord();
396 start_y = ReadCoord();
397 start_z = ReadCoord();
401 end_dz = ReadCoord();
402 speed = ReadShort() * 16;
404 zcurveparticles(effectnum, start, end, end_dz, speed, 5); // at most 32 segments
407 void Net_ReadNexgunBeamParticle()
409 vector shotorg, endpos;
410 shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
411 endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
413 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
415 //draw either the old v2.3 beam or the new beam
416 if (cvar("cl_particles_oldnexbeam") && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
417 trailparticles(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos);
419 trailparticles(world, particleeffectnum("nex_beam"), shotorg, endpos);