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;
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.scriptstate = !!e.scriptstate; // turns 0 to 0 and 2 to 1
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 e.scriptstate = 0; // 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 e.scriptstate = (e.scriptvelocity > 0) ? 2 : 0;
139 e.scripttime = stof(argv(1));
145 if(e.bgmscriptdecay >= 1)
146 return (e.scriptstate == 2);
148 return pow(0.5, (t - e.scripttime) * (e.bgmscriptdecay / (1 - e.bgmscriptdecay))) * e.scriptvelocity;
154 void Draw_PointParticles()
156 float n, i, fail, force;
161 sz = self.maxs - self.mins;
162 n = self.impulse * drawframetime;
163 n *= PointparticlesScript(self);
167 force = (self.scriptstate == 2);
168 for(i = random(); (force || i <= n) && fail <= 64*n; ++i)
171 p_x += random() * sz_x;
172 p_y += random() * sz_y;
173 p_z += random() * sz_z;
174 if(PointInBrush(self, p))
176 if(self.movedir != '0 0 0')
178 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
180 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
183 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
187 sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
191 else if(self.absolute)
200 void Ent_PointParticles_Remove()
203 strunzone(self.noise);
204 self.noise = string_null;
206 strunzone(self.bgmscript);
207 self.bgmscript = string_null;
210 void Ent_PointParticles()
217 self.impulse = ReadCoord(); // density (<0: point, >0: volume)
221 self.origin_x = ReadCoord();
222 self.origin_y = ReadCoord();
223 self.origin_z = ReadCoord();
227 self.modelindex = ReadShort();
230 self.mins_x = ReadCoord();
231 self.mins_y = ReadCoord();
232 self.mins_z = ReadCoord();
233 self.maxs_x = ReadCoord();
234 self.maxs_y = ReadCoord();
235 self.maxs_z = ReadCoord();
240 self.maxs_x = ReadCoord();
241 self.maxs_y = ReadCoord();
242 self.maxs_z = ReadCoord();
245 self.cnt = ReadShort(); // effect number
247 self.velocity = decompressShortVector(ReadShort());
248 self.movedir = decompressShortVector(ReadShort());
249 self.waterlevel = ReadCoord();
250 self.count = ReadCoord();
251 self.glow_color = ReadByte();
253 strunzone(self.noise);
254 self.noise = strzone(ReadString());
257 self.atten = ReadByte() / 64.0;
258 self.volume = ReadByte() / 255.0;
261 strunzone(self.bgmscript);
262 self.bgmscript = strzone(ReadString());
263 if(self.bgmscript != "")
264 self.bgmscriptdecay = ReadByte() / 255.0;
265 PointparticlesScript_InitEntity(self);
270 self.absolute = (self.impulse >= 0);
273 v = self.maxs - self.mins;
274 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
278 setorigin(self, self.origin);
279 setsize(self, self.mins, self.maxs);
280 self.solid = SOLID_NOT;
281 self.draw = Draw_PointParticles;
282 self.entremove = Ent_PointParticles_Remove;
287 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
292 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, self.count * drawframetime, self.glow_color);
295 void Ent_RainOrSnow()
297 self.impulse = ReadByte(); // Rain, Snow, or Whatever
298 self.origin_x = ReadCoord();
299 self.origin_y = ReadCoord();
300 self.origin_z = ReadCoord();
301 self.maxs_x = ReadCoord();
302 self.maxs_y = ReadCoord();
303 self.maxs_z = ReadCoord();
304 self.velocity = decompressShortVector(ReadShort());
305 self.count = ReadShort() * 10;
306 self.glow_color = ReadByte(); // color
308 self.mins = -0.5 * self.maxs;
309 self.maxs = 0.5 * self.maxs;
310 self.origin = self.origin - self.mins;
312 setorigin(self, self.origin);
313 setsize(self, self.mins, self.maxs);
314 self.solid = SOLID_NOT;
316 self.draw = Draw_Rain;
318 self.draw = Draw_Snow;
322 void zcurveparticles(float effectnum, vector start, vector end, float end_dz, float speed, float depth)
325 // IF IT WERE A STRAIGHT LINE, it'd end end_dz above end
328 mid = (start + end) * 0.5;
334 if(depth < 0 || normalize(mid - start) * normalize(end - start) > 0.999999)
335 // TODO make this a variable threshold
336 // currently: 0.081 degrees
337 // 0.99999 would be 0.256 degrees and is visible
339 zcurve.velocity = speed * normalize(end - start);
340 trailparticles(zcurve, effectnum, start, end);
344 zcurveparticles(effectnum, start, mid, end_dz, speed, depth);
345 zcurveparticles(effectnum, mid, end, end_dz, speed, depth);
349 void Net_ReadZCurveParticles()
353 float effectnum, speed;
358 zcurve.classname = "zcurve";
361 effectnum = ReadShort();
363 start_x = ReadCoord();
364 start_y = ReadCoord();
365 start_z = ReadCoord();
369 end_dz = ReadCoord();
370 speed = ReadShort() * 16;
372 zcurveparticles(effectnum, start, end, end_dz, speed, 5); // at most 32 segments
375 void Net_ReadNexgunBeamParticle()
377 vector shotorg, endpos;
378 shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
379 endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
381 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
383 //draw either the old v2.3 beam or the new beam
384 if (cvar("cl_particles_oldnexbeam") && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
385 trailparticles(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos);
387 trailparticles(world, particleeffectnum("nex_beam"), shotorg, endpos);