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 impulse; // density
46 .string noise; // sound
49 .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
50 .vector movedir; // trace direction
52 .float bgmscriptdecay;
54 float pointparticles_scriptbuf;
55 float pointparticles_scriptbufsize;
56 float pointparticles_scriptbufloaded;
57 void PointparticlesScript_Init()
61 pointparticles_scriptbuf = pointparticles_scriptbufsize = 0;
62 pointparticles_scriptbufloaded = 1;
63 s = strcat("maps/", mi_shortname, ".bgs");
64 fh = fopen(s, FILE_READ);
67 pointparticles_scriptbuf = buf_create();
68 while((s = fgets(fh)))
70 bufstr_set(pointparticles_scriptbuf, pointparticles_scriptbufsize, s);
71 ++pointparticles_scriptbufsize;
78 .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.just_toggled = 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)
139 e.just_toggled = e.scriptstate = TRUE;
141 e.just_toggled = e.scriptstate = FALSE;
143 e.scripttime = stof(argv(1));
147 return pow(0.5, (t - e.scripttime) * e.bgmscriptdecay) * e.scriptvelocity;
152 void Draw_PointParticles()
159 sz = self.maxs - self.mins;
160 n = PointparticlesScript(self);
161 if(self.absolute == 2)
164 n = self.just_toggled ? self.impulse : 0;
166 n = self.impulse * drawframetime;
170 n *= self.impulse * drawframetime;
171 if(self.just_toggled)
178 for(i = random(); i <= n && fail <= 64*n; ++i)
181 p_x += random() * sz_x;
182 p_y += random() * sz_y;
183 p_z += random() * sz_z;
184 if(PointInBrush(self, p))
186 if(self.movedir != '0 0 0')
188 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
190 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count);
194 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count);
199 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
201 self.just_toggled = 0;
203 else if(self.absolute)
212 void Ent_PointParticles_Remove()
215 strunzone(self.noise);
216 self.noise = string_null;
218 strunzone(self.bgmscript);
219 self.bgmscript = string_null;
222 void Ent_PointParticles()
229 i = ReadCoord(); // density (<0: point, >0: volume)
230 if(i && !self.impulse && self.cnt) // self.cnt check is so it only happens if the ent already existed
231 self.just_toggled = 1;
236 self.origin_x = ReadCoord();
237 self.origin_y = ReadCoord();
238 self.origin_z = ReadCoord();
242 self.modelindex = ReadShort();
247 self.mins_x = ReadCoord();
248 self.mins_y = ReadCoord();
249 self.mins_z = ReadCoord();
250 self.maxs_x = ReadCoord();
251 self.maxs_y = ReadCoord();
252 self.maxs_z = ReadCoord();
257 self.maxs_x = ReadCoord();
258 self.maxs_y = ReadCoord();
259 self.maxs_z = ReadCoord();
264 self.mins = self.maxs = '0 0 0';
267 self.cnt = ReadShort(); // effect number
271 self.velocity = decompressShortVector(ReadShort());
272 self.movedir = decompressShortVector(ReadShort());
276 self.velocity = self.movedir = '0 0 0';
280 self.waterlevel = ReadShort() / 16.0;
281 self.count = ReadByte() / 16.0;
289 strunzone(self.noise);
291 strunzone(self.bgmscript);
292 self.noise = strzone(ReadString());
295 self.atten = ReadByte() / 64.0;
296 self.volume = ReadByte() / 255.0;
298 self.bgmscript = strzone(ReadString());
299 if(self.bgmscript != "")
300 self.bgmscriptdecay = ReadByte() / 255.0;
301 PointparticlesScript_InitEntity(self);
306 self.absolute = (self.impulse >= 0);
309 v = self.maxs - self.mins;
310 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
317 setorigin(self, self.origin);
318 setsize(self, self.mins, self.maxs);
319 self.solid = SOLID_NOT;
320 self.draw = Draw_PointParticles;
321 self.entremove = Ent_PointParticles_Remove;
324 .float glow_color; // palette index
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);