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)
163 n = self.just_toggled ? self.impulse : 0;
167 n *= self.impulse * drawframetime;
168 if(self.just_toggled)
175 for(i = random(); i <= n && fail <= 64*n; ++i)
178 p_x += random() * sz_x;
179 p_y += random() * sz_y;
180 p_z += random() * sz_z;
181 if(PointInBrush(self, p))
183 if(self.movedir != '0 0 0')
185 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
187 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count);
191 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count);
196 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
198 self.just_toggled = 0;
200 else if(self.absolute)
209 void Ent_PointParticles_Remove()
212 strunzone(self.noise);
213 self.noise = string_null;
215 strunzone(self.bgmscript);
216 self.bgmscript = string_null;
219 void Ent_PointParticles()
226 i = ReadCoord(); // density (<0: point, >0: volume)
227 if(i && !self.impulse && self.cnt) // self.cnt check is so it only happens if the ent already existed
228 self.just_toggled = 1;
233 self.origin_x = ReadCoord();
234 self.origin_y = ReadCoord();
235 self.origin_z = ReadCoord();
239 self.modelindex = ReadShort();
244 self.mins_x = ReadCoord();
245 self.mins_y = ReadCoord();
246 self.mins_z = ReadCoord();
247 self.maxs_x = ReadCoord();
248 self.maxs_y = ReadCoord();
249 self.maxs_z = ReadCoord();
254 self.maxs_x = ReadCoord();
255 self.maxs_y = ReadCoord();
256 self.maxs_z = ReadCoord();
261 self.mins = self.maxs = '0 0 0';
264 self.cnt = ReadShort(); // effect number
268 self.velocity = decompressShortVector(ReadShort());
269 self.movedir = decompressShortVector(ReadShort());
273 self.velocity = self.movedir = '0 0 0';
277 self.waterlevel = ReadShort() / 16.0;
278 self.count = ReadByte() / 16.0;
286 strunzone(self.noise);
288 strunzone(self.bgmscript);
289 self.noise = strzone(ReadString());
292 self.atten = ReadByte() / 64.0;
293 self.volume = ReadByte() / 255.0;
295 self.bgmscript = strzone(ReadString());
296 if(self.bgmscript != "")
297 self.bgmscriptdecay = ReadByte() / 255.0;
298 PointparticlesScript_InitEntity(self);
303 self.absolute = (self.impulse >= 0);
306 v = self.maxs - self.mins;
307 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
314 setorigin(self, self.origin);
315 setsize(self, self.mins, self.maxs);
316 self.solid = SOLID_NOT;
317 self.draw = Draw_PointParticles;
318 self.entremove = Ent_PointParticles_Remove;
321 .float glow_color; // palette index
324 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
329 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
332 void Ent_RainOrSnow()
334 self.impulse = ReadByte(); // Rain, Snow, or Whatever
335 self.origin_x = ReadCoord();
336 self.origin_y = ReadCoord();
337 self.origin_z = ReadCoord();
338 self.maxs_x = ReadCoord();
339 self.maxs_y = ReadCoord();
340 self.maxs_z = ReadCoord();
341 self.velocity = decompressShortVector(ReadShort());
342 self.count = ReadShort() * 10;
343 self.glow_color = ReadByte(); // color
345 self.mins = -0.5 * self.maxs;
346 self.maxs = 0.5 * self.maxs;
347 self.origin = self.origin - self.mins;
349 setorigin(self, self.origin);
350 setsize(self, self.mins, self.maxs);
351 self.solid = SOLID_NOT;
353 self.draw = Draw_Rain;
355 self.draw = Draw_Snow;
359 void zcurveparticles(float effectnum, vector start, vector end, float end_dz, float speed, float depth)
362 // IF IT WERE A STRAIGHT LINE, it'd end end_dz above end
365 mid = (start + end) * 0.5;
371 if(depth < 0 || normalize(mid - start) * normalize(end - start) > 0.999999)
372 // TODO make this a variable threshold
373 // currently: 0.081 degrees
374 // 0.99999 would be 0.256 degrees and is visible
376 zcurve.velocity = speed * normalize(end - start);
377 trailparticles(zcurve, effectnum, start, end);
381 zcurveparticles(effectnum, start, mid, end_dz, speed, depth);
382 zcurveparticles(effectnum, mid, end, end_dz, speed, depth);
386 void Net_ReadZCurveParticles()
390 float effectnum, speed;
395 zcurve.classname = "zcurve";
398 effectnum = ReadShort();
400 start_x = ReadCoord();
401 start_y = ReadCoord();
402 start_z = ReadCoord();
406 end_dz = ReadCoord();
407 speed = ReadShort() * 16;
409 zcurveparticles(effectnum, start, end, end_dz, speed, 5); // at most 32 segments
412 void Net_ReadNexgunBeamParticle()
414 vector shotorg, endpos;
415 shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
416 endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
418 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
420 //draw either the old v2.3 beam or the new beam
421 if (cvar("cl_particles_oldnexbeam") && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
422 trailparticles(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos);
424 trailparticles(world, particleeffectnum("nex_beam"), shotorg, endpos);