1 #include "pointparticles.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_POINTPARTICLES)
5 // NOTE: also contains func_sparks
7 bool pointparticles_SendEntity(entity this, entity to, float fl)
9 WriteHeader(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
11 // optional features to save space
13 if(this.spawnflags & 2)
14 fl |= 0x10; // absolute count on toggle-on
15 if(this.movedir != '0 0 0' || this.velocity != '0 0 0')
16 fl |= 0x20; // 4 bytes - saves CPU
17 if(this.waterlevel || this.count != 1)
18 fl |= 0x40; // 4 bytes - obscure features almost never used
19 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
20 fl |= 0x80; // 14 bytes - saves lots of space
22 WriteByte(MSG_ENTITY, fl);
26 WriteCoord(MSG_ENTITY, this.impulse);
28 WriteCoord(MSG_ENTITY, 0); // off
32 WriteVector(MSG_ENTITY, this.origin);
36 if(this.model != "null")
38 WriteShort(MSG_ENTITY, this.modelindex);
41 WriteVector(MSG_ENTITY, this.mins);
42 WriteVector(MSG_ENTITY, this.maxs);
47 WriteShort(MSG_ENTITY, 0);
50 WriteVector(MSG_ENTITY, this.maxs);
53 WriteShort(MSG_ENTITY, this.cnt);
54 WriteString(MSG_ENTITY, this.mdl);
57 WriteShort(MSG_ENTITY, compressShortVector(this.velocity));
58 WriteShort(MSG_ENTITY, compressShortVector(this.movedir));
62 WriteShort(MSG_ENTITY, this.waterlevel * 16.0);
63 WriteByte(MSG_ENTITY, this.count * 16.0);
65 WriteString(MSG_ENTITY, this.noise);
68 WriteByte(MSG_ENTITY, floor(this.atten * 64));
69 WriteByte(MSG_ENTITY, floor(this.volume * 255));
71 WriteString(MSG_ENTITY, this.bgmscript);
72 if(this.bgmscript != "")
74 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
75 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
76 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
77 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
83 void pointparticles_use(entity this, entity actor, entity trigger)
85 this.state = !this.state;
89 void pointparticles_think(entity this)
91 if(this.origin != this.oldorigin)
94 this.oldorigin = this.origin;
96 this.nextthink = time;
99 void pointparticles_reset(entity this)
101 if(this.spawnflags & 1)
107 spawnfunc(func_pointparticles)
109 if(this.model != "") { precache_model(this.model); _setmodel(this, this.model); }
110 if(this.noise != "") precache_sound(this.noise);
111 if(this.mdl != "") this.cnt = 0; // use a good handler
113 if(!this.bgmscriptsustain) this.bgmscriptsustain = 1;
114 else if(this.bgmscriptsustain < 0) this.bgmscriptsustain = 0;
116 if(!this.atten) this.atten = ATTEN_NORM;
117 else if(this.atten < 0) this.atten = 0;
118 if(!this.volume) this.volume = 1;
119 if(!this.count) this.count = 1;
120 if(!this.impulse) this.impulse = 1;
124 setorigin(this, this.origin + this.mins);
125 setsize(this, '0 0 0', this.maxs - this.mins);
127 //if(!this.cnt) this.cnt = _particleeffectnum(this.mdl);
129 Net_LinkEntity(this, (this.spawnflags & 4), 0, pointparticles_SendEntity);
133 this.use = pointparticles_use;
134 this.reset = pointparticles_reset;
139 setthink(this, pointparticles_think);
140 this.nextthink = time;
143 spawnfunc(func_sparks)
145 // this.cnt is the amount of sparks that one burst will spawn
147 this.cnt = 25.0; // nice default value
150 // this.wait is the probability that a sparkthink will spawn a spark shower
151 // range: 0 - 1, but 0 makes little sense, so...
152 if(this.wait < 0.05) {
153 this.wait = 0.25; // nice default value
156 this.count = this.cnt;
159 this.velocity = '0 0 -1';
160 this.mdl = "TE_SPARK";
161 this.impulse = 10 * this.wait; // by default 2.5/sec
163 this.cnt = 0; // use mdl
165 spawnfunc_func_pointparticles(this);
169 .int dphitcontentsmask;
171 entityclass(PointParticles);
172 classfield(PointParticles) .int cnt; // effect number
173 classfield(PointParticles) .vector velocity; // particle velocity
174 classfield(PointParticles) .float waterlevel; // direction jitter
175 classfield(PointParticles) .int count; // count multiplier
176 classfield(PointParticles) .int impulse; // density
177 classfield(PointParticles) .string noise; // sound
178 classfield(PointParticles) .float atten;
179 classfield(PointParticles) .float volume;
180 classfield(PointParticles) .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
181 classfield(PointParticles) .vector movedir; // trace direction
182 classfield(PointParticles) .float glow_color; // palette index
184 void Draw_PointParticles(entity this)
191 sz = this.maxs - this.mins;
192 n = doBGMScript(this);
193 if(this.absolute == 2)
196 n = this.just_toggled ? this.impulse : 0;
198 n = this.impulse * drawframetime;
202 n *= this.impulse * drawframetime;
203 if(this.just_toggled)
210 for(i = random(); i <= n && fail <= 64*n; ++i)
213 p.x += random() * sz.x;
214 p.y += random() * sz.y;
215 p.z += random() * sz.z;
216 if(WarpZoneLib_BoxTouchesBrush(p, p, this, NULL))
218 if(this.movedir != '0 0 0')
220 traceline(p, p + normalize(this.movedir) * 4096, 0, NULL);
226 eff_num = _particleeffectnum(this.mdl);
227 __pointparticles(eff_num, p, trace_plane_normal * vlen(this.movedir) + this.velocity + randomvec() * this.waterlevel, this.count);
235 eff_num = _particleeffectnum(this.mdl);
236 __pointparticles(eff_num, p, this.velocity + randomvec() * this.waterlevel, this.count);
241 _sound(this, CH_AMBIENT, this.noise, VOL_BASE * this.volume, this.atten);
243 this.just_toggled = 0;
245 else if(this.absolute)
254 void Ent_PointParticles_Remove(entity this)
257 strfree(this.bgmscript);
261 NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew)
268 i = ReadCoord(); // density (<0: point, >0: volume)
269 if(i && !this.impulse && (this.cnt || this.mdl)) // this.cnt check is so it only happens if the ent already existed
270 this.just_toggled = 1;
275 this.origin = ReadVector();
279 this.modelindex = ReadShort();
284 this.mins = ReadVector();
285 this.maxs = ReadVector();
290 this.maxs = ReadVector();
295 this.mins = this.maxs = '0 0 0';
298 this.cnt = ReadShort(); // effect number
299 this.mdl = strzone(ReadString()); // effect string
303 this.velocity = decompressShortVector(ReadShort());
304 this.movedir = decompressShortVector(ReadShort());
308 this.velocity = this.movedir = '0 0 0';
312 this.waterlevel = ReadShort() / 16.0;
313 this.count = ReadByte() / 16.0;
320 strcpy(this.noise, ReadString());
323 this.atten = ReadByte() / 64.0;
324 this.volume = ReadByte() / 255.0;
326 strcpy(this.bgmscript, ReadString());
327 if(this.bgmscript != "")
329 this.bgmscriptattack = ReadByte() / 64.0;
330 this.bgmscriptdecay = ReadByte() / 64.0;
331 this.bgmscriptsustain = ReadByte() / 255.0;
332 this.bgmscriptrelease = ReadByte() / 64.0;
334 BGMScript_InitEntity(this);
341 this.absolute = (this.impulse >= 0);
344 v = this.maxs - this.mins;
345 this.impulse *= -v.x * v.y * v.z / 262144; // relative: particles per 64^3 cube
352 setorigin(this, this.origin);
353 setsize(this, this.mins, this.maxs);
354 this.solid = SOLID_NOT;
355 this.draw = Draw_PointParticles;
356 if (isnew) IL_PUSH(g_drawables, this);
357 this.entremove = Ent_PointParticles_Remove;